Ejemplo n.º 1
0
 public function testApplicationModulesDefinitionClosure()
 {
     // Creates the autoloader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/'));
     $loader->register();
     $_GET['_url'] = '/login';
     Phalcon\DI::reset();
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('router', function () {
         $router = new Phalcon\Mvc\Router(false);
         $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\'));
         $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\'));
         return $router;
     });
     $application = new Phalcon\Mvc\Application();
     $view = new \Phalcon\Mvc\View();
     $application->registerModules(array('frontend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(__DIR__ . '/modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view->setViewsDir(__DIR__ . '/modules/backend/views/');
             return $view;
         });
     }));
     $application->setDi($di);
     $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL);
     $loader->unregister();
 }
Ejemplo n.º 2
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $config = (include __DIR__ . "/../apps/config/config.php");
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array($config->application->libraryDir, $config->application->pluginDir))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/cats/index", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'index'));
         $router->add("/cat/:params", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'cat', 'params' => 1));
         $router->add("/ask/:params", array('module' => 'frontend', 'controller' => 'ask', 'action' => 'ask', 'params' => 1));
         $router->add("/admin/:controller/:action/:params", array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->set('db', function () use($config) {
         $mysql = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
         $mysql->query("set names 'utf8'");
         return $mysql;
     });
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(array('compiledPath' => $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->volt->stat));
         return $volt;
     });
     //Set the views cache service
     $di->set('viewCache', function () {
         //Cache data for one day by default
         $frontCache = new Phalcon\Cache\Frontend\Output(array("lifetime" => 86400));
         //Memcached connection settings
         $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../apps/caches/"));
         return $cache;
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () use($config) {
         if (isset($config->models->metadata)) {
             $metaDataConfig = $config->models->metadata;
             $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             return new $metadataAdapter();
         } else {
             return new Phalcon\Mvc\Model\Metadata\Memory();
         }
     });
     //Start the session the first time some component request the session service
     $di->set('session', function () {
         $session = new Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->setDI($di);
 }
Ejemplo n.º 3
0
 public function testUrl()
 {
     Phalcon\DI::reset();
     //Create a default DI
     $di = new Phalcon\DI();
     $di['router'] = function () {
         $router = new \Phalcon\Mvc\Router(FALSE);
         $router->add('/:controller/:action', array('controller' => 1, 'action' => 2))->setHostName('phalconphp.com')->setName('test');
         return $router;
     };
     $di->set('url', function () {
         $url = new Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     $url = $di->url->get(array('for' => 'test', 'hostname' => true, 'controller' => 'index', 'action' => 'test'));
     $this->assertEquals($url, 'phalconphp.com/index/test');
 }
Ejemplo n.º 4
0
 public static function initSystemService()
 {
     global $di;
     //读取配置项
     $config = (require CONFIG_PATH . "/config.php");
     $di->setShared('config', function () use($config) {
         return $config;
     });
     //设置master数据库
     $di->setShared('dbMaster', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbMaster->toArray());
     });
     //设置slave1数据库
     $di->setShared('dbSlave1', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbSlave1->toArray());
     });
     //设置slave2数据库
     $di->setShared('dbSlave2', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->dbSlave2->toArray());
     });
     //设置redis缓存
     $di->setShared('redis', function () use($config) {
         $frontCache = new \Phalcon\Cache\Frontend\Data($config->cache_life->toArray());
         return new Phalcon\Cache\Backend\Redis($frontCache, $config->redis->toArray());
     });
     //设置Beanstalk队列
     $di->setShared('queue', function () use($config) {
         return new Phalcon\Queue\Beanstalk($config->beanstalk->toArray());
     });
     //设置session
     $di->setShared('session', function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     //设置router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("home");
         $router->add('/:module/:controller/:action', array('module' => 1, 'controller' => 2, 'action' => 3));
         return $router;
     });
 }
Ejemplo n.º 5
0
 private static function cgiRegister()
 {
     $di = get_app_di();
     $config = self::getConfig();
     self::registCommonService($di, $config);
     $di->setShared('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->removeExtraSlashes(true);
         $router->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->setShared('dispatcher', function () {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace("App\\Controllers\\");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($config->view->templatePath);
         $view->registerEngines(array('.html' => function ($view, $di) {
             $config = $di->get('config');
             $compiledPath = $config->view->compiledPath;
             if (!file_exists($compiledPath)) {
                 mkdir($compiledPath, 0744, true);
             }
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => isset($config->view->compileAlways) ?: false));
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new VoltExtension());
             $autoEscape = isset($config->view->autoEscape) ?: true;
             ClassUtil::modifyPrivateProperties($compiler, array('_autoescape' => $autoEscape));
             return $volt;
         }));
         return $view;
     });
     $di->setShared('elements', function () {
         return new ElementsPlugin();
     });
 }
