Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * findPaths
  *
  * @param string $layout
  *
  * @return  \SplFileInfo
  */
 public function findPaths($layout = null)
 {
     $layout = $layout ?: $this->getLayout();
     if (is_file($this->getPath() . '/' . $layout)) {
         return new \SplFileInfo(realpath($this->getPath() . '/' . $layout));
     }
     $layout = explode('/', $layout);
     $name = array_pop($layout);
     $layout = implode('/', $layout);
     if (is_dir($this->getPath() . '/' . $layout)) {
         $files = Filesystem::find($this->path . '/' . $layout, $name);
         /** @var \SplFileInfo $file */
         foreach ($files as $file) {
             if (File::stripExtension($file->getFilename()) == $name) {
                 return $file;
             }
         }
     }
     return null;
 }
Esempio n. 3
0
 /**
  * guessSubmenus
  *
  * @param string $inflection
  *
  * @return array
  */
 protected function findViewMenus($inflection = self::PLURAL)
 {
     $inflector = StringInflector::getInstance();
     $viewFolder = ADMIN_ROOT . '/View';
     $views = Filesystem::folders($viewFolder);
     $menus = array();
     /** @var \SplFileInfo $view */
     foreach ($views as $view) {
         if ($view->isFile()) {
             continue;
         }
         $name = strtolower($view->getBasename());
         if ($inflection == static::PLURAL && $inflector->isPlural($name)) {
             $menus[] = $name;
         } elseif ($inflection == static::SINGULAR && $inflector->isSingular($name)) {
             $menus[] = $name;
         }
     }
     return $menus;
 }
 /**
  * Get folder iterator of all paths
  *
  * @param  boolean $recursive True to resursive.
  *
  * @return  \AppendIterator  Iterator only include dirs.
  */
 public function getFolders($recursive = false)
 {
     return $this->appendIterator(function ($path) use($recursive) {
         return Filesystem::folders((string) $path, $recursive);
     });
 }
Esempio n. 5
0
 /**
  * folders
  *
  * @param string   $path
  * @param boolean  $recursive
  * @param integer  $pathType
  *
  * @return  array
  */
 public static function folders($path, $recursive = false, $pathType = self::PATH_ABSOLUTE)
 {
     $files = array();
     /** @var $file \SplFileInfo */
     foreach (Filesystem::folders($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;
 }
Esempio n. 6
0
 /**
  * Moves a file
  *
  * @param   string $src   The path to the source file
  * @param   string $dest  The path to the destination file
  * @param   bool   $force Force move it.
  *
  * @throws Exception\FilesystemException
  * @return  boolean  True on success
  *
  * @since   2.0
  */
 public static function move($src, $dest, $force = false)
 {
     // Check src path
     if (!is_readable($src)) {
         return 'Cannot find source file.';
     }
     // Delete first if exists
     if (file_exists($dest)) {
         if ($force) {
             Filesystem::delete($dest);
         } else {
             throw new FilesystemException('File: ' . $dest . ' exists, move failed.');
         }
     }
     // Check folder exists
     $dir = dirname($dest);
     if (!is_dir($dir)) {
         Folder::create($dir);
     }
     if (!@rename($src, $dest)) {
         throw new FilesystemException(__METHOD__ . ': Rename failed.');
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Using a closure function to filter file.
  *
  * @param  \Closure $callback  A callback function to filter file.
  * @param  boolean  $recursive True to recursive.
  *
  * @return  \CallbackFilterIterator  Filtered file or path iteator.
  *
  * @see    http://www.php.net/manual/en/class.callbackfilteriterator.php
  * @since  2.0
  */
 public function findByCallback(\Closure $callback, $recursive = false)
 {
     return Filesystem::findByCallback((string) $this, $callback, $recursive);
 }
 /**
  * setUp
  *
  * @return  void
  */
 protected function setUp()
 {
     static::$dest = __DIR__ . '/dest';
     static::$src = __DIR__ . '/files';
     Filesystem::copy(static::$src, static::$dest);
 }
Esempio n. 9
0
 /**
  * Method to test createIterator().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Filesystem::createIterator
  */
 public function testCreateIterator()
 {
     $this->assertInstanceOf('Windwalker\\Filesystem\\Iterator\\RecursiveDirectoryIterator', Filesystem::createIterator(static::$dest));
     $this->assertInstanceOf('RecursiveIteratorIterator', Filesystem::createIterator(static::$dest, true));
 }
Esempio n. 10
0
 /**
  * Destructor
  */
 public function __destruct()
 {
     Filesystem::delete(__DIR__ . '/cache');
 }
Esempio n. 11
0
if (is_file(__DIR__ . '/vendor/autoload.php')) {
    require_once __DIR__ . '/vendor/autoload.php';
}
use Windwalker\Filesystem\File;
use Windwalker\Filesystem\Path;
use Windwalker\Filesystem\Folder;
use Windwalker\Filesystem\Filesystem;
use Alchemy\Zippy\Zippy;
Task::register('build', function ($task) {
    $basepath = realpath(__DIR__ . '/..');
    $distfolder = Path::clean($basepath . '/dist');
    $pluginfolder = Path::clean($distfolder . '/notify');
    $task->writeln('Cleaning files out.');
    // Prepare dist folder
    if (file_exists($distfolder)) {
        Filesystem::delete($distfolder);
        Folder::create($distfolder);
    }
    $task->writeln('Copying files over.');
    recursiveCopy('dev', $basepath, $distfolder);
    $task->writeln('Running composer');
    $task->exec(function ($process) {
        $basepath = realpath(__DIR__ . '/..');
        $distfolder = Path::clean($basepath . '/dist');
        $distfolder = str_replace(' ', '\\ ', $distfolder);
        $process->runLocally("cd " . $distfolder . '/dev' . " && composer install --prefer-dist --optimize-autoloader");
        $process->runLocally("cd .. && cd ..");
    });
    Folder::move($distfolder . '/dev', $distfolder . '/notify');
    $task->writeln('Zipping');
    $zippy = Zippy::load();