getContent() public static méthode

Returns the request body content.
public static getContent ( boolean $asResource = false ) : string | resource
$asResource boolean If true, a resource will be returned
Résultat string | resource The request body content or a resource to read the body stream
Exemple #1
1
 /** 
  * @param Request $request
  */
 protected function updateHeaders($request)
 {
     $content = $request->getContent();
     $contentLength = strlen($content);
     $request->addHeader('Content-Length: ' . $contentLength);
     $request->addHeader('Content-Type: application/xml;charset=UTF-8');
 }
Exemple #2
0
 /**
  * Create a new job based on the PUT parameters given and content-type.
  */
 public static function createJob($uri)
 {
     list($collection_uri, $name) = self::getParts($uri);
     // Retrieve the parameters of the PUT requests (either a JSON document or a key=value string)
     $params = \Request::getContent();
     // Is the body passed as JSON, if not try getting the request parameters from the uri
     if (!empty($params)) {
         $params = json_decode($params, true);
     } else {
         $params = \Input::all();
     }
     // If we get empty params, then something went wrong
     if (empty($params)) {
         \App::abort(400, "The parameters could not be parsed from the body or request URI, make sure parameters are provided and if they are correct (e.g. correct JSON).");
     }
     // Validate the job properties
     $job_params = self::validateParameters('Job', 'job', $params);
     // Retrieve the collection uri and resource name
     $matches = array();
     // Check which parts are set for validation purposes
     $extract = @$params['extract'];
     $map = @$params['map'];
     $load = @$params['load'];
     $publisher = @$params['publish'];
     // Check for every emlp part if the type is supported
     $extractor = self::validateType(@$extract, 'extract');
     $mapper = self::validateType(@$map, 'map');
     $loader = self::validateType(@$load, 'load');
     $publisher = self::validateType(@$publisher, 'publish');
     // Save the emlp models
     $extractor->save();
     $loader->save();
     if (!empty($mapper)) {
         $mapper->save();
     }
     if (!empty($publisher)) {
         $publisher->save();
     }
     // Create the job associated with emlp relations
     $job = new \Job();
     $job->collection_uri = $collection_uri;
     $job->name = $name;
     // Add the validated job params
     foreach ($job_params as $key => $value) {
         $job->{$key} = $value;
     }
     $job->extractor_id = $extractor->id;
     $job->extractor_type = self::getClass($extractor);
     $job->mapper_id = @$mapper->id;
     $job->mapper_type = self::getClass($mapper);
     $job->loader_id = $loader->id;
     $job->loader_type = self::getClass($loader);
     $job->publisher_id = @$publisher->id;
     $job->publisher_type = self::getClass($publisher);
     $job->save();
     $response = \Response::make(null, 200);
     $response->header('Location', \Request::getHost() . '/' . $uri);
     return $response;
 }
 public function receiveLabRequest()
 {
     //authenticate() connection
     $labRequest = Request::getContent();
     $labRequest = str_replace(['labRequest', '='], ['', ''], $labRequest);
     //Validate::ifValid()
     //Fire event with the received data
     Event::fire('api.receivedLabRequest', json_decode($labRequest));
 }
