public function init(Phalcon\Mvc\Micro $app) { try { $param = $app->request->getQuery(); $this->validation($param); if (in_array($param['module'], $this->moduleHidden)) { throw new Phalcon\Mvc\Micro\Exception("Esta aplicação não pode ser executada.", 401); } if (isset($this->moduleMask[$param['module']])) { $param['module'] = $this->moduleMask[$param['module']]; } $this->setModule($this->getModule($param['module'])); $this->registerNamespace(); $service = $this->getService($param); if (!method_exists($service, $param['action'])) { throw new Phalcon\Mvc\Micro\Exception("Esta ação não existe.", 401); } $this->module->processMiddleware($param, $app); return \Common\Util\Response::success($service->{$param}['action']($app->request)); } catch (Phalcon\Mvc\Micro\Exception $e) { return \Common\Util\Response::error($e->getCode(), $e->getMessage()); } }
<?php use Phalcon\Mvc\Micro; require_once './bootstrap/app.php'; require_once './module/common/util/Response.php'; require_once './module/module.php'; try { $app = new Micro(); $bootstrap = new Bootstrap(); $init = function () use($app, $bootstrap) { return $bootstrap->init($app); }; // Retrieves all robots $app->get('/', $init); // Adds a new robot $app->post('/', $init); // Updates robots based on primary key $app->put('/', $init); // Deletes robots based on primary key $app->delete('/', $init); $app->options('/{catch:(.*)}', $bootstrap->optionsRequest($app)); $app->notFound(function () use($app) { return \Common\Util\Response::error(404, 'Não encontrado!'); }); $app->handle(); } catch (Phalcon\Mvc\Micro\Exception $e) { \Common\Util\Response::error(500, $e->getMessage()); }