コード例 #1
0
 public function run()
 {
     $url = Graphene::getInstance()->getSettings()['modulesUrl'] . "";
     $namespace = 'testmod';
     $name = 'com.test' . $namespace;
     $author = 'Pippo rossi';
     mkdir($url . "/" . $namespace);
     $manifest = array("v" => "0.1.1", "info" => array("version" => "0.0.0.1", "name" => $name, "namespace" => $namespace, "author" => $author, "support" => ''), "actions" => array(array("method" => 'get', "query" => 'hello', "name" => 'HELLO_WORLD', "handler" => 'HelloWorld@actions/HelloWorld.HELLO_WORLD.php')));
     $fp = fopen($url . "/" . $namespace . "/manifest.json", 'w');
     fwrite($fp, json_encode($manifest, JSON_PRETTY_PRINT));
     fclose($fp);
     //ADD ACTION
     $head = "<?php\nnamespace " . $namespace . ";\nuse Graphene\\controllers\\Action;\nclass HelloWorld extends Action {\n";
     $content = "\tpublic function run() {\n\t\t\$this->sendMessage('hello world');\n\t}";
     $end = "\n}";
     $actionFl = $head . $content . $end;
     if (!file_exists($url . "/" . $namespace . "/actions")) {
         mkdir($url . "/" . $namespace . "/actions");
     }
     $fp = fopen($url . "/" . $namespace . "/actions/HelloWorld.HELLO_WORLD.php", 'w');
     fwrite($fp, $actionFl);
     fclose($fp);
     $this->sendMessage('module created on: ' . $url . "/" . $namespace);
     //$this->sendMessage($url);
 }
コード例 #2
0
 public function run()
 {
     $model = new $this->pars[0]();
     $data = $this->request->getData();
     //var_dump($data);
     $query = $data['search'];
     $sortBy = $data['sort']['by'] !== null ? $data['sort']['by'] : '';
     $pageSize = intval($data['page']['size']) ? intval($data['page']['size']) : null;
     $page = intval($data['page']['no']) ? intval($data['page']['no']) : 1;
     $sortMode = boolval($data['sort']['discend']) ? 'DSC' : 'ASC';
     $gQuery = ['search' => $query, 'sort' => ['by' => $sortBy, 'mode' => $sortMode]];
     $model->setLazy(true);
     $readed = $model->read(true, $gQuery, $page, $pageSize);
     if ($readed instanceof ModelCollection) {
         $url = 'http://' . $_SERVER['HTTP_HOST'] . Graphene::getInstance()->getSettings()['baseUrl'] . $this->request->getUrl();
         $page = $readed->getPage();
         $pageSize = $readed->getPageSize();
         $httpQ = ['search' => $query, 'sort_by' => $sortBy, 'sort_discend' => $sortMode === 'DSC' ? '1' : '0', 'page_size' => $pageSize, 'page_no' => $page];
         $httpQN = $httpQ;
         $httpQN['page_no'] = $httpQN['page_no'] + 1;
         $httpQP = $httpQ;
         $httpQP['page_no'] = $httpQP['page_no'] - 1;
         $readed->setNextPageUrl($url . '?' . http_build_query($httpQN));
         $readed->setCurrentPageUrl($url . '?' . http_build_query($httpQ));
         if ($page > 1) {
             $readed->setPreviousPageUrl($url . '?' . http_build_query($httpQP));
         }
     }
     $this->send($readed);
 }
コード例 #3
0
 public function execFilters(GraphRequest $req, Module $module, Action $action)
 {
     if ($req->getHeader('system-token') !== null && $req->getHeader('system-token') === Graphene::getInstance()->getSystemToken()) {
         return true;
     }
     $executed = array();
     self::$ids++;
     $errs = array();
     do {
         $execs = 0;
         foreach ($this->filters as $filter) {
             if (array_search($filter->getName(), $executed) === false && $this->checkAfter($executed, $filter)) {
                 $execs++;
                 $executed[] = $filter->getName();
                 Log::debug('executing filter: ' . $filter->getName());
                 if (!$filter->exec($req, $module, $action)) {
                     $errs[] = array('ignored' => $filter->errorIgnored(), 'name' => $filter->getName(), 'status' => $filter->getStatus(), 'message' => $filter->getMessage());
                 }
             }
         }
     } while ($execs > 0);
     if (count($executed) !== count($this->filters)) {
         Log::err('Some filter was not executed');
         //TODO elenco filtri non eseguiti e dipendenze richieste
     }
     $this->filterErrors[self::$ids] = $errs;
     return !$this->haveErrors();
 }
