1. Go to this page and download the library: Download twinkle/di 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 App\Services;
class HelloService
{
public function sayHello()
{
return 'hello';
}
}
namespace App\Controllers;
use App\Services\HelloService;
use Twinkle\DI\ServiceLocatorTrait;
/**
* Class HelloController
* @package App\Controllers
* @property HelloService $helloService
*/
class HelloController
{
use ServiceLocatorTrait;
public static function supportAutoNamespaces()
{
return [
'App\\Services',
'Twinkle\\Services'
];
}
public function indexAction()
{
echo $this->helloService->sayHello();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.