Example #1
0
 /**
  * Executes the task
  *
  * @param array $uParameters parameters
  *
  * @return int exit code
  */
 public function executeTask(array $uParameters)
 {
     $tPath = Core::$instance->loader->basepath . "/var/cache";
     FileSystem::garbageCollect($tPath, ["dotFiles" => false]);
     $this->interface->writeColor("yellow", "done.");
     return 0;
 }
Example #2
0
 /**
  * Loads a yaml configuration and adds it to stack
  *
  * @param string  $uProjectConfigPath  The path of yaml configuration file
  *
  * @return void
  *
  * @todo use cached reader and cache yaml
  */
 public function addConfig($uPath)
 {
     if ($this->yamlParser === null) {
         $this->yamlParser = new Parser();
     }
     $tYaml = $this->yamlParser->parse(FileSystem::read($uPath));
     $this->config->add($tYaml);
 }
 /**
  * Scans a file
  *
  * @param string      $uFile             file path
  *
  * @return void
  */
 public function processFile($uFile)
 {
     $tFileContents = FileSystem::read($uFile);
     foreach ($this->scanners as $tScanner) {
         $tScanner->processFile($uFile, $tFileContents);
     }
     $tTokenStream = TokenStream::fromString($tFileContents);
     $this->processTokenStream($tTokenStream);
 }
Example #4
0
 /**
  * Compiles given configuration files into single configuration
  *
  * @return array final configuration
  */
 public function get()
 {
     // TODO mass caching with pathnames and flags
     foreach ($this->paths as $tPath) {
         $tConfigPath = Core::$instance->translateVariables($tPath[0]);
         $tConfigContent = Core::$instance->cachedRead("file." . realpath($tConfigPath), function () use($tConfigPath) {
             $tParser = new Parser();
             return $tParser->parse(FileSystem::read($tConfigPath));
         }, ["ttl" => 60 * 60]);
         $this->process($this->content, $tConfigContent, $tPath[1]);
     }
     return $this->content;
 }
Example #5
0
 /**
  * Stops the code coverage
  *
  * @return array results
  */
 public static function coverageStop()
 {
     if (!extension_loaded("xdebug")) {
         return null;
     }
     $tCoverageData = xdebug_get_code_coverage();
     xdebug_stop_code_coverage();
     $tFinal = ["files" => [], "total" => ["coveredLines" => 0, "totalLines" => 0]];
     foreach ($tCoverageData as $tPath => $tLines) {
         $tFileCoverage = ["path" => $tPath, "coveredLines" => array_keys($tLines), "totalLines" => FileSystem::getFileLineCount($tPath)];
         $tFinal["files"][] = $tFileCoverage;
         $tFinal["total"]["coveredLines"] += count($tFileCoverage["coveredLines"]);
         $tFinal["total"]["totalLines"] += $tFileCoverage["totalLines"];
     }
     $tFinal["total"]["percentage"] = $tFinal["total"]["coveredLines"] * 100 / $tFinal["total"]["totalLines"];
     return $tFinal;
 }
 /**
  * Scans given file to search for classes
  *
  * @param string $uFile             file
  * @param string $uNamespacePrefix  namespace prefix
  *
  * @return void
  */
 public function scanFile($uFile, $uNamespacePrefix)
 {
     $tFileContents = FileSystem::read($uFile);
     $tTokenStream = TokenStream::fromString($tFileContents);
     $this->annotationScanner->process($tTokenStream, $uNamespacePrefix);
 }
Example #7
0
 /**
  * Compiles given configuration files into single configuration
  *
  * @param null|string $uMimeTypeFilter only compiles filtered mimetypes
  *
  * @return void
  */
 public function compile($uMimeTypeFilter = null)
 {
     if (count($this->contents) > 0) {
         $this->output = "";
         foreach ($this->contents as $tContent) {
             if ($uMimeTypeFilter !== null && $uMimeTypeFilter !== $tContent[1]) {
                 continue;
             }
             if ($tContent[0] === "direct") {
                 $tOutput = $tContent[2];
             } elseif ($tContent[0] === "callback") {
                 $tOutput = call_user_func($tContent[2]);
             } elseif ($tContent[0] === "file") {
                 $tOutput = FileSystem::read($tContent[2]);
             }
             if (isset($this->filters[$tContent[1]])) {
                 $tOutput = call_user_func($this->filters[$tContent[1]], $tOutput);
             }
             $this->output .= $tOutput;
         }
         $this->contents = [];
     }
     return $this->output;
 }
 /**
  * Saves a file into writable folder
  *
  * @param string $uFilename   filename
  * @param mixed  $uContent    file content to be written
  * @param bool   $uSaveAsPHP  saves file contents as php file if it is true
  *
  * @return void
  */
 public function saveFile($uFilename, $uContent, $uSaveAsPHP = false)
 {
     if ($uSaveAsPHP) {
         FileSystem::writePhpFile(Core::$instance->translateVariables($this->applicationWritablePath . "/{$uFilename}"), $uContent);
         return;
     }
     FileSystem::write(Core::$instance->translateVariables($this->applicationWritablePath . "/{$uFilename}"), $uContent);
 }
Example #9
0
 /**
  * Reads the contents from cache folder as long as it is not expired
  * If the file is expired, invokes callback method and caches output
  *
  * @param string      $uKey          key for the value going to be cached
  * @param mixed       $uDefaultValue the default value
  * @param array       $uOptions      options
  *
  * @return mixed the result
  */
 public function cachedRead($uKey, $uDefaultValue, array $uOptions = [])
 {
     $tCacheFile = $this->loader->basepath . "/var/cache/" . crc32($uKey);
     return FileSystem::readFromCacheFile($tCacheFile, $uDefaultValue, $uOptions);
 }