/**
  * Do this execute.
  *
  * @return  mixed
  * @throws \Windwalker\Filesystem\Exception\FilesystemException
  */
 protected function doExecute()
 {
     /** @var CopyOperator $copyOperator */
     $copyOperator = $this->container->get('operator.factory')->getOperator('copy');
     $src = $this->config['dir.src'];
     $dest = $this->config['dir.dest'];
     $migName = $this->config['replace.controller.item.name.cap'] . 'Init';
     if (!is_dir($src . '/Migration')) {
         return;
     }
     if (!is_dir($dest . '/Migration')) {
         Folder::create($dest . '/Migration');
     }
     // Copy migration
     $files = Folder::files($dest . '/Migration');
     $hasSameName = false;
     foreach ($files as $file) {
         if (strpos($file, $migName . '.php') !== false) {
             $hasSameName = true;
             break;
         }
     }
     // Migration already exists, return.
     if ($hasSameName) {
         return;
     }
     $migFile = Folder::files($src . '/Migration')[0];
     $newName = gmdate('YmdHis') . '_' . $migName . '.php';
     $copyOperator->copy($migFile, $dest . '/Migration/' . $newName, $this->replace);
     $this->io->out('[<info>Action</info>] Create migration file: ' . $newName);
 }
Beispiel #2
0
 /**
  * Method to run the application routines.  Most likely you will want to instantiate a controller
  * and execute it, or perform some sort of task directly.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function doExecute()
 {
     $package = $this->io->getArgument(0);
     $class = $this->io->getArgument(1);
     $class = StringNormalise::toClassNamespace($class);
     if (!class_exists($class)) {
         $class = 'Windwalker\\' . ucfirst($package) . '\\' . $class;
     }
     if (!class_exists($class)) {
         $this->stop('Class not exists: ' . $class);
     }
     $packagePath = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $package;
     $classPath = ReflectionHelper::getPath($class);
     $testPath = $packagePath . DIRECTORY_SEPARATOR . 'Test';
     $testClass = $this->io->getArgument(2, ReflectionHelper::getShortName($class) . 'Test');
     $testClass = StringNormalise::toClassNamespace($testClass);
     $testFile = $testPath . DIRECTORY_SEPARATOR . $testClass . '.php';
     $realTestClass = 'Windwalker\\' . ucfirst($package) . '\\Test\\' . $testClass;
     $autoload = WINDWALKER_ROOT . '/vendor/autoload.php';
     $command = sprintf('vendor/phpunit/phpunit-skeleton-generator/phpunit-skelgen generate-test --bootstrap="%s" %s %s %s %s', $autoload, $class, $classPath, $realTestClass, $testFile);
     $command = 'php ' . WINDWALKER_ROOT . '/' . $command;
     if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
         // Replace '\' to '\\' in MAC
         $command = str_replace('\\', '\\\\', $command);
     }
     \Windwalker\Filesystem\Folder::create(dirname($testFile));
     $this->exec($command);
 }
Beispiel #3
0
 /**
  * doExecute
  *
  * @return  bool
  */
 protected function doExecute()
 {
     $table = $this->getArgument(0);
     if (!$table) {
         throw new \InvalidArgumentException('No table');
     }
     $db = Ioc::getDatabase();
     $columns = $db->getTable($table)->getColumnDetails();
     if ($file = $this->getOption('o')) {
         if ($file == 1) {
             $file = '/form/fields/' . $table . '.php.tpl';
         }
         $file = new \SplFileInfo(WINDWALKER_TEMP . '/' . ltrim($file, '/\\'));
         if (!is_dir($file)) {
             Folder::create($file->getPath());
         }
         $output = '';
         foreach ($columns as $column) {
             $output .= $this->handleColumn($column) . "\n";
         }
         file_put_contents($file->getPathname(), $output);
         $this->out()->out('File output to: ' . $file->getPathname());
     } else {
         $this->out()->out('Start Generate Fields')->out('--------------------------------------------------')->out()->out();
         foreach ($columns as $column) {
             $this->out($this->handleColumn($column));
         }
     }
     return true;
 }
 /**
  * doAjax
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     if (!$this->app->get('unidev.image.storage')) {
         throw new \LogicException('No image storage set in config.');
     }
     $file = $this->input->files->get($this->fieldName);
     $folder = $this->input->getPath('folder');
     $folder = ltrim($folder . '/', '/');
     if ($file->getError()) {
         throw new \RuntimeException('Upload fail: ' . UploadedFileHelper::getUploadMessage($file->getError()), 500);
     }
     $id = $this->getImageName($file->getClientFilename());
     $temp = $this->getImageTemp($id, File::getExtension($file->getClientFilename()));
     if (!is_dir(dirname($temp))) {
         Folder::create(dirname($temp));
     }
     $file->moveTo($temp);
     $temp = $this->resize($temp);
     if (!is_file($temp)) {
         throw new \RuntimeException('Temp file not exists');
     }
     $url = ImageUploader::upload($temp, $this->getImagePath($folder . $id, File::getExtension($temp)));
     File::delete($temp);
     $this->addMessage('Upload success.');
     return array('url' => $url);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     static::$path = realpath(__DIR__ . '/Tmpl/blade');
     if (!static::$path) {
         throw new \RuntimeException('Path not exists');
     }
     Folder::create(__DIR__ . '/cache');
     $this->instance = new BladeRenderer(static::$path, array('cache_path' => __DIR__ . '/cache'));
 }
Beispiel #6
0
 /**
  * createThumb
  *
  * @param string $src
  *
  * @return  bool
  */
 public static function createThumb($src, $width = 400, $height = 400)
 {
     $dest = new \SplFileInfo(WINDWALKER_CACHE . '/image/temp/' . md5($src));
     Folder::create($dest->getPath());
     $image = new Image();
     $image->loadFile($src);
     $image->cropResize($width, $height, false);
     $image->toFile($dest->getPathname() . '.jpg');
     return $dest->getPathname() . '.jpg';
 }
