예제 #1
0
 /**
  * Log in to Magister 6.
  * @param string $username - Magister 6 username.
  * @param string $password - Magister 6 password.
  * @return {MagisterAccount}
  * @throws {MagisterException}
  */
 public function login($school, $username, $password)
 {
     $rmi = Magister::getRMI();
     $rmi->setSchool($school);
     $current = $this->get('/api/sessies/huidige', [], true, false);
     if (isset($current->state) && $current->state == 'active') {
         return new Account($username);
     }
     $this->delete('/api/sessies/huidige', [], true, false);
     $results = $this->post('/api/sessies', [], ['Gebruikersnaam' => $username, 'Wachtwoord' => $password, 'IngelogdBlijven' => true], true, false);
     if (isset($results->message)) {
         throw new MagisterException($results->message);
     }
     if (isset($results->omschrijving)) {
         throw new MagisterException($results->omschrijving);
     }
     return new Account($username);
 }
 /**
  * Perform a HTTP request.
  * @param string $method - The HTTP method.
  * @param string $url - The URL to parse.
  * @param array $arguments - The arguments to replace in the URL.
  * @param object $data - An object representing what to send as JSON with
  * the request. Defaults to an empty object.
  * @param boolean $prependApi - Whether to prepend /api/personen/<id> to the
  * URL. Defaults to true.
  * @param boolean $newPrepend - Whether to to use /api/leerlingen/<id>
  * instead of /api/personen/<id> when using $prependApi. Defaults to false.
  * @return string|object
  */
 protected function request($method, $url, $arguments, $data = [], $parse = true, $prependApi = true, $newPrepend = false)
 {
     $rmi = Magister::getRMI();
     if ($prependApi) {
         $url = ($newPrepend ? '/api/leerlingen/' : '/api/personen/') . '/' . $rmi->getAccountId() . $url;
     }
     foreach ($arguments as $key => $value) {
         $url = str_replace(':' . $key, $value, $url);
     }
     $req = (new RawMagisterRequest())->setUrl($url)->setMethod($method);
     if ($method == 'POST' || $method == 'PUT') {
         $req->setBody(json_encode($data));
     }
     $response = $req->send();
     if ($parse) {
         return $response->getJson();
     }
     return $response->getBody();
 }
예제 #3
0
 /**
  * Bootstrap the given application.
  *
  * @param \Magister\Magister $app
  *
  * @return void
  */
 public function bootstrap(Magister $app)
 {
     $app->registerProviders();
 }
예제 #4
0
 /**
  * Bootstrap the application for http requests.
  *
  * @return void
  */
 public function bootstrap()
 {
     if (!$this->app->hasBeenBootstrapped()) {
         $this->app->bootstrapWith($this->bootstrappers());
     }
 }
예제 #5
0
 /**
  * Load a certain interface.
  * @param string $name - Name of the interface.
  * @return {MagisterInterface}
  */
 protected function loadInterface($name)
 {
     $class = Magister::loadClass('Interfaces/' . ucfirst($name));
     $object = new $class($this->rmi);
     $this->interfaces->{$name} = $object;
 }
예제 #6
0
 /**
  * Bootstrap the given application.
  *
  * @param \Magister\Magister $app
  *
  * @return void
  */
 public function bootstrap(Magister $app)
 {
     $loader = $app->getConfigLoader();
     $app->bind('config', new Repository($loader));
     mb_internal_encoding('UTF-8');
 }
예제 #7
0
 /**
  * Bootstrap the given application.
  *
  * @param \Magister\Magister $app
  *
  * @return void
  */
 public function bootstrap(Magister $app)
 {
     $app->boot();
 }
 /**
  * Send the request.
  * @return {RawMagisterResponse}
  */
 public function send()
 {
     $startTime = microtime(true);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'https://' . Magister::getRMI()->getSchool() . '.magister.net' . $this->url);
     curl_setopt($ch, CURLOPT_USERAGENT, Config::load()->connection_useragent);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_COOKIEJAR, Magister::getRMI()->getSessionFile());
     curl_setopt($ch, CURLOPT_COOKIEFILE, Magister::getRMI()->getSessionFile());
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::load()->connection_timeout_connect);
     curl_setopt($ch, CURLOPT_TIMEOUT, Config::load()->connection_timeout_total);
     switch ($this->method) {
         case 'GET':
             break;
         case 'POST':
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=UTF-8'));
             break;
         case 'PUT':
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
             curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=UTF-8'));
         case 'DELETE':
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
     }
     /* Wait for a bit to prevent the firewall from hating us. */
     usleep(Config::load()->connection_wait);
     /* Now download. */
     $responseBody = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new MagisterException('cURL Error (' . curl_errno($ch) . '): ' . curl_error($ch));
     }
     curl_close($ch);
     $response = new RawMagisterResponse($this->method, $this->url, $responseBody, $this->body);
     Magister::getRMI()->history[] = (object) array('url' => $this->url, 'method' => $this->method, 'startTime' => $startTime, 'endTime' => microtime(true), 'body' => $this->body, 'response' => $response);
     return $response;
 }
예제 #9
0
 /**
  * Register the application service providers.
  *
  * @param array $providers
  *
  * @return void
  */
 public function load(array $providers)
 {
     foreach ($providers as $provider) {
         $this->app->register($this->createProvider($provider));
     }
 }