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

[WIP] Propel integration #176

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
342ff0b
Started to integrate propel [WIP]
K-Phoen Dec 10, 2013
49642e3
Use the PropertyAccess component to manipulate objects
K-Phoen Dec 10, 2013
2343213
Cleaned a bit the configuration definition
K-Phoen Dec 10, 2013
04fba41
Fixed dependency constraint
K-Phoen Dec 10, 2013
8a98c8d
Fixed a few typos
K-Phoen Dec 10, 2013
e55a472
Added a few tests for the PropelAdapter class
K-Phoen Dec 10, 2013
9153517
Updated FileInjectorTest
K-Phoen Dec 10, 2013
3ab8fea
Updated PropertyMapping tests
K-Phoen Dec 10, 2013
4c48621
Updated DoctrineUploaderListener tests
K-Phoen Dec 10, 2013
4327cd8
Updated Tests/Storage/FileSystemStorageTest.php
K-Phoen Dec 10, 2013
886fb93
Fixed GaufretteStorage test
K-Phoen Dec 10, 2013
29b964e
Little cs fix
K-Phoen Dec 10, 2013
143de76
Renamed MappingReader to MetadataReader
K-Phoen Dec 11, 2013
bf77f28
Cleaned adapters definition
K-Phoen Dec 11, 2013
590d445
Fixed a few typos
K-Phoen Dec 11, 2013
17934f7
Moar cs fixes
K-Phoen Dec 11, 2013
d1855ec
Added a few tests for the PropelUploader listener
K-Phoen Dec 11, 2013
8e7dbce
Fixed doctrine related listeners
K-Phoen Dec 11, 2013
5b7674f
Updated propel event dispatcher dependency dependency
K-Phoen Dec 19, 2013
4c789b4
Reduced the coupling with reflection objects
K-Phoen Dec 22, 2013
f0e96e0
File namers should use PropertyMapping instances instead of relying o…
K-Phoen Dec 22, 2013
fbe6e47
Cleaned last usages of Reflection in adapters as they now are useless
K-Phoen Dec 22, 2013
a031096
Allow older versions of the PropertyAccess component
K-Phoen Dec 22, 2013
f39fc1d
Fixed namespace for Naming testcases
K-Phoen Dec 22, 2013
600eac9
Fixed phpunit config file
K-Phoen Dec 22, 2013
7b48f37
Started to work on the testsuite (less code, more meaningfull tests a…
K-Phoen Dec 22, 2013
a0e22b0
Fixed tests due to rebase
K-Phoen Dec 24, 2013
fa1d9b5
Cleaned a bit more the FileSystemStorage test
K-Phoen Dec 24, 2013
6d144e7
Fixed the FileInjector tests so that the filesystem isn't impacted an…
K-Phoen Dec 24, 2013
db1e0db
Fixed a few checkstyles
K-Phoen Dec 24, 2013
62e8a0d
Cleaned a bit the PropertyMappingFactory test
K-Phoen Dec 24, 2013
0b438f7
Cleaned the DoctrineUploaderListener test
K-Phoen Dec 24, 2013
0dce039
Worked on the DirectoryNamers
K-Phoen Dec 24, 2013
79fb200
Fixed tests for new DirectoryNamer implementation
K-Phoen Dec 24, 2013
47fda4e
Removed unused var in FileSystemStorage test
K-Phoen Dec 24, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Vich\UploaderBundle\Adapter;

use Doctrine\Common\EventArgs;

/**
* AdapterInterface.
*
Expand All @@ -12,26 +10,26 @@
interface AdapterInterface
{
/**
* Gets the mapped object from the event arguments.
* Gets the mapped object from an event.
*
* @param EventArgs $e The event arguments.
* @return object The mapped object.
* @param object $event The event argument.
* @return object The mapped object.
*/
public function getObjectFromArgs(EventArgs $e);
public function getObjectFromEvent($event);

/**
* Recomputes the change set for the object.
* Recomputes the change set for the given object.
*
* @param EventArgs $e The event arguments.
* @param object $event The event arguments.
*/
public function recomputeChangeSet(EventArgs $e);
public function recomputeChangeSet($event);

/**
* Gets the reflection class for the object taking
* proxies into account.
* Gets class name for the object, taking proxies into account.
*
* @param object $object The object.
*
* @param object $obj The object.
* @return \ReflectionClass The reflection class.
* @return string The FQCN of the className.
*/
public function getReflectionClass($obj);
public function getClassName($object);
}
28 changes: 15 additions & 13 deletions Adapter/ODM/MongoDB/MongoDBAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Vich\UploaderBundle\Adapter\ODM\MongoDB;

use Vich\UploaderBundle\Adapter\AdapterInterface;
use Doctrine\Common\EventArgs;
use Doctrine\ODM\MongoDB\Proxy\Proxy;

/**
Expand All @@ -16,33 +15,36 @@ class MongoDBAdapter implements AdapterInterface
/**
* {@inheritDoc}
*/
public function getObjectFromArgs(EventArgs $e)
public function getObjectFromEvent($event)
{
return $e->getDocument();
/* @var $event \Doctrine\Common\EventArgs */

return $event->getDocument();
}

/**
* {@inheritDoc}
*/
public function recomputeChangeSet(EventArgs $e)
public function recomputeChangeSet($event)
{
$obj = $this->getObjectFromArgs($e);
/* @var $event \Doctrine\Common\EventArgs */
$object = $this->getObjectFromEvent($event);

$dm = $e->getDocumentManager();
$dm = $event->getDocumentManager();
$uow = $dm->getUnitOfWork();
$metadata = $dm->getClassMetadata(get_class($obj));
$uow->recomputeSingleDocumentChangeSet($metadata, $obj);
$metadata = $dm->getClassMetadata(get_class($object));
$uow->recomputeSingleDocumentChangeSet($metadata, $object);
}

/**
* {@inheritDoc}
*/
public function getReflectionClass($obj)
public function getClassName($object)
{
if ($obj instanceof Proxy) {
return new \ReflectionClass(get_parent_class($obj));
if ($object instanceof Proxy) {
return get_parent_class($object);
} else {
return get_class($object);
}

return new \ReflectionClass($obj);
}
}
28 changes: 15 additions & 13 deletions Adapter/ORM/DoctrineORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Vich\UploaderBundle\Adapter\ORM;

use Vich\UploaderBundle\Adapter\AdapterInterface;
use Doctrine\Common\EventArgs;
use Doctrine\Common\Persistence\Proxy;

/**
Expand All @@ -16,33 +15,36 @@ class DoctrineORMAdapter implements AdapterInterface
/**
* {@inheritDoc}
*/
public function getObjectFromArgs(EventArgs $e)
public function getObjectFromEvent($event)
{
return $e->getEntity();
/* @var $event \Doctrine\Common\EventArgs */

return $event->getEntity();
}

/**
* {@inheritDoc}
*/
public function recomputeChangeSet(EventArgs $e)
public function recomputeChangeSet($event)
{
$obj = $this->getObjectFromArgs($e);
/* @var $event \Doctrine\Common\EventArgs */
$object = $this->getObjectFromEvent($event);

$em = $e->getEntityManager();
$em = $event->getEntityManager();
$uow = $em->getUnitOfWork();
$metadata = $em->getClassMetadata(get_class($obj));
$uow->recomputeSingleEntityChangeSet($metadata, $obj);
$metadata = $em->getClassMetadata(get_class($object));
$uow->recomputeSingleEntityChangeSet($metadata, $object);
}

/**
* {@inheritDoc}
*/
public function getReflectionClass($obj)
public function getClassName($object)
{
if ($obj instanceof Proxy) {
return new \ReflectionClass(get_parent_class($obj));
if ($object instanceof Proxy) {
return get_parent_class($object);
} else {
return get_class($object);
}

return new \ReflectionClass($obj);
}
}
38 changes: 38 additions & 0 deletions Adapter/Propel/PropelAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Vich\UploaderBundle\Adapter\Propel;

use Vich\UploaderBundle\Adapter\AdapterInterface;

/**
* Propel adapter.
*
* @author Kévin Gomez <[email protected]>
*/
class PropelAdapter implements AdapterInterface
{
/**
* {@inheritDoc}
*/
public function getObjectFromEvent($event)
{
/* @var $event \Symfony\Component\EventDispatcher\GenericEvent */

return $event->getSubject();
}

/**
* {@inheritDoc}
*/
public function recomputeChangeSet($event)
{
}

/**
* {@inheritDoc}
*/
public function getClassName($object)
{
return get_class($object);
}
}
32 changes: 32 additions & 0 deletions DependencyInjection/CompilerPass/RegisterPropelModelsPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Vich\UploaderBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Register the uploadable models in BazingaPropelEventDispatcherBundle
*
* @author Kévin Gomez <[email protected]>
*/
class RegisterPropelModelsPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->getParameter('vich_uploader.driver') !== 'propel') {
return;
}

$propelListener = $container->getDefinition('vich_uploader.listener.uploader.propel');
$metadata = $container->get('vich_uploader.metadata_reader');
foreach ($metadata->getUploadableClasses() as $class) {
$propelListener->addTag('propel.event_subscriber', array(
'class' => $class
));
}
}
}
40 changes: 35 additions & 5 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vich\UploaderBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -22,12 +23,37 @@ public function getConfigTreeBuilder()
$tb = new TreeBuilder();
$root = $tb->root('vich_uploader');

$supportedDbDrivers = array('orm', 'odm', 'propel');

$root
->children()
->scalarNode('db_driver')->isRequired()->end()
->scalarNode('db_driver')
->isRequired()
->beforeNormalization()
->ifString()
->then(function ($v) { return strtolower($v); })
->end()
->validate()
->ifNotInArray($supportedDbDrivers)
->thenInvalid('The db driver %s is not supported. Please choose one of ' . implode(', ', $supportedDbDrivers))
->end()
->end()
->scalarNode('storage')->defaultValue('vich_uploader.storage.file_system')->end()
->scalarNode('twig')->defaultTrue()->end()
->scalarNode('gaufrette')->defaultFalse()->end()
->end()
;

$this->addMetadataSection($root);
$this->addMappingsSection($root);

return $tb;
}

protected function addMetadataSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('metadata')
->addDefaultsIfNotSet()
->fixXmlConfig('directory', 'directories')
Expand All @@ -50,6 +76,13 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->end();
}

protected function addMappingsSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('mappings')
->useAttributeAsKey('id')
->prototype('array')
Expand All @@ -64,9 +97,6 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->end()
;

return $tb;
->end();
}
}
Loading