/**
  * cleanPaths
  *
  * @param array $paths
  *
  * @return  mixed
  */
 public static function cleanPaths($paths)
 {
     foreach ($paths as $key => $path) {
         $paths[$key] = Path::clean($path);
     }
     sort($paths);
     return $paths;
 }
Beispiel #2
0
 /**
  * getPackagePath
  *
  * @param string $class
  * @param string $classPath
  *
  * @return  void
  */
 protected function getPackagePath($class, $classPath)
 {
     $classFile = Path::clean($class) . '.php';
     $classFile = substr($classFile, 11);
     $this->out($classFile);
     $this->out($classPath);
     $packagePath = str_replace($classFile, '', $classPath);
     $this->out($packagePath);
     print_r($classFile);
 }
 /**
  * configurePath
  *
  * @return  $this
  */
 protected function configurePath()
 {
     $config = $this->config;
     $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client']));
     $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']);
     $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']);
     // Replace DS
     $config['dir.dest'] = Path::clean($config['dir.dest']);
     $config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
     $config['dir.src'] = Path::clean($config['dir.src']);
     return $this;
 }
 /**
  * Constructor.
  *
  * @param   \Windwalker\DI\Container      $container
  * @param   \Muse\IO\IOInterface $io
  * @param   Registry                      $config
  */
 public function __construct(Container $container, IOInterface $io, Registry $config = null)
 {
     // Get item & list name
     $ctrl = $config['ctrl'] ?: $io->getArgument(1);
     $ctrl = explode('.', $ctrl);
     $inflector = \JStringInflector::getInstance();
     if (empty($ctrl[0])) {
         $ctrl[0] = 'item';
     }
     if (empty($ctrl[1])) {
         $ctrl[1] = $inflector->toPlural($ctrl[0]);
     }
     list($itemName, $listName) = $ctrl;
     $replace['extension.element.lower'] = strtolower($config['element']);
     $replace['extension.element.upper'] = strtoupper($config['element']);
     $replace['extension.element.cap'] = ucfirst($config['element']);
     $replace['extension.name.lower'] = strtolower($config['name']);
     $replace['extension.name.upper'] = strtoupper($config['name']);
     $replace['extension.name.cap'] = ucfirst($config['name']);
     $replace['controller.list.name.lower'] = strtolower($listName);
     $replace['controller.list.name.upper'] = strtoupper($listName);
     $replace['controller.list.name.cap'] = ucfirst($listName);
     $replace['controller.item.name.lower'] = strtolower($itemName);
     $replace['controller.item.name.upper'] = strtoupper($itemName);
     $replace['controller.item.name.cap'] = ucfirst($itemName);
     // Set replace to config.
     foreach ($replace as $key => $val) {
         $config->set('replace.' . $key, $val);
     }
     // Set copy dir.
     $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client']));
     $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']);
     $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']);
     // Replace DS
     $config['dir.dest'] = Path::clean($config['dir.dest']);
     $config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
     $config['dir.src'] = Path::clean($config['dir.src']);
     // Push container
     $this->container = $container;
     parent::__construct($io, $config, $replace);
 }
Beispiel #5
0
 /**
  * execute
  *
  * @return  void
  */
 public function execute()
 {
     // Prepare zip name.
     $zipFile = BUILD_ROOT . '/../windwalker-rad-%s.zip';
     $version = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;
     if (!$version) {
         $this->out('Please enter a version.');
         $this->out('[Usage] php build.php <version>');
         exit;
     }
     // Remove unnecessary files and folders.
     $this->removeFiles();
     // Prepare load composer
     $this->exec("php -r \"readfile('https://getcomposer.org/installer');\" | php");
     rename('composer.phar', BUILD_ROOT . '/composer.phar');
     $this->exec(sprintf('php %s/composer.phar install', BUILD_ROOT));
     $this->out('>> Remove composer.phar');
     unlink(sprintf('%s/composer.phar', BUILD_ROOT));
     // Include dependency to do more things.
     include BUILD_ROOT . '/vendor/autoload.php';
     $zipFile = new \SplFileInfo(\Windwalker\Filesystem\Path::clean(sprintf($zipFile, $version)));
     $dir = new \Windwalker\Filesystem\Path\PathLocator(BUILD_ROOT);
     // Start ZIP archive
     $zip = new ZipArchive();
     @unlink($zipFile->getPathname());
     $zip->open($zipFile->getPathname(), ZIPARCHIVE::CREATE);
     foreach ($dir->getFiles(true) as $file) {
         $file = str_replace(BUILD_ROOT . DIRECTORY_SEPARATOR, '', $file->getPathname());
         if (strpos($file, '.') === 0) {
             continue;
         }
         $this->out('[Zip file] ' . $file);
         $zip->addFile(str_replace('\\', '/', $file));
     }
     $zip->close();
     $this->out('Zip success to: ' . realpath($zipFile->getPathname()));
 }
