/** * 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); }
/** * Method to get the field options. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { $options = array(); // Initialize some field attributes. $filter = (string) $this->element['filter']; $exclude = (string) $this->element['exclude']; $hideNone = (string) $this->element['hide_none']; $hideDefault = (string) $this->element['hide_default']; // Get the path in which to search for file options. $path = (string) $this->element['directory']; if (!is_dir($path)) { $path = JPATH_ROOT . '/' . $path; } // Prepend some default options based on field attributes. if (!$hideNone) { $options[] = Html::_('select.option', '-1', Text::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname))); } if (!$hideDefault) { $options[] = Html::_('select.option', '', Text::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname))); } // Get a list of folders in the search path with the given filter. $folders = Folder::folders($path, $filter); // Build the options list from the list of folders. if (is_array($folders)) { foreach ($folders as $folder) { // Check to see if the file is in the exclude mask. if ($exclude) { if (preg_match(chr(1) . $exclude . chr(1), $folder)) { continue; } } $options[] = Html::_('select.option', $folder, $folder); } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Tests the Folder::folders method for an exception. * * @return void * * @covers Joomla\Filesystem\Folder::folders * @expectedException \UnexpectedValueException */ public function testFoldersException() { Folder::folders('this/is/not/a/path'); }
/** * Tests the Folder::folders method. * * @return void * * @since 1.0 * * @covers Joomla\Filesystem\Folder::files * @covers Joomla\Filesystem\Folder::_items */ public function testFolders() { // Make sure previous test files are cleaned up $this->_cleanupTestFiles(); // Create the test folders mkdir(Path::clean(__DIR__ . '/tmp/test'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo1'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo1/bar1'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo1/bar2'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo2'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo2/bar1'), 0777, true); mkdir(Path::clean(__DIR__ . '/tmp/test/foo2/bar2'), 0777, true); $this->assertEquals(array(), Folder::folders(Path::clean(__DIR__ . '/tmp/test'), 'bar1', true, true, array('foo1', 'foo2'))); // Use of realpath to ensure test works for on all platforms $result = Folder::folders(Path::clean(__DIR__ . '/tmp/test'), 'bar1', true, true, array('foo1')); $result[0] = realpath($result[0]); $this->assertEquals(array(Path::clean(__DIR__ . '/tmp/test/foo2/bar1')), $result); // Use of realpath to ensure test works for on all platforms $result = Folder::folders(Path::clean(__DIR__ . '/tmp/test'), 'bar1', true, true); $result[0] = realpath($result[0]); $result[1] = realpath($result[1]); $this->assertEquals(array(Path::clean(__DIR__ . '/tmp/test/foo1/bar1'), Path::clean(__DIR__ . '/tmp/test/foo2/bar1')), $result); // Use of realpath to ensure test works for on all platforms $result = Folder::folders(Path::clean(__DIR__ . '/tmp/test'), 'bar', true, true); $result[0] = realpath($result[0]); $result[1] = realpath($result[1]); $result[2] = realpath($result[2]); $result[3] = realpath($result[3]); $this->assertEquals(array(Path::clean(__DIR__ . '/tmp/test/foo1/bar1'), Path::clean(__DIR__ . '/tmp/test/foo1/bar2'), Path::clean(__DIR__ . '/tmp/test/foo2/bar1'), Path::clean(__DIR__ . '/tmp/test/foo2/bar2')), $result); // Use of realpath to ensure test works for on all platforms $result = Folder::folders(Path::clean(__DIR__ . '/tmp/test'), '.', true, true); $result[0] = realpath($result[0]); $result[1] = realpath($result[1]); $result[2] = realpath($result[2]); $result[3] = realpath($result[3]); $result[4] = realpath($result[4]); $result[5] = realpath($result[5]); $this->assertEquals(array(Path::clean(__DIR__ . '/tmp/test/foo1'), Path::clean(__DIR__ . '/tmp/test/foo1/bar1'), Path::clean(__DIR__ . '/tmp/test/foo1/bar2'), Path::clean(__DIR__ . '/tmp/test/foo2'), Path::clean(__DIR__ . '/tmp/test/foo2/bar1'), Path::clean(__DIR__ . '/tmp/test/foo2/bar2')), $result); $this->assertEquals(array(Path::clean('bar1'), Path::clean('bar1'), Path::clean('bar2'), Path::clean('bar2'), Path::clean('foo1'), Path::clean('foo2')), Folder::folders(Path::clean(__DIR__ . '/tmp/test'), '.', true, false)); // Use of realpath to ensure test works for on all platforms $result = Folder::folders(Path::clean(__DIR__ . '/tmp/test'), '.', false, true); $result[0] = realpath($result[0]); $result[1] = realpath($result[1]); $this->assertEquals(array(Path::clean(__DIR__ . '/tmp/test/foo1'), Path::clean(__DIR__ . '/tmp/test/foo2')), $result); $this->assertEquals(array(Path::clean('foo1'), Path::clean('foo2')), Folder::folders(Path::clean(__DIR__ . '/tmp/test'), '.', false, false, array(), array())); $this->assertFalse(Folder::folders('this/is/not/a/path'), 'Line: ' . __LINE__ . ' Non-existent path should return false'); // Clean up the folders rmdir(Path::clean(__DIR__ . '/tmp/test/foo2/bar2')); rmdir(Path::clean(__DIR__ . '/tmp/test/foo2/bar1')); rmdir(Path::clean(__DIR__ . '/tmp/test/foo2')); rmdir(Path::clean(__DIR__ . '/tmp/test/foo1/bar2')); rmdir(Path::clean(__DIR__ . '/tmp/test/foo1/bar1')); rmdir(Path::clean(__DIR__ . '/tmp/test/foo1')); rmdir(Path::clean(__DIR__ . '/tmp/test')); }
public static function getLanguages() { jimport('joomla.filesystem.folder'); $dirs = Folder::folders(JPATH_SITE . "/language"); $ret = array(); if (count($dirs) > 0) { foreach ($dirs as $lang) { $ret[$lang] = $lang; } } return $ret; }