本文整理汇总了PHP中Filesystem::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::exists方法的具体用法?PHP Filesystem::exists怎么用?PHP Filesystem::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFile
/**
* Method for parsing ini files
*
* @param string $filename Path and name of the ini file to parse
*
* @return array Array of strings found in the file, the array indices will be the keys. On failure an empty array will be returned
*
* @since 2.5
*/
public static function parseFile($filename)
{
if (!Filesystem::exists($filename)) {
return array();
}
// Capture hidden PHP errors from the parsing
$version = phpversion();
$php_errormsg = null;
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
if ($version >= '5.3.1') {
$contents = file_get_contents($filename);
$contents = str_replace('_QQ_', '"\\""', $contents);
$strings = @parse_ini_string($contents);
if ($strings === false) {
return array();
}
} else {
$strings = @parse_ini_file($filename);
if ($strings === false) {
return array();
}
if ($version == '5.3.0' && is_array($strings)) {
foreach ($strings as $key => $string) {
$strings[$key] = str_replace('_QQ_', '"', $string);
}
}
}
return $strings;
}
示例2: element
public function element($element, $data = array())
{
$element_path = Filesystem::path('app/views/') . $this->elementName($element);
if (Filesystem::exists($element_path)) {
return $this->renderView($element_path, $data);
} else {
throw new MissingViewException($this->filename($element) . ' could not be found');
}
}
示例3: load
public static function load($name)
{
if (!class_exists($name) && Filesystem::exists('lib/behaviors/' . $name . '.php')) {
require_once 'lib/behaviors/' . $name . '.php';
}
if (!class_exists($name)) {
throw new MissingBehaviorException(array('behavior' => $name));
}
}
示例4: load
public static function load($name)
{
if (!class_exists($name) && Filesystem::exists('lib/helpers/' . $name . '.php')) {
require_once 'lib/helpers/' . $name . '.php';
}
if (!class_exists($name)) {
$message = 'The helper <code>' . $name . '</code> was not found.';
throw new RuntimeException('The helper <code>' . $name . '</code> was not found.');
}
}
示例5: load
public static function load($name)
{
$filename = 'lib/behaviors/' . $name . '.php';
if (!class_exists($name) && Filesystem::exists($filename)) {
require $filename;
}
if (!class_exists($name)) {
throw new RuntimeException('The behavior <code>' . $name . '</code> was not found.');
}
}
示例6: renderTemplate
public function renderTemplate($source, $destination, $data = array())
{
if (!Filesystem::exists($destination)) {
$view = new View();
$content = $view->renderView(Filesystem::path($source), $data);
Filesystem::write($destination, $content);
$this->log('created', $destination);
} else {
$this->log('exists', $destination);
}
}
示例7: refresh
/**
* Method for refreshing the cache in the database with the known language strings
*
* @return boolean True on success, Exception object otherwise
*
* @since 2.5
*/
public function refresh()
{
require_once JPATH_COMPONENT . '/helpers/languages.php';
$app = JFactory::getApplication();
$app->setUserState('com_languages.overrides.cachedtime', null);
// Empty the database cache first
try {
$this->_db->setQuery('TRUNCATE TABLE ' . $this->_db->qn('#__overrider'));
$this->_db->query();
} catch (RuntimeException $e) {
return $e;
}
// Create the insert query
$query = $this->_db->getQuery(true)->insert($this->_db->qn('#__overrider'))->columns('constant, string, file');
// Initialize some variables
$client = $app->getUserState('com_languages.overrides.filter.client', 'site') ? 'administrator' : 'site';
$language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
$base = constant('JPATH_' . strtoupper($client));
$path = $base . '/language/' . $language;
$files = array();
// Parse common language directory
if (Filesystem::exists($path)) {
$files = Filesystem::files($path, $language . '.*ini$', false, true);
}
// Parse language directories of components
$files = array_merge($files, Filesystem::files($base . '/components', $language . '.*ini$', 3, true));
// Parse language directories of modules
$files = array_merge($files, Filesystem::files($base . '/modules', $language . '.*ini$', 3, true));
// Parse language directories of templates
$files = array_merge($files, Filesystem::files($base . '/templates', $language . '.*ini$', 3, true));
// Parse language directories of plugins
$files = array_merge($files, Filesystem::files(JPATH_PLUGINS, $language . '.*ini$', 3, true));
// Parse all found ini files and add the strings to the database cache
foreach ($files as $file) {
$strings = LanguagesHelper::parseFile($file);
if ($strings && count($strings)) {
$query->clear('values');
foreach ($strings as $key => $string) {
$query->values($this->_db->q($key) . ',' . $this->_db->q($string) . ',' . $this->_db->q(JPath::clean($file)));
}
try {
$this->_db->setQuery($query);
if (!$this->_db->query()) {
return new Exception($this->_db->getErrorMsg());
}
} catch (RuntimeException $e) {
return $e;
}
}
}
// Update the cached time
$app->setUserState('com_languages.overrides.cachedtime.' . $client . '.' . $language, time());
return true;
}
示例8:
/**
* Method to get the lang tag
* @return string lang iso tag
*/
function &getLangTag()
{
if (is_null($this->lang_tag)) {
$this->lang_tag = Lang::getTag();
if (!Filesystem::exists(JPATH_BASE . '/help/' . $this->lang_tag)) {
$this->lang_tag = 'en-GB';
// use english as fallback
}
}
return $this->lang_tag;
}
示例9: toString
public function toString()
{
ob_end_clean();
$this->header($this->status);
if (Filesystem::exists('app/views/layouts/error.htm.php')) {
$view = new View();
return $view->renderView('app/views/layouts/error.htm.php', array('exception' => $this));
} else {
echo '<pre>';
throw new Exception('error layout was not found');
}
}
示例10: load
public static function load($name, $instance = false)
{
if (!class_exists($name) && Filesystem::exists('lib/components/' . $name . '.php')) {
require_once 'lib/components/' . $name . '.php';
}
if (class_exists($name)) {
if ($instance) {
return new $name();
} else {
return true;
}
} else {
throw new MissingComponentException(array('component' => $name));
}
}
示例11: load
public static function load($name, $instance = false)
{
if (!class_exists($name) && Filesystem::exists('app/controllers/' . Inflector::underscore($name) . '.php')) {
require_once 'app/controllers/' . Inflector::underscore($name) . '.php';
}
if (class_exists($name)) {
if ($instance) {
return new $name();
} else {
return true;
}
} else {
throw new MissingControllerException(array('controller' => $name));
}
}
示例12: load
public static function load($name)
{
if (!array_key_exists($name, Model::$instances)) {
if (!class_exists($name) && Filesystem::exists('app/models/' . Inflector::underscore($name) . '.php')) {
require_once 'app/models/' . Inflector::underscore($name) . '.php';
}
if (class_exists($name)) {
Model::$instances[$name] = new $name();
Model::$instances[$name]->connection();
Model::$instances[$name]->createLinks();
} else {
throw new MissingModelException(array('model' => $name));
}
}
return Model::$instances[$name];
}
示例13: param
/**
* Registrar parametro do template.
*/
public function param($name, $value = '')
{
// Se foi informado um array
if (is_array($name)) {
foreach ($name as $n => $v) {
$this->param($n, $v);
}
return $this;
}
// Aplicar parâmetro nos filtros
foreach ($this->filters as $filter_file) {
if ($this->files->exists($filter_file) != true) {
error('File %s not found', $filter_file);
}
$buffer = file_get_contents($filter_file);
$buffer = str_replace('{{' . $name . '}}', $value, $buffer);
file_put_contents($filter_file, $buffer);
}
return $this;
}
示例14: getTypeOptionsFromLayouts
protected function getTypeOptionsFromLayouts($component, $view)
{
// Initialise variables.
$options = array();
$layouts = array();
$layoutNames = array();
$templateLayouts = array();
$lang = Lang::getRoot();
// Get the layouts from the view folder.
$path = PATH_CORE . '/components/' . $component . '/views/' . $view . '/tmpl';
$path2 = PATH_CORE . '/components/' . $component . '/site/views/' . $view . '/tmpl';
if (Filesystem::exists($path)) {
$layouts = array_merge($layouts, Filesystem::files($path, '.xml$', false, true));
} else {
if (Filesystem::exists($path2)) {
$layouts = array_merge($layouts, Filesystem::files($path2, '.xml$', false, true));
} else {
return $options;
}
}
// build list of standard layout names
foreach ($layouts as $layout) {
$layout = trim($layout, '/');
// Ignore private layouts.
if (strpos(basename($layout), '_') === false) {
$file = $layout;
// Get the layout name.
$layoutNames[] = Filesystem::name(basename($layout));
}
}
// get the template layouts
// TODO: This should only search one template -- the current template for this item (default of specified)
$folders = Filesystem::directories(JPATH_SITE . '/templates', '', false, true);
// Array to hold association between template file names and templates
$templateName = array();
foreach ($folders as $folder) {
if (Filesystem::exists($folder . '/html/' . $component . '/' . $view)) {
$template = basename($folder);
$lang->load('tpl_' . $template . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $template . '.sys', JPATH_SITE . '/templates/' . $template, null, false, true);
$templateLayouts = Filesystem::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true);
foreach ($templateLayouts as $layout) {
$file = trim($layout, '/');
// Get the layout name.
$templateLayoutName = Filesystem::name(basename($layout));
// add to the list only if it is not a standard layout
if (array_search($templateLayoutName, $layoutNames) === false) {
$layouts[] = $layout;
// Set template name array so we can get the right template for the layout
$templateName[$layout] = basename($folder);
}
}
}
}
// Process the found layouts.
foreach ($layouts as $layout) {
$layout = trim($layout, '/');
// Ignore private layouts.
if (strpos(basename($layout), '_') === false) {
$file = $layout;
// Get the layout name.
$layout = Filesystem::name(basename($layout));
// Create the menu option for the layout.
$o = new \Hubzero\Base\Object();
$o->title = ucfirst($layout);
$o->description = '';
$o->request = array('option' => $component, 'view' => $view);
// Only add the layout request argument if not the default layout.
if ($layout != 'default') {
// If the template is set, add in format template:layout so we save the template name
$o->request['layout'] = isset($templateName[$file]) ? $templateName[$file] . ':' . $layout : $layout;
}
// Load layout metadata if it exists.
if (is_file($file)) {
// Attempt to load the xml file.
if ($xml = simplexml_load_file($file)) {
// Look for the first view node off of the root node.
if ($menu = $xml->xpath('layout[1]')) {
$menu = $menu[0];
// If the view is hidden from the menu, discard it and move on to the next view.
if (!empty($menu['hidden']) && $menu['hidden'] == 'true') {
unset($xml);
unset($o);
continue;
}
// Populate the title and description if they exist.
if (!empty($menu['title'])) {
$o->title = trim((string) $menu['title']);
}
if (!empty($menu->message[0])) {
$o->description = trim((string) $menu->message[0]);
}
}
}
}
// Add the layout to the options array.
$options[] = $o;
}
}
return $options;
}
示例15: uploadTask
/**
* Upload a file or create a new folder
*
* @return void
*/
public function uploadTask()
{
// Check for request forgeries
Request::checkToken();
// Incoming directory (this should be a path built from a resource ID and its creation year/month)
$listdir = Request::getVar('listdir', '', 'post');
if (!$listdir) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR'));
$this->displayTask();
return;
}
// Incoming sub-directory
$subdir = Request::getVar('dirPath', '', 'post');
// Build the path
$path = Utilities::buildUploadPath($listdir, $subdir);
// Are we creating a new folder?
$foldername = Request::getVar('foldername', '', 'post');
if ($foldername != '') {
// Make sure the name is valid
if (preg_match("/[^0-9a-zA-Z_]/i", $foldername)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_INVALID_CHARACTERS'));
} else {
if (!is_dir($path . DS . $foldername)) {
if (!\Filesystem::makeDirectory($path . DS . $foldername)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
}
} else {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_EXISTS'));
}
}
// Directory created
} else {
// Make sure the upload path exist
if (!is_dir($path)) {
if (!\Filesystem::makeDirectory($path)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
$this->displayTask();
return;
}
}
// Incoming file
$file = Request::getVar('upload', '', 'files', 'array');
if (!$file['name']) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_FILE'));
$this->displayTask();
return;
}
// Make the filename safe
$file['name'] = \Filesystem::clean($file['name']);
// Ensure file names fit.
$ext = \Filesystem::extension($file['name']);
$file['name'] = str_replace(' ', '_', $file['name']);
if (strlen($file['name']) > 230) {
$file['name'] = substr($file['name'], 0, 230);
$file['name'] .= '.' . $ext;
}
// Perform the upload
if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UPLOADING'));
} else {
// File was uploaded
// Was the file an archive that needs unzipping?
$batch = Request::getInt('batch', 0, 'post');
if ($batch) {
//build path
$path = rtrim($path, DS) . DS;
$escaped_file = escapeshellarg($path . $file['name']);
//determine command to uncompress
switch ($ext) {
case 'gz':
$cmd = "tar zxvf {$escaped_file} -C {$path}";
break;
case 'tar':
$cmd = "tar xvf {$escaped_file} -C {$path}";
break;
case 'zip':
default:
$cmd = "unzip -o {$escaped_file} -d {$path}";
}
//unzip file
if ($result = shell_exec($cmd)) {
// Remove original archive
\Filesystem::delete($path . $file['name']);
// Remove MACOSX dirs if there
if (\Filesystem::exists($path . '__MACOSX')) {
\Filesystem::deleteDirectory($path . '__MACOSX');
}
//remove ._ files
$dotFiles = \Filesystem::files($path, '._[^\\s]*', true, true);
foreach ($dotFiles as $dotFile) {
\Filesystem::delete($dotFile);
}
}
}
}
//.........这里部分代码省略.........