コード例 #1
0
ファイル: BuildCommand.php プロジェクト: 0mars/losolib
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     if (\Zend_Registry::isRegistered(\LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex()) && ($container = \Zend_Registry::get(\LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())) instanceof \Symfony\Component\DependencyInjection\ContainerInterface) {
         $mappingPaths = $container->getParameter('doctrine.orm.mapping_paths');
         $entitiesPaths = $container->getParameter('doctrine.orm.entities_paths');
     } else {
         $doctrineConfig = \Zend_Registry::get('doctrine.config');
         $mappingPaths = $doctrineConfig['doctrine.orm.mapping_paths'];
         $entitiesPaths = $doctrineConfig['doctrine.orm.entities_paths'];
     }
     $cmf = new DisconnectedClassMetadataFactory($em);
     $metadatas = $cmf->getAllMetadata();
     foreach ($mappingPaths as $namespace => $mappingPath) {
         // Process destination directory
         $destPath = realpath($entitiesPaths[$namespace]);
         if (!file_exists($destPath)) {
             throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $destPath));
         } else {
             if (!is_writable($destPath)) {
                 throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath));
             }
         }
         $moduleMetadatas = MetadataFilter::filter($metadatas, $namespace);
         if (count($moduleMetadatas)) {
             // Create EntityGenerator
             $entityGenerator = new EntityGenerator();
             $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
             $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
             $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
             $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
             $entityGenerator->setNumSpaces($input->getOption('num-spaces'));
             if (($extend = $input->getOption('extend')) !== null) {
                 $entityGenerator->setClassToExtend($extend);
             }
             foreach ($moduleMetadatas as $metadata) {
                 $output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
             }
             // Generating Entities
             $entityGenerator->generate($moduleMetadatas, $destPath);
             $this->_processNamespaces($destPath, $namespace);
             // Outputting information message
             $output->write(sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
         } else {
             $output->write('No Metadata Classes to process.' . PHP_EOL);
         }
     }
     /*$output->write(PHP_EOL . 'Reset database.' . PHP_EOL);
     
             $metadatas = $em->getMetadataFactory()->getAllMetadata();
             $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
             $output->write('Dropping database schema...' . PHP_EOL);
             $schemaTool->dropSchema($metadatas);
             $output->write('Database schema dropped successfully!' . PHP_EOL);
             $output->write('Creating database schema...' . PHP_EOL);
             $schemaTool->createSchema($metadatas);
             $output->write('Database schema created successfully!' . PHP_EOL);*/
 }
コード例 #2
0
ファイル: GenericRepository.php プロジェクト: nuxwin/losolib
 public function __construct()
 {
     if (empty($this->entityName)) {
         throw new LoSo_Exception('EntityName must be defined when extending LoSo GenericRepository.');
     }
     $em = Zend_Registry::get(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())->em;
     $metadata = $em->getClassMetadata($this->entityName);
     parent::__construct($em, $metadata);
 }
コード例 #3
0
 /**
  * Check for dependencies and inject them if needed.
  */
 protected function setUp()
 {
     parent::setUp();
     if (Zend_Registry::isRegistered(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex()) && ($container = Zend_Registry::get(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())) instanceof \Symfony\Component\DependencyInjection\ContainerInterface) {
         $r = new Zend_Reflection_Class($this);
         $properties = $r->getProperties();
         foreach ($properties as $property) {
             if ($property->getDocComment() && $property->getDocComment()->hasTag('Inject')) {
                 $injectTag = $property->getDocComment()->getTag('Inject');
                 $serviceName = $injectTag->getDescription();
                 if (empty($serviceName)) {
                     $serviceName = $this->_formatServiceName($property->getName());
                 }
                 if ($container->has($serviceName)) {
                     $property->setAccessible(true);
                     $property->setValue($this, $container->get($serviceName));
                 }
             }
         }
     }
 }
コード例 #4
0
 /**
  * Dispatch to a controller/action.
  *   - If the container is a Symfony Dependency Injection container, controller and his dependencies are loaded
  *     by the container.
  *   - If not the controller is instantiated as it would have been in the standard dispatcher.
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @param  Zend_Controller_Response_Abstract $response
  * @throws Zend_Controller_Dispatcher_Exception
  * @throws LoSo_Exception
  */
 public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     /**
      * Get controller class
      */
     if (!$this->isDispatchable($request)) {
         $controller = $request->getControllerName();
         if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
             require_once 'Zend/Controller/Dispatcher/Exception.php';
             throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
         }
         $className = $this->getDefaultControllerClass($request);
     } else {
         $className = $this->getControllerClass($request);
         if (!$className) {
             $className = $this->getDefaultControllerClass($request);
         }
     }
     /**
      * Load the controller class file
      */
     $className = $this->loadClass($className);
     /**
      * Retrieve or instantiate controller with request, response, and invocation
      * arguments; throw exception if it's not an action controller
      */
     /**
      * Retrieve Symfony Dependency Injection container.
      */
     if (Zend_Registry::isRegistered(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())) {
         $container = Zend_Registry::get(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex());
         $controllerId = lcfirst($className);
     } else {
         $container = null;
     }
     /**
      * If container is a Symfony Dependency Injection container, retrieve controller instance
      * throught the container
      */
     if (null !== $container && $container->has(lcfirst($controllerId))) {
         $controller = $container->get($controllerId);
         if (!$controller instanceof LoSo_Zend_Controller_Action) {
             throw new LoSo_Exception('Controller from Symfony Container "' . $className . '" is not an instance of LoSo_Zend_Controller_Action');
         }
         $controller->init();
     } else {
         $controller = new $className($request, $this->getResponse(), $this->getParams());
         if ($controller instanceof LoSo_Zend_Controller_Action) {
             $controller->init();
         }
     }
     if (!$controller instanceof Zend_Controller_Action_Interface && !$controller instanceof Zend_Controller_Action) {
         require_once 'Zend/Controller/Dispatcher/Exception.php';
         throw new Zend_Controller_Dispatcher_Exception('Controller "' . $className . '" is not an instance of Zend_Controller_Action_Interface');
     }
     /**
      * Retrieve the action name
      */
     $action = $this->getActionMethod($request);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     // by default, buffer output
     $disableOb = $this->getParam('disableOutputBuffering');
     $obLevel = ob_get_level();
     if (empty($disableOb)) {
         ob_start();
     }
     try {
         $controller->dispatch($action);
     } catch (Exception $e) {
         // Clean output buffer on error
         $curObLevel = ob_get_level();
         if ($curObLevel > $obLevel) {
             do {
                 ob_get_clean();
                 $curObLevel = ob_get_level();
             } while ($curObLevel > $obLevel);
         }
         throw $e;
     }
     if (empty($disableOb)) {
         $content = ob_get_clean();
         $response->appendBody($content);
     }
     // Destroy the page controller instance and reflection objects
     $controller = null;
 }
コード例 #5
0
 /**
  * Set container's registry index.
  *
  * @param  string $registryIndex
  * @return LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap
  */
 public static function setRegistryIndex($registryIndex)
 {
     self::$_registryIndex = $registryIndex;
     return $this;
 }