Skip to content
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

Use of protected class properties in FilesystemLoader #54

Merged
merged 1 commit into from
Mar 8, 2012
Merged

Use of protected class properties in FilesystemLoader #54

merged 1 commit into from
Mar 8, 2012

Conversation

petrjaros
Copy link
Contributor

No description provided.

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 8, 2012

can you explain the use case for when you require access to these properties?

@petrjaros
Copy link
Contributor Author

I have created a data loader class which is changing the name of source image to be cached which different name (there are some sensitive data in the image name - this data belong to the image, but I don't want to show the data to the users). So I have created class which extends FileSystemLoader. I need access to rootPath property in my class.
So, the only reason for this pull request is, that I would like to access properties of FileSystemLoader from extending class.
There is my code:

<?php
namespace Dmc\ConfiguratorBundle\Imagine\Data\Loader;

use Liip\ImagineBundle\Imagine\Data\Loader\FileSystemLoader;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class CarDataLoader extends FileSystemLoader
{    
    public function find($path)
    {
        $path = $this->carModelSourcePath($path);
        return parent::find($path);
    }

    private function carModelSourcePath($path)
    {
        $dir = dirname($path);
        $filename = basename($path);
        $parts = explode('-', $filename, 3);

        $finder = new Finder();
        $finder->files()->in($this->rootPath . '/' . $dir)->name($parts[0] . '-' . $parts[1] . '-' . '*' . '-' . substr($parts[2], 0, -3) . '*');
        $i = $finder->getIterator();
        $i->next();
        $file = $i->current();
        if(!$file instanceof \SplFileInfo) throw new NotFoundHttpException(sprintf('Car image not found for "%s"', $path));
        return $dir . '/' . $file->getFilename();
    }
}

I know that it's possible to make own constructor and save rootPath in another class property but it's duplicity I would like to awoid.

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 8, 2012

ok .. merging.

lsmith77 added a commit that referenced this pull request Mar 8, 2012
Use of protected class properties in FilesystemLoader
@lsmith77 lsmith77 merged commit ef8fb67 into liip:master Mar 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants