예제 #1
0
 static function __tt780_include($query, $uri, $search = null, $in_configuration = null, $pointer = null)
 {
     if (strpos('path:', $uri) !== false) {
         $uri = str_replace('path:', '', $uri);
         if ($search) {
             $uri = Paths::compose($search, dirname($pages[$uri])) . basename($pages[$uri]);
         }
         return file_exists($uri) ? $uri : null;
     }
     if (preg_match('/^\\w+$/', $uri)) {
         return $uri;
     }
     return true;
 }
예제 #2
0
 static function __tt780_include($query, $uri, $search = null)
 {
     if (!is_string($uri)) {
         return null;
     }
     if (strpos($uri, ':') != -1) {
         $aux = explode(':', $uri);
         $uri = $aux[0];
     }
     // adjust path to be visible from 'search' location, maybe with absolute path (realpath) its more easy... anyway
     if ($uri && $search) {
         $uri = Paths::compose($search, $uri);
     }
     return file_exists($uri) ? $uri : null;
 }
예제 #3
0
 static function __tt780_include($query, $uri, $search = null)
 {
     $query = explode('.', $query);
     $pages = !is_array($uri) ? array($query[1] => $uri) : $uri;
     if (!isset($pages[$query[1]])) {
         return null;
     }
     if (strpos('path:', $pages[$query[1]]) !== false) {
         $pages[$query[1]] = str_replace('path:', '', $pages[$query[1]]);
     }
     // adjust path to be visible from 'search' location, maybe with absolute path (realpath) its more easy... anyway
     if ($search) {
         $pages[$query[1]] = Paths::compose($search, dirname($pages[$query[1]])) . basename($pages[$query[1]]);
     }
     if (is_dir($pages[$query[1]])) {
         $pages[$query[1]] = "{$pages[$query[1]]}{$query[1]}.php";
     }
     return file_exists($pages[$query[1]]) ? $pages[$query[1]] : null;
 }
예제 #4
0
 function parameter_source($name, $value, $parameters, $origin = null)
 {
     $default = null;
     if (preg_match('/^source:([^:]+)(?:\\:(.+))?$/', $value, $aux)) {
         $value = $aux[1];
         $default = isset($aux[2]) ? $aux[2] : null;
     }
     if ($origin == 'configuration_file') {
         $paths = new Paths();
         $this->target = $paths->compose(dirname($parameters->getParameter('configuration_file')), $value);
     } else {
         $this->target = $value;
     }
     //$this->__save(null, $default);
     if (!file_exists($this->target)) {
         if (!@touch($this->target)) {
             return $this->addError('can\'t create the target: ' . $this->target);
         }
     }
 }
