Пример #1
0
 public static function loadFile($file)
 {
     if (false === ($ffile = Pluf::fileExists($file))) {
         throw new Exception(sprintf(__('Fixture file not found: %s.'), $file));
     }
     return self::load(file_get_contents($ffile));
 }
Пример #2
0
 public static function url($file = '')
 {
     if ($file !== '' && Pluf::f('last_update_file', false) && false !== ($last_update = Pluf::fileExists(Pluf::f('last_update_file')))) {
         $file = $file . '?' . substr(md5(filemtime($last_update)), 0, 5);
     }
     return Pluf::f('url_media', Pluf::f('app_base') . '/media') . $file;
 }
Пример #3
0
 public static function loadSetLocale($lang)
 {
     $GLOBALS['_PX_current_locale'] = $lang;
     setlocale(LC_TIME, array($lang . '.UTF-8', $lang . '_' . strtoupper($lang) . '.UTF-8'));
     if (isset($GLOBALS['_PX_locale'][$lang])) {
         return;
         // We consider that it was already loaded.
     }
     $GLOBALS['_PX_locale'][$lang] = array();
     foreach (Pluf::f('installed_apps') as $app) {
         if (false != ($pofile = Pluf::fileExists($app . '/locale/' . $lang . '/' . strtolower($app) . '.po'))) {
             $GLOBALS['_PX_locale'][$lang] += Pluf_Translation::readPoFile($pofile);
         }
     }
 }
Пример #4
0
 /**
  * Find the migrations for the current app.
  *
  * @return array Migrations names indexed by order.
  */
 public function findMigrations()
 {
     $migrations = array();
     if (false !== ($mdir = Pluf::fileExists($this->app . '/Migrations'))) {
         $dir = new DirectoryIterator($mdir);
         foreach ($dir as $file) {
             $matches = array();
             if (!$file->isDot() && !$file->isDir() && preg_match('#^(\\d+)#', $file->getFilename(), $matches)) {
                 $info = pathinfo($file->getFilename());
                 $migrations[(int) $matches[1]] = $info['filename'];
             }
         }
     }
     return $migrations;
 }
Пример #5
0
 public function testFileExists()
 {
     $this->assertEquals(true, Pluf::fileExists('Pluf.php'));
     $this->assertEquals(true, Pluf::fileExists('PEAR.php'));
     $this->assertEquals(false, Pluf::fileExists('Pluf-dummy.php'));
 }
Пример #6
0
 /**
  * Load a function depending on its name.
  *
  * The implementation file of the function
  * MyApp_Youpla_Boum_Stuff() is MyApp/Youpla/Boum.php That way it
  * is possible to group all the related function in one file.
  *
  * Throw an exception if not possible to load the function.
  *
  * @param string Function to load.
  */
 public static function loadFunction($function)
 {
     if (function_exists($function)) {
         return;
     }
     $elts = explode('_', $function);
     array_pop($elts);
     $file = implode(DIRECTORY_SEPARATOR, $elts) . '.php';
     if (false !== ($file = Pluf::fileExists($file))) {
         include $file;
     }
     if (!function_exists($function)) {
         throw new Exception('Impossible to load the function: ' . $function);
     }
 }