has() public method

public has ( string $path ) : boolean
$path string
return boolean
Example #1
0
 /**
  * @param string $path
  * @return array
  */
 protected function getBundlesFromPath($path)
 {
     $bundles = [];
     if ($this->localFilesystem->has($path)) {
         $finder = new Finder();
         $finder->files()->name('*Bundle.php')->notPath('/\\/Tests\\//')->notPath('/\\/Test\\//')->notPath('Tests/Integration/skeletion')->notPath('Jarves/vendor')->in($this->rootDir . '/../' . $path);
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         foreach ($finder as $file) {
             $file = $file->getRealPath();
             $content = file_get_contents($file);
             preg_match('/^\\s*\\t*class ([a-z0-9_]+)/mi', $content, $className);
             if (isset($className[1]) && $className[1]) {
                 preg_match('/\\s*\\t*namespace ([a-zA-Z0-9_\\\\]+)/', $content, $namespace);
                 $class = (isset($namespace[1]) ? $namespace[1] . '\\' : '') . $className[1];
                 if ('Bundle' === $className[1]) {
                     continue;
                 }
                 if (class_exists($class)) {
                     $reflection = new \ReflectionClass($class);
                     $interfaces = $reflection->getInterfaceNames();
                     if (in_array('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface', $interfaces)) {
                         $bundles[] = $class;
                     }
                 }
             }
         }
     }
     return $bundles;
 }
Example #2
0
    /**
     * @param Bundle $bundle
     * @param $property
     * @return bool
     */
    public function saveFileBased(Bundle $bundle, $property)
    {
        $xml = $bundle->exportFileBased($property);
        $xmlFile = $bundle->getPropertyFilePath($property);
        $emptyXml = '<config>
  <bundle/>
</config>';
        if ($xml == $emptyXml) {
            if ($this->localFilesystem->has($xmlFile)) {
                return $this->localFilesystem->delete($xmlFile);
            } else {
                return true;
            }
        } else {
            return $this->localFilesystem->write($xmlFile, $xml);
        }
    }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
 {
     $result = null;
     $path = $pk['path'];
     if ($depth === null) {
         $depth = 1;
     }
     if ($path) {
         $path = '@' . trim($path, '/@');
         $path = str_replace(':', '/', $path);
     }
     $c = 0;
     $offset = $options['offset'];
     $limit = $options['limit'];
     $result = array();
     if (!$path) {
         $result = array();
         $bundles = array_keys($this->jarves->getBundles());
         foreach ($bundles as $bundleName) {
             $directory = $this->jarves->resolvePath('@' . $bundleName, 'Resources/views', true);
             if (!$this->localFilesystem->has($directory)) {
                 continue;
             }
             $file = $this->localFilesystem->getFile($directory);
             if (!$file) {
                 $result[] = $directory;
                 continue;
             }
             $file = $file->toArray();
             $file['name'] = $bundleName;
             $file['path'] = $bundleName;
             if ($offset && $offset > $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $file)) {
                 $result[] = $directory;
                 continue;
             }
             $c++;
             if ($depth > 0) {
                 $children = self::getBranch(array('path' => $bundleName), $condition, $depth - 1);
                 $file['_childrenCount'] = count($children);
                 if ($depth > 1 && $file['type'] == 'dir') {
                     $file['_children'] = $children;
                 }
             }
         }
     } else {
         if (!($bundleName = $this->jarves->getBundleFromPath($path))) {
             return [];
         }
         $directory = $this->jarves->resolvePath($path, 'Resources/views', true) . '/';
         if (!$this->localFilesystem->has($directory)) {
             return [];
         }
         $files = $this->localFilesystem->getFiles($directory);
         foreach ($files as $file) {
             $item = $file->toArray();
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $item, 'jarves/file')) {
                 continue;
             }
             $c++;
             if ($offset && $offset >= $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             $item = array('name' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)), 'path' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)));
             if ($file->isDir()) {
                 $children = self::getBranch(array('path' => $item['path']), $condition, $depth - 1);
                 foreach ($children as $child) {
                     //                        $child['name'] = $item['name'] . '/' . $child['name'];
                     $result[] = $child;
                 }
             }
             if ($file->isFile()) {
                 $result[] = $item;
             }
         }
     }
     return $result;
 }
