SlideShare a Scribd company logo
1 of 32
Download to read offline
Application Layer
ein Vortrag von Per Bernhardt
Agenda
• Disclaimer / Credits
• Ein kleines bisschen Theorie
• Ein echtes Beispiel: Chefkoch API
Credit goes to…
• http://martinfowler.com/
• http://domainlanguage.com/
• http://alistair.cockburn.us/
• http://www.whitewashing.de/
• und viele andere..
Ein bisschen
Theorie…
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
- Fasade
- Transaktionen
- Sicherheit / Zugriffsschutz
- Integration / Orchestrierung
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
- Fasade
- Transaktionen
- Sicherheit / Zugriffsschutz
- Integration / Orchestrierung
- Daten
- Geschäftslogik
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
- Fasade
- Transaktionen
- Sicherheit / Zugriffsschutz
- Integration / Orchestrierung
- Daten
- Geschäftslogik
- Datenbank
- Mailserver
- Logger
- …
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
- Fasade
- Transaktionen
- Sicherheit / Zugriffsschutz
- Integration / Orchestrierung
- Daten
- Geschäftslogik
- Datenbank
- Mailserver
- Logger
- …
Application Layer
Presentation Layer
Infrastructure Layer
Domain Layer
- Controller
- Template / HTML
- Session / HTTP
- Fasade
- Transaktionen
- Sicherheit / Zugriffsschutz
- Integration / Orchestrierung
- Daten
- Geschäftslogik
- Datenbank
- Mailserver
- Logger
- …
Chefkoch API
POST /cookbooks/{id}/categories
<?php
!
namespace ChefkochBundleApiBundleController;
!
use SymfonyBundleFrameworkBundleControllerController;
use ChefkochDomainModelCookbookCookbookId
use SensioBundleFrameworkExtraBundleConfigurationParamConverter;
use ChefkochBundleApiBundleAnnotationApiSerialize;
use ChefkochApplicationCookbookRequest;
use ChefkochApplicationCookbookCommand;
use PixelhouseApplicationEventDispatchingService;
use PixelhouseApplicationResponse;
!
class CookbookController extends Controller
{
!
...
!
/**
* @ParamConverter("category", options={"deserialize"=true})
* @ApiSerialize
* @return Response
*/
public function saveCategoryAction(CookbookId $cookbookId, RequestCategoryRequest $category)
{
return $this->getCookbookService()->execute(
new CommandSaveCategoryCommand($cookbookId, $category)
);
}
!
...
!
/**
* @return DispatchingService
*/
private function getCookbookService()
{
return $this->get('chefkoch_api.application.cookbook_service');
}
}
<?php
!
namespace ChefkochApplicationCookbookCommand;
!
use ChefkochApplicationCookbookRequestCategoryRequest;
use ChefkochApplicationCookbookSecurityCookbookWriteAccessRequired;
use ChefkochDomainModelCookbookCookbookId;
use PixelhouseApplicationCommand;
!
class SaveCategoryCommand implements Command, CookbookWriteAccessRequired
{
!
/** @var CookbookId */
private $cookbookId;
!
/** @var CategoryRequest */
private $categoryRequest;
!
public function __construct(CookbookId $cookbookId, CategoryRequest $categoryRequest)
{
$this->cookbookId = $cookbookId;
$this->categoryRequest = $categoryRequest;
}
!
public function getCookbookId()
{
return $this->cookbookId;
}
!
public function getCategoryRequest()
{
return $this->categoryRequest;
}
}
<?php
!
namespace PixelhouseApplicationEvent;
!
use PixelhouseApplicationCommand;
use PixelhouseApplicationUseCase;
use PixelhouseEventDispatcherEventDispatcher;
!
class DispatchingService
{
!
/** @var EventDispatcher */
private $eventDispatcher;
!
/** @var UseCase[] */
private $useCases = array();
!
public function __construct(EventDispatcher $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
!
public function registerCommand($commandClass, UseCase $useCase)
{
$this->useCases[$commandClass] = $useCase;
}
!
public function execute(Command $command)
{
...
}
}
<?php
!
namespace PixelhouseApplicationEvent;
!
class Events
{
const PRE_COMMAND = 'application.pre_command';
const POST_COMMAND = 'application.post_command';
const EXCEPTION = 'application.exception';
}
<?php
!
namespace PixelhouseApplicationEvent;
!
use PixelhouseApplicationCommand;
!
class DispatchingService
{
!
...
!
public function execute(Command $command)
{
try {
$this->eventDispatcher->dispatch(
Events::PRE_COMMAND,
new CommandEvent($command)
);
$response = $this->useCases[get_class($command)]->run($command);
$this->eventDispatcher->dispatch(
Events::POST_COMMAND,
new PostCommandEvent($command, $response)
);
!
return $response;
} catch (Exception $exception) {
$event = new CommandExceptionEvent($command, $exception);
$this->eventDispatcher->dispatch(
Events::EXCEPTION,
$event
);
if ($response = $event->getResponse()) {
return $response;
} else {
throw $exception;
}
}
}
}
<?php
!
namespace ChefkochInfrastructureApplication;
!
use PixelhouseApplicationEvent;
use PixelhouseEventDispatcherSubscriber;
use DoctrineORMEntityManager;
!
class DoctrineTransactionListener implements Subscriber
{
!
/** @var EntityManager */
private $entityManager;
!
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
!
public function preCommand(EventCommandEvent $event)
{
$this->entityManager->getConnection()->beginTransaction();
}
!
public function postCommand(EventPostCommandEvent $event)
{
$this->entityManager->flush();
$this->entityManager->getConnection()->commit();
}
!
public function onException(EventCommandExceptionEvent $event)
{
$this->entityManager->close();
if ($this->entityManager->getConnection()->isTransactionActive()) {
$this->entityManager->getConnection()->rollBack();
}
}
}
<?php
!
namespace PixelhouseApplicationSecurity;
!
use PixelhouseApplicationEvent;
use PixelhouseEventDispatcherSubscriber;
!
class SecurityListener implements Subscriber
{
!
/** @var Context */
private $context;
!
/** @var Policy[] */
private $policies = array();
!
public function __construct(Context $context)
{
$this->context = $context;
}
!
public function addPolicy(Policy $policy)
{
$this->policies[] = $policy;
}
!
/**
* throws Exception
*/
public function preCommand(EventCommandEvent $event)
{
foreach ($this->policies as $policy) {
$policy->check($this->securityContext, $event->getCommand());
}
}
}
<?php
!
namespace ChefkochApplicationCookbookSecurity;
!
use ChefkochDomainModelCookbookCookbookRepository;
use ChefkochUserDomainModelUserRepository;
use PixelhouseApplicationCommand;
use PixelhouseApplicationSecurityAccessDeniedException;
use PixelhouseApplicationSecurityContext;
use PixelhouseApplicationSecurityPolicy;
!
class CookbookAccessPolicy implements Policy
{
!
/** @var CookbookRepository */
private $cookbookRepository;
!
/** @var UserRepository */
private $userRepository;
!
public function __construct(CookbookRepository $cbRepo, UserRepository $uRepo)
{
$this->cookbookRepository = $cbRepo;
$this->userRepository = $uRepo;
}
!
public function check(Context $context, Command $command)
{
if ($command instanceof CookbookWriteAccessRequired) {
$cookbook = $this->cookbookRepository->findOneById($command->getCookbookId());
$user = $this->userRepository->findOneById($context->getUserId());
!
// Zugriff prüfen
...
!
throw new AccessDeniedException();
}
}
}
<?xml version="1.0" ?>
<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services ...">
<services>
...
!
<service
id="chefkoch_api.application.use_case.cookbook_save_category"
class="ChefkochApplicationCookbookUseCaseSaveCategory">
<argument
type="service"
id="chefkoch_api.infrastructure.cookbook_category_repository" />
<argument
type="service"
id="chefkoch_api.infrastructure.user_repository" />
<argument
type="service"
id="chefkoch_api.application.security_context" />
<tag
name="chefkoch_api.application.use_case"
commandClass="ChefkochApplicationCookbookCommandSaveCategoryCommand"
applicationService="chefkoch_api.application.cookbook_service" />
</service>
!
...
</services>
</container>
<?php
!
namespace ChefkochApplicationCookbookUseCase;
!
use ChefkochApplicationCookbookCommandSaveCategoryCommand;
use PixelhouseApplicationSecurityContext;
use PixelhouseApplicationUseCase;
use ChefkochDomainModelCookbookCategoryRepository;
use ChefkochUserDomainModelUserRepository;
!
class SaveCategory implements UseCase
{
!
/** @var CategoryRepository */
private $categoryRepository;
!
/** @var UserRepository */
private $userRepository;
!
/** @var Context */
private $context;
!
public function __construct(CategoryRepository $cRepo, UserRepository $uRepo, Context $context)
{
$this->categoryRepository = $cRepo;
$this->userRepository = $uRepo;
$this->context = $context;
}
!
public function run(SaveCategoryCommand $command)
{
...
}
}
<?php
!
namespace ChefkochApplicationCookbookUseCase;
!
use PixelhouseApplicationUseCase;
use ChefkochApplicationCookbookCommandSaveCategoryCommand;
use ChefkochDomainModelCookbookCategory;
use ChefkochApplicationCookbookNotificationCategorySavedSuccess;
use ChefkochApplicationCookbookResponseCategoryResponse;
use PixelhouseApplicationResponse;
!
class SaveCategory implements UseCase
{
...
!
public function run(SaveCategoryCommand $command)
{
$user = $this->userRepository->findOneById($this->context->getUserId());
!
$category = new Category(
$command->getCookbookId(),
$user->getId(),
$command->getCategoryRequest()->getName(),
$command->getCategoryRequest()->getDescriptionText()
);
!
$this->categoryRepository->add($category);
!
$categoryResponse = new CategoryResponse($category, $user);
!
$response = new Response();
$response->getNotification()->addMessage(new CategorySavedSuccess($categoryResponse));
!
return $response;
}
}
HTTP/1.1 201 Created
Per Bernhardt
info@perprogramming.de
perprogramming.de
slideshare.net/perprogramming
Bilder
• Warning: https://www.flickr.com/photos/gerardstolk/
6538330609
• Show Time: https://www.flickr.com/photos/
florida_photo_guy/5212663826
• Question Marks: https://www.flickr.com/photos/
loneblackrider/315302588
• Thank You: https://www.flickr.com/photos/wwworks/
4759535950

More Related Content

What's hot

AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 

What's hot (20)

AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
Composer
ComposerComposer
Composer
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first class
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
V2 and beyond
V2 and beyondV2 and beyond
V2 and beyond
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
Wykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w LaraveluWykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w Laravelu
 
Phinx talk
Phinx talkPhinx talk
Phinx talk
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 

Viewers also liked

Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, Capgemini
Lars-Erik Kindblad
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layer
Hasam Panezai
 

Viewers also liked (15)

CQRS
CQRSCQRS
CQRS
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated
 
Application Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, CapgeminiApplication Architecture by Lars-Erik Kindblad, Capgemini
Application Architecture by Lars-Erik Kindblad, Capgemini
 
The Fluent Interface Pattern
The Fluent Interface PatternThe Fluent Interface Pattern
The Fluent Interface Pattern
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014
 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-framework
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
CQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорCQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафор
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layer
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in php
 
Network Layer,Computer Networks
Network Layer,Computer NetworksNetwork Layer,Computer Networks
Network Layer,Computer Networks
 

Similar to Application Layer in PHP

symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 

Similar to Application Layer in PHP (20)

関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Event Sourcing with php
Event Sourcing with phpEvent Sourcing with php
Event Sourcing with php
 
Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)Crafting Quality PHP Applications (PHP Benelux 2018)
Crafting Quality PHP Applications (PHP Benelux 2018)
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012
 
