/**
  * Return the lock instance to work on.
  *
  * @return \BeatSwitch\Lock\Callers\CallerLock|\BeatSwitch\Lock\Roles\RoleLock
  * @throws \Exception
  */
 protected function lock()
 {
     if ($this->subject == 'user') {
         return $this->manager->caller($this->user);
     } elseif ($this->subject == 'role') {
         return $this->manager->role($this->role);
     } else {
         throw new \Exception("Caller not allowed: {$this->subject}");
     }
 }
Beispiel #2
0
 public function __construct()
 {
     // Prepare
     parent::__construct();
     $manager = new Manager(new ArrayDriver());
     $this->__lock = $manager->caller(new Path());
     $this->__lock->deny('all');
     // REST
     $this->middleware(function ($middlewares) {
         if (isset($_POST['_METHOD'])) {
             $_SERVER['REQUEST_METHOD'] = strtoupper($_POST['_METHOD']);
             unset($_POST['_METHOD']);
         }
         $middlewares->next();
     });
     // Return allowed files
     $this->middleware(function ($middlewares) {
         $path = $this->_formatPath($this['request']->getResourceUri());
         if (file_exists($path) && is_file($path) && $this->__lock->can($this->_formatPath($path))) {
             // Get mime type
             $mime = mimetype($path);
             // Try some more extensions
             if ($mime == 'text/plain') {
                 if (strpos($path, '.css')) {
                     $mime = 'text/css';
                 }
                 if (strpos($path, '.js')) {
                     $mime = 'application/javascript';
                 }
                 if (strpos($path, '.json')) {
                     $mime = 'application/json';
                 }
             }
             // Set content type
             if ($mime != 'text/plain') {
                 header('Content-Type: ' . $mime);
             }
             // Print file
             echo file_get_contents($path);
             exit;
         }
         $middlewares->next();
     });
 }
 /**
  * @return \BeatSwitch\Lock\Callers\CallerLock
  */
 protected function getCallerLock()
 {
     return $this->manager->caller($this->caller);
 }