getRootDir() public method

public getRootDir ( ) : string
return string
Ejemplo n.º 1
0
 public function search($query, Condition $condition = null, $max = 20)
 {
     $result = [];
     $finder = Finder::create()->in($webRoot = sprintf('%s/../web', $this->jarves->getRootDir()))->followLinks()->exclude('cache')->exclude('bundles/jarves');
     $query = trim($query);
     $regexSearch = true;
     $regex = '/' . str_replace(['\\*', '_'], ['.*', '.'], preg_quote($query, '/')) . '/';
     if (preg_match('/^[a-zA-Z\\_\\-\\.]+\\*?$/', $query)) {
         //onl query like 'test*';
         $regexSearch = false;
         $query = rtrim($query, '*');
     }
     /** @var SplFileInfo $file */
     foreach ($finder as $file) {
         $path = substr($file->getPath() . '/' . $file->getFilename(), strlen($webRoot));
         if ($regexSearch) {
             if (!preg_match($regex, $file->getFilename())) {
                 continue;
             }
         } else {
             if (0 !== strpos($file->getFilename(), $query)) {
                 continue;
             }
         }
         $result[] = ['path' => $path, '_label' => $path];
         if (count($result) >= $max) {
             return $result;
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param array $files
  * @param string $includePath The directory where to compressed css is. with trailing slash!
  *
  * @return string
  */
 public function compressCss(array $files, $includePath = '')
 {
     $webDir = realpath($this->jarves->getRootDir() . '/../web') . '/';
     $content = '';
     foreach ($files as $assetPath) {
         $cssFile = $this->jarves->resolvePublicWebPath($assetPath);
         //bundles/jarves/css/style.css
         $cssDir = dirname($cssFile) . '/';
         //admin/css/...
         $cssDir = str_repeat('../', substr_count($includePath, '/')) . $cssDir;
         $content .= "\n\n/* file: {$assetPath} */\n\n";
         if (file_exists($file = $webDir . $cssFile)) {
             $h = fopen($file, "r");
             if ($h) {
                 while (!feof($h) && $h) {
                     $buffer = fgets($h, 4096);
                     $buffer = preg_replace('/@import \'(?!.*:\\/\\/)([^\\/].*)\'/', '@import \'' . $cssDir . '$1\'', $buffer);
                     $buffer = preg_replace('/@import "(?!.*:\\/\\/)([^\\/].*)"/', '@import "' . $cssDir . '$1"', $buffer);
                     $buffer = preg_replace('/url\\(\'(?!.*:\\/\\/)([^\\/][^\\)]*)\'\\)/', 'url(\'' . $cssDir . '$1\')', $buffer);
                     $buffer = preg_replace('/url\\(\\"(?!.*:\\/\\/)([^\\/][^\\)]*)\\"\\)/', 'url(\\"' . $cssDir . '$1\\")', $buffer);
                     $buffer = preg_replace('/url\\((?!.*data:image)(?!.*:\\/\\/)([^\\/\'].*)\\)/', 'url(' . $cssDir . '$1)', $buffer);
                     $buffer = str_replace(array('  ', '    ', "\t", "\n", "\r"), '', $buffer);
                     $buffer = str_replace(': ', ':', $buffer);
                     $content .= $buffer;
                 }
                 fclose($h);
             }
         } else {
             $content .= '/* => `' . $cssFile . '` not exist. */';
         }
     }
     return $content;
 }
Ejemplo n.º 3
0
 /**
  * @param string $path
  *
  * @return AdapterInterface
  */
 public function getAdapter($path = null)
 {
     $adapterServiceId = 'jarves.filesystem.adapter.local';
     $params['root'] = realpath($this->jarves->getRootDir() . '/../web/');
     if ($path && '/' !== $path[0]) {
         $path = '/' . $path;
     }
     if ($path != '/') {
         $sPos = strpos(substr($path, 1), '/');
         if (false === $sPos) {
             $firstFolder = substr($path, 1);
         } else {
             $firstFolder = substr($path, 1, $sPos);
         }
     } else {
         $firstFolder = '/';
     }
     if ('/' !== $firstFolder) {
         //todo
         $mounts = $this->jarvesConfig->getSystemConfig()->getMountPoints(true);
         //if firstFolder a mounted folder?
         if ($mounts && $mounts->hasMount($firstFolder)) {
             //                $mountPoint = $mounts->getMount($firstFolder);
             //                $adapterClass = $mountPoint->getClass();
             //                $params = $mountPoint->getParams();
             //                $mountName = $firstFolder;
         } else {
             $firstFolder = '/';
         }
     }
     if (isset($this->adapterInstances[$firstFolder])) {
         return $this->adapterInstances[$firstFolder];
     }
     $adapter = $this->newAdapter($adapterServiceId, $firstFolder, $params);
     $adapter->setMountPath($firstFolder);
     if ($adapter instanceof ContainerAwareInterface) {
         $adapter->setContainer($this->container);
     }
     $adapter->loadConfig();
     return $this->adapterInstances[$firstFolder] = $adapter;
 }
Ejemplo n.º 4
0
 /**
  * @ApiDoc(
  *  section="Backend",
  *  description="Prints all CSS files combined"
  * )
  *
  * @Rest\Get("/admin/backend/css")
  *
  * @return string CCS
  */
 public function loadCssAction()
 {
     $oFile = $this->jarves->getRootDir() . '/../web/cache/admin.style-compiled.css';
     $md5String = '';
     /** @var \Jarves\AssetHandler\Container $assetHandlerContainer */
     $assetHandlerContainer = $this->container->get('jarves.asset_handler.container');
     $files = [];
     foreach ($this->jarves->getConfigs() as $bundleConfig) {
         foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
             if (!$assetInfo->isCompressionAllowed()) {
                 continue;
             }
             if ($assetInfo->isStylesheet()) {
                 $path = $this->jarves->resolveWebPath($assetInfo->getPath());
                 if (file_exists($path)) {
                     $files[] = $assetInfo->getPath();
                     $md5String .= filemtime($path);
                 }
             }
             if ($assetInfo->isScss()) {
                 $path = $this->jarves->resolveWebPath($assetInfo->getPath());
                 if (file_exists($path)) {
                     foreach ($assetHandlerContainer->compileAsset($assetInfo) as $subAssetInfo) {
                         $files[] = $subAssetInfo->getPath();
                     }
                     $md5String .= filemtime($path);
                 }
             }
         }
     }
     $handle = @fopen($oFile, 'r');
     $fileUpToDate = false;
     $md5Line = '/* ' . md5($md5String) . "*/\n";
     if ($handle) {
         $line = fgets($handle);
         fclose($handle);
         if ($line == $md5Line) {
             $fileUpToDate = true;
         }
     }
     if (!$fileUpToDate) {
         $content = $this->utils->compressCss($files, $this->jarves->getAdminPrefix() . 'admin/backend/');
         $content = $md5Line . $content;
         file_put_contents($oFile, $content);
     }
     $expires = 60 * 60 * 24 * 14;
     $response = new Response(file_get_contents($oFile));
     $response->headers->set('Content-Type', 'text/css');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Cache-Control', 'max-age=' . $expires);
     $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     return $response;
 }
Ejemplo n.º 5
0
 /**
  * @ApiDoc(
  *  section="Bundle/Package Manager",
  *  description="Returns a list of all local available bundles and packages"
  * )
  *
  * @Rest\Get("/admin/system/bundle/manager/local")
  *
  * @return array
  */
 public function getLocalAction()
 {
     $finder = new Finder();
     $root = $this->jarves->getRootDir();
     $finder->files()->ignoreUnreadableDirs()->name('*Bundle.php')->exclude('Jarves/vendor')->exclude('/\\/Test\\//')->exclude('/\\/Tests\\//');
     if (file_exists($root . '/../vendor')) {
         $finder->in($root . '/../vendor');
     }
     if (file_exists($root . '/../src')) {
         $finder->in($root . '/../src');
     }
     return $this->getBundles($finder);
 }
Ejemplo n.º 6
0
 /**
  * Extracts parent's class information.
  *
  * @internal
  *
  * @param $parentClass
  * @param $methods
  *
  * @throws ClassNotFoundException
  */
 protected function extractParentClassInformation($parentClass, &$methods)
 {
     if (!class_exists($parentClass)) {
         throw new ClassNotFoundException();
     }
     $reflection = new \ReflectionClass($parentClass);
     $root = realpath($this->jarves->getRootDir() . '/../');
     //        $parentPath = substr($reflection->getFileName(), strlen($root) + 1);
     $parentContent = explode("\n", file_get_contents($reflection->getFileName()));
     $parentReflection = new \ReflectionClass($parentClass);
     $methods2 = $parentReflection->getMethods();
     foreach ($methods2 as $method) {
         if (isset($methods[$method->name])) {
             continue;
         }
         if ($method->class == $parentClass) {
             $code = '';
             $startLine = $method->getStartLine();
             $endLine = $method->getEndLine();
             for ($i = $startLine - 1; $i < $method->getEndLine(); $i++) {
                 $code .= @$parentContent[$i] . "\n";
                 if (strpos(@$parentContent[$i], '{')) {
                     break;
                 }
             }
             if ($doc = $method->getDocComment()) {
                 $code = "    {$doc}\n{$code}";
             }
             $methods[$method->name] = str_replace("\r", '', $code);
         }
     }
     $parent = $parentReflection->getParentClass();
     if ($parent) {
         $this->extractParentClassInformation($parent->name, $methods);
     }
 }