/** * Autoloader for Photon. */ function photonAutoLoad($class) { $parts = array_filter(explode('\\', $class)); if (1 < count($parts)) { // We have a namespace. $class_name = array_pop($parts); $file = implode(DIRECTORY_SEPARATOR, $parts) . '.php'; } else { $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; } // As we load only once to have everything is the process, the // require_once instead of require penalty is low. But the // require_once will prevent double loading a file and will result // in non confusing error messages. // printf("Class: %s, file: %s\n", $class, $file); $includePath = \photon\path\Dir::getIncludePath(); foreach ($includePath as $path) { $fullpath = $path . DIRECTORY_SEPARATOR . $file; if (is_readable($fullpath)) { require_once $fullpath; break; } } }
public function run() { $this->loadConfig(); $folders = Conf::f('template_folders', array()); $tmp_folder = sys_get_temp_dir() . '/' . uniqid('photon', true); @mkdir($tmp_folder); @touch($this->potfile); // Compile all template to generate PHP Code $already_compiled = array(); foreach ($folders as $folder) { foreach (\photon\path\Dir::listFiles($folder) as $tpl) { if (!in_array($tpl, $already_compiled)) { // Compile the template $compiler = new compiler\Compiler($tpl, $folders); $content = $compiler->compile(); // save it $output = $tmp_folder . '/' . $tpl; $directory = dirname($output); if (is_dir($directory) === false) { mkdir($directory, 0777, true); } file_put_contents($output, $content); $already_compiled[] = $tpl; } } } $return_var = 0; // Run xgettext on PHP project source $cmd = 'cd ' . $this->cwd . ' && find . -type f -iname "*.php" | sed -e \'s/^\\.\\///\' | xargs xgettext -o ' . $this->potfile . ' -p ' . $this->cwd . ' --from-code=UTF-8 -j --keyword --keyword=__ --keyword=_n:1,2 -L PHP'; passthru($cmd, $return_var); // Run xgettext on PHP project compiled template source $cmd = 'cd ' . $tmp_folder . ' && find . -type f | sed -e \'s/^\\.\\///\' | xargs xgettext -o ' . $this->potfile . ' -p ' . $this->cwd . ' --from-code=UTF-8 -j --keyword --keyword=__ --keyword=_n:1,2 -L PHP'; passthru($cmd, $return_var); \photon\path\Dir::remove($tmp_folder); }
public function testListFiles() { // review this test, adding a file in the data folder breaks it... $this->assertEquals(13, count(Dir::listFiles(__DIR__ . '/../data'))); }
/** * Load the locales of a lang. * * It does not activate the locale. * * @param $lang Language to load * @param $photon Load the Photon translations (true) * @return array Path to loaded file */ public static function loadLocale($lang, $photon = true) { $locale_folders = Conf::f('locale_folders', array()); $path_folders = Dir::getIncludePath(); $loaded = array(); self::$loaded[$lang] = array(); if ($photon) { $pofile = sprintf('%s/locale/%s/photon.po', __DIR__, $lang); if (file_exists($pofile)) { self::$loaded[$lang] += self::readPoFile($pofile); $loaded[] = $pofile; } } foreach ($locale_folders as $locale_folder) { foreach ($path_folders as $path_folder) { $pofile = sprintf('%s/%s/%s.po', $path_folder, $locale_folder, $lang); if (file_exists($pofile)) { self::$loaded[$lang] += self::readPoFile($pofile); $loaded[] = $pofile; break; } } } if (count($loaded)) { self::$plural_forms[$lang] = plural_to_php(file_get_contents($loaded[0])); } return $loaded; }