本文整理汇总了PHP中Cake\Filesystem\Folder类的典型用法代码示例。如果您正苦于以下问题:PHP Folder类的具体用法?PHP Folder怎么用?PHP Folder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Folder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
/**
* Installing plugin
* @param null $zipPath
* @return array|bool
* @throws CakeException
*/
public function install($zipPath = null)
{
if (!file_exists($zipPath)) {
throw new Exception(__d('spider', 'Invalid plugin file path'));
}
$pluginInfo = $this->getPluginMeta($zipPath);
$pluginHomeDir = App::path('Plugin');
$pluginHomeDir = reset($pluginHomeDir);
$pluginPath = $pluginHomeDir . $pluginInfo->name . DS;
if (is_dir($pluginPath)) {
throw new Exception(__d('spider', 'Plugin already exists'));
}
$Zip = new \ZipArchive();
if ($Zip->open($zipPath) === true) {
new Folder($pluginPath, true);
$Zip->extractTo($pluginPath);
if (!empty($pluginInfo->rootPath)) {
$old = $pluginPath . $pluginInfo->rootPath;
$new = $pluginPath;
$Folder = new Folder($old);
$Folder->move($new);
}
$Zip->close();
return (array) $pluginInfo;
} else {
throw new CakeException(__d('spider', 'Failed to extract plugin'));
}
return false;
}
示例2: testLoadList
/**
* Test plugin load by list.
*
* @return void
*/
public function testLoadList()
{
$Folder = new Folder();
$pluginsDir = APP_ROOT . 'Plugins' . DS;
$TestPlgPath = $pluginsDir . 'PluginTest';
$Folder->create($TestPlgPath, 0777);
new File($TestPlgPath . '/config/bootstrap.php', true);
new File($TestPlgPath . '/config/routes.php', true);
$NoRoutesPlgPath = $pluginsDir . 'NoRoutes';
$Folder->create($NoRoutesPlgPath, 0777);
new File($NoRoutesPlgPath . '/config/bootstrap.php', true);
$NoBootstrapPlgPath = $pluginsDir . 'NoBootstrap';
$Folder->create($NoBootstrapPlgPath, 0777);
new File($NoBootstrapPlgPath . '/config/routes.php', true);
$NoConfigPlgPath = $pluginsDir . 'NoConfig';
$Folder->create($NoConfigPlgPath, 0777);
Plugin::load('Migrations');
Plugin::loadList(['NoConfig', 'NoRoutes', 'PluginTest', 'Migrations', 'NoBootstrap']);
$this->assertTrue(Plugin::loaded('NoBootstrap'));
$this->assertTrue(Plugin::loaded('PluginTest'));
$this->assertTrue(Plugin::loaded('NoRoutes'));
$this->assertTrue(Plugin::loaded('NoConfig'));
// Check virtual paths.
$this->assertSame(1, count(vPath()->getPaths('NoBootstrap:')));
$this->assertSame(1, count(vPath()->getPaths('PluginTest:')));
$this->assertSame(1, count(vPath()->getPaths('NoRoutes:')));
$this->assertSame(1, count(vPath()->getPaths('NoConfig:')));
$Folder->delete($TestPlgPath);
$Folder->delete($NoRoutesPlgPath);
$Folder->delete($NoConfigPlgPath);
$Folder->delete($NoBootstrapPlgPath);
}
示例3: initialize
/**
* Overwrite shell initialize to dynamically load all Queue Related Tasks.
*
* @return void
*/
public function initialize()
{
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$pluginPaths = App::path('Shell/Task', $plugin);
foreach ($pluginPaths as $pluginPath) {
$Folder = new Folder($pluginPath);
$res = $Folder->find('Queue.+Task\\.php');
foreach ($res as &$r) {
$r = $plugin . '.' . basename($r, 'Task.php');
}
$this->tasks = array_merge($this->tasks, $res);
}
}
$paths = App::path('Shell/Task');
foreach ($paths as $path) {
$Folder = new Folder($path);
$res = array_merge($this->tasks, $Folder->find('Queue.+\\.php'));
foreach ($res as &$r) {
$r = basename($r, 'Task.php');
}
$this->tasks = $res;
}
parent::initialize();
$this->QueuedTasks->initConfig();
}
示例4: testPostAutoloadDump
/**
* Test composer post autoload dump event.
*
* @return void
*/
public function testPostAutoloadDump()
{
Plugin::load('DebugKit');
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('TMP')) {
define('TMP', sys_get_temp_dir() . DS);
}
$vendorDir = ROOT . 'vendor';
$webRoot = $vendorDir . '/cakephp/debug_kit/webroot';
$assetsDir = $vendorDir . '/cakephp/debug_kit/assets';
if (!is_dir($webRoot) && is_dir($assetsDir)) {
$debugWebroot = new Folder($assetsDir);
$debugWebroot->copy($webRoot);
$debugWebroot->delete($assetsDir);
}
$composer = new Composer();
/** @var Config $config */
$config = new Config();
$config->merge(['config' => ['vendor-dir' => $vendorDir]]);
$composer->setConfig($config);
/** @var IOInterface $io */
$io = $this->getMock('Composer\\IO\\IOInterface');
$event = new Event('postAutoloadDump', $composer, $io);
Installer::postAutoloadDump($event);
Plugin::unload('DebugKit');
}
示例5: tearDown
/**
* @return void
*/
public function tearDown()
{
parent::tearDown();
$dir = new Folder(TMP . 'lock');
$dir->delete();
unset($this->Lock);
}
示例6: scanFolder
/**
* Scan folder by path.
*
* @param null $path
* @return void|\Cake\Network\Response
*/
public function scanFolder($path = null)
{
if (!$path) {
$path = WWW_ROOT;
}
$Folder = new Folder();
$_path = $this->request->query('path') ? $this->request->query('path') : $path;
if (!is_dir($_path)) {
$Folder->create($_path);
}
$_path = realpath($_path) . DS;
$regex = '/^' . preg_quote(realpath($path), '/') . '/';
if (preg_match($regex, $_path) == false) {
$this->_controller->Flash->error(__d('file_manager', 'Path {0} is restricted', $_path));
return $this->_controller->redirect(['action' => 'browse']);
}
$blacklist = ['.git', '.svn', '.CVS'];
$regex = '/(' . preg_quote(implode('|', $blacklist), '.') . ')/';
if (in_array(basename($_path), $blacklist) || preg_match($regex, $_path)) {
$this->_controller->Flash->error(__d('file_manager', 'Path %s is restricted', $_path));
return $this->_controller->redirect(['action' => 'browse']);
}
$Folder->path = $_path;
$content = $Folder->read();
$this->_controller->set('path', $_path);
$this->_controller->set('content', $content);
}
示例7: beforeMarshal
public function beforeMarshal(Event $event, $data, $options)
{
$config = $this->_config;
foreach ($config['fields'] as $fieldKey => $fieldValue) {
$virtualField = $fieldKey;
$file = $data[$fieldKey];
if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
continue;
}
if (!isset($fieldValue['path'])) {
throw new \LogicException(__('The path for the {0} field is required.', $fieldKey));
}
if (isset($fieldValue['prefix']) && (is_bool($fieldValue['prefix']) || is_string($fieldValue['prefix']))) {
$this->_prefix = $fieldValue['prefix'];
}
$extension = (new File($file['name'], false))->ext();
$uploadPath = $this->_getUploadPath($data, $fieldValue['path'], $extension);
if (!$uploadPath) {
throw new \ErrorException(__('Error to get the uploadPath.'));
}
$folder = new Folder($this->_config['root']);
$folder->create($this->_config['root'] . dirname($uploadPath));
if ($this->_moveFile($data, $file['tmp_name'], $uploadPath, $fieldKey, $fieldValue)) {
if (!$this->_prefix) {
$this->_prefix = '';
}
$data[$fieldKey] = $uploadPath;
}
}
}
示例8: beforeSave
/**
* Check if there is some files to upload and modify the entity before
* it is saved.
*
* At the end, for each files to upload, unset their "virtual" property.
*
* @param Event $event The beforeSave event that was fired.
* @param Entity $entity The entity that is going to be saved.
*
* @throws \LogicException When the path configuration is not set.
* @throws \ErrorException When the function to get the upload path failed.
*
* @return void
*/
public function beforeSave(Event $event, Entity $entity)
{
$config = $this->_config;
foreach ($config['fields'] as $field => $fieldOption) {
$data = $entity->toArray();
$virtualField = $field . $config['suffix'];
if (!isset($data[$virtualField]) || !is_array($data[$virtualField])) {
continue;
}
$file = $entity->get($virtualField);
if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
continue;
}
if (!isset($fieldOption['path'])) {
throw new \LogicException(__('The path for the {0} field is required.', $field));
}
if (isset($fieldOption['prefix']) && (is_bool($fieldOption['prefix']) || is_string($fieldOption['prefix']))) {
$this->_prefix = $fieldOption['prefix'];
}
$extension = (new File($file['name'], false))->ext();
$uploadPath = $this->_getUploadPath($entity, $fieldOption['path'], $extension);
if (!$uploadPath) {
throw new \ErrorException(__('Error to get the uploadPath.'));
}
$folder = new Folder($this->_config['root']);
$folder->create($this->_config['root'] . dirname($uploadPath));
if ($this->_moveFile($entity, $file['tmp_name'], $uploadPath, $field, $fieldOption)) {
if (!$this->_prefix) {
$this->_prefix = '';
}
$entity->set($field, $this->_prefix . $uploadPath);
}
$entity->unsetProperty($virtualField);
}
}
示例9: includeCmsAdminAssets
/**
* Includes all necessary JS code for admin editing of CmsBlocks.
*
* @return void
*/
public function includeCmsAdminAssets()
{
$script = 'var Cms = {AdminWidgetControllers: {}};';
$this->Html->scriptBlock($script, ['block' => true]);
$this->Html->script('Cms.app/lib/AdminWidgetController.js', ['block' => true]);
$availableWidgets = WidgetManager::getAvailableWidgets();
$adminControllers = [];
$folder = new Folder();
foreach ($availableWidgets as $widgetIdentifier) {
$widget = WidgetFactory::identifierFactory($widgetIdentifier);
$webrootPath = $widget->getWebrootPath();
if (!is_dir($webrootPath)) {
continue;
}
$folder->cd($webrootPath . 'js/');
$jsFiles = $folder->read();
if (empty($jsFiles[1])) {
continue;
}
foreach ($jsFiles[1] as $filename) {
if (strpos($filename, 'AdminWidgetController.js') !== false) {
$adminControllers[] = '/cms/widget/' . $widgetIdentifier . '/js/' . $filename;
}
}
}
$this->Html->script($adminControllers, ['block' => true]);
}
示例10: extract
/**
* Extract valid theme archive.
*
* @return $this|void
*/
public function extract()
{
$Zip = $this->zip();
$Theme = ThemeExtension::getInstance();
$name = $this->_attr->get('name');
$path = $Theme->getPath() . $name . DS;
$alias = Plugin::nameToAlias($name);
$isExits = $this->table()->findByAlias($alias)->first();
if (is_dir($path) && $isExits !== null) {
$this->_setOutput(__d('extensions', 'The theme «{0}» already exits.', sprintf('<strong>%s</strong>', $name)));
}
new Folder($path);
$tmp = $this->_request->data($this->_inputName);
$Zip->open($tmp);
$Zip->extractTo($path);
if (!empty($this->_rootPath[$tmp])) {
$old = $path . DS . $this->_rootPath[$tmp];
$new = $path;
$Folder = new Folder($old);
$Folder->move($new);
}
$this->_setResult(true);
$this->_setOutput(__d('extensions', 'The theme «{0}» has bin successful uploaded.', sprintf('<strong>%s</strong>', $name)), true);
return $this;
}
示例11: tearDown
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
$Folder = new Folder($this->Task->path . 'BakeTestApp');
$Folder->delete();
unset($this->Task);
}
示例12: clean
/**
* @return int|null
*/
public function clean()
{
if (!empty($this->args[0])) {
$folder = realpath($this->args[0]);
} else {
$folder = APP;
}
$App = new Folder($folder);
$this->out('Cleaning copyright notices in ' . $folder);
$ext = '.*';
if (!empty($this->params['ext'])) {
$ext = $this->params['ext'];
}
$files = $App->findRecursive('.*\\.' . $ext);
$this->out('Found ' . count($files) . ' files.');
$count = 0;
foreach ($files as $file) {
$this->out('Processing ' . $file, 1, Shell::VERBOSE);
$content = $original = file_get_contents($file);
$content = preg_replace('/\\<\\?php\\s*\\s+\\/\\*\\*\\s*\\s+\\* CakePHP.*\\*\\//msUi', '<?php', $content);
if ($content === $original) {
continue;
}
$count++;
if (empty($this->params['dry-run'])) {
file_put_contents($file, $content);
}
}
$this->out('--------');
$this->out($count . ' files fixed.');
}
示例13: _findTemplates
/**
* Find the paths to all the installed shell templates in the app.
*
* Bake templates are directories under `Template/Bake` path.
* They are listed in this order: app -> plugin -> default
*
* @return array Array of bake templates that are installed.
*/
protected function _findTemplates()
{
$paths = App::path('Template');
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$paths[] = Plugin::classPath($plugin) . 'Template' . DS;
}
$core = current(App::core('Template'));
$Folder = new Folder($core . 'Bake' . DS . 'default');
$contents = $Folder->read();
$templateFolders = $contents[0];
$paths[] = $core;
foreach ($paths as $i => $path) {
$paths[$i] = rtrim($path, DS) . DS;
}
$this->_io->verbose('Found the following bake templates:');
$templates = [];
foreach ($paths as $path) {
$Folder = new Folder($path . 'Bake', false);
$contents = $Folder->read();
$subDirs = $contents[0];
foreach ($subDirs as $dir) {
$Folder = new Folder($path . 'Bake' . DS . $dir);
$contents = $Folder->read();
$subDirs = $contents[0];
if (array_intersect($contents[0], $templateFolders)) {
$templateDir = $path . 'Bake' . DS . $dir . DS;
$templates[$dir] = $templateDir;
$this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
}
}
}
return $templates;
}
示例14: tearDown
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($this->Task);
$Folder = new Folder($this->path);
$Folder->delete();
Plugin::unload();
}
示例15: removeAndCreateFolder
private function removeAndCreateFolder($path)
{
$dir = new Folder($path);
$dir->delete();
$dir->create($path);
$file = new File($path . DS . 'empty');
$file->create();
}