示例#1
0
 /**
  * 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);
 }
 /**
  * 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);
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 /**
  * loadAllFromPath
  *
  * @param   string $path
  * @param   string $format
  * @param   string $package
  */
 public static function loadAllFromPath($path, $format, $package = null)
 {
     $config = Ioc::getConfig();
     $locale = $config['language.locale'] ?: 'en-GB';
     $default = $config['language.default'] ?: 'en-GB';
     $locale = LanguageNormalize::toLanguageTag($locale);
     $default = LanguageNormalize::toLanguageTag($default);
     $localePath = $path . '/' . $locale;
     $files = array();
     if (is_dir($localePath)) {
         $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME));
     }
     $defaultPath = $path . '/' . $default;
     if (is_dir($defaultPath)) {
         $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME));
     }
     foreach ($files as $file) {
         $ext = File::getExtension($file);
         if (strcasecmp($ext, $format) !== 0) {
             continue;
         }
         Translator::loadFile(File::stripExtension($file), strtolower($format), $package);
     }
 }
示例#6
0
 /**
  * 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 files().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\Folder::files
  */
 public function testFiles()
 {
     $files = Folder::files(__DIR__ . '/dest/folder1/level2', true);
     $this->assertEquals(FilesystemTestHelper::cleanPaths(array(__DIR__ . '/dest/folder1/level2/file3')), FilesystemTestHelper::cleanPaths($files));
     // No full name
     $files = Folder::files(__DIR__ . '/dest/folder1/level2', true, Folder::PATH_BASENAME);
     $this->assertEquals(FilesystemTestHelper::cleanPaths(array('file3')), FilesystemTestHelper::cleanPaths($files));
     $files = Folder::files(__DIR__ . '/dest/folder1', true, Folder::PATH_RELATIVE);
     $this->assertEquals(FilesystemTestHelper::cleanPaths(array('level2/file3', 'path1')), FilesystemTestHelper::cleanPaths($files));
     // Recursive
     $files = Folder::files(static::$dest, true);
     $compare = FilesystemTestHelper::getFilesRecursive('dest');
     $this->assertEquals(FilesystemTestHelper::cleanPaths($compare), FilesystemTestHelper::cleanPaths($files));
 }
示例#8
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);
 }
示例#9
0
 /**
  * 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;
 }