예제 #1
0
 /**
  * @param Request|WebRequest $request
  * @return \watoki\curir\delivery\WebResponse
  */
 public function respond(Request $request)
 {
     $this->app->prepare($request);
     if (!$this->isContainerTarget($request)) {
         $request = $request->withTarget(Path::fromString('execute'))->withArgument(ExecuteResource::ACTION_ARG, $request->getTarget()->toString());
     }
     return parent::respond($request);
 }
예제 #2
0
 public static function quickRoot($rootDirectory, $defaultPath = 'index', $namespace = '', Factory $factory = null)
 {
     $factory = $factory ?: self::init();
     $router = new WebRouter($factory, $rootDirectory, $namespace);
     $router->setDefaultTarget(CallbackTarget::factory(function (WebRequest $request) use($router, $defaultPath) {
         return $router->route($request->withTarget(Path::fromString($defaultPath)))->respond();
     }));
     self::quickRoute($router, $factory);
 }
예제 #3
0
파일: WebFixture.php 프로젝트: jonfm/domin
 public function whenIGet_From($path, $resourceClass)
 {
     $request = $this->request->withTarget(Path::fromString($path))->withMethod('get');
     $stub = new TestDelivererStub($request);
     $router = new NoneRouter(RespondingTarget::factory($this->factory, $this->factory->getInstance($resourceClass)));
     $delivery = new WebDelivery($router, $stub, $stub);
     $stub->onDeliver(function (WebResponse $response) {
         if ($response instanceof ErrorResponse) {
             throw $response->getException();
         }
         $this->model = $response->getBody();
     });
     $delivery->run();
 }
예제 #4
0
파일: Box.php 프로젝트: watoki/boxes
 public function dispatch(WebRequest $request, Router $router)
 {
     $arguments = $request->getArguments();
     $request->setTarget($this->target);
     if ($arguments->isEmpty()) {
         $arguments->merge($this->arguments);
         $request->setMethod(WebRequest::METHOD_GET);
     } else {
         if ($arguments->has(self::$TARGET_KEY)) {
             $request->setTarget(Path::fromString($arguments->get(self::$TARGET_KEY)));
         }
         if ($arguments->has(WebRequest::$METHOD_KEY)) {
             $request->setMethod($arguments->get(WebRequest::$METHOD_KEY));
         } else {
             $request->setMethod(WebRequest::METHOD_GET);
         }
     }
     $this->response = $router->route($request)->respond();
     if ($this->response->getHeaders()->has(WebResponse::HEADER_LOCATION)) {
         throw new WrappedRedirection($this->response->getHeaders()->get(WebResponse::HEADER_LOCATION));
     }
     return $request;
 }
예제 #5
0
 /**
  * @param string $path
  * @param array $args
  * @return Box
  */
 protected function box($path, $args = array())
 {
     return new Box(Path::fromString($path), new Map($args));
 }
예제 #6
0
파일: fatal.php 프로젝트: watoki/deli
<?php

use spec\watoki\deli\fixtures\TestDelivererStub;
use watoki\deli\Delivery;
use watoki\deli\Path;
use watoki\deli\Request;
use watoki\deli\router\NoneRouter;
use watoki\deli\target\CallbackTarget;
require_once __DIR__ . '/../../vendor/autoload.php';
error_reporting(0);
$router = new NoneRouter(CallbackTarget::factory(function () {
    /** @noinspection PhpUndefinedFunctionInspection */
    causeFatalError();
}));
$test = new TestDelivererStub(new Request(new Path(), Path::fromString('some/target')));
$test->onDeliver(function ($response) {
    echo $response;
});
$delivery = new Delivery($router, $test, $test);
$delivery->run();
예제 #7
0
 /**
  * @param Request|WebRequest $request
  * @return \watoki\curir\delivery\WebResponse
  */
 public function respond(Request $request)
 {
     $request = $request->withTarget(Path::fromString('execute'))->withArgument(ExecuteResource::ACTION_ARG, $request->getTarget()->toString());
     return parent::respond($request);
 }
예제 #8
0
 public function addPath($pathString, TargetFactory $factory)
 {
     $this->add(new PathMatcher(Path::fromString($pathString)), $factory);
 }
예제 #9
0
 protected function determineTarget($server)
 {
     list(, $target) = $this->splitContextAndTarget($server);
     return Path::fromString(ltrim(urldecode($target), '/'));
 }
예제 #10
0
파일: BoxFixture.php 프로젝트: watoki/boxes
 public function givenTheRequestTarget_Is($string)
 {
     $this->request->setTarget(Path::fromString($string));
 }
예제 #11
0
 /**
  * @param $path
  */
 public function whenIRoute($path)
 {
     $this->target = $this->router->route(new Request(new Path(), Path::fromString($path)));
 }
예제 #12
0
 public function givenTheRequestHasTheTarget($pathString)
 {
     $this->request = $this->request->withTarget(Path::fromString($pathString));
 }
예제 #13
0
파일: Url.php 프로젝트: watoki/curir
 public static function fromString($string)
 {
     if (!$string) {
         return new Url(null, null, null, new Path());
     }
     $fragment = null;
     $fragmentPos = strpos($string, self::FRAGMENT_SEPARATOR);
     if ($fragmentPos !== false) {
         $fragment = substr($string, $fragmentPos + 1);
         $string = substr($string, 0, $fragmentPos);
     }
     $parameters = new Map();
     $queryPos = strpos($string, self::QUERY_STRING_SEPARATOR);
     if ($queryPos !== false) {
         $query = substr($string, $queryPos + 1);
         $string = substr($string, 0, $queryPos);
         if ($query) {
             $parameters = self::parseParameters($query);
         }
     }
     $scheme = null;
     $schemeSepPos = strpos($string, self::SCHEME_SEPARATOR . self::HOST_PREFIX);
     if ($schemeSepPos !== false) {
         $scheme = substr($string, 0, $schemeSepPos);
         $string = substr($string, $schemeSepPos + 1);
     }
     $host = null;
     $port = null;
     if (substr($string, 0, 2) == self::HOST_PREFIX) {
         $string = substr($string, 2);
         $hostPos = strpos($string, Path::SEPARATOR) ?: strlen($string);
         $host = substr($string, 0, $hostPos);
         $string = substr($string, $hostPos);
         $portPos = strpos($host, self::PORT_SEPARATOR);
         if ($portPos !== false) {
             $port = intval(substr($host, $portPos + 1));
             $host = substr($host, 0, $portPos);
         }
     }
     if (!$host && !$string) {
         $path = new Path();
     } else {
         $path = Path::fromString($string);
         if ($path->isEmpty()) {
             $path = new Path(array(''));
         }
     }
     return new Url($scheme, $host, $port, $path, $parameters, $fragment);
 }
예제 #14
0
 public function givenTheTargetPathIs($string)
 {
     $this->environment->target = Path::fromString($string);
 }