示例#1
0
function unadcalendar_find_calendar(Slim\Route $route)
{
    global $app, $info;
    $curso = $route->getParam('cs');
    $email = $route->getParam('em');
    $gcVersion = $info['google/calendar']['version'];
    $clientId = $info['unadcalendar']['client_id'];
    $rqCalendar = google_calendar_find($gcVersion, $clientId, $curso)->body();
    $rqCalendar = json_decode($rqCalendar);
    if ($rqCalendar->status) {
        //no existe problemas
        $calendarId = $rqCalendar->calendar->id;
        $rqEvents = google_calendar_get_events($gcVersion, $clientId, $calendarId)->body();
        $rqEvents = json_decode($rqEvents);
        if (!$rqEvents->status) {
            return;
        }
        $mpEvent = _unadcalendar_map_events($calendarId, $rqEvents->events, $email);
        if (is_null($mpEvent)) {
            //existe problemas con el calendario
            //no hay eventos, se elimina el calendario
            google_calendar_delete($gcVersion, $clientId, $calendarId);
            return;
        }
        $request['name'] = get_course_by_code(JSON_COUSER, $rqCalendar->calendar->summary);
        $request['code'] = $rqCalendar->calendar->summary;
        $request['status'] = true;
        $request['calendar_id'] = $calendarId;
        $request['events'] = $mpEvent;
        $app->response()->body(json_encode($request));
        $app->stop();
    }
}
示例#2
0
 protected function addRoute($route, $pathStr)
 {
     $method = "any";
     if (strpos($pathStr, "@") !== false) {
         list($pathStr, $method) = explode("@", $pathStr);
     }
     $func = $this->processCallback($pathStr);
     $r = new \Slim\Route($route, $func);
     $r->setHttpMethods(strtoupper($method));
     array_push($this->routes, $r);
 }
 public function addRoutes($routes)
 {
     foreach ($routes as $route => $path) {
         $method = "any";
         if (strpos($path, "@") !== false) {
             list($path, $method) = explode("@", $path);
         }
         $func = $this->processCallback($path);
         $r = new \Slim\Route($route, $func);
         $r->setHttpMethods(strtoupper($method));
         array_push($this->routes, $r);
     }
 }
示例#4
0
 protected function setUp()
 {
     if (!interface_exists('\\Psr\\Http\\Message\\ServerRequestInterface')) {
         $this->markTestSkipped('\\Psr\\Http\\Message\\ServerRequestInterface is not available');
     }
     if (!class_exists('\\Slim\\Route')) {
         $this->markTestSkipped('\\Slim\\Route is not available');
     }
     $view = new \Aimeos\MW\View\Standard();
     $route = new \Slim\Route(array('GET'), '/shop', null);
     $route->setName('route');
     $this->mock = $this->getMockBuilder('\\Psr\\Http\\Message\\ServerRequestInterface')->getMock();
     $this->mock->expects($this->once())->method('getAttribute')->will($this->returnValue($route));
     $this->mock->expects($this->once())->method('getServerParams')->will($this->returnValue(array('REMOTE_ADDR' => '127.0.0.1')));
     $this->object = new \Aimeos\MW\View\Helper\Request\Slim($view, $this->mock);
 }
 /**
  * @param Route $route
  */
 public function addRoute(Route $route)
 {
     $slimRoute = new \Slim\Route($route->getPath(), [$this, 'dummyCallable']);
     $slimRoute->setName($route->getName());
     $allowedMethods = $route->getAllowedMethods();
     $slimRoute->via($allowedMethods === Route::HTTP_METHOD_ANY ? 'ANY' : $allowedMethods);
     // Process options
     $options = $route->getOptions();
     if (isset($options['conditions']) && is_array($options['conditions'])) {
         $slimRoute->setConditions($options['conditions']);
     }
     // The middleware is merged with the rest of the route params
     $params = ['middleware' => $route->getMiddleware()];
     if (isset($options['defaults']) && is_array($options['defaults'])) {
         $params = array_merge($options['defaults'], $params);
     }
     $slimRoute->setParams($params);
     $this->router->map($slimRoute);
 }
示例#6
0
 /**
  * Test middleware with arguments
  */
 public function testRouteMiddlwareArguments()
 {
     $this->expectOutputString('foobar');
     $route = new \Slim\Route('/foo', function () {
         echo "bar";
     });
     $route->setName('foo');
     $route->setMiddleware(function ($route) {
         echo $route->getName();
     });
     $route->matches('/foo');
     //<-- Extracts params from resource URI
     $route->dispatch();
 }
示例#7
0
 /**
  * Test that a Route manages the HTTP methods that it supports
  *
  * Case A: Route initially supports no HTTP methods
  * Case B: Route can set its supported HTTP methods
  * Case C: Route can append supported HTTP methods
  * Case D: Route can test if it supports an HTTP method
  * Case E: Route can lazily declare supported HTTP methods with `via`
  */
 public function testHttpMethods()
 {
     //Case A
     $r = new \Slim\Route('/foo', function () {
     });
     $this->assertEmpty($r->getHttpMethods());
     //Case B
     $r->setHttpMethods('GET');
     $this->assertEquals(array('GET'), $r->getHttpMethods());
     //Case C
     $r->appendHttpMethods('POST', 'PUT');
     $this->assertEquals(array('GET', 'POST', 'PUT'), $r->getHttpMethods());
     //Case D
     $this->assertTrue($r->supportsHttpMethod('GET'));
     $this->assertFalse($r->supportsHttpMethod('DELETE'));
     //Case E
     $viaResult = $r->via('DELETE');
     $this->assertTrue($viaResult instanceof \Slim\Route);
     $this->assertTrue($r->supportsHttpMethod('DELETE'));
 }
示例#8
0
 public function testDispatchWithoutCallable()
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/hello/josh', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim'));
     $env = \Slim\Environment::getInstance();
     $req = new \Slim\Http\Request($env);
     $router = new \Slim\Router();
     $router->setResourceUri($req->getResourceUri());
     $route = new \Slim\Route('/hello/:name', 'foo');
     $route->matches($req->getResourceUri());
     //<-- Extracts params from resource URI
     $this->assertFalse($router->dispatch($route));
 }
示例#9
0
function google_calendar_valid_client(Slim\Route $route)
{
    global $app;
    $clientId = $route->getParam('clientId');
    $data = Spyc::YAMLLoad(dirname(__FILE__) . "/client/{$clientId}.yaml");
    if (!isset($data['key']) || !isset($data['key_api']) || !isset($data['key_client'])) {
        $request = array('status' => false, 'message' => 'Denied ClientID o Params not found');
        $app->response()->body(json_encode($request));
        $app->response()->status(302);
        $app->stop();
    }
}
示例#10
0
 /**
  * Führt das Modul entsprechend der Commands.json und Component.json Definitionen aus
  */
 public function run()
 {
     // runs the CConfig
     $com = new CConfig($this->_prefix, $this->_path, $this->_noInfo, $this->_noHelp);
     // lädt die Konfiguration des Moduls
     if ($com->used()) {
         return;
     }
     $conf = $com->loadConfig();
     $this->_conf = $conf;
     $this->_com = $com;
     $commands = $com->commands(array(), true, true);
     // multi Requests werden noch nicht unterstützt, das Model soll automatisch die Möglichkeit bieten,
     // mehrere Anfragen mit einmal zu beantworten
     ////$commands[] = array('name' => 'postMultiGetRequest','method' => 'POST', 'path' => '/multiGetRequest', 'inputType' => 'Link', 'outputType' => '');
     // Erstellt für jeden angebotenen Befehl einen Router
     // Ein Router stellt einen erlaubten Aufruf dar (mit Methode und URI), sodass geprüft werden kann,
     // welcher für die Beantwortung zuständig ist
     $router = new \Slim\Router();
     foreach ($commands as &$command) {
         if (!isset($command['name'])) {
             continue;
         }
         if (!isset($command['method'])) {
             $command['method'] = 'GET';
         }
         if (!isset($command['callback'])) {
             $command['callback'] = $command['name'];
         }
         if (!isset($command['seqInput'])) {
             $command['seqInput'] = 'TRUE';
         }
         if (!isset($command['singleOutput'])) {
             $command['singleOutput'] = 'FALSE';
         }
         if (!isset($command['placeholder'])) {
             $command['placeholder'] = array();
         }
         // Methoden können durch Komma getrennt aufgelistet sein
         $methods = explode(',', $command['method']);
         foreach ($methods as $method) {
             $route = new \Slim\Route($command['path'], array($this->_class, $command['callback']), false);
             $route->via(strtoupper($method));
             $route->setName($command['name']);
             $router->map($route);
             // wenn es ein GET Befehl ist, wird automatisch HEAD unterstützt
             if (strtoupper($method) == 'GET') {
                 // erzeugt einen HEAD Router
                 $route = new \Slim\Route($command['path'], array($this->_class, $command['callback']), false);
                 $route->via('HEAD');
                 $route->setName($command['name']);
                 $router->map($route);
             }
         }
     }
     // hier wird die eingehende URI erzeugt
     // Bsp.: /user/1
     $scriptName = $_SERVER['SCRIPT_NAME'];
     $requestUri = $_SERVER['REQUEST_URI'];
     $path = str_replace('?' . (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''), '', substr_replace($requestUri, '', 0, strlen(strpos($requestUri, $scriptName) !== false ? $scriptName : str_replace('\\', '', dirname($scriptName)))));
     // ermittelt den zuständigen Befehl
     $matches = $router->getMatchedRoutes(strtoupper($_SERVER['REQUEST_METHOD']), $path);
     if (count($matches) > 0) {
         // mindestens ein zutreffender Befehl wurde gefunden (nimm den Ersten)
         $matches = $matches[0];
         // suche den zugehörigen $commands Eintrag
         $selectedCommand = null;
         foreach ($commands as $command) {
             if ($command['name'] === $matches->getName()) {
                 $selectedCommand = $command;
                 break;
             }
         }
         if ($selectedCommand == null) {
             http_response_code(500);
             return;
         }
         // lies die eingehenden PHP Daten
         $rawInput = \Slim\Environment::getInstance()->offsetGet('slim.input');
         if (!$rawInput) {
             $rawInput = @file_get_contents('php://input');
         }
         // wir wollen wissen, ob die Eingabedaten als Liste rein kommen
         $arr = true;
         // wenn zu diesem Befehl ein inputType angegeben wurde, wird eine Type::decodeType() aufgerufen
         if (isset($selectedCommand['inputType']) && trim($selectedCommand['inputType']) != '') {
             $inputType = $selectedCommand['inputType'];
             $rawInput = call_user_func_array('\\' . $inputType . '::decode' . $inputType, array($rawInput));
             if (!is_array($rawInput)) {
                 // es ist keine Liste, also mach eine daraus (damit man sie einheitlich behandeln kann)
                 $rawInput = array($rawInput);
                 $arr = false;
             }
         }
         if (strtoupper($selectedCommand['seqInput']) != 'TRUE') {
             $arr = false;
         }
         $params = $matches->getParams();
         $placeholder = array();
         // prüfe die Bedingungen für die Platzhalter
         foreach ($selectedCommand['placeholder'] as $holder) {
             if (!isset($holder['name'])) {
                 continue;
             }
             if (!isset($holder['regex'])) {
                 continue;
             }
             $placeholder[$holder['name']] = $holder['regex'];
         }
         /*foreach ($params as $key => $value){
               if (isset($placeholder[$key])){
                   if (is_array($value)){
                       // wenn es ein Array ist, wurde ein :Element+ verwendet (Slim)
                       // daher wird der Ausdruck auf jedes Element angewendet
                       foreach($value as $val){
                           $pregRes = @preg_match($placeholder[$key], $val);
                           if ($pregRes === false){
                               error_log(__FILE__.':'.__LINE__.' '.$placeholder[$key].' konnte nicht interpretiert werden');
                               $this->finishRequest(self::isError());
                               return;
                           } else if ($pregRes === 0){
                               error_log(__FILE__.':'.__LINE__.' '.$val.' passt nicht zu '.$placeholder[$key]);
                               $this->finishRequest(self::isPreconditionError());
                               return;
                           }
                       }
                   } else {
                       // einzelnes Element für Slim verwendet :Element
                       $pregRes = @preg_match($placeholder[$key], $value);
                       if ($pregRes === false){
                           error_log(__FILE__.':'.__LINE__.' '.$placeholder[$key].' konnte nicht interpretiert werden');
                           $this->finishRequest(self::isError());
                           return;
                       } else if ($pregRes === 0){
                           error_log(__FILE__.':'.__LINE__.' '.$value.' passt nicht zu '.$placeholder[$key]);
                           $this->finishRequest(self::isPreconditionError());
                           return;
                       }
                   }
               }
           }*/
         // nun soll die zugehörige Funktion im Modul aufgerufen werden
         if (isset($selectedCommand['inputType']) && trim($selectedCommand['inputType']) != '' && isset($rawInput)) {
             // initialisiert die Ausgabe positiv
             $result = array("status" => 201, "content" => array());
             if (strtoupper($selectedCommand['seqInput']) == 'TRUE') {
                 try {
                     // für jede Eingabe wird die Funktion ausgeführt
                     foreach ($rawInput as $input) {
                         // Aufruf der Modulfunktion
                         $res = call_user_func_array($matches->getCallable(), array($selectedCommand['name'], "input" => $input, $params));
                         // wenn es ein Ausgabeobjekt gibt, wird versucht dort einen Status zu setzen
                         if (is_callable(array($res['content'], 'setStatus'))) {
                             $res['content']->setStatus($res['status']);
                         }
                         // setze Status und Ausgabe
                         $result["content"][] = $res['content'];
                         if (isset($res['status'])) {
                             $result["status"] = $res['status'];
                         }
                     }
                 } catch (Exception $e) {
                     header_remove();
                     error_log($e->getMessage());
                     $this->finishRequest(self::isError());
                     return;
                 }
             } else {
                 try {
                     // Aufruf der Modulfunktion
                     $res = call_user_func_array($matches->getCallable(), array($selectedCommand['name'], "input" => $rawInput, $params));
                     // wenn es ein Ausgabeobjekt gibt, wird versucht dort einen Status zu setzen
                     if (is_callable(array($res['content'], 'setStatus'))) {
                         $res['content']->setStatus($res['status']);
                     }
                     // setze Status und Ausgabe
                     $result["content"] = $res['content'];
                     if (isset($res['status'])) {
                         $result["status"] = $res['status'];
                     }
                 } catch (Exception $e) {
                     header_remove();
                     error_log($e->getMessage());
                     $this->finishRequest(self::isError());
                     return;
                 }
             }
         } else {
             // wenn keinen vorgegebenen Eingabetyp gibt, wird die Eingabe direkt an die Modulfunktion weitergegeben
             $result = call_user_func_array($matches->getCallable(), array($selectedCommand['name'], "input" => $rawInput, $params));
         }
         if ($selectedCommand['method'] == 'HEAD') {
             // Bei einer HEAD Funktion (die eventuell im Modul als GET bearbeitet wird),
             // kann die Ausgabe verworfen werden
             $result['content'] = '';
         } elseif (isset($selectedCommand['outputType']) && trim($selectedCommand['outputType']) != '' && trim($selectedCommand['outputType']) != 'binary') {
             // wenn ein Ausgabetyp angegeben ist, wird eine Typ::encodeTyp() ausgeführt
             $outputType = $selectedCommand['outputType'];
             if (isset($result['content'])) {
                 if (!is_array($result['content'])) {
                     $result['content'] = array($result['content']);
                 }
                 if ($command['singleOutput'] !== 'FALSE' && count($result['content']) >= 1) {
                     $result['content'] = $result['content'][0];
                 } elseif (!$arr && count($result['content']) == 1) {
                     $result['content'] = $result['content'][0];
                 }
                 $result['content'] = call_user_func_array('\\' . $outputType . '::encode' . $outputType, array($result['content']));
             }
             header('Content-Type: application/json');
         } elseif (isset($selectedCommand['outputType']) && trim($selectedCommand['outputType']) == 'binary') {
             // wenn der Ausgabetyp "binär" ist, erfolgt keine Anpassung
         } else {
             // selbst wenn nichts zutrifft, wird json kodiert
             if (isset($result['content'])) {
                 $result['content'] = json_encode($result['content']);
             }
             header('Content-Type: application/json');
         }
     } else {
         // es wurde kein zutreffender Befehl gefunden, also gibt es eine leere Antwort
         $this->finishRequest(self::isError());
         return;
     }
     // ab hier werden die Ergebnisse ausgegeben
     $this->finishRequest($result);
 }
