addGlobalIgnoredName() публичный статический Метод

Add a new annotation to the globally ignored annotation names with regard to exception handling.
public static addGlobalIgnoredName ( string $name )
$name string
 /**
  * @return AnnotationReader
  */
 public static function getAnnotationReader()
 {
     if (self::$annotationReader !== null) {
         return self::$annotationReader;
     }
     //For old AnnotationReader (<=1.2.7)
     //For new (>1.2.7) version of AnnotationReader, we can give a DocParser since a3c2928912eeb5dc5678352f22c378173def16b6
     $parser = new DocParser();
     $parser->setIgnoreNotImportedAnnotations(true);
     self::$annotationReader = new AnnotationReader($parser);
     //For old version of AnnotationReader (<=1.2.7) , we have to specify manually all ignored annotations
     foreach (self::$ignoredAnnotationNames as $ignoredAnnotationName) {
         self::$annotationReader->addGlobalIgnoredName($ignoredAnnotationName);
     }
     return self::$annotationReader;
 }
 /**
  * @DI\InjectParams({
  *     "dto" = @DI\Inject("servicedto"),
  *     "entityManager" = @DI\Inject("doctrine.orm.entity_manager"),
  *     "container" = @DI\Inject("service_container"),
  * })
  */
 public function __construct(ServiceDto $dto, EntityManager $entityManager = null, $container)
 {
     AnnotationReader::addGlobalIgnoredName('innerEntity');
     $this->setDto($dto);
     $this->container = $container;
     //Altera parâmetros da conexão
     $this->em = $entityManager;
     $this->conn = $entityManager->getConnection();
     if ($this->checkOracle()) {
         //Plataforma personalizada
         $this->platform = new SysAllOraclePlatform();
         //Schema manager personalizado
         $this->scm = new SysAllOracleSchemaManager($this->conn, $this->platform);
     } else {
         $this->scm = $this->conn->getSchemaManager();
         // $this->driver = $entityManager->getConfiguration()->getMetadataDriverImpl();
     }
     //obtém e define driver utilizado
     $this->driver = new DatabaseDriver($this->scm);
     $entityManager->getConfiguration()->setMetadataDriverImpl($this->driver);
     //realiza a reversa do banco
     $this->cmf = new DisconnectedClassMetadataFactory();
     $this->cmf->setEntityManager($entityManager);
     parent::__construct($dto, $entityManager);
 }
Пример #3
0
 public function disableValidatorAnnotationForDoctrine(Event $e)
 {
     if (class_exists('Doctrine\\Common\\Annotations\\AnnotationReader')) {
         $moduleManager = $e->getTarget();
         $config = $moduleManager->getModule('AnnotationValidator')->getConfig();
         AnnotationReader::addGlobalIgnoredName($config['validator_annotation']);
     }
 }
 /**
  * Add a new annotation to the globally ignored annotation names with regard to exception handling.
  */
 public function ignoredAnnotations()
 {
     if (isset($this->configuration['ignores'])) {
         $ignores = $this->configuration['ignores'];
         if (count($ignores)) {
             foreach ($ignores as $ignore) {
                 AnnotationReader::addGlobalIgnoredName($ignore);
             }
         }
     }
 }
 /**
  * 
  * @param array $config
  * @return AnnotationReader
  */
 public static function factory(array $config)
 {
     AnnotationRegistry::registerAutoloadNamespaces($config['namespaces']);
     $reader = new AnnotationReader();
     foreach ($config['ignored_annotations'] as $ignore) {
         $reader->addGlobalIgnoredName($ignore);
     }
     if (is_string($config['cache'])) {
         $reader = new CachedReader($reader, new FilesystemCache($config['cache'], 'cache'), $config['cache_debug']);
     }
     return $reader;
 }
Пример #6
0
 /**
  * This method will set the docblock annotations that we need Doctrine to ignore.
  *
  * @codeCoverageIgnore
  * @param ClassLoader $loader
  */
 public static function allowAnnotations($loader)
 {
     AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
     // this will keep the doctrine DocParser from throwing exceptions at our @route annotations in PropelSOA
     // enable controllers
     $reader = new AnnotationReader();
     AnnotationReader::addGlobalIgnoredName('Route');
     AnnotationReader::addGlobalIgnoredName('Method');
     AnnotationReader::addGlobalIgnoredName('route');
     AnnotationReader::addGlobalIgnoredName('QueryParameter');
     AnnotationReader::addGlobalIgnoredName('willAccept');
     AnnotationReader::addGlobalIgnoredName('wontAccept');
 }
Пример #7
0
 /**
  * [setupReaderAnnotations description]
  * @param  array $config
  * @return void
  */
 private function setupReaderAnnotations($config)
 {
     /**
      * Prepare AnnotationRegistry
      */
     AnnotationRegistry::registerFile(__DIR__ . '/../ApiRoute.php');
     AnnotationRegistry::registerFile(__DIR__ . '/../ApiRouteSpec.php');
     AnnotationReader::addGlobalIgnoredName('persistent');
     AnnotationReader::addGlobalIgnoredName('inject');
     foreach ($config['ignoreAnnotation'] as $ignore) {
         AnnotationReader::addGlobalIgnoredName($ignore);
     }
 }
Пример #8
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $reflectionReader = $builder->addDefinition($this->prefix('reflectionReader'))->setClass('Doctrine\\Common\\Annotations\\AnnotationReader')->setAutowired(FALSE);
     Validators::assertField($config, 'ignore', 'array');
     foreach ($config['ignore'] as $annotationName) {
         $reflectionReader->addSetup('addGlobalIgnoredName', array($annotationName));
         AnnotationReader::addGlobalIgnoredName($annotationName);
     }
     $builder->addDefinition($this->prefix('reader'))->setClass('Doctrine\\Common\\Annotations\\Reader')->setFactory('Doctrine\\Common\\Annotations\\CachedReader', array($this->prefix('@reflectionReader'), Helpers::processCache($this, $config['cache'], 'annotations'), $config['debug']))->setInject(FALSE);
     // for runtime
     AnnotationRegistry::registerLoader("class_exists");
 }
