本文整理汇总了PHP中Symfony\Component\Filesystem\Filesystem::chmod方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::chmod方法的具体用法?PHP Filesystem::chmod怎么用?PHP Filesystem::chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Filesystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::chmod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: move
/**
* Move file.
*
* @param string $directory
* @param null|string $name
* @param bool $overwrite
*
* @return File
*/
public function move($directory, $name = null, $overwrite = false)
{
$targetFile = $this->getTargetFile($directory, $name);
$this->fileSystem->rename($this->getPathname(), $targetFile, $overwrite);
$this->fileSystem->chmod($targetFile, 0666, umask());
return $targetFile;
}
示例2: createRequiredFiles
public static function createRequiredFiles(Event $event)
{
$fs = new Filesystem();
$root = static::getDrupalRoot(getcwd());
$dirs = ['modules', 'profiles', 'themes'];
// Required for unit testing
foreach ($dirs as $dir) {
if (!$fs->exists($root . '/' . $dir)) {
$fs->mkdir($root . '/' . $dir);
$fs->touch($root . '/' . $dir . '/.gitkeep');
}
}
// Prepare the settings file for installation
if (!$fs->exists($root . '/sites/default/settings.php')) {
$fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php');
$fs->chmod($root . '/sites/default/settings.php', 0666);
$event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
}
// Prepare the services file for installation
if (!$fs->exists($root . '/sites/default/services.yml')) {
$fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml');
$fs->chmod($root . '/sites/default/services.yml', 0666);
$event->getIO()->write("Create a sites/default/services.yml file with chmod 0666");
}
// Create the files directory with chmod 0777
if (!$fs->exists($root . '/sites/default/files')) {
$oldmask = umask(0);
$fs->mkdir($root . '/sites/default/files', 0777);
umask($oldmask);
$event->getIO()->write("Create a sites/default/files directory with chmod 0777");
}
}
示例3: chmod
/**
* {@inheritdoc}
*/
public function chmod($file, $mode)
{
try {
$this->filesystem->chmod($this->getRealPathName($file), $mode);
return true;
} catch (\Exception $e) {
return false;
}
}
示例4: tearDown
protected function tearDown()
{
parent::tearDown();
$this->filesystem->chmod(self::REMOTE_REPOSITORY_DIRECTORY, 0777, 00, true);
$this->filesystem->remove(self::REMOTE_REPOSITORY_DIRECTORY);
if (is_dir(self::LOCAL_REPOSITORY_DIRECTORY)) {
$this->filesystem->chmod(self::LOCAL_REPOSITORY_DIRECTORY, 0777, 00, true);
$this->filesystem->remove(self::LOCAL_REPOSITORY_DIRECTORY);
}
}
示例5: ensureWritable
/**
* @param int $mode
* @throws IOException
* @return Dir
*/
protected function ensureWritable($mode = 0777)
{
try {
$this->io->mkdir($this->dir, $mode);
$this->io->chmod($this->dir, $mode, 00, TRUE);
} catch (SfException $e) {
throw new IOException("Please make directory '{$this->dir}' writable, it cannot be done automatically", 0, $e);
}
return $this;
}
示例6: execute
/**
* @override \ComponentManager\Step\Step
*
* @param \ComponentManager\Task\InstallTask $task
*/
public function execute($task, LoggerInterface $logger)
{
$resolvedComponentVersions = $task->getResolvedComponentVersions();
foreach ($resolvedComponentVersions as $resolvedComponentVersion) {
$logger->info('Installing component', ['component' => $resolvedComponentVersion->getComponent()->getName(), 'packageRepository' => $resolvedComponentVersion->getPackageRepository()->getName(), 'version' => $resolvedComponentVersion->getVersion()->getVersion(), 'release' => $resolvedComponentVersion->getVersion()->getRelease()]);
$projectLockFile = $this->project->getProjectLockFile();
$component = $resolvedComponentVersion->getComponent();
$packageSource = $this->project->getPackageSource($resolvedComponentVersion->getSpecification()->getPackageSource());
$typeDirectory = $this->moodle->getPluginTypeDirectory($component->getPluginType());
$targetDirectory = $this->platform->joinPaths([$typeDirectory, $component->getPluginName()]);
$tempDirectory = $this->platform->createTempDirectory();
$sourceDirectory = $packageSource->obtainPackage($tempDirectory, $resolvedComponentVersion, $this->filesystem, $logger);
if ($resolvedComponentVersion->getFinalVersion() === null) {
$logger->warning('Package source did not indicate final version; defaulting to desired version', ['version' => $resolvedComponentVersion->getVersion()->getVersion()]);
$resolvedComponentVersion->setFinalVersion($resolvedComponentVersion->getVersion()->getVersion());
}
$logger->debug('Downloaded component source', ['packageSource' => $packageSource->getName(), 'sourceDirectory' => $sourceDirectory]);
if ($this->filesystem->exists($targetDirectory)) {
$logger->info('Component directory already exists; removing', ['targetDirectory' => $targetDirectory]);
$this->filesystem->remove($targetDirectory);
}
$logger->info('Copying component source to Moodle directory', ['sourceDirectory' => $sourceDirectory, 'targetDirectory' => $targetDirectory]);
$this->filesystem->mirror($sourceDirectory, $targetDirectory);
$logger->info('Pinning component at installed final version', ['finalVersion' => $resolvedComponentVersion->getFinalVersion()]);
$projectLockFile->addResolvedComponentVersion($resolvedComponentVersion);
$logger->info('Cleaning up after component installation', ['tempDirectory' => $tempDirectory]);
try {
$this->filesystem->chmod([$tempDirectory], 0750, 00, true);
$this->filesystem->remove([$tempDirectory]);
} catch (IOException $e) {
$logger->warning('Unable to clean up temporary directory', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'tempDirectory' => $tempDirectory]);
}
}
}
示例7: compileContainer
/**
* Creates the container file from the discovered providers.
*
* @param Discovery $discovery
*/
public static function compileContainer(Discovery $discovery)
{
$containerFile = self::getContainerFilePath();
$compiler = new Compiler();
$bindings = $discovery->findBindings('container-interop/DefinitionProviderFactories');
$definitionProviders = [];
$priorities = [];
foreach ($bindings as $binding) {
/* @var $binding ClassBinding */
$definitionProviderFactoryClassName = $binding->getClassName();
// From the factory class name, let's call the buildDefinitionProvider static method to get the definitionProvider.
$definitionProviders[] = call_user_func([$definitionProviderFactoryClassName, 'buildDefinitionProvider'], $discovery);
$priorities[] = $binding->getParameterValue('priority');
}
// Sort definition providers according to their priorities.
array_multisort($priorities, $definitionProviders);
foreach ($definitionProviders as $provider) {
$compiler->register($provider);
}
$containerFileContent = $compiler->compile('\\TheCodingMachine\\Yaco\\Container');
$filesystem = new Filesystem();
if (!$filesystem->exists(dirname($containerFile))) {
$filesystem->mkdir(dirname($containerFile));
}
$filesystem->dumpFile($containerFile, $containerFileContent);
$filesystem->chmod($containerFile, 0664);
}
示例8: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$gitHooksPath = $this->paths()->getGitHooksDir();
$resourceHooksPath = $this->paths()->getGitHookTemplatesDir() . $this->grumPHP->getHooksPreset();
$resourceHooksPath = $this->paths()->getPathWithTrailingSlash($resourceHooksPath);
$customHooksPath = $this->paths()->getPathWithTrailingSlash($this->grumPHP->getHooksDir());
// Some git clients to not automatically create a git hooks folder.
if (!$this->filesystem->exists($gitHooksPath)) {
$this->filesystem->mkdir($gitHooksPath);
$output->writeln(sprintf('<fg=yellow>Created git hooks folder at: %s</fg=yellow>', $gitHooksPath));
}
foreach (self::$hooks as $hook) {
$gitHook = $gitHooksPath . $hook;
$hookTemplate = $resourceHooksPath . $hook;
if ($customHooksPath && $this->filesystem->exists($customHooksPath . $hook)) {
$hookTemplate = $customHooksPath . $hook;
}
if (!$this->filesystem->exists($hookTemplate)) {
throw new \RuntimeException(sprintf('Could not find hook template for %s at %s.', $hook, $hookTemplate));
}
$content = $this->parseHookBody($hook, $hookTemplate);
file_put_contents($gitHook, $content);
$this->filesystem->chmod($gitHook, 0775);
}
$output->writeln('<fg=yellow>Watch out! GrumPHP is sniffing your commits!<fg=yellow>');
}
示例9: installHooks
/**
* @return int 0 if OK, 1 if ERROR
*/
public function installHooks()
{
try {
if (!$this->filesystem->exists($this->hooksDestinationPath)) {
$this->filesystem->mkdir($this->hooksDestinationPath);
}
$hooks = [];
foreach (new \DirectoryIterator($this->hooksSourcePath) as $hook) {
if ($hook->isDot()) {
continue;
}
$hooks[] = $hook->getFilename();
}
$this->progressBarInit(count($hooks));
foreach ($hooks as $hook) {
$sourceFile = $this->hooksSourcePath . '/' . $hook;
$destinationFile = $this->hooksDestinationPath . '/' . $hook;
$this->backupHook($destinationFile);
$this->filesystem->copy($sourceFile, $destinationFile, true);
$this->filesystem->chmod($destinationFile, 0755);
$this->progressBarAdvance();
$this->outputWriteln(" <info>Copying {$sourceFile} to {$destinationFile}</info>", true);
}
$this->progressBarFinish();
$this->outputWriteln('');
$this->outputWriteln(sprintf('<info>Hooks installed succesfully %s</info>', Constants::CHARACTER_THUMB_UP));
} catch (\Exception $e) {
$this->outputWriteln(" <error>" . $e->getMessage() . " Aborting</error>");
return 1;
}
return 0;
}
示例10: create
/**
* Loads a container and returns it.
*
* If the cache file for the service container exists and is current, it
* will be loaded and returned. Otherwise, a new container will be built
* using the configuration file and the provided optional builder. The
* builder will be used to make changes to the service container before
* it is compiled and cached.
*
* It may be important to note that debug mode for the `ConfigCache` class
* is enabled by default. This will ensure that cached configuration files
* are updated whenever they are changed.
*
* @param string $containerCacheFilePath The container cache file path.
* @param callable $containerBuilderCallable The new container builder callable.
* @param string $compiledContainerClassName The compiled container class name.
* @param boolean $debug Is debugging mode enabled?
*
* @return Jarvis The loaded application.
*/
public static function create($containerCacheFilePath, callable $containerBuilderCallable = null, $compiledContainerClassName = 'AppCachedContainer', $debug = true)
{
$cacheManager = new ConfigCache($containerCacheFilePath, $debug);
if (!$cacheManager->isFresh()) {
$container = static::createContainer();
if (null !== $containerBuilderCallable) {
$containerBuilderCallable($container);
}
if ($debug) {
$filename = pathinfo($containerCacheFilePath, PATHINFO_DIRNAME) . '/' . pathinfo($containerCacheFilePath, PATHINFO_FILENAME) . '.xml';
$container->setParameter('debug.container.dump', $filename);
}
$container->compile();
$dumper = new PhpDumper($container);
$cacheManager->write($dumper->dump(array('class' => $compiledContainerClassName)), $container->getResources());
if ($debug) {
$filename = $container->getParameter('debug.container.dump');
$dumper = new XmlDumper($container);
$filesystem = new Filesystem();
$filesystem->dumpFile($filename, $dumper->dump(), null);
try {
$filesystem->chmod($filename, 0666, umask());
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
}
if (!class_exists($compiledContainerClassName)) {
/** @noinspection PhpIncludeInspection */
require $containerCacheFilePath;
}
return new Jarvis(new $compiledContainerClassName());
}
示例11: upgrade
/**
* @param string $currentRevision
* @param string $distantRevision
*/
protected function upgrade($currentRevision, $distantRevision)
{
$fs = new Filesystem();
$versionDir = sprintf('%s/versions', $this->config->get('twgit.protected.global.root_dir'));
if (!is_dir($versionDir)) {
mkdir($versionDir, 0755);
}
$newPharFile = sprintf('%s/twgit-%s.phar', $versionDir, $distantRevision);
$oldPharFile = sprintf('%s/twgit-%s.phar-old', $versionDir, $currentRevision);
$currentPharFile = realpath(str_replace(['phar://', '/src/NMR/Command'], ['', ''], __DIR__));
$this->getLogger()->info('Download new version...');
$this->getClient()->get(self::REMOTE_URL_PHAR, ['save_to' => $newPharFile]);
if ($fs->exists($newPharFile)) {
$this->getLogger()->info('Backup current version...');
if ($fs->exists($oldPharFile)) {
$fs->remove($oldPharFile);
}
$fs->rename($currentPharFile, $oldPharFile);
$this->getLogger()->info('Install new version...');
$fs->remove($currentPharFile);
$fs->rename($newPharFile, $currentPharFile);
$fs->chmod($currentPharFile, 0777);
} else {
$this->getLogger()->error('Failed to download new version.');
}
}
示例12: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws Exception
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$fs = new Filesystem();
$localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
$tmpDir = dirname($localFilename);
$tmpFilename = 'forge-cli-tmp.phar';
$tmpFilepath = $tmpDir . '/' . $tmpFilename;
if (!is_writable($tmpDir)) {
throw new Exception('Forge update failed: "' . $tmpDir . '" is not writable. Try `sudo !!`.');
}
if (!is_writable($localFilename)) {
throw new Exception('Forge update failed: "' . $localFilename . '" is not writable. Try `sudo !!`.');
}
$output->writeln('<info>Updating ' . $localFilename . '...</info>');
$file = file_get_contents(self::SRC, false, $this->createStreamContext($output));
$fs->dumpFile($tmpFilepath, $file, true);
if ($fs->exists($tmpFilepath)) {
$fs->rename($tmpFilepath, $localFilename, true);
$fs->remove($tmpFilepath);
$fs->chmod($localFilename, 0777);
$output->writeln('<info>Update completed!</info>');
} else {
throw new Exception('Update Failed...');
}
}
示例13: tearDown
protected function tearDown()
{
parent::tearDown();
$filesystem = new Filesystem();
// Ensure all files in the directory are writable before removing
$filesystem->chmod($this->tempDir, 0755, 00, true);
$filesystem->remove($this->tempDir);
}
示例14: createDirectories
/**
* Create default directories for domain.
*
* @param Domain $domain
*/
public function createDirectories(Domain $domain)
{
$fs = new Filesystem();
$dirs = array_merge(array($domain->getPath()), $this->_getDefaultDirs($domain->getPath()));
$fs->mkdir($dirs, 0750);
$fs->chmod($dirs, 0750);
$this->_changeDirectoryOwner($domain);
}
示例15: chmod
protected static function chmod($dir, $mode)
{
$filesystem = new Filesystem();
try {
$filesystem->chmod($dir, $mode);
} catch (\Exception $e) {
}
}