Beispiel #1
0
 /**
  * Configures Honeybadger for the supplied Slim app for exception catching.
  *
  * @param   Slim    $app      The Slim app.
  * @param   array   $options  The config options.
  * @return  Config  The Honeybadger configuration.
  */
 protected static function init(\Slim\Slim $app, array $options = array())
 {
     if ($logger = $app->getLog()) {
         // Wrap the application logger.
         Honeybadger::$logger = new \Honeybadger\Logger\Slim($app->getLog());
     }
     // Add missing, detected options.
     $options = Arr::merge(array('environment_name' => $app->getMode(), 'framework' => sprintf('Slim: %s', \Slim\Slim::VERSION)), $options);
     // Create a new configuration with the merged options.
     Honeybadger::$config = new Config(Honeybadger::$config->merge($options));
 }
Beispiel #2
0
 public function __construct(Slim $slim)
 {
     $this->slim = $slim;
     if ($log = $slim->getLog()) {
         $this->originalLogWriter = $log->getWriter();
         $log->setWriter($this);
         $log->setEnabled(true);
     }
 }
Beispiel #3
0
 /**
  * @param object $endpoint
  * @param string $type
  * @param array  $params
  *
  * @throws Slim\Exception\Stop
  */
 private function _handleEndpointCall($endpoint, $type, array $params)
 {
     if ($endpoint instanceof SlimBootstrap\Endpoint\InjectClientId) {
         $endpoint->setClientId($this->_app->router()->getCurrentRoute()->getParam('clientId'));
     }
     try {
         $outputWriter =& $this->_hook->getResponseOutputWriter();
         if ($endpoint instanceof SlimBootstrap\Endpoint\ForceDefaultMimeType) {
             $csvConfig = array();
             if (true === \array_key_exists('csv', $this->_applicationConfig) && true === \is_array($this->_applicationConfig['csv'])) {
                 $csvConfig = $this->_applicationConfig['csv'];
             }
             // create output writer
             $responseOutputWriterFactory = new SlimBootstrap\ResponseOutputWriter\Factory($this->_app->request, $this->_app->response, $this->_app->response->headers, $this->_applicationConfig['shortName'], $csvConfig);
             $outputWriter = $responseOutputWriterFactory->create($endpoint->getDefaultMimeType());
         }
         if ($endpoint instanceof SlimBootstrap\Endpoint\Streamable) {
             if ($outputWriter instanceof SlimBootstrap\ResponseOutputWriterStreamable) {
                 $endpoint->setOutputWriter($outputWriter);
                 \ob_start();
                 $endpoint->{$type}($params, $this->_app->request->{$type}());
                 \ob_end_clean();
             } else {
                 throw new SlimBootstrap\Exception('media type does not support streaming', 406, Slim\Log::WARN);
             }
         } else {
             $data = $endpoint->{$type}($params, $this->_app->request->{$type}());
             if ($endpoint instanceof SlimBootstrap\Endpoint\PlainData) {
                 if ($outputWriter instanceof SlimBootstrap\ResponseOutputWriterPlainData) {
                     $outputWriter->writePlain($data);
                 } else {
                     throw new SlimBootstrap\Exception('media type does not support plain data writing', 406, Slim\Log::WARN);
                 }
             } else {
                 $outputWriter->write($data);
             }
         }
     } catch (SlimBootstrap\Exception $e) {
         $this->_app->getLog()->log($e->getLogLevel(), $e->getCode() . ' - ' . $e->getMessage());
         $this->_app->response->setStatus($e->getCode());
         $this->_app->response->setBody($e->getMessage());
         $this->_app->stop();
     }
 }
Beispiel #4
0
 public function responseStatus()
 {
     $this->_app->etag(md5($this->_app->response->getBody()));
     $this->_app->getLog()->debug('Response status: ' . $this->_app->response->getStatus());
 }
Beispiel #5
0
});
$app->get('/page/:page', function ($page = 1) use($app, $container) {
    $images = $container['imageService']->findAll();
    $paginator = $container['pagination']->newPaginator($images, $page, 10);
    $home = $page == 1 ? true : false;
    $app->render('index.html', array('paginator' => $paginator, 'pages' => $paginator->getPages(), 'home' => $home));
});
$app->get('/day/:day', function ($day) use($app, $container) {
    $image = $container['imageService']->find($day);
    if (!$image) {
        $app->notFound();
    }
    $app->render('day.html', $image);
})->conditions(array('day' => '([1-9]\\d?|[12]\\d\\d|3[0-5]\\d|36[0-6])'));
$app->post('/admin/clear-cache', function () use($app, $container) {
    $log = $app->getLog();
    $cleared = null;
    $clear = $app->request()->post('clear');
    if ($clear == 1) {
        if ($container['cache']->flush()) {
            $app->flash('cacheSuccess', 'Cache cleared.');
        } else {
            $app->flash('cacheFailure', 'Problem clearing cache!');
            $log->error('Cache not cleared');
        }
    }
    $app->redirect('/admin/settings');
});
$app->get('/admin(/page/:page)', function ($page = 1) use($app, $container) {
    $images = $container['imageService']->findAll();
    $paginator = $container['pagination']->newPaginator($images, $page, 25);
<?php

/**
 * Listen for teamspeak server events.
 */
require './vendor/autoload.php';
use Slim\Slim;
use SlackTeamspeakIntegration\EventWorker;
$app = new Slim();
$app->config('debug', false);
$eventWorker = new EventWorker($app->getLog());
$eventWorker->run();
Beispiel #7
0
<?php

require '../vendor/autoload.php';
use Slim\Slim;
use SlackTeamspeakIntegration\SlackTsNotifier;
$app = new Slim();
$app->config('debug', false);
/**
 * List TeamSpeak connected clients for custom slack slash commands
 * @see https://api.slack.com/slash-commands
 */
$app->post('/clients', function () use($app) {
    $channel = $app->request->post('channel_name');
    $slackTsNotifier = new SlackTsNotifier($app->getLog(), $channel);
    $slackTsNotifier->sendUserList();
});
$app->run();