Exemple #4
0
 protected function prepare(Request $request)
 {
     if (strpos($request->headers->get('Content-Type'), 'application/json') === 0) {
         $data = json_decode($request->getContent(), true);
         $request->request->replace(is_array($data) ? $data : array());
     } else {
         throw new BadRequestException('Content-Type header of the request is not supported');
     }
 }
 /**
  * Post Ping function - Handle Auto from Atlas Module 2.0
  *
  */
 public function autoPostModule()
 {
     $requestContent = Request::getContent();
     Log::debug("DATA received: " . $requestContent);
     $json = json_decode($requestContent, true);
     Log::info('Module uuid: ' . $json['id']);
     $authorizedModule = $this->authService->getAuthourizedModule($json['id']);
     $json['atlas_id'] = $authorizedModule->atlas_id;
     $markerSite = MarkerSiteBuilder::buildForModule($json);
     $markerSite->save();
     Log::debug("Updated " . $markerSite->id . " from " . $_SERVER['REMOTE_ADDR']);
     $this->auditService->auditModuleSite($markerSite, $json['id']);
     return 'SUCCES';
 }
 /**
  * @return Response
  *
  * @throws BadResponseException
  */
 protected function process(Request $request)
 {
     $headerStr = [];
     foreach ($request->getHeaders() as $name => $value) {
         foreach ((array) $value as $v) {
             $headerStr[] = "{$name}: {$v}";
         }
     }
     $options = ['http' => ['method' => $request->getMethod(), 'header' => implode("\r\n", $headerStr) . "\r\n", 'follow_location' => 0, 'protocol_version' => 1.1, 'ignore_errors' => TRUE], 'ssl' => ['verify_peer' => TRUE, 'cafile' => realpath(__DIR__ . '/../../ca-chain.crt'), 'disable_compression' => TRUE]];
     if (($content = $request->getContent()) !== NULL) {
         $options['http']['content'] = $content;
     }
     if ($this->sslOptions) {
         $options['ssl'] = $this->sslOptions + $options['ssl'];
     }
     list($code, $headers, $content) = $this->fileGetContents($request->getUrl(), $options);
     return new Response($code, $headers, $content);
 }
 public function authModule()
 {
     $json = json_decode(Request::getContent(), true);
     $module = $json['token'];
     $site = $json['site'];
     Log::info('Auth module request: ');
     Log::info('Site: ' . $site);
     Log::info('Module: ' . $module);
     $privileges = DB::table('auth')->where('token', '=', $module)->count();
     if ($privileges > 0) {
         App::abort(400, 'This module is allready linked to a site');
     }
     $isAllreadyLinked = DB::table('auth')->where('atlas_id', '=', $site)->where('principal', 'like', '%module:%')->count();
     if ($isAllreadyLinked > 0) {
         App::abort(400, 'This site is allready linked to a module');
     }
     DB::table('auth')->insert(array('atlas_id' => $site, 'principal' => 'module:' . $module, 'token' => $module, 'privileges' => 'STATS'));
     Log::debug("Created auth");
 }
 /**
  * Post Ping function - Handle Ping from Atlas Module 2.0
  * Never Used and deprecated
  */
 public function pingPostModule()
 {
     $this->createTableIfNotPresent();
     Log::debug("DATA received: " . Request::getContent());
     $json = json_decode(Request::getContent(), true);
     $date = new \DateTime();
     $module = $json['id'];
     Log::info('Module uuid: ' . $module);
     $siteM = DB::table('auth')->where('token', '=', $module)->first();
     if ($siteM == NULL) {
         App::abort(403, 'Unauthorized');
     }
     $param = array('id' => $siteM->atlas_id, 'patients' => intval($json['patients']), 'encounters' => intval($json['encounters']), 'observations' => intval($json['observations']), 'atlas_version' => $json['atlasVersion'], 'date_created' => $date);
     $site = DB::table('atlas')->where('id', '=', $param['id'])->first();
     if ($site != null) {
         DB::table('archive')->insert(array('archive_date' => $date, 'site_uuid' => $site->id, 'id' => Uuid::uuid4()->toString(), 'action' => 'UPDATE', 'type' => $site->type, 'longitude' => $site->longitude, 'latitude' => $site->latitude, 'name' => $site->name, 'url' => $site->url, 'image' => $site->image, 'contact' => $site->contact, 'changed_by' => 'module:' . $_SERVER['REMOTE_ADDR'], 'patients' => $site->patients, 'encounters' => $site->encounters, 'observations' => $site->observations, 'openmrs_version' => $openmrs_version, 'notes' => $site->notes, 'email' => $site->email, 'data' => $site->data, 'show_counts' => $site->show_counts, 'atlas_version' => $site->atlas_version, 'date_created' => $site->date_created));
         unset($param['date_created']);
         DB::table('atlas')->where('id', '=', $site->id)->update($param);
         Log::debug("Updated " . $param['id'] . " from " . $_SERVER['REMOTE_ADDR']);
     } else {
         Log::debug("Site not found: " . $param['id'] . " from " . $_SERVER['REMOTE_ADDR']);
     }
     return 'SUCCES';
 }
Exemple #9
0
<?php

