/** * 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); }
/** * Do this execute. * * @return mixed */ protected function doExecute() { $dest = $this->config['dir.dest']; $migName = $this->config['replace.controller.item.name.cap'] . 'Init'; if (!is_dir($dest . '/Migration')) { return; } // Copy migration $files = Folder::files($dest . '/Migration'); $file = false; // If last migration with same name exists, delete duplicated migration. foreach ($files as $file) { $fileName = pathinfo($file, PATHINFO_BASENAME); if (strpos($file, $migName . '.php') !== false && $fileName != '19700101000000_' . $migName . '.php') { if (is_file($dest . '/Migration/' . '19700101000000_' . $migName . '.php')) { File::delete($dest . '/Migration/' . '19700101000000_' . $migName . '.php'); } return; } } foreach ($files as $file) { if (strpos($file, $migName . '.php') !== false) { break; } } // Migration not exists, return. if (!$file) { return; } $newName = gmdate('YmdHis') . '_' . $migName . '.php'; File::move($file, $dest . '/Migration/' . $newName); $this->io->out('[<info>Action</info>] Rename migration file to: ' . $newName); }
/** * 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); }
/** * tearDown * * @return void */ protected function tearDown() { parent::tearDown(); if (is_dir(static::$dest)) { Folder::delete(static::$dest); } }
/** * 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); }
/** * delete * * @param string $path * * @return bool */ public static function delete($path) { if (is_dir($path)) { Folder::delete($path); } elseif (is_file($path)) { File::delete($path); } return true; }
/** * 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')); }
/** * 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'; }
/** * 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; }
/** * loadRouting * * @return mixed */ public function loadRouting() { $files = Folder::files(__DIR__ . '/Resources/routing'); $routes = array(); foreach ($files as $file) { $ext = File::getExtension($file); if ($ext != 'yml') { continue; } $routes = array_merge($routes, Yaml::parse(file_get_contents($file))); } return $routes; }
function recursiveCopy($filename, $initialfolder, $targetfolder) { $badfiles = ['vendor', 'node_modules', '.DS_Store', 'sftp-config.json', '.git', '.gitignore', 'build.sh']; foreach (Folder::items($initialfolder . '/' . $filename, false, Folder::PATH_BASENAME) as $item) { if (!in_array($item, $badfiles)) { if (is_dir($initialfolder . '/' . $filename . '/' . $item)) { recursiveCopy($item, $initialfolder . '/' . $filename, $targetfolder . '/' . $filename); } else { File::copy($initialfolder . '/' . $filename . '/' . $item, $targetfolder . '/' . $filename . '/' . $item); } } } }
/** * doExecute * * @return mixed|void */ public function doExecute() { // Flip replace array because we want to convert template. $replace = array_flip($this->replace); foreach ($replace as &$val) { $val = '{{' . $val . '}}'; } // Flip src and dest because we want to convert template. $src = $this->config['dir.src']; $dest = $this->config['dir.dest']; // Remove dir first if (is_dir($dest)) { Folder::delete($dest); } $this->container->get('operator.convert')->copy($src, $dest, $replace); }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { // Flip src and dest because we want to convert template. $dest = $this->config->get('dir.dest'); $src = $this->config->get('dir.src'); $this->config->set('dir.dest', $src); $this->config->set('dir.src', $dest); $this->doAction(new Action\ConvertTemplateAction()); // Rename migration if (is_dir($src . '/Migration')) { $file = Folder::files($src . '/Migration')[0]; $time = '19700101000000'; $newFilename = preg_replace('/\\d+(_.+Init\\.php\\.tpl)/', $time . '$1', $file); File::move($file, $newFilename); } return true; }
/** * doExecute * * @return mixed|void */ public function doExecute() { // Flip replace array because we want to convert template. $replace = array_flip($this->replace); foreach ($replace as &$val) { $val = '{{' . $val . '}}'; } // Flip src and dest because we want to convert template. $src = $this->config['dir.src']; $dest = $this->config['dir.dest']; if (!is_dir($src)) { throw new \RuntimeException(sprintf('Extension "%s" in %s not exists', $this->config['element'], $this->config['client'])); } // Remove dir first Folder::delete($dest); $this->container->get('operator.convert')->copy($src, $dest, $replace); }
/** * Do this execute. * * @return mixed */ protected function doExecute() { /** @var ConvertOperator $operator */ $operator = $this->container->get('operator.factory')->getOperator('convert'); $replace = ArrayHelper::flatten($this->replace); // Flip replace array because we want to convert template. $replace = array_flip($replace); foreach ($replace as &$val) { $val = StringHelper::quote($val, $operator->getTagVariable()); } // Flip src and dest because we want to convert template. $src = $this->config['dir.src']; $dest = $this->config['dir.dest']; if (is_dir($dest)) { // Remove dir first Folder::delete($dest); } $operator->copy($src, $dest, $replace); }
/** * 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))); }
/** * 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.'); }
/** * 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; }
/** * onAfterWriteFiles * * @return void */ public function onAfterWriteFiles() { include_once __DIR__ . '/../../vendor/autoload.php'; $base = realpath(__DIR__ . '/../../..'); $items = Folder::files($base, true); $sitemap = new Sitemap(); $root = Ioc::getConfig()->get('site.root'); $sitemap->addItem($root, 1.0); foreach ($items as $item) { if (File::getExtension($item) != 'html') { continue; } $loc = str_replace('\\', '/', substr($item, strlen($base) + 1)); $sitemap->addItem($root . '/' . $loc, 0.8, ChangeFreq::WEEKLY, new \DateTime()); } $xml = $sitemap->toString(); file_put_contents($base . '/sitemap.xml', $xml); }
/** * loadRouting * * @param MainRouter $router * @param string $group * * @return MainRouter */ public function loadRouting(MainRouter $router, $group = null) { $router = parent::loadRouting($router, $group); $router->group($group, function (MainRouter $router) { $router->addRouteFromFiles(Folder::files(__DIR__ . '/Resources/routing'), $this->getName()); // Merge other routes here... }); return $router; }
/** * Method to test makeSafe(). * * @return void * * @covers Windwalker\Filesystem\Folder::makeSafe */ public function testMakeSafe() { $safe = Folder::makeSafe('fo_o/bar 2/yo-o.o/三杯雞 go:to:fly.ing'); $this->assertEquals('fo_o/bar2/yo-o.o/gotofly.ing', $safe); }
/** * getAllProfiles * * @return array */ public static function getAllProfiles() { return Folder::folders(SQLSYNC_RESOURCE, false, Folder::PATH_BASENAME); }
/** * loadRouting * * @return mixed */ public function loadRouting() { $routes = parent::loadRouting(); foreach (Folder::files(__DIR__ . '/Resources/routing') as $file) { if (File::getExtension($file) == 'yml') { $routes = array_merge($routes, (array) Yaml::parse(file_get_contents($file))); } } // Merge other routes here... $routes = array_merge($routes, WarderHelper::getAdminRouting()); $routes = array_merge($routes, LunaHelper::getAdminRouting()); return $routes; }
/** * createFolder * * @param string $dest * * @return void */ protected function createFolder($dest) { $this->out('<info>Create</info>: ' . $dest); Folder::create($dest); File::write($dest . '/.gitkeep', ''); }
/** * 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; }