本文整理汇总了PHP中Cake\Filesystem\Folder::isAbsolute方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::isAbsolute方法的具体用法?PHP Folder::isAbsolute怎么用?PHP Folder::isAbsolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\Folder
的用法示例。
在下文中一共展示了Folder::isAbsolute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Checks that given project path does not already exist, and
* finds the app directory in it. Then it calls bake() with that information.
*
* @return mixed
*/
public function main()
{
$project = null;
if (isset($this->args[0])) {
$project = $this->args[0];
} else {
$appContents = array_diff(scandir(APP), ['.', '..']);
if (empty($appContents)) {
$suggestedPath = rtrim(APP, DS);
} else {
$suggestedPath = APP . 'MyApp';
}
}
while (!$project) {
$prompt = 'What is the path to the project you want to bake?';
$project = $this->in($prompt, null, $suggestedPath);
}
$namespace = basename($project);
if (!preg_match('/^\\w[\\w\\d_]+$/', $namespace)) {
$err = 'Project Name/Namespace must start with a letter' . ' and can only contain letters, digits and underscore';
$this->err($err);
$this->args = [];
return $this->main();
}
if ($project && !Folder::isAbsolute($project) && isset($_SERVER['PWD'])) {
$project = $_SERVER['PWD'] . DS . $project;
}
$response = false;
$bootstrapPath = '..' . DS . 'config' . DS . 'boostrap.php';
while (!$response && is_dir($project) === true && file_exists($project . $boostrapPath)) {
$prompt = sprintf('<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
$response = $this->in($prompt, ['y', 'n'], 'n');
if (strtolower($response) === 'n') {
$response = $project = false;
}
}
if ($project === false) {
$this->out('Aborting project creation.');
return;
}
if ($this->bake($project)) {
$this->out('<success>Project baked successfully!</success>');
return $project;
}
}
示例2: __construct
/**
* Construct.
* It sets the origin file.
*
* If the origin is relative, it will be relative to `APP/webroot/img`.
* @param string $origin Origin file
* @return \Thumbs\Utility\ThumbCreator
* @throws InternalErrorException
* @uses $height
* @uses $origin
* @uses $width
* @uses _downloadTemporary()
*/
public function __construct($origin)
{
//If the origin is a remote file, downloads as temporary file
if (isUrl($origin)) {
$origin = $this->_downloadTemporary($origin);
//If it's a local file, can be relative to `APP/webroot/img/`
} elseif (!Folder::isAbsolute($origin)) {
$origin = WWW_ROOT . 'img' . DS . $origin;
}
//Checks if is readable
if (!is_readable($origin)) {
throw new NotFoundException(__d('thumbs', 'File or directory {0} not readable', $origin));
}
//Checks if has a valid extension
if (!in_array(extension($origin), ['gif', 'jpg', 'jpeg', 'png'])) {
throw new InternalErrorException(__d('thumbs', 'The file {0} is not an image', $origin));
}
//Sets path, width and height of the origin file
$this->origin = $origin;
$this->width = getimagesize($origin)[0];
$this->height = getimagesize($origin)[1];
return $this;
}
示例3: main
/**
* main method
*
* @param string $tempDir an other directory to clear of all folders and files, if desired
* @return void
*/
public function main($tempDir = null)
{
if (empty($tempDir)) {
$tempDir = Configure::read('Attachments.tmpUploadsPath');
}
if (!Folder::isAbsolute($tempDir)) {
$this->out('The path must be absolute, "' . $tempDir . '" given.');
exit;
}
$Folder = new Folder();
if ($Folder->cd($tempDir) === false) {
$this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
exit;
}
$dir = new Folder($tempDir);
$folders = $dir->read();
$files = $dir->findRecursive();
$deletedFiles = 0;
$deletedFolders = 0;
$this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
foreach ($files as $filePath) {
$file = new File($filePath);
// only delete if last change is longer than 24 hours ago
if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
$deletedFiles++;
}
$file->close();
}
foreach ($folders[0] as $folderName) {
$folder = new Folder($dir->pwd() . $folderName);
// only delete if folder is empty
if ($folder->dirsize() === 0 && $folder->delete()) {
$deletedFolders++;
}
}
$this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
}
示例4: realpath
/**
* Get the real path (taking ".." and such into account)
*
* @param string $path Path to resolve
* @return string The resolved path
*/
public function realpath($path)
{
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
$parts = explode(DIRECTORY_SEPARATOR, $path);
$newparts = [];
$newpath = '';
if ($path[0] === DIRECTORY_SEPARATOR) {
$newpath = DIRECTORY_SEPARATOR;
}
while (($part = array_shift($parts)) !== null) {
if ($part === '.' || $part === '') {
continue;
}
if ($part === '..') {
if (!empty($newparts)) {
array_pop($newparts);
continue;
}
return false;
}
$newparts[] = $part;
}
$newpath .= implode(DIRECTORY_SEPARATOR, $newparts);
return Folder::slashTerm($newpath);
}
示例5: filename
/**
* Sets the filename where to export the database
* @param string $filename Filename path
* @return string Filename path
* @throws InternalErrorException
* @uses compression()
* @uses $filename
*/
public function filename($filename)
{
if (!\Cake\Filesystem\Folder::isAbsolute($filename)) {
$filename = BACKUPS . DS . $filename;
}
if (!is_readable($filename)) {
throw new InternalErrorException(__d('database_backup', 'File or directory {0} not readable', $filename));
}
//Checks if the file has an extension
if (!preg_match('/\\.(.+)$/', pathinfo($filename, PATHINFO_BASENAME), $matches)) {
throw new InternalErrorException(__d('database_backup', 'Invalid file extension'));
}
$this->compression(getCompression($matches[1]));
return $this->filename = $filename;
}
示例6: testIsAbsolute
/**
* testIsAbsolute method
*
* @return void
*/
public function testIsAbsolute()
{
$this->assertFalse(Folder::isAbsolute('path/to/file'));
$this->assertFalse(Folder::isAbsolute('cake/'));
$this->assertFalse(Folder::isAbsolute('path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('\\path/to/file'));
$this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
$this->assertFalse(Folder::isAbsolute('notRegisteredStreamWrapper://example'));
$this->assertFalse(Folder::isAbsolute('://example'));
$this->assertTrue(Folder::isAbsolute('/usr/local'));
$this->assertTrue(Folder::isAbsolute('//path/to/file'));
$this->assertTrue(Folder::isAbsolute('C:\\cake'));
$this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
$this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
$this->assertTrue(Folder::isAbsolute('http://www.example.com'));
}
示例7: import
/**
* Imports a database backup
* @param string $filename Filename
* @return void
* @uses DatabaseBackup\Utility\BackupImport::filename()
* @uses DatabaseBackup\Utility\BackupImport::import()
*/
public function import($filename)
{
//The filename can be relative to the APP root
if (!Folder::isAbsolute($filename)) {
$filename = ROOT . DS . $filename;
}
try {
$backup = new \DatabaseBackup\Utility\BackupImport();
$backup->filename($filename);
//Imports the backup file
$file = $backup->import();
$this->success(__d('database_backup', 'The backup {0} has been imported', $file));
} catch (InternalErrorException $e) {
$this->abort($e->getMessage());
}
}