示例#1
0
文件: Twig.php 项目: joomlla/jissues
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     $this->getApplication()->outputTitle('Clear Twig cache dir');
     if (!$this->getApplication()->get('renderer.cache', false)) {
         $this->out('Twig caching is not enabled.');
         return;
     }
     $cacheDir = JPATH_ROOT . '/' . $this->getApplication()->get('renderer.cache');
     $this->logOut(sprintf('Cleaning the cache dir in "%s"', $cacheDir));
     if (is_dir($cacheDir)) {
         Folder::delete($cacheDir);
     }
     $this->out()->out('The Twig cache directory has been cleared.');
 }
 /**
  * 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
     Folder::delete($dest);
     $this->container->get('operator.convert')->copy($src, $dest, $replace);
 }
 /**
  * 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);
 }
示例#4
0
 /**
  * Execute the application.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function doExecute()
 {
     if ($this->input->get('h') || $this->input->get('help')) {
         $this->out();
         $this->out('GetJoomlaCLI ' . self::VERSION);
         $this->out('--------------------------------------------------------');
         $this->out('GetJoomlaCLI is a Joomla Framework simple Command Line Apllication.');
         $this->out('With GetJoomlaCLI you can easily download the latest Joomla CMS into a folder.');
         $this->out('called "testingsite".');
         $this->out();
         $this->out('           -h | --help    Prints this usage information.');
         $this->out('           -folder        the folder name where to create the joomla site');
         $this->out('                          "testingsite" will be used if no name is provided');
         $this->out('EXAMPLE USAGE:');
         $this->out('           php -f getjoomlacli.php -h');
         $this->out('           php -f getjoomlacli.php --folder=testingsite');
         $this->out();
     } else {
         $folder = JPATH_ROOT . '/' . $this->input->get('folder', 'testingsite');
         if (is_dir($folder)) {
             $this->out('Removing old files in the folder...');
             Folder::delete($folder);
         }
         Folder::create($folder);
         $this->out('Downloading Joomla...');
         $repository = 'https://github.com/joomla/joomla-cms.git';
         $branch = 'staging';
         $command = "git clone -b {$branch} --single-branch --depth 1 {$repository} {$folder}";
         $this->out($command);
         $output = array();
         exec($command, $output, $returnValue);
         if ($returnValue) {
             $this->out('Sadly we were not able to download Joomla.');
         } else {
             $this->out('Joomla Downloaded and ready for executing the tests.');
         }
     }
 }
 /**
  * Execute the command
  *
  * @return  void
  *
  * @since   1.0
  */
 public function execute()
 {
     // Check if caching is enabled
     $twigCache = $this->app->get('template.cache', false);
     if ($twigCache === false) {
         $this->app->out('Twig caching is disabled.');
         return;
     }
     // Display status
     $this->app->out('Resetting Twig Cache.');
     // First remove the existing cache files
     if (is_dir(JPATH_ROOT . '/' . $twigCache)) {
         foreach (Folder::folders(JPATH_ROOT . '/' . $twigCache) as $folder) {
             Folder::delete(JPATH_ROOT . '/' . $twigCache . '/' . $folder);
         }
     }
     // Now get a list of all the templates
     $files = Folder::files(JPATH_TEMPLATES, '.twig', true, true);
     // Load each template now
     /** @var \Joomla\Renderer\TwigRenderer $twigRenderer */
     $twigRenderer = $this->app->getContainer()->get('renderer');
     $engine = $twigRenderer->getRenderer();
     $errorFiles = [];
     foreach ($files as $file) {
         $template = str_replace(JPATH_TEMPLATES . '/', '', $file);
         try {
             $engine->loadTemplate($template);
         } catch (\Twig_Error $e) {
             $errorFiles[] = $file;
         }
     }
     if (count($errorFiles)) {
         $msg = 'The following Twig resources failed to cache: ' . implode(', ', $errorFiles);
     } else {
         $msg = 'The cached Twig resources were successfully created.';
     }
     $this->app->out($msg);
 }
示例#6
0
 /**
  * Tests the Folder::delete method with an array as an input
  *
  * @return  void
  *
  * @expectedException  UnexpectedValueException
  */
 public function testDeleteArrayPath()
 {
     Folder::delete(array('/path/to/folder'));
 }
示例#7
0
 /**
  * Test write method
  *
  * @return void
  *
  * @covers        Joomla\Filesystem\File::write
  * @since         1.0
  */
 public function testWrite()
 {
     $name = 'tempFile';
     $path = __DIR__;
     $data = 'Lorem ipsum dolor sit amet';
     // Create a file on pre existing path.
     $this->assertThat(File::write($path . '/' . $name, $data), $this->isTrue(), 'Line:' . __LINE__ . ' File should be written successfully.');
     // Create a file on pre existing path by using streams.
     $this->assertThat(File::write($path . '/' . $name, $data, true), $this->isTrue(), 'Line:' . __LINE__ . ' File should be written successfully.');
     // Create a file on non-existing path.
     $this->assertThat(File::write($path . '/TempFolder/' . $name, $data), $this->isTrue(), 'Line:' . __LINE__ . ' File should be written successfully.');
     // Removes file and folder.
     File::delete($path . '/' . $name);
     Folder::delete($path . '/TempFolder');
 }
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 protected function tearDown()
 {
     Folder::delete(JPATH_ROOT . '/language');
 }
 /**
  * Clean cache for a group given a mode.
  *
  * @param   string  $group  The cache data group.
  * @param   string  $mode   The mode for cleaning cache [group|notgroup].
  * group mode    : cleans all cache in the group
  * notgroup mode : cleans all cache not in the group
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   11.1
  */
 public function clean($group, $mode = null)
 {
     if (trim($group) == '') {
         $clmode = 'notgroup';
     }
     if ($mode == null) {
         $clmode = 'group';
     }
     switch ($mode) {
         case 'notgroup':
             $clmode = 'notingroup';
             $success = self::$CacheLiteInstance->clean($group, $clmode);
             break;
         case 'group':
             if (is_dir($this->_root . '/' . $group)) {
                 $clmode = $group;
                 self::$CacheLiteInstance->setOption('cacheDir', $this->_root . '/' . $group . '/');
                 $success = self::$CacheLiteInstance->clean($group, $clmode);
                 Folder::delete($this->_root . '/' . $group);
             } else {
                 $success = true;
             }
             break;
         default:
             if (is_dir($this->_root . '/' . $group)) {
                 $clmode = $group;
                 self::$CacheLiteInstance->setOption('cacheDir', $this->_root . '/' . $group . '/');
                 $success = self::$CacheLiteInstance->clean($group, $clmode);
             } else {
                 $success = true;
             }
             break;
     }
     if ($success == true) {
         return $success;
     } else {
         return false;
     }
 }