本文整理汇总了PHP中Folder::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::exists方法的具体用法?PHP Folder::exists怎么用?PHP Folder::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the instance of a given hook
*
* @param string $namespace The namespace (addon/aspect) calling the hook
* @param string $hook Name of hook
* @param string $type Cumulative/replace/call
* @param mixed $return Pass-through values
* @param mixed $data Data to pass to hooked method
* @return mixed
*/
public static function run($namespace, $hook, $type = NULL, $return = NULL, $data = NULL)
{
// @Todo: Clean this up globally
$addons_path = BASE_PATH . Config::getAddOnsPath();
if (Folder::exists($addons_path) && Folder::exists(APP_PATH . '/core/tags')) {
$finder = new Finder();
$files = $finder->files()->in($addons_path)->in(APP_PATH . '/core/tags')->name("hooks.*.php");
foreach ($files as $file) {
require_once $file->getRealPath();
$class_name = 'Hooks_' . $file->getRelativePath();
$hook_class = new $class_name();
$method = $namespace . '__' . $hook;
if (!method_exists($hook_class, $method)) {
continue;
}
if ($type == 'cumulative') {
$response = $hook_class->{$method}($data);
if (is_array($response)) {
$return = is_array($return) ? $return + $response : $response;
} else {
$return .= $response;
}
} elseif ($type == 'replace') {
$return = $hook_class->{$method}($data);
} else {
$hook_class->{$method}($data);
}
}
} else {
Log::error('Add-ons path not found', 'hooks');
}
return $return;
}
示例2: unlink
public function unlink()
{
$f = new Folder($this->temp);
$f->create();
$f->unlink();
$this->assertFalse($f->exists());
}
示例3: newFile
public function newFile($name, $contents)
{
$file = new File($this->t, $name);
$path = new Folder($file->getPath());
$path->exists() || $path->create();
$file->out()->write($contents);
}
示例4: __construct
/**
* Constructor
*
* @param io.Folder folder
* @throws lang.IllegalArgumentException if the given folder does not exist
*/
public function __construct(Folder $folder)
{
if (!$folder->exists()) {
throw new IllegalArgumentException('Folder "' . $folder->getURI() . '" does not exist!');
}
$this->folder = $folder;
}
示例5: getFiles
public function getFiles($formset, $path, $extension = "yaml")
{
if (!Folder::exists($path)) {
return array();
}
$finder = new Finder();
$matches = $finder->name("*." . $extension)->depth(0)->files()->followLinks()->in($path);
$files = array();
foreach ($matches as $file) {
$file_data = Parse::yaml($file->getContents());
$file_data['datestamp'] = date($this->config['datestamp_format'], $file->getMTime());
$meta = array('path' => $file->getRealpath(), 'filename' => $file->getFilename(), 'formset' => $formset, 'extension' => $file->getExtension(), 'datestamp' => $file->getMTime());
$data = array('meta' => $meta, 'fields' => $file_data);
$files[] = $data;
}
return array_reverse($files);
}
示例6: getFiles
public function getFiles($formset, $path, $extension = "yaml")
{
if (!Folder::exists($path)) {
return array();
}
$finder = new Finder();
$matches = $finder->name("*." . $extension)->depth(0)->files()->followLinks()->in($path);
$files = array();
foreach ($matches as $file) {
// Ignore page.md
if ($file->getFilename() == 'page.md') {
continue;
}
$file_data = Parse::yaml($file->getContents());
$file_data['datestamp'] = date(array_get($this->config, 'datestamp_format', "m/d/Y"), $file->getMTime());
$meta = array('path' => $file->getRealpath(), 'filename' => $file->getFilename(), 'formset' => $formset, 'extension' => $file->getExtension(), 'datestamp' => $file->getMTime());
$meta['edit_path'] = Path::trimSlashes(Path::trimFileSystemFromContent(substr($meta['path'], 0, -1 - strlen($meta['extension']))));
$data = array('meta' => $meta, 'fields' => $file_data);
$files[] = $data;
}
return array_reverse($files);
}
示例7: perform
/**
* Execute action
*
* @return int
*/
public function perform()
{
$this->archive->open(ARCHIVE_READ);
$args = $this->getArguments();
while ($entry = $this->archive->getEntry()) {
if (!$this->_filter($entry, $args)) {
continue;
}
$f = new File($entry);
$data = $this->archive->extract($entry);
if (!($this->options & Options::SIMULATE)) {
// Create folder on demand. Note that inside a XAR, the directory
// separator is *ALWAYS* a forward slash, so we need to change
// it to whatever the OS we're currently running on uses.
$dir = new Folder(str_replace('/', DIRECTORY_SEPARATOR, dirname($entry)));
if (!$dir->exists()) {
$dir->create();
}
FileUtil::setContents($f, $data);
}
$this->options & Options::VERBOSE && $this->out->writeLinef('%10s %s', number_format(strlen($data), 0, FALSE, '.'), $entry);
}
$this->archive->close();
}
示例8: folderExists
public function folderExists()
{
return Folder::exists(Path::assemble(BASE_PATH, $this->config['destination']));
}
示例9: list_files
private function list_files($theme_selected)
{
$files = array();
$files[] = new FormFieldSelectChoiceOption('--', '');
$folder = new Folder(PATH_TO_ROOT . $this->templates_path . $theme_selected . $this->tpl_files_path);
foreach ($folder->get_files('`\\.tpl$`') as $file) {
$files[] = new FormFieldSelectChoiceOption($file->get_name(), $file->get_name_without_extension());
}
foreach (ModulesManager::get_activated_modules_map_sorted_by_localized_name() as $id => $module) {
$folder = new Folder(PATH_TO_ROOT . '/' . $module->get_id() . '/templates');
if ($folder->exists()) {
foreach ($folder->get_files('`\\.tpl$`') as $file) {
$files[] = new FormFieldSelectChoiceOption(LangLoader::get_message('module', 'admin-modules-common') . ' ' . ModulesManager::get_module($module->get_id())->get_configuration()->get_name() . ' : ' . $file->get_name(), $module->get_id() . '/' . $file->get_name_without_extension());
}
}
}
$folder = new Folder(PATH_TO_ROOT . '/user/templates');
if ($folder->exists()) {
foreach ($folder->get_files('`\\.tpl$`') as $file) {
$files[] = new FormFieldSelectChoiceOption(LangLoader::get_message('users', 'user-common') . ' : ' . $file->get_name(), 'user/' . $file->get_name_without_extension());
}
}
return $files;
}
示例10: redirect_to_update_script_if_needed
/**
* @desc Redirect to update script when it is present and not installed.
*/
private static function redirect_to_update_script_if_needed()
{
$folder = new Folder(PATH_TO_ROOT . '/update');
if ($folder->exists() && !AppContext::get_request()->get_is_localhost() && version_compare(GeneralConfig::load()->get_phpboost_major_version(), UpdateServices::NEW_KERNEL_VERSION, '<')) {
self::load_dynamic_constants();
AppContext::get_response()->redirect(new Url(HOST . DIR . '/update'));
}
}
示例11: delete_folder
private function delete_folder($folder_name)
{
$folder = new Folder(PATH_TO_ROOT . '/' . $folder_name);
if ($folder->exists()) {
$folder->delete();
}
}
示例12: start
/**
* Entry point
*
* @param text.doclet.RootDoc root
* @return var
*/
public function start(RootDoc $root)
{
$this->processor = new MarkupBuilder();
// Option: API (will be used in title, default: none)
$this->api = $this->option('api');
// Option: Gen (will be used in footer)
$this->gen = $this->option('gen');
// Option: CSS to embed (filename, default: none)
if ($css = $this->option('css')) {
$this->css = FileUtil::getContents(new File($css));
}
// Option: Output folder (default: Current directory, created if non-existant)
$target = new Folder($this->option('output', '.'));
$target->exists() || $target->create();
// Compute hierarchy
Console::write('[');
$this->hierarchy = array();
$seen = array();
while ($this->classes->hasNext()) {
$class = $this->classes->next();
if (isset($seen[$class->qualifiedName()])) {
continue;
}
$seen[$class->qualifiedName()] = TRUE;
$key = $class->containingPackage()->name();
if (!isset($this->hierarchy[$key])) {
$sub = new Folder($target, strtr($key, '.', DIRECTORY_SEPARATOR));
$sub->exists() || $sub->create();
$this->hierarchy[$key] = array('target' => $sub, 'doc' => $class->containingPackage(), 'contents' => array(INTERFACE_CLASS => array(), ORDINARY_CLASS => array(), ENUM_CLASS => array(), EXCEPTION_CLASS => array(), ERROR_CLASS => array()));
}
Console::write('.');
$this->hierarchy[$key]['contents'][$class->classType()][] = $class;
}
// Generate HTML files
Console::write('>');
$this->writeOverview($this->hierarchy, $target)->close();
Console::writeLine($target, ']');
}
示例13: perform
/**
* Perform this action
*
* @param string[] args
*/
public function perform(array $args)
{
$installation = new Installation();
$installation->setBase(new Folder(isset($args[0]) ? $args[0] : dirname(Runtime::getInstance()->bootstrapScript()) . '/..'));
$force = in_array('-f', $args);
with($version = $installation->getVersion());
Console::writeLine('===> Local version ', $version, ' @ ', $installation->getBase());
if (strstr($version, '-dev')) {
Console::writeLine('*** Cannot update development checkouts');
return 2;
}
// Query releases website for newer versions
$c = new HttpConnection(self::UPGRADE_URL);
$r = $c->get(new RequestData($version));
switch ($r->getStatusCode()) {
case HttpConstants::STATUS_OK:
case HttpConstants::STATUS_NOT_EXTENDED:
Console::writeLine('*** ', $this->readLine($r->getInputStream()));
return 2;
case HttpConstants::STATUS_SEE_OTHER:
$upgrade = $r->getHeader('X-Upgrade-To');
$base = $r->getHeader('Location');
Console::writeLine('---> Upgrading to ', $upgrade, ' (', $base, ')');
$target = new Folder($installation->getBase(), $upgrade);
$target->exists() || $target->create();
// Verify dependencies
$this->extract($base, 'depend', $target);
with($p = new Properties($target->getURI() . 'depend.ini'));
$verify = 1;
$rtversion = phpversion();
$extensions = array_flip(array_map('strtolower', get_loaded_extensions()));
foreach ($p->readSection('php') as $op => $compare) {
if (!version_compare(phpversion(), $compare, $op)) {
$verify &= $this->error('PHP version ' . $op . ' ' . $compare . ' required, have ' . $rtversion);
}
}
foreach ($p->readSection('ext.required') as $ext => $usage) {
if (!isset($extensions[$ext])) {
$verify &= $this->error('PHP Extension ' . $ext . ' required for ' . $usage);
}
}
foreach ($p->readSection('ext.conflict') as $ext => $usage) {
if (isset($extensions[$ext])) {
$verify &= $this->error('PHP Extension ' . $ext . ' conflicts (' . $usage . ')');
}
}
foreach ($p->readSection('ext.optional') as $ext => $usage) {
if (!isset($extensions[$ext])) {
$verify &= $this->error('PHP Extension ' . $ext . ' not found, needed for ' . $usage . ' (ignoring)');
}
}
foreach ($p->readSection('ini') as $setting => $match) {
$value = ini_get($setting);
if (!preg_match($match, $value)) {
$verify &= $this->error('PHP .ini setting ' . $setting . ' needs to match ' . $match . ' (but is ' . $value . ')');
}
}
// Remove depend.ini, finally check if we should continue
create(new File($p->getFilename()))->unlink();
if (!$verify) {
if (!$force) {
return 3;
}
Console::writeLine('!!! Ignoring errors because -f was passed');
}
// Download base, tools, libraries and meta information
$this->extract($base, 'base', $target);
$this->extract($base, 'tools', $target);
$this->extract($base, 'lib', $target);
$this->extract($base, 'meta-inf', $target);
// Verify it works by running the XP Framework core unittests
$tests = array('net.xp_framework.unittest.core.**');
Console::writeLine('---> Running tests with [USE_XP=', $upgrade, ']:');
$rt = Runtime::getInstance();
set_include_path(implode(PATH_SEPARATOR, array(rtrim($target->getURI(), DIRECTORY_SEPARATOR), '', $target->getURI() . 'lib' . DIRECTORY_SEPARATOR . 'xp-net.xp_framework-' . $upgrade . '.xar')));
with($p = $rt->newInstance($rt->startupOptions(), 'class', 'xp.unittest.Runner', $tests));
$p->in->close();
while (!$p->out->eof()) {
Console::writeLine($p->out->readLine());
}
while (!$p->err->eof()) {
Console::writeLine($p->err->readLine());
}
$exit = $p->close();
// Nonzero exit means failure
if (0 !== $exit) {
Console::writeLine('*** Test run failed, please consult above error messsages');
Console::writeLine($p->getCommandLine());
return 2;
}
Console::writeLine('===> Done, installed @ ', $target);
return 0;
default:
throw new IllegalStateException('Unexpected response ' . xp::stringOf($r));
}
//.........这里部分代码省略.........
示例14: loadAddonResource
/**
* Attempts to load an add-on file
*
* @param integer $type Type of add-on file to load
* @param string $addon Add-on to load
* @return Addon
* @throws Exception
*/
public static function loadAddonResource($type, $addon)
{
$folders = Config::getAddOnLocations();
$file = null;
$type_map = array(self::PLUGIN => array('abbreviation' => 'pi', 'name' => 'plugin'), self::FIELDTYPE => array('abbreviation' => 'ft', 'name' => 'fieldtype'), self::HOOKS => array('abbreviation' => 'hooks', 'name' => 'hooks'), self::TASKS => array('abbreviation' => 'tasks', 'name' => 'tasks'), self::MODIFIER => array('abbreviation' => 'mod', 'name' => 'modifier'), self::API => array('abbreviation' => 'api', 'name' => 'API'));
if (!isset($type_map[$type])) {
Log::error("Unknown add-on type.", "API", "Resource");
throw new Exception("Unknown add-on type.");
}
// grab the abbreviation and name
$addon_details = $type_map[$type];
$abbr = $addon_details['abbreviation'];
$name = $addon_details['name'];
// loop through folders looking for addon
foreach ($folders as $folder) {
if (Folder::exists(BASE_PATH . '/' . $folder . $addon) && File::exists(BASE_PATH . '/' . $folder . $addon . '/' . $abbr . '.' . $addon . '.php')) {
$file = $folder . $addon . '/' . $abbr . '.' . $addon . '.php';
break;
}
}
if (!$file) {
Log::error("Could not find files to load the `{$addon}` {$name}.", "API", "Resource");
throw new Exception("Could not find files to load the `{$addon}` {$name}.");
}
$class = ucwords($name) . "_" . $addon;
if (!class_exists($class)) {
throw new ResourceNotFoundException("Improperly formatted {$name} object.");
}
return new $class();
}
示例15: createBreadcrumbJSON
/**
* Creates an array of breadcrumbs for a given Folder, ready to be
* transformed to JSON
*
* @param Folder $folder
* @return array
*/
protected function createBreadcrumbJSON(Folder $folder)
{
$breadcrumbs = array();
while ($folder->exists()) {
$breadcrumbs[] = array('title' => $folder->Title, 'id' => $folder->ID);
$folder = $folder->Parent();
}
$breadcrumbs[] = array('title' => ASSETS_DIR, 'id' => 0);
return array_reverse($breadcrumbs);
}