-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow DataEndpoint singleton to auto-discover available data endpoints #157
Allow DataEndpoint singleton to auto-discover available data endpoints #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor misspellings / questions is all.
classes/ETL/DataEndpoint.php
Outdated
* @var string | ||
*/ | ||
|
||
private static $dataEndpointRelativeNs = 'DataEndpoint'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended that these be changed at some point during the classes life time? Just wanting to understand the choice of private static
vs const
. This same question applies to $dataEndpointRequiredInterface
and $endpointNameConstant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, no they don't change programmatically so it does make sense for them to be constants. I'll make that change.
classes/ETL/DataEndpoint.php
Outdated
} // getDataEndpointInfo() | ||
|
||
/** ----------------------------------------------------------------------------------------- | ||
* Discover the list of currently supported data endpoints and constuct a list mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/constuct/construct
classes/ETL/DataEndpoint.php
Outdated
// file resides represent sub-namespaces. | ||
|
||
// The endpoint directory is relative to the directory where this file is found | ||
$endpointDir = dirname(__FILE__) . '/' . strtr(self::$dataEndpointRelativeNs, '\\', '/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More for myself than anything else are hard coded '/' cool as opposed to using say, DIRECTORY_SEPARATOR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DIRECTORY_SEPARATOR is a more portable way to specify it (not that it matters on the platforms that we support). I'll make that change as well.
classes/ETL/DataEndpoint.php
Outdated
|
||
class DataEndpoint | ||
{ | ||
/** | ||
* Namesapce, relative to the current namespace, where data endpoint classes are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Namesapce/Namespace
classes/ETL/DataEndpoint.php
Outdated
/** ----------------------------------------------------------------------------------------- | ||
* Discover the list of currently supported data endpoints and constuct a list mapping | ||
* their names to the classes that implement them. All data endpoints must implement | ||
* the interface specified in self::$dataEndpointRequiredInterface. By automatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should either mention that they also need to define the const ENDPOINT_NAME
or add a function to iDataEndpoint
that returns this value so that all that is required is to implement the interface.
classes/ETL/DataEndpoint.php
Outdated
* @param $options A DataEndpointOptions object containing options parsed from the ETL config. | ||
* @param DataEndpointOptions $options A DataEndpointOptions object containing options | ||
* parsed from the ETL config. | ||
* @param Log $logger A PEAR Log object or null to use the null logger. | ||
* | ||
* @return A data endpoint object implementing the iDataEndpoint interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a return type
$dotDirFilterIterator = new \CallbackFilterIterator( | ||
$iterator, | ||
function ($current, $key, $iterator) { | ||
if ( $iterator->isDot() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to return ! $iterator->isDot();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points.
); | ||
} | ||
|
||
if ( null !== $this->maxRecursionDepth ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to move this line to 464 into the try above as all of these operations depend on $flattenedIterator existing. It would also then conform to the pattern seen elsewhere in the code of: try block that creates new iterator, maybe does a few things and ultimately sets iterator = new iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
ubccr#157) * Remove commented out code, improve control structure flow * Allow DataEndpoint to auto-discover classes implementing iDataEndpoint * Add overseer option to list available data endpoint types
ubccr#157) * Remove commented out code, improve control structure flow * Allow DataEndpoint to auto-discover classes implementing iDataEndpoint * Add overseer option to list available data endpoint types
Allow DataEndpoint singleton to auto-discover available data endpoints
Description
Rather than require a developer to modify
ETL\DataEndpoint.php
and explicitly list each available data endpoint and it's configuration code, we now allow theDataEndpoint
singleton to automatically discover what data endpoints are available. As per PSR-4 the contiguous sub-namespace names after the "namespace prefix" (ETL
in our case) correspond to a subdirectory within a "base directory", in which the namespace separators represent directory separators. From this, we can assume theETL\DataEndpoint
sub-namespace is in theDataEndpoint
subdirectory relative to where theDataEndpoint
singleton class is defined. Using this knowledge we use reflection to recursively examine each file in theDataEndpoint
subdirectory and any class implementingiDataEndpoint
and also defining anENDPOINT_NAME
constant will be a valid endpoint definition. TheENDPOINT_NAME
constant defines the endpoint name to be used in configuration files. Conflicts in endpoint names are logged.The
etl_overseer
script has been modified to list the available endpoints:Motivation and Context
Make it easier to define data endpoints.
Tests performed
Ran existing tests, several of which use the File and Json endpoints.
Types of changes
Checklist: