-
Notifications
You must be signed in to change notification settings - Fork 379
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
[Data Loader] Add a chain loader implementation #953
Conversation
|
||
$loader = $this->getLoader('baz'); | ||
|
||
foreach (['images/cats.jpeg', 'images/cats2.jpeg', 'file.ext', 'bar-bundle-file.ext', 'foo-bundle-file.ext'] as $file) { |
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.
Shorthand array syntax breaking PHP 5.3 builds
Binary/Loader/ChainLoader.php
Outdated
*/ | ||
private function getLoaderNamesString() | ||
{ | ||
$names = []; |
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.
Shorthand array syntax is breaking PHP 5.3 builds.
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.
{ | ||
public function testImplementsLoaderFactoryInterface() | ||
{ | ||
$rc = new \ReflectionClass('\Liip\ImagineBundle\DependencyInjection\Factory\Loader\ChainLoaderFactory'); |
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.
Might have asked this before but I wonder if these assertions on interface are still needed?
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.
IDK if they are "needed" but for consistency with the other loader tests, I feel like we should include it for now. In the meantime, I have changed it to remove the reflection-based method used, with a much more sensible use of PHPUnit's assertInstanceOf()
test assertion.
)); | ||
|
||
$this->assertArrayHasKey('loaders', $config); | ||
$this->assertCount(2, $config['loaders']); |
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.
Worth asserting that the array itself is as we expect, versus the count?
private function assertValidLoaderFindReturn($return, $message = null) | ||
{ | ||
$this->assertInstanceOf('\Liip\ImagineBundle\Model\FileBinary', $return, $message); | ||
$this->assertStringStartsWith('text/', $return->getMimeType(), $message); |
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.
Not a change, just curiosity--Is this assertion purely for the case where something is returned?
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.
Yup. I needed a clean way to validate the returned values from loaders, and checking if it is a FileBinary
and a text
file seemed pretty solid.
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.
Very nice way of going about it, and a slightly better assertion IMO than just checking something is present.
@antoligy Never tried to "dismiss" a review; wanted to see how that worked. ;-) Anyway, that was a crazy quick reviewing! How do you feel about the merits of this PR, as well as the implementation? Worth it? FYI: This still isn't ready for merge, as docs are still missing. |
a9e6e92
to
6e8ec6d
Compare
Fair enough! I didn't say anything about the merits of this PR earlier: I think it's a very useful addition, and similar projects of this type have similar logic. For me it's particularly interesting in clustered environments where a system might have an asset available locally to it quicker than the same asset over a network. Will be interesting to hear/see other uses that may emerge too! |
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.
Great new feature - thx Rob!
I'll open a new pull request with the documentation for this feature sometime tomorrow, as my comment about this fell through the cracks #953 (comment):
|
woops. |
@cedricziel It's all good; give #957 a review when you can. |
Chain data loader implementation. This allows one to define one "filter set" that searches multiple loader configurations (for example, this allows you to check both a Gaufrette stream loader and a file system loader simultaneously).
Here is an example configuration for the loader:
This implementation simply loops through the available loaders and selects the first valid result, so if the file exists in multiple loaders, the first defined in your configuration will be selected. For example, if
file.ext
exists in both thefoo
andbar
loader, the one found via thefoo
loader will be returned because it is defined first forbaz.chain.loaders
.