예제 #1
1
 /**
  * Attach routes to the application.
  * @return \Georeferencer\Application\Micro
  **/
 private function bootstrapRouting()
 {
     $config = $this->getApplication()->getDI()->get(self::DI_CONFIG);
     $this->getApplication()->notFound(function () {
         $controller = new \Georeferencer\Controller\IndexCtrl();
         return $controller->notFound();
     });
     if (isset($config['routesCollection'])) {
         foreach ($config['routesCollection'] as $routeCollection) {
             $collection = new \Phalcon\Mvc\Micro\Collection();
             $collection->setHandler($routeCollection['setHandler'], true);
             foreach ($routeCollection['routes'] as $type => $routes) {
                 foreach ($routes as $pattern => $callback) {
                     $collection->{$type}($pattern, $callback);
                 }
             }
             $this->getApplication()->mount($collection);
         }
     }
     //Set the correct url for the helper.
     if (isset($_SERVER['SERVER_NAME'])) {
         // Detect scheme
         $scheme = 'http';
         if (isset($_SERVER['HTTPS'])) {
             $scheme = 'https';
         }
         if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
             $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'];
         }
         $this->getApplication()->getDI()->get(self::DI_URL_HELPER)->setBaseUri($scheme . '://' . $_SERVER['SERVER_NAME']);
     }
     return $this;
 }
예제 #2
0
 public function resource($route, $controller, $additionals = [])
 {
     $collection = new \Phalcon\Mvc\Micro\Collection();
     $collection->setPrefix($route);
     $collection->setHandler(new $controller());
     $collection->get('/', 'getAll');
     $collection->get('/{id}', 'get');
     $collection->post('/', 'create');
     $collection->put('/{id}', 'update');
     $collection->delete('/{id}', 'delete');
     $this->mount($collection);
 }
예제 #3
0
 public static function getAppInstance()
 {
     if (!self::$appInstance) {
         try {
             /**
              * Read the configuration
              */
             $config = (include APP_PATH . "/app/config/config.php");
             /**
              * Read auto-loader
              */
             include APP_PATH . "/app/config/loader.php";
             /**
              * Read services
              */
             $di = self::getDiInstance();
             include APP_PATH . "/app/config/services.php";
             /**
              * Handle the Route
              */
             self::$appInstance = new \Phalcon\Mvc\Micro($di);
             $syncRoute = new Phalcon\Mvc\Micro\Collection();
             // $syncRoute->setHandler(new SyncController($di));
             $syncRoute->setHandler('SyncController', true);
             $syncRoute->setPrefix('sync/');
             $syncRoute->map('get_user/{api}/{guid}', 'indexAction');
             $syncRoute->map('add_user/{api}/{guid}', 'addUserAction');
             $syncRoute->map('update_user/{api}/{guid}', 'updateUserAction');
             $syncRoute->map('insert_user/{api}/{guid}', 'insertUserAction');
             $syncRoute->map('plus_user/{api}/{guid}', 'plusUserAction');
             self::$appInstance->mount($syncRoute);
             $asyncRoute = new Phalcon\Mvc\Micro\Collection();
             // $asyncRoute->setHandler(new AsyncController($di));
             $asyncRoute->setHandler('AsyncController', true);
             $asyncRoute->setPrefix('async/');
             $asyncRoute->map('add_user/{api}/{guid}', 'addUserAction');
             $asyncRoute->map('update_user/{api}/{guid}', 'updateUserAction');
             $asyncRoute->map('insert_user/{api}/{guid}', 'insertUserAction');
             $asyncRoute->map('plus_user/{api}/{guid}', 'plusUserAction');
             self::$appInstance->mount($asyncRoute);
             file_put_contents("/tmp/sw_server_instance.log", "new AppInstance" . date("Y-m-d H:i:s") . "\r\n", FILE_APPEND);
         } catch (\Exception $e) {
             echo $e->getMessage() . '<br>';
             echo '<pre>' . $e->getTraceAsString() . '</pre>';
         }
     }
     return self::$appInstance;
 }
예제 #4
0
 public static function resource(&$app, $path, $controller)
 {
     $collection = new \Phalcon\Mvc\Micro\Collection();
     $collection->setHandler(new $controller());
     // index
     $collection->get($path, 'indexAction');
     // show?
     $collection->get("{$path}/search/{id}", 'searchAction');
     // edit?
     $app->get("{$path}/{id:[0-9]+}", 'editAction');
     // store
     $app->post($path, 'storeAction');
     // update
     $app->put("{$path}/{id:[0-9]+}", 'updateAction');
     // delete
     $app->delete("{$path}/{id:[0-9]+}", 'deleteAction');
     $app->mount($collection);
 }
예제 #5
0
 public static function getAppInstance()
 {
     if (!self::$appInstance) {
         try {
             /**
              * Read the configuration
              */
             $config = (include APP_PATH . "/app/config/config.php");
             /**
              * Read auto-loader
              */
             include APP_PATH . "/app/config/loader.php";
             /**
              * Read services
              */
             $di = self::getDiInstance();
             include APP_PATH . "/app/config/services.php";
             self::$appInstance = new \Phalcon\Mvc\Micro($di);
             /**
              * Handle the Route, Sync RPC handler
              */
             $syncRoute = new Phalcon\Mvc\Micro\Collection();
             $syncRoute->setHandler('IndexController', true);
             $syncRoute->setPrefix('sync/');
             $syncRoute->map('getUserById/{key}', 'getUserByIdAction');
             $syncRoute->map('checkUserLoginInfo/{key}', 'checkUserLoginInfoAction');
             $syncRoute->map('checkLoginName/{key}', 'checkLoginNameAction');
             $syncRoute->map('addUser/{key}', 'addUserAction');
             $syncRoute->map('updateUser/{key}', 'updateUserAction');
             $syncRoute->map('deleteUser/{key}', 'deleteUserAction');
             $syncRoute->map('getUsers/{key}', 'getUsersAction');
             self::$appInstance->mount($syncRoute);
             /**
              * More, just like Async RPC handler
              */
         } catch (\Exception $e) {
             echo $e->getMessage() . '<br>';
             echo '<pre>' . $e->getTraceAsString() . '</pre>';
         }
     }
     return self::$appInstance;
 }
 public function testMicroCollectionsLazy()
 {
     Phalcon\DI::reset();
     $app = new Phalcon\Mvc\Micro();
     $collection = new Phalcon\Mvc\Micro\Collection();
     $collection->setHandler('PersonasLazyController', true);
     $collection->map('/', 'index');
     $collection->map('/edit/{number}', 'edit');
     $app->mount($collection);
     $app->handle('/');
     $this->assertEquals(PersonasLazyController::getEntered(), 1);
     $app->handle('/edit/100');
     $this->assertEquals(PersonasLazyController::getEntered(), 101);
 }
<?php

$app = new Phalcon\Mvc\Micro();
$collection = new Phalcon\Mvc\Micro\Collection();
$collection->setHandler(new PostsController());
$collection->get('/posts/edit/{id}', 'edit');
$app->mount($collection);