本文整理汇总了PHP中Symfony\Component\HttpKernel\Kernel::getBundles方法的典型用法代码示例。如果您正苦于以下问题:PHP Kernel::getBundles方法的具体用法?PHP Kernel::getBundles怎么用?PHP Kernel::getBundles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Kernel
的用法示例。
在下文中一共展示了Kernel::getBundles方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locate
/**
* {@inheritdoc}
*/
public function locate($resource, GeneratorInterface $generator)
{
$bundles = $this->kernel->getBundles();
$class = get_class($generator);
$appResources = $this->kernel->getContainer()->getParameter('kernel.root_dir') . '/Resources/';
$location = "skeleton/{$generator->getName()}/{$resource}";
/** @var Bundle $bundle */
foreach ($bundles as $bundle) {
if (strpos($class, $bundle->getNamespace()) !== false) {
$global = "{$appResources}/{$bundle->getName()}/{$location}";
if (file_exists($global) && is_readable($global)) {
return $global;
} else {
$local = "{$bundle->getPath()}/Resources/{$location}";
if (file_exists($local) && is_readable($local)) {
return $local;
} else {
throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}");
}
}
}
}
$nonBundle = "{$appResources}{$location}";
if (file_exists($nonBundle) && is_readable($nonBundle)) {
return $nonBundle;
}
throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}");
}
示例2: findWebsocketClasses
/**
* @author Krzysztof Bednarczyk
* @return string[]
*/
public function findWebsocketClasses()
{
$dirs = array();
foreach ($this->kernel->getBundles() as $bundle) {
if (in_array($bundle->getName(), $this->blackListedBundles)) {
continue;
}
if (!is_dir($websocketDir = $bundle->getPath() . '/Websocket')) {
continue;
}
$dirs[] = $websocketDir;
}
foreach (Finder::create()->name('*Websocket.php')->in($dirs)->files() as $file) {
$filename = $file->getRealPath();
if (!in_array($filename, $this->blackListedWebsocketFiles)) {
require_once $filename;
}
}
// It is not so important if these controllers never can be reached with
// the current configuration nor whether they are actually controllers.
// Important is only that we do not miss any classes.
return array_filter(get_declared_classes(), function ($name) {
return preg_match('/Websocket\\\\(.+)Websocket$/', $name) > 0;
});
}
示例3: getBundles
/**
* @param null $filter
* @return array|BundleInterface[]
*/
public function getBundles($filter = null)
{
$bundles = $this->kernel->getBundles();
$filterFunction = function (Bundle $bundle) use($filter) {
return strpos($bundle->getName(), $filter) !== false;
};
if (!$filter) {
return $bundles;
} else {
return array_filter($bundles, $filterFunction);
}
}
示例4: loadScripts
/**
* Read scripts info from files
*/
protected function loadScripts()
{
$index = 0;
$scripts = [];
$this->scripts = [];
$rootDir = realpath($this->kernel->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
$bundles = $this->kernel->getBundles();
foreach ($bundles as $bundle) {
$bundleDirName = $bundle->getPath();
$this->getScriptInfo($bundleDirName, $index, $scripts);
$relativePathArray = explode(DIRECTORY_SEPARATOR, str_replace($rootDir, '', $bundleDirName));
if ($relativePathArray[0] == '') {
unset($relativePathArray[0]);
}
for ($i = count($relativePathArray); $i >= 0; $i--) {
unset($relativePathArray[$i]);
$checkPath = $rootDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $relativePathArray);
if ($this->getScriptInfo($checkPath, $index, $scripts)) {
break;
}
}
}
if (!empty($scripts)) {
usort($scripts, array($this, "compareScripts"));
foreach ($scripts as $script) {
$this->scripts[$script['key']] = $script;
}
}
}
示例5: loadBundleGenerators
/**
* Load the generators confirming to default naming rules in all bundles in the given Kernel.
* @param Kernel $kernel
*/
public function loadBundleGenerators(Kernel $kernel)
{
/** @var Bundle $bundle */
foreach ($kernel->getBundles() as $bundle) {
$this->loadGeneratorsForBundle($bundle);
}
}
示例6: symfony2ToBigFoot
/**
* Converti les fichiers de traductions "Symfony2 style" vers les fichiers "Bigfoot style"
*
* @param array $bundles
* @param ProgressBar $progress
*/
public function symfony2ToBigFoot(array $bundles = array(), $progress = null)
{
$newTranslationFiles = array();
$bundles = count($bundles) == 0 ? $this->kernel->getBundles() : $bundles;
foreach ($bundles as $bundle) {
$translationsPath = $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations';
$translationFiles = array();
$this->findTranslationFiles($translationsPath, $translationFiles);
foreach ($translationFiles as $translationFile) {
$pathinfo = pathinfo($translationFile);
$domain = substr($pathinfo['filename'], 0, strrpos($pathinfo['filename'], '.'));
$lang = substr($pathinfo['filename'], strrpos($pathinfo['filename'], '.') + 1);
$parsedTranslations = array();
$translations = Yaml::parse(file_get_contents($translationFile));
// les clefs qui ont au moins 3 niveaux (par exemple foo.bar.baz) sont gérées dans un fichier foo.bar.yml
// les clefs qui ont moins de 3 niveaux sont gérées dans default.yml
foreach ($translations as $key1 => $translation1) {
if (is_array($translation1)) {
foreach ($translation1 as $key2 => $translation2) {
$fileName = $this->getTranslationKey($key1, $key2) . '.yml';
if (array_key_exists($fileName, $newTranslationFiles) == false) {
$newTranslationFiles[$fileName] = array();
}
if (is_array($translation2)) {
$parsedTranslations = array();
$this->parseTranslations(null, $translation2, $parsedTranslations);
foreach ($parsedTranslations as $parsedKey => $parsedTranslation) {
if (array_key_exists($parsedKey, $newTranslationFiles[$fileName]) == false) {
$newTranslationFiles[$fileName][$parsedKey] = array();
if ($domain != 'messages') {
$newTranslationFiles[$fileName][$parsedKey]['domain'] = $domain;
}
$newTranslationFiles[$fileName][$parsedKey]['value'] = array();
}
$newTranslationFiles[$fileName][$parsedKey]['value'][$lang] = $parsedTranslation;
// multiline
if (strpos($parsedTranslation, "\n")) {
$newTranslationFiles[$fileName][$parsedKey]['multiline'] = true;
}
// plural
if (strpos($parsedTranslation, "|")) {
$newTranslationFiles[$fileName][$parsedKey]['plural'] = true;
}
}
}
}
}
}
}
if ($progress instanceof ProgressBar) {
$progress->advance();
}
}
// écriture des fichiers
foreach ($newTranslationFiles as $newTranslationFile => $newTranslations) {
$fileName = 'app' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translatable_label' . DIRECTORY_SEPARATOR . $newTranslationFile;
file_put_contents($fileName, Yaml::dump($newTranslations, 3));
}
}
示例7: __construct
/**
* CommandValidator constructor.
*
* @param Kernel $kernel
*/
public function __construct(Kernel $kernel)
{
$this->_kernel = $kernel;
$this->_app = new Application($kernel);
foreach ($kernel->getBundles() as $bundle) {
if ($bundle instanceof Bundle) {
$bundle->registerCommands($this->_app);
}
}
}
示例8: getUserBundles
/**
* @param Kernel $kernel
* @return array
*/
protected function getUserBundles(Kernel $kernel)
{
$bundles = [];
/** @var Bundle $bundle */
foreach ($kernel->getBundles() as $bundle) {
if (strpos($bundle->getPath(), 'vendor') === false) {
$bundles[] = $bundle;
}
}
return $bundles;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dumper = new Dumper();
$bundles = $this->kernel->getBundles();
$configs = $this->generator->generate();
/** @var Bundle $bundle */
foreach ($bundles as $bundle) {
foreach ($configs as $entity => $config) {
if (strpos($entity, $bundle->getNamespace()) === false) {
continue;
}
$refl = new \ReflectionClass($entity);
$factoryDir = $this->getDirectory($bundle);
$file = $factoryDir . $refl->getShortName() . '.yml';
if (!file_exists($factoryDir)) {
mkdir($factoryDir, 0777, true);
}
$content = $dumper->dump([$entity => $config], 4);
// TODO check for existing files and merge them
file_put_contents($file, $content);
}
}
}
示例10: getNamespaceAutoComplete
/**
* Returns a list of namespaces as array with a forward slash to split the namespace & bundle.
*
* @param Kernel $kernel
* @return array
*/
private function getNamespaceAutoComplete(Kernel $kernel)
{
$ret = array();
foreach ($kernel->getBundles() as $k => $v) {
$ret[] = $this->fixNamespace($v->getNamespace());
}
return $ret;
}