Exemple #1
0
 protected function get($type)
 {
     $module = new CountryModule($this->client);
     $em = $this->getEntityManager();
     $countries = $em->getRepository('Erpk\\Common\\Entity\\Country');
     $code = $this->getParameter('code');
     if (preg_match('/^[0-9]+$/', $code)) {
         $country = $countries->findOneById((int) $code);
     } else {
         $country = $countries->findOneByCode($code);
     }
     if ($country instanceof Country) {
         $data = $module->{'get' . $type}($country);
         switch ($type) {
             case 'Economy':
                 $data['embargoes']['@nodeName'] = 'embargo';
                 break;
             case 'Society':
                 $data['regions']['@nodeName'] = 'region';
                 break;
         }
         $vm = new ViewModel($data);
         $vm->setRootNodeName('country');
     } else {
         $vm = ViewModel::error('CountryNotFoundException', 500);
     }
     return $vm;
 }
Exemple #2
0
 protected function controller($params)
 {
     $ex = explode('::', $params['_controller']);
     $className = 'Erpk\\Harserver\\Controller\\' . $ex[0];
     $obj = new $className($this->client, $params);
     try {
         return $obj->{$ex[1]}();
     } catch (Exception $e) {
         return ViewModel::error(get_class($e), 500, (string) $e);
     }
 }