Exemple #1
0
 /**
  * Set it up
  * @param unknown $id
  * @param string $module
  */
 public function __construct($id, $module = null)
 {
     parent::__construct($id, $module);
     $this->initController();
     $this->platform = new Platform();
     $this->m62->setService('platform', function ($c) {
         return $this->platform;
     });
     $this->m62->setDbConfig($this->platform->getDbCredentials());
     $this->settings = $this->services['settings']->get();
     $this->errors = $this->services['errors']->checkWorkingDirectory($this->settings['working_directory'])->checkStorageLocations($this->settings['storage_details'])->licenseCheck($this->settings['license_number'], $this->services['license'])->getErrors();
 }
Exemple #2
0
 /**
  * Handle
  *
  * @param Request $request Request
  *
  * @return void
  */
 public function handle(BaseController $class, array $variables)
 {
     $request = $class->getRequest();
     $user = \Craft\craft()->userSession->getUser();
     $is_authenticated = $this->isAuthenticated($request, $user);
     $this->validateRoute($request, $user, $is_authenticated);
     if ($request->getMethod() === 'GET' && !$request->getAttribute('elementType') && !$request->getAttribute('elementId') && !$request->getAttribute('action')) {
         $permissions = \Craft\craft()->restfulApi_config->getCompiledElementsPermissions($is_authenticated);
         return $class->actionShowPermissions($permissions);
     }
     if ($request->getAttribute('action')) {
         $method = 'action' . ucwords($request->getAttribute('action'));
         if (!method_exists($class, $method)) {
             $exception = new Exception();
             $exception->setStatus(404)->setMessage(sprintf('`%s` method of `%s` was not found.', $method, get_class($class)));
             throw $exception;
         }
         return $class->{$method}($variables);
     }
     if ($request->getMethod() === 'GET' && !$request->getAttribute('elementId')) {
         return $class->actionIndex($variables);
     }
     if ($request->getMethod() === 'GET' && $request->getAttribute('elementId')) {
         return $class->actionShow($variables);
     }
     if ($request->getMethod() === 'POST' && !$request->getAttribute('elementId')) {
         return $class->actionStore($variables);
     }
     if (in_array($request->getMethod(), ['PUT', 'PATCH']) && $request->getAttribute('elementId')) {
         return $class->actionUpdate($variables);
     }
     if ($request->getMethod() === 'DELETE' && $request->getAttribute('elementId')) {
         return $class->actionDelete($variables);
     }
     $exception = new Exception();
     $exception->setStatus(405)->setMessage(sprintf('`%s` method not allowed for resource `%s`.', $request->getMethod(), $request->getAttribute('elementType')));
     throw $exception;
 }