define('__ROOT__', dirname(__FILE__));
require_once __ROOT__ . "/webready/controller.php";
require_once __ROOT__ . "/webready/request.php";
require_once __ROOT__ . "/webready/view.php";
$css = array("/style/style.css");
$js = array();
$request = new Request();
var_dump($request->getPath());
echo "<br />";
var_dump($request->getMethod());
echo "<br />";
echo json_encode($request->getContent());
Exemple #10
0
 /**
  * Edit a job
  *
  * @return \Response
  */
 private function editJob()
 {
     $uri = $this->getUri();
     $job = $this->get($uri);
     $config = \Request::getContent();
     $config = json_decode($config, true);
     if (empty($job)) {
         return \Redirect::to('api/admin/jobs');
     }
     // Validate the job properties
     $job_params = $this->validateParameters('Job', 'job', $config);
     // Retrieve the collection uri and resource name
     $matches = array();
     // Check which parts are set for validation purposes
     $extract = @$config['extract'];
     $load = @$config['load'];
     // Check for every ETL part if the type is supported
     $extractor = $this->getClassOfType(@$extract, 'Extract');
     $loader = $this->getClassOfType(@$load, 'Load');
     $job->extractor()->delete();
     $job->loader()->delete();
     $extractor->save();
     $loader->save();
     // Add the validated job params
     foreach ($job_params as $key => $value) {
         $job->{$key} = $value;
     }
     $job->extractor_id = $extractor->id;
     $job->extractor_type = $this->getClass($extractor);
     $job->loader_id = $loader->id;
     $job->loader_type = $this->getClass($loader);
     $job->save();
     // If the job is scheduled once, push the job to the queue
     if ($job->schedule == 'once' && !$job->added_to_queue) {
         $job_name = $job->collection_uri . '/' . $job->name;
         \Queue::push(function ($queued_job) use($job_name) {
             \Artisan::call('input:execute', ['jobname' => $job_name]);
             $queued_job->delete();
         });
         $job->added_to_queue = true;
         $job->save();
     }
     return \Response::make([], 200);
 }
 /**
  * Handle Post Ping from Atlas Server
  *
  */
 public function pingAtlas()
 {
     $this->createTable();
     $user = Session::get(user);
     $date = new \DateTime();
     Log::debug("DATA received: " . Request::getContent());
     $json = json_decode(Request::getContent(), true);
     $id['id'] = $json['uuid'] != '' ? $json['uuid'] : Uuid::uuid4()->toString();
     $param = array('id' => $id['id'], 'latitude' => floatval($json['latitude']), 'longitude' => floatval($json['longitude']), 'name' => $json['name'], 'url' => $json['url'], 'patients' => intval($json['patients']), 'encounters' => intval($json['encounters']), 'observations' => intval($json['observations']), 'type' => $json['type'], 'image' => $json['image'], 'contact' => $json['contact'], 'email' => $json['email'], 'notes' => $json['notes'], 'date_created' => $date, 'openmrs_version' => $json['version'], 'show_counts' => intval($json['show_counts']), 'created_by' => $user->principal, 'distribution' => intval($json['distribution']));
     $param['patients'] = is_int($param['patients']) ? $param['patients'] : '';
     $param['encounters'] = is_int($param['encounters']) ? $param['encounters'] : '';
     $param['observations'] = is_int($param['observations']) ? $param['observations'] : '';
     $privileges = DB::table('auth')->where('token', '=', $user->uid)->where('atlas_id', '=', $param['id'])->where('privileges', '=', 'ALL')->first();
     if ($user->role == 'ADMIN' && $privileges == NULL) {
         $privileges = new Privileges(array('token' => $user->uid, 'principal' => 'admin:' . $user->uid, 'privileges' => 'ADMIN'));
     }
     Log::debug("Privileges: " . $privileges->principal . "/" . $privileges->privileges);
     $site = DB::table('atlas')->where('id', '=', $param['id'])->first();
     if ($site != null) {
         DB::table('archive')->insert(array('site_uuid' => $site->id, 'id' => Uuid::uuid4()->toString(), 'archive_date' => $date, 'type' => $site->type, 'longitude' => $site->longitude, 'latitude' => $site->latitude, 'name' => $site->name, 'url' => $site->url, 'image' => $site->image, 'contact' => $site->contact, 'changed_by' => $privileges->principal, 'patients' => $site->patients, 'encounters' => $site->encounters, 'observations' => $site->observations, 'notes' => $site->notes, 'action' => 'UPDATE', 'email' => $site->email, 'show_counts' => $site->show_counts, 'data' => $site->data, 'openmrs_version' => $site->openmrs_version, 'atlas_version' => $site->atlas_version, 'date_created' => $site->date_created, 'show_counts' => $site->show_counts, 'created_by' => $site->created_by, 'distribution' => $site->distribution));
         unset($param['created_by']);
         unset($param['date_created']);
         DB::table('atlas')->where('id', '=', $site->id)->update($param);
         Log::debug("Updated " . $param['id'] . " from " . $_SERVER['REMOTE_ADDR']);
     } else {
         // new implementation
         DB::table('atlas')->insert($param);
         //insert into archive
         $param['action'] = "ADD";
         $param['site_uuid'] = Uuid::uuid4()->toString();
         $param['archive_date'] = $date;
         DB::table('archive')->insert($param);
         Log::debug("Created " . $param['id'] . " from " . $_SERVER['REMOTE_ADDR']);
         $principal = 'openmrs_id:' . $user->uid;
         $auth = DB::table('auth')->where('atlas_id', '=', $param['id'])->where('principal', '=', $principal)->first();
         if ($auth == NULL) {
             DB::table('auth')->insert(array('atlas_id' => $param['id'], 'principal' => $principal, 'token' => $user->uid, 'privileges' => 'ALL'));
             Log::debug("Created auth");
         }
         if (Session::has('module')) {
             // Add module authoritation if marker created in module
             $module = Session::get('module');
             Log::info('Module create a marker');
             Log::info('Module UUID: ' . $module);
             $privileges = DB::table('auth')->where('token', '=', $module)->count();
             if ($privileges > 0) {
                 log::info('This module is allready linked to a site');
             } else {
                 DB::table('auth')->insert(array('atlas_id' => $param['id'], 'principal' => 'module:' . $module, 'token' => $module, 'privileges' => 'STATS'));
                 Log::debug("Created auth for module");
             }
         }
     }
     return $param['id'];
 }
 /**
  * @Security("has_role('ROLE_USER')")
  * @Route("/troops/{id}/affect-role", name="affect_troop_role", methods={"PUT"})
  */
 public function affectRoleAction(Troop $troop, Request $request)
 {
     $data = json_decode($request->getContent(), true);
     if ($this->get('kilix_abac.security')->enforce('troop_leadership', $this->getUser(), $troop, ['dynamic_attributes' => ['troop-id' => $troop->getId()]]) !== true) {
         throw new AccessDeniedHttpException('troops.access_denied');
     }
     try {
         $translator = $this->get('translator');
         $association = $this->get('medievistes.troop_manager')->affectRole($troop, (int) $data['role_id'], (int) $data['member_id']);
         return new JsonResponse(['message' => $translator->trans('troops.associations.affectation_success', ['%username%' => $association->getUser()->getUsername(), '%role_label%' => $association->getRole() !== null ? $association->getRole()->getLabel() : $translator->trans('troops.roles.unassigned_members')])]);
     } catch (\Exception $ex) {
         return new JsonResponse(['errors' => [['message' => $ex->getMessage()]]], 400);
     }
 }
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('greeting', ['REQUEST_URI' => Request::url()]);
});
Route::any('test', function () {
    return Input::all();
});
Route::group(['prefix' => 'api'], function () {
    Route::any('{uri?}', function ($uri = null) {
        $cmd = 'rsserial -j ';
        parse_str(Request::getContent(), $param);
        $reqStr = json_encode(array('method' => Request::method(), 'parameter' => array_merge($param, Input::all()), 'path' => $uri == null ? [] : explode('/', $uri)));
        $qStr = json_encode(array('request' => $reqStr, 'ver' => '0001'));
        $qStr = str_replace("\\", "\\\\", $qStr);
        $qStr = '"' . str_replace("\"", "\\\"", $qStr) . '"';
        return response(shell_exec($cmd . $qStr))->header('Content-Type', "application/json");
    })->where(['uri' => '.*']);
});
Route::group(['prefix' => 'widget'], function () {
    Route::any('{uri?}', function ($uri = null) {
        $cmd = 'rsserial -j ';
        $reqStr = json_encode(array('method' => 'GET', 'parameter' => array(), 'path' => array('widget_registry')));
        $qStr = json_encode(array('request' => $reqStr, 'ver' => '0001'));
        $qStr = str_replace("\\", "\\\\", $qStr);
        $qStr = '"' . str_replace("\"", "\\\"", $qStr) . '"';
        $rtn = json_decode(shell_exec($cmd . $qStr), true);
Exemple #14
0
 /**
  * Retrieve the input of the request and lowercase all of the keys
  *
  * @return array
  */
 private function fetchInput()
 {
     // Retrieve the parameters of the PUT requests (either a JSON document or a key=value string)
     $input = \Request::getContent();
     // Is the body passed as JSON, if not try getting the request parameters from the uri
     if (!empty($input)) {
         $input = json_decode($input, true);
     } else {
         $input = \Input::all();
     }
     // If input is empty, then something went wrong
     if (empty($input)) {
         \App::abort(400, "The parameters could not be parsed from the body or request URI, make sure parameters are provided and if they are correct (e.g. correct JSON).");
     }
     // Change all of the parameters to lowercase
     $input = array_change_key_case($input);
     return $input;
 }
    $user = Session::get(user);
    if ($user->role !== 'ADMIN') {
        return Redirect::home();
    }
});
Route::filter('module', function () {
    if (!Input::has('uuid')) {
        App::abort(500, 'Missing Parameter');
    }
    if (strlen(Input::get('uuid')) < 30) {
        App::abort(500, 'Invalid parameters');
    }
});
Route::when('module/*', 'module', array('GET', 'DELETE'));
Route::filter('module-auth', function () {
    $json = json_decode(Request::getContent(), true);
    if ($json == NULL) {
        App::abort(400, 'Missing data');
    }
    if (!is_array($json)) {
        App::abort(400, 'Unable to parse data');
    }
    if (!array_key_exists('token', $json)) {
        App::abort(400, 'Missing module token');
    }
    if (!array_key_exists('site', $json)) {
        App::abort(400, 'Missing site uuid');
    }
    if ($json['token'] != Session::get('module')) {
        App::abort(400, 'Module and token mismatch');
    }
 public function action(Request $request)
 {
     $app = $this->serializer->deserialize($request->getContent());
     return Dto\App\AppCreationResponse::createFromServerApp($this->serverAppCreator->createServerApp($app));
 }
 public function getContent()
 {
     return $this->getParam('content', \Request::getContent());
 }
 public function anyTest()
 {
     try {
         if (!($data = Input::get('data'))) {
             if (!($data = \Request::getContent())) {
                 return false;
             }
         }
         if (empty($data)) {
             return false;
         }
         $data = json_decode($data, true);
         $data['softwareAgent_id'] = strtolower($data['softwareAgent_id']);
         try {
             $this->createPostSoftwareAgent($data);
         } catch (Exception $e) {
             return serialize([$e->getMessage()]);
         }
         try {
             $activity = new Activity();
             $activity->softwareAgent_id = $data['softwareAgent_id'];
             $activity->save();
         } catch (Exception $e) {
             // Something went wrong with creating the Activity
             $activity->forceDelete();
             return serialize([$e->getMessage()]);
         }
         $entity = new Entity();
         $entity->format = 'image';
         $entity->domain = $data['domain'];
         $entity->tags = $data['tags'];
         $entity->documentType = $data['documentType'];
         $entity->softwareAgent_configuration = $data['softwareAgent_configuration'];
         if (isset($data['parents'])) {
             $entity->parents = $data['parents'];
         }
         $entity->content = $data['content'];
         if (isset($data['threshold'])) {
             $entity->threshold = $data['threshold'];
         }
         if (isset($data['relevantFeatures'])) {
             $entity->recognizedFeatures = $data['relevantFeatures'];
         }
         if (isset($data['hash'])) {
             $entity->hash = $data['hash'];
         } else {
             $entity->hash = md5(serialize($data['content']));
         }
         $entity->activity_id = $activity->_id;
         if (Entity::where('hash', $entity->hash)->first()) {
             //dd('asdasd');
         } else {
             $entity->save();
         }
         return Response::json($entity);
     } catch (Exception $e) {
         dd($e->getMessage());
     }
 }