Ejemplo n.º 1
0
 /**
  * RpcCall constructor.
  * @param string $className Class name without namespace
  * @param string $methodName Method Name
  * @param mixed $arguments Method argument
  * @throws InputError
  * @throws SecurityException
  * @throws \ema\exceptions\FatalError
  */
 public function __construct($className, $methodName, $arguments = '')
 {
     if (!self::classExists($className)) {
         throw new InputError('Unknown class requested', 6100);
     }
     $this->className = self::CALLER_NS . $className;
     if (!self::methodExists($className, $methodName)) {
         throw new InputError('Unknown method requested', 6101);
     }
     $this->methodName = $methodName;
     $gp = new GroupPolicy($this->className);
     $allowedMethods = $gp->getAjaxMethods();
     if (!in_array($methodName, $allowedMethods, true)) {
         throw new SecurityException('Method not allowed', 6102);
     }
     unset($allowedMethods, $gp);
     $this->arguments = $arguments;
 }
Ejemplo n.º 2
0
 private static function getViewModels(array $models)
 {
     $modelsData = array();
     $gp = new GroupPolicy('dummy');
     $modelsWithNS = array();
     foreach ($models as $model) {
         if (self::modelExists($model)) {
             $modelsWithNS[] = self::MODELS_NAMESPACE . $model;
         }
     }
     $methods = $gp->getViewModelMethods($modelsWithNS);
     unset($modelsWithNS, $gp);
     foreach ($models as $model) {
         $tmpArray = array();
         $className = self::MODELS_NAMESPACE . $model;
         if (!empty($methods[$model])) {
             $tmpArray['methods'] = $methods[$model];
         }
         $dataStructure = $className::getDataStructureStatic();
         if (!empty($dataStructure)) {
             $tmpArray['model'] = $dataStructure;
         }
         if (!empty($tmpArray)) {
             $modelsData[$model] = $tmpArray;
         }
         unset($tmpArray, $className);
     }
     print json_encode($modelsData);
 }