Example #1
0
 /**
  * @param $action    string
  * @param $params    array
  * @param $route_key string
  */
 public function action($action, $params = array(), $route_key = '')
 {
     if (!in_array($action, $this->whitelisted_actions) && !$this->isAuthenticated()) {
         throw new \OperaCore\Exception\Forbidden('Enter username and password to continue.');
     }
     parent::action($action, $params, $route_key = '');
 }
Example #2
0
File: index.php Project: ezrra/PHP
<?php

session_start();
$_SESSION['user'] = array();
$_SESSION['user']['name'] = 'Carlos';
require 'User.php';
require 'Coffee.php';
class Controller
{
    public function action()
    {
        $user = new User($_SESSION['user']);
        $coffe = new Coffee();
        $message = $user->drink($coffe);
        echo $message;
    }
}
$controller = new Controller();
$controller->action();
Example #3
0
<?php

require 'User.php';
require 'Coffee.php';
require 'AuthenticationService.php';
require 'CoffeeMaker.php';
require 'BarTender.php';
interface BeverageMaker
{
    public function make();
}
class Controller
{
    private $auth;
    public function __construct(AuthenticationService $auth)
    {
        $this->auth = $auth;
    }
    public function action(BeverageMaker $beverageMake)
    {
        $user = $this->auth->user();
        $beverage = $beverageMake->make();
        $message = $user->drink($beverage);
        require 'view.php';
    }
}
$auth = new AuthenticationService(['name' => 'Yoel']);
$controller = new Controller($auth);
$controller->action(new BarTender());
Example #4
0
 protected static function parseQuery($query)
 {
     if (!ConfigValue::get('AdminInstalled', false) && !in_array($query, array('admin/pre_install', 'admin/check_install', 'admin/install'))) {
         $query = 'admin/pre_install';
     }
     if (!empty($query)) {
         $terms = explode('/', $query);
     } else {
         $terms = array();
     }
     //We want to now what a parameter was, even if it's empty, so don't filter
     //$terms = array_filter($terms);
     self::$area = count($terms) ? array_shift($terms) : ConfigValue::get('DefaultController', 'home');
     if (count($terms)) {
         self::$action = array_shift($terms);
     } else {
         if (Component::isActive(class_name(self::$area))) {
             self::$action = ConfigValue::get('Default' . class_name(self::$area) . 'Action', ConfigValue::get('DefaultAction', 'index'));
         } else {
             self::$action = ConfigValue::get('DefaultAction', 'index');
         }
     }
     self::$parameters = !empty($terms) ? $terms : array();
     if (Component::isActive(class_name(self::$area)) && method_exists(class_name(self::$area), 'checkParameters')) {
         self::$parameters = call_user_func(array(class_name(self::$area), 'checkParameters'), self::$parameters);
     }
     return self::$parameters;
 }