示例#11
0
 public static function show($console, $result, $data)
 {
     $isUpdate = isset($data['action']) && $data['action'] == 'update' ? true : false;
     $text = '';
     if (!$console) {
         $text .= Design::erstelleBeschreibung($console, Language::Get('components', 'description'));
         $text .= Design::erstelleZeile($console, Language::Get('components', 'init'), 'e', '', 'v', Design::erstelleSubmitButton(self::$onEvents['install']['event'][0]), 'h');
         $text .= Design::erstelleZeile($console, Language::Get('components', 'details'), 'e', Design::erstelleAuswahl($console, $data['CO']['co_details'], 'data[CO][co_details]', 'details', null, true), 'v');
     }
     if (isset($result[self::$onEvents['install']['name']]) && $result[self::$onEvents['install']['name']] != null) {
         $result = $result[self::$onEvents['install']['name']];
     } else {
         $result = array('content' => null, 'fail' => false, 'errno' => null, 'error' => null);
     }
     $fail = $result['fail'];
     $error = $result['error'];
     $errno = $result['errno'];
     $content = $result['content'];
     if (self::$installed) {
         // counts installed commands
         $installedCommands = 0;
         // counts installed components
         $installedComponents = 0;
         // counts installed links
         $installedLinks = 0;
         foreach ($content as $componentName => &$component) {
             if (isset($component['init'])) {
                 $component['init'] = Component::decodeComponent(json_encode($component['init']));
             }
             if (isset($component['links'])) {
                 $component['links'] = Link::decodeLink(json_encode($component['links']));
             }
             if (isset($component['commands'])) {
                 $router = new \Slim\Router();
                 foreach ($component['commands'] as $command) {
                     $route = new \Slim\Route($command['path'], 'is_array');
                     $route->via(isset($command['method']) ? strtoupper($command['method']) : 'GET');
                     $router->map($route);
                 }
                 $component['router'] = $router;
             }
         }
         foreach ($content as $componentName => $component) {
             $linkNames = array();
             $linkNamesUnique = array();
             $callNames = array();
             $links = array();
             if (isset($component['links'])) {
                 $links = $component['links'];
             }
             foreach ($links as $link) {
                 $linkNames[] = $link->getName();
                 $linkNamesUnique[$link->getName()] = $link->getName();
             }
             $calls = null;
             if (isset($component['call'])) {
                 $calls = $component['call'];
             }
             if ($calls !== null) {
                 foreach ($calls as $pos => $callList) {
                     if (isset($callList['name'])) {
                         $callNames[$callList['name']] = $callList['name'];
                     }
                 }
             }
             $countLinks = 1;
             if (isset($component['init']) && $component['init'] !== null && $component['init']->getStatus() === 201) {
                 $countLinks += count($linkNames) + count(array_diff($callNames, $linkNamesUnique)) + count($linkNamesUnique) - count(array_diff($linkNamesUnique, $callNames));
                 $countLinks++;
             } else {
                 if (!isset($component['init']) || $component['init'] === null) {
                     $fail = true;
                     $error = Language::Get('components', 'componentCrashed');
                 }
             }
             $countCommands = count(isset($component['commands']) ? $component['commands'] : array());
             if (isset($component['init']) && isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
                 $defs = explode(";", $component['init']->getDef());
                 $baseComponent = count($defs) > 2 ? "<br><span class='info-color tiny'>(" . $defs[0] . ")</span>" : '';
                 $text .= "<tr><td class='e' rowspan='{$countLinks}'>{$componentName}{$baseComponent}</td><td class='v'>{$component['init']->getAddress()}</td><td class='e'><div align ='center'>" . ($component['init']->getStatus() === 201 ? Language::Get('main', 'ok') : "<font color='red'>" . Language::Get('main', 'fail') . " ({$component['init']->getStatus()})</font>") . "</align></td></tr>";
             }
             if (isset($component['init']) && $component['init'] !== null && $component['init']->getStatus() === 201) {
                 $installedComponents++;
                 $installedLinks += count(isset($component['links']) ? $component['links'] : array());
                 $installedCommands += $countCommands;
                 if (isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
                     $text .= "<tr><td class='v' colspan='2'>" . Language::Get('components', 'installedCalls') . ": {$countCommands}</td></tr>";
                 }
                 $links = array();
                 if (isset($component['links'])) {
                     $links = $component['links'];
                 }
                 $lastLink = null;
                 foreach ($links as $link) {
                     $calls = null;
                     if (isset($component['call'])) {
                         $calls = $component['call'];
                     }
                     $linkFound = false;
                     if ($calls !== null) {
                         foreach ($calls as $pos => $callList) {
                             if (isset($callList['name']) && $callList['name'] === $link->getName()) {
                                 $linkFound = true;
                                 break;
                             }
                         }
                     }
                     if ($lastLink != $link->getName() && $linkFound) {
                         $calls = null;
                         if (isset($component['call'])) {
                             $calls = $component['call'];
                         }
                         $notRoutable = false;
                         if ($calls !== null) {
                             foreach ($calls as $pos => $callList) {
                                 if ($link->getName() !== $callList['name']) {
                                     continue;
                                 }
                                 if (isset($callList['links']) && $callList['links'] !== null) {
                                     foreach ($callList['links'] as $pos2 => $call) {
                                         if (!isset($content[$link->getTargetName()]['router'])) {
                                             $notRoutable = true;
                                             break;
                                         }
                                         if ($content[$link->getTargetName()]['router'] == null) {
                                             continue;
                                         }
                                         if ($call === null) {
                                             continue;
                                         }
                                         if (!isset($call['method'])) {
                                             continue;
                                         }
                                         if (!isset($call['path'])) {
                                             continue;
                                         }
                                         $routes = count($content[$link->getTargetName()]['router']->getMatchedRoutes(strtoupper($call['method']), $call['path']), true);
                                         if ($routes === 0) {
                                             $notRoutable = true;
                                             break;
                                         }
                                     }
                                 }
                                 if ($notRoutable) {
                                     break;
                                 }
                             }
                             if (isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
                                 $text .= "<tr><td class='v'>{$link->getName()}</td><td class='e'><div align ='center'>" . (!$notRoutable ? Language::Get('main', 'ok') : '<font color="red">' . Language::Get('components', 'notRoutable') . '</font>') . "</align></td></tr>";
                             }
                         }
                     }
                     if (isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
                         $text .= "<tr><td class='v'>{$link->getName()}" . (!$linkFound ? " (<font color='red'>" . Language::Get('components', 'unknown') . "</font>)" : '') . "</td><td class='v'>{$link->getTargetName()}</td></tr>";
                     }
                     $lastLink = $link->getName();
                 }
                 // fehlende links
                 $calls = null;
                 if (isset($component['call'])) {
                     $calls = $component['call'];
                 }
                 if ($calls !== null) {
                     foreach ($calls as $pos => $callList) {
                         $found = false;
                         foreach ($links as $link) {
                             if ($link->getName() == $callList['name']) {
                                 $found = true;
                                 break;
                             }
                         }
                         if (!$found) {
                             if (isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
                                 $text .= "<tr><td class='v'>{$callList['name']}</td><td class='e'><font color='red'>" . Language::Get('components', 'unallocated') . "</font></td></tr>";
                             }
                         }
                     }
                 }
             }
         }
         if ($installedComponents == 0) {
             $fail = true;
             $error = Language::Get('components', 'noComponents');
         } else {
             if ($installedLinks == 0) {
                 $fail = true;
                 $error = Language::Get('components', 'noLinks');
             } else {
                 if ($installedCommands == 0) {
                     $fail = true;
                     $error = Language::Get('components', 'noCommands');
                 }
             }
         }
         if (isset($data['CO']['co_details']) && $data['CO']['co_details'] === 'details' && !$isUpdate) {
             $text .= Design::erstelleZeile($console, '', '', '', '', '', '');
         }
         $text .= Design::erstelleZeile($console, Language::Get('components', 'installedComponents'), 'e', '', 'v', $installedComponents, 'v');
         $text .= Design::erstelleZeile($console, Language::Get('components', 'installedLinks'), 'e', '', 'v', $installedLinks, 'v');
         $text .= Design::erstelleZeile($console, Language::Get('components', 'installedCommands'), 'e', '', 'v', $installedCommands, 'v');
         $text .= Design::erstelleInstallationszeile($console, $fail, $errno, $error);
     }
     echo Design::erstelleBlock($console, Language::Get('components', 'title'), $text);
 }
示例#12
0
 public function testRouteMiddlwareArguments()
 {
     $this->expectOutputString('foobar');
     \Slim\Environment::mock(array('SCRIPT_NAME' => '', 'PATH_INFO' => '/foo'));
     $env = \Slim\Environment::getInstance();
     $req = new \Slim\Http\Request($env);
     $router = new \Slim\Router();
     $route = new \Slim\Route('/foo', function () {
         echo "bar";
     });
     $route->setName('foo');
     $route->setMiddleware(function ($route) {
         echo $route->getName();
     });
     $route->matches($req->getResourceUri());
     //<-- Extracts params from resource URI
     $router->dispatch($route);
 }
示例#13
0
 /**
  * the getl function uses a list of links to find a
  * relevant component for the $data request
  *
  * @param $data a slim generated array of URI segments (String[])
  */
 public function getl($data)
 {
     Logger::Log('starts Controller routing', LogLevel::DEBUG);
     // if no URI is received, abort process
     if (count($data) == 0) {
         Logger::Log('Controller nothing to route', LogLevel::DEBUG);
         $this->_app->response->setStatus(409);
         $this->_app->stop();
         return;
     }
     $URI = '/' . implode('/', $data);
     // get possible links
     $list = CConfig::getLinks($this->_conf->getLinks(), 'out');
     foreach ($list as $links) {
         $componentURL = $links->getAddress();
         $similar = Controller2::UrlAnd($componentURL, $URI);
         if ($similar != null) {
             $URI2 = substr($URI, Controller2::UrlAnd($componentURL, $URI));
             $relevanz = explode(' ', $links->getRelevanz());
             $found = false;
             foreach ($relevanz as $rel) {
                 if ($rel == 'ALL') {
                     $found = true;
                     break;
                 }
                 $sub = strpos($rel, '_');
                 if ($sub !== false) {
                     $method = substr($rel, 0, $sub);
                     $path = substr($rel, $sub + 1);
                     if (strtoupper($method) == strtoupper($this->_app->request->getMethod())) {
                         $router = new \Slim\Router();
                         $route = new \Slim\Route($path, 'is_array');
                         $route->via(strtoupper($method));
                         $router->map($route);
                         $routes = count($router->getMatchedRoutes(strtoupper($method), $URI2), true);
                         if ($routes === 0) {
                             continue;
                         }
                         $found = true;
                         break;
                     }
                 }
             }
             if (!$found) {
                 continue;
             }
             // create a custom request
             $ch = Request::custom($this->_app->request->getMethod(), $componentURL . substr($URI, $similar), array(), $this->_app->request->getBody());
             // checks the answered status code
             if ($ch['status'] >= 200 && $ch['status'] <= 299) {
                 // finished
                 $this->_app->response->setStatus($ch['status']);
                 $this->_app->response->setBody($ch['content']);
                 if (isset($ch['headers']['Content-Type'])) {
                     $this->_app->response->headers->set('Content-Type', $ch['headers']['Content-Type']);
                 }
                 if (isset($ch['headers']['Content-Disposition'])) {
                     $this->_app->response->headers->set('Content-Disposition', $ch['headers']['Content-Disposition']);
                 }
                 Logger::Log('Controller2 search done', LogLevel::DEBUG);
                 $this->_app->stop();
             }
         }
     }
     // no positive response or no operative link
     $this->_app->response->setStatus(409);
     $this->_app->response->setBody('');
 }