* gredu_labs. * * @link https://github.com/eellak/gredu_labs for the canonical source repository * * @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html */ return function (App $app) { $container = $app->getContainer(); $events = $container['events']; $events('on', 'app.services', function ($c) { $c['in_numbers_get_totals_from_mm'] = function ($c) { $settings = $c['settings']; $httpClient = new GuzzleHttp\Client(['base_uri' => $settings['sch_mm']['api_url'], 'auth' => [$settings['sch_mm']['api_user'], $settings['sch_mm']['api_pass']]]); return function ($type) use($httpClient) { $config = $httpClient->getConfig(); $baseUri = $config['base_uri']; $auth = $config['auth']; $url = $baseUri->withQueryValue($baseUri, 'unit_type', $type); $url = $url->withQueryValue($url, 'pagesize', 1); $url = $url->withQueryValue($url, 'state', 1); $response = $httpClient->request('GET', $url, ['auth' => $auth]); $responseData = json_decode($response->getBody()->getContents(), true); return isset($responseData['total']) ? $responseData['total'] : null; }; }; $c['in_numbers_get_totals_from_mm'] = $c->extend('in_numbers_get_totals_from_mm', function ($fn, $c) { $settings = $c['settings']; $cacheFile = isset($settings['in_numbers']['cache']) ? $settings['in_numbers']['cache'] : false; $cacheLifetime = isset($settings['in_numbers']['cache_lifetime']) ? $settings['in_numbers']['cache_lifetime'] : false; if (!$cacheFile) {