Exemple #1
0
 public function testPassingConcreteDependency()
 {
     $simpleClass = new SimpleClass();
     $simpleClass->foo = "bar";
     $object = $this->container->instance(OneDependency::class, $simpleClass);
     $this->assertEquals("bar", $object->injected->foo);
 }
Exemple #2
0
 /**
  * @return static
  */
 public static function getProvider()
 {
     if (!self::$defaultSet) {
         self::setProviderClassName(CurlHttpClient::class);
         self::$defaultSet = true;
     }
     return Container::instance(static::class);
 }
Exemple #3
0
 public function testEmailSends()
 {
     // Note this test only confirms the email has made it to the provider.
     $email = Container::instance(SimpleEmail::class);
     $email->addRecipientsByEmail("*****@*****.**")->SetText("This is a test email");
     SendableProvider::selectProviderAndSend($email);
     $lastEmail = UnitTestingEmailProvider::getLastEmail();
     $this->assertEquals($email, $lastEmail);
 }
 public static function enableExceptionTrapping()
 {
     /**
      * @var ExceptionSettings $exceptionSettings
      */
     $exceptionSettings = ExceptionSettings::singleton();
     $exceptionSettings->exceptionTrappingOn = true;
     ini_set("display_errors", false);
     // Register the exception handler. Not that this is only to catch exceptions that happen
     // outside of the normal Module response generation pipeline which should be very rare.
     set_exception_handler($exceptionHandler = function ($er) {
         // Upscale non core exceptions to RhubarbExceptions (via NonRhubarbException)
         if (!$er instanceof RhubarbException) {
             $er = new NonRhubarbException($er);
         }
         // Dispatch the exception to the handler.
         /**
          * @var ExceptionHandler $handler
          */
         $handler = Container::instance(ExceptionHandler::class);
         $response = $handler->processException($er);
         $response->send();
     });
     // Register the default php error handler to convert errors to exceptions.
     set_error_handler(function ($code, $message, $file, $line) {
         $reportingLevel = error_reporting();
         // If errors are turned off or they are being suppressed with an '@' we don't do anything with
         // them. This is to allow for optimistic auto loading in the Module class.
         if ($reportingLevel == 0) {
             return;
         }
         throw new ErrorException($message, 0, $code, $file, $line);
     });
     // Make sure we handle fatal errors too.
     register_shutdown_function(function () use($exceptionHandler) {
         /**
          * @var ExceptionSettings $exceptionSettings
          */
         $exceptionSettings = ExceptionSettings::singleton();
         if ($exceptionSettings->exceptionTrappingOn) {
             $error = error_get_last();
             if ($error != null) {
                 // Ensure we're in the project root directory, as some webservers (e.g. apache) can change
                 // the working directory during shutdown.
                 chdir(__DIR__ . '/../../../../../../');
                 if (!file_exists("shutdown_logs")) {
                     @mkdir("shutdown_logs");
                 }
                 @file_put_contents('shutdown_logs/' . date("Y-m-d_H-i-s") . '.txt', "Type: {$error["type"]}\n" . "Message: {$error["message"]}\n" . "File: {$error["file"]}\n" . "Line: {$error["line"]}\n\n", FILE_APPEND);
             }
             if ($error != null && ($error["type"] == E_ERROR || $error["type"] == E_COMPILE_ERROR)) {
                 $exceptionHandler(new ErrorException($error["message"], 0, $error["type"], $error["file"], $error["line"]));
             }
         }
     });
 }
 public function extractSessionData()
 {
     $data = parent::extractSessionData();
     $encrypted = [];
     $keySalt = $this->getEncryptionKeySalt();
     $provider = Container::instance(EncryptionProvider::class);
     foreach ($data as $key => $value) {
         if (is_object($value) || is_array($value)) {
             continue;
         }
         $encrypted[$key] = $provider->encrypt($value, $keySalt);
     }
     return $encrypted;
 }
Exemple #6
0
 /**
  * Returns a new instance of the session provider used to store this session.
  *
  * Override this to replace the default behaviour of using the default provider class.
  *
  * @return SessionProviders\SessionProvider
  */
 protected function getNewSessionProvider()
 {
     return Container::instance(SessionProvider::class);
 }