コード例 #1
0
ファイル: CompanyController.php プロジェクト: kulishkin/gis
 public function getAction($id)
 {
     $entity = $this->repository->find($id);
     if (!$entity) {
         return new Response($this->serializer->serialize(ResponseMeta::error(sprintf('object %s not found.', $id)), $this->request->getRequestFormat()), Response::HTTP_NOT_FOUND);
     }
     return new Response($this->serializer->serialize(ResponseMeta::success($entity), $this->request->getRequestFormat(), ['groups' => ['single']]));
 }
コード例 #2
0
ファイル: BaseController.php プロジェクト: kulishkin/gis
 public function companyListAction($id)
 {
     $entity = $this->repository->find($id);
     if (!$entity) {
         return new Response($this->serializer->serialize(ResponseMeta::error(sprintf('object %s not found.', $id)), $this->request->getRequestFormat()), Response::HTTP_NOT_FOUND);
     }
     $entities = $this->repository->getCompanyList($entity, $this->request->limit(), $this->request->offset());
     return new Response($this->serializer->serialize(ResponseMeta::success($entities), $this->request->getRequestFormat(), ['groups' => ['list']]));
 }
コード例 #3
0
ファイル: BuildingController.php プロジェクト: kulishkin/gis
 public function listAction()
 {
     $entities = $this->repository->findBy([], [], $this->request->limit(), $this->request->offset());
     return new Response($this->serializer->serialize(ResponseMeta::success($entities), $this->request->getRequestFormat(), ['groups' => ['list']]));
 }
コード例 #4
0
ファイル: app.php プロジェクト: kulishkin/gis
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
use Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
$app = new Application();
$app['profiling.start'] = microtime(true);
$app->register(new MonologServiceProvider(), ['monolog.logfile' => __DIR__ . '/../var/logs/prod.log', 'monolog.level' => Logger::ERROR]);
$app->register(new ServiceControllerServiceProvider());
$app->register(new SerializerServiceProvider());
$app['serializer.normalizers'] = $app->share(function () {
    return [new PropertyNormalizer(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())))];
});
$app->register(new DoctrineServiceProvider(), ['db.options' => ['driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'gis', 'user' => 'root', 'password' => 'test', 'charset' => 'utf8mb4']]);
$app->register(new DoctrineOrmServiceProvider(), ['orm.proxies_dir' => __DIR__ . '/Gis/Proxy', 'orm.default_cache' => 'apc', 'orm.em.options' => ['mappings' => [['type' => 'annotation', 'namespace' => 'Gis\\Entity', 'path' => __DIR__ . '/Gis/Entity', 'use_simple_annotation_reader' => false]]], 'orm.custom.functions.numeric' => ['DISTANCE' => 'Gis\\Doctrine\\Query\\Mysql\\Distance']]);
$app->register(new UrlGeneratorServiceProvider());
$app->get('/', function () use($app) {
    return $app->redirect('/api/v1');
});
$apiProvider = new ApiProvider();
$app->register($apiProvider);
$app->mount('/api/v1', $apiProvider);
$app->error(function (\Exception $e, $code) use($app) {
    $app['monolog']->addError($e->getMessage());
    $app['monolog']->addError($e->getTraceAsString());
    return new Response($app['serializer']->serialize(ResponseMeta::error($e->getMessage()), $app['request']->getRequestFormat('json')), Response::HTTP_INTERNAL_SERVER_ERROR);
});
AnnotationRegistry::registerFile(__DIR__ . '/../vendor/symfony/serializer/Annotation/Groups.php');
DoctrineExtensions::registerAnnotations();
$treeListener = new TreeListener();
$app['db.event_manager']->addEventSubscriber($treeListener);
return $app;