static function execute($source, $destination, $level, $class, $is_top, $lazy)
 {
     $source = patchwork_realpath($source);
     if (self::$recursivePool && $lazy) {
         $pool =& self::$recursivePool[count(self::$recursivePool) - 1];
         $pool[$source] = array($destination, $level, $class, $is_top);
         return;
     }
     $pool = array($source => array($destination, $level, $class, $is_top));
     self::$recursivePool[] =& $pool;
     $tmpPool = array();
     while (list($source, list($destination, $level, $class, $is_top)) = each($pool)) {
         $preproc = new self();
         $code = $preproc->preprocess($source, $level, $class, $is_top);
         $tmp = PATCHWORK_PROJECT_PATH . '.~' . uniqid(mt_rand(), true);
         if (false !== file_put_contents($tmp, $code)) {
             $tmpPool[] = array($tmp, $destination);
         }
     }
     while (list($tmp, $destination) = array_pop($tmpPool)) {
         /**/
         if ('\\' === DIRECTORY_SEPARATOR) {
             file_exists($destination) && @unlink($destination);
         }
         rename($tmp, $destination) || unlink($tmp);
     }
     array_pop(self::$recursivePool);
 }
 function getParentApps($realpath)
 {
     $parent = array();
     $config = $realpath . 'config.patchwork.php';
     // Get config's source and clean it
     $source = file_get_contents($config);
     $i = error_reporting(81);
     $source = token_get_all($source);
     error_reporting($i);
     if ($source) {
         $i = T_INLINE_HTML === $source[0][0] ? 2 : 1;
         $len = count($source);
         while ($i < $len) {
             $a = $source[$i++];
             if (in_array($a[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), true)) {
                 if (T_COMMENT === $a[0] && '#patchwork' === rtrim(substr($a[1], 0, 11), " \t")) {
                     $parent[] = trim(substr($a[1], 11));
                 }
             } else {
                 break;
             }
         }
     }
     // Parent's config file path is relative to the current application's directory
     $len = count($parent);
     for ($i = 0; $i < $len; ++$i) {
         $a = $parent[$i];
         if ('__patchwork__' == substr($a, 0, 13)) {
             $a = $this->basePath . substr($a, 13);
         }
         if ('/' !== $a[0] && '\\' !== $a[0] && ':' !== $a[1]) {
             $a = $realpath . $a;
         }
         if ('/*' === substr(strtr($a, '\\', '/'), -2) && ($a = patchwork_realpath(substr($a, 0, -2)))) {
             $a = rtrim($a, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
             $source = array();
             $p = array($a);
             $parent[$i] = $a;
             $pLen = 1;
             for ($j = 0; $j < $pLen; ++$j) {
                 $d = $p[$j];
                 if (file_exists($d . 'config.patchwork.php')) {
                     $source[] = $d;
                 } else {
                     if ($h = opendir($d)) {
                         while (false !== ($file = readdir($h))) {
                             '.' !== $file[0] && is_dir($d . $file) && ($p[$pLen++] = $d . $file . DIRECTORY_SEPARATOR);
                         }
                         closedir($h);
                     }
                 }
                 unset($p[$j]);
             }
             $p = array();
             foreach ($source as $source) {
                 if ($this->rootPath !== $source && $realpath !== $source) {
                     foreach ($this->c3mro->linearize($source) as $a) {
                         if (false !== ($a = array_search($a, $p))) {
                             $p[$a] = $source;
                             $source = false;
                             break;
                         }
                     }
                     $source && ($p[] = $source);
                 }
             }
             $a = count($p);
             array_splice($parent, $i, 1, $p);
             $i += --$a;
             $len += $a;
         } else {
             if (!file_exists($a . '/config.patchwork.php')) {
                 throw new Patchwork_Bootstrapper_Exception('Missing file ' . rtrim(strtr($parent[$i], '\\', '/'), '/') . '/config.patchwork.php in ' . $config);
             }
             $a = patchwork_realpath($a);
             $a = rtrim($a, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
             if ($this->rootPath === $a) {
                 unset($parent[$i]);
             } else {
                 $parent[$i] = $a;
             }
         }
     }
     $this->rootPath === $realpath && array_unshift($parent, $this->topPath);
     return $parent;
 }
Пример #3
0
 protected function initInheritance()
 {
     $this->cwd = rtrim(patchwork_realpath($this->cwd), '/\\') . DIRECTORY_SEPARATOR;
     $a = $this->bootstrapper . '_Inheritance';
     $a = new $a();
     $a = $a->linearizeGraph($this->pwd, $this->cwd, $this->base);
     $b = array_slice($a[0], 0, $a[1]);
     foreach (array_reverse($b) as $c) {
         if (file_exists($c .= 'bootup.patchwork.php')) {
             $this->steps[] = array(null, $c);
         }
     }
     $b[] = $this->pwd;
     foreach ($b as $c) {
         if (file_exists($c .= 'config.patchwork.php')) {
             $this->steps[] = array(null, $c);
         }
     }
     $this->paths = $a[0];
     $this->last = $a[1];
 }