Crafting Quality PHP Applications (PHPkonf 2018)
Crafting Quality PHP Applications (PHPkonf 2018)Crafting Quality PHP Applications (PHPkonf 2018)
Crafting Quality PHP Applications (PHPkonf 2018)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
实战Ecos
实战Ecos实战Ecos
实战Ecos
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 

More from Per Bernhardt

More from Per Bernhardt (12)

Die Rolle des CTO
Die Rolle des CTODie Rolle des CTO
Die Rolle des CTO
 
Event Carried State Transfer @ LeanIX
Event Carried State Transfer @ LeanIXEvent Carried State Transfer @ LeanIX
Event Carried State Transfer @ LeanIX
 
Communication in a Microservice Architecture (Ljubljana Backend Meetup 2021)
Communication in a Microservice Architecture (Ljubljana Backend Meetup 2021)Communication in a Microservice Architecture (Ljubljana Backend Meetup 2021)
Communication in a Microservice Architecture (Ljubljana Backend Meetup 2021)
 
Microservice Test Strategy (@Bonn Code Meetup)
Microservice Test Strategy (@Bonn Code Meetup)Microservice Test Strategy (@Bonn Code Meetup)
Microservice Test Strategy (@Bonn Code Meetup)
 
Communication in a Microservice Architecture
Communication in a Microservice ArchitectureCommunication in a Microservice Architecture
Communication in a Microservice Architecture
 
