first commit
This commit is contained in:
90
bundles/KupShop/KupShopBundle/Util/System/BundleFinder.php
Normal file
90
bundles/KupShop/KupShopBundle/Util/System/BundleFinder.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: joe
|
||||
* Date: 3/22/17
|
||||
* Time: 5:21 PM.
|
||||
*/
|
||||
|
||||
namespace KupShop\KupShopBundle\Util\System;
|
||||
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Functional\Mapping;
|
||||
use KupShop\KupShopBundle\Util\StringUtil;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
class BundleFinder
|
||||
{
|
||||
/** @var Container */
|
||||
private $container;
|
||||
/** @var PathFinder */
|
||||
private $pathFinder;
|
||||
|
||||
public function __construct(PathFinder $pathFinder)
|
||||
{
|
||||
$this->pathFinder = $pathFinder;
|
||||
}
|
||||
|
||||
public function getBundles()
|
||||
{
|
||||
$bundles = $this->getContainer()->getParameter('kernel.bundles');
|
||||
|
||||
return array_filter($bundles, function ($value) {
|
||||
return StringUtil::startsWith($value, 'KupShop')
|
||||
|| StringUtil::startsWith($value, 'Shop')
|
||||
|| StringUtil::startsWith($value, 'External');
|
||||
});
|
||||
}
|
||||
|
||||
public function getBundlesResource($path)
|
||||
{
|
||||
return Mapping::withKeys($this->getBundles(), function ($bundle, $tmp) use ($path) {
|
||||
return "@{$bundle}/{$path}";
|
||||
});
|
||||
}
|
||||
|
||||
public function getBundlesPath($path)
|
||||
{
|
||||
return Mapping::withKeys($this->getBundles(), function ($bundle, $class) use ($path) {
|
||||
$bundles = $this->getContainer()->getParameter('kernel.bundles_metadata');
|
||||
|
||||
return $bundles[$bundle]['path'].'/'.$path;
|
||||
});
|
||||
}
|
||||
|
||||
public function getExistingBundlesPath($path)
|
||||
{
|
||||
$bundles = $this->getBundlesPath($path);
|
||||
|
||||
$files = array_filter($bundles, function ($value) {
|
||||
return file_exists($value);
|
||||
});
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
*
|
||||
* @return BundleFinder
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Container
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
if ($this->container) {
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
return $this->container = ServiceContainer::getContainer();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user