コード例 #4
0
 public function run()
 {
     $data = $this->request->getData();
     $action = strtoupper($data['action']);
     $detail = array_key_exists('detail', $data) && $data['detail'] == '1' ? true : false;
     $doc = Graphene::getInstance()->getDoc($action, $detail);
     $this->response->setData(["DocAction" => $doc]);
 }
コード例 #5
0
 /**
  * @return string
  */
 public function getDomain()
 {
     if ($this->domain == null) {
         $fw = Graphene::getInstance();
         $this->domain = $fw->getApplicationName() . "." . $fw->getCurrentModule()->getNamespace() . "." . $this->getModelName();
     }
     return $this->domain;
 }
コード例 #6
0
 /**
  * Recupera l'istanza del framework, o ne crea una nel caso non esista
  *
  * @return Graphene instance
  *        
  */
 public static function getInstance()
 {
     if (Graphene::$instance == null) {
         Graphene::registerAutoloaders();
         Graphene::$instance = new Graphene();
     }
     return Graphene::$instance;
 }
コード例 #7
0
function autol_moduleContent($name)
{
    $settings = Graphene::getInstance()->getSettings();
    $modPath = $settings['modulesUrl'];
    $name = str_replace('\\', '/', $name);
    $filename = $modPath . "/" . $name . ".php";
    if (is_readable(G_path($filename))) {
        G_Require($filename);
    }
}
コード例 #8
0
function autol_moduleContent($name)
{
    $settings = Graphene::getInstance()->getSettings();
    $modPath = $settings['modulesUrl'];
    $name = str_replace('\\', '/', $name);
    $filename = $modPath . '/' . $name . '.php';
    //Log::debug( 'module filename: '.$filename);
    if (is_readable($filename)) {
        require_once $filename;
    }
}
コード例 #9
0
 public function run()
 {
     $req = json_decode($this->request->getBody(), true)['Stat'];
     if ($req !== null) {
         $method = $req['method'];
         $url = $req['url'];
         $body = $req['body'];
         $res = $this->forward($url, json_encode($body), $method);
         $this->response->setBody(json_encode(["response" => json_decode($res->getBody(), true), "Stats" => Graphene::getInstance()->getStats()], JSON_PRETTY_PRINT));
     } else {
         $this->sendError(400, 'invalid request', 400);
     }
 }
コード例 #10
0
 public static function createByRequest(GraphRequest $request, Module $mod = null, $lazyChecks = false)
 {
     if ($mod == null) {
         $mod = Graphene::getInstance()->getCurrentModule();
     }
     if (($decoded = json_decode($request->getBody(), true)) === null) {
         throw new GraphException('Malformed request, check jsons structs on body', ExceptionsCodes::REQUEST_MALFORMED, 400);
     }
     $return = array();
     foreach ($decoded as $ModelName => $modelContent) {
         $domain = Graphene::getInstance()->getApplicationName() . '.' . $mod->getNamespace() . '.' . $ModelName;
         if (($return[$ModelName] = self::createModel($modelContent, $domain, $lazyChecks)) === false) {
             self::$BEAN_PARSING_ERRS[] = self::$LAST_BEAN->getLastTestErrors();
             throw new GraphException(self::$LAST_BEAN->getLastTestErrors(), ExceptionsCodes::REQUEST_MALFORMED, 400);
         }
     }
     return $return;
 }
コード例 #11
0
 public function run()
 {
     $this->status = array();
     $fw = Graphene::getInstance();
     $mods = $fw->getInstalledModulesInfos();
     $this->status['framework-infos'] = Graphene::INFO;
     $this->status['framework-version'] = Graphene::VERSION;
     $this->status['php-version'] = 'PHP v.' . phpversion();
     $this->status['app-name'] = $fw->getApplicationName();
     if ($fw->getStorage()->checkConnection()) {
         $this->status['db']['connectionStatus'] = 'ok';
     } else {
         $this->status['db']['connectionStatus'] = 'connection fails';
     }
     $this->status['db']['driver'] = $fw->getStorage()->getDriverInfos();
     // Sending response
     $this->status['server']['time'] = date('Y-m-d H:i:s');
     $this->status['server']['software'] = $_SERVER['SERVER_SOFTWARE'];
     $this->status['installed-modules'] = array();
     foreach ($mods as $mod) {
         $this->status['installed-modules'][] = str_pad($mod['name'], 20) . ' [' . count($mod['actions']) . ']';
     }
     $this->response->setBody($this->getStatusBody());
 }
