1. Go to this page and download the library: Download phlogisticfugu/squirt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace MyApp;
use Monlog\Logger;
use GuzzleHttp\Client;
class App
{
private $logger;
private $client;
private $url;
public static function factory(array $params=array())
{
return new static($params);
}
protected function __construct(array $params)
{
/*
* Read in and validate all of our injected dependencies
* Note that the Squirt\Common\SquirtUtil class contains helper functions
* which can reduce the repetition below.
*/
if (isset($params['logger']) && ($params['logger'] instanceof Logger)) {
$this->logger = $params['logger'];
} else {
throw new \InvalidArgumentException('Invalid or missing logger');
}
if (isset($params['client']) && ($params['client'] instanceof Client)) {
$this->client = $params['client'];
} else {
throw new \InvalidArgumentException('Invalid or missing client');
}
if (! empty($params['url'])) {
$this->url = $params['url'];
} else {
throw new \InvalidArgumentException('Missing url');
}
}
public function run()
{
$response = $this->client->get($this->url);
$this->logger->info('Got result: ' . $response->getBody());
}
}
namespace MyApp;
use Monolog\Logger as MonologLogger;
use Monolog\Handler\StreamHandler;
class Logger extends MonologLogger
{
public static function factory(array $params=array())
{
$logFile = $params['logFile'];
$instance = new static();
$instance->pushHandler(new StreamHandler($logFile));
return $instance;
}
}
namespace MyApp;
use GuzzleHttp\Client;
class GuzzleClient extends Client
{
public static function factory(array $params=array())
{
return new static($params);
}
}
use Squirt\ServiceBuilder\SquirtServiceBuilder;
actory(array(
'fileName' => 'app_config.php'
));
// Note that only one service needs to be requested. All
use MyApp\App;
use MyApp\Logger;
use MyApp\GuzzleClient;
log/app.log'
));
$client = GuzzleClient::factory();
$app = App::factory(array(
'logger' => $logger,
'client' => $client,
'url' => 'https://github.com'
));
$app->run();
return array(
'g.php',
'database_config.php',
'production_logger_config.php'
),
'services' => array(
// service definitions which depend on services defined elsewhere
)
);