Beispiel #1
0
 /**
  * doExecute
  *
  * @return  integer
  */
 protected function doExecute()
 {
     DateTimeHelper::setDefaultTimezone();
     $this->out()->out('Vaseman generator')->out('-----------------------------')->out()->out('<comment>Start generating site</comment>')->out();
     $controller = new GetController();
     $event = new Event('onBeforeRenderFiles');
     $event['config'] = $this->app->getConfig();
     $event['controller'] = $controller;
     $event['io'] = $this->io;
     Ioc::getDispatcher()->triggerEvent($event);
     $dataRoot = $this->app->get('project.path.data', WINDWALKER_ROOT);
     $folders = $this->app->get('folders', array());
     $controller->setPackage(PackageHelper::getPackage('vaseman'));
     $controller->setApplication($this->app);
     $assets = array();
     $processors = array();
     foreach ($folders as $folder) {
         $files = Filesystem::files($dataRoot . '/' . $folder, true);
         foreach ($files as $file) {
             $asset = new Asset($file, $dataRoot . '/' . $folder);
             $layout = Path::clean($asset->getPath(), '/');
             $input = new Input(array('paths' => explode('/', $layout)));
             $config = $controller->getConfig();
             $config->set('layout.path', $asset->getRoot());
             $config->set('layout.folder', $folder);
             $controller->setInput($input)->execute();
             $processors[] = $controller->getProcessor();
         }
     }
     $event->setName('onAfterRenderFiles');
     $event['processors'] = $processors;
     Ioc::getDispatcher()->triggerEvent($event);
     $event->setName('onBeforeWriteFiles');
     Ioc::getDispatcher()->triggerEvent($event);
     $dir = $this->getOption('dir');
     $dir = $dir ?: $this->app->get('outer_project') ? "" : 'output';
     $dir = $this->app->get('project.path.root') . '/' . $dir;
     /** @var AbstractFileProcessor $processor */
     foreach ($processors as $processor) {
         $file = Path::clean($dir . '/' . $processor->getTarget());
         $this->out('<info>Write file</info>: ' . $file);
         Folder::create(dirname($file));
         file_put_contents($file, $processor->getOutput());
     }
     $event->setName('onAfterWriteFiles');
     Ioc::getDispatcher()->triggerEvent($event);
     $this->out()->out('<info>Complete</info>')->out();
     return 0;
 }
Beispiel #2
0
 /**
  * Method to test files().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Filesystem::files
  */
 public function testFiles()
 {
     $files = Filesystem::files(__DIR__ . '/dest/folder1/level2', true, true);
     $this->assertEquals(FilesystemTestHelper::cleanPaths(array(__DIR__ . '/dest/folder1/level2/file3')), FilesystemTestHelper::cleanPaths($files));
     // Recursive
     $files = Filesystem::files(static::$dest, true, true);
     $compare = FilesystemTestHelper::getFilesRecursive('dest');
     $this->assertEquals(FilesystemTestHelper::cleanPaths($compare), FilesystemTestHelper::cleanPaths($files));
     // Iterator
     $files = Filesystem::files(static::$dest, true);
     $this->assertInstanceOf('CallbackFilterIterator', $files);
     $files2 = Filesystem::iteratorToArray($files);
     $this->assertEquals(FilesystemTestHelper::cleanPaths($compare), FilesystemTestHelper::cleanPaths($files2));
     $files->rewind();
     $this->assertInstanceOf('SplFileinfo', $files->current());
 }
 /**
  * Get file iterator of all paths
  *
  * @param  boolean $recursive True to resursive.
  *
  * @return  \AppendIterator  Iterator only include files.
  */
 public function getFiles($recursive = false)
 {
     return $this->appendIterator(function ($path) use($recursive) {
         return Filesystem::files((string) $path, $recursive);
     });
 }
Beispiel #4
0
 /**
  * files
  *
  * @param string   $path
  * @param boolean  $recursive
  * @param integer  $pathType
  *
  * @return  array
  */
 public static function files($path, $recursive = false, $pathType = self::PATH_ABSOLUTE)
 {
     $files = array();
     /** @var $file \SplFileInfo */
     foreach (Filesystem::files($path, $recursive) as $file) {
         switch ($pathType) {
             case $pathType === self::PATH_BASENAME:
                 $name = $file->getBasename();
                 break;
             case $pathType === static::PATH_RELATIVE:
                 $pathLength = strlen($path);
                 $name = $file->getRealPath();
                 $name = trim(substr($name, $pathLength), DIRECTORY_SEPARATOR);
                 break;
             case $pathType === static::PATH_ABSOLUTE:
             default:
                 $name = $file->getPathname();
                 break;
         }
         $files[] = $name;
     }
     return $files;
 }
Beispiel #5
0
 /**
  * Get file iterator of current dir
  *
  * @param  boolean $recursive True to resursive.
  *
  * @return  \CallbackFilterIterator  Iterator only include files.
  */
 public function getFiles($recursive = false)
 {
     return Filesystem::files((string) $this, $recursive);
 }