Ejemplo n.º 6
0
 public function testHostnameRegexRouteGroup()
 {
     $this->specify("Router Groups with regular expressions don't work properly", function ($actualHost, $expectedHost, $controller) {
         \Phalcon\Mvc\Router\Route::reset();
         $di = new \Phalcon\DI();
         $di->set("request", function () {
             return new \Phalcon\Http\Request();
         });
         $router = new \Phalcon\Mvc\Router(false);
         $router->setDI($di);
         $router->add("/edit", ["controller" => "posts3", "action" => "edit3"]);
         $group = new \Phalcon\Mvc\Router\Group();
         $group->setHostname("([a-z]+).phalconphp.com");
         $group->add("/edit", ["controller" => "posts", "action" => "edit"]);
         $router->mount($group);
         $_SERVER["HTTP_HOST"] = $actualHost;
         $router->handle("/edit");
         expect($router->getControllerName())->equals($controller);
         expect($router->getMatchedRoute()->getHostname())->equals($expectedHost);
     }, ["examples" => $this->hostnamedRegexRoutesProvider()]);
 }
Ejemplo n.º 7
0
 /**
  * Attach dependencies to the DI container.
  * All DI Objects are attached here. The DI is not modified
  * outside of this method.
  * @return \Georeferencer\Application\Micro
  **/
 private function bootstrapDi($appConfig)
 {
     $di = $this->getApplication()->getDI();
     //configuration
     $di->setShared(self::DI_CONFIG, $appConfig);
     //circular
     $di->setShared(self::DI_APPLICATION, function () {
         return $this;
     });
     //Set the DB.
     $di->setShared(self::DI_DB, function () use($appConfig) {
         return new \Phalcon\Db\Adapter\Pdo\Postgresql($appConfig['db']);
     });
     //Router
     $router = new \Phalcon\Mvc\Router();
     $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
     $di->setShared(self::DI_ROUTER, $router);
     //Url Helper
     $di->setShared(self::DI_URL_HELPER, new \Phalcon\Mvc\Url());
     //Listener
     $di->setShared(self::DI_REST_LISTENER, new \Georeferencer\Listener\Rest());
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Register the services here to make them general or register in
  * the ModuleDefinition to make them module-specific.
  */
 protected function _registerServices()
 {
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     /*
     $loader->registerDirs(
             array(
                     __DIR__ . '/../library/',
                     __DIR__ . '/../vendor/',
             )
     )->register();
     */
     // Init a DI
     $di = new \Phalcon\DI\FactoryDefault();
     // Registering a router:
     $defaultModule = self::DEFAULT_MODULE;
     $modules = self::$modules;
     $di->set('router', function () use($defaultModule, $modules) {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule($defaultModule);
         foreach ($modules as $moduleName => $module) {
             // do not route default module
             if ($defaultModule == $moduleName) {
                 continue;
             }
             $router->add('#^/' . $moduleName . '(|/)$#', array('module' => $moduleName, 'controller' => 'index', 'action' => 'index'));
             $router->add('#^/' . $moduleName . '/([a-zA-Z0-9\\_]+)[/]{0,1}$#', array('module' => $moduleName, 'controller' => 1));
             $router->add('#^/' . $moduleName . '[/]{0,1}([a-zA-Z0-9\\_]+)/([a-zA-Z0-9\\_]+)(/.*)*$#', array('module' => $moduleName, 'controller' => 1, 'action' => 2, 'params' => 3));
         }
         return $router;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di['url'] = function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     };
     /**
      * Start the session the first time some component request the session service
      */
     $di['session'] = function () {
         $session = new \Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     };
     $this->setDI($di);
 }
Ejemplo n.º 9
0
 /**
  * @dataProvider hostnamedRegexRoutesProvider
  */
 public function testHostnameRegexRouteGroup($actualHost, $expectedHost, $controller)
 {
     Phalcon\Mvc\Router\Route::reset();
     $di = new Phalcon\DI();
     $di->set('request', function () {
         return new Phalcon\Http\Request();
     });
     $router = new Phalcon\Mvc\Router(false);
     $router->setDI($di);
     $router->add('/edit', array('controller' => 'posts3', 'action' => 'edit3'));
     $group = new Phalcon\Mvc\Router\Group();
     $group->setHostname('([a-z]+).phalconphp.com');
     $group->add('/edit', array('controller' => 'posts', 'action' => 'edit'));
     $router->mount($group);
     $_SERVER['HTTP_HOST'] = $actualHost;
     $router->handle('/edit');
     $this->assertEquals($router->getControllerName(), $controller);
     $this->assertEquals($router->getMatchedRoute()->getHostname(), $expectedHost);
 }
Ejemplo n.º 10
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
         $router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
         $router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
         return $router;
     });
     $this->setDI($di);
 }
