Example #1
0
 * versions. Regarding AnnotationDriver setup it most probably will be changed into
 * xml. Because annotation driver fails to read other classes in same namespace
 */
// connection args, modify at will
$connection = array('host' => '127.0.0.1', 'port' => 3306, 'user' => 'root', 'password' => null, 'dbname' => 'test', 'driver' => 'pdo_mysql');
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
    die('cannot find vendors, read README.md how to use composer');
}
// First of all autoloading of vendors
$loader = (require __DIR__ . '/../vendor/autoload.php');
// gedmo extensions
$loader->add('Gedmo', __DIR__ . '/../lib');
// autoloader for Entity namespace
$loader->add('Entity', __DIR__ . '/app');
// ensure standard doctrine annotations are registered
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Second configure ORM
// globally used cache driver, in production use APC or memcached
$cache = new Doctrine\Common\Cache\ArrayCache();
// standard annotation reader
$annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
// create a driver chain for metadata reading
$driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
// load superclass metadata mapping only, into driver chain
// also registers Gedmo annotations.NOTE: you can personalize it
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
// now we want to register our application entities,
// for that we need another metadata driver used for Entity namespace
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/app/Entity'));
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever
Example #2
0
 * This is bootstrap for phpUnit unit tests,
 * use README.md for more details
 *
 * @author Gediminas Morkevicius <*****@*****.**>
 * @package Gedmo.Tests
 * @link http://www.gediminasm.org
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
if (!class_exists('PHPUnit_Framework_TestCase') || version_compare(PHPUnit_Runner_Version::id(), '3.5') < 0) {
    die('PHPUnit framework is required, at least 3.5 version');
}
if (!class_exists('PHPUnit_Framework_MockObject_MockBuilder')) {
    die('PHPUnit MockObject plugin is required, at least 1.0.8 version');
}
define('TESTS_PATH', __DIR__);
define('TESTS_TEMP_DIR', __DIR__ . '/temp');
define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
$classLoaderFile = VENDOR_PATH . '/Symfony/Component/ClassLoader/UniversalClassLoader.php';
if (!file_exists($classLoaderFile)) {
    die('cannot find vendor, run: php bin/vendors.php');
}
require_once $classLoaderFile;
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array('Symfony' => VENDOR_PATH, 'Doctrine\\MongoDB' => VENDOR_PATH . '/doctrine-mongodb/lib', 'Doctrine\\ODM\\MongoDB' => VENDOR_PATH . '/doctrine-mongodb-odm/lib', 'Doctrine\\Common' => VENDOR_PATH . '/doctrine-common/lib', 'Doctrine\\DBAL' => VENDOR_PATH . '/doctrine-dbal/lib', 'Doctrine\\ORM' => VENDOR_PATH . '/doctrine-orm/lib', 'Gedmo\\Mapping\\Mock' => __DIR__, 'Gedmo' => __DIR__ . '/../lib', 'Tool' => __DIR__ . '/Gedmo', 'Translator\\Fixture' => __DIR__ . '/Gedmo', 'Translatable\\Fixture' => __DIR__ . '/Gedmo', 'Timestampable\\Fixture' => __DIR__ . '/Gedmo', 'Tree\\Fixture' => __DIR__ . '/Gedmo', 'Sluggable\\Fixture' => __DIR__ . '/Gedmo', 'Sortable\\Fixture' => __DIR__ . '/Gedmo', 'Mapping\\Fixture' => __DIR__ . '/Gedmo', 'Loggable\\Fixture' => __DIR__ . '/Gedmo', 'SoftDeleteable\\Fixture' => __DIR__ . '/Gedmo', 'Uploadable\\Fixture' => __DIR__ . '/Gedmo', 'Wrapper\\Fixture' => __DIR__ . '/Gedmo', 'Gedmo\\Uploadable\\Stub' => __DIR__));
$loader->register();
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php');
Gedmo\DoctrineExtensions::registerAnnotations();
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
$_ENV['annotation_reader'] = $reader;
Example #3
0
<?php

