PHP Classes

File: src/dependencies.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Chronicle   src/dependencies.php   Download  
File: src/dependencies.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change: Optional feature: Cache responses for a very short period of time.

This will allow us to serve a lot more requests per second.
Type safety
Date: 1 year ago
Size: 1,368 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
Cache\Adapter\Memcached\MemcachedCachePool;
use
Slim\Container;
// DIC configuration

if (!isset($app)) {
    throw new
Error('Variable $app is not defined');
}
if (!(
$app instanceof \Slim\App)) {
    throw new
Error('Variable $app is not an App');
}

/** @var Container $container */
$container = $app->getContainer();

// view renderer
$container['renderer'] = function (Container $c): \Slim\Views\PhpRenderer {
   
/** @var array<string, array> $cset */
   
$cset = $c->get('settings');
   
/** @var array<string, string> $settings */
   
$settings = $cset['renderer'];
    return new
Slim\Views\PhpRenderer($settings['template_path']);
};

// monolog
$container['logger'] = function (Container $c): \Monolog\Logger {

   
/** @var array<string, array> $cset */
   
$cset = $c->get('settings');
   
/** @var array<string, string> $settings */
   
$settings = $cset['logger'];
   
$logger = new Monolog\Logger((string)$settings['name']);
   
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
   
$logger->pushHandler(
        new
Monolog\Handler\StreamHandler(
           
$settings['path'],
            (int)
$settings['level']
        )
    );
    return
$logger;
};

// easydb
$container['database'] = function (Container $c): \ParagonIE\EasyDB\EasyDB {
    return \
ParagonIE\Chronicle\Chronicle::getDatabase();
};