예제 #1
0
 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
 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
 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;