public function testGet_Emptydatas() { $server = ["HTTP_ACCEPT" => "application/json", 'REQUEST_METHOD' => 'GET', 'SCRIPT_FILENAME' => 'my/base/path/my/request/uri/filename', "REQUEST_URI" => "my/base/path/my/request/uri", 'PHP_SELF' => 'my/base/path']; $request = new Request(["callback" => ""], [], [], [], [], $server); $data = []; $api_result = new API_V1_result(self::$DI['app'], $request, $this->api); $api_result->set_datas($data); $this->assertEquals($data, $api_result->get_datas()); }
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);
public function get_feed_entry(Request $request, $entry_id, User $user) { $result = new API_V1_result($this->app, $request, $this); $entry = $this->app['EM']->getRepository('Phraseanet:FeedEntry')->find($entry_id); $collection = $entry->getFeed()->getCollection($this->app); if (null !== $collection && !$this->app['acl']->get($user)->has_access_to_base($collection->get_base_id())) { throw new \API_V1_exception_forbidden('You have not access to the parent feed'); } $datas = ['entry' => $this->list_publication_entry($entry)]; $result->set_datas($datas); return $result; }