$vendorDir = __DIR__ . '/../vendor';
$bundleDir = __DIR__ . '/../vendor/bundles';
require $vendorDir . '/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
$loader = new Symfony\Component\ClassLoader\ApcUniversalClassLoader('lichess.cl.');
$loader->registerNamespaces(array('Symfony' => array($vendorDir . '/symfony/src', $bundleDir), 'Doctrine\\MongoDB' => $vendorDir . '/doctrine-mongodb/lib', 'Doctrine\\ODM\\MongoDB' => $vendorDir . '/doctrine-mongodb-odm/lib', 'Doctrine\\Common\\DataFixtures' => $vendorDir . '/doctrine-data-fixtures/lib', 'Doctrine\\Common' => $vendorDir . '/doctrine-common/lib', 'Zend' => $vendorDir . '/zend-subtrees', 'Monolog' => $vendorDir . '/monolog/src', 'Assetic' => $vendorDir . '/assetic/src', 'Pagerfanta' => $vendorDir . '/pagerfanta/src', 'Gedmo' => $vendorDir . '/doctrine-extensions/lib', 'EasyCSV' => $vendorDir . '/easy-csv/lib', 'Buzz' => $vendorDir . '/buzz/lib', 'Ornicar' => $bundleDir, 'Sensio' => $bundleDir, 'WhiteOctober' => $bundleDir, 'FOS' => $bundleDir, 'Herzult' => $bundleDir, 'Bundle' => $bundleDir, 'FOQ' => $bundleDir));
$loader->registerPrefixes(array('Twig_' => $vendorDir . '/twig/lib', 'Elastica_' => $vendorDir . '/elastica/lib'));
$loader->registerPrefixFallbacks(array(__DIR__ . '/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
$loader->registerNamespaceFallbacks(array(__DIR__ . '/../src'));
$loader->register();
// doctrine annotations
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) use($loader) {
    $loader->loadClass($class);
    return class_exists($class, false);
});
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php');
Example #4
0
 private static function newConnect()
 {
     $dir = __DIR__ . '/../../libs/Doctrine/';
     $vendorPath = realpath($dir);
     $ExtensionPath = realpath($dir . '/DoctrineExtensions');
     require_once $vendorPath . '/Doctrine/Common/ClassLoader.php';
     // autoload all vendors
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\Common', $vendorPath);
     $loader->register();
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\DBAL', $vendorPath);
     $loader->register();
     $loader = new Doctrine\Common\ClassLoader('Doctrine\\ORM', $vendorPath);
     $loader->register();
     // gedmo extensions
     $loader = new Doctrine\Common\ClassLoader('Gedmo', $ExtensionPath);
     $loader->register();
     // Pagefanta
     $classLoader = new Doctrine\Common\ClassLoader("Pagerfanta", $ExtensionPath);
     $classLoader->register();
     //MYSQL Functions
     $classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', realpath($dir));
     $classLoader->register();
     // autoloader for Entity namespace
     $loader = new Doctrine\Common\ClassLoader('Entities', $dir);
     $loader->register();
     // ensure standard doctrine annotations are registered
     Doctrine\Common\Annotations\AnnotationRegistry::registerFile($vendorPath . '/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     // Second configure ORM
     // globally used cache driver
     $cache = new Doctrine\Common\Cache\ArrayCache();
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Gedmo\\Mapping\\Annotation', $ExtensionPath);
     $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array($dir . 'Entities', $ExtensionPath . '/Gedmo/Tree/Entity'));
     // drivers
     $driverChain->addDriver($annotationDriver, 'Gedmo\\Tree\\Entity');
     $driverChain->addDriver($annotationDriver, 'Entities');
     // general ORM configuration
     $config = new Doctrine\ORM\Configuration();
     //$config->setProxyDir(sys_get_temp_dir());
     $config->setProxyDir($dir . '/Proxies');
     $config->setProxyNamespace('Proxy');
     $config->setAutoGenerateProxyClasses(true);
     // this can be based on production config. FALSE
     // register metadata driver
     $config->setMetadataDriverImpl($driverChain);
     // use our allready initialized cache driver
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Third, create event manager and hook prefered extension listeners
     $evm = new Doctrine\Common\EventManager();
     // gedmo extension listeners
     // tree
     $treeListener = new Gedmo\Tree\TreeListener();
     $treeListener->setAnnotationReader($reader);
     $evm->addEventSubscriber($treeListener);
     // timestampable
     $timestampableListener = new Gedmo\Timestampable\TimestampableListener();
     $timestampableListener->setAnnotationReader($reader);
     $evm->addEventSubscriber($timestampableListener);
     // mysql set names UTF-8 if required
     $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
     // Finally, create entity manager
     $connection = array('dbname' => DB_DATABASE, 'user' => DB_USER, 'password' => DB_PASSWORD, 'host' => DB_HOST, 'driver' => 'pdo_mysql');
     $config->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\\Query\\Mysql\\Year');
     $config->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\\Query\\Mysql\\Month');
     $config->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\\Query\\Mysql\\Day');
     $config->addCustomDatetimeFunction('HOUR', 'DoctrineExtensions\\Query\\Mysql\\Hour');
     $config->addCustomDatetimeFunction('DATE', 'DoctrineExtensions\\Query\\Mysql\\Date');
     $config->addCustomDatetimeFunction('DATEDIFF', 'DoctrineExtensions\\Query\\MySql\\DateDiff');
     try {
         $em = Doctrine\ORM\EntityManager::create($connection, $config, $evm);
     } catch (Exception $e) {
     }
     self::$EntityManager = $em;
 }
