Ejemplo n.º 1
0
 /**
  * Push an application
  *
  * @param mixed  $uApplicationConfig the application configuration
  * @param string $uWritablePath      writable output folder
  *
  * @return void
  */
 public function pushApplication($uApplicationConfig, $uWritablePath)
 {
     // MD create application directory if it does not exist
     if (!file_exists($uWritablePath)) {
         mkdir($uWritablePath, 0777, true);
     }
     // MD push framework variables to undo application's own variable definitions
     $this->pushSourcePaths($uApplicationConfig);
     // MD include compilation file for the application
     // FIXME is it needed to be loaded before Core and ApplicationBase?
     if (file_exists($tFile = "{$uWritablePath}/compiled.php")) {
         require $tFile;
     } else {
         $tGeneratorRegistry = new GeneratorRegistry($uApplicationConfig, $uWritablePath);
         $tGeneratorRegistry->execute();
     }
     // MD add configuration entries too
     $uApplicationConfig += (require "{$uWritablePath}/unified-config.php");
     // MD construct the application class
     $this->runningApplications[] = [ApplicationBase::$current, $this->variables];
     $tApplicationType = $uApplicationConfig["type"];
     $tApplication = new $tApplicationType($uApplicationConfig, $uWritablePath);
     ApplicationBase::$current = $tApplication;
 }
Ejemplo n.º 2
0
 /**
  * Executes the task
  *
  * @param array $uParameters parameters
  *
  * @throws RuntimeException if configuration is invalid
  * @return int exit code
  */
 public function executeTask(array $uParameters)
 {
     /*
     if (count($uParameters) === 0) {
         $tProjectFile = "etc/project.yml";
         $tApplicationKey = "default";
     } else {
         $tExploded = explode("/", $uParameters[0], 2);
         if (count($tExploded) === 1) {
             $tProjectFile = "etc/project.yml";
             $tApplicationKey = $tExploded[0];
         } else {
             $tProjectFile = $tExploded[0];
             $tApplicationKey = $tExploded[1];
         }
     }
     
     $tProjectFile = FileSystem::combinePaths(
         Core::$instance->loader->basepath,
         Core::$instance->translateVariables($tProjectFile)
     );
     $uApplicationConfig = Config::load($tProjectFile)->get();
     
     if (!isset($uApplicationConfig[$tApplicationKey])) {
         throw new RuntimeException(sprintf("invalid configuration - %s::%s", $tProjectFile, $tApplicationKey));
     }
     
     // TODO is sanitizing $tApplicationKey needed for paths?
     $tApplicationWritablePath = Core::$instance->loader->basepath . "/var/generated/app.{$tApplicationKey}";
     
     if (!file_exists($tApplicationWritablePath)) {
         mkdir($tApplicationWritablePath, 0777, true);
     }
     
     // initialize annotation scanner
     $this->annotationScanner = new AnnotationScanner();
     
     // initialize generators read from configuration
     if (isset($this->config["generators"])) {
         foreach ($this->config["generators"] as $tTaskGeneratorClass) {
             $tInstance = new $tTaskGeneratorClass (
                 $uApplicationConfig[$tApplicationKey],
                 $tApplicationWritablePath
             );
     
             foreach ($tInstance->annotations as $tAnnotationKey => $tAnnotation) {
                 $this->annotationScanner->annotations[$tAnnotationKey] = $tAnnotation;
             }
     
             $this->generators[$tTaskGeneratorClass] = $tInstance;
         }
     }
     
     // -- scan composer maps
     Core::$instance->pushSourcePaths($uApplicationConfig[$tApplicationKey]);
     $tFolders = iterator_to_array(Core::$instance->loader->getComposerFolders(), false);
     
     $this->interface->writeColor("green", "Composer Maps:");
     foreach ($tFolders as $tFolder) {
         $this->interface->writeColor("white", sprintf("- [%s] \\%s => %s", $tFolder[2], $tFolder[0], $tFolder[1]));
     }
     
     foreach ($this->generators as $tGenerator) {
         $tGenerator->initialize();
     }
     
     // -- process files
     foreach ($tFolders as $tPath) {
         if (file_exists($tPath[1])) {
             FileSystem::getFilesWalk(
                 $tPath[1],
                 "*.*",
                 true,
                 [$this, "processFile"],
                 $tPath[0]
             );
         }
     }
     
     foreach ($this->generators as $tGenerator) {
         $tGenerator->processAnnotations($this->annotationScanner->result);
     }
     
     foreach ($this->generators as $tGenerator) {
         $tGenerator->finalize();
     }
     
     foreach ($this->generators as $tGenerator) {
         $tGenerator->dump();
     }
     
     Core::$instance->popSourcePaths();
     */
     $tApplication = ApplicationBase::$current;
     $tGeneratorRegistry = new GeneratorRegistry($tApplication->config, $tApplication->writablePath);
     $tGeneratorRegistry->execute();
     $this->interface->writeColor("yellow", "done.");
     return 0;
 }