Example #1
0
 /**
  * {@inheritdoc}
  */
 public function checkPermission($operation, $resource = null)
 {
     $requestType = $this->request ? $this->request->getRequestorType() : ServiceRequestorTypes::API;
     Session::checkServicePermission($operation, $this->name, $resource, $requestType);
 }
Example #2
0
 /**
  * @param string $method
  * @param string $path
  * @param array  $payload
  * @param array  $curlOptions Additional CURL options for external requests
  *
  * @return array
  */
 public static function inlineRequest($method, $path, $payload = null, $curlOptions = [])
 {
     if (null === $payload || 'null' == $payload) {
         $payload = [];
     }
     if (!empty($curlOptions)) {
         $options = [];
         foreach ($curlOptions as $key => $value) {
             if (!is_numeric($key)) {
                 if (defined($key)) {
                     $options[constant($key)] = $value;
                 }
             }
         }
         $curlOptions = $options;
         unset($options);
     }
     try {
         if ('https:/' == ($protocol = substr($path, 0, 7)) || 'http://' == $protocol) {
             $result = static::externalRequest($method, $path, $payload, $curlOptions);
         } else {
             $result = null;
             $params = [];
             if (false !== ($pos = strpos($path, '?'))) {
                 $paramString = substr($path, $pos + 1);
                 if (!empty($paramString)) {
                     $pArray = explode('&', $paramString);
                     foreach ($pArray as $k => $p) {
                         if (!empty($p)) {
                             $tmp = explode('=', $p);
                             $name = ArrayUtils::get($tmp, 0, $k);
                             $value = ArrayUtils::get($tmp, 1);
                             $params[$name] = urldecode($value);
                         }
                     }
                 }
                 $path = substr($path, 0, $pos);
             }
             if (false === ($pos = strpos($path, '/'))) {
                 $serviceName = $path;
                 $resource = null;
             } else {
                 $serviceName = substr($path, 0, $pos);
                 $resource = substr($path, $pos + 1);
                 //	Fix removal of trailing slashes from resource
                 if (!empty($resource)) {
                     if (false === strpos($path, '?') && '/' === substr($path, strlen($path) - 1, 1) || '/' === substr($path, strpos($path, '?') - 1, 1)) {
                         $resource .= '/';
                     }
                 }
             }
             if (empty($serviceName)) {
                 return null;
             }
             $format = DataFormats::PHP_ARRAY;
             if (!is_array($payload)) {
                 $format = DataFormats::TEXT;
             }
             Session::checkServicePermission($method, $serviceName, $resource, ServiceRequestorTypes::SCRIPT);
             $request = new ScriptServiceRequest($method, $params);
             $request->setContent($payload, $format);
             //  Now set the request object and go...
             $service = ServiceHandler::getService($serviceName);
             $result = $service->handleRequest($request, $resource);
         }
     } catch (\Exception $ex) {
         $result = ResponseFactory::create($ex);
         Log::error('Exception: ' . $ex->getMessage(), ['response' => $result]);
     }
     return ResponseFactory::sendScriptResponse($result);
 }
 /**
  * @param string $operation
  * @param string $resource
  *
  * @return bool
  */
 public function checkPermission($operation, $resource = null)
 {
     $path = $this->getFullPathName();
     if (!empty($resource)) {
         $path = !empty($path) ? '/' . $resource : $resource;
     }
     $requestType = $this->request ? $this->request->getRequestorType() : ServiceRequestorTypes::API;
     Session::checkServicePermission($operation, $this->getServiceName(), $path, $requestType);
 }