Пример #1
0
 public function register(Application $app)
 {
     $app->set("Filesystem", function ($name = null, $configs = []) use($app) {
         $name = $name ?: $app->getConfig('filesystem.default');
         $filesystemManager = new FilesystemManager($app);
         return $filesystemManager->load($name, $configs);
     });
 }
Пример #2
0
 public function register(Application $app)
 {
     $app->set("Database", function ($database = null) use($app) {
         $isDevMode = $app->getConfig('app.settings.environment') == 'development' ?: false;
         $database = $database ?: $app->getConfig('db.default');
         $databaseConfig = $app->getConfig("db.connections.{$database}");
         $doctrineConfig = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/../app/Models"), $isDevMode);
         return EntityManager::create($databaseConfig, $doctrineConfig);
     });
 }
Пример #3
0
 public function register(Application $app)
 {
     $whoops = new \Whoops\Run();
     $whoops->allowQuit(false);
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $handler->setPageTitle("Whoops! There was a problem.");
     $whoops->pushHandler($handler);
     $whoops->register();
     $app->set('Whoops', $whoops);
 }
Пример #4
0
 public function register(Application $app)
 {
     $app->set("View", function ($baseDir = null) use($app) {
         $baseDir = $baseDir ?: APP_PATH . 'views';
         $plates = new \League\Plates\Engine();
         $plates->loadExtension(new URI($app->Request->getPathInfo()));
         $plates->setDirectory($baseDir);
         return $plates;
     });
 }
Пример #5
0
 /**
  * Get a filesystem instance.
  *
  * @param  string  $name
  * @return \League\Flysystem\AdapterInterface
  */
 private function resolveAdapter($name, $configs)
 {
     try {
         $adatperClass = $this->app->get('\\TitaPHP\\Filesystem\\' . ucfirst($name) . 'Adapter');
     } catch (NotFoundException $e) {
         throw new \Exception("Filesystem driver {$name} could not be located");
     }
     $adapter = $adatperClass->adapt($configs);
     if (!$adapter instanceof \League\Flysystem\AdapterInterface) {
         throw new \Exception('Adapter must be instance of \\League\\Flysystem\\AdapterInterface');
     }
     return $adapter;
 }
Пример #6
0
 public function handle(EventInterface $event)
 {
     $logger = Application::instance()->get('Logger');
     $log = new Log();
     $log->log = $logger->getLogString();
     $log->created_at = date('Y-m-d H:i:s');
     $log->save();
 }
Пример #7
0
 /**
  * returns a string with currency formatted accordingly to locale settings
  * @param string $value
  * @param string $decimals
  * @param string $currencyCode
  * @return string
  */
 public static function currency($value, $decimals = 2, $currencyCode = null)
 {
     $app = Application::instance();
     $currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
     $nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
     $nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
     return $nf->formatCurrency($value, $currencyCode);
 }
Пример #8
0
 public function handle(EventInterface $event)
 {
     $app = Application::instance();
     // TODO: render 404 error template
     // TODO: log request url?
     $responseStr = '<h2>Page not found!</h2>';
     $response = $app->get('Response');
     $response->setContent($responseStr);
     $response->setStatusCode(404);
 }
Пример #9
0
 /**
  * Initialize Application.
  *
  * @return void
  */
 protected function init()
 {
     parent::init();
     $this->router = $this->container->get('Router');
     $this->router->addRoutes($this->getConfig('routes'));
     $session = $this->container->get('Session');
     $session->start();
     // load providers
     $this->loadProviders($this->getConfig('http.providers'));
     // load events
     $this->loadEvents($this->getConfig('http.events'));
 }
Пример #10
0
 public function handle(EventInterface $event)
 {
     $app = Application::instance();
     $log = $app->get('Logger')->getLogString();
     if ($log !== '') {
         $filePath = 'logs/' . date('Y_m') . '.txt';
         $fileSystem = $app->get('Filesystem');
         if ($fileSystem->has($filePath)) {
             $log .= $fileSystem->read($filePath);
         }
         $fileSystem->put($filePath, $log);
     }
 }
Пример #11
0
 public function handle(EventInterface $event, $errorNum = null, $e = null)
 {
     $app = Application::instance();
     $app->get('Logger')->fatal(PHP_EOL . $e->getMessage() . PHP_EOL . $e->getTraceAsString());
     if ($app->environment === 'development') {
         $app->get('Whoops')->handleException($e);
     } else {
         // TODO: render a error template
         $responseStr = "<h2>Exception:</h2> <p>" . $e->getMessage() . '</p><p>' . $e->getTraceAsString() . '</p>';
         $response = $app->get('Response');
         $response->setContent($responseStr);
         $response->setStatusCode(500);
     }
 }
Пример #12
0
 public function register(Application $app)
 {
     $app->set("Mail.send", function ($to, $subject, $body, $attachments = array(), $replyTo = "", $from = "", $fromName = "") use($app) {
         $config = $app->getConfig('mail.' . $app->environment);
         $from = !empty($from) ? $from : $config['from'];
         $fromName = !empty($fromName) ? $fromName : $config['fromName'];
         $replyTo = !empty($replyTo) ? $replyTo : $config['replyTo'];
         // Create the SMTP configuration
         $transport = \Swift_SmtpTransport::newInstance($config['server'], $config['port']);
         $transport->setUsername($config['username']);
         $transport->setPassword($config['password']);
         // Create the message
         $message = \Swift_Message::newInstance();
         $message->setTo($to);
         $message->setSubject($subject);
         $message->setBody($body);
         $message->setFrom($from, $fromName);
         $message->addReplyTo($replyTo);
         // Send the email
         $mailer = \Swift_Mailer::newInstance($transport);
         $mailer->send($message);
     });
 }
Пример #13
0
 public function register(Application $app)
 {
     // boot Eloquent
     $defaultConn = $app->getConfig('db.default');
     $capsule = new Capsule();
     $capsule->addConnection($app->getConfig("db.connections.{$defaultConn}"));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     $capsule->connection();
     // register Database in container
     $app->set("Database", function ($name = null) use($app) {
         $name = $name ?: $app->getConfig('db.default');
         $config = $app->getConfig("db.connections.{$name}");
         $capsule = new Capsule();
         $capsule->addConnection($config, $name);
         return $capsule->getConnection($name);
     });
 }