/** * @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); }
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); }
/** * @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; }
/** * @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']); }
/** * @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"); }
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); }
/** * @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"); } }
/** * @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); }
/** * @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); // } }
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); }
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; }
/** * 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); }
/** * @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); }