laravel-doctrine / extensions

Extensions integration for Doctrine2 and Laravel
http://laraveldoctrine.org/
MIT License
48 stars 24 forks source link

uploadable #7

Closed mitjarobic closed 8 years ago

mitjarobic commented 8 years ago

Hello,

i am trying to use the uploadable extension. How do i get the $listener variable used in the documentation example?

$listener->setDefaultPath('/my/path');

$file = new File();

$listener->addEntityFileInfo($file, new CustomFileInfo('/path/to/file.txt'));

$em->persist($file);
$em->flush();
patrickbrouwers commented 8 years ago

@jee7 can you answer this question?

jee7 commented 8 years ago

Of course. You see, the UploadableExtensionServiceProvider registers a singleton with the alias of the class name of UploadableListener.

You can use that to fetch the singleton anywhere in your code (or inject it as an hard dependency if you want).

Using the app() shortcut:

$listener = app(UploadableListener::class);
mitjarobic commented 8 years ago

Thank you, but i can not get it to work. Is there something else I should set in doctrine.php except uncomment the 'LaravelDoctrine\Extensions\Uploadable\UploadableExtension::class' which is missing by default.

It seems the $this->fileInfoObjects is empty in onFlush method

https://github.com/Atlantic18/DoctrineExtensions/blob/master/lib/Gedmo/Uploadable/UploadableListener.php#L144

although i set it with

$listener->addEntityFileInfo($file, new CustomFileInfo('/path/to/file.txt'));
jee7 commented 8 years ago

Did you add the LaravelDoctrine\Extensions\Uploadable\UploadableExtensionServiceProvider::class to the list of service providers (the providers key) in your app.php config?

mitjarobic commented 8 years ago

That was it, thank you!

jee7 commented 8 years ago

Btw, there is also an Uploadable facade that you can use. See my last comment in the PR.

You're welcome. Don't know, why the service provider registration seems to be missing from the doc.

patrickbrouwers commented 8 years ago

Seems like the docs weren't updated after your PR. Could you make a PR with some notes about the singleton?