leopard-core is the core library for the Leopard Framework, providing essential features such as routing, attributes, dependency injection container, and other foundational components.
Install leopard-core using Composer:
composer require locky42/leopard-coreThe Container is a simple dependency injection container that allows you to register services and retrieve their instances.
use Leopard\Core\Container;
$container = new Container();
// Register a service
$container->set('logger', function () {
return new Logger();
});
// Retrieve the service
$logger = $container->get('logger');The Router allows you to define routes using attributes and handle HTTP requests.
use Leopard\Core\Router;
use Leopard\Core\Attributes\Route;
class TestController
{
#[Route('/test', method: 'GET')]
public function test(): string
{
return "Hello, world!";
}
}
$router = new Router();
$response = $router->dispatch('/test', 'GET');
echo $response; // Outputs "Hello, world!"leopard-core supports PHP attributes for defining routes and other metadata.
use Leopard\Core\Attributes\Route;
#[Route('/user/{id}', method: 'GET')]
public function getUser(string $id): string
{
return "User ID: $id";
}use Leopard\Core\Config;
$config = new Config();
$config->load(__DIR__ . '/config/app.yaml');
echo $config->get('database.host'); // Outputs 'localhost'To run tests, use the following command:
./run-tests.shThe tests are located in the vendor/locky42/leopard-core/tests directory.
This project is licensed under the MIT License.