1. Go to this page and download the library: Download pmieleszkiewicz/chevrotain 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/ */
pmieleszkiewicz / chevrotain example snippets
// LoggerInterface.php
interface LoggerInterface
{
public function log(string $message);
}
// EchoLogger.php
class EchoLogger implements LoggerInterface
{
public function log(string $message)
{
echo $message;
}
}
// UserService.php
class UserService
{
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function log(string $message)
{
$this->logger->log(sprintf("[%s] %s", date('Y-m-d H:i:s'), $message));
}
}
declare(strict_types=1);
use App\Services\UserService;
use App\Loggers\EchoLogger;
use App\Loggers\LoggerInterface;
use PMieleszkiewicz\Chevrotain\Container;
use PMieleszkiewicz\Chevrotain\Exceptions\ContainerException;
log('It works!');
} catch (ContainerException $e) {
// handle exception
}
// Output
[2020-12-21 01:00:04] It works!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.