1. Go to this page and download the library: Download raphhh/puppy-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/ */
raphhh / puppy-application example snippets
use Puppy\Application;
use Puppy\Config\Config;
use Symfony\Component\HttpFoundation\Request;
$puppy = new Application(new Config(), Request::createFromGlobals());
$puppy->get('hello', function(){
return 'Hello world!';
});
$puppy->run(); //good dog! :)
$puppy->get($uri, $controller); //filter on GET http method
$puppy->post($uri, $controller); //filter on POST http method
$puppy->json($uri, $controller); //filter on JSON format
$puppy->any($uri, $controller); //filter only on the requested uri
$puppy->filter($filter, $controller); //specific filter as callable
$puppy->get(':all', $controller); //every uri
$puppy->get(':home', $controller); //home uri (empty or '/')
$puppy->get(':slug', $controller); //string uri, with numeric, '_' and '-'
$puppy->get(':id', $controller); //any unsigned int, except 0
$puppy->get(':index', $controller); //any unsigned int
$puppy->get(':lang', $controller); //two letters lower case, eventually followed by hyphen and two letters upper case (e.i. fr-FR)
$puppy->get(':datetime', $controller); //datetime with format yyyy-mm-ddThh:mm:ss or yyyy-mm-ddThh:mm:ss+hh:ss
$puppy->get(':date', $controller); //date with format yyyy-mm-dd
$puppy->get(':time', $controller); //time with format hh:mm:ss
$puppy->mirror('mail', 'contact'); //request uri "mail" will point to "contact"
$puppy->mirror('mail/:id', 'contact/{id}');
$puppy->addService('serviceName', function(Container $services){
return new MyService();
});
$puppy->getService('myService');
$appController->getService('myService');
//you want the request?
$puppy->get('hello', function(Request $request){
...
});
//you want the request and the config?
$puppy->get('hello', function(Request $request, \ArrayAccess $config){
...
});
//you want the router and the appController?
$puppy->get('hello', function(Router $router, AppController $appController){
...
});
//your module class
class MyModule implements \Puppy\Module\IModule{
function init(\Puppy\Application $puppy){
$puppy->get('my-module/:all', function(){
return 'This is my module';
});
}
}
//add the module to the Application
$puppy->addModule(new MyModule());