コード例 #12
0
ファイル: index.php プロジェクト: GrapheneProject/Graphene
<?php

require 'Graphene/Graphene.class.php';
use Graphene\Graphene;
$gr = Graphene::getInstance();
$gr->start('settings.json');
コード例 #13
0
ファイル: cli.php プロジェクト: GrapheneProject/Graphene
            $this->request = $this->data['request'];
            $this->context = $this->data['context'];
            $this->settings = $this->data['settings'];
        }
    }
    public function isEnabled()
    {
        return $this->isEnabled;
    }
    public function getData()
    {
        return $this->data;
    }
    public function getRequest()
    {
        return $this->request;
    }
    public function getContext()
    {
        return $this->context;
    }
    public function getSettings()
    {
        return $this->settings;
    }
    private $data, $request, $context, $settings, $isEnabled;
    public static $instance = null;
}
if (Cli::getInstance($argv)->isEnabled()) {
    Graphene::getInstance()->start();
}
コード例 #14
0
 public function run()
 {
     $this->response->setBody(json_encode(array('InstalledModules' => Graphene::getInstance()->getInstalledModulesInfos()), JSON_PRETTY_PRINT));
 }
コード例 #15
0
 private function injectActions($injection, $request)
 {
     $injectionDir = Graphene::getInstance()->getRouter()->getInjectionDir();
     $injectionName = strtoupper(substr($injection['name'], 1));
     if (file_exists($injectionDir . '/' . $injectionName . '/manifest.xml')) {
         $injXml = json_decode(json_encode(simplexml_load_file($injectionDir . '/' . $injectionName . '/manifest.xml')), true);
         if (isset($injXml['action'])) {
             $actions = $injXml['action'];
         } else {
             $actions = array();
         }
         foreach ($actions as $action) {
             $action = $action['@attributes'];
             if (str_starts_with($action['name'], '$')) {
                 $this->injectActions($action, $request);
             } else {
                 if (isset($injection['pars'])) {
                     $pars = explode(',', $injection['pars']);
                 } else {
                     $pars = array();
                 }
                 if (isset($injection['query-prefix'])) {
                     $pfx = $injection['query-prefix'];
                 } else {
                     $pfx = '';
                 }
                 $this->loadAction($action, $request, $injectionDir . '/' . strtoupper($injectionName), 'injection', $pars, $pfx);
             }
         }
     } else {
         //echo 'no injection for: ' . $injectionDir . '/' . $injectionName . '/manifest.xml';
     }
 }