Ejemplo n.º 11
0
<?php

use PhalconSeed\Routes\AuthRoute;
use PhalconSeed\Routes\UserRoute;
use PhalconSeed\Routes\RoleRoute;
use PhalconSeed\Routes\PermissionRoute;
use PhalconSeed\Routes\LogRoute;
/*
 * Define custom routes. File gets included in the router service definition.
 */
$router = new Phalcon\Mvc\Router(false);
// Add the group of auth route to the router
$router->mount(new AuthRoute());
// Add the group of user route to the router
$router->mount(new UserRoute());
// Add the group of role route to the router
$router->mount(new RoleRoute());
// Add the group of permission route to the router
$router->mount(new PermissionRoute());
// Add the group of log route to the router
$router->mount(new LogRoute());
return $router;
Ejemplo n.º 12
0
    }
}
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    session_name('sessionIGO');
    $session->start();
    return $session;
});
/**
* Ajout du routing pour le navigateur construit, en utilisant les paramètres REST plutot que KVP.
*/
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    //Define a route
    $router->add("/contexte/{contexte}", array("controller" => "igo", "action" => "contexte", "contexteid" => 1));
    $router->add("/configuration/{configuration}", array("controller" => "igo", "action" => "configuration", "configuration" => 1));
    $router->add("/couche/{coucheId}", array("controller" => "igo", "action" => "couche", "coucheid" => 1));
    $router->add("/groupe/{groupeId}", array("controller" => "igo", "action" => "groupe", "coucheid" => 1));
    $router->setDefaults(array('controller' => 'index', 'action' => 'index'));
    return $router;
});
if (isset($config->application->authentification->module)) {
    $authentificationModule = new $config->application->authentification->module();
    if ($authentificationModule instanceof AuthentificationController) {
        $di->set("authentificationModule", $authentificationModule);
    } else {
        error_log("Le module d'authentificaiton n'est pas une instance d'AuthentificationController");
    }
Ejemplo n.º 13
0
<?php

/*
 * Define custom routes. File gets included in the router service definition.
 */
$router = new \Phalcon\Mvc\Router();
//Remove trailing slashes automatically
$router->removeExtraSlashes(true);
$router->add('/([a-zA-Z\\-]+)/([a-zA-Z\\-]+)/:params', array('controller' => 1, 'action' => 2, 'params' => 3))->convert('action', function ($action) {
    return Phalcon\Text::camelize($action);
});
$router->add('/signup', array('namespace' => 'Talon\\Controllers', 'controller' => 'session', 'action' => 'signup'))->setName('session-signup');
$router->add('/login', array('namespace' => 'Talon\\Controllers', 'controller' => 'session', 'action' => 'login'))->setName('session-login');
$router->add('/forgot-password', array('namespace' => 'Talon\\Controllers', 'controller' => 'session', 'action' => 'forgotPassword'))->setName('session-forgotPassword');
$router->add('/reset-password/{code}/{email}', array('controller' => 'users_control', 'action' => 'resetPassword'))->setName('session-resetPassword');
$router->add('/confirm/{code}/{email}', array('controller' => 'users_control', 'action' => 'confirmEmail'))->setName('users_control-confirmEmail');
$router->add('/resend-confirmation/{email}', array('controller' => 'users_control', 'action' => 'resendConfirmation'))->setName('users_control-resendConfirmation');
return $router;
Ejemplo n.º 14
0
 public function testHostnameRegexRouteGroup()
 {
     Phalcon\Mvc\Router\Route::reset();
     $di = new Phalcon\DI();
     $di->set('request', function () {
         return new Phalcon\Http\Request();
     });
     $router = new Phalcon\Mvc\Router(false);
     $router->setDI($di);
     $router->add('/edit', array('controller' => 'posts3', 'action' => 'edit3'));
     $group = new Phalcon\Mvc\Router\Group();
     $group->setHostname('([a-z]+).phalconphp.com');
     $group->add('/edit', array('controller' => 'posts', 'action' => 'edit'));
     $router->mount($group);
     $routes = array(array('hostname' => 'localhost', 'controller' => 'posts3'), array('hostname' => 'my.phalconphp.com', 'controller' => 'posts'), array('hostname' => null, 'controller' => 'posts3'));
     foreach ($routes as $route) {
         $_SERVER['HTTP_HOST'] = $route['hostname'];
         $router->handle('/edit');
         $this->assertEquals($router->getControllerName(), $route['controller']);
     }
 }
Ejemplo n.º 15
0
/**
 * Start the session the first time some component request the session service
 */
$di->set('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Register configurations
 */
$di->set('config', function () use($config) {
    return $config;
});
/**
 * Register router
 */
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    $router->removeExtraSlashes(true);
    $router->setDefaults(['controller' => 'index', 'action' => 'index']);
    /*$router->notFound([
          'controller'    => 'errors',
          'action'        => 'pageNotFound'
      ]);*/
    $router->addGet('/project/{profile:([a-zA-Z0-9-(.)]+)}', ['action' => 'profile', 'project' => 1]);
    $router->addPost('/filter', ['action' => 'filter'])->beforeMatch(function ($uri, $route) {
        return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
    });
    return $router;
});
Ejemplo n.º 16
0
 public function testRegex()
 {
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $router->add('/:controller/:action/:params', array("controller" => 1, "action" => 2, "params" => 3));
     $router->handle('/c/a/p');
     $this->assertEquals($router->getMatches(), array(0 => '/c/a/p', 1 => 'c', 2 => 'a', 3 => '/p'));
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $router->add('/:controller/:action:params', array("controller" => 1, "action" => 2, "params" => 3), array(':controller' => '([a-zA-Z0-9_-]+)', ':action' => '([a-zA-Z0-9_-]+)', ':params' => '(/[a-zA-Z0-9_-]+)?'));
     $router->handle('/c/a/p');
     $this->assertEquals($router->getMatches(), array(0 => '/c/a/p', 1 => 'c', 2 => 'a', 3 => '/p'));
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $router->add(':controller:action:params', array("controller" => 1, "action" => 2, "params" => 3), array(':controller' => '/([a-zA-Z0-9_-]+)', ':action' => '/([a-zA-Z0-9_-]+)', ':params' => '(/[a-zA-Z0-9_-]+)?'));
     $router->handle('/c/a/p');
     $this->assertEquals($router->getMatches(), array(0 => '/c/a/p', 1 => 'c', 2 => 'a', 3 => '/p'));
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $router->add('/(:controller(/:action(/:params)?)?)?', array("controller" => 2, "action" => 4, "params" => 5), array(':controller' => '([a-zA-Z0-9_-]+)', ':action' => '([a-zA-Z0-9_-]+)', ':params' => '([a-zA-Z0-9_-]+)?'));
     $router->handle('/c/a/p');
     $this->assertEquals($router->getMatches(), array(0 => '/c/a/p', 1 => 'c/a/p', 2 => 'c', 3 => '/a/p', 4 => 'a', 5 => '/p', 6 => 'p'));
     $router->handle('/c/a');
     $this->assertEquals($router->getMatches(), array(0 => '/c/a', 1 => 'c/a', 2 => 'c', 3 => '/a', 4 => 'a'));
     $router->handle('/c');
     $this->assertEquals($router->getMatches(), array(0 => '/c', 1 => 'c', 2 => 'c'));
 }
