Inheritance: implements Jarves\Filesystem\FilesystemInterface
Exemple #1
0
 /**
  * @ApiDoc(
  *  section="Bundle Editor",
  *  description="Saves Propel's Resources/config/jarves.propel.schema.xml file"
  * )
  *
  * @Rest\QueryParam(name="bundle", requirements=".*", strict=true, description="The bundle name")
  * @Rest\RequestParam(name="model", requirements=".*", description="Propel's model content (schema.xml)")
  *
  * @Rest\Post("/admin/system/bundle/editor/model")
  *
  * @param ParamFetcher $paramFetcher
  * @return bool
  */
 public function setModelAction(ParamFetcher $paramFetcher)
 {
     $bundle = $paramFetcher->get('bundle');
     $model = $paramFetcher->get('model');
     $path = $this->jarves->getBundleDir($bundle) . 'Resources/config/jarves.propel.schema.xml';
     return $this->localFilesystem->write($path, $model);
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * @param array $files
  *
  * @return AssetInfo
  */
 public function compressFiles(array $files)
 {
     $md5String = '';
     foreach ($files as $file) {
         $path = $this->getAssetPath($file);
         $md5String .= '.' . filemtime($path);
     }
     $fileUpToDate = false;
     $md5Line = '/* ' . md5($md5String) . " */\n";
     $oFile = 'cache/compressed-css/' . md5($md5String) . '.css';
     $handle = @fopen($this->getJarves()->getRootDir() . '/../web/' . $oFile, 'r');
     if ($handle) {
         $line = fgets($handle);
         fclose($handle);
         if ($line == $md5Line) {
             $fileUpToDate = true;
         }
     }
     if (!$fileUpToDate) {
         $content = $this->utils->compressCss($files, 'cache/compressed-css/');
         $content = $md5Line . $content;
         $this->webFilesystem->write($oFile, $content);
     }
     $assetInfo = new AssetInfo();
     $assetInfo->setPath($oFile);
     return $assetInfo;
 }
    /**
     * @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);
        }
    }
 /**
  * @ApiDoc(
  *  section="Interface i18n",
  *  description="Prints the language plural form"
  * )
  *
  * @Rest\QueryParam(name="lang", requirements="[a-z]{2,3}", strict=true, description="The language code")
  *
  * @Rest\Get("/admin/ui/language-plural")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return string javascript
  */
 public function getLanguagePluralFormAction(ParamFetcher $paramFetcher)
 {
     $lang = $paramFetcher->get('lang');
     $lang = preg_replace('/[^a-z]/', '', $lang);
     $file = $this->translator->getPluralJsFunctionFile($lang);
     //just make sure the file has been created
     $response = new Response();
     $response->headers->set('Content-Type', 'text/javascript');
     $response->setContent($this->webFilesystem->read($file));
     return $response;
 }
Exemple #6
0
 public function downloadFolder($path, $to = null)
 {
     $fs = $this->getAdapter($path);
     $files = $fs->getFiles($this->normalizePath($path));
     $to = $to ?: $this->createTempFolder('', false);
     if (is_array($files)) {
         foreach ($files as $file) {
             if ('file' === $file['type']) {
                 $content = $fs->read($this->normalizePath($path . '/' . $file['name']));
                 $this->cacheFilesystem->write($to . '/' . $file['name'], $content);
             } else {
                 $this->downloadFolder($path . '/' . $file['name'], $to . '/' . $file['name']);
             }
         }
     }
     return $to;
 }
Exemple #7
0
 /**
  * @param array $files
  *
  * @return AssetInfo
  */
 public function compressFiles(array $files)
 {
     $md5String = '';
     foreach ($files as $file) {
         $path = $this->getAssetPath($file);
         $md5String .= '.' . filemtime($path);
     }
     $fileUpToDate = false;
     $md5Line = '/* ' . md5($md5String) . " */\n";
     $oFile = 'cache/compressed-js/' . md5($md5String) . '.js';
     $handle = @fopen($this->getJarves()->getRootDir() . '/../web/' . $oFile, 'r');
     if ($handle) {
         $line = fgets($handle);
         fclose($handle);
         if ($line == $md5Line) {
             $fileUpToDate = true;
         }
     }
     if (!$fileUpToDate) {
         // googles minifier
         //            $result = $this->getJarves()->getUtils()->compressJs(
         //                $files,
         //                $oFile
         //            );
         $content = '';
         foreach ($files as $assetPath) {
             $content .= "\n/* {$assetPath} */\n\n";
             $path = $this->getAssetPath($assetPath);
             $content .= file_get_contents($path);
         }
         $content = $md5Line . $content;
         $this->webFilesystem->write($oFile, $content);
     }
     $assetInfo = new AssetInfo();
     $assetInfo->setPath($oFile);
     return $assetInfo;
 }
Exemple #8
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;
 }
Exemple #9
0
 public function compressJs(array $assets, $targetPath)
 {
     $oFile = $targetPath;
     $files = [];
     $md5String = '';
     $newestMTime = 0;
     foreach ($assets as $assetPath) {
         $path = $this->jarves->resolveWebPath($assetPath);
         $files[] = '--js ' . escapeshellarg($path);
         $mtime = filemtime($path);
         $newestMTime = max($newestMTime, $mtime);
         $md5String .= ">{$path}.{$mtime}<";
     }
     $sourceMap = $oFile . '.map';
     $cmdTest = 'java -version 2>&1';
     $closure = 'vendor/google/closure-compiler/compiler.jar';
     $compiler = escapeshellarg(realpath('../' . $closure));
     $cmd = 'java -jar ' . $compiler . ' --js_output_file ' . escapeshellarg('web/' . $oFile);
     $returnVal = 0;
     $debugMode = false;
     $handle = @fopen($oFile, 'r');
     $fileUpToDate = false;
     $md5Line = '//' . md5($md5String) . "\n";
     if ($handle) {
         $line = fgets($handle);
         fclose($handle);
         if ($line === $md5Line) {
             $fileUpToDate = true;
         }
     }
     if ($fileUpToDate) {
         return true;
     } else {
         if (!$debugMode) {
             exec($cmdTest, $outputTest, $returnVal);
         }
         if (0 === $returnVal) {
             $cmd .= ' --create_source_map ' . escapeshellarg('web/' . $sourceMap);
             $cmd .= ' --source_map_format=V3';
             $cmd .= ' ' . implode(' ', $files);
             $cmd .= ' 2>&1';
             $output = [];
             exec($cmd, $output, $returnVal);
             if (0 === $returnVal) {
                 //                    if (false === strpos($output, 'ERROR - Parse error')) {
                 $content = file_get_contents('web/' . $oFile);
                 $sourceMapUrl = '//@ sourceMappingURL=' . basename($sourceMap);
                 $content = $md5Line . $content . $sourceMapUrl;
                 file_put_contents('web/' . $oFile, $content);
                 return true;
                 //                    }
             }
         }
         $content = '';
         foreach ($assets as $assetPath) {
             $content .= "\n/* {$assetPath} */\n\n";
             $path = $this->jarves->resolveWebPath($assetPath);
             $content .= file_get_contents($path);
         }
         if ($content) {
             $this->webFilesystem->write($oFile, $content);
             return true;
         }
         return false;
     }
 }
Exemple #10
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;
 }