Example #5
0
    /**
     * Init doctrine method
     *
     * @return Shopware\Components\Model\ModelManager
     */
    public function initModels()
    {
       /** @var $config \Doctrine\ORM\Configuration */
        $config = $this->getResource('ModelConfig');

        $cacheResource = $this->getResource('Cache');

        // Check if native Doctrine ApcCache may be used
        if ($cacheResource->getBackend() instanceof Zend_Cache_Backend_Apc) {
            $cache = new Doctrine\Common\Cache\ApcCache();
        } else {
            $cache = new Shopware\Components\Model\Cache($cacheResource);
        }

        // register standard doctrine annotations
        Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
            'Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
        );

        // register symfony validation annotions
        Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
            'Symfony\Component\Validator\Constraint'
        );

        // register gedmo annotions
        Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
            'Gedmo/Mapping/Annotation/All.php'
        );

        $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader(
            new Doctrine\Common\Annotations\AnnotationReader,
            $cache
        );

        $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
            $cachedAnnotationReader, array(
            $this->Application()->Loader()->isReadable('Gedmo/Tree/Entity/MappedSuperclass'),
            $this->Application()->AppPath('Models')
        ));

        // create a driver chain for metadata reading
        $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();

        // register annotation driver for our application
        $driverChain->addDriver($annotationDriver, 'Gedmo');
        $driverChain->addDriver($annotationDriver, 'Shopware\\Models\\');
        $driverChain->addDriver($annotationDriver, 'Shopware\\CustomModels\\');

        $this->registerResource('ModelAnnotations', $annotationDriver);

        $config->setMetadataDriverImpl($driverChain);

        // Create event Manager
        $eventManager = new \Doctrine\Common\EventManager();

        $treeListener = new Gedmo\Tree\TreeListener;
        $treeListener->setAnnotationReader($cachedAnnotationReader);
        $eventManager->addEventSubscriber($treeListener);

        // Create new shopware event subscriber to handle the entity lifecycle events.
        $liveCycleSubscriber = new \Shopware\Components\Model\EventSubscriber(
            $this->Application()->Events()
        );
        $eventManager->addEventSubscriber($liveCycleSubscriber);

        // now create the entity manager and use the connection
        // settings we defined in our application.ini
        $conn = \Doctrine\DBAL\DriverManager::getConnection(
            array('pdo' => $this->Application()->Db()->getConnection()),
            $config,
            $eventManager
        );

        $entityManager = Shopware\Components\Model\ModelManager::create($conn, $config, $eventManager);

        //if (!is_readable(rtrim($config->getProxyDir(), '/') . '/__CG__ShopwareModelsShopShop.php')) {
        //    $metadata     = $entityManager->getMetadataFactory()->getAllMetadata();
        //    $proxyFactory = $entityManager->getProxyFactory();
        //    $proxyFactory->generateProxyClasses($metadata);
        //}

        return $entityManager;
    }
