コード例 #1
0
 public function testGetEntity()
 {
     $controller = new JsonApiController();
     $meta = $this->getMockBuilder("Doctrine\\ORM\\Mapping\\ClassMetadata")->setConstructorArgs(["NwApi\\Entities\\User"])->getMock();
     $di = Di::getInstance();
     $di->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $di->em->expects($this->any())->method('find')->willReturn(new NwApi\Entities\User());
     $meta->identifier = ['id'];
     $controller->getEntity($meta, [$this->faker->randomDigit()]);
 }
コード例 #2
0
 /**
  * handler Json Response when everything is ok.
  */
 protected function handleJsonResponse()
 {
     $acceptContentType = $this->app->request->headers->get('Accept');
     $body = $this->app->response->getBody();
     if (strpos($acceptContentType, 'text/html') !== false) {
         $di = Di::getInstance();
         $this->app->response->headers->set('Content-Type', 'text/html');
         $this->app->response->setBody('');
         $responseStatus = $this->app->response->getStatus();
         $this->app->render('JsonMiddleware.php', ['requestUri' => $this->app->request->getResourceUri(), 'requestHeaders' => $this->app->request->headers->all(), 'requestBody' => $this->app->request->getBody(), 'responseHeaders' => $this->app->response->headers->all(), 'responseBody' => $body, 'responseStatusMessage' => $this->app->response->getMessageForCode($responseStatus), 'sqlQueries' => $di->sqlLogger->queries]);
     }
 }
コード例 #3
0
 protected function __construct($instanceId)
 {
     parent::__construct($instanceId);
     $di = \NwApi\Di::getInstance();
     require $di->configPath . $instanceId . '.php';
     $vars = get_defined_vars();
     unset($vars['instanceId']);
     unset($vars['di']);
     foreach ($vars as $name => $value) {
         $this->{$name} = $value;
     }
 }
コード例 #4
0
<?php

require '../vendor/autoload.php';
\NwApi\Di::getInstance()->slim->run();
コード例 #5
0
<?php

return \NwApi\Di::getInstance()->srcPath . 'Templates/';
コード例 #6
0
<?php

return \NwApi\Di::getInstance()->srcPath . 'Entities/';
コード例 #7
0
<?php

use NwApi\Di;
use NwApi\Middlewares\JsonApiMiddleware;
$di = Di::getInstance();
if ($di->env === ENV_DEVELOPMENT) {
    $slimMode = 'development';
    $debug = true;
} else {
    $slimMode = 'production';
    $debug = false;
}
$app = new Slim\Slim(['mode' => $slimMode, 'debug' => false, 'templates.path' => $di->templatesPath]);
$app->add(new JsonApiMiddleware());
if ($debug === true) {
    $app->add(new \Slim\Middleware\PrettyExceptions());
    $app->error(function (\Exception $e) {
        throw $e;
    });
}
$app->get('/hello/:name', function ($name) {
    echo "Hello, {$name}";
});
return $app;
コード例 #8
0
 private function responseEntities($entities, $filters, $orders, $limit, $offset)
 {
     $links = [];
     if ($limit > 0) {
         if ($offset > 0) {
             $links['prev'] = $this->getEntitiesUrl($filters, $orders, $limit, max($offset - $limit, 0));
         }
         if (count($entities) === $limit) {
             $links['next'] = $this->getEntitiesUrl($filters, $orders, $limit, $offset + $limit);
         }
     }
     $di = Di::getInstance();
     $di->slim->response->header('X-Json-Api', json_encode(['links' => $links]));
     $this->response($entities);
 }
コード例 #9
0
 /**
  * Gets the class metadata descriptor for a class.
  *
  * @param string $className The name of the class.
  *
  * @return ClassMetadata
  */
 private function getEntityMeta($className)
 {
     $di = Di::getInstance();
     return $di->em->getMetadataFactory()->getMetadataFor($className);
 }
コード例 #10
0
<?php

return \NwApi\Di::getInstance()->rootPath . 'config/';
コード例 #11
0
<?php

return \NwApi\Di::getInstance()->rootPath . 'src/';