Exemplo n.º 1
0
 /**
  * @internal param \Auryn\Injector $injector
  * @internal param $category
  * @return TextResponse
  */
 public function renderCategoryIndex()
 {
     $injectionParams = new InjectionParams();
     $injectionParams->defineParam('pageTitle', "Imagick demos");
     $injectionParams->alias('ImagickDemo\\Navigation\\Nav', 'ImagickDemo\\Navigation\\CategoryNav');
     return JigExecutable::create('categoryIndex', $injectionParams);
 }
Exemplo n.º 2
0
 public function testDefineParam()
 {
     $injectorMock = Mockery::mock('Auryn\\Injector');
     $injectorMock->shouldReceive('defineParam')->with('foo', 'bar')->once();
     $params = new InjectionParams();
     $params->defineParam('foo', 'bar');
     $params->addToInjector($injectorMock);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
Arquivo: Router.php Projeto: 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']);
 }
Exemplo n.º 5
0
 /**
  * @throws TierException
  */
 public function executeInternal()
 {
     // Create and share these as they need to be the same
     // across the application
     $this->injector->share($this->injector);
     //yolo
     $this->initialInjectionParams->addToInjector($this->injector);
     foreach ($this->executableListByTier as $appStage => $tiersForStage) {
         foreach ($tiersForStage as $tier) {
             //Check we haven't got caught in a redirect loop
             $this->internalExecutions++;
             if ($this->internalExecutions > $this->maxInternalExecutions) {
                 $message = "Too many tiers executed. You probably have a recursion error in your application.";
                 throw new TierException($message);
             }
             /** @var $tier Executable  */
             if ($tier instanceof Executable) {
                 $skipIfProduced = $tier->getSkipIfProduced();
                 if ($skipIfProduced && $this->hasExpectedProductBeenProduced($skipIfProduced) == true) {
                     continue;
                 }
                 // Setup the information created by the previous Tier
                 if ($injectionParams = $tier->getInjectionParams()) {
                     $injectionParams->addToInjector($this->injector);
                 }
                 // If the next Tier has a setup function, call it
                 $setupCallable = $tier->getSetupCallable();
                 if ($setupCallable) {
                     $this->injector->execute($setupCallable);
                 }
                 // Call this Tier's callable
                 $result = $this->injector->execute($tier->getCallable());
             } else {
                 $result = $this->injector->execute($tier);
             }
             // TODO - if we need to allow user handlers this is the place they would go
             $finished = $this->processResult($result);
             if ($finished == self::PROCESS_END_STAGE) {
                 break;
             }
             if ($finished == self::PROCESS_END) {
                 return;
             }
         }
     }
     throw new TierException("Processing did not result in a TierApp::PROCESS_END");
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 /**
  * @throws TierException
  */
 public function executeInternal()
 {
     // Create and share these as they need to be the same
     // across the application
     $this->injector->share($this->injector);
     //yolo
     $this->initialInjectionParams->addToInjector($this->injector);
     foreach ($this->executableListByTier as $appStage => $tiersForStage) {
         foreach ($tiersForStage as $tier) {
             //Check we haven't got caught in a redirect loop
             $this->internalExecutions++;
             if ($this->internalExecutions > $this->maxInternalExecutions) {
                 $message = "Too many tiers executed. You probably have a recursion error in your application.";
                 throw new TierException($message);
             }
             /** @var $tier Executable  */
             if ($tier instanceof Executable) {
                 //Some executables shouldn't be run if a certain product
                 //has already been made. This allows very easy caching layers.
                 $skipIfProduced = $tier->getSkipIfExpectedProductProduced();
                 if ($skipIfProduced !== null && $this->hasExpectedProductBeenProduced($skipIfProduced) === true) {
                     continue;
                 }
                 $result = self::executeExecutable($tier, $this->injector);
             } else {
                 $result = $this->injector->execute($tier);
             }
             $finished = $this->processResult($result, $tier);
             if ($finished === self::PROCESS_END_STAGE) {
                 break;
             }
             if ($finished === self::PROCESS_END) {
                 return;
             }
         }
     }
     if ($this->warnOnSilentProcessingEnd === true) {
         throw new TierException("Processing did not result in a TierApp::PROCESS_END");
     }
 }
Exemplo n.º 8
0
 /**
  * @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);
 }
Exemplo n.º 9
0
 /**
  * @param GithubService $api
  * @param AccessResponse $accessResponse
  * @param $username
  * @param $repo
  */
 function listRepoCommits(GithubService $api)
 {
     //AccessResponse $accessResponse,
     $username = "******";
     $repo = "GithubArtaxService";
     //$command = $api->listRepoCommits(new Oauth2Token($accessResponse->accessToken), $username, $repo);
     $command = $api->listRepoCommits(new NullToken(), $username, $repo);
     //$command->setAuthor('Danack');
     $commits = $command->execute();
     $injectionParams = InjectionParams::fromShareObjects([$commits]);
     return JigExecutable::create("pages/listRepoCommits", $injectionParams);
     //        if ($commits->pager) {
     //            displayAndSaveLinks($commits->pager);
     //        }
 }
Exemplo n.º 10
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);
}
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
 /**
  * Helper function to allow template rendering to be easier.
  * @param $templateName
  * @param array $sharedObjects
  * @return Executable
  */
 public static function renderTemplateExecutable($templateName, InjectionParams $injectionParams = null)
 {
     if ($injectionParams === null) {
         $injectionParams = new InjectionParams();
     }
     $fn = function (Jig $jigRender) use($templateName, $injectionParams) {
         $className = $jigRender->compile($templateName);
         $injectionParams->alias('Jig\\JigBase', $className);
         $fn = function (Injector $injector) use($className) {
             return $injector->make($className);
         };
         $injectionParams->delegate('Jig\\JigBase', $fn);
         return new Executable(['Tier\\Tier', 'createHtmlBody'], $injectionParams);
     };
     return new Executable($fn);
 }
Exemplo n.º 13
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);
 }