Magazin-Relaunch bei Chefkoch
Magazin-Relaunch bei ChefkochMagazin-Relaunch bei Chefkoch
Magazin-Relaunch bei Chefkoch
 
Contract Tests mit Pact
Contract Tests mit PactContract Tests mit Pact
Contract Tests mit Pact
 
Chefkoch goes Drupal8
Chefkoch goes Drupal8Chefkoch goes Drupal8
Chefkoch goes Drupal8
 
Umzug eines Hochlast-Dienstes
Umzug eines Hochlast-DienstesUmzug eines Hochlast-Dienstes
Umzug eines Hochlast-Dienstes
 
kubernetes @ chefkoch.de - Kubernetes Meetup Cologne
kubernetes @ chefkoch.de - Kubernetes Meetup Colognekubernetes @ chefkoch.de - Kubernetes Meetup Cologne
kubernetes @ chefkoch.de - Kubernetes Meetup Cologne
 
Continiuous Integration and Delivery with Bamboo
Continiuous Integration and Delivery with BambooContiniuous Integration and Delivery with Bamboo
Continiuous Integration and Delivery with Bamboo
 
Anwendungsintegration mit Edge Side Includes
Anwendungsintegration mit Edge Side IncludesAnwendungsintegration mit Edge Side Includes
Anwendungsintegration mit Edge Side Includes
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 

Application Layer in PHP

  • 1. Application Layer ein Vortrag von Per Bernhardt
  • 2. Agenda • Disclaimer / Credits • Ein kleines bisschen Theorie • Ein echtes Beispiel: Chefkoch API
  • 3.
  • 4. Credit goes to… • http://martinfowler.com/ • http://domainlanguage.com/ • http://alistair.cockburn.us/ • http://www.whitewashing.de/ • und viele andere..
  • 7. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP
  • 8. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP - Fasade - Transaktionen - Sicherheit / Zugriffsschutz - Integration / Orchestrierung
  • 9. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP - Fasade - Transaktionen - Sicherheit / Zugriffsschutz - Integration / Orchestrierung - Daten - Geschäftslogik
  • 10. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP - Fasade - Transaktionen - Sicherheit / Zugriffsschutz - Integration / Orchestrierung - Daten - Geschäftslogik - Datenbank - Mailserver - Logger - …
  • 11. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP - Fasade - Transaktionen - Sicherheit / Zugriffsschutz - Integration / Orchestrierung - Daten - Geschäftslogik - Datenbank - Mailserver - Logger - …
  • 12. Application Layer Presentation Layer Infrastructure Layer Domain Layer - Controller - Template / HTML - Session / HTTP - Fasade - Transaktionen - Sicherheit / Zugriffsschutz - Integration / Orchestrierung - Daten - Geschäftslogik - Datenbank - Mailserver - Logger - …
  • 14.
  • 16. <?php ! namespace ChefkochBundleApiBundleController; ! use SymfonyBundleFrameworkBundleControllerController; use ChefkochDomainModelCookbookCookbookId use SensioBundleFrameworkExtraBundleConfigurationParamConverter; use ChefkochBundleApiBundleAnnotationApiSerialize; use ChefkochApplicationCookbookRequest; use ChefkochApplicationCookbookCommand; use PixelhouseApplicationEventDispatchingService; use PixelhouseApplicationResponse; ! class CookbookController extends Controller { ! ... ! /** * @ParamConverter("category", options={"deserialize"=true}) * @ApiSerialize * @return Response */ public function saveCategoryAction(CookbookId $cookbookId, RequestCategoryRequest $category) { return $this->getCookbookService()->execute( new CommandSaveCategoryCommand($cookbookId, $category) ); } ! ... ! /** * @return DispatchingService */ private function getCookbookService() { return $this->get('chefkoch_api.application.cookbook_service'); } }
  • 17. <?php ! namespace ChefkochApplicationCookbookCommand; ! use ChefkochApplicationCookbookRequestCategoryRequest; use ChefkochApplicationCookbookSecurityCookbookWriteAccessRequired; use ChefkochDomainModelCookbookCookbookId; use PixelhouseApplicationCommand; ! class SaveCategoryCommand implements Command, CookbookWriteAccessRequired { ! /** @var CookbookId */ private $cookbookId; ! /** @var CategoryRequest */ private $categoryRequest; ! public function __construct(CookbookId $cookbookId, CategoryRequest $categoryRequest) { $this->cookbookId = $cookbookId; $this->categoryRequest = $categoryRequest; } ! public function getCookbookId() { return $this->cookbookId; } ! public function getCategoryRequest() { return $this->categoryRequest; } }
  • 18. <?php ! namespace PixelhouseApplicationEvent; ! use PixelhouseApplicationCommand; use PixelhouseApplicationUseCase; use PixelhouseEventDispatcherEventDispatcher; ! class DispatchingService { ! /** @var EventDispatcher */ private $eventDispatcher; ! /** @var UseCase[] */ private $useCases = array(); ! public function __construct(EventDispatcher $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; } ! public function registerCommand($commandClass, UseCase $useCase) { $this->useCases[$commandClass] = $useCase; } ! public function execute(Command $command) { ... } }
  • 19. <?php ! namespace PixelhouseApplicationEvent; ! class Events { const PRE_COMMAND = 'application.pre_command'; const POST_COMMAND = 'application.post_command'; const EXCEPTION = 'application.exception'; }
  • 20. <?php ! namespace PixelhouseApplicationEvent; ! use PixelhouseApplicationCommand; ! class DispatchingService { ! ... ! public function execute(Command $command) { try { $this->eventDispatcher->dispatch( Events::PRE_COMMAND, new CommandEvent($command) ); $response = $this->useCases[get_class($command)]->run($command); $this->eventDispatcher->dispatch( Events::POST_COMMAND, new PostCommandEvent($command, $response) ); ! return $response; } catch (Exception $exception) { $event = new CommandExceptionEvent($command, $exception); $this->eventDispatcher->dispatch( Events::EXCEPTION, $event ); if ($response = $event->getResponse()) { return $response; } else { throw $exception; } } } }
  • 21. <?php ! namespace ChefkochInfrastructureApplication; ! use PixelhouseApplicationEvent; use PixelhouseEventDispatcherSubscriber; use DoctrineORMEntityManager; ! class DoctrineTransactionListener implements Subscriber { ! /** @var EntityManager */ private $entityManager; ! public function __construct(EntityManager $entityManager) { $this->entityManager = $entityManager; } ! public function preCommand(EventCommandEvent $event) { $this->entityManager->getConnection()->beginTransaction(); } ! public function postCommand(EventPostCommandEvent $event) { $this->entityManager->flush(); $this->entityManager->getConnection()->commit(); } ! public function onException(EventCommandExceptionEvent $event) { $this->entityManager->close(); if ($this->entityManager->getConnection()->isTransactionActive()) { $this->entityManager->getConnection()->rollBack(); } } }
  • 22. <?php ! namespace PixelhouseApplicationSecurity; ! use PixelhouseApplicationEvent; use PixelhouseEventDispatcherSubscriber; ! class SecurityListener implements Subscriber { ! /** @var Context */ private $context; ! /** @var Policy[] */ private $policies = array(); ! public function __construct(Context $context) { $this->context = $context; } ! public function addPolicy(Policy $policy) { $this->policies[] = $policy; } ! /** * throws Exception */ public function preCommand(EventCommandEvent $event) { foreach ($this->policies as $policy) { $policy->check($this->securityContext, $event->getCommand()); } } }
  • 23. <?php ! namespace ChefkochApplicationCookbookSecurity; ! use ChefkochDomainModelCookbookCookbookRepository; use ChefkochUserDomainModelUserRepository; use PixelhouseApplicationCommand; use PixelhouseApplicationSecurityAccessDeniedException; use PixelhouseApplicationSecurityContext; use PixelhouseApplicationSecurityPolicy; ! class CookbookAccessPolicy implements Policy { ! /** @var CookbookRepository */ private $cookbookRepository; ! /** @var UserRepository */ private $userRepository; ! public function __construct(CookbookRepository $cbRepo, UserRepository $uRepo) { $this->cookbookRepository = $cbRepo; $this->userRepository = $uRepo; } ! public function check(Context $context, Command $command) { if ($command instanceof CookbookWriteAccessRequired) { $cookbook = $this->cookbookRepository->findOneById($command->getCookbookId()); $user = $this->userRepository->findOneById($context->getUserId()); ! // Zugriff prüfen ... ! throw new AccessDeniedException(); } } }
  • 24. <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services ..."> <services> ... ! <service id="chefkoch_api.application.use_case.cookbook_save_category" class="ChefkochApplicationCookbookUseCaseSaveCategory"> <argument type="service" id="chefkoch_api.infrastructure.cookbook_category_repository" /> <argument type="service" id="chefkoch_api.infrastructure.user_repository" /> <argument type="service" id="chefkoch_api.application.security_context" /> <tag name="chefkoch_api.application.use_case" commandClass="ChefkochApplicationCookbookCommandSaveCategoryCommand" applicationService="chefkoch_api.application.cookbook_service" /> </service> ! ... </services> </container>
  • 25. <?php ! namespace ChefkochApplicationCookbookUseCase; ! use ChefkochApplicationCookbookCommandSaveCategoryCommand; use PixelhouseApplicationSecurityContext; use PixelhouseApplicationUseCase; use ChefkochDomainModelCookbookCategoryRepository; use ChefkochUserDomainModelUserRepository; ! class SaveCategory implements UseCase { ! /** @var CategoryRepository */ private $categoryRepository; ! /** @var UserRepository */ private $userRepository; ! /** @var Context */ private $context; ! public function __construct(CategoryRepository $cRepo, UserRepository $uRepo, Context $context) { $this->categoryRepository = $cRepo; $this->userRepository = $uRepo; $this->context = $context; } ! public function run(SaveCategoryCommand $command) { ... } }
  • 26. <?php ! namespace ChefkochApplicationCookbookUseCase; ! use PixelhouseApplicationUseCase; use ChefkochApplicationCookbookCommandSaveCategoryCommand; use ChefkochDomainModelCookbookCategory; use ChefkochApplicationCookbookNotificationCategorySavedSuccess; use ChefkochApplicationCookbookResponseCategoryResponse; use PixelhouseApplicationResponse; ! class SaveCategory implements UseCase { ... ! public function run(SaveCategoryCommand $command) { $user = $this->userRepository->findOneById($this->context->getUserId()); ! $category = new Category( $command->getCookbookId(), $user->getId(), $command->getCategoryRequest()->getName(), $command->getCategoryRequest()->getDescriptionText() ); ! $this->categoryRepository->add($category); ! $categoryResponse = new CategoryResponse($category, $user); ! $response = new Response(); $response->getNotification()->addMessage(new CategorySavedSuccess($categoryResponse)); ! return $response; } }
  • 28.
  • 29.
  • 30.
  • 32. Bilder • Warning: https://www.flickr.com/photos/gerardstolk/ 6538330609 • Show Time: https://www.flickr.com/photos/ florida_photo_guy/5212663826 • Question Marks: https://www.flickr.com/photos/ loneblackrider/315302588 • Thank You: https://www.flickr.com/photos/wwworks/ 4759535950