Beispiel #6
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 #7
0
 /**
  * Lists folder in format suitable for tree display.
  *
  * @param   string   $path      The path of the folder to read.
  * @param   integer  $maxLevel  The maximum number of levels to recursively read, defaults to three.
  * @param   integer  $level     The current level, optional.
  * @param   integer  $parent    Unique identifier of the parent folder, if any.
  *
  * @return  array  Folders in the given folder.
  *
  * @since   2.0
  */
 public static function listFolderTree($path, $maxLevel = 3, $level = 0, $parent = 0)
 {
     $dirs = array();
     static $index;
     static $base;
     if ($level == 0) {
         $index = 0;
         $base = Path::clean($path);
     }
     if ($level < $maxLevel) {
         $folders = static::folders($path, false, false);
         sort($folders);
         // First path, index foldernames
         foreach ($folders as $name) {
             $id = ++$index;
             $fullName = Path::clean($path . '/' . $name);
             $dirs[] = array('id' => $id, 'parent' => $parent, 'name' => $name, 'fullname' => $fullName, 'relative' => trim(str_replace($base, '', $fullName), DIRECTORY_SEPARATOR));
             $dirs2 = self::listFolderTree($fullName, $maxLevel, $level + 1, $id);
             $dirs = array_merge($dirs, $dirs2);
         }
     }
     return $dirs;
 }
 /**
  * setPrefix description
  *
  * @param  string
  * @param  string
  * @param  string
  *
  * @return  string  setPrefixReturn
  *
  * @since  2.0
  */
 public function testSetPrefix()
 {
     $this->setUp();
     $this->collection->addPath('windwalker/dir/foo/bar', 'foo');
     $this->collection->addPath('windwalker/dir/yoo/hoo', 'yoo');
     $this->collection->setPrefix('/var/www');
     $expects = array(Path::clean('/var/www/windwalker/dir/foo/bar'), Path::clean('/var/www/windwalker/dir/yoo/hoo'));
     $paths = array((string) $this->collection->getPath('foo'), (string) $this->collection->getPath('yoo'));
     $this->assertEquals($paths, $expects);
 }
Beispiel #9
0
 /**
  * Moves an uploaded file to a destination folder
  *
  * @param   string   $src          The name of the php (temporary) uploaded file
  * @param   string   $dest         The path (including filename) to move the uploaded file to
  *
  * @return  boolean  True on success
  *
  * @since   2.0
  * @throws  FilesystemException
  */
 public static function upload($src, $dest)
 {
     // Ensure that the path is valid and clean
     $dest = Path::clean($dest);
     // Create the destination directory if it does not exist
     $baseDir = dirname($dest);
     if (!file_exists($baseDir)) {
         Folder::create($baseDir);
     }
     if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) {
         // Short circuit to prevent file permission errors
         if (Path::setPermissions($dest)) {
             return true;
         } else {
             throw new FilesystemException(__METHOD__ . ': Failed to change file permissions.');
         }
     }
     throw new FilesystemException(__METHOD__ . ': Failed to move file.');
 }