Example #6
0
$loader->register();
$loader = new ClassLoader('Doctrine\\DBAL', $vendorPath . '/doctrine-dbal/lib');
$loader->register();
$loader = new ClassLoader('Doctrine\\ORM', $vendorPath . '/doctrine-orm/lib');
$loader->register();
// gedmo extensions
$loader = new ClassLoader('Gedmo', $gedmoPath);
$loader->register();
// if you use yaml, you need a yaml parser, same as command line tool
$loader = new ClassLoader('Symfony', $vendorPath);
$loader->register();
// autoloader for Entity namespace
$loader = new ClassLoader('Entity', __DIR__ . '/app');
$loader->register();
// ensure standard doctrine annotations are registered
Doctrine\Common\Annotations\AnnotationRegistry::registerFile($vendorPath . '/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Second configure ORM
// globally used cache driver, in production use APC or memcached
$cache = new Doctrine\Common\Cache\ArrayCache();
// standard annotation reader
$annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
// create a driver chain for metadata reading
$driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
// load superclass metadata mapping only, into driver chain
// also registers Gedmo annotations.NOTE: you can personalize it
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
// now we want to register our application entities,
// for that we need another metadata driver used for Entity namespace
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/app/Entity'));
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever
<?php

// Some paths
define('TESTS_BASEDIR', realpath(__DIR__));
define('LIBRARY_PATH', realpath(TESTS_BASEDIR . '/../library'));
define('VENDOR_PATH', realpath(TESTS_BASEDIR . '/../vendor'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(LIBRARY_PATH, VENDOR_PATH, get_include_path())));
// Load the Composer autoloader and point it at BedREST
require_once VENDOR_PATH . '/autoload.php';
$loader = new Composer\Autoload\ClassLoader();
$loader->add('BedRest\\TestFixtures', TESTS_BASEDIR);
$loader->add('BedRest\\Tests', TESTS_BASEDIR);
$loader->add('BedRest', LIBRARY_PATH);
$loader->register();
// register custom annotations
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/bedrest/bedrest/library/BedRest/Resource/Mapping/Annotations.php');
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/bedrest/bedrest/library/BedRest/Service/Mapping/Annotations.php');
<?php

define('TESTS_TEMP_DIR', '/tmp');
define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->add('AshleyDawson\\DoctrineGaufretteStorableBundle\\Tests', __DIR__);
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(VENDOR_PATH . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// todo: implement Mongo ODM support
//Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
//    VENDOR_PATH.'/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php'
//);
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
$_ENV['annotation_reader'] = $reader;
Example #9
0
 public function _initDoctrine()
 {
     $event = $this->profiler->startEvent('Init library: Doctrine');
     $loader = new Doctrine\Common\ClassLoader('Entity', $this->config->db->doctrine->entity);
     $loader->register();
     $loader = new Doctrine\Common\ClassLoader('EntityProxy', $this->config->db->doctrine->entityProxy);
     $loader->register();
     $config = new Doctrine\ORM\Configuration();
     $cache = new Doctrine\Common\Cache\ArrayCache();
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($this->config->db->doctrine->entityProxy);
     $config->setProxyNamespace('EntityProxy');
     $config->setAutoGenerateProxyClasses(true);
     Doctrine\Common\Annotations\AnnotationRegistry::registerFile(LIBRARY_PATH . '/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     $driver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(new Doctrine\Common\Annotations\AnnotationReader(), array($this->config->db->doctrine->entity));
     $config->setMetadataDriverImpl($driver);
     $config->setMetadataCacheImpl($cache);
     $em = Doctrine\ORM\EntityManager::create($this->config->db->params->toArray(), $config);
     Yaf\Registry::set('entityManager', $em);
     $this->profiler->endEvent($event);
 }
Example #10
0
<?php

// Some paths
define('TESTS_BASEDIR', realpath(__DIR__));
define('LIBRARY_PATH', realpath(TESTS_BASEDIR . '/../library'));
define('VENDOR_PATH', realpath(TESTS_BASEDIR . '/../vendor'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(LIBRARY_PATH, VENDOR_PATH, get_include_path())));
// Load the Composer autoloader and point it at the BedREST namespaces
require_once VENDOR_PATH . '/autoload.php';
$loader = new Composer\Autoload\ClassLoader();
$loader->add('BedRest\\TestFixtures', TESTS_BASEDIR);
$loader->add('BedRest\\Tests', TESTS_BASEDIR);
$loader->add('BedRest', LIBRARY_PATH);
$loader->register();
// register custom annotations
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(LIBRARY_PATH . '/BedRest/Resource/Mapping/Annotations.php');
Doctrine\Common\Annotations\AnnotationRegistry::registerFile(LIBRARY_PATH . '/BedRest/Service/Mapping/Annotations.php');