Пример #1
0
 protected function createFileDriver($name)
 {
     $namespace = $this->config->getRequired("neptune.cache.{$name}.namespace");
     $dir = $this->config->get("neptune.cache.{$name}.dir", sys_get_temp_dir());
     if (substr($dir, 0, 1) !== '/') {
         $dir = $this->neptune->getRootDirectory() . $dir;
     }
     $driver = new FilesystemCache($dir);
     $driver->setNamespace($namespace);
     return $driver;
 }
Пример #2
0
 /**
  * Retorna a lista de todos as empresas cadastradas na Anvisa.
  *
  * @return array
  */
 public static function listarEmpresas()
 {
     $cacheDriver = new FilesystemCache(sys_get_temp_dir());
     $cacheDriver->setNamespace('hevertonfreitas_bulario_');
     $result = $cacheDriver->fetch('lista_empresas');
     if (empty($result)) {
         $listaEmpresas = file_get_contents('http://www.anvisa.gov.br/datavisa/fila_bula/funcoes/ajax.asp?opcao=getsuggestion&ptipo=2');
         $result = json_decode(utf8_encode($listaEmpresas));
         $cacheDriver->save('lista_empresas', $result);
     }
     return $result;
 }
Пример #3
0
    }
    return $router;
}), LoggerInterface::class => factory(function (ContainerInterface $c) {
    $logger = new Logger('main');
    $file = $c->get('directory.logs') . '/app.log';
    $logger->pushHandler(new StreamHandler($file, Logger::WARNING));
    return $logger;
}), Poser::class => object()->constructor(link(SvgFlatRender::class)), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    $twig->addExtension($c->get(PiwikTwigExtension::class));
    return $twig;
}), PiwikTwigExtension::class => object()->constructor(link('piwik.host'), link('piwik.site_id'), link('piwik.enabled')), Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('directory.cache') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'storage.repositories' => factory(function (ContainerInterface $c) {
    $backend = new StorageWithTransformers(new FileStorage($c->get('directory.data') . '/repositories.json'));
    $backend->addTransformer(new JsonEncoder(true));
    $storage = new MapWithTransformers(new MapAdapter($backend));
    $storage->addTransformer(new ObjectArrayMapper(Repository::class));
    return $storage;
}), 'storage.statistics' => factory(function (ContainerInterface $c) {
    $storage = new MapWithTransformers(new MultipleFileStorage($c->get('directory.data') . '/statistics'));
    $storage->addTransformer(new PhpSerializeEncoder());
    return $storage;
}), Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('directory.cache') . '/github';
    $client = new Client(new CachedHttpClient(['cache_dir' => $cacheDirectory]));
    $authToken = $c->get('github.auth_token');
Пример #4
0
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], Monolog\Logger::DEBUG));
    return $logger;
};
// Twig views
$container['view'] = function ($container) {
    $settings = $container->get('settings')['view'];
    $view = new \Slim\Views\Twig($settings['templates'], ['cache' => $settings['cache'], 'debug' => true]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], \nanotwi\Middleware\ProxiedHttpsSupport::getRealUri($container['request'])));
    $view->addExtension(new nanotwi\Views\TwigExtensionAutologinPath($container));
    return $view;
};
// Twig views
$container['cache'] = function ($container) {
    $settings = $container->get('settings')['cache'];
    $cache = new FilesystemCache($settings['path']);
    $cache->setNamespace('twitter_');
    return $cache;
};
// High-level Twitter API
$container['nanoTwitter'] = function ($container) {
    $settings = $container->get('settings')['twitter'];
    $cache = $container->get('cache');
    return new \nanotwi\NanoTwitter($settings, $cache);
};
// Twitter OAuth
$container['oAuthFlow'] = function ($container) {
    $settings = $container->get('settings')['twitter'];
    return new \nanotwi\OAuthFlow($settings['consumerKey'], $settings['consumerSecret']);
};
// Auto-login link
$container['autoLogin'] = function ($container) {
 /**
  * @return CacheInterface
  */
 protected function createDefinitionCache($config)
 {
     /** @var CacheInterface $cacheDriver */
     $cacheDriver = null;
     if ('production' == $this->env) {
         $cacheOptions = $config->options;
         switch ($config->type) {
             case 'redis':
                 $redis = new \Redis();
                 $redis->connect($cacheOptions->host, $cacheOptions->port);
                 /** @var RedisCache $cacheDriver */
                 $cacheDriver = new RedisCache();
                 $cacheDriver->setRedis($redis);
                 break;
             case 'memcached':
                 $memcached = new \Memcached();
                 $memcached->addServer($cacheOptions->host, $cacheOptions->port);
                 /** @var MemcachedCache $cacheDriver */
                 $cacheDriver = new MemcachedCache();
                 $cacheDriver->setMemcached($memcached);
                 break;
             case 'apcu':
                 $cacheDriver = new ApcuCache();
                 break;
             default:
                 $cacheDriver = new FilesystemCache(PIMCORE_CACHE_DIRECTORY);
         }
         $cacheDriver->setNamespace($config->namespace);
     }
     return $cacheDriver ? $cacheDriver : new ArrayCache();
 }