-
-
Save ftassi/32378f4000df482a8b9b to your computer and use it in GitHub Desktop.
Wiring up Symfony2 services in the DIC using configuration parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="vich_uploader.property_mapping_factory" class="Vich\UploaderBundle\Mapping\PropertyMappingFactory" public="false"> | |
<argument type="service" id="service_container" /> | |
<argument type="service" id="vich_uploader.annotation_driver" /> | |
<argument type="service" id="vich_uploader.adapter" /> | |
<argument>%vich_uploader.mappings%</argument> | |
</service> | |
<service id="vich_uploader.storage_factory" class="Vich\UploaderBundle\Storage\StorageFactory"> | |
<argument type="service" id="service_container" /> | |
</service> | |
</services> | |
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="vich_uploader.storage.adapter.rackspace_cloud_files" class="Vich\UploaderBundle\Storage\Adapter\RackspaceCloudFilesAdapter"> | |
<call method="setContainer"> | |
<argument type="service" id="service_container" /> | |
</call> | |
<call method="setMediaContainer"> | |
<argument type="string">%vich_uploader.storage.adapter.rackspace.media_container%</argument> | |
</call> | |
</service> | |
<service id="vich_uploader.storage.file_system" class="Vich\UploaderBundle\Storage\FileSystemStorage"> | |
<argument type="service" id="vich_uploader.property_mapping_factory" /> | |
</service> | |
<service id="vich_uploader.storage.cdn" class="Vich\UploaderBundle\Storage\CDNStorage"> | |
<argument type="service" id="vich_uploader.property_mapping_factory" /> | |
<argument type="service" id="vich_uploader.storage.adapter.rackspace_cloud_files" /> | |
</service> | |
<service | |
id="vich_uploader.storage" | |
class="Vich\UploaderBundle\Storage\StorageInterface" | |
factory-service="vich_uploader.storage_factory" | |
factory-method ="createStorage"> | |
</service> | |
</services> | |
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vich\UploaderBundle\Storage; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* StorageFactory | |
* | |
** @author Francesco Tassi <tassi.francesco@gmail.com> | |
*/ | |
class StorageFactory | |
{ | |
/** | |
* | |
* @var ContainerInterface | |
*/ | |
protected $container; | |
/** | |
* | |
* @param ContainerInterface $container | |
*/ | |
public function __construct(ContainerInterface $container) | |
{ | |
$this->container = $container; | |
} | |
public function createStorage() | |
{ | |
return $this->container->get($this->container->getParameter('vich_uploader.storage_service')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment