示例#1
0
文件: Router.php 项目: Zvax/Tier
 /**
  * @param Request $request
  * @return Executable
  */
 public function routeRequest(Request $request)
 {
     $path = $request->getPath();
     $queryPosition = strpos($path, '?');
     if ($queryPosition !== false) {
         $path = substr($path, 0, $queryPosition);
     }
     $routeInfo = $this->dispatcher->dispatch($request->getMethod(), $path);
     $dispatcherResult = $routeInfo[0];
     if ($dispatcherResult == \FastRoute\Dispatcher::FOUND) {
         $handler = $routeInfo[1];
         $vars = $routeInfo[2];
         $params = InjectionParams::fromParams($vars);
         return new Executable($handler, $params, null);
     } else {
         if ($dispatcherResult == \FastRoute\Dispatcher::METHOD_NOT_ALLOWED) {
             //TODO - need to embed allowedMethods....theoretically.
             return new Executable([$this, 'serve405ErrorPage']);
         }
     }
     $templateName = $this->templateExists($path, $this->jigConfig);
     if ($templateName != false) {
         return $this->tierJig->createJigExecutable($templateName);
     }
     return new Executable([$this, 'serve404ErrorPage']);
 }
示例#2
0
 /**
  * @param Request $request
  * @return Executable
  */
 public function routeRequest(Request $request)
 {
     $path = $request->getUri()->getPath();
     $routeInfo = $this->dispatcher->dispatch($request->getMethod(), $path);
     $dispatcherResult = $routeInfo[0];
     if ($dispatcherResult === \FastRoute\Dispatcher::FOUND) {
         $handler = $routeInfo[1];
         $vars = $routeInfo[2];
         $injectionParams = InjectionParams::fromParams($vars);
         $injectionParams->share(new \Tier\JigBridge\RouteInfo($vars));
         $executable = new Executable($handler, $injectionParams, null);
         $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
         return $executable;
     } else {
         if ($dispatcherResult === \FastRoute\Dispatcher::METHOD_NOT_ALLOWED) {
             //TODO - need to embed allowedMethods....theoretically.
             $executable = new Executable([$this, 'serve405ErrorPage']);
             $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
             return $executable;
         }
     }
     $executable = new Executable([$this, 'serve404ErrorPage']);
     $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
     return $executable;
 }
示例#3
0
文件: TierJig.php 项目: Zvax/Tier
 public function createJigExecutable($templateName, InjectionParams $injectionParams = null)
 {
     if ($injectionParams == null) {
         $injectionParams = InjectionParams::fromParams([]);
     }
     $className = $this->jig->compile($templateName);
     $injectionParams->alias('Jig\\JigBase', $className);
     return new Executable(['Tier\\JigBridge\\TierJig', 'createHtmlBody'], $injectionParams);
 }
示例#4
0
 public function testFromParams()
 {
     $injector = new Injector();
     $injectionParams = InjectionParams::fromParams(['foo' => 'bar']);
     $injectionParams->addToInjector($injector);
     $fooTest = null;
     $fn = function ($foo) use(&$fooTest) {
         $fooTest = $foo;
     };
     $injector->execute($fn);
     $this->assertEquals('bar', $fooTest);
     $this->assertInternalType('array', $injectionParams->getShares());
     $this->assertInternalType('array', $injectionParams->getAliases());
     $this->assertInternalType('array', $injectionParams->getParams());
     $this->assertInternalType('array', $injectionParams->getDelegates());
     $this->assertInternalType('array', $injectionParams->getPrepares());
     $this->assertInternalType('array', $injectionParams->getDefines());
 }
示例#5
0
文件: TierAppTest.php 项目: Zvax/Tier
 /**
  * @throws TierException
  */
 public function testInjectorParamsUsed()
 {
     $injectionParams = new InjectionParams();
     $tierApp = new TierApp($injectionParams);
     //Create the second function first, so it can be use'd
     $fooDebug = null;
     $fn2 = function ($foo) use(&$fooDebug) {
         $fooDebug = $foo;
         return TierApp::PROCESS_END;
     };
     //First executable sets up the 'foo' param and runs the 2nd fn.
     $fn1 = function () use($fn2) {
         $params = InjectionParams::fromParams(['foo' => 'bar']);
         return new Executable($fn2, $params);
     };
     $tierApp->addExecutable(0, $fn1);
     $tierApp->addExecutable(5, $fn2);
     $tierApp->executeInternal();
     $this->assertEquals('bar', $fooDebug);
 }
示例#6
0
function createRenderTemplateTier($templateName, InjectionParams $injectionParams = null)
{
    $fn = function (Jig $jig) use($injectionParams, $templateName) {
        if ($injectionParams == null) {
            $injectionParams = InjectionParams::fromParams([]);
        }
        $className = $jig->getTemplateCompiledClassname($templateName);
        $jig->checkTemplateCompiled($templateName);
        $injectionParams->alias('Jig\\JigBase', $className);
        return new Tier('createHtmlBody', $injectionParams);
    };
    return new Tier($fn);
}
示例#7
0
 public function getImageResponse(\ImagickDemo\Control $control)
 {
     $params = $control->getFullParams([]);
     $params['customImage'] = false;
     $injectionParams = InjectionParams::fromParams(array('params' => $params, 'customImage' => false));
     $tiers = [];
     $tiers[] = new Executable('cachedImageCallable', $injectionParams);
     $tiers[] = new Executable('createImageTask');
     $tiers[] = new Executable('directImageCallable');
     return $tiers;
 }
示例#8
0
 /**
  * @internal param \Auryn\Injector $injector
  * @internal param $category
  * @return TextResponse
  */
 public function renderCategoryIndex()
 {
     $injectionParams = InjectionParams::fromParams(['pageTitle' => "Imagick demos"]);
     $injectionParams->alias('ImagickDemo\\Navigation\\Nav', 'ImagickDemo\\Navigation\\CategoryNav');
     return createRenderTemplateTier('categoryIndex', $injectionParams);
 }