Beispiel #10
0
 /**
  * getRoute
  *
  * @return  string
  */
 public function getRoute()
 {
     if ($this->name == 'index' || $this->name == 'default') {
         $route = dirname($this->path);
         return Path::clean($route == '.' ? null : $route, '/');
     }
     return Path::clean(File::stripExtension($this->path), '/');
 }
 /**
  * Reset cache position.
  *
  * @return void
  */
 public function resetCachePosition()
 {
     if ($this->extension) {
         $params = ExtensionHelper::getParams($this->extension);
     } else {
         $params = new Registry();
     }
     $this->config = new Registry();
     $this->config['path.cache'] = Path::clean(JPATH_ROOT . $params->get('thumb.cache-path', '/cache/thumbs/cache'));
     $this->config['path.temp'] = Path::clean(JPATH_ROOT . $params->get('thumb.temp-path', '/cache/thumbs/temp'));
     $this->config['url.cache'] = $params->get('thumb.cache-url', '/cache/thumbs/cache');
     $this->config['url.temp'] = $params->get('thumb.temp-url', '/cache/thumbs/cache');
 }
 /**
  * Constructor.
  *
  * @param   \Windwalker\DI\Container $container
  * @param   \Muse\IO\IOInterface     $io
  * @param   Structure                $config
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(Container $container, IOInterface $io, Structure $config = null)
 {
     // Get item & list name
     $ctrl = $config['ctrl'] ?: $io->getArgument(1);
     $ctrl = explode('.', $ctrl);
     $inflector = StringInflector::getInstance();
     if (empty($ctrl[0])) {
         $ctrl[0] = 'item';
     }
     if (empty($ctrl[1])) {
         $ctrl[1] = $inflector->toPlural($ctrl[0]);
     }
     list($itemName, $listName) = $ctrl;
     // Prepare package name
     $class = explode('\\', str_replace('/', '\\', $config['name']));
     $name = array_pop($class);
     $class = StringNormalise::toClassNamespace(implode('\\', $class));
     $class = $class ? $class . '\\' : null;
     // Check keywords
     if (in_array(strtolower($name), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $name);
     }
     if (in_array(strtolower($listName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $listName);
     }
     if (in_array(strtolower($itemName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $itemName);
     }
     $config['package.name'] = $name;
     $config['package.namespace'] = $class;
     $this->replace = new Structure();
     $this->replace['package.namespace'] = $class;
     $this->replace['package.name.lower'] = lcfirst($name);
     $this->replace['package.name.upper'] = strtoupper($name);
     $this->replace['package.name.cap'] = ucfirst($name);
     $this->replace['controller.list.name.lower'] = strtolower($listName);
     $this->replace['controller.list.name.upper'] = strtoupper($listName);
     $this->replace['controller.list.name.cap'] = ucfirst($listName);
     $this->replace['controller.item.name.lower'] = strtolower($itemName);
     $this->replace['controller.item.name.upper'] = strtoupper($itemName);
     $this->replace['controller.item.name.cap'] = ucfirst($itemName);
     // Set replace to config.
     $config->mergeTo('replace', $this->replace);
     // Set copy dir.
     $config->set('dir.dest', WINDWALKER_SOURCE . '/' . $this->replace['package.namespace'] . $this->replace['package.name.cap']);
     $config->set('dir.tmpl', PHOENIX_TEMPLATES . '/package/' . $config['template']);
     $config->set('dir.src', $config->get('dir.tmpl'));
     // Replace DS
     $config['dir.dest'] = Path::clean($config['dir.dest']);
     $config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
     $config['dir.src'] = Path::clean($config['dir.src']);
     // Push container
     $this->container = $container;
     parent::__construct($io, $config, $this->replace->toArray());
 }
Beispiel #13
0
 /**
  * Method to test findOne().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Filesystem::findOne
  */
 public function testFindOne()
 {
     // String condition
     $file = Filesystem::findOne(static::$dest, 'file', true);
     $files = Filesystem::find(static::$dest, 'file', true, true);
     $this->assertEquals(Path::clean((string) $files[0]), Path::clean((string) $file));
 }
 /**
  * Method to test listFolderTree().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Folder::listFolderTree
  */
 public function testListFolderTree()
 {
     $tree = Folder::listFolderTree(static::$dest);
     $this->assertEquals($tree[0]['relative'], 'folder1');
     $this->assertEquals($tree[1]['parent'], 1);
     $this->assertEquals($tree[1]['relative'], 'folder1' . DIRECTORY_SEPARATOR . 'level2');
     $this->assertEquals($tree[2]['fullname'], Path::clean(static::$dest . '/folder2'));
 }
 /**
  * Create file iterator of current dir.
  *
  * @param  string  $path      The directory path.
  * @param  boolean $recursive True to recursive.
  * @param  integer $options   FilesystemIterator Flags provides which will affect the behavior of some methods.
  *
  * @throws \InvalidArgumentException
  * @return  \FilesystemIterator|\RecursiveIteratorIterator  File & dir iterator.
  */
 public static function createIterator($path, $recursive = false, $options = null)
 {
     $path = Path::clean($path);
     if ($recursive) {
         $options = $options ?: \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO;
     } else {
         $options = $options ?: \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS;
     }
     try {
         $iterator = new RecursiveDirectoryIterator($path, $options);
     } catch (\UnexpectedValueException $exception) {
         throw new \InvalidArgumentException(sprintf('Dir: %s not found.', (string) $path), null, $exception);
     }
     // If rescurive set to true, use RecursiveIteratorIterator
     return $recursive ? new \RecursiveIteratorIterator($iterator) : $iterator;
 }
 /**
  * Method to test clean().
  *
  * @param   string  $input
  * @param   string  $ds
  * @param   string  $expected
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Path::clean
  *
  * @dataProvider  getCleanData
  */
 public function testClean($input, $ds, $expected)
 {
     $this->assertEquals($expected, Path::clean($input, $ds));
 }
Beispiel #17
0
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();
    $archive = $zippy->create('flarum-notify.zip', array('notify' => $distfolder . '/notify'));
    $task->writeln('Deleting copied folder');
    Folder::delete($distfolder . '/notify');
    File::move($basepath . '/flarum-notify.zip', $distfolder . '/flarum-notify.zip');
})->description("Builds a release ready package from the current project state and stores it in /dist.");
function recursiveCopy($filename, $initialfolder, $targetfolder)
{
    $badfiles = ['vendor', 'node_modules', '.DS_Store', 'sftp-config.json', '.git', '.gitignore', 'build.sh'];