/**
  * Visitor method that adds a initialized class loader to the passed application.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface         $application   The application instance
  * @param \TechDivision\ApplicationServer\Api\Node\ClassLoaderNodeInterface $configuration The class loader configuration node
  *
  * @return void
  */
 public static function visit(ApplicationInterface $application, ClassLoaderNodeInterface $configuration = null)
 {
     // load the application directory
     $webappPath = $application->getWebappPath();
     // initialize the array with the configured directories
     $directories = array();
     // load the composer class loader for the configured directories
     foreach ($configuration->getDirectories() as $directory) {
         // we prepare the directories to include scripts AFTER registering (in application context)
         $directories[] = $webappPath . $directory->getNodeValue();
         // check if an autoload.php is available
         if (file_exists($webappPath . $directory->getNodeValue() . DIRECTORY_SEPARATOR . 'autoload.php')) {
             // if yes, we try to instanciate a new class loader instance
             $classLoader = new ComposerClassLoader($directories);
             // set the composer include paths
             if (file_exists($webappPath . $directory->getNodeValue() . '/composer/include_paths.php')) {
                 $includePaths = (require $webappPath . $directory->getNodeValue() . '/composer/include_paths.php');
                 array_push($includePaths, get_include_path());
                 set_include_path(join(PATH_SEPARATOR, $includePaths));
             }
             // add the composer namespace declarations
             if (file_exists($webappPath . $directory->getNodeValue() . '/composer/autoload_namespaces.php')) {
                 $map = (require $webappPath . $directory->getNodeValue() . '/composer/autoload_namespaces.php');
                 foreach ($map as $namespace => $path) {
                     $classLoader->set($namespace, $path);
                 }
             }
             // add the composer PSR-4 compatible namespace declarations
             if (file_exists($webappPath . $directory->getNodeValue() . '/composer/autoload_psr4.php')) {
                 $map = (require $webappPath . $directory->getNodeValue() . '/composer/autoload_psr4.php');
                 foreach ($map as $namespace => $path) {
                     $classLoader->setPsr4($namespace, $path);
                 }
             }
             // add the composer class map
             if (file_exists($webappPath . $directory->getNodeValue() . '/composer/autoload_classmap.php')) {
                 $classMap = (require $webappPath . $directory->getNodeValue() . '/composer/autoload_classmap.php');
                 if ($classMap) {
                     $classLoader->addClassMap($classMap);
                 }
             }
             // add the class loader instance
             $application->addClassLoader($classLoader);
         }
     }
 }
 /**
  * Visitor method that adds a initialized class loader to the passed application.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface         $application   The application instance
  * @param \TechDivision\ApplicationServer\Api\Node\ClassLoaderNodeInterface $configuration The class loader configuration node
  *
  * @return void
  */
 public static function visit(ApplicationInterface $application, ClassLoaderNodeInterface $configuration = null)
 {
     // load the web application path we want to register the class loader for
     $webappPath = $application->getWebappPath();
     // initialize the array with the applications additional include paths
     $includePath = array();
     // add the possible class path if folder is available
     foreach ($configuration->getDirectories() as $directory) {
         if (is_dir($webappPath . $directory->getNodeValue())) {
             array_push($includePath, $webappPath . $directory->getNodeValue());
         }
     }
     // initialize the SPL class loader instance
     $classLoader = new SplClassLoader($application->getInitialContext(), null, $includePath);
     // add the class loader instance
     $application->addClassLoader($classLoader);
 }
 /**
  * Returns TRUE if the application matches this virtual host configuration.
  *
  * @param \TechDivision\ApplicationServer\Interfaces\ApplicationInterface $application The application to match
  *
  * @return boolean TRUE if the application matches this virtual host, else FALSE
  */
 public function match(ApplicationInterface $application)
 {
     return trim($this->getAppBase(), '/') === $application->getName();
 }
 /**
  * Visitor method that adds a initialized class loader to the passed application.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface         $application   The application instance
  * @param \TechDivision\ApplicationServer\Api\Node\ClassLoaderNodeInterface $configuration The class loader configuration node
  *
  * @return void
  */
 public static function visit(ApplicationInterface $application, ClassLoaderNodeInterface $configuration = null)
 {
     // load the web application path we want to register the class loader for
     $webappPath = $application->getWebappPath();
     // initialize the class path and the enforcement directories
     $classPath = array();
     $enforcementDirs = array();
     // add the possible class path if folder is available
     foreach ($configuration->getDirectories() as $directory) {
         if (is_dir($webappPath . $directory->getNodeValue())) {
             array_push($classPath, $webappPath . $directory->getNodeValue());
             if ($directory->isEnforced()) {
                 array_push($enforcementDirs, $webappPath . $directory->getNodeValue());
             }
         }
     }
     // initialize the arrays of different omit possibilities
     $omittedEnforcement = array();
     $omittedAutoLoading = array();
     // iterate over all namespaces and check if they are omitted in one or the other way
     foreach ($configuration->getNamespaces() as $namespace) {
         // is the enforcement omitted for this namespace?
         if ($namespace->omitEnforcement()) {
             $omittedEnforcement[] = $namespace->getNodeValue()->__toString();
         }
         // is the autoloading omitted for this namespace?
         if ($namespace->omitAutoLoading()) {
             $omittedAutoLoading[] = $namespace->getNodeValue()->__toString();
         }
     }
     // initialize the class loader configuration
     $config = new Config();
     // set the environment mode we want to use
     $config->setValue('environment', $configuration->getEnvironment());
     // set the cache directory
     $config->setValue('cache/dir', $application->getCacheDir());
     // set the default autoloader values
     $config->setValue('autoloader/dirs', $classPath);
     // collect the omitted namespaces (if any)
     $config->setValue('autoloader/omit', $omittedAutoLoading);
     $config->setValue('enforcement/omit', $omittedEnforcement);
     // set the default enforcement configuration values
     $config->setValue('enforcement/dirs', $enforcementDirs);
     $config->setValue('enforcement/enforce-default-type-safety', $configuration->getTypeSafety());
     $config->setValue('enforcement/processing', $configuration->getProcessing());
     $config->setValue('enforcement/level', $configuration->getEnforcementLevel());
     $config->setValue('enforcement/logger', $application->getInitialContext()->getSystemLogger());
     // create the autoloader instance and fill the structure map
     $autoLoader = new self($config);
     // add the class loader instance to the application
     $application->addClassLoader($autoLoader);
 }
 /**
  * Connects the passed application to the system configuration.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface $application The application to be prepared
  *
  * @return void
  */
 protected function addApplicationToSystemConfiguration(ApplicationInterface $application)
 {
     // try to load the API app service instance
     $appNode = $this->getService()->loadByWebappPath($application->getWebappPath());
     // check if the application has already been attached to the container
     if ($appNode == null) {
         $appNode = $this->getService()->newFromApplication($application);
     }
     // connect the application to the container
     $application->connect();
 }
 /**
  * Clean up the the directories for the webapp, e. g. to delete cached stuff
  * that has to be recreated after a restart.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface $application The application to clean up the directories for
  *
  * @return void
  */
 public function cleanUpFolders($application)
 {
     // create the directory we want to store the sessions in
     $cleanUpFolders = array(new \SplFileInfo($application->getCacheDir()));
     // create the applications temporary directories
     foreach ($cleanUpFolders as $cleanUpFolder) {
         $this->cleanUpDir($cleanUpFolder);
     }
 }
 /**
  * Returns an new app node instance.
  *
  * @param \TechDivision\Application\Interfaces\ApplicationInterface $application The application to create a new app node instance from
  *
  * @return \TechDivision\ApplicationServer\Api\Node\AppNode The app node representation of the application
  */
 protected function create(ApplicationInterface $application)
 {
     // create a new AppNode and initialize it with the values from this instance
     $appNode = new AppNode();
     $appNode->setNodeName(AppService::NODE_NAME);
     $appNode->setUuid($appNode->newUuid());
     $appNode->setName($application->getName());
     $appNode->setWebappPath($application->getWebappPath());
     $appNode->setDatasources($application->getDatasources());
     // return the AppNode instance
     return $appNode;
 }