-
Notifications
You must be signed in to change notification settings - Fork 0
Dependency Container
John Aldrich Bernardo edited this page May 13, 2018
·
2 revisions
Saddle is the dependecy container for Calf.
<?php
require_once('vendor/autoload.php');
// Create a new Saddle (Dependency Injector)
$container = new \Calf\Saddle();
// Test message for our Saddle
$container->message = 'Hello World';
// More examples for our Saddle
$container->products = [
'supplies' => ['Pen'],
'fruits' => ['Apple', 'Pineapple']
];
$container->getProducts = function(\Calf\Saddle $c) {
return $c->products;
};
// Let's instantiate our application
$app = new \Calf\App($container);
?><?php
// Products Service Route Group
$products = new \Calf\HTTP\RouteGroup('products');
$products->add(
// Test using url:
// {host}/products/get
new \Calf\HTTP\Route('/get', function(\Calf\HTTP\Request $req, \Calf\HTTP\Response $res, array $args = []) {
$res->write($this->getProducts);
return $res;
}, ['GET'])
);The calf is open-sourced software licensed under the MIT license.