public function loader($locale = 'es_ES') { $Translator = new Translator($locale); $Translator->addLoader('array', new ArrayLoader()); $data = array(); $part_locale = explode('_', $locale); $bundles = Service::getBundles(); foreach ($bundles as $bundle) { $path_i18n = str_replace('\\', '/', $bundle->getPath() . '/i18n/' . $part_locale[0]); if (is_dir($path_i18n)) { $finder = new Finder(); $finder->files()->name('*.i18n.php')->in($path_i18n); // Une todos los esquemas en un solo array foreach ($finder as $file) { $_a = (require $file->getRealpath()); $data = array_merge($data, $_a); } } } $path_i18n = str_replace('\\', '/', Ki_APP . 'src/i18n/' . $part_locale[0]); if (is_dir($path_i18n)) { $finder = new Finder(); $finder->files()->name('*.i18n.php')->in($path_i18n); // Une todos los esquemas en un solo array foreach ($finder as $file) { $_a = (require $file->getRealpath()); $data = array_merge($data, $_a); } } $Translator->addResource('array', $data, $locale); $this->Translator = $Translator; }
protected function execute(InputInterface $input, OutputInterface $output) { $path_schema = Ki_APP . 'src/storage/schemas/'; $action = $input->getArgument('action'); $behavior = $input->getArgument('behavior'); $yaml = new Parser(); if (!in_array($action, array('create', 'freeze'))) { $output->writeln(PHP_EOL . 'El parametro "action" debe ser create o freeze. Por defecto es create.' . PHP_EOL); exit; } $bundles = Service::getBundles(); $_schema = array(); $mirrors = array(); foreach ($bundles as $bundle) { $dir_schema = str_replace('\\', '/', $bundle->getPath() . '/config/schema'); if (is_dir($dir_schema)) { $mirrors[$bundle->getNameSpace()] = $bundle; $finder = new Finder(); $finder->files()->name('*.yml')->in($dir_schema); // Une todos los esquemas en un solo array foreach ($finder as $file) { // Concatena el esquema de cada archivo conseguido $_schema = array_merge($_schema, $yaml->parse(file_get_contents($file))); } } } if (count($mirrors) == 0) { $output->write(PHP_EOL . " <info>No se ha encontrado al menos un esquema en los bundles registrados.</info>" . PHP_EOL); exit; } $ValidateSchema = Service::get('validate_schema'); /* Valida los archivos *.yml y muestra los posibles errores */ if (!$ValidateSchema->isValid($_schema)) { $this->showErrors($ValidateSchema); exit; } /* Obtiene el array() del esquema */ $schema = $ValidateSchema->getSchema(); switch (strtoupper($action)) { case 'CREATE': $this->createSchema($input, $output, $path_schema, $schema, $behavior); $this->mkdir($path_schema . 'current/bundles'); $this->mkdir($path_schema . 'current/tmp'); $fs = new Filesystem(); $_path_schema_bundle = str_replace('\\', '/', $path_schema . 'current/bundles/'); $_path_schema_tmp = str_replace('\\', '/', $path_schema . 'current/tmp/'); foreach ($mirrors as $namespace => $mirror) { $path_source = str_replace('\\', '/', Ki_BUNDLES . $namespace . '/config/schema'); // Hace un espejo desde el esquema del bundle al directorio temporal $fs->mirror($path_source, $_path_schema_tmp . $namespace, null, array('override' => true, 'delete' => true)); } // Hace un espejo desde el directorio temporal al current/bundles/ $fs->mirror($_path_schema_tmp, $_path_schema_bundle, null, array('override' => true, 'delete' => true)); // Elimina el directorio temporal $fs->remove($_path_schema_tmp); break; case 'FREEZE': $this->freezeSchema($input, $output, $path_schema, $schema, $action); break; } }
public function __construct(ConfigBuilderInterface $config, SessionInterface $user, UrlGenerator $url_generator) { $this->User = $user; $this->Config = $config; $this->UrlGenerator = $url_generator; $bundles = Service::getBundles(); $theme_web = $config->get('app', 'theme_web'); $theme_admin = $config->get('app', 'theme_admin'); $enabled_path_themes = $config->get('app', 'enabled_path_themes'); $path_templates = array(Ki_APP . 'src/layouts', Ki_APP . 'src/templates'); if ($enabled_path_themes) { if (is_dir(Ki_THEMES . $theme_web . '/layouts')) { $path_templates[] = Ki_THEMES . $theme_web . '/layouts'; } if (is_dir(Ki_THEMES . $theme_web . '/templates')) { $path_templates[] = Ki_THEMES . $theme_web . '/templates'; } if (is_dir(Ki_THEMES . $theme_admin . '/layouts')) { $path_templates[] = Ki_THEMES . $theme_admin . '/layouts'; } if (is_dir(Ki_THEMES . $theme_admin . '/templates')) { $path_templates[] = Ki_THEMES . $theme_admin . '/templates'; } } foreach ($bundles as $bundle) { $path_bundles_templates = str_replace('\\', '/', $bundle->getPath() . '/templates'); if (is_dir($path_bundles_templates)) { $path_templates[] = $path_bundles_templates; } } $Twig_Loader_Filesystem = new \Twig_Loader_Filesystem($path_templates); $Twig = new \Twig_Environment(null, array('cache' => Ki_CACHE . 'views', 'debug' => Ki_DEBUG)); // Funcion para construir las url $build_url = new \Twig_SimpleFunction('build_url', function ($name_route, $parameters = array(), $locale = null) { return \Kodazzi\Tools\Util::buildUrl($name_route, $parameters, $locale); }); // Funcion para construir las url $cut_text = new \Twig_SimpleFunction('cut_text', function ($string, $limit = 100, $end_char = '...') { return \Kodazzi\Tools\StringProcessor::cutText($string, $limit, $end_char); }); // Funcion para cortar texto muy largo. $resume = new \Twig_SimpleFunction('resume', function ($string, $limit = 100, $end_char = '...') { return \Kodazzi\Tools\StringProcessor::resume($string, $limit, $end_char); }); // Funcion para dar formato a un numero $number_format = new \Twig_SimpleFunction('number_format', function ($number, $decimals = 0, $dec_point = ',', $thousands_sep = '.') { return number_format($number, $decimals, $dec_point, $thousands_sep); }); // Funcion para dar formato a un numero $date_format = new \Twig_SimpleFunction('date_format', function ($date, $format) { return \Kodazzi\Tools\Date::format($date, $format); }); // Funcion para dar formato a un numero $get_date = new \Twig_SimpleFunction('get_date', function ($string) { return \Kodazzi\Tools\Date::getDate($string); }); // Funcion para indicar si existe un archivo $isFile = new \Twig_SimpleFunction('isFile', function ($path, $file) { return \Kodazzi\Tools\Util::isFile($path, $file); }); // Funcion para indicar si existe un archivo $hash = new \Twig_SimpleFunction('hash', function ($id, $str = 'z6i5v36h3F5', $position = 5, $prefix = '') { return \Kodazzi\Tools\Util::hash($id, $str, $position, $prefix); }); // Funcion para indicar si existe un archivo $ucfirst = new \Twig_SimpleFunction('ucfirst', function ($string) { return ucfirst($string); }); // Funcion para acceder al catalogo de traduccion. $i18n = new \Twig_SimpleFunction('i18n', function ($string) { return Service::get('translator')->get($string); }); // Funcion para indicar si existe un archivo $dump = new \Twig_SimpleFunction('dump', function ($var) { ob_start(); var_dump($var); $a = ob_get_contents(); ob_end_clean(); return $a; }); $Twig->addFunction($build_url); $Twig->addFunction($cut_text); $Twig->addFunction($get_date); $Twig->addFunction($resume); $Twig->addFunction($number_format); $Twig->addFunction($isFile); $Twig->addFunction($date_format); $Twig->addFunction($hash); $Twig->addFunction($ucfirst); $Twig->addFunction($i18n); $Twig->addFunction($dump); $this->Twig_Loader_Filesystem = $Twig_Loader_Filesystem; $this->Twig = $Twig; }