Пример #9
0
 /**
  * @param ClassLoader $loader
  * @param string      $apps
  * @param string      $appDir
  */
 public static function registerLoader(ClassLoader $loader, &$apps, $appDir)
 {
     foreach ($apps['apps'] as &$app) {
         $namespace = $app['namespace'] . '\\';
         $prefixes = $loader->getPrefixesPsr4();
         if (isset($prefixes[$namespace])) {
             $app['path'] = $prefixes[$namespace][0];
             continue;
         }
         $app['path'] = $loader->getPrefixesPsr4()[$namespace];
     }
     AnnotationRegistry::registerLoader([$loader, 'loadClass']);
     AnnotationReader::addGlobalIgnoredName('noinspection');
     AnnotationReader::addGlobalIgnoredName('returns');
 }
 /**
  * Creates a new entity manager instance based on the passed configuration.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface                 $application         The application instance to create the entity manager for
  * @param \AppserverIo\Appserver\Core\Api\Node\PersistenceUnitNodeInterface $persistenceUnitNode The datasource configuration
  *
  * @return object The entity manager instance
  */
 public static function factory(ApplicationInterface $application, PersistenceUnitNodeInterface $persistenceUnitNode)
 {
     // register additional annotation libraries
     foreach ($persistenceUnitNode->getAnnotationRegistries() as $annotationRegistry) {
         AnnotationRegistry::registerAutoloadNamespace($annotationRegistry->getNamespace(), $annotationRegistry->getDirectoriesAsArray($application->getWebappPath()));
     }
     // globally ignore configured annotations to ignore
     foreach ($persistenceUnitNode->getIgnoredAnnotations() as $ignoredAnnotation) {
         AnnotationReader::addGlobalIgnoredName($ignoredAnnotation->getNodeValue()->__toString());
     }
     // load the metadata configuration
     $metadataConfiguration = $persistenceUnitNode->getMetadataConfiguration();
     // prepare the setup properties
     $absolutePaths = $metadataConfiguration->getDirectoriesAsArray($application->getWebappPath());
     $proxyDir = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_PROXY_DIR);
     $isDevMode = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_IS_DEV_MODE);
     $useSimpleAnnotationReader = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_USE_SIMPLE_ANNOTATION_READER);
     // load the factory method from the available mappings
     $factoryMethod = EntityManagerFactory::$metadataMapping[$metadataConfiguration->getType()];
     // create the database configuration and initialize the entity manager
     $configuration = Setup::$factoryMethod($absolutePaths, $isDevMode, $proxyDir, null, $useSimpleAnnotationReader);
     // load the datasource node
     $datasourceNode = null;
     foreach ($application->getInitialContext()->getSystemConfiguration()->getDatasources() as $datasourceNode) {
         if ($datasourceNode->getName() === $persistenceUnitNode->getDatasource()->getName()) {
             break;
         }
     }
     // throw a exception if the configured datasource is NOT available
     if ($datasourceNode == null) {
         throw new \Exception(sprintf('Can\'t find a datasource node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // load the database node
     $databaseNode = $datasourceNode->getDatabase();
     // throw an exception if the configured database is NOT available
     if ($databaseNode == null) {
         throw new \Exception(sprintf('Can\'t find database node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // load the driver node
     $driverNode = $databaseNode->getDriver();
     // throw an exception if the configured driver is NOT available
     if ($driverNode == null) {
         throw new \Exception(sprintf('Can\'t find driver node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // initialize and return a entity manager decorator instance
     return new DoctrineEntityManagerDecorator(EntityManager::create(ConnectionUtil::get($application)->fromDatabaseNode($databaseNode), $configuration));
 }
 public function __construct(array $loaders = array(), array $globalIgnores = array())
 {
     foreach ($loaders as $loader) {
         if (is_object($loader) && method_exists($loader, 'loadClass')) {
             // support for composer/symfony's autoloader
             AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
         } elseif (is_callable($loader)) {
             AnnotationRegistry::registerLoader($loader);
         } elseif (is_array($loader) && is_string($loader[0])) {
             AnnotationRegistry::registerAutoloadNamespace($loader[0], $loader[1]);
         } elseif (is_array($loader) && is_string(key($loader))) {
             AnnotationRegistry::registerAutoloadNamespace(key($loader), reset($loader));
         } elseif (is_string($loader)) {
             AnnotationRegistry::registerFile($loader);
         } else {
             throw new \LogicException('Not a valid Annotation loader. Must be a Composer Autoloader instance, a callable, a array with namespace/path format or a string with path to a register file');
         }
     }
     foreach ($globalIgnores as $annotation) {
         AnnotationReader::addGlobalIgnoredName($annotation);
     }
 }
Пример #12
0
 /**
  * Dispatch a remote method call.
  * 
  * @param  Hatimeria\ExtJSBundle\Router\Call $call
  * @return Mixed
  */
 private function dispatch($call)
 {
     $controller = $this->resolveController($call->getAction());
     $method = $call->getMethod() . "Action";
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName("remote");
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName("form");
     $event = new FilterControllerEvent($this->container->get("kernel"), array($controller, $method), $this->container->get('request'), 'GET');
     $listener = $this->container->get("security.extra.controller_listener");
     $listener->onCoreController($event);
     $controller = $event->getController();
     if (!is_callable($controller)) {
         throw new ExtJSException(sprintf("Controller %s method %s is not callable", get_class($controller), $method));
     }
     try {
         if ($controller instanceof \Closure) {
             $response = $controller($call->getParams(), $this->request->getFiles());
         } else {
             $response = $controller[0]->{$method}($call->getParams(), $this->request->getFiles());
         }
         // default behavior - everything went fine
         if ($response == null) {
             $response = new Success();
         }
         if (is_object($response)) {
             if ($response instanceof ResponseInterface) {
                 $response = $response->toArray();
             } else {
                 $response = $this->container->get('hatimeria_extjs.dumper')->dump($response)->toArray();
             }
         }
         $result = $call->getResponse($response);
     } catch (NotFoundHttpException $e) {
         $result = $call->getResponse(array('success' => false, 'exception' => true, 'code' => $e->getStatusCode(), 'msg' => $e->getMessage()));
     } catch (AccessDeniedException $e) {
         $result = $call->getResponse(array('success' => false, 'exception' => true, 'code' => $e->getCode(), 'msg' => $e->getMessage(), 'anonymous' => $this->container->get('security.context')->getToken() instanceof AnonymousToken));
     }
     return $result;
 }
Пример #13
0
 /**
  * Gibt einen neuen SimpleAnnotationReader zurück
  *
  * der Namespace Doctrine\ORM\Mapping wird automatisch hinzugefügt
  * es wird der interne Cache benutzt
  * @return Doctrine\Common\Annotations\SimpleAnnotationReader()
  */
 public function createAnnotationReader($simple = TRUE, array $ignoredAnnotations = array())
 {
     if ($simple) {
         $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
         $reader->addNamespace('Doctrine\\ORM\\Mapping');
     } else {
         $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     }
     foreach ($ignoredAnnotations as $ignore) {
         $reader->addGlobalIgnoredName($ignore);
     }
     $reader = new \Doctrine\Common\Annotations\CachedReader($reader, $this->getCache());
     return $reader;
 }
Пример #14
0
 /**
  * Lädt alle für Doctrine wichtigen Klassen und Objekte
  * 
  */
 public function bootstrap($bootFlags = 0x0)
 {
     if (!isset($this->configuration)) {
         $this->configuration = new Configuration();
     }
     /* Custom Functions */
     $this->configuration->addCustomDatetimeFunction('month', 'Psc\\Doctrine\\Functions\\Month');
     $this->configuration->addCustomDatetimeFunction('year', 'Psc\\Doctrine\\Functions\\Year');
     $this->configuration->addCustomDatetimeFunction('day', 'Psc\\Doctrine\\Functions\\Day');
     $this->configuration->addCustomStringFunction('soundex', 'Psc\\Doctrine\\Functions\\Soundex');
     /* Annotations */
     // Register the ORM Annotations in the AnnotationRegistry
     AnnotationRegistry::registerFile($this->project->dir('vendor')->getFile('doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'));
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('chainable');
     if (!isset($this->driverChain)) {
         $this->driverChain = new MappingDriverChain();
     }
     $this->driverChain->addDriver($this->getAnnotationDriver(), $this->entitiesNamespace);
     $this->configuration->setMetadataDriverImpl($this->driverChain);
     // Metadatadriver für einzelne Entities
     $this->registerEntityClassesMetadataDriver(array(), 'Psc', $this->getDefaultAnnotationReader());
     /* Ci-Ca-Caches */
     if (($cache = $this->project->getConfiguration()->get('doctrine.cache')) != NULL) {
         $this->useCache($cache);
     }
     $this->configuration->setMetadataCacheImpl($this->getCache());
     $this->configuration->setQueryCacheImpl($this->getCache());
     $this->configuration->setResultCacheImpl($this->getResultCache());
     // das ist wichtig, damit dieselben abfragen pro result gecached werden
     $this->configuration->setProxyDir($this->project->dir('cache')->sub('Proxies/')->create());
     $this->configuration->setProxyNamespace('Proxies');
     $this->configuration->setAutoGenerateProxyClasses(TRUE);
     $this->registerDefaultTypes();
     $this->registerCustomTypes();
     $this->dispatchBootstrapped();
     return $this;
 }
Пример #15
0
 /**
  * Initializes the application instance.
  *
  * This method
  * starts the session,
  * call Slim constructor,
  * set the custom log writer (if is defined in config),
  * bootstraps the Doctrine,
  * bootstraps the Auth Manager,
  * creates the cache and rcache components,
  * sets the file storage,
  * adds midlewares,
  * instantiates the Route Manager and
  * includes the theme.php file of the active theme if the file exists.
  *
  *
  * If the application was previously initiated, this method returns the application in the first line.
  *
  * @return \MapasCulturais\App
  */
 public function init($config = array())
 {
     if ($this->_initiated) {
         return $this;
     }
     $this->_initiated = true;
     if ($config['slim.debug']) {
         error_reporting(E_ALL ^ E_STRICT);
     }
     session_start();
     $config['app.mode'] = key_exists('app.mode', $config) ? $config['app.mode'] : 'production';
     $this->_config = $config;
     $this->_config['path.layouts'] = APPLICATION_PATH . 'themes/active/layouts/';
     $this->_config['path.templates'] = APPLICATION_PATH . 'themes/active/views/';
     $this->_config['path.metadata_inputs'] = APPLICATION_PATH . 'themes/active/metadata-inputs/';
     if (!key_exists('app.sanitize_filename_function', $this->_config)) {
         $this->_config['app.sanitize_filename_function'] = null;
     }
     parent::__construct(array('log.level' => $config['slim.log.level'], 'log.enabled' => $config['slim.log.enabled'], 'debug' => $config['slim.debug'], 'templates.path' => $this->_config['path.templates'], 'view' => new View(), 'mode' => $this->_config['app.mode']));
     $config = $this->_config;
     // custom log writer
     if (isset($config['slim.log.writer']) && is_object($config['slim.log.writer']) && method_exists($config['slim.log.writer'], 'write')) {
         $log = $this->getLog();
         $log->setWriter($config['slim.log.writer']);
     }
     // =============== CACHE =============== //
     if (key_exists('app.cache', $config) && is_object($config['app.cache']) && is_subclass_of($config['app.cache'], '\\Doctrine\\Common\\Cache\\CacheProvider')) {
         $this->_cache = $config['app.cache'];
     } else {
         $this->_cache = new \Doctrine\Common\Cache\ArrayCache();
     }
     // creates runtime cache component
     $this->_rcache = new \Doctrine\Common\Cache\ArrayCache();
     // ===================================== //
     // ========== BOOTSTRAPING DOCTRINE ========== //
     // annotation driver
     $doctrine_config = Setup::createConfiguration($config['doctrine.isDev']);
     $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
     $classLoader->register();
     $driver = new AnnotationDriver(new AnnotationReader());
     $driver->addPaths(array(__DIR__ . '/Entities/'));
     // tells the doctrine to ignore hook annotation.
     AnnotationReader::addGlobalIgnoredName('hook');
     // driver must be pdo_pgsql
     $config['doctrine.database']['driver'] = 'pdo_pgsql';
     // registering noop annotation autoloader - allow all annotations by default
     AnnotationRegistry::registerLoader('class_exists');
     $doctrine_config->setMetadataDriverImpl($driver);
     $proxy_dir = APPLICATION_PATH . 'lib/MapasCulturais/DoctrineProxies';
     $proxy_namespace = 'MapasCulturais\\DoctrineProxies';
     $doctrine_config->setProxyDir($proxy_dir);
     $doctrine_config->setProxyNamespace($proxy_namespace);
     \Doctrine\ORM\Proxy\Autoloader::register($proxy_dir, $proxy_namespace);
     /** DOCTRINE2 SPATIAL */
     $doctrine_config->addCustomStringFunction('st_asbinary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsBinary');
     $doctrine_config->addCustomStringFunction('st_astext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsText');
     $doctrine_config->addCustomNumericFunction('st_area', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STArea');
     $doctrine_config->addCustomStringFunction('st_centroid', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCentroid');
     $doctrine_config->addCustomStringFunction('st_closestpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STClosestPoint');
     $doctrine_config->addCustomNumericFunction('st_contains', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContains');
     $doctrine_config->addCustomNumericFunction('st_containsproperly', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContainsProperly');
     $doctrine_config->addCustomNumericFunction('st_covers', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCovers');
     $doctrine_config->addCustomNumericFunction('st_coveredby', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCoveredBy');
     $doctrine_config->addCustomNumericFunction('st_crosses', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCrosses');
     $doctrine_config->addCustomNumericFunction('st_disjoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDisjoint');
     $doctrine_config->addCustomNumericFunction('st_distance', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDistance');
     $doctrine_config->addCustomStringFunction('st_envelope', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STEnvelope');
     $doctrine_config->addCustomStringFunction('st_geomfromtext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STGeomFromText');
     $doctrine_config->addCustomNumericFunction('st_length', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLength');
     $doctrine_config->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLineCrossingDirection');
     $doctrine_config->addCustomStringFunction('st_startpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STStartPoint');
     $doctrine_config->addCustomStringFunction('st_summary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STSummary');
     $doctrine_config->addCustomStringFunction('string_agg', 'MapasCulturais\\DoctrineMappings\\Functions\\StringAgg');
     $doctrine_config->addCustomStringFunction('unaccent', 'MapasCulturais\\DoctrineMappings\\Functions\\Unaccent');
     $doctrine_config->addCustomStringFunction('recurring_event_occurrence_for', 'MapasCulturais\\DoctrineMappings\\Functions\\RecurringEventOcurrenceFor');
     $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\\DoctrineMappings\\Functions\\STDWithin');
     $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\\DoctrineMappings\\Functions\\STMakePoint');
     $doctrine_config->setQueryCacheImpl($this->_cache);
     // obtaining the entity manager
     $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config);
     \MapasCulturais\DoctrineMappings\Types\Frequency::register();
     \MapasCulturais\DoctrineMappings\Types\Point::register();
     \MapasCulturais\DoctrineMappings\Types\Geography::register();
     \MapasCulturais\DoctrineMappings\Types\Geometry::register();
     if (@$config['app.log.query']) {
         $doctrine_config->setSQLLogger($config['app.queryLogger']);
     }
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'geography');
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'geometry');
     // ============= STORAGE =============== //
     if (key_exists('storage.driver', $config) && class_exists($config['storage.driver']) && is_subclass_of($config['storage.driver'], '\\MapasCulturais\\Storage')) {
         $storage_class = $config['storage.driver'];
         $this->_storage = key_exists('storage.config', $config) ? $storage_class::i($config['storage.config']) : $storage_class::i();
     } else {
         $this->_storage = \MapasCulturais\Storage\FileSystem::i();
     }
     // ===================================== //
     // add middlewares
     if (is_array($config['slim.middlewares'])) {
         foreach ($config['slim.middlewares'] as $middleware) {
             $this->add($middleware);
         }
     }
     // instantiate the route manager
     $this->_routesManager = new RoutesManager(key_exists('routes', $config) ? $config['routes'] : array());
     $this->applyHookBoundTo($this, 'mapasculturais.init');
     $this->register();
     // =============== AUTH ============== //
     $auth_class_name = $config['auth.provider'][0] === '\\' ? $config['auth.provider'] : 'MapasCulturais\\AuthProviders\\' . $config['auth.provider'];
     $this->_auth = new $auth_class_name($config['auth.config']);
     $this->_auth->setCookies();
     // run theme theme.php
     if (file_exists(ACTIVE_THEME_PATH . 'theme.php')) {
         include ACTIVE_THEME_PATH . 'theme.php';
     }
     // ===================================== //
     // run plugins
     foreach ($config['plugins.enabled'] as $plugin) {
         include PLUGINS_PATH . $plugin . '.php';
     }
     // ===================================== //
     if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) {
         $this->_dbUpdates();
     }
     return $this;
 }
Пример #16
0
 /**
  * Initializes the application instance.
  *
  * This method
  * starts the session,
  * call Slim constructor,
  * set the custom log writer (if is defined in config),
  * bootstraps the Doctrine,
  * bootstraps the Auth Manager,
  * creates the cache and rcache components,
  * sets the file storage,
  * adds midlewares,
  * instantiates the Route Manager and
  * includes the theme.php file of the active theme if the file exists.
  *
  *
  * If the application was previously initiated, this method returns the application in the first line.
  *
  * @return \MapasCulturais\App
  */
 public function init($config = [])
 {
     if ($this->_initiated) {
         return $this;
     }
     $this->_initiated = true;
     if ($config['slim.debug']) {
         error_reporting(E_ALL ^ E_STRICT);
     }
     session_start();
     if ($config['app.offline']) {
         $bypass_callable = $config['app.offlineBypassFunction'];
         if (!is_callable($bypass_callable) || !$bypass_callable()) {
             http_response_code(307);
             header('Location: ' . $config['app.offlineUrl']);
         }
     }
     // =============== CACHE =============== //
     if (key_exists('app.cache', $config) && is_object($config['app.cache']) && is_subclass_of($config['app.cache'], '\\Doctrine\\Common\\Cache\\CacheProvider')) {
         $this->_cache = $config['app.cache'];
     } else {
         $this->_cache = new \Doctrine\Common\Cache\ArrayCache();
     }
     $this->_cache->setNamespace($config['app.cache.namespace']);
     spl_autoload_register(function ($class) use($config) {
         $cache_id = "AUTOLOAD_CLASS:{$class}";
         if ($config['app.useRegisteredAutoloadCache'] && $this->cache->contains($cache_id)) {
             $path = $this->cache->fetch($cache_id);
             require_once $path;
             return true;
         }
         foreach ($config['namespaces'] as $namespace => $base_dir) {
             if (strpos($class, $namespace) === 0) {
                 $path = str_replace('\\', '/', str_replace($namespace, $base_dir, $class) . '.php');
                 if (\file_exists($path)) {
                     require_once $path;
                     if ($config['app.useRegisteredAutoloadCache']) {
                         $this->cache->save($cache_id, $path, $config['app.registeredAutoloadCache.lifetime']);
                     }
                     return true;
                 }
             }
         }
     });
     // extende a config with theme config files
     $theme_class = "\\" . $config['themes.active'] . '\\Theme';
     $theme_path = $theme_class::getThemeFolder() . '/';
     if (file_exists($theme_path . 'conf-base.php')) {
         $theme_config = (require $theme_path . 'conf-base.php');
         $config = array_merge($config, $theme_config);
     }
     if (file_exists($theme_path . 'config.php')) {
         $theme_config = (require $theme_path . 'config.php');
         $config = array_merge($config, $theme_config);
     }
     $config['app.mode'] = key_exists('app.mode', $config) ? $config['app.mode'] : 'production';
     $this->_config = $config;
     $this->_config['path.layouts'] = APPLICATION_PATH . 'themes/active/layouts/';
     $this->_config['path.templates'] = APPLICATION_PATH . 'themes/active/views/';
     $this->_config['path.metadata_inputs'] = APPLICATION_PATH . 'themes/active/metadata-inputs/';
     if (!key_exists('app.sanitize_filename_function', $this->_config)) {
         $this->_config['app.sanitize_filename_function'] = null;
     }
     $theme_class = $config['themes.active'] . '\\Theme';
     parent::__construct(['log.level' => $config['slim.log.level'], 'log.enabled' => $config['slim.log.enabled'], 'debug' => $config['slim.debug'], 'templates.path' => $this->_config['path.templates'], 'view' => new $theme_class($config['themes.assetManager']), 'mode' => $this->_config['app.mode']]);
     $config = $this->_config;
     // custom log writer
     if (isset($config['slim.log.writer']) && is_object($config['slim.log.writer']) && method_exists($config['slim.log.writer'], 'write')) {
         $log = $this->getLog();
         $log->setWriter($config['slim.log.writer']);
     }
     // creates runtime cache component
     $this->_rcache = new \Doctrine\Common\Cache\ArrayCache();
     // ===================================== //
     // ========== BOOTSTRAPING DOCTRINE ========== //
     // annotation driver
     $doctrine_config = Setup::createConfiguration($config['doctrine.isDev']);
     $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
     $classLoader->register();
     $driver = new AnnotationDriver(new AnnotationReader());
     $driver->addPaths([__DIR__ . '/Entities/']);
     // tells the doctrine to ignore hook annotation.
     AnnotationReader::addGlobalIgnoredName('hook');
     // driver must be pdo_pgsql
     $config['doctrine.database']['driver'] = 'pdo_pgsql';
     // registering noop annotation autoloader - allow all annotations by default
     AnnotationRegistry::registerLoader('class_exists');
     $doctrine_config->setMetadataDriverImpl($driver);
     $proxy_dir = APPLICATION_PATH . 'lib/MapasCulturais/DoctrineProxies';
     $proxy_namespace = 'MapasCulturais\\DoctrineProxies';
     $doctrine_config->setProxyDir($proxy_dir);
     $doctrine_config->setProxyNamespace($proxy_namespace);
     \Doctrine\ORM\Proxy\Autoloader::register($proxy_dir, $proxy_namespace);
     /** DOCTRINE2 SPATIAL */
     $doctrine_config->addCustomStringFunction('st_asbinary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsBinary');
     $doctrine_config->addCustomStringFunction('st_astext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsText');
     $doctrine_config->addCustomNumericFunction('st_area', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STArea');
     $doctrine_config->addCustomStringFunction('st_centroid', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCentroid');
     $doctrine_config->addCustomStringFunction('st_closestpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STClosestPoint');
     $doctrine_config->addCustomNumericFunction('st_contains', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContains');
     $doctrine_config->addCustomNumericFunction('st_containsproperly', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContainsProperly');
     $doctrine_config->addCustomNumericFunction('st_covers', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCovers');
     $doctrine_config->addCustomNumericFunction('st_coveredby', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCoveredBy');
     $doctrine_config->addCustomNumericFunction('st_crosses', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCrosses');
     $doctrine_config->addCustomNumericFunction('st_disjoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDisjoint');
     $doctrine_config->addCustomNumericFunction('st_distance', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDistance');
     $doctrine_config->addCustomStringFunction('st_envelope', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STEnvelope');
     $doctrine_config->addCustomStringFunction('st_geomfromtext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STGeomFromText');
     $doctrine_config->addCustomNumericFunction('st_length', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLength');
     $doctrine_config->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLineCrossingDirection');
     $doctrine_config->addCustomStringFunction('st_startpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STStartPoint');
     $doctrine_config->addCustomStringFunction('st_summary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STSummary');
     $doctrine_config->addCustomStringFunction('string_agg', 'MapasCulturais\\DoctrineMappings\\Functions\\StringAgg');
     $doctrine_config->addCustomStringFunction('unaccent', 'MapasCulturais\\DoctrineMappings\\Functions\\Unaccent');
     $doctrine_config->addCustomStringFunction('recurring_event_occurrence_for', 'MapasCulturais\\DoctrineMappings\\Functions\\RecurringEventOcurrenceFor');
     $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\\DoctrineMappings\\Functions\\STDWithin');
     $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\\DoctrineMappings\\Functions\\STMakePoint');
     $doctrine_config->setMetadataCacheImpl($this->_cache);
     $doctrine_config->setQueryCacheImpl($this->_cache);
     $doctrine_config->setResultCacheImpl($this->_cache);
     // obtaining the entity manager
     $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config);
     \MapasCulturais\DoctrineMappings\Types\Frequency::register();
     \MapasCulturais\DoctrineMappings\Types\Point::register();
     \MapasCulturais\DoctrineMappings\Types\Geography::register();
     \MapasCulturais\DoctrineMappings\Types\Geometry::register();
     if (@$config['app.log.query']) {
         $doctrine_config->setSQLLogger($config['app.queryLogger']);
     }
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'geography');
     $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'geometry');
     // ============= STORAGE =============== //
     if (key_exists('storage.driver', $config) && class_exists($config['storage.driver']) && is_subclass_of($config['storage.driver'], '\\MapasCulturais\\Storage')) {
         $storage_class = $config['storage.driver'];
         $this->_storage = key_exists('storage.config', $config) ? $storage_class::i($config['storage.config']) : $storage_class::i();
     } else {
         $this->_storage = \MapasCulturais\Storage\FileSystem::i();
     }
     // ===================================== //
     // add middlewares
     if (is_array($config['slim.middlewares'])) {
         foreach ($config['slim.middlewares'] as $middleware) {
             $this->add($middleware);
         }
     }
     // instantiate the route manager
     $this->_routesManager = new RoutesManager(key_exists('routes', $config) ? $config['routes'] : []);
     $this->applyHookBoundTo($this, 'mapasculturais.init');
     $this->register();
     // =============== AUTH ============== //
     if ($token = $this->request()->headers->get('authorization')) {
         $this->_auth = new AuthProviders\JWT(['token' => $token]);
     } else {
         $auth_class_name = strpos($config['auth.provider'], '\\') !== false ? $config['auth.provider'] : 'MapasCulturais\\AuthProviders\\' . $config['auth.provider'];
         $this->_auth = new $auth_class_name($config['auth.config']);
         $this->_auth->setCookies();
     }
     // initialize theme
     $this->view->init();
     // ===================================== //
     // run plugins
     foreach ($config['plugins.enabled'] as $plugin) {
         include PLUGINS_PATH . $plugin . '.php';
     }
     // ===================================== //
     if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) {
         $this->_dbUpdates();
     }
     return $this;
 }
Пример #17
0
<?php

/*
 * This file is part of the SDK package.
 *
 * (c) PHPPRO <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @var \Composer\Autoload\ClassLoader $loader
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('group');
return $loader;
<?php

use Ray\Di\Injector;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use KumamidoriSnippet\UserRegistration\Module\AppModule;
load:
/* @var $loader \Composer\Autoload\ClassLoader */
$loader = (require __DIR__ . '/vendor/autoload.php');
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
AnnotationReader::addGlobalIgnoredName('visible');
$entityManager = (new Injector(new AppModule()))->getInstance(EntityManagerInterface::class);
return ConsoleRunner::createHelperSet($entityManager);
Пример #19
0
<?php

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
 * @var ClassLoader
 */
$loader = (require __DIR__ . '/../vendor/autoload.php');
// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__ . '/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationReader::addGlobalIgnoredName('type');
return $loader;
Пример #20
0
 public function __construct()
 {
     AnnotationRegistry::registerLoader("class_exists");
     $this->annotationReader = new AnnotationReader();
     $this->annotationReader->addGlobalIgnoredName('inject');
 }
Пример #21
0
<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;
$loader = (include __DIR__ . '/../vendor/autoload.php');
// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__ . '/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
    $loader->add('', __DIR__ . '/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
# ignore api flag
AnnotationReader::addGlobalIgnoredName('api');
# ignore behat mink annotations
AnnotationReader::addGlobalIgnoredName('BeforeScenario');
AnnotationReader::addGlobalIgnoredName('Given');
AnnotationReader::addGlobalIgnoredName('When');
AnnotationReader::addGlobalIgnoredName('Then');
AnnotationReader::addGlobalIgnoredName('BeforeSuite');
AnnotationReader::addGlobalIgnoredName('AfterScenario');
return $loader;
 /**
  * Register globally ignored annotations
  */
 protected function registerGlobalIgnoredAnnotations()
 {
     // There is a bug in the Doctrine annotation DocParser class.
     // If there's a class named the same as an annotation, an exeption will be raised.
     // In the case of Concrete5 this is the \@package annotaton. Even though
     // the addGlobalIgnoredName is set the exception is still thrown.
     // http://stackoverflow.com/questions/21609571/swagger-php-and-doctrine-annotation-issue
     // Solution 1: Add this fix to \Doctrine\Common\Annotations\DocParser and customize other Classes
     // https://github.com/bfanger/annotations/commit/1dfb5073061d3fe856c3b138286aa4c75120fcd3
     // Solution 2: Comment all [at]package annotation found in concrete/src with a backslash. Example \@package
     // The annotations added to the global ignored namespace are still valid for the simple annotation reader
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('subpackages');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('package');
     // Default Doctrine annotations
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Column');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('ColumnResult');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Cache');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('ChangeTrackingPolicy');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('DiscriminatorColumn');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('DiscriminatorMap');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Entity');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('EntityResult');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('FieldResult');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('GeneratedValue');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('HasLifecycleCallbacks');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Id');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('InheritanceType');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('JoinColumn');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('JoinColumns');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('JoinTable');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('ManyToOne');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('ManyToMany');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('MappedSuperclass');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('NamedNativeQuery');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('OneToOne');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('OneToMany');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('OrderBy');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PostLoad');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PostPersist');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PostRemove');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PostUpdate');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PrePersist');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PreRemove');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('PreUpdate');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SequenceGenerator');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('SqlResultSetMapping');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Table');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('UniqueConstraint');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Version');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Embeddable');
     \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('Embedded');
 }
 public function createEntityManager()
 {
     // retrieve parameters for connection
     $params = array();
     foreach ($GLOBALS as $key => $value) {
         if (0 === strpos($key, 'jackalope.doctrine.dbal.')) {
             $params[substr($key, strlen('jackalope.doctrine.dbal.'))] = $value;
         }
     }
     $config = Setup::createConfiguration(true);
     $reader = new AnnotationReader();
     $reader->addGlobalIgnoredName('group');
     if (empty($paths)) {
         $paths = array(__DIR__ . "/../../../Models");
     }
     $metaDriver = new OrmAnnotationDriver($reader, $paths);
     $config->setMetadataDriverImpl($metaDriver);
     // obtaining the entity manager
     $this->connection = DriverManager::getConnection($params);
     $eventManager = new EventManager();
     $this->em = EntityManager::create($params, $config, $eventManager);
 }
Пример #24
0
 /**
  * Initializes this service.
  *
  * This method must be run only after all dependencies have been injected.
  *
  * @param \TYPO3\FLOW3\Core\Bootstrap $bootstrap
  * @return void
  */
 public function initialize(\TYPO3\FLOW3\Core\Bootstrap $bootstrap)
 {
     $this->context = $bootstrap->getContext();
     if ($this->context->isProduction() && $this->reflectionDataRuntimeCache->getBackend()->isFrozen()) {
         $this->classReflectionData = $this->reflectionDataRuntimeCache->get('__classNames');
         $this->annotatedClasses = $this->reflectionDataRuntimeCache->get('__annotatedClasses');
         $this->loadFromClassSchemaRuntimeCache = TRUE;
     } else {
         $this->loadClassReflectionCompiletimeCache();
     }
     $this->annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
     foreach ($this->settings['reflection']['ignoredTags'] as $tag) {
         \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName($tag);
     }
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($this->classLoader, 'loadClass'));
 }
Пример #25
0
 /**
  * Initialize the reflection service lazily
  *
  * This method must be run only after all dependencies have been injected.
  *
  * @return void
  */
 protected function initialize()
 {
     $this->context = $this->environment->getContext();
     if ($this->context->isProduction() && $this->reflectionDataRuntimeCache->getBackend()->isFrozen()) {
         $this->classReflectionData = $this->reflectionDataRuntimeCache->get('__classNames');
         $this->annotatedClasses = $this->reflectionDataRuntimeCache->get('__annotatedClasses');
         $this->loadFromClassSchemaRuntimeCache = TRUE;
     } else {
         $this->loadClassReflectionCompiletimeCache();
     }
     $this->annotationReader = new AnnotationReader();
     foreach ($this->settings['reflection']['ignoredTags'] as $tag) {
         AnnotationReader::addGlobalIgnoredName($tag);
     }
     AnnotationRegistry::registerLoader(array($this->classLoader, 'loadClass'));
     $this->initialized = TRUE;
 }
 /**
  * Creates a new entity manager instance based on the passed configuration.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface                 $application         The application instance to create the entity manager for
  * @param \AppserverIo\Appserver\Core\Api\Node\PersistenceUnitNodeInterface $persistenceUnitNode The datasource configuration
  *
  * @return object The entity manager instance
  */
 public static function factory(ApplicationInterface $application, PersistenceUnitNodeInterface $persistenceUnitNode)
 {
     // register additional annotation libraries
     foreach ($persistenceUnitNode->getAnnotationRegistries() as $annotationRegistry) {
         AnnotationRegistry::registerAutoloadNamespace($annotationRegistry->getNamespace(), $annotationRegistry->getDirectoriesAsArray($application->getWebappPath()));
     }
     // globally ignore configured annotations to ignore
     foreach ($persistenceUnitNode->getIgnoredAnnotations() as $ignoredAnnotation) {
         AnnotationReader::addGlobalIgnoredName($ignoredAnnotation->getNodeValue()->__toString());
     }
     // load the metadata configuration
     $metadataConfiguration = $persistenceUnitNode->getMetadataConfiguration();
     // prepare the setup properties
     $absolutePaths = $metadataConfiguration->getDirectoriesAsArray($application->getWebappPath());
     $proxyDir = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_PROXY_DIR);
     $isDevMode = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_IS_DEV_MODE);
     $useSimpleAnnotationReader = $metadataConfiguration->getParam(MetadataConfigurationNode::PARAM_USE_SIMPLE_ANNOTATION_READER);
     // load the factory method from the available mappings
     $factoryMethod = EntityManagerFactory::$metadataMapping[$metadataConfiguration->getType()];
     // create the database configuration and initialize the entity manager
     $configuration = Setup::$factoryMethod($absolutePaths, $isDevMode, $proxyDir, null, $useSimpleAnnotationReader);
     // load the datasource node
     $datasourceNode = null;
     foreach ($application->getInitialContext()->getSystemConfiguration()->getDatasources() as $datasourceNode) {
         if ($datasourceNode->getName() === $persistenceUnitNode->getDatasource()->getName()) {
             break;
         }
     }
     // throw a exception if the configured datasource is NOT available
     if ($datasourceNode == null) {
         throw new \Exception(sprintf('Can\'t find a datasource node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // load the database node
     $databaseNode = $datasourceNode->getDatabase();
     // throw an exception if the configured database is NOT available
     if ($databaseNode == null) {
         throw new \Exception(sprintf('Can\'t find database node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // load the driver node
     $driverNode = $databaseNode->getDriver();
     // throw an exception if the configured driver is NOT available
     if ($driverNode == null) {
         throw new \Exception(sprintf('Can\'t find driver node for persistence unit %s', $persistenceUnitNode->getName()));
     }
     // initialize the connection parameters with the mandatory driver
     $connectionParameters = array('driver' => $databaseNode->getDriver()->getNodeValue()->__toString());
     // initialize the path/memory to the database when we use sqlite for example
     if ($pathNode = $databaseNode->getPath()) {
         $connectionParameters['path'] = $application->getWebappPath() . DIRECTORY_SEPARATOR . $pathNode->getNodeValue()->__toString();
     } elseif ($memoryNode = $databaseNode->getMemory()) {
         $connectionParameters['memory'] = Boolean::valueOf(new String($memoryNode->getNodeValue()->__toString()))->booleanValue();
     } else {
         // do nothing here, because there is NO option
     }
     // add username, if specified
     if ($userNode = $databaseNode->getUser()) {
         $connectionParameters['user'] = $userNode->getNodeValue()->__toString();
     }
     // add password, if specified
     if ($passwordNode = $databaseNode->getPassword()) {
         $connectionParameters['password'] = $passwordNode->getNodeValue()->__toString();
     }
     // add database name if using another PDO driver than sqlite
     if ($databaseNameNode = $databaseNode->getDatabaseName()) {
         $connectionParameters['dbname'] = $databaseNameNode->getNodeValue()->__toString();
     }
     // add database host if using another PDO driver than sqlite
     if ($databaseHostNode = $databaseNode->getDatabaseHost()) {
         $connectionParameters['host'] = $databaseHostNode->getNodeValue()->__toString();
     }
     // add database port if using another PDO driver than sqlite
     if ($databasePortNode = $databaseNode->getDatabasePort()) {
         $connectionParameters['port'] = $databasePortNode->getNodeValue()->__toString();
     }
     // add charset, if specified
     if ($charsetNode = $databaseNode->getCharset()) {
         $connectionParameters['charset'] = $charsetNode->getNodeValue()->__toString();
     }
     // add driver options, if specified
     if ($driverOptionsNode = $databaseNode->getDriverOptions()) {
         // explode the raw options separated with a semicolon
         $rawOptions = explode(';', $driverOptionsNode->getNodeValue()->__toString());
         // prepare the array with the driver options key/value pair (separated with a =)
         $options = array();
         foreach ($rawOptions as $rawOption) {
             list($key, $value) = explode('=', $rawOption);
             $options[$key] = $value;
         }
         // set the driver options
         $connectionParameters['driverOptions'] = $options;
     }
     // add driver options, if specified
     if ($unixSocketNode = $databaseNode->getUnixSocket()) {
         $connectionParameters['unix_socket'] = $unixSocketNode->getNodeValue()->__toString();
     }
     // initialize and return a entity manager decorator instance
     return new DoctrineEntityManagerDecorator(EntityManager::create($connectionParameters, $configuration));
 }
Пример #27
0
 public function loadConfiguration()
 {
     AnnotationRegistry::registerLoader("class_exists");
     AnnotationReader::addGlobalIgnoredName('persistent');
 }
Пример #28
0
<?php

namespace Helloworld;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;
$packageDir = dirname(dirname(dirname(__DIR__)));
// Auto loader
require_once $packageDir . '/vendor/autoload.php';
// Annotation auto loader
AnnotationRegistry::registerAutoloadNamespace(__NAMESPACE__ . '\\Annotation\\', dirname(__DIR__));
AnnotationRegistry::registerAutoloadNamespace('Ray\\Di\\Di\\', $packageDir . '/vendor/ray/di/src/');
AnnotationRegistry::registerAutoloadNamespace('BEAR\\Resource\\Annotation\\', $packageDir . '/vendor/bear/resource/src/');
AnnotationRegistry::registerAutoloadNamespace('BEAR\\Sunday\\Annotation\\', $packageDir . '/vendor/bear/sunday/src/');
AnnotationReader::addGlobalIgnoredName('noinspection');
AnnotationReader::addGlobalIgnoredName('returns');
// for Mr.Smarty. :(
unset($packageDir);
 /**
  * Initialize the reflection service lazily
  *
  * This method must be run only after all dependencies have been injected.
  *
  * @return void
  */
 protected function initialize()
 {
     $this->context = $this->environment->getContext();
     if ($this->hasFrozenCacheInProduction()) {
         $this->classReflectionData = $this->reflectionDataRuntimeCache->get('__classNames');
         $this->annotatedClasses = $this->reflectionDataRuntimeCache->get('__annotatedClasses');
         $this->loadFromClassSchemaRuntimeCache = true;
     } else {
         $this->loadClassReflectionCompiletimeCache();
     }
     $this->annotationReader = new AnnotationReader();
     foreach ($this->settings['reflection']['ignoredTags'] as $tagName => $ignoreFlag) {
         // Make this setting backwards compatible with old array schema (deprecated since 3.0)
         if (is_numeric($tagName) && is_string($ignoreFlag)) {
             AnnotationReader::addGlobalIgnoredName($ignoreFlag);
         }
         if ($ignoreFlag === true) {
             AnnotationReader::addGlobalIgnoredName($tagName);
         }
     }
     $this->initialized = true;
 }
Пример #30
0
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationRegistry;
$apiClassLoader = new \Doctrine\Common\ClassLoader('Application', __DIR__ . '/module/Application/src');
$apiClassLoader->register();
$coreClassLoader = new \Doctrine\Common\ClassLoader('Core', __DIR__ . '/module/Core/src');
$coreClassLoader->register();
$adminClassLoader = new \Doctrine\Common\ClassLoader('Admin', __DIR__ . '/module/Admin/src');
$adminClassLoader->register();
$entityClassLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__ . '/module/Application/src/Application/Entity');
$entityClassLoader->register();
$proxyClassLoader = new \Doctrine\Common\ClassLoader('EntityProxy', __DIR__ . '/module/Application/src/Application/Entity/Proxies');
$proxyClassLoader->register();
$config = (include __DIR__ . '/config/autoload/global.php');
$cache = new $config['doctrine']['driver']['cache']();
$doctrineConfig = new \Doctrine\ORM\Configuration();
$cache = new $config['doctrine']['driver']['cache']();
$doctrineConfig->setQueryCacheImpl($cache);
$doctrineConfig->setProxyDir('/tmp');
$doctrineConfig->setProxyNamespace('EntityProxy');
$doctrineConfig->setAutoGenerateProxyClasses(true);
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('events');
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new \Doctrine\Common\Annotations\AnnotationReader(), array(__DIR__ . '/module/Application/src/Application/Entity'));
$doctrineConfig->setMetadataDriverImpl($driver);
$doctrineConfig->setMetadataCacheImpl($cache);
$em = \Doctrine\ORM\EntityManager::create($config['doctrine']['connection'], $doctrineConfig);
/** @var $em \Doctrine\ORM\EntityManager */
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$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)));