/** * Run module - this function should be called by Resto.php * * @param array $segments : route segments * @param array $data : POST or PUT parameters * * @return string : result from run process in the $context->outputFormat */ public function run($segments, $data = array()) { if (!$this->context) { RestoLogUtil::httpError(500, 'Invalid Context'); } /* * Set POST data from resto */ $this->data = $data; /* * Authentication issuer is identified as the first $elements */ $issuerId = isset($segments[0]) ? RestoUtil::sanitize($segments[0]) : null; /* * Get provider */ $provider = $this->getProvider($issuerId); /* * Authenticate from input protocol */ switch ($provider['protocol']) { case 'oauth2': return $this->oauth2($issuerId, $provider); default: RestoLogUtil::httpError(400, 'Unknown sso protocol for issuer "' . $issuerId . '"'); } }
public function test() { $this->initContext(); $this->assertEquals(false, RestoUtil::UUIDv5('toto', 'toto')); $this->assertEquals('tototototiti', RestoUtil::superImplode('toto', array('toto', 'titi', null))); $this->assertEquals('http://localhost/titi/toto/tata.format?huhu=tty.json', RestoUtil::updateUrlFormat('http://localhost/titi/toto/tata?huhu=tty.json', 'format')); $this->assertEquals('http://localhost/tata.format?huhu=tty.json', RestoUtil::updateUrlFormat('http://localhost/tata.json?huhu=tty.json', 'format')); $this->assertEquals('1977-01-01T00:00:00Z', RestoUtil::toISO8601('1977')); $this->assertEquals('1977-02-01T00:00:00Z', RestoUtil::toISO8601('1977-02')); $this->assertEquals('1977-02-10T00:00:00Z', RestoUtil::toISO8601('1977-02-10')); $this->assertEquals('1977-02-10T12:11:30Z', RestoUtil::toISO8601('1977-02-10T12:11:30Z')); $this->assertEquals(array('toto', 'titi', 'tata', 'tet', ' tifi ', 'cdd'), RestoUtil::splitString('toto"titi"tata tet" tifi "cdd')); $this->assertEquals(false, RestoUtil::isUrl(null)); $this->assertEquals(false, RestoUtil::isUrl('tokijhfomqzcdna')); $this->assertEquals(true, RestoUtil::isUrl('http://tititit.com/foiherfoh')); $this->assertEquals(null, RestoUtil::sanitize(null)); $this->assertEquals(array('tototot', 'tydsnc'), RestoUtil::sanitize(array('tototot', 'tydsnc'))); $this->assertEquals('ogfdrhefvdjsncosd', RestoUtil::sanitize('ogfdrhefvdjsncosd')); $this->assertEquals('', RestoUtil::kvpsToQueryString('ogfdrhefvdjsncosd')); $this->assertEquals('?&toto=ttiti&frfr=trtr', RestoUtil::kvpsToQueryString(array('toto' => 'ttiti', 'frfr' => 'trtr'))); $this->assertEquals('?&toto=ttiti&frfr=trtr&arr[]=titi&arr[]=toto', RestoUtil::kvpsToQueryString(array('toto' => 'ttiti', 'frfr' => 'trtr', 'arr' => array('toto', 'titi')))); $this->assertEquals(array('totot_tiiti_titi' => ''), RestoUtil::queryStringToKvps('totot tiiti titi')); }
/** * Set query parameters from input */ private function setQuery() { /* * Aggregate input parameters * * Note: PUT is handled by RestoUtil::readInputData() function */ $query = array(); switch ($this->method) { case 'GET': case 'DELETE': case 'POST': $query = RestoUtil::sanitize($_GET); break; default: break; } /* * Remove unwanted parameters */ if (isset($query['RESToURL'])) { unset($query['RESToURL']); } /* * Trim all values and remove empty values */ foreach ($query as $key => $value) { $query[$key] = trim($value); if ($query[$key] === '') { unset($query[$key]); } } $this->query = $query; }