Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b295d80

Browse files
author
Bc. Libor Jonát
committed
Caching path relitivli to app dir
1 parent 715fbff commit b295d80

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

Bower/Bower.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct($bowerPath = '/usr/bin/bower', EventDispatcherInterf
7575
{
7676
$this->bowerPath = $bowerPath;
7777
$this->eventDispatcher = $eventDispatcher;
78-
$this->dependencyMapper = $dependencyMapper ?: new DependencyMapper();
78+
$this->dependencyMapper = $dependencyMapper ?: new DependencyMapper($kernelRootDir);
7979
$this->offline = $offline;
8080
$this->allowRoot = $allowRoot;
8181
$this->kernelRootDir = $kernelRootDir;
@@ -138,6 +138,19 @@ public function createDependencyMappingCache(ConfigurationInterface $config)
138138
throw new InvalidMappingException('Bower returned an invalid dependency mapping. This mostly happens when the dependencies are not yet installed or if you are using an old version of bower.');
139139
}
140140

141+
$kernelDir = realpath($this->kernelRootDir . '/../');
142+
143+
$filterDir = function(&$mapping) use ($kernelDir, &$filterDir) {
144+
$mapping['canonicalDir'] = str_replace($kernelDir, '', realpath($mapping['canonicalDir']));
145+
if (isset($mapping['dependencies']) && !empty($mapping['dependencies'])) {
146+
foreach ($mapping['dependencies'] as & $package) {
147+
$filterDir($package);
148+
}
149+
}
150+
};
151+
152+
$filterDir($mapping);
153+
141154
$cacheKey = $this->createCacheKey($config);
142155
$config->getCache()->save($cacheKey, $mapping);
143156

Bower/Package/DependencyMapper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class DependencyMapper implements DependencyMapperInterface
2626

2727
const DEPENDENCIES_KEY = 'dependencies';
2828

29+
/**
30+
* @var string KernelRootDir
31+
*/
32+
private $kernelRootDir;
33+
2934
/**
3035
* @var array
3136
*/
@@ -69,9 +74,17 @@ class DependencyMapper implements DependencyMapperInterface
6974
*/
7075
private $packages;
7176

72-
public function __construct()
77+
/**
78+
* @param $kernelRootDir
79+
*/
80+
public function __construct($kernelRootDir)
7381
{
7482
$this->packages = new ArrayCollection();
83+
$this->kernelRootDir = $kernelRootDir;
84+
85+
if (empty($kernelRootDir)) {
86+
throw new \RuntimeException('Kernel directory cannot be empty');
87+
}
7588
}
7689

7790
/**
@@ -173,6 +186,9 @@ private function getFiles(array $packageInfo, $type)
173186
*/
174187
private function extractFiles($canonicalDir, $files, array $extensions)
175188
{
189+
$appDir = realpath($this->kernelRootDir . '/../');
190+
$canonicalDir = $appDir . '/' . $canonicalDir;
191+
176192
if (!is_array($files)) {
177193
$files = array($files);
178194
}

0 commit comments

Comments
 (0)