Beispiel #7
0
 /**
  * doExecute
  *
  * @return  bool
  */
 protected function doExecute()
 {
     $dest = WINDWALKER_ROOT . '/.idea/blade.xml';
     if (!is_dir(dirname($dest))) {
         Folder::create(dirname($dest));
     }
     $http = new HttpClient();
     $http->download($this->file, $dest);
     $this->out('Downloaded <info>blade.xml</info> to <info>.idea</info> folder');
     return true;
 }
Beispiel #8
0
 /**
  * onBeforeRenderFiles
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onBeforeRenderFiles(Event $event)
 {
     $this->data = array();
     $files = new \DirectoryIterator(__DIR__ . '/../../resources');
     $resources = new PriorityQueue();
     $menus = new PriorityQueue();
     /** @var \SplFileInfo $file */
     foreach ($files as $file) {
         if ($file->isDir()) {
             continue;
         }
         $data = new Registry();
         $data->loadFile($file->getPathname(), 'yaml');
         $resName = $file->getBasename('.yml');
         list($priority, $resName) = explode('-', $resName, 2);
         $data['alias'] = $resName;
         $resources->insert($data->toArray(), PHP_INT_MAX - $priority);
         $menus->insert(array('title' => $data['title'], 'alias' => $resName), PHP_INT_MAX - $priority);
     }
     // Store in cache
     $this->data['menus'] = $menus->toArray();
     foreach ($resources as $data) {
         $this->data['resources'][$data['alias']] = $data;
     }
     // Auto create pages
     $categoryFolder = new \SplFileInfo(__DIR__ . '/../../entries/type');
     if (is_dir($categoryFolder->getPathname())) {
         Folder::delete($categoryFolder->getPathname());
     }
     Folder::create($categoryFolder->getPathname());
     foreach ($this->data['resources'] as $catName => &$category) {
         File::copy(__DIR__ . '/../../layouts/tmpl/category.twig', __DIR__ . '/../../entries/type/' . $catName . '.twig');
         // Auto create items page
         $itemFolder = new \SplFileInfo(__DIR__ . '/../../entries/type/' . $catName);
         if (is_dir($itemFolder->getPathname())) {
             Folder::delete($itemFolder->getPathname());
         }
         Folder::create($itemFolder->getPathname());
         foreach ($category['data'] as $itemAlias => &$item) {
             File::copy(__DIR__ . '/../../layouts/tmpl/item.twig', __DIR__ . '/../../entries/type/' . $catName . '/' . $itemAlias . '.twig');
             $item['alias'] = $itemAlias;
         }
     }
 }
Beispiel #9
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 #10
0
 /**
  * dumpOrphans
  *
  * @param string $format
  *
  * @return  void
  *
  * @throws \Windwalker\Filesystem\Exception\FilesystemException
  */
 public static function dumpOrphans($format = 'ini')
 {
     $format = strtolower($format);
     $ext = $format === 'yaml' ? 'yml' : $format;
     $file = WINDWALKER_TEMP . '/language/orphans.' . $ext;
     if (!is_file($file)) {
         Folder::create(dirname($file));
         file_put_contents($file, '');
     }
     $orphans = new Structure();
     $orphans->loadFile($file, $format, array('processSections' => true));
     $orphans->loadString(static::getFormattedOrphans($format), $format, array('processSections' => true));
     file_put_contents($file, $orphans->toString($format, array('inline' => 99)));
 }
Beispiel #11
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 #12
0
 /**
  * createFolder
  *
  * @param string $dest
  *
  * @return  void
  */
 protected function createFolder($dest)
 {
     $this->out('<info>Create</info>: ' . $dest);
     Folder::create($dest);
     File::write($dest . '/.gitkeep', '');
 }
 /**
  * Method to test delete().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Folder::delete
  */
 public function testDelete()
 {
     Folder::create(static::$dest . '/flower');
     Folder::delete(static::$dest . '/flower');
     $this->assertFalse(is_dir(static::$dest . '/flower'));
 }
Beispiel #14
0
    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();
    $archive = $zippy->create('flarum-notify.zip', array('notify' => $distfolder . '/notify'));
Beispiel #15
0
 /**
  * quickUpload
  *
  * @param   string  $base64
  * @param   string  $uri
  *
  * @return  string
  */
 public static function quickUpload($base64, $uri)
 {
     $ext = Base64Image::getTypeFromBase64($base64);
     if (!$ext) {
         return false;
     }
     $temp = WINDWALKER_TEMP . '/unidev/images/temp/' . gmdate('Ymd') . '/' . md5(uniqid(mt_rand(1, 999))) . '.' . $ext;
     if (!is_dir(dirname($temp))) {
         Folder::create(dirname($temp));
     }
     Base64Image::toFile($base64, $temp);
     // Upload to Cloud
     $url = ImageUploader::upload($temp, $uri);
     if (is_file($temp)) {
         File::delete($temp);
     }
     return $url;
 }