Exemplo n.º 1
0
 public function __construct()
 {
     $this->extensions = new Map();
     $this->packages = new Map();
     // load up all extensions
     $exts = ExtensionQuery::create()->joinPackage()->find();
     foreach ($exts as $ext) {
         /* @var $ext Extension */
         $key = $ext->getKey();
         $packageName = $ext->getPackage()->getName();
         $data = Json::decode($ext->getData());
         // add to global extensions
         if (!$this->extensions->has($key)) {
             $this->extensions->set($key, new ArrayList());
         }
         $this->extensions->get($key)->add($data);
         // add to package extensions
         if (!$this->packages->has($packageName)) {
             $this->packages->set($packageName, new Map());
         }
         $pkg = $this->packages->get($packageName);
         if (!$pkg->has($key)) {
             $pkg->set($key, new ArrayList());
         }
         $pkg->get($key)->add($data);
     }
 }
 /**
  * {@inheritDoc}
  * @see \Symfony\Component\Translation\Loader\LoaderInterface::load()
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $repo = $this->service->getResourceRepository();
     if (!$repo->contains($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     // find file in puli repo
     $file = $repo->get($resource);
     $json = $file->getBody();
     $data = Json::decode($json);
     $messages = [];
     // flatten plural strings
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $vals = [];
             foreach ($value as $k => $v) {
                 $vals[] = sprintf('%s: %s', $k, $v);
             }
             $val = implode('|', $vals);
         } else {
             $val = $value;
         }
         $messages[$key] = str_replace(['{{', '}}'], '%', $val);
     }
     // put them into message catalog
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     return $catalogue;
 }
Exemplo n.º 3
0
 private function fileToArray($filename)
 {
     $file = new File($filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
     }
     return Json::decode($file->read());
 }
Exemplo n.º 4
0
 /**
  *
  * @param string $filename
  * @throws FileNotFoundException
  * @throws JsonException
  * @return static
  */
 public static function fromFile($filename)
 {
     $file = new File($filename);
     if (!$file->exists()) {
         throw new FileNotFoundException(sprintf('File not found at: %s', $filename));
     }
     $json = Json::decode($file->read());
     return new static($json);
 }
Exemplo n.º 5
0
 /**
  *
  * @param BodyResource $file
  * @return array
  */
 private function getJson(BodyResource $file)
 {
     $config = Json::decode($file->getBody());
     // fix version
     if (!isset($config['version'])) {
         $config['version'] = 'dev-master';
     }
     return $config;
 }
Exemplo n.º 6
0
 public function testComplex()
 {
     $data = ['a' => 1, 'b' => [1, 2, 4], 'c' => 3, 'd' => 4, 'e' => 5];
     $json = Json::encode($data);
     $map = Json::toMap($json);
     $this->assertTrue($map instanceof Map);
     $this->assertTrue($map->get('b') instanceof ArrayList);
     $this->assertEquals($data, $map->toArray());
 }
Exemplo n.º 7
0
 /**
  * Automatically generated method, will be overridden
  *
  * @param Request $request      	
  * @return Response
  */
 public function run(Request $request)
 {
     $json = Json::decode($request->getContent());
     $path = new JSONPath($json);
     $login = $path->find('$.data.attributes.login')->first();
     $password = $path->find('$.data.attributes.password')->first();
     $domain = new SessionDomain($this->getServiceContainer());
     $payload = $domain->login($login, $password);
     return $this->responder->run($request, $payload);
 }
Exemplo n.º 8
0
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $body = Json::decode($request->getContent());
     if (!isset($body['data'])) {
         throw new InvalidParameterException();
     }
     $data = $body['data'];
     $domain = new JudgeDomain($this->getServiceContainer());
     $payload = $domain->create($data);
     return $this->responder->run($request, $payload);
 }
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $body = Json::decode($request->getContent());
     if (!isset($body['data'])) {
         throw new InvalidParameterException();
     }
     $data = $body['data'];
     $id = $this->getParam('id');
     $domain = new RoutineDomain($this->getServiceContainer());
     $payload = $domain->setPerformanceChoreographyStatisticId($id, $data);
     return $this->responder->run($request, $payload);
 }
Exemplo n.º 10
0
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $body = Json::decode($request->getContent());
     if (!isset($body['data'])) {
         throw new InvalidParameterException();
     }
     $data = $body['data'];
     $id = $this->getParam('id');
     $domain = new StartgroupDomain($this->getServiceContainer());
     $payload = $domain->setCompetitionId($id, $data);
     return $this->responder->run($request, $payload);
 }
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $body = Json::decode($request->getContent());
     if (!isset($body['data'])) {
         throw new InvalidParameterException();
     }
     $data = $body['data'];
     $id = $this->getParam('id');
     $domain = new LocalizationDomain($this->getServiceContainer());
     $payload = $domain->updateLanguageVariant($id, $data);
     return $this->responder->run($request, $payload);
 }
