Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added base DI classes.

  • Loading branch information...
commit 7248f7f0cd50e093cde51a59e9002e7b386d57c2 1 parent 328a024
@golovanov authored
View
30 DependencyInjection/Compiler/CreateProxyDirectoryPass.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Doctrine\Bundle\OXMBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+class CreateProxyDirectoryPass implements CompilerPassInterface
+{
+ public function process(ContainerBuilder $container)
+ {
+ if (!$container->hasParameter('doctrine.oxm.proxy_dir')) {
+ return;
+ }
+ // Don't do anything if auto_generate_proxy_classes is false
+ if (!$container->getParameter('doctrine.oxm.auto_generate_proxy_classes')) {
+ return;
+ }
+ // Create document proxy directory
+ $proxyCacheDir = $container->getParameter('doctrine.oxm.proxy_dir');
+ if (!is_dir($proxyCacheDir)) {
+ if (false === @mkdir($proxyCacheDir, 0777, true)) {
+ exit(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
+ }
+ } elseif (!is_writable($proxyCacheDir)) {
+ exit(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir));
+ }
+ }
+
+}
View
2  DependencyInjection/Compiler/EventManagerPass.php
@@ -1,6 +1,6 @@
<?php
-namespace Go\DoctrineOXMBundle\DependencyInjection\Compiler;
+namespace Doctrine\Bundle\OXMBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
View
17 DependencyInjection/Configuration.php
@@ -1,6 +1,6 @@
<?php
-namespace Go\DoctrineOXMBundle\DependencyInjection;
+namespace Doctrine\Bundle\OXMBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -33,17 +33,16 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('doctrine_oxm');
- $this->addEntityManagersSection($rootNode);
+ $rootNode
+ ->children()
+ ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end()
+ ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/oxm/Proxies')->end()
+ ->scalarNode('auto_generate_proxy_classes')->defaultValue(false)->end()
+ ->end()
+ ;
return $treeBuilder;
}
- /**
- * Configures the "document_managers" section
- */
- private function addEntityManagersSection(ArrayNodeDefinition $rootNode)
- {
-
- }
}
View
36 DependencyInjection/DoctrineOXMExtension.php
@@ -1,6 +1,6 @@
<?php
-namespace Go\DoctrineOXMBundle\DependencyInjection;
+namespace Doctrine\Bundle\OXMBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -26,7 +26,39 @@ public function load(array $configs, ContainerBuilder $container)
// Load DoctrineMongoDBBundle/Resources/config/mongodb.xml
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('oxm.xml');
+
+
+
+ // set some options as parameters and unset them
+ $config = $this->overrideParameters($config, $container);
+ }
+
+
+ /**
+ * Uses some of the extension options to override DI extension parameters.
+ *
+ * @param array $options The available configuration options
+ * @param ContainerBuilder $container A ContainerBuilder instance
+ */
+ protected function overrideParameters($options, ContainerBuilder $container)
+ {
+ $overrides = array(
+ 'proxy_namespace',
+ 'proxy_dir',
+ 'auto_generate_proxy_classes',
+ );
+
+ foreach ($overrides as $key) {
+ if (isset($options[$key])) {
+ $container->setParameter('doctrine.oxm.'.$key, $options[$key]);
+
+ // the option should not be used, the parameter should be referenced
+ unset($options[$key]);
+ }
+ }
+
+ return $options;
}
@@ -37,7 +69,7 @@ protected function getObjectManagerElementName($name)
protected function getMappingObjectDefaultName()
{
- return 'Document';
+ return 'XmlEntity';
}
protected function getMappingResourceConfigDirectory()
View
4 DoctrineOXMBundle.php
@@ -1,11 +1,11 @@
<?php
-namespace Go\DoctrineOXMBundle;
+namespace Doctrine\Bundle\OXMBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Go\DoctrineOXMBundle\DependencyInjection\Compiler\EventManagerPass;
+use Doctrine\Bundle\OXMBundle\DependencyInjection\Compiler\EventManagerPass;
/**
* Doctrine OXM bundle.
View
2  Mapping/Driver/XmlDriver.php
@@ -1,6 +1,6 @@
<?php
-namespace Go\DoctrineOXMBundle\Mapping\Driver;
+namespace Doctrine\Bundle\OXMBundle\Mapping\Driver;
use Doctrine\OXM\Mapping\Driver\XmlDriver as BaseXmlDriver;
use Doctrine\OXM\OXMException;
View
2  Mapping/Driver/YamlDriver.php
@@ -1,6 +1,6 @@
<?php
-namespace Go\DoctrineOXMBundle\Mapping\Driver;
+namespace Doctrine\Bundle\Mapping\Driver;
use Doctrine\OXM\Mapping\Driver\YamlDriver as BaseYamlDriver;
use Doctrine\OXM\OXMException;
View
9 README.md
@@ -1,3 +1,12 @@
# Doctrine 2 OXM Bundle
Doctrine OXM is a PHP 5.3 project for PHP object to XML mapping that provides support for persisting the XML to a file system via common Doctrine techniques.
+
+
+## Instaliation
+
+### Register annotations.
+
+```php
+AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine-oxm/lib/Doctrine/OXM/Mapping/Driver/DoctrineAnnotations.php');
+```
View
6 Resources/config/oxm.xml
@@ -8,9 +8,9 @@
<parameter key="doctrine.oxm.event_manager.class">Doctrine\Common\EventManager</parameter>
<!-- proxies -->
- <parameter key="doctrine.odm.mongodb.proxy_namespace">Proxies</parameter>
- <parameter key="doctrine.odm.mongodb.proxy_dir">%kernel.cache_dir%/doctrine/odm/mongodb/Proxies</parameter>
- <parameter key="doctrine.odm.mongodb.auto_generate_proxy_classes">false</parameter>
+ <parameter key="doctrine.oxm.proxy_namespace">Proxies</parameter>
+ <parameter key="doctrine.oxm.proxy_dir">%kernel.cache_dir%/doctrine/oxm/Proxies</parameter>
+ <parameter key="doctrine.oxm.auto_generate_proxy_classes">false</parameter>
<!-- cache -->
<parameter key="doctrine.oxm.cache.array.class">Doctrine\Common\Cache\ArrayCache</parameter>
Please sign in to comment.
Something went wrong with that request. Please try again.