Más contenido relacionado La actualidad más candente (20) Similar a PHP pod mikroskopom (20) PHP pod mikroskopom6. Traits
class Base class MyHelloWorld
{ extends Base
public function sayHello()
{ {
echo 'Hello ';
}
use SayWorld;
} }
trait SayWorld
{
$o = new
public function sayHello()
{ MyHelloWorld();
parent::sayHello();
$o->sayHello();
echo 'World!';
}
}
8. Зашто?
Фрејмворк је обично:
● тешко оружје
● тежак за учење
10. HTTP протокол
GET /index.html HTTP/1.1
Host: www.example.com
HTTP/1.1 200 OK
Date: Mon, 23 May 2012 22:38:34 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Content-Type: text/html; charset=UTF-8
...
14. Silex
$app = new SilexApplication();
$app->get('/hello/{name}', function($name) {
return 'Hello '.$name;
});
$app->run();
15. Silex
$app->before(function() {
// пре обаде захтева
});
$app->after(function() {
// после обаде захтева
});
$app->finish(function() {
// после слања одговора
});
16. Silex
$app = new SilexApplication();
$app->error(function (Exception $e, $code) {
// руковање грешкама
});
18. Dependency Injection
class JsonUserPersister
{
private $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
public function persist(UserInterface $user)
{
$this->storage->store($user);
}
}
20. Pimple
$container = new Pimple();
$container['cookie_name'] = 'SESSION_ID';
$container['storage_class'] = 'SessionStorage';
$container['session_storage'] = function ($c) {
return new $c['storage_class']($c['cookie_name']);
};
$container['session'] = function ($c) {
return new Session($c['session_storage']);
};
23. Service Providers
$app = new SilexApplication();
$app->register(new UrlGeneratorServiceProvider());
…
$app['url_generator']->generate('home');
24. Service Providers
● Twig ● Security
● URL Generator ● Swiftmailer
● Session ● Monolog
● Validator ● Translation
● Form ● Doctrine
● HTTP Cache
25. Тестирање
class YourTest extends SilexWebTestCase
{
public function createApplication()
{
return require __DIR__.'/../../../app.php';
}
public function testFooBar()
{
// ...
}
}
26. Тестирање
public function testHomePage()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue($client->getResponse()->isOk());
$this->assertCount(
1,
$crawler->filter('h1:contains("Contact us")')
);
$this->assertCount(1, $crawler->filter('form'));
// ...
}
29. Twig
$app->get(
'/hello/{name}',
function ($name) use ($app) {
return $app['twig']->render(
'hello.twig',
array(
'name' => $name
));
}
);
32. Composer
{
"require": {
"silex/silex": "1.*"
}
}
35. Литература
● php.net
● sinatrarb.com
● silex.sensiolabs.org
● pimple.sensiolabs.org
● twig.sensiolabs.org
● getcomposer.org