Exemplo n.º 12
0
 protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg)
 {
     // remove all existing extensions from this package first
     ExtensionQuery::create()->filterByPackage($model)->delete();
     // add them one by one
     foreach ($pkg->getAllExtensions() as $key => $exts) {
         foreach ($exts as $data) {
             $ext = new Extension();
             $ext->setKey($key);
             $ext->setData(Json::encode($data, Json::UNESCAPED_SLASHES));
             $ext->setPackage($model);
             $ext->save();
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $url = str_replace($request->getRequestUri(), '', $request->getUri());
     $baseurl = str_replace($url, '', $this->getBaseUrl());
     $sport = SportQuery::create()->findOneById($this->getParam('sport'));
     if (!$sport->getIsDefault()) {
         $baseurl .= '/' . $sport->getSlug();
     }
     // load assets
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $repo = $this->getServiceContainer()->getResourceRepository();
     $page->addStyles($repo->find('/gossi/trixionary-client/public/app/assets/*.css')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/vendor-*.js')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/trixionary-*.js')->getPaths());
     // set configuration
     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
     $config = ['modulePrefix' => 'trixionary', 'environment' => 'production', 'rootURL' => $baseurl, 'locationType' => 'auto', 'APP' => ['name' => 'trixionary', 'version' => '0.0.0+0d11dfba'], 'keeko' => ['api' => $prefs->getApiUrl(), 'trixionary' => ['sportId' => $sport->getId(), 'slug' => ['skill' => $sport->getSkillSlug(), 'group' => $sport->getGroupSlug(), 'object' => $sport->getObjectSlug()]]]];
     $meta = new Meta();
     $meta->setName('trixionary/config/environment');
     $meta->setContent(rawurlencode(Json::encode($config)));
     $page->addMeta($meta);
     return $this->responder->run($request, new Blank(['sport' => $sport]));
 }
Exemplo n.º 14
0
 private function updateApi(Module $model, ModuleSchema $module, $actions)
 {
     $repo = $this->service->getResourceRepository();
     $filename = sprintf('/packages/%s/api.json', $model->getName());
     if (!$repo->contains($filename)) {
         return;
     }
     // delete every api existent for the given module prior to create the new ones
     ApiQuery::create()->filterByActionId(array_values($actions))->delete();
     // 		$extensions = $this->service->getExtensionRegistry()->getExtensionsByPackage('keeko.api', $model->getName());
     $json = Json::decode($repo->get($filename)->getBody());
     $swagger = new Swagger($json);
     foreach ($swagger->getPaths() as $path) {
         /* @var $path Path */
         foreach (Swagger::$METHODS as $method) {
             if ($path->hasOperation($method)) {
                 $op = $path->getOperation($method);
                 $actionName = $op->getOperationId();
                 if (!isset($actions[$actionName])) {
                     continue;
                 }
                 // find required parameters
                 $required = [];
                 foreach ($op->getParameters() as $param) {
                     /* @var $param Parameter */
                     if ($param->getIn() == 'path' && $param->getRequired()) {
                         $required[] = $param->getName();
                     }
                 }
                 // 					$prefix = isset($extensions[$actionName])
                 // 						? $extensions[$actionName]
                 // 						: $module->getSlug();
                 $prefix = $module->getSlug();
                 $fullPath = str_replace('//', '/', $prefix . '/' . $path->getPath());
                 $api = new Api();
                 $api->setMethod($method);
                 $api->setRoute($fullPath);
                 $api->setActionId($actions[$actionName]);
                 $api->setRequiredParams(implode(',', $required));
                 $api->save();
             }
         }
     }
     $model->setApi(true);
     $model->save();
 }
Exemplo n.º 15
0
 /**
  *
  * @expectedException \phootwork\json\JsonException
  * @expectedExceptionCode \phootwork\json\Json::ERROR_DEPTH
  */
 public function testDecodeBrokenStackDepth()
 {
     $json = json_encode([1 => ['English' => ['One', 'January'], 'French' => ['Une', 'Janvier']]]);
     Json::decode($json, 0, 3);
 }
Exemplo n.º 16
0
 private function loadModules()
 {
     if (!empty($this->modules)) {
         return $this->modules;
     }
     $modules = [];
     $models = ModuleQuery::create()->filterByApi(true)->find();
     $repo = $this->service->getResourceRepository();
     foreach ($models as $model) {
         $package = $this->service->getPackageManager()->getPackage($model->getName());
         $filename = sprintf('/packages/%s/api.json', $model->getName());
         if ($repo->contains($filename)) {
             $routes = [];
             $json = Json::decode($repo->get($filename)->getBody());
             $swagger = new Swagger($json);
             foreach ($swagger->getPaths() as $path) {
                 /* @var $path Path */
                 foreach (Swagger::$METHODS as $method) {
                     if ($path->hasOperation($method)) {
                         $op = $path->getOperation($method);
                         $actionName = $op->getOperationId();
                         $routes[str_replace('-', '_', $actionName)] = ['method' => $method, 'path' => $path->getPath()];
                     }
                 }
             }
             $modules[] = ['title' => $model->getTitle(), 'slug' => $package->getKeeko()->getModule()->getSlug(), 'model' => $model, 'routes' => $routes];
         }
     }
     $this->modules = $modules;
     return $modules;
 }
Exemplo n.º 17
0
 public function testExtendedPackage()
 {
     $package = PackageSchema::fromFile(__DIR__ . '/fixture/extended.json');
     $json = Json::encode($package->toArray(), Json::PRETTY_PRINT | Json::UNESCAPED_SLASHES);
     $expected = file_get_contents(__DIR__ . '/fixture/extended.json');
     $this->assertEquals($expected, $json);
 }