예제 #5
0
파일: Control.php 프로젝트: axoquen/tt780
 private function __h_include($query, $tracking = false)
 {
     if (!isset($GLOBALS['tt780'][$this->id]['includes'])) {
         $GLOBALS['tt780'][$this->id]['includes'] = array();
     }
     if ($tracking) {
         echo "<b>include</b>: {$query}. <br>\n";
     }
     // in "cache"
     if (isset($GLOBALS['tt780'][$this->id]['includes'][$query])) {
         if ($tracking) {
             echo "localization in cache<br>\n";
         }
         return $GLOBALS['tt780'][$this->id]['includes'][$query];
     }
     list($handler, $method, $query, $explicit) = $this->__h_extract($query);
     // search
     // ... resource extern to configuration file,
     // "in-line" declared, run-time query  :       component:/path/file/class.php
     if ($explicit) {
         if (!file_exists($explicit[1])) {
             return null;
         }
         if ($tracking) {
             echo "extern configuration: {$explicit[1]}<br>\n";
         }
         return $GLOBALS['tt780'][$this->id]['includes'][$query] = array($explicit[1], $explicit[0], $query);
     }
     // ... resource lambda
     if (isset($GLOBALS['tt780'][$this->id]['configuration'][$query]) && is_object($GLOBALS['tt780'][$this->id]['configuration'][$query]) && $GLOBALS['tt780'][$this->id]['configuration'][$query] instanceof Closure) {
         if ($tracking) {
             echo "explicitly declared like: lambda function <br>\n";
         }
         return $GLOBALS['tt780'][$this->id]['includes'][$query] = array($GLOBALS['tt780'][$this->id]['configuration'][$query], 'lambda', $query);
     }
     // ... resource explicitly declared
     if (($pointer = isset($GLOBALS['tt780'][$this->id]['configuration']["{$handler}.{$method}"]) ? "{$handler}.{$method}" : null) || ($pointer = isset($GLOBALS['tt780'][$this->id]['configuration'][$handler]) ? $handler : null)) {
         if ($tracking) {
             echo "explicitly declared in configuration like: '{$pointer}'<br>\n";
         }
         // extends... 20140206
         if ($pointer == "{$handler}.{$method}" && isset($GLOBALS['tt780'][$this->id]['configuration'][$handler])) {
             $GLOBALS['tt780'][$this->id]['configuration'][$pointer] = array_merge($GLOBALS['tt780'][$this->id]['configuration'][$handler], $GLOBALS['tt780'][$this->id]['configuration']["{$handler}.{$method}"]);
         }
         foreach (Control::$types as $t_key => $t_handler) {
             if (is_array($GLOBALS['tt780'][$this->id]['configuration'][$pointer]) && isset($GLOBALS['tt780'][$this->id]['configuration'][$pointer][$t_key])) {
                 if ($tracking) {
                     echo "\t type explicitly declared like \"{$t_key}\" whit \"{$GLOBALS['tt780'][$this->id]['configuration'][$pointer][$t_key]}\"<br>\n";
                 }
                 if (!class_exists($t_handler)) {
                     tt780_loader($t_handler);
                 }
                 // $query
                 // $uri    ... uri, configuration string of the handlar
                 // $search ... if the values on uri string these need adjust in relation to this path
                 // $in_configuration ... parameters
                 // $pointer ... $query string is no necesary the same key on the configuration file (pointer)
                 eval("\n                        \$res = {$t_handler}::__TT780_include(\n                            '{$query}',\n                            \$GLOBALS['tt780'][\$this->id]['configuration'][\$pointer][\$t_key],\n                            \$GLOBALS['tt780'][\$this->id]['search_path'],\n\n                            \$GLOBALS['tt780'][\$this->id]['configuration'][\$pointer],\n                            \$pointer\n                        );\n                    ");
                 if ($tracking) {
                     echo "\t including with " . ($res ? print_r($res, true) : '--') . "<br>\n";
                 }
                 return $res ? $GLOBALS['tt780'][$this->id]['includes'][$query] = array($res, $t_key, $pointer) : null;
             }
         }
     }
     // ... resource localization by conventions
     if (!isset($GLOBALS['tt780'][$this->id]['configuration']['convention'])) {
         return null;
     }
     $h = array_keys($GLOBALS['tt780'][$this->id]['configuration']['convention']);
     foreach ($h as $mode) {
         // clean plural name ¬¬
         // $mode = "{$t_key}s";
         $t_key = preg_replace('/s$/', '', $mode);
         if (!isset(Control::$types[$t_key])) {
             continue;
         }
         $t_handler = Control::$types[$t_key];
         if ($tracking) {
             echo "localization by conventions: like {$mode}<br>\n";
         }
         if (!isset($GLOBALS['tt780'][$this->id]['configuration']['convention'][$mode])) {
             continue;
         }
         if (!is_array($GLOBALS['tt780'][$this->id]['configuration']['convention'][$mode])) {
             $GLOBALS['tt780'][$this->id]['configuration']['convention'][$mode] = array($GLOBALS['tt780'][$this->id]['configuration']['convention'][$mode]);
         }
         foreach ($GLOBALS['tt780'][$this->id]['configuration']['convention'][$mode] as $reg_exp => $template) {
             if ($tracking) {
                 echo "localization by conventions: try {$reg_exp} <br>\n";
             }
             $last = error_get_last();
             $preg_match = @preg_match($reg_exp, $query, $aux);
             if (($err = error_get_last()) !== null && $err['message'] != $last['message'] && $err['file'] != $last['file'] && $err['line'] != $last['line']) {
                 trigger_error(defined('TT780_DEBUG') ? "Regular expresion error: '{$reg_exp}': " . $err['message'] . "<br>In convention configuration \"" . $GLOBALS['tt780'][$this->id]['globals']->getParameter('configuration_file') . "\"" : "System Error", E_USER_ERROR);
             }
             if ($preg_match === false) {
                 if ($tracking) {
                     echo "... NO<br>\n";
                 }
                 continue;
             }
             $replaces = array('__HANDLER__' => $handler, '__METHOD__' => $method);
             for ($i = 1; $i < count($aux); $i++) {
                 $replaces["\${$i}"] = $aux[$i];
             }
             if (!is_array($template)) {
                 $template = array($template);
             }
             foreach ($template as $t) {
                 if (!class_exists($t_handler)) {
                     tt780_loader($t_handler);
                 }
                 if ($tracking) {
                     echo "&nbsp; &nbsp; search in: {$t}";
                 }
                 $res = Paths::compose($GLOBALS['tt780'][$this->id]['search_path'], str_replace(array_keys($replaces), $replaces, $t));
                 // check if can include
                 eval("\n                        \$exists = {$t_handler}::__TT780_include(\n                            '{$query}',\n                            '{$res}'\n                        );\n                    ");
                 if (!$exists) {
                     if ($tracking) {
                         echo "... NO<br>\n";
                     }
                     continue;
                 }
                 if ($tracking) {
                     echo "... <b>YES</b><br>\n";
                     echo "&nbsp; &nbsp; &nbsp; {$t_key}:{$handler} {$res}";
                 }
                 return $GLOBALS['tt780'][$this->id]['includes'][$query] = array($res, $t_key, $handler);
             }
         }
     }
     return null;
 }
예제 #6
0
 function parameter_path($name, $value, $parameters)
 {
     $paths = new Paths();
     $this->value = $paths->compose(dirname($parameters->getParameter('configuration_file')), substr($value, 5) . '/');
 }
예제 #7
0
 function parameter_file($name, $value, $parameters, $origin = null)
 {
     $this->name = basename(substr($value, 5));
     $paths = new Paths();
     $this->path = $paths->compose(dirname($parameters->getParameter('configuration_file')), substr(dirname($value) . '/', 5));
 }
예제 #8
0
 private static function __scp($query, $origin, $destiny)
 {
     if (handler_lend::$trace) {
         var_dump(Handler::__from());
     }
     if (handler_lend::$hl[$query]['type'] == 'ssh-client') {
         return handler_lend::__exec("scp " . " {$origin}" . " " . handler_lend::$hl[$query]['user'] . "@" . handler_lend::$hl[$query]['host'] . ":{$destiny}", $query);
     }
     if (handler_lend::$hl[$query]['type'] == 'local') {
         //            $destiny = handler_lend::$hl[$query]['path'] . $destiny;
         $destiny = Paths::compose(handler_lend::$hl[$query]['path'], $destiny);
         return handler_lend::__exec("cp {$origin} {$destiny}", $query);
     }
     return null;
 }