コード例 #16
0
 public function read($modulePath)
 {
     if (array_key_exists($modulePath, self::$cache)) {
         $this->manifest = self::$cache[$modulePath];
     }
     Graphene::getInstance()->startStat('loadManifest', $modulePath);
     $this->modulePath = $modulePath;
     $manifest = array();
     $rManifest = $this->loadJson($modulePath);
     if ($rManifest === null) {
         $rManifest = $this->loadXml($modulePath);
     }
     //Exceptions
     if ($rManifest === null) {
         throw new GraphException('module manifest not valid in: ' . $modulePath, 500);
     }
     if (!array_key_exists('info', $rManifest)) {
         throw new GraphException('module info node not found in: ' . $modulePath, 500);
     }
     if (!array_key_exists('namespace', $rManifest['info'])) {
         throw new GraphException('module namespace is undefined in: ' . $modulePath, 500);
     }
     if (!array_key_exists('name', $rManifest['info'])) {
         throw new GraphException('module name is undefined in: ' . $modulePath, 500);
     }
     if (!array_key_exists('version', $rManifest['info'])) {
         throw new GraphException('module version is undefined in: ' . $modulePath, 500);
     }
     //Defaults
     if (!array_key_exists('support', $rManifest['info'])) {
         $rManifest['info']['support'] = Graphene::host() . '/doc/' . $rManifest['info']['namespace'];
     }
     if (!array_key_exists('domain', $rManifest['info'])) {
         $rManifest['info']['domain'] = $rManifest['info']['namespace'];
     }
     if (!array_key_exists('models-path', $rManifest['info'])) {
         $rManifest['info']['models-path'] = 'models';
     }
     if (!array_key_exists('actions-path', $rManifest['info'])) {
         $rManifest['info']['actions-path'] = 'actions';
     }
     if (!array_key_exists('filters-path', $rManifest['info'])) {
         $rManifest['info']['filters-path'] = 'filters';
     }
     if (!array_key_exists('doc-path', $rManifest['info'])) {
         $rManifest['info']['doc-path'] = 'doc';
     }
     if (!array_key_exists('depends', $rManifest['info'])) {
         $rManifest['info']['depends'] = '';
     }
     if (!array_key_exists('actions', $rManifest)) {
         $rManifest['actions'] = array();
     }
     if (!array_key_exists('filters', $rManifest)) {
         $rManifest['filters'] = array();
     }
     $manifest['info'] = array();
     $manifest['actions'] = array();
     $manifest['filters'] = array();
     //Informations
     $manifest['info']['version'] = $rManifest['info']['version'];
     $manifest['info']['name'] = $rManifest['info']['name'];
     $manifest['info']['depends'] = $this->parseCommas($rManifest['info']['depends']);
     $manifest['info']['namespace'] = $rManifest['info']['namespace'];
     $manifest['info']['support'] = $rManifest['info']['support'];
     $manifest['info']['domain'] = $rManifest['info']['domain'];
     $manifest['info']['models-path'] = $rManifest['info']['models-path'];
     $manifest['info']['actions-path'] = $rManifest['info']['actions-path'];
     $manifest['info']['filters-path'] = $rManifest['info']['filters-path'];
     $manifest['info']['doc-path'] = $rManifest['info']['doc-path'];
     $manifest['info']['author'] = $rManifest['info']['author'];
     //Resolving imports
     $rManifest['actions'] = $this->resolveImports($rManifest['actions']);
     //Actions
     foreach ($rManifest['actions'] as $k => $action) {
         if (array_key_exists('name', $action)) {
             if (!array_key_exists('pars', $action)) {
                 $rManifest['actions'][$k]['pars'] = '';
             }
             if (!array_key_exists('query-prefix', $action)) {
                 $rManifest['actions'][$k]['query-prefix'] = '';
             }
             if (!array_key_exists('handler', $action)) {
                 $rManifest['actions'][$k]['handler'] = $this->actionNameToCamel($action['name']) . '@' . $rManifest['info']['actions-path'] . DIRECTORY_SEPARATOR . $rManifest['info']['namespace'] . '.' . $action['name'] . '.php';
             }
             if (!array_key_exists('doc', $action)) {
                 $rManifest['actions'][$k]['doc'] = $rManifest['info']['doc-path'] . DIRECTORY_SEPARATOR . $rManifest['info']['namespace'] . '.' . $action['name'] . '.md';
             }
             if (!array_key_exists('method', $action)) {
                 $rManifest['actions'][$k]['method'] = 'GET';
             }
             if (!array_key_exists('query', $action)) {
                 $rManifest['actions'][$k]['query'] = '';
             }
             if (!array_key_exists('pars', $action)) {
                 $rManifest['actions'][$k]['pars'] = '';
             }
             if (!array_key_exists('query-prefix', $action)) {
                 $rManifest['actions'][$k]['query-prefix'] = '';
             }
             if (!array_key_exists('name-prefix', $action)) {
                 $rManifest['actions'][$k]['name-prefix'] = '';
             }
             if (!array_key_exists('name-postfix', $action)) {
                 $rManifest['actions'][$k]['name-postfix'] = '';
             }
             $rManifest['actions'][$k]['name'] = strtoupper($rManifest['actions'][$k]['name-prefix'] . $rManifest['actions'][$k]['name'] . $rManifest['actions'][$k]['name-postfix']);
             $expl = explode('@', $rManifest['actions'][$k]['handler']);
             $class = $expl[0];
             $file = $expl[1];
             $file = $this->cleanUrl($file, $modulePath);
             $rManifest['actions'][$k]['doc'] = $this->cleanUrl($rManifest['actions'][$k]['doc'], $modulePath);
             $manifest['actions'][$k] = array();
             $manifest['actions'][$k]['name'] = $rManifest['actions'][$k]['name'];
             $manifest['actions'][$k]['doc'] = $rManifest['actions'][$k]['doc'];
             $manifest['actions'][$k]['unique-name'] = $manifest['info']['name'] . '.' . $rManifest['actions'][$k]['name'];
             $manifest['actions'][$k]['method'] = strtoupper($rManifest['actions'][$k]['method']);
             $manifest['actions'][$k]['imported'] = $rManifest['actions'][$k]['imported'];
             $manifest['actions'][$k]['query'] = $rManifest['actions'][$k]['query-prefix'] . $rManifest['actions'][$k]['query'];
             $manifest['actions'][$k]['handler'] = $rManifest['actions'][$k]['handler'];
             $manifest['actions'][$k]['file'] = $file;
             $manifest['actions'][$k]['class'] = $class;
             $manifest['actions'][$k]['pars'] = $this->parseCommas($rManifest['actions'][$k]['pars']);
         } else {
             Log::err('action ' . $k . ' name is not defined in: ' . $modulePath);
         }
     }
     //Filters
     $manifest['filters'] = $rManifest['filters'];
     foreach ($rManifest['filters'] as $k => $filter) {
         if (array_key_exists('name', $filter)) {
             $rManifest['filters'][$k]['name'] = strtoupper($filter['name']);
             if (!array_key_exists('handler', $filter)) {
                 $rManifest['filters'][$k]['handler'] = $this->filterNameToCamel($filter['name']) . '@' . $rManifest['info']['filters-path'] . '/' . $rManifest['info']['namespace'] . '.' . $filter['name'] . '.php';
             }
             if (!array_key_exists('scope', $filter)) {
                 $rManifest['filters'][$k]['scope'] = 'MODULE';
             }
             if (!array_key_exists('after', $filter)) {
                 $rManifest['filters'][$k]['after'] = '';
             }
             $expl = explode('@', $rManifest['filters'][$k]['handler']);
             $class = $expl[0];
             $file = $expl[1];
             $file = $this->cleanUrl($file, $modulePath);
             $manifest['filters'][$k]['name'] = $rManifest['filters'][$k]['name'];
             $manifest['filters'][$k]['unique-name'] = $manifest['info']['name'] . '.' . $rManifest['filters'][$k]['name'];
             $manifest['filters'][$k]['file'] = $file;
             $manifest['filters'][$k]['class'] = $class;
             $manifest['filters'][$k]['handler'] = $rManifest['filters'][$k]['handler'];
             $manifest['filters'][$k]['scope'] = strtoupper($rManifest['filters'][$k]['scope']);
             $manifest['filters'][$k]['after'] = $this->parseCommas($rManifest['filters'][$k]['after']);
         } else {
             Log::err('filter ' . $k . ' name is not defined in: ' . $modulePath);
         }
     }
     //Log::debug("\n-------\nLOADED MANIFEST\n--------\n".json_encode($manifest,JSON_PRETTY_PRINT));
     //print_r($manifest);
     self::$cache[$modulePath] = $manifest;
     $this->manifest = $manifest;
     Graphene::getInstance()->stopStat('loadManifest', $modulePath);
 }
