예제 #1
0
 /**
  * @param array $options
  * @param array $arguments
  * @return mixed
  */
 public function run(array $options, array $arguments)
 {
     $port = isset($arguments[0]) ? $arguments[0] : "8001";
     $host = isset($arguments[1]) ? $arguments[1] : "0.0.0.0";
     /** @var \Castle23\Http\Server $server */
     $server = $this->container->getInstanceOf(Server::class);
     $this->socket->listen($port, $host);
     $this->loop->run();
 }
예제 #2
0
 /**
  * conveniant method to create new instances
  * @param string $collection
  * @return MongoObject
  */
 public function newObject($collection)
 {
     /** @var MongoObject $obj */
     $obj = $this->container->getInstanceOf($this->classMap->getClassForResult($collection, []));
     $obj->setCollection($collection);
     return $obj;
 }
예제 #3
0
 /**
  * Iterator::current
  * return current specific object
  *
  * @return MongoObject
  * @throws Exception
  */
 public function current()
 {
     $documentData = $this->myResultCursor->current();
     /** @var MongoObject $document */
     $document = $this->container->getInstanceOf($this->classMapInterface->getClassForResult($this->collection, $documentData));
     $document->setCollection($this->collection);
     $document->loadFromArray($documentData);
     return $document;
 }
예제 #4
0
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     // if the queue is empty, we have reached the lowest level
     if (count($this->queue) == 0) {
         return $response;
     }
     /** @var callable $middleware */
     $middleware = $this->container->getInstanceOf(array_shift($this->queue));
     return $middleware($request, $response, $this);
 }
예제 #5
0
 /**
  * Handle a regular route
  *
  * @param array $info
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param string $route
  * @return ResponseInterface
  * @throws \King23\Controller\Exceptions\ActionDoesNotExistException
  */
 private function handleRoute($info, ServerRequestInterface $request, ResponseInterface $response, $route)
 {
     // initialize router attributes for the request
     $attributes = ['params' => ['url' => [], 'host' => []]];
     // prepare parameters
     if ($paramstr = substr($request->getUri()->getPath(), strlen($route))) {
         $attributes['params']['url'] = $this->filterParameters($info['parameters'], explode("/", $paramstr));
     }
     // check host parameters
     if (count($info["hostparameters"]) > 0) {
         $attributes['params']['host'] = $this->extractHostParameters($request, $info);
     }
     // put route parameters into king23.router.parameters attribute
     $request = $request->withAttribute('king23.router', $attributes);
     /** @var \King23\Controller\Controller $controller */
     $controller = $this->container->getInstanceOf($info["class"]);
     return $controller->dispatch($info["action"], $request, $response);
 }