本文整理汇总了PHP中Symfony\Component\HttpKernel\Kernel::locateResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Kernel::locateResource方法的具体用法?PHP Kernel::locateResource怎么用?PHP Kernel::locateResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Kernel
的用法示例。
在下文中一共展示了Kernel::locateResource方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilters
public function getFilters()
{
$client = new \Mleko\ImageSqueeze\Client\Client();
$squeeze = new \Twig_SimpleFilter('squeeze', function ($path) use($client) {
$path = (string) $path;
if (strlen($path) > 0 && $path[0] === '@') {
$path = $this->kernel->locateResource($path);
}
if (file_exists($path)) {
$inputFile = new \Mleko\ImageSqueeze\Client\File($path);
} else {
$inputFile = new \Mleko\ImageSqueeze\Client\File($path, $this->webRoot);
}
$pathHash = str_pad(base_convert(sha1($path), 16, 36), 31, '0', STR_PAD_LEFT);
$compressedName = implode("/", str_split(substr($pathHash, 0, 6), 1)) . "/" . substr($pathHash, 6);
if (false !== ($dotPosition = strrpos($path, "."))) {
$compressedName .= substr($path, $dotPosition);
}
$newPath = '/cache/image/' . $compressedName;
$fullPath = $this->webRoot . $newPath;
if (!file_exists($fullPath)) {
$newDir = dirname($fullPath);
if (!file_exists($newDir)) {
mkdir($newDir, 0777, true);
}
return $client->shrink($inputFile)->toFile($newPath, $this->webRoot);
}
return new \Mleko\ImageSqueeze\Client\File($newPath, $this->webRoot);
});
return ['squeeze' => $squeeze];
}
示例2: copyTemplates
protected function copyTemplates()
{
$from = $this->kernel->locateResource('@AnimeDbCatalogBundle/Resources/views/');
$to = $this->root_dir . '/Resources/';
// overwrite twig error templates
$this->fs->copy($from . 'errors/error.html.twig', $to . 'TwigBundle/views/Exception/error.html.twig', true);
$this->fs->copy($from . 'errors/error404.html.twig', $to . 'TwigBundle/views/Exception/error404.html.twig', true);
}
示例3: resolveTargetFormType
public function resolveTargetFormType($name)
{
$parts = preg_split('/:/', $name);
$bundleName = $parts[0];
$formType = $parts[1];
$bundlePath = $this->kernel->locateResource(sprintf('@%s', $bundleName));
$path = sprintf('%sForm/Type/%sType.php', $bundlePath, $formType);
return $path;
}
示例4: resolve
protected function resolve($groups, $input)
{
$resolved = array();
if (strpos($input, '@') === false) {
return array($this->webdir . '/' . $input);
}
$cleaned = str_replace('@', '', $input);
if (isset($groups[$cleaned])) {
foreach ($groups[$cleaned]['inputs'] as $candidate) {
$resolved = array_merge($resolved, $this->resolve($groups, $candidate));
}
return $resolved;
}
if (($star = strpos($input, '*')) === false) {
return array($this->kernel->locateResource($input));
} else {
$dir = $this->kernel->locateResource(substr($input, 0, $star));
$it = new \DirectoryIterator($dir);
foreach ($it as $file) {
if ($file->isFile()) {
array_push($resolved, $it->getRealPath());
}
}
}
return $resolved;
}
示例5: let
public function let(IntentDocumentGeneratedEvent $event, RumGeneratorInterface $rumGenerator, Intent $intent, Kernel $kernel)
{
$this->event = $event;
$this->rumGenerator = $rumGenerator;
$this->intent = $intent;
$this->kernel = $kernel;
$this->event->getIntent()->willReturn($this->intent);
$kernel->locateResource('@DonatePaymentBundle/Resources/public/img/sepa-template.jpg')->willReturn(__DIR__ . '/test.jpg');
$this->beConstructedWith($rumGenerator, $kernel);
}
示例6: __construct
/**
* Construct the manager
*
* @param Kernel $kernel
* @param string $path
* @param string $maskBuilder
*/
public function __construct(Kernel $kernel, $path, $maskBuilder)
{
$this->maskBuilder = $maskBuilder;
$path = $kernel->locateResource('@' . $path);
$config = Yaml::parse($path);
$this->config = $config['acl_config'];
$replace = array();
if (isset($config['parameters'])) {
foreach ($config['parameters'] as $k => $v) {
$replace['%' . $k . '%'] = $v;
}
$this->config = $this->replaceParameters($this->config, $replace);
}
return $this->config;
}
示例7: locateResource
public function locateResource($name, $dir = null, $first = true)
{
if (substr($name, 0, 4) == '@Kwc') {
if (!$first) {
throw new \Kwf_Exception_NotYetImplemented();
}
$componentClass = substr($name, 4, strpos($name, '/') - 4);
$name = substr($name, strpos($name, '/') + 1);
$paths = \Kwc_Abstract::getSetting($componentClass, 'parentFilePaths');
foreach ($paths as $path => $cls) {
if (file_exists($path . '/' . $name)) {
return $path . '/' . $name;
}
}
throw new \Kwf_Exception();
} else {
return parent::locateResource($name, $dir, $first);
}
}
示例8: uploadfile
/**
* Returns an UploadedFile based on a source file
* @param string $source
* @return UploadedFile
*/
public function uploadfile($source)
{
$source = $this->kernel->locateResource($source);
return new UploadedFile($source, basename($source));
}
示例9: locateResource
/**
* @param string $name
* @param string $dir
* @param bool $first
* @return string|array
*/
public function locateResource($name, $dir = null, $first = true)
{
return $this->kernel->locateResource($name, $dir, $first);
}
示例10: locateResource
/**
* {@inheritdoc}
*
* @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
*/
public function locateResource($name, $dir = null, $first = true)
{
$themeBundle = $this->container->get('zikula_core.common.theme_engine')->getTheme();
$locations = parent::locateResource($name, $dir, false);
if ($locations && false !== strpos($locations[0], $dir)) {
// if found in $dir (typically app/Resources) return it immediately.
return $locations[0];
}
// add theme path to template locator
// this method functions if the controller uses `@Template` or `ZikulaSpecModule:Foo:index.html.twig` naming scheme
// if `@ZikulaSpecModule/Foo/index.html.twig` (name-spaced) naming scheme is used
// the \Zikula\Bundle\CoreBundle\EventListener\ThemeListener::setUpThemePathOverrides method is used instead
if ($themeBundle && false === strpos($name, $themeBundle->getName())) {
// do not add theme override path to theme files
$customThemePath = $themeBundle->getPath() . '/Resources';
return parent::locateResource($name, $customThemePath, true);
}
return $locations[0];
}