Ejemplo n.º 17
0
<?php

use Phalcon\Mvc\Dispatcher as MvcDispatcher, Phalcon\Mvc\Dispatcher\Exception as DispatchException, Phalcon\Events\Manager as EventsManager;
include __DIR__ . '/../../../common/config/services.php';
error_reporting(7);
/* @var $di Phalcon\DI\FactoryDefault */
$di->setShared('router', function () {
    // 如果不使用默认的路由规则,请传入参数false
    // 此时必需完全匹配路由表,否则调用默认的index/index
    $router = new Phalcon\Mvc\Router();
    // 如果URL以/结尾,删除这个/
    $router->removeExtraSlashes(false);
    // use $_SERVER['REQUEST_URI'] (default)
    $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI);
    // Not Found Paths
    $router->notFound(['controller' => 'index', 'action' => 'show404']);
    $router->add('/', ['controller' => 'home', 'action' => 'index']);
    return $router;
});
/**
 * debug模式使用File存储,正式使用memcache,未来使用redis
 */
$di->setShared('cache', function () use($config) {
    // 默认15分钟
    $frontCache = new \Phalcon\Cache\Frontend\Data(["lifetime" => 900]);
    if ($config->debug) {
        return new \Phalcon\Cache\Backend\File($frontCache, ["cacheDir" => __DIR__ . "/../cache/"]);
    } else {
        return new \Phalcon\Cache\Backend\Redis($frontCache, ["host" => $config->redis->host, "port" => $config->redis->port, 'persistent' => $config->redis->persistent, "prefix" => $config->redis->prefix]);
    }
});
Ejemplo n.º 18
0
/**
* @author The Phuc
* @since  06/01/2016
*/
error_reporting(E_ALL);
try {
    /** Define */
    define('BASEURL', 'http://phalcon.dev/');
    define('CACHE_DATA_ADMIN', '../apps/common/caches/admin');
    define('CACHE_DATA_USERS', '../apps/common/caches/users');
    define('ADMIN_INFO', serialize(array('name' => 'Thế Phúc', 'email' => '*****@*****.**', 'mailHost' => 'smtp.gmail.com', 'mailPort' => 587, 'mailPassword' => '----')));
    /** The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */
    $di = new \Phalcon\DI\FactoryDefault();
    /** Registering a router */
    $di['router'] = function () {
        $router = new \Phalcon\Mvc\Router();
        $router->setDefaultModule('users');
        $router->setDefaultController('index');
        $router->setDefaultAction('index');
        $adminRoutes = glob(dirname(__DIR__) . "/apps/**/routes/*.php");
        foreach ($adminRoutes as $key => $value) {
            require_once $value;
        }
        $router->notFound(array('module' => 'users', 'controller' => 'error', 'action' => 'error404'));
        $router->removeExtraSlashes(true);
        return $router;
    };
    /** The URL component is used to generate all kind of urls in the application */
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/');
Ejemplo n.º 19
0
<?php

$router = new Phalcon\Mvc\Router(true);
$router->setDefaultModule("frontend");
$router->removeExtraSlashes(TRUE);
$router->add('/:controller/:action[/]{0,1}', array('module' => 'frontend', 'controller' => 1, 'action' => 2, 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/{language:[a-z]{2}}/:controller[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => "index", 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/{language:[a-z]{2}}/:controller/:action[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => 3, 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/{language:[a-z]{2}}/:controller/:action/:int[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => 3, 'uid' => 4, 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/', array('controller' => 'index', 'action' => 'index', 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/session/index/', array('controller' => 'session', 'action' => 'index', 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/session/start[/]{0,1}', array('controller' => 'session', 'action' => 'start', 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/session/logout[/]{0,1}', array('controller' => 'session', 'action' => 'logout', 'module' => 'frontend', 'namespace' => 'reportingtool\\Modules\\Modules\\Frontend\\Controllers'));
$router->add('/backend/{language:[a-z]{2}}/:controller[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => "index", 'module' => 'backend', 'namespace' => 'reportingtool\\Modules\\Modules\\Backend\\Controllers'));
$router->add('/backend/{language:[a-z]{2}}/:controller/:action[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => 3, 'module' => 'backend', 'namespace' => 'reportingtool\\Modules\\Modules\\Backend\\Controllers'));
$router->add('/backend/{language:[a-z]{2}}/:controller/:action/:int[/]{0,1}', array('language' => 1, 'controller' => 2, 'action' => 3, 'uid' => 4, 'module' => 'backend', 'namespace' => 'reportingtool\\Modules\\Modules\\Backend\\Controllers'));
$router->add('/backend', array('controller' => 'index', 'action' => 'index', 'module' => 'backend', 'namespace' => 'reportingtool\\Modules\\Modules\\Backend\\Controllers'));
$router->handle();
return $router;
Ejemplo n.º 20
0
<?php

/*
 * Define custom routes. File gets included in the router service definition.
 */
$router = new Phalcon\Mvc\Router();
$router->add('/restore-password', ['controller' => 'signin', 'action' => 'restorePassword']);
$router->add('/new-password', ['controller' => 'profile', 'action' => 'newPassword']);
$router->add('/change-password', ['controller' => 'profile', 'action' => 'changePassword']);
$router->add('/language/{language}', ['controller' => 'language', 'action' => 'index']);
$userManagement = new \Phalcon\Mvc\Router\Group(['controller' => 'usermanagement']);
$userManagement->setPrefix('/manage-users');
$userManagement->add('', ['action' => 'index']);
$userManagement->add('/email', ['action' => 'sendEmail']);
$router->mount($userManagement);
return $router;
Ejemplo n.º 21
0
<?php

$router = new Phalcon\Mvc\Router();
//Remove trailing slashes automatically
$router->removeExtraSlashes(true);
//SECURE ROUTES
$router->add('/login', 'Secure::login');
$router->addGet('/sign-up', 'Secure::signUp');
$router->addGet('/remind-password', 'Secure::remindPassword');
$router->addGet('/logout', 'Secure::logout');
$router->addPost('/register', 'Secure::register');
$router->add('/plates/{id}', 'Requests::plates');
//testing porpuses
$router->addGet('/test', 'Index::test');
//Requests section
$router->addGet('/requests', 'Requests::index');
$router->addGet('/requests/history', 'Requests::history');
$router->addPost('/requests/create', 'Requests::create');
$router->addPost('/requests/view/{id}', 'Requests::view');
$router->addGet('/requests/status/{id}/{id_status}', 'Requests::changeStatus');
//Cart
$router->addPost('/add-cart-item', 'Cart::add');
$router->addGet('/add-cart-item', 'Index::home');
$router->addGet('/cart', 'Cart::view');
$router->add('/cart-delete/{id}', 'Cart::delete');
$router->add('/delete-cart', 'Cart::deleteCart');
//Inbox section
$router->addGet('/inbox', 'Inbox::index');
//Reports section
$router->addGet('/reports', 'Reports::index');
$router->addGet('/reports/history', 'Reports::history');
Ejemplo n.º 22
0
<?php

// 如果不使用默认的路由规则,请传入参数false
// 此时必需完全匹配路由表,否则调用默认的index/index
$router = new Phalcon\Mvc\Router();
// 如果URL以/结尾,删除这个/
$router->removeExtraSlashes(false);
$router->add('/', ['controller' => 'home', 'action' => 'index']);
// Not Found Paths
$router->notFound(['controller' => 'index', 'action' => 'show404']);
return $router;
Ejemplo n.º 23
0
    $crypt = new \Phalcon\Crypt();
    $crypt->setKey($config->auth->cookie_hash);
    return $crypt;
});
$di->setShared('cookies', function () {
    $cookies = new \Phalcon\Http\Response\Cookies();
    return $cookies;
});
$di->setShared('session', function () {
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});
//Specify routes for modules
$di->setShared('router', function () use($config, $routers) {
    $router = new \Phalcon\Mvc\Router(false);
    $router->clear();
    $router->removeExtraSlashes(true);
    $router->clear();
    $router->setDefaultModule($config->app->defaultApp);
    $router->setDefaultController($config->app->defaultController);
    $router->setDefaultAction($config->app->defaultAction);
    if (!empty($routers)) {
        foreach ($routers as $name => $rule) {
            $pattern = $rule->pattern;
            unset($rule->pattern);
            $router->add($pattern, $rule->toArray())->setName($name);
        }
    }
    return $router;
});
Ejemplo n.º 24
0
<?php

$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    //Define a route
    $router->add('/login', array('controller' => 'member', 'action' => 'login'));
    $router->add('/logout', array('controller' => 'member', 'action' => 'logout'));
    $router->add('/signup', array('controller' => 'member', 'action' => 'signup'));
    $router->add('member', array('controller' => 'member', 'action' => 'page'));
    //Define admin route
    $router->add('/admin/:controller', array('controller' => 1, 'action' => 'admin_index'));
    $router->add('/admin/:controller/view/:params', array('controller' => 1, 'action' => 'admin_view', 'params' => 2));
    $router->add('/admin/:controller/add', array('controller' => 1, 'action' => 'admin_add'));
    $router->add('/admin/:controller/pending/:params', array('controller' => 1, 'action' => 'admin_pending', 'params' => 2));
    $router->add('/admin/login', array('controller' => 'user', 'action' => 'admin_login'));
    $router->add('/admin/logout', array('controller' => 'user', 'action' => 'admin_logout'));
    $router->add('/admin', array('controller' => 'user', 'action' => 'admin_login'));
    $router->add('/admin/:controller/login', array('controller' => 'user', 'action' => 'admin_login'));
    $router->add('/admin/user/login', array('controller' => 'user', 'action' => 'admin_login'));
    $router->add('/advertiser/login', array('controller' => 'member', 'action' => 'advertiser_login'));
    $router->add('/advertiser/signup', array('controller' => 'member', 'action' => 'advertiser_signup'));
    $router->add('/advertiser/emailConfimation/:params/:params/:params', array('controller' => 'member', 'action' => 'advertiser_emailConfimation', 'params' => 1, 'params' => 2, 'params' => 3));
    $router->add('/search', array('controller' => 'index', 'action' => 'search'));
    return $router;
});
Ejemplo n.º 25
0
/*
 +------------------------------------------------------------------------+
 | Phosphorum                                                             |
 +------------------------------------------------------------------------+
 | Copyright (c) 2013-2014 Phalcon Team and contributors                  |
 +------------------------------------------------------------------------+
 | This source file is subject to the New BSD License that is bundled     |
 | with this package in the file docs/LICENSE.txt.                        |
 |                                                                        |
 | If you did not receive a copy of the license and are unable to         |
 | obtain it through the world-wide-web, please send an email             |
 | to license@phalconphp.com so we can send you a copy immediately.       |
 +------------------------------------------------------------------------+
*/
$router = new Phalcon\Mvc\Router(false);
$router->add('/sitemap', array('controller' => 'sitemap', 'action' => 'index'));
$router->add('/help/stats', array('controller' => 'help', 'action' => 'stats'));
$router->add('/help/about', array('controller' => 'help', 'action' => 'about'));
$router->add('/help/moderators', array('controller' => 'help', 'action' => 'moderators'));
$router->add('/help/voting', array('controller' => 'help', 'action' => 'voting'));
$router->add('/help/markdown', array('controller' => 'help', 'action' => 'markdown'));
$router->add('/help/karma', array('controller' => 'help', 'action' => 'karma'));
$router->add('/help/badges', array('controller' => 'help', 'action' => 'badges'));
$router->add('/help/create-post', array('controller' => 'help', 'action' => 'create'));
$router->add('/help', array('controller' => 'help', 'action' => 'index'));
$router->add('/index.html', array('controller' => 'discussions', 'action' => 'index'));
$router->add('/discussions', array('controller' => 'discussions', 'action' => 'index'));
$router->add('/hook/mail-bounce', array('controller' => 'hooks', 'action' => 'mailBounce'));
$router->add('/hook/mail-reply', array('controller' => 'hooks', 'action' => 'mailReply'));
$router->add('/search', array('controller' => 'discussions', 'action' => 'search'));
Ejemplo n.º 26
0
 * Register config
 */
$di->setShared('config', $config);
/**
 * Registering a dispatcher
 */
$di->set('dispatcher', function () {
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('Tools\\Controllers');
    return $dispatcher;
});
/**
 * Register routers
 */
$di->setShared('router', function () use($config) {
    $router = new \Phalcon\Mvc\Router();
    $router->removeExtraSlashes(true);
    $router->setDefaults(array('namespace' => 'Tools\\Controllers', 'controller' => 'index', 'action' => 'index'));
    $router->add('/:controller/:action/:params', array('namespace' => 'Tools\\Controllers', 'controller' => 1, 'action' => 2, 'params' => 3));
    return $router;
});
/**
 *  Register assets that will be loaded in every page
 */
$di->setShared('assets', function () {
    $assets = new \Phalcon\Assets\Manager();
    $assets->collection('header-js')->addJs('js/jquery-1.11.3.min.js')->addJs('js/jquery-ui.min.js')->addJs('js/bootstrap.min.js')->addJs('js/mg.js');
    $assets->collection('header-css')->addCss('css/jquery-ui.min.css')->addCss('css/bootstrap.min.css')->addCss('css/style.css');
    return $assets;
});
/**
Ejemplo n.º 27
0
<?php

$router = new Phalcon\Mvc\Router(false);
$router->removeExtraSlashes(true);
$router->setDefaults(array('controller' => 'apireference', 'action' => 'index'));
$router->add('/error/404', array('controller' => 'error', 'action' => '_404'))->setName('404');
$router->notFound($router->getRouteByName('404')->getPaths());
// this only need to get URL to class reference by route name
$router->add('/{language:[A-Za-z]{2,2}}/{version:((\\d+\\.\\d+\\.\\d+)|latest)}/{class:(?i)phalcon(/[\\w/]+)?}', array('controller' => 'apireference', 'action' => 'showClass'))->setName('showClass');
// this only need to get URL by route name
$router->add('/{language:[A-Za-z]{2,2}}/{version:((\\d+\\.\\d+\\.\\d+)|latest)}/{type:(classes|namespaces|interfaces|changelog)}', array('controller' => 'apireference', 'action' => 'index'))->setName('showSummary');
$router->add('/?([A-Za-z]{2,2})?(/((\\d+\\.\\d+\\.\\d+)|latest))?(/(classes|namespaces|interfaces|changelog))?', array('controller' => 'apireference', 'action' => 'index', 'language' => 1, 'version' => 3, 'summary' => 6))->convert('language', function ($param) {
    return $param === 1 || !$param ? null : strtolower($param);
})->convert('version', function ($param) {
    return $param === 3 || !$param ? null : $param;
})->convert('summary', function ($param) {
    return $param === 6 || !$param ? 'classes' : $param;
});
$router->add('(/([A-Za-z]{2,2}))?(/((\\d+\\.\\d+\\.\\d+)|latest))?/((?i)phalcon(/[\\w/]+)?)', array('controller' => 'apireference', 'action' => 'showClass', 'language' => 2, 'version' => 4, 'class' => 6))->convert('language', function ($param) {
    return $param === 2 || !$param ? null : strtolower($param);
})->convert('version', function ($param) {
    return $param === 4 || !$param ? null : $param;
})->convert('class', function ($param) {
    return $param === 6 || !$param ? null : str_replace('/', '\\', strtolower($param));
});
return $router;
Ejemplo n.º 28
0
<?php

$router = new Phalcon\Mvc\Router(false);
$router->add('/:controller/:action/:params', array('namespace' => 'MyApp\\Controllers', 'controller' => 1, 'action' => 2, 'params' => 3));
$router->add('/:controller', array('namespace' => 'MyApp\\Controllers', 'controller' => 1));
$router->add('/admin/:controller/:action/:params', array('namespace' => 'MyApp\\Controllers\\Admin', 'controller' => 1, 'action' => 2, 'params' => 3));
$router->add('/admin/:controller', array('namespace' => 'MyApp\\Controllers\\Admin', 'controller' => 1));
return $router;
Ejemplo n.º 29
0
<?php

error_reporting(E_ALL);
try {
    /**
     * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
     */
    $di = new \Phalcon\DI\FactoryDefault();
    /**
     * Registering a router
     */
    $di['router'] = function () {
        $router = new \Phalcon\Mvc\Router(false);
        $router->add('/admin', array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
        $router->add('/index', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
        $router->add('/', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
        return $router;
    };
    /**
     * The URL component is used to generate all kind of urls in the application
     */
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/mvc/multiple-shared-layouts/');
        return $url;
    });
    /**
     * Start the session the first time some component request the session service
     */
    $di->set('session', function () {
        $session = new \Phalcon\Session\Adapter\Files();
Ejemplo n.º 30
-1
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(FOLDER_PROJECT . '/apps/library/', FOLDER_PROJECT . '/apps/backend/models', FOLDER_PROJECT . '/apps/frontend/models'))->register();
     //usando autoloader do composer para carregar as depêndencias instaladas via composer
     require_once FOLDER_PROJECT . 'vendor/autoload.php';
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add('/:controller/:action', array('module' => 'backend', 'controller' => 1, 'action' => 2));
         $router->add("/admin", array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/editor", array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/index/:action", array('controller' => 'index', 'action' => 1));
         return $router;
     });
     $di->set("libMail", function () {
         return new Multiple\Library\Mail();
     });
     /**
      * Caso exista o arquivo de configuração config.ini coleta os dados existentes nele e
      * conecta com o banco de dados
      */
     if (file_exists('../apps/config/config.ini')) {
         $config = new \Phalcon\Config\Adapter\Ini('../apps/config/config.ini');
         //Seta a conexão com o banco de dados
         $di->set('db', function () use($config) {
             $dbclass = 'Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter;
             return new $dbclass(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => 'utf8'));
         });
     }
     $this->setDI($di);
 }