本文整理汇总了PHP中Webmozart\PathUtil\Path::makeAbsolute方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::makeAbsolute方法的具体用法?PHP Path::makeAbsolute怎么用?PHP Path::makeAbsolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\PathUtil\Path
的用法示例。
在下文中一共展示了Path::makeAbsolute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
$options = array_replace_recursive(self::$defaultOptions, $options);
if (!isset($options['path'])) {
$options['path'] = $targetMethod->getClass()->getDirectory() . '/path-mappings.json';
}
Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
Assert::boolean($options['optimize'], 'The "optimize" option should be a boolean. Got: %s');
Assert::isArray($options['change-stream'], 'The "change-stream" option should be an array. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['root-dir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$relBaseDir = Path::makeRelative($options['root-dir'], $targetMethod->getClass()->getDirectory());
$escPath = '__DIR__.' . var_export('/' . $relPath, true);
$escBaseDir = $relBaseDir ? '__DIR__.' . var_export('/' . $relBaseDir, true) : '__DIR__';
if ($options['optimize']) {
$streamGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::CHANGE_STREAM, $options['change-stream']['type']);
$streamOptions = $options['change-stream'];
$streamOptions['root-dir'] = $options['root-dir'];
$streamGenerator->generateNewInstance('stream', $targetMethod, $generatorRegistry, $streamOptions);
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\OptimizedJsonRepository'));
$targetMethod->addBody(sprintf('$%s = new OptimizedJsonRepository(%s, %s, false, $stream);', $varName, $escPath, $escBaseDir));
} else {
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\JsonRepository'));
$targetMethod->addBody(sprintf('$%s = new JsonRepository(%s, %s, true);', $varName, $escPath, $escBaseDir));
}
}
示例2: installResource
/**
* {@inheritdoc}
*/
public function installResource(Resource $resource, InstallationParams $params)
{
$targetPath = Path::makeAbsolute($params->getTargetLocation(), $params->getRootDirectory());
if (!file_exists($targetPath)) {
mkdir($targetPath, 0777, true);
}
$repoPath = $params->getWebPathForResource($resource);
$parameterValues = $params->getParameterValues();
$relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
$filesystemRepo = new FilesystemRepository($targetPath, $this->symlinks, $relative);
if ('/' === $repoPath) {
foreach ($resource->listChildren() as $child) {
$name = $child->getName();
// If the resource is not attached, the name is empty
if (!$name && $child instanceof FilesystemResource) {
$name = Path::getFilename($child->getFilesystemPath());
}
if ($name) {
$filesystemRepo->remove($repoPath . '/' . $name);
}
}
} else {
$filesystemRepo->remove($repoPath);
}
$filesystemRepo->add($repoPath, $resource);
}
示例3: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
if (!isset($options['path'])) {
$options['path'] = $targetMethod->getClass()->getDirectory() . '/repository';
}
Assert::string($options['path'], 'The "path" option should be a string. Got: %s');
Assert::string($options['rootDir'], 'The "rootDir" option should be a string. Got: %s');
Assert::boolean($options['symlink'], 'The "symlink" option should be a boolean. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['rootDir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$escPath = $relPath ? '__DIR__.' . var_export('/' . $relPath, true) : '__DIR__';
if ($relPath) {
$targetMethod->addBody(<<<EOF
if (!file_exists({$escPath})) {
mkdir({$escPath}, 0777, true);
}
EOF
);
}
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\FilesystemRepository'));
$targetMethod->addBody(sprintf('$%s = new FilesystemRepository(%s, %s);', $varName, $escPath, var_export($options['symlink'], true)));
}
示例4: installResource
/**
* {@inheritdoc}
*/
public function installResource(PuliResource $resource, InstallationParams $params)
{
$documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory());
if (!file_exists($documentRoot)) {
mkdir($documentRoot, 0777, true);
}
$serverPath = $params->getServerPathForResource($resource);
$parameterValues = $params->getParameterValues();
$relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
$filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative);
if ('/' === $serverPath) {
foreach ($resource->listChildren() as $child) {
$name = $child->getName();
// If the resource is not attached, the name is empty
if (!$name && $child instanceof FilesystemResource) {
$name = Path::getFilename($child->getFilesystemPath());
}
if ($name) {
$filesystemRepo->remove($serverPath . '/' . $name);
}
}
} else {
$filesystemRepo->remove($serverPath);
}
// Don't attach the original resource to the repository we just created
$filesystemRepo->add($serverPath, clone $resource);
}
示例5: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
Assert::boolean($options['serialize-strings'], 'The "serialize-strings" option should be a boolean. Got: %s');
Assert::boolean($options['serialize-arrays'], 'The "serialize-arrays" option should be a boolean. Got: %s');
Assert::boolean($options['escape-slash'], 'The "escape-slash" option should be a boolean. Got: %s');
Assert::boolean($options['pretty-print'], 'The "pretty-print" option should be a boolean. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['root-dir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$flags = array();
if (!$options['serialize-strings']) {
$flags[] = 'JsonFileStore::NO_SERIALIZE_STRINGS';
}
if (!$options['serialize-arrays']) {
$flags[] = 'JsonFileStore::NO_SERIALIZE_ARRAYS';
}
if (!$options['serialize-arrays']) {
$flags[] = 'JsonFileStore::NO_ESCAPE_SLASH';
}
if ($options['pretty-print']) {
$flags[] = 'JsonFileStore::PRETTY_PRINT';
}
$targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
$targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s%s%s);', $varName, $flags ? "\n " : '', '__DIR__.' . var_export('/' . $relPath, true), $flags ? ",\n " . implode("\n | ", $flags) . "\n" : ''));
}
示例6: handleAdd
/**
* Handles the "package --add" command.
*
* @param Args $args The console arguments.
*
* @return int The status code.
*/
public function handleAdd(Args $args)
{
$packageName = $args->getArgument('name');
$installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
$installer = $args->getOption('installer');
$this->packageManager->installPackage($installPath, $packageName, $installer);
return 0;
}
示例7: makeConfigPathRelative
/**
* Concat two path member only if the second is not absolute
* and make the result relative to the last parameter.
*/
public static function makeConfigPathRelative($config_path, $option_path, $current_path = null)
{
$current_path = $current_path === null ? getcwd() : $current_path;
$config_path = Path::makeAbsolute($config_path, $current_path);
$absolute_path = Path::makeAbsolute($option_path, $config_path);
$relative_path = Path::makeRelative($absolute_path, $current_path);
return $relative_path === '' ? '.' : $relative_path;
}
示例8: handleInstall
/**
* Handles the "package --install" command.
*
* @param Args $args The console arguments.
*
* @return int The status code.
*/
public function handleInstall(Args $args)
{
$packageName = $args->getArgument('name');
$installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
$installer = $args->getOption('installer');
$env = $args->isOptionSet('dev') ? Environment::DEV : Environment::PROD;
$this->packageManager->installPackage($installPath, $packageName, $installer, $env);
return 0;
}
示例9: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
$path = Path::makeAbsolute($options['path'], $options['rootDir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
$targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s, %s);', $varName, '__DIR__.' . var_export('/' . $relPath, true), $options['cache'] ? 'true' : 'false'));
}
示例10: analyse
/**
* @param string $path
* @param string|null $configFile
* @param AbstractLogger $logger
* @return Result
*/
public function analyse($path, $configFile = null, AbstractLogger $logger = null)
{
$logger = $logger ?: new NullLogger();
$path = Path::makeAbsolute($path, getcwd());
if (!$configFile) {
$configFile = Path::join([$path, '.simpspector.yml']);
}
$config = $this->loader->load($configFile);
return $this->executor->run($path, $config, $logger);
}
示例11: handle
/**
* Handles the "tree" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handle(Args $args, IO $io)
{
$path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
$resource = $this->repo->get($path);
$total = 0;
$io->writeLine('<c1>' . $resource->getPath() . '</c1>');
$this->printTree($io, $resource, $total);
$io->writeLine('');
$io->writeLine($total . ' resources');
return 0;
}
示例12: retrieve
/**
* {@inheritdoc}
*/
public function retrieve($uri)
{
if (isset($this->mappings[$uri])) {
$uri = $this->mappings[$uri];
if (Path::isLocal($uri)) {
$uri = 'file://' . ($this->baseDir ? Path::makeAbsolute($uri, $this->baseDir) : $uri);
}
$this->lastUsedRetriever = $this->filesystemRetriever;
return $this->filesystemRetriever->retrieve($uri);
}
$this->lastUsedRetriever = $this->fallbackRetriever;
return $this->fallbackRetriever->retrieve($uri);
}
示例13: handle
/**
* Handles the "ls" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handle(Args $args, IO $io)
{
$path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
$resource = $this->repo->get($path);
if (!$resource->hasChildren()) {
throw new RuntimeException(sprintf('The resource "%s" does not have children.', $resource->getPath()));
}
if ($args->isOptionSet('long')) {
$this->listLong($io, $resource->listChildren());
} else {
$this->listShort($io, $resource->listChildren());
}
return 0;
}
示例14: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
if (!isset($options['path'])) {
$options['path'] = $targetMethod->getClass()->getDirectory() . '/change-stream.json';
}
Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['root-dir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$escPath = '__DIR__.' . var_export('/' . $relPath, true);
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\ChangeStream\\JsonChangeStream'));
$targetMethod->addBody(sprintf('$%s = new JsonChangeStream(%s);', $varName, $escPath));
}
示例15: handle
/**
* Handles the "ls" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handle(Args $args, IO $io)
{
$path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
$resources = $this->repo->find($path);
if (!count($resources)) {
$io->errorLine("No resources found for path {$path}");
return 1;
}
foreach ($resources as $resource) {
if ($resource instanceof BodyResource) {
$io->writeLine($resource->getBody());
}
}
return 0;
}