Example #4
0
 public function compileFile(AssetInfo $assetInfo)
 {
     $assetPath = $assetInfo->getPath();
     $localPath = $this->getAssetPath($assetPath);
     if (!file_exists($localPath)) {
         return null;
     }
     $publicPath = $this->getPublicAssetPath($assetPath);
     $targetPath = 'cache/scss/' . substr($publicPath, 0, strrpos($publicPath, '.'));
     if ('.css' !== substr($targetPath, -4)) {
         $targetPath .= '.css';
     }
     $needsCompilation = true;
     $sourceMTime = filemtime($localPath);
     $dir = dirname($localPath);
     if ($this->filesystem->has('web/' . $targetPath)) {
         $fh = $this->filesystem->handle('web/' . $targetPath);
         if ($fh) {
             $firstLine = fgets($fh);
             $info = substr($firstLine, strlen('/* compiled at '), -3);
             $spacePosition = strpos($info, ' ');
             $lastSourceMTime = 0;
             $dependencies = [];
             if ($spacePosition > 0) {
                 $lastSourceMTime = (int) substr($info, 0, $spacePosition);
                 $dependencies = trim(substr($info, $spacePosition + 1));
                 if ($dependencies) {
                     $dependencies = explode(',', trim(substr($info, $spacePosition + 1)));
                 } else {
                     $dependencies = [];
                 }
             } else {
                 //old format without dependencies
                 $lastSourceMTime = (int) $info;
             }
             $needsCompilation = $lastSourceMTime !== $sourceMTime;
             if (!$needsCompilation) {
                 //check dependencies
                 foreach ($dependencies as $dependency) {
                     list($path, $depLastMTime) = explode(':', $dependency);
                     $depLastMTime = (int) $depLastMTime;
                     if (!file_exists($dir . '/' . $path)) {
                         //depended file does not exist anymore, so we need to recompile
                         $needsCompilation = true;
                         break;
                     }
                     $depSourceMTime = filemtime($dir . '/' . $path);
                     if ($depLastMTime !== $depSourceMTime) {
                         $needsCompilation = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($needsCompilation) {
         //resolve all dependencies
         $dependencies = [];
         $this->resolveDependencies($localPath, $dependencies);
         $processBuilder = new ProcessBuilder();
         $processBuilder->setInput(file_get_contents($localPath))->add('sass')->add('--scss')->add('--no-cache')->add('--unix-newlines')->add('--load-path')->add(dirname($localPath))->add($localPath)->enableOutput();
         $process = $processBuilder->getProcess();
         $process->start();
         while ($process->isRunning()) {
         }
         if (127 === $process->getExitCode()) {
             throw new \RuntimeException('sass binary not found. Please install sass first and make its in $PATH. ' . $process->getExitCodeText());
         }
         if (0 !== $process->getExitCode()) {
             throw new \RuntimeException(sprintf("Error during scss compilation of %s:\n%s\n%s\n%s", $assetPath, $process->getExitCodeText(), $process->getErrorOutput(), $process->getOutput()));
         }
         $compiled = $process->getOutput();
         $compiled = $this->replaceRelativePaths($publicPath, $targetPath, $compiled);
         $dependencies = implode(',', $dependencies);
         $info = "{$sourceMTime} {$dependencies}";
         $compiled = "/* compiled at {$info} */\n" . $compiled;
         $this->filesystem->write('web/' . $targetPath, $compiled);
     }
     $assetInfo = new AssetInfo();
     $assetInfo->setPath($targetPath);
     $assetInfo->setContentType('text/css');
     return $assetInfo;
 }