1. Go to this page and download the library: Download mattferris/application 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/ */
mattferris / application example snippets
use MattFerris\Application\Application;
use MattFerris\Di\Di;
// setup your application by adding components to it
$app = new Application(new Di(), [
'\MattFerris\Events\EventsComponent', // event handling
'\MattFerris\Http\Routing\HttpRoutingComponent' // HTTP request handling
]);
// then run it by passing a startup callable to run()
$app->run(['\MattFerris\Http\Routing\HttpRoutingComponent', 'run']);
namespace My\Project;
use MattFerris\Application\Component;
class MyProjectComponent extends Component
{
}
namespace My\Project;
use MattFerris\Provider\ProviderInterface;
class EventsProvider implements ProviderInterface
{
public function provides($consumer)
{
// register events, etc...
}
}
// provided by mattferris/bridge-components
use MattFerris\Bridge\Components\Di\DiComponent;
use MattFerris\Di\Di;
use MattFerris\Application\Application;
use My\Project\MyProjectComponent;
$app = new Application(new Di(), [
DiComponent::class,
MyProjectComponent::class
]);
namespace My\Project;
use MattFerris\Provider\ProviderInterface;
class ServicesProvider implements ProviderInterface
{
public function provides($consumer)
{
// $consumer will contain an instance of the service container
$container = $consumer;
// register a service
$container->set('MyProjectService', new MyProjectService());
}
}
namespace My\Project;
use MattFerris\Component\ComponentInterface;
use MattFerris\Provider\ProviderInterface;
class MyProjectComponent implements ComponentInterface, ProviderInterface
{
public function provides($consumer)
{
// $consumer will contain an instance of MattFerris\Application\Application
$consumer->addProvider('MyProjectType', MyProjectConsumer::class);
}
// ...
}