/** * Returns the roadmap for this project. * @return RoadMap */ public function getRoadMap() { $bundle_name = strtolower(preg_replace('#[A-Z][a-z0-9]#', '_$0', $this->getProjectName())); $road_map = new RoadMap(); $lessRoad = new LessRoad("LESSCSS", $this->generateCacheDir($this->getProjectRootDir()), new File("../web/chiji/" . $bundle_name, StaticsManager::getKernel()->getRootDir())); $lessRoad->bundleName = $bundle_name; $rootRoad = new \Chigi\Chiji\Project\SourceRoad("ROOT", $this->generateCacheDir($this->getProjectRootDir()), new File('../web/chiji/' . $bundle_name, StaticsManager::getKernel()->getRootDir())); $rootRoad->bundleName = $bundle_name; $road_map->append($lessRoad); $road_map->append($rootRoad); $road_map->append(new TwigRoad('TWIG', new File('Resources/views', StaticsManager::getBundle()->getPath()), new File('../web/chiji/', StaticsManager::getKernel()->getRootDir()))); $road_map->append(new BuildRoad("BuildCache", $this->getProjectRootDir())); return $road_map; }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code * * @throws LogicException When this abstract method is not implemented * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); /* @var $filesystem Filesystem */ $filesystem = $this->getContainer()->get('filesystem'); try { /* @var $bundle BundleInterface */ $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument("name")); } catch (InvalidArgumentException $exc) { throw $exc; } \Chigi\Bundle\ChijiBundle\Util\StaticsManager::setContainer($this->getContainer()); \Chigi\Bundle\ChijiBundle\Util\StaticsManager::setBundle($bundle); /* @var $kernel KernelInterface */ $kernel = $this->getContainer()->get('kernel'); $chiji_resources_path = $bundle->getPath() . '/Resources/chiji'; if (!is_dir($chiji_resources_path)) { throw new \Chigi\Chiji\Exception\InvalidConfigException(sprintf("The Path (\"%s\") NOT FOUND", $chiji_resources_path)); } $project = new Project($chiji_resources_path . '/chiji-conf.php'); \Chigi\Chiji\Util\ProjectUtil::registerProject($project); // Clear all the release directories. foreach ($project->getReleaseDirs() as $dir) { $this->taskCleanDir($dir->getAbsolutePath())->run(); } $twig_stack_dir = new \Chigi\Component\IO\File("Resources/views/chiji", $bundle->getPath()); if (!$twig_stack_dir->exists()) { $twig_stack_dir->mkdirs(); } $this->taskCleanDir($twig_stack_dir->getAbsolutePath())->run(); $project->getCacheManager()->openCache(); do { $newly_registered_pathhash = array(); foreach ($project->getSourceDirs() as $dir) { if ($dir->isDirectory()) { $finder = new Finder(); foreach ($finder->files()->followLinks()->in($dir->getAbsolutePath()) as $spl_file) { $file = new \Chigi\Component\IO\File($spl_file->getPathname()); if (!is_null($project->getResourceByFile($file))) { continue; } if (($road = $project->getMatchRoad($file)) instanceof SourceRoad) { $this->say('Registered <' . $road->getName() . '>:' . $file->getAbsolutePath()); } else { continue; } array_push($newly_registered_pathhash, md5($file->getAbsolutePath())); } } } foreach ($project->getRegisteredResources() as $resource) { /* @var $resource \Chigi\Chiji\File\AbstractResourceFile */ if (!in_array(md5($resource->getRealPath()), $newly_registered_pathhash)) { continue; } // ONLY BUILD newly registered file preventing looply building. $road = $project->getMatchRoad($resource->getFile()); $road->buildCache($resource); } } while (count($newly_registered_pathhash) > 0); foreach ($project->getRegisteredResources() as $resource) { /* @var $resource \Chigi\Chiji\File\AbstractResourceFile */ if ($resource instanceof \Chigi\Chiji\File\Annotation && $resource->getMemberId() === $resource->getFinalCache()->getMemberId()) { $resource->analyzeAnnotations(); } } foreach ($project->getReleasesCollection() as $resource) { /* @var $resource \Chigi\Chiji\File\AbstractResourceFile */ $project->getMatchRoad($resource->getFinalCache()->getFile())->releaseResource($resource->getFinalCache()); $this->say("[Released] " . $resource->getRealPath()); } foreach (StaticsManager::getPostEndFunctionAnnotations() as $function) { /* @var $function FunctionAnnotation */ $function->execute(); } $project->getCacheManager()->closeCache(); return; //$template_path = $this->getContainer()->get('templating.locator')->locate($this->getContainer()->get('templating.name_parser')->parse('ChigiBlogBundle:chiji:edit.html.twig')); //var_dump($this->getContainer()->get('templating.name_parser')->parse('ChigiBlogBundle:Post:edit.html.twig')->getPath()); //var_dump($this->getTemplatePath($this->getContainer()->get('templating.name_parser')->parse('ChigiBlogBundle:Post:edit.html.twig'))); // foreach (ResourcesManager::getAll() as $resource) { // // 遍历所有 resource 对象,并针对有目标输入流的资源对象写入模板 HTML // /* @var $resource AbstractResourceFile */ // if ($resource instanceof RequiresMapInterface) { // //var_dump($resource->getRequires()->getArrayCopy()); // } // foreach ($print_nodes as $node) { // if (trim($node) === "") { // continue; // } // $include_match = array(); // if (preg_match('#^include\([\'"](.+)[\'"]\)$#', trim($node), $include_match)) { // // 将最终结果写入到目标 TWIG 文件中 // $target_subtemplate = $this->getTemplatePath($this->getContainer()->get('templating.name_parser')->parse(end($include_match))); // if (!is_file($target_subtemplate)) { // $filesystem->touch($target_subtemplate); // } // file_put_contents($target_subtemplate, "QQCUM"); // } // } // } var_dump($kernel->getEnvironment()); var_dump($bundle->getPath() . '/Resources/'); var_dump($this->getBasePathForClass($bundle->getName(), $bundle->getNamespace(), $bundle->getPath())); }