コード例 #17
0
 /**
  * Crea una risposta sicura (Modulo non trovato se non e pervenuta una
  * risposta)
  *
  * @param  GraphResponse | null $response
  * @return GraphResponse
  */
 private function getSafeResponse($response)
 {
     $filterManager = Graphene::getInstance()->getFilterManager();
     if ($response === null) {
         $response = new GraphResponse();
         $response->setHeader('content-type', 'application/json');
         if ($filterManager->haveErrors()) {
             $response->setBody($filterManager->serializeErrors());
             $ff = $filterManager->getFailedFilter();
             $response->setBody(json_encode(array("error" => array("message" => '[' . $ff['name'] . '] ' . $ff['message'], "code" => $ff['status'])), JSON_PRETTY_PRINT));
             $response->setStatusCode($ff['status']);
         } else {
             $response->setBody(json_encode(array("error" => array("message" => "action not found", "code" => "400")), JSON_PRETTY_PRINT));
             $response->setStatusCode(400);
         }
     }
     return $response;
 }
コード例 #18
0
 protected function forward($url, $data = null, $method = null, $checkErrors = true)
 {
     //Statistics
     $statId = uniqid();
     Graphene::getInstance()->startStat('RequestForwarding', $url . ' : ' . $statId);
     $req = new GraphRequest(true);
     $req->setUrl($url);
     //setting http method
     if ($data === null && $method === null) {
         $req->setMethod('GET');
     } else {
         if ($data !== null && $method === null) {
             $req->setMethod('POST');
         } else {
             if ($method !== null) {
                 $req->setMethod($method);
             }
         }
     }
     //setting request data
     if ($data === null) {
         $req->setData([]);
     } else {
         if (is_array($data)) {
             $req->setData($data);
         } else {
             if (is_string($data)) {
                 $req->setData(json_decode($data, true));
             } else {
                 if ($data instanceof Model) {
                     $req->setData($data->getData());
                 } else {
                     if ($data instanceof ModelCollection) {
                         $req->setData($data->getData());
                     }
                 }
             }
         }
     }
     //setting headers
     $headers = $this->request->getHeaders();
     foreach ($headers as $hk => $hv) {
         $req->setHeader($hk, $hv);
     }
     $req->setHeader('forwarded-by', $this->getUniqueActionName());
     $req->appendForward($this);
     $res = Graphene::getInstance()->forward($req);
     Graphene::getInstance()->stopStat('RequestForwarding', $url . ' : ' . $statId);
     if ($checkErrors && $res->getStatusCode() >= 400) {
         $data = $res->getData();
         throw new GraphException($res->getHeader('graphene-action') . ': ' . $data['error']['message'], $data['error']['code'], 400);
     }
     return $res;
 }
