Merge pull request #672 from hell0w0rd/simplification_example
Simplification example
This commit is contained in:
commit
a36f84eeb5
41
tools/sandbox/bootstrap.php
Normal file
41
tools/sandbox/bootstrap.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Cache;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
// Path to composer autoloader. You can use different provided by your favorite framework,
|
||||
// if you want to.
|
||||
$loaderPath = __DIR__ . '/../../vendor/autoload.php';
|
||||
if(!is_readable($loaderPath)){
|
||||
throw new LogicException('Run php composer.phar install at first');
|
||||
}
|
||||
$loader = require $loaderPath;
|
||||
|
||||
// Set up class loading.
|
||||
$loader->add('Entities', __DIR__);
|
||||
$loader->add('Proxies', __DIR__);
|
||||
|
||||
$debug = true;
|
||||
$config = new \Doctrine\ORM\Configuration();
|
||||
|
||||
// Set up Metadata Drivers
|
||||
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/Entities"));
|
||||
$config->setMetadataDriverImpl($driverImpl);
|
||||
|
||||
// Set up caches, depending on $debug variable.
|
||||
// You can use another variable to define which one of the cache systems you gonna use.
|
||||
$cache = $debug ? new Cache\ArrayCache : new Cache\ApcCache;
|
||||
$config->setMetadataCacheImpl($cache);
|
||||
$config->setQueryCacheImpl($cache);
|
||||
|
||||
// Proxy configuration
|
||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||
$config->setProxyNamespace('Proxies');
|
||||
|
||||
// Database connection information
|
||||
$connectionOptions = array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => 'database.sqlite'
|
||||
);
|
||||
|
||||
return EntityManager::create($connectionOptions, $config);
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
|
||||
$classLoader->register();
|
||||
|
||||
$config = new \Doctrine\ORM\Configuration();
|
||||
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
|
||||
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
|
||||
$config->setMetadataDriverImpl($driverImpl);
|
||||
|
||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||
$config->setProxyNamespace('Proxies');
|
||||
|
||||
$connectionOptions = array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => 'database.sqlite'
|
||||
);
|
||||
|
||||
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
|
||||
|
||||
$helpers = new Symfony\Component\Console\Helper\HelperSet(array(
|
||||
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
|
||||
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
|
||||
));
|
@ -1,27 +1,14 @@
|
||||
<?php
|
||||
|
||||
require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
|
||||
$classLoader->register();
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
|
||||
$classLoader->register();
|
||||
|
||||
require __DIR__ . '/cli-config.php';
|
||||
$em = require_once __DIR__.'/bootstrap.php';
|
||||
|
||||
$cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\Common\Version::VERSION);
|
||||
$cli->setCatchExceptions(true);
|
||||
|
||||
// Variable $helpers is defined inside cli-config.php
|
||||
$cli->setHelperSet($helpers);
|
||||
$cli->setHelperSet(new Symfony\Component\Console\Helper\HelperSet(array(
|
||||
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
|
||||
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
|
||||
)));
|
||||
|
||||
$cli->addCommands(array(
|
||||
// DBAL Commands
|
||||
|
@ -9,50 +9,10 @@
|
||||
|
||||
namespace Sandbox;
|
||||
|
||||
use Doctrine\Common\ClassLoader,
|
||||
Doctrine\ORM\Configuration,
|
||||
Doctrine\ORM\EntityManager,
|
||||
Doctrine\Common\Cache\ApcCache,
|
||||
Entities\User, Entities\Address;
|
||||
use Entities\Address;
|
||||
use Entities\User;
|
||||
|
||||
require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
|
||||
|
||||
// Set up class loading. You could use different autoloaders, provided by your favorite framework,
|
||||
// if you want to.
|
||||
$classLoader = new ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
|
||||
$classLoader->register();
|
||||
$classLoader = new ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
|
||||
$classLoader->register();
|
||||
$classLoader = new ClassLoader('Entities', __DIR__);
|
||||
$classLoader->register();
|
||||
$classLoader = new ClassLoader('Proxies', __DIR__);
|
||||
$classLoader->register();
|
||||
|
||||
// Set up caches
|
||||
$config = new Configuration;
|
||||
$cache = new ApcCache;
|
||||
$config->setMetadataCacheImpl($cache);
|
||||
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
|
||||
$config->setMetadataDriverImpl($driverImpl);
|
||||
$config->setQueryCacheImpl($cache);
|
||||
|
||||
// Proxy configuration
|
||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||
$config->setProxyNamespace('Proxies');
|
||||
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
|
||||
|
||||
// Database connection information
|
||||
$connectionOptions = array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => 'database.sqlite'
|
||||
);
|
||||
|
||||
// Create EntityManager
|
||||
$em = EntityManager::create($connectionOptions, $config);
|
||||
$em = require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
## PUT YOUR TEST CODE BELOW
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user