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] 1.0 release #183

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5324b5a
Started to integrate propel [WIP]
K-Phoen Dec 10, 2013
db36ffc
Use the PropertyAccess component to manipulate objects
K-Phoen Dec 10, 2013
ffb7ad9
Cleaned a bit the configuration definition
K-Phoen Dec 10, 2013
f81d091
Fixed dependency constraint
K-Phoen Dec 10, 2013
06a8dfb
Fixed a few typos
K-Phoen Dec 10, 2013
8746f74
Added a few tests for the PropelAdapter class
K-Phoen Dec 10, 2013
e079f40
Updated FileInjectorTest
K-Phoen Dec 10, 2013
c95e9e1
Updated PropertyMapping tests
K-Phoen Dec 10, 2013
88b23bc
Updated DoctrineUploaderListener tests
K-Phoen Dec 10, 2013
5a52771
Updated Tests/Storage/FileSystemStorageTest.php
K-Phoen Dec 10, 2013
9355d10
Fixed GaufretteStorage test
K-Phoen Dec 10, 2013
6db07b5
Little cs fix
K-Phoen Dec 10, 2013
8f99e26
Renamed MappingReader to MetadataReader
K-Phoen Dec 11, 2013
70c5fc4
Cleaned adapters definition
K-Phoen Dec 11, 2013
695eaaa
Fixed a few typos
K-Phoen Dec 11, 2013
ac9c4d8
Moar cs fixes
K-Phoen Dec 11, 2013
2b847f6
Added a few tests for the PropelUploader listener
K-Phoen Dec 11, 2013
51ef775
Fixed doctrine related listeners
K-Phoen Dec 11, 2013
8f78254
Updated propel event dispatcher dependency dependency
K-Phoen Dec 19, 2013
4ecaab6
Reduced the coupling with reflection objects
K-Phoen Dec 22, 2013
2382acf
File namers should use PropertyMapping instances instead of relying o…
K-Phoen Dec 22, 2013
d2edc2d
Cleaned last usages of Reflection in adapters as they now are useless
K-Phoen Dec 22, 2013
0867935
Allow older versions of the PropertyAccess component
K-Phoen Dec 22, 2013
dee3819
Fixed namespace for Naming testcases
K-Phoen Dec 22, 2013
adc3094
Fixed phpunit config file
K-Phoen Dec 22, 2013
8df8920
Started to work on the testsuite (less code, more meaningfull tests a…
K-Phoen Dec 22, 2013
1a26339
Fixed tests due to rebase
K-Phoen Dec 24, 2013
8538aca
Cleaned a bit more the FileSystemStorage test
K-Phoen Dec 24, 2013
c3cf0a8
Fixed the FileInjector tests so that the filesystem isn't impacted an…
K-Phoen Dec 24, 2013
b939d47
Fixed a few checkstyles
K-Phoen Dec 24, 2013
74967ab
Cleaned a bit the PropertyMappingFactory test
K-Phoen Dec 24, 2013
f79203c
Cleaned the DoctrineUploaderListener test
K-Phoen Dec 24, 2013
ef882a7
Worked on the DirectoryNamers
K-Phoen Dec 24, 2013
667ef48
Fixed tests for new DirectoryNamer implementation
K-Phoen Dec 24, 2013
b5baacc
Removed unused var in FileSystemStorage test
K-Phoen Dec 24, 2013
40d6ff0
Added a Xml driver
K-Phoen Dec 24, 2013
9ed7515
First full event-based implementation
K-Phoen Dec 24, 2013
19f1a6a
Cleaned MongoDBAdapter test
K-Phoen Dec 25, 2013
1e2f81d
Few fixes
K-Phoen Dec 25, 2013
bb63daf
Started to fix tests
K-Phoen Dec 25, 2013
9ba7bed
Deleted useless methods from PropertyMapping
K-Phoen Dec 25, 2013
6467b5a
Introduced a CachedPropertyMappingFactory class
K-Phoen Dec 25, 2013
46b7a1a
Fixed event listeners tests
K-Phoen Dec 25, 2013
ff066a1
Removed useless else statements
K-Phoen Dec 25, 2013
8ae1a5d
Renamed drivers
K-Phoen Dec 25, 2013
030c794
Added missing check in PropertyMappingFactory
K-Phoen Dec 25, 2013
6d2ce00
Fixed propel compiler pass
K-Phoen Dec 25, 2013
8500f0e
Added tests for the UploadHandler
K-Phoen Dec 25, 2013
fa652ef
Cleaned a bit adapters tests
K-Phoen Dec 25, 2013
400fd9e
Renamed UploadHandler methods
K-Phoen Dec 25, 2013
98c3e3c
Renamed FileInjector::injectFiles method to injectFile
K-Phoen Dec 25, 2013
aef9ed9
Gave a more precise version constraint for Propel
K-Phoen Dec 26, 2013
89efe45
Raised the minimum symfony version to 2.1
K-Phoen Dec 26, 2013
335aaf6
Added myself to the authors
K-Phoen Dec 26, 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ php:
- hhvm

env:
- SYMFONY_VERSION="~2.0.0" DOCTRINE_VERSION="~2.2.0"
- SYMFONY_VERSION="~2.1.0" DOCTRINE_VERSION=">=2.2.3,<2.5-dev"
- SYMFONY_VERSION="~2.2.0" DOCTRINE_VERSION="~2.2,>=2.2.3"
- SYMFONY_VERSION="~2.3.0" DOCTRINE_VERSION=">=2.2.3,<2.4-dev"
Expand Down
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);
}
23 changes: 11 additions & 12 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,33 @@ class MongoDBAdapter implements AdapterInterface
/**
* {@inheritDoc}
*/
public function getObjectFromArgs(EventArgs $e)
public function getObjectFromEvent($event)
{
return $e->getDocument();
return $event->getDocument();
}

/**
* {@inheritDoc}
*/
public function recomputeChangeSet(EventArgs $e)
public function recomputeChangeSet($event)
{
$obj = $this->getObjectFromArgs($e);
$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);
}

return new \ReflectionClass($obj);
return get_class($object);
}
}
23 changes: 11 additions & 12 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,33 @@ class DoctrineORMAdapter implements AdapterInterface
/**
* {@inheritDoc}
*/
public function getObjectFromArgs(EventArgs $e)
public function getObjectFromEvent($event)
{
return $e->getEntity();
return $event->getEntity();
}

/**
* {@inheritDoc}
*/
public function recomputeChangeSet(EventArgs $e)
public function recomputeChangeSet($event)
{
$obj = $this->getObjectFromArgs($e);
$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);
}

return new \ReflectionClass($obj);
return get_class($object);
}
}
36 changes: 36 additions & 0 deletions Adapter/Propel/PropelAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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)
{
return $event->getSubject();
}

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

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

$metadata = $container->get('vich_uploader.metadata_reader');
$classes = $metadata->getUploadableClasses();

foreach ($container->findTaggedServiceIds('vich_uploader.listener') as $id => $attributes) {
$listener = $container->getDefinition($id);
$listener->setClass($container->getDefinition($listener->getParent())->getClass());
$listener->setPublic(true);

foreach ($classes as $class) {
$listener->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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace odm to mongodb. Doctrine has 3 odm projects.


$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