public function testGet_publication() { self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Notification\\Deliverer')->disableOriginalConstructor()->getMock(); $date = new DateTime(); $request = new Request([], [], [], [], [], ['HTTP_Accept' => 'application/json']); $feeds = self::$DI['app']['EM']->getRepository('Phraseanet:Feed')->getAllForUser(self::$DI['app']['acl']->get(self::$DI['user'])); foreach ($feeds as $feed) { $result = $this->object->get_publication($request, $feed->getId(), self::$DI['user']); $this->checkResponseField($result, "feed", 'array'); $this->checkResponseField($result, "entries", 'array'); $this->checkResponseField($result, "offset_start", 'integer'); $this->checkResponseField($result, "per_page", 'integer'); } }
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent; use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent; use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber; use Monolog\Logger; use Monolog\Processor\WebProcessor; use Silex\Application as SilexApplication; use Symfony\Component\HttpFoundation\Request; return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $app = new PhraseaApplication($environment); $app->loadPlugins(); $app['exception_handler'] = $app->share(function ($app) { return new ApiExceptionHandlerSubscriber($app); }); $app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) { $monolog->pushProcessor(new WebProcessor()); return $monolog; })); $app->register(new \API_V1_Timer()); $app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_START, new ApiLoadStartEvent()); $app->get('/api/', function (Request $request, SilexApplication $app) { $apiAdapter = new \API_V1_adapter($app); $result = new \API_V1_result($app, $request, $apiAdapter); return $result->set_datas(['name' => $app['conf']->get(['registry', 'general', 'title']), 'type' => 'phraseanet', 'description' => $app['conf']->get(['registry', 'general', 'description']), 'documentation' => 'https://docs.phraseanet.com/Devel', 'versions' => ['1' => ['number' => $apiAdapter->get_version(), 'uri' => '/api/v1/', 'authenticationProtocol' => 'OAuth2', 'authenticationVersion' => 'draft#v9', 'authenticationEndPoints' => ['authorization_token' => '/api/oauthv2/authorize', 'access_token' => '/api/oauthv2/token']]]])->get_response(); }); $app->mount('/api/oauthv2', new Oauth2()); $app->mount('/api/v1', new V1()); $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber($app['phraseanet.exception_handler'], $app['translator'])); $app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent()); return $app; }, isset($environment) ? $environment : PhraseaApplication::ENV_PROD);
/** * API v1 Result constructor * * @param Application $app * @param Request $request * @param API_V1_adapter $api * * @return API_V1_result */ public function __construct(Application $app, Request $request, API_V1_adapter $api) { $date = new DateTime(); $this->app = $app; $this->request = $request; $this->api_version = $api->get_version(); $this->response_time = $date->format(DATE_ATOM); $this->response = new stdClass(); $this->parse_response_type(); return $this; }