Exemple #1
0
 protected function _writeFile()
 {
     if ($this->_file_writed) {
         return;
     }
     $this->_file_writed = true;
     $file = lmbFs::normalizePath($this->get('src'), lmbFs::UNIX);
     $abs_file = $this->getRootDir() . '/' . $file;
     if (!file_exists($abs_file)) {
         if ($this->getBool('safe', false)) {
             $this->_file_path = $abs_file;
             $this->_file_url = $this->get('src');
             return;
         } else {
             throw new lmbMacroException('File ' . $abs_file . ' not found!');
         }
     }
     $contents = file_get_contents($abs_file);
     $css_dir = dirname($file);
     if (preg_match_all('~url\\(([^\\)]+)\\)~', $contents, $matches)) {
         $replaces = array();
         foreach ($matches[1] as $key => $match) {
             $match = trim($match, '\'" ');
             $replaces[$matches[0][$key]] = 'url(' . $this->addVersion(lmbFs::normalizePath($css_dir . '/' . $match, lmbFs::UNIX)) . ')';
         }
         $contents = str_replace(array_keys($replaces), array_values($replaces), $contents);
     }
     $url = lmbFs::normalizePath(ltrim($this->get('dir') . '/' . str_replace('/', '-', $file), '/'));
     $path = $this->getRootDir() . '/' . $url;
     lmbFs::safeWrite($path, trim($contents));
     $this->_file_path = $path;
     $this->_file_url = $url;
 }
Exemple #2
0
 function getConf($name)
 {
     $name = $this->_normalizeConfName($name);
     if (isset($this->confs[$name])) {
         return $this->confs[$name];
     }
     $ext = substr($name, strpos($name, '.'));
     if ($ext == '.ini') {
         $file = $this->_locateConfFiles($name);
         if (lmb_env_has('LIMB_VAR_DIR')) {
             $this->confs[$name] = new lmbCachedIni($file, lmb_env_get('LIMB_VAR_DIR') . '/ini/');
         } else {
             $this->confs[$name] = new lmbIni($file);
         }
     } elseif ($ext == '.yml') {
         $file = $this->_locateConfFiles($name);
         $this->confs[$name] = $this->parseYamlFile(lmbFs::normalizePath($file));
     } elseif ($ext == '.conf.php') {
         $file = $this->_locateConfFiles($name);
         if (!count($file)) {
             throw new lmbFileNotFoundException($name);
         }
         $this->confs[$name] = new lmbConf(lmbFs::normalizePath($file));
     } else {
         throw new lmbException("'{$ext}' type configuration is not supported!");
     }
     return $this->confs[$name];
 }
Exemple #3
0
 protected function _writeFile()
 {
     if ($this->_file_writed) {
         return;
     }
     $files = array();
     $join_contents = '';
     foreach ($this->children as $child) {
         if ($child instanceof lmbJsRequireOnceMacroTag) {
             $file = $child->getFilePath();
             if (!is_file($file) || !realpath($file) || null === ($content = file_get_contents($file))) {
                 if ($child->getBool('safe')) {
                     $join_contents .= "\n/* include " . basename($file) . " - NOT FOUND */\n";
                     continue;
                 } else {
                     throw new lmbMacroException('File "' . $file . '" not found in ' . $this->getRootDir() . ', src: "' . $child->get('src') . '"');
                 }
             }
             $file = lmbFs::normalizePath(realpath($file));
             if (!in_array($file, $files)) {
                 $files[] = $file;
                 $join_contents .= "\n/* include " . basename($file) . " */\n" . $content;
             }
         }
     }
     sort($files, SORT_STRING);
     $url = lmbFs::normalizePath(ltrim($this->get('dir') . '/' . md5(implode("\n", $files)) . '.js', '/'));
     $path = $this->getRootDir() . '/' . $url;
     lmbFs::safeWrite($path, trim($join_contents));
     $this->_file_path = $path;
     $this->_file_url = $url;
     $this->_file_writed = true;
 }
 function testLocateAll()
 {
     $locator = new lmbFileLocator($mock = new MockFileLocations());
     $mock->expectOnce('getLocations');
     $mock->setReturnValue('getLocations', array(dirname(__FILE__) . '/design/', dirname(__FILE__) . '/design/_en/'));
     $all_files = $locator->locateAll('*.html');
     sort($all_files);
     $this->assertEqual(lmbFs::normalizePath($all_files[0]), lmbFs::normalizePath(dirname(__FILE__) . '/design/test1.html'));
     $this->assertEqual(lmbFs::normalizePath($all_files[1]), lmbFs::normalizePath(dirname(__FILE__) . '/design/_en/test1.html'));
 }
 function processFile($file)
 {
     $file = lmbFs::normalizePath($file);
     if ($this->_isProcessed($file)) {
         return '';
     }
     $contents = file_get_contents($file);
     $this->_markAsProcessed($file);
     $result = $this->_processDirectives($contents);
     return $result;
 }
Exemple #6
0
 function getLogDSNes()
 {
     $default_dsn = 'file://' . lmbFs::normalizePath(lmb_env_get('LIMB_VAR_DIR') . '/log/error.log');
     if (!$this->toolkit->hasConf('common')) {
         return array($default_dsn);
     }
     $conf = $this->toolkit->getConf('common');
     if (!isset($conf['logs'])) {
         return array($default_dsn);
     }
     return $conf['logs'];
 }
Exemple #7
0
 function getFileUrl()
 {
     return lmbFs::normalizePath($this->get('src'), lmbFs::UNIX);
 }
 function assertPathsEqual($path1, $path2, $msg = false)
 {
     $this->assertEqual(rtrim(lmbFs::normalizePath($path1), '/\\'), rtrim(lmbFs::normalizePath($path2), '/\\'), $msg);
 }
 function testFindRecursive()
 {
     $this->_createFileSystem();
     $res = lmbFs::findRecursive(LIMB_VAR_DIR . '/tmp/', 'fd', '~test\\d_1~');
     $this->assertEqual($this->_sort($res), $this->_sort(array(lmbFs::normalizePath(LIMB_VAR_DIR . '/tmp/test1_1'), lmbFs::normalizePath(LIMB_VAR_DIR . '/tmp/wow/hey/test3_1'), lmbFs::normalizePath(LIMB_VAR_DIR . '/tmp/wow/test2_1'))));
     $this->_removeFileSystem();
 }
 function _assertFile($it, $path, $line = '')
 {
     $this->assertTrue($it->valid(), '%s ' . $line);
     $this->assertFalse($it->isDot(), '%s ' . $line);
     $this->assertFalse($it->isDir(), '%s ' . $line);
     $this->assertTrue($it->isFile(), '%s ' . $line);
     $this->assertEqual(lmbFs::normalizePath($it->getPath()), lmbFs::normalizePath($path), '%s ' . $line);
 }