/** * Test that checks basic functionality * @return array */ public function getBasicConfigUse() { $config = $this->getInstance(); $previusConfigData = $config->dumpConfig(); $config->clearConfig(); // Check if config can create the config dir $dirtmp = uniqid('test'); Config::createDir(CONFIG_DIR . DIRECTORY_SEPARATOR . $dirtmp); $this->assertFileExists(CONFIG_DIR . DIRECTORY_SEPARATOR . $dirtmp, 'Can\'t create test dir'); @rmdir(CONFIG_DIR . DIRECTORY_SEPARATOR . $dirtmp); // Check if platform is configured $this->assertTrue(is_bool($config->getDebugMode())); // Check path getters $this->assertFileExists($config->getTemplatePath()); $this->assertFileExists($config->getCachePath()); Config::save([], ['label' => ['test'], 'value' => [true]]); $configData = $config->dumpConfig(); $this->assertNotEmpty($configData, 'Empty configuration'); $this->assertTrue(is_array($configData), 'Configuration is not an array'); $propelParams = $config->getPropelParams(); $this->assertNotEmpty($propelParams, 'Empty configuration'); $this->assertTrue(is_array($propelParams), 'Configuration is not an array'); $configured = $config->isConfigured(); $this->assertTrue(is_bool($configured) && false === $configured); $this->assertTrue(is_bool($config->checkTryToSaveConfig())); $this->simulateRequiredConfig(); $configured = $config->isConfigured(); $this->assertTrue(is_bool($configured) && true === $configured); return $previusConfigData; }
/** * Método que guarda un text en un fichero * @param string $data * @param string $path * @param boolean $absolute * @throws ConfigException */ private function saveTextToFile($data, $path, $absolute = false) { $absolutePath = $absolute ? $path : CACHE_DIR . DIRECTORY_SEPARATOR . $path; $filename = basename($absolutePath); Config::createDir(str_replace($filename, "", $absolutePath)); if (false === file_put_contents($absolutePath, $data)) { throw new ConfigException(_('No se tienen los permisos suficientes para escribir en el fichero ') . $absolutePath); } }
/** * Method that assign the locale to the request * @return $this */ private function setLocale() { $this->locale = $this->config->get("default_language"); Logger::log('Set locale to project [' . $this->locale . ']'); // Load translations putenv("LC_ALL=" . $this->locale); setlocale(LC_ALL, $this->locale); // Load the locale path $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale'; Logger::log('Set locale dir ' . $locale_path); Config::createDir($locale_path); bindtextdomain('translations', $locale_path); textdomain('translations'); bind_textdomain_codeset('translations', 'UTF-8'); return $this; }
/** * Method that copy a resource * @param string $src * @param string $dst * @throws ConfigException */ public static function copyr($src, $dst) { $dir = opendir($src); Config::createDir($dst); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { self::copyr($src . '/' . $file, $dst . '/' . $file); } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) { throw new ConfigException("Can't copy " . $src . " to " . $dst); } } } closedir($dir); }
/** * Método que extrae el recurso css de una línea de estilos css * @param $handle * @param string $filename_path * @throws ConfigException */ public static function extractCssLineResource($handle, $filename_path) { $line = fgets($handle); $urls = array(); if (preg_match_all('#url\\((.*?)\\)#', $line, $urls, PREG_SET_ORDER)) { foreach ($urls as $source) { $orig = self::calculateResourcePathname($filename_path, $source); $orig_part = explode("Public", $orig); $dest = WEB_DIR . $orig_part[1]; Config::createDir(dirname($dest)); if (@copy($orig, $dest) === false) { throw new ConfigException("Can't copy " . $orig . " to " . $dest); } } } }
/** * Método que genera las urls amigables para usar dentro del framework * @return Router */ public function simpatize() { $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; $this->generateSlugs($absoluteTranslationFileName); Config::createDir(CONFIG_DIR); Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); return $this; }
/** * Método que crea el path del logger * @param Config $config * * @return string */ private function createLoggerPath(Config $config) { $logger = $this->setLoggerName($config); $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); Config::createDir($path); return $path; }
/** * Método que procesa un recurso para su copia en el DocumentRoot * @param string $string * @param string $name * @param boolean $return * @param string $filename_path * * @return string */ private static function processAsset($string, $name, $return, $filename_path) { $file_path = $filename_path; if (file_exists($filename_path)) { list($base, $html_base, $file_path) = AssetsParser::calculateAssetPath($string, $name, $return, $filename_path); //Creamos el directorio si no existe Config::createDir($base . $html_base); //Si se ha modificado if (!file_exists($base . $file_path) || filemtime($base . $file_path) < filemtime($filename_path)) { if ($html_base == 'css') { self::processCssLines($filename_path); } self::putResourceContent($name, $filename_path, $base, $file_path); } } return $file_path; }
if (!isset($console)) { $console = new Application(); } $console->register('psfs:create:root')->setDefinition(array(new InputArgument('path', InputArgument::OPTIONAL, 'Path en el que crear el Document Root')))->setDescription('Comando de creación del Document Root del projecto')->setCode(function (InputInterface $input, OutputInterface $output) { // Creates the html path $path = $input->getArgument('path'); if (empty($path)) { $path = WEB_DIR; } \PSFS\base\config\Config::createDir($path); $paths = array("js", "css", "img", "media", "font"); foreach ($paths as $htmlPath) { \PSFS\base\config\Config::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); } // Generates the root needed files $files = ['_' => '_.php', 'browserconfig' => 'browserconfig.xml', 'crossdomain' => 'crossdomain.xml', 'humans' => 'humans.txt', 'robots' => 'robots.txt']; foreach ($files as $templates => $filename) { $text = \PSFS\base\Template::getInstance()->dump("generator/html/" . $templates . '.html.twig'); if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { $output->writeln('Can\\t create the file ' . $filename); } else { $output->writeln($filename . ' created successfully'); } } //Export base locale translations if (!file_exists(BASE_DIR . DIRECTORY_SEPARATOR . 'locale')) { \PSFS\base\config\Config::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); \PSFS\Services\GeneratorService::copyr(SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'locale', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); } $output->writeln("Document root generado en " . $path); });