1. Go to this page and download the library: Download kecik/dic 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/ */
kecik / dic example snippets
= array (
'libraries' => array (
'DIC' => array (
'enable' => TRUE
)
),
);
$app = new Kecik\Kecik($config);
class Test1 {
public function __construct() {
echo "Hello is Test1 <br />";
}
}
class Test2 {
public function __construct(Test1 $test) {
echo "Hello is Test2 <br />";
}
public function index() {
echo 'Is Index';
}
}
$app->container['Test1'] = function($c) {
return new Test1();
};
$app->container['Test2'] = function($c) {
return new Test2($c['Test1']);
};
$app->container['Test3'] = $app->container->factory(function($c) {
return new Test2($c['Test1']);
});
$app->get('/', function() use ($app){
$app->container['Test1'];
$app->container['Test2']->index();
});
$app->run();
namespace Controller;
use Kecik\Controller;
class Welcome extends Controller {
public function __construct() {
echo 'Hello is Welcome Controller';
}
}
namespace Controller;
use Kecik\Controller;
class Hello extends Controller {
public function __construct(Welcome $welcome) {
echo 'Hello is Hello Controller';
}
public function say($name) {
echo "Hello, $name";
}
}