AppserverIo\Appserver\PersistenceContainer\DependencyInjection\DirectoryParser::parse PHP Метод

parse() публичный Метод

Parses the bean context's web application base directory for beans that has to be registered in the object manager.
public parse ( ) : void
Результат void
    public function parse()
    {
        // load the web application base directory
        $webappPath = $this->getBeanContext()->getWebappPath();
        // load the directories to be parsed
        $directories = array();
        // append the directory found in the servlet managers configuration
        /** @var \AppserverIo\Appserver\Core\Api\Node\DirectoryNode $directoryNode */
        foreach ($this->getBeanContext()->getDirectories() as $directoryNode) {
            // prepare the custom directory defined in the servlet managers configuration
            $customDir = $webappPath . DIRECTORY_SEPARATOR . ltrim($directoryNode->getNodeValue()->getValue(), DIRECTORY_SEPARATOR);
            // check if the directory exists
            if (is_dir($customDir)) {
                $directories[] = $customDir;
            }
        }
        // parse the directories for annotated servlets
        foreach ($directories as $directory) {
            $this->parseDirectory($directory);
        }
    }

Usage Example

Пример #1
0
 /**
  * Registers the message beans at startup.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  */
 public function registerBeans(ApplicationInterface $application)
 {
     // query whether or not the web application folder exists
     if (is_dir($this->getWebappPath()) === false) {
         return;
     }
     // initialize the directory parser and parse the web application's base directory for annotated beans
     $directoryParser = new DirectoryParser();
     $directoryParser->injectBeanContext($this);
     $directoryParser->parse();
     // initialize the deployment descriptor parser and parse the web application's deployment descriptor for beans
     $deploymentDescriptorParser = new DeploymentDescriptorParser();
     $deploymentDescriptorParser->injectBeanContext($this);
     $deploymentDescriptorParser->parse();
     // load the object manager
     /** @var \AppserverIo\Appserver\DependencyInjectionContainer\Interfaces\ObjectManagerInterface $objectManager */
     $objectManager = $this->getApplication()->search('ObjectManagerInterface');
     // register the beans found by annotations and the XML configuration
     /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
     foreach ($objectManager->getObjectDescriptors() as $descriptor) {
         // check if we've found a bean descriptor and register the bean
         if ($descriptor instanceof BeanDescriptorInterface) {
             $this->registerBean($descriptor);
         }
         // if we found a singleton session bean with a startup callback
         if ($descriptor instanceof SingletonSessionBeanDescriptorInterface && $descriptor->isInitOnStartup()) {
             $this->getApplication()->search($descriptor->getName(), array(null, array($application)));
         }
     }
 }