コード例 #19
0
 public function exec(GraphRequest $req, Module $mod, Action $action)
 {
     $this->message = self::DEFAULT_MESSAGE;
     $this->status = self::DEFAULT_STATUS;
     $this->ignored = 0;
     $this->request = $req;
     $this->module = $mod;
     $this->action = $action;
     if ($this->isHandled($mod, $action)) {
         $startId = md5(uniqid(true));
         Graphene::getInstance()->startStat('Filter run', '[' . $startId . '] ' . $this->getName());
         $this->run();
         Graphene::getInstance()->stopStat('Filter run', '[' . $startId . '] ' . $this->getName());
     }
     return $this->isOk();
 }
コード例 #20
0
 public function getCurrentAction()
 {
     $action = Graphene::getInstance()->getCurrentModule()->getCurrentAction();
     return $action;
 }
コード例 #21
0
 /**
  * Carica un model compilato parzialmente utilizzando
  * i campi compilati come criterio di ricerca in <b>AND<b> tra loro
  *
  * @param Model $model
  * @param bool $multiple
  * @param null $query
  * @param null $pageNo
  * @param null $pageElements
  * @return Model | ModelCollection Uno o piu model che corrispondono ai criteri di ricerca
  * @throws GraphException
  * @internal param $ <b>Model</b> modello parzialmente compilato*            <b>Model</b> modello parzialmente compilato
  */
 public function read(Model $model, $multiple = false, $query = null, $page = null, $pageSize = null)
 {
     Log::debug('calling storage driver for read');
     Graphene::getInstance()->startStat('storageRead');
     if (!$multiple) {
         $page = 1;
         $pageSize = 2;
     } else {
         if ($page === null) {
             $page = 1;
         }
         if ($pageSize === null) {
             $pageSize = self::DEFAULT_PAGE_SIZE;
         }
     }
     $readed = $this->driver->read($this->serializeForDb($model, $page, $pageSize), $query);
     // echo "JSON Letto\n----\n";
     // echo ($readed);
     $result = ModelFactory::createByDbSerialization($readed);
     if (is_null($result)) {
         Graphene::getInstance()->stopStat('storageRead');
         throw new GraphException('Error when read, Stored ' . $model->getModelName() . ' is corrupt' . ModelFactory::getModelParsingErrs(), ExceptionsCodes::BEAN_STORAGE_CORRUPTED_BEAN, 400);
     } else {
         if (count($result) == 0) {
             Graphene::getInstance()->stopStat('storageRead');
             return null;
         } else {
             if ($multiple) {
                 $ret = new ModelCollection($model);
                 $ret->add($result);
                 $ret->setPage($page);
                 $ret->setPageSize($pageSize);
                 Graphene::getInstance()->stopStat('storageRead');
                 return $ret;
             } else {
                 if (count($result) == 1) {
                     Graphene::getInstance()->stopStat('storageRead');
                     return $result[0];
                 } else {
                     Graphene::getInstance()->stopStat('storageRead');
                     throw new GraphException("Unexpected result, loaded must be single model", 5002, 500);
                 }
             }
         }
     }
 }