SlideShare a Scribd company logo
1 of 91
Download to read offline
Applications for the
Enterprise with PHP
Solve complex problems with excellence
and get back the joy of software development.
@robertlemke

project founder of FLOW3 / TYPO3 Phoenix

co-founder of the TYPO3 Association

coach, coder, consultant

36 years old

lives in Lübeck, Germany

1 wife, 2 daughters, 1 espresso machine

likes drumming
PHP
Java
is_php_a_good_language() ?
       TRUE : FALSE;
inconsistent($needle, $haystack);
functional_toolbox::$lackingElegance;
The programming language
   is rarely the problem.
I♥PHP
I   PHP
Let me focus
on the fun part
10 Features
1   Controller
modelviewcontroller
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;

class HelloWorldController extends ActionController {

    /**
      * @return string
      */
    public function greetAction() {
         return '¡Hola mundo!';
    }

}
TEXT HERE
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;

class HelloWorldController extends ActionController {

    /**
      * @param string $name The name to mention
      * @return string
      */
    public function greetAction($name) {
         return "¡Hola $name!";
    }

}
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;
use AcmeDemoDomainModelPerson;

class HelloWorldController extends ActionController {

    /**
      * @param AcmeDemoDomainModelPerson $person
      * @return string
      */
    public function greetAction(Person $person) {
         return "¡Hola " . $person->getName() . "!";
    }
2   HTTP
Network Working Group                                           R. Fielding
Request for Comments: 2616                                        UC Irvine
Obsoletes: 2068                                                   J. Gettys
Category: Standards Track                                        Compaq/W3C
                                                                   J. Mogul
                                                                     Compaq
                                                                 H. Frystyk
                                                                    W3C/MIT
                                                                L. Masinter
                                                                      Xerox
                                                                   P. Leach
                                                                  Microsoft
                                                             T. Berners-Lee
                                                                    W3C/MIT
                                                                  June 1999




                   Hypertext Transfer Protocol -- HTTP/1.1


Status of this Memo


   This document specifies an Internet standards track protocol for the
   Internet community, and requests discussion and suggestions for
   improvements.     Please refer to the current edition of the "Internet
HTTP/1.1 has been designed to allow implementations of applications
                                                     /**
   that do not depend on knowledge of ranges.
                                                      * Represents a HTTP request
                                                      */
4 HTTP Message
                                                     class Request extends Message {

4.1 Message Types
                                                         /**
                                                           * @var string
   HTTP messages consist of requests from client to    server and responses
                                                           */
   from server to client.
                                                         protected $method = 'GET';

       HTTP-message   = Request | Response       ; HTTP/1.1 messages
                                                        /**
                                                          * @var TYPO3FLOW3HttpUri
   Request   (section 5) and Response (section 6) messages use the generic
                                                          */
   message   format of RFC 822 [9] for transferring entities (the payload
                                                        protected $uri;
   of the message). Both types of message consist of a start-line, zero
   or more header fields (also known as "headers"), an empty line (i.e.,
                                                        /**
   a line with nothing preceding the CRLF) indicating   the end of the
                                                          * @var TYPO3FLOW3HttpUri
   header fields, and possibly a message-body.
                                                          */
                                                        protected $baseUri;
        generic-message = start-line
                            *(message-header CRLF)
                                                         /**
                            CRLF
                                                          * @var array
                            [ message-body ]
                                                          */
        start-line      = Request-Line | Status-Line
                                                         protected $arguments;
$request->getHeader('User-Agent'); # C64

$request->setHeader('X-Coffee', 'too few');
$now = new DateTime();
$response->setLastModified($now);
$response->getHeaders()
  ->setCacheControlDirective('s-max-age', 100);
# set cookie in response:
$response->setCookie(new Cookie('counter', 1));

  # retrieve cookie on next request:
$cookie = $request->getCookie('counter');
3   Templating
<html lang="en">
    <head>
        <title>Templating</title>
    </head>
    <body>

          Our templating engine
          is called

                         Fluid
    </body>
</html>
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;

class HelloWorldController extends ActionController {

    /**
      * @param string $name
      * @return void
      */
    public function greetAction($name) {
         $this->view->assign('name', $name);
    }

}
<html>
    <head>
        <title>Fluid Example</title>
    </head>
    <body>
        <p>Hello, {name}!</p>
    </body>
</html>
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;
use AcmeDemoDomainModelBook;

class BookController extends ActionController {

    /**
     * @return void
     */
    public function indexAction() {
        $book = new Book();
        $book->setTitle('Manual del Guerrero de la Luz');

        $books = array($book);

        $this->view->assign('books', $books);
    }

}
<ul>
   <f:for each="{books}" as="book">
       <li>{book.title}</li>
   </f:for>
</ul>
4   Model
public function createAction(Book $book) {
    if (!$this->securityManager->hasRole('BookAdmin')) {
        throw new Exception('Not allowed.');
    }

    $statementHandle = $this->databaseHandle->prepare(
        'INSERT INTO "books" ("identifier", "title", "isbn") ' .
        'VALUES (?, ?, ?)'
    );
    $result = $statementHandle->execute(
        array($book->getId(), $book->getTitle(), $book->getIsbn())
    );
    if ($result === FALSE) {
        throw new Exception('Could not create book.');
    }
}
class Book extends BaseModel {

    protected $id;
    protected $title;
    protected $isbn;
    …

    public function __construct() {
        $this->id = TYPO3FLOW3UtilityAlgorithms::generateUUID();
    }
    …

    public function getSalesVolume() {
        if (!$this->securityManager->hasRole('Management')) {
            throw new Exception('Access Denied');
        }

        $statementHandle = $this->databaseHandle->prepare(
            'SELECT "identifier" FROM "orders" WHERE "date">? AND "
        $result = $statementHandle->execute(array(time() - 604800));
        if ($result === FALSE) {
Tackling the Heart of Software Development

                                         /**
Domain-Driven Design                      * A Book
                                          *
                                          * @FLOW3Scope(“protot
                                                                 ype”)
                                          * @FLOW3Entity
A methodology which ...                   */
                                        class Book {

 • results in rich domain models        	    /**
                                        	     * @var string
                                        	     */
 • provides a common language           	    protected $title;

   across the project team          	       /**
                                    	        * @var string
                                    	        */
 • simplify the design of complex   	       protected $isbn;
   applications                     	       /**
                                    	        * @var string
                                    	        */
                                    	       protected $description
                                                                   ;
FLOW3 is the first PHP framework
                                    	       /**
tailored to Domain-Driven Design    	        * @var integer
                                    	        */
                                    	       protected $price;
namespace RoeBooksShopDomainModel;
use TYPO3FLOW3Annotations as FLOW3;

/**
 * A Book
 *
 * @FLOW3Entity
 */
class Book {

    /**
     * @var string
     */
    protected $title;

    /**
     * @var integer
     */
    protected $price;
/**
  * Get the Book's title
  *
  * @return string The Book's title
  */
public function getTitle() {
     return $this->title;
}

/**
  * Sets this Book's title
  *
  * @param string $title The Book's title
  * @return void
  */
public function setTitle($title) {
     $this->title = $title;
}
/**
  * Get the Book's Sales Volume
  *
  * @return integer The Book's sales volume
  */
public function getSalesVolume() {
     $time = new DateTime('last month');
     $total = $this->bookRepository->calculateTotalSalesSince($time);
     return $total;
}
interface RepositoryInterface {

    /**
     * Adds an object to this repository.
     * @param object $object The object to add
     * @return void
     */
    public function add($object);

    /**
     * Removes an object from this repository.
     * @param object $object The object to remove
     * @return void
     */
    public function remove($object);

    /**
     * Returns all objects of this repository.
     * @return TYPO3FLOW3PersistenceQueryResultInterface The que
     */
    public function findAll();
/**
 * A repository for Books
 *
 * @FLOW3Scope("singleton")
 */
class BookRepository extends Repository {

    /**
      * Returns the total sales volume
      *
      * @param DateTime $time
      */
    public function calculateTotalSalesSince(DateTime $time) {
         # implementation …
    }

}
/**
  * Adds the given new book object to the book repository
  *
  * @param AcmeDemoDomainModelBook $newBook A new book to ad
  * @return void
  */
public function createAction(Book $newBook) {
     $this->bookRepository->add($newBook);
     $this->redirect('index');
}
TEXT HERE
5   Resources
TEXT HERE
TEXT HERE
TEXT HERE
TEXT HERE
TEXT HERE
Dependency
6   Injection
class Foo {

    protected static $instance;

    public function getInstance() {
        if (self::$instance === NULL) {
            self::$instance = new self;
        }
        return self::$instance;
    }
}

class Bar {

    public function action() {
        $foo = Foo::getInstance();
    }
}
class ServiceLocator {

    protected static $services = array();

    public function get($serviceName) {
        return self::$services[$serviceName];
    }
}

class Bar {

    public function action() {
        $foo = ServiceLocator::get('Foo');
    }
}
class Bar {

    /**
     * @var Foo
     */
    protected $foo;

    /**
      * @param Foo $foo
      */
    public function __construct(Foo $foo) {
         $this->foo = $foo;
    }

    /**
      * @return string
      */
    public function action() {
         $this->foo->doSomething();
    }
}
class Bar {

    /**
     * @var Foo
     * @FLOW3Inject
     */
    protected $foo;




    /**
      * @return string
      */
    public function action() {
         $this->foo->doSomething();
    }
}
Object Management
Object Management

FLOW3's take on Dependency Injection
 • one of the first PHP implementations
   (started in 2006, improved ever since)
Object Management

FLOW3's take on Dependency Injection
 • one of the first PHP implementations
   (started in 2006, improved ever since)

 • object management for the whole lifecycle of all objects
Object Management

FLOW3's take on Dependency Injection
 • one of the first PHP implementations
   (started in 2006, improved ever since)

 • object management for the whole lifecycle of all objects

 • no unnecessary configuration if information can be
   gatered automatically (autowiring)
Object Management

FLOW3's take on Dependency Injection
 • one of the first PHP implementations
   (started in 2006, improved ever since)

 • object management for the whole lifecycle of all objects

 • no unnecessary configuration if information can be
   gatered automatically (autowiring)

 • intuitive use and no bad magical surprises
Object Management

FLOW3's take on Dependency Injection
 • one of the first PHP implementations
   (started in 2006, improved ever since)

 • object management for the whole lifecycle of all objects

 • no unnecessary configuration if information can be
   gatered automatically (autowiring)

 • intuitive use and no bad magical surprises

 • fast! (like hardcoded or faster)
Aspect-Oriented
7   Programming
<?php
namespace AcmeDemoController;
use TYPO3FLOW3MvcControllerActionController;

class HelloWorldController extends ActionController {

    /**
      * @param string $name The name to mention
      * @return string
      */
    public function greetAction($name) {
         return "¡Hola $name!";
    }

}
namespace AcmeDemoAspect;

use TYPO3FLOW3AopJoinPoint;
use TYPO3FLOW3AnnotationsAround;

class BetterWorldAspect {

    /**
      * Advice which tweaks the HelloWorld controller
      *
      * @param JoinPoint $joinPoint
      * @Around("method(.*Controller->greetAction())")
      */
    public function someAdvice(JoinPoint $joinPoint) {
         $name = $joinPoint->getMethodArgument('name');
         return sprintf("%s, you're running out of time!", $name);
    }

}
Robert, you’re running out of time!
8   Security
#
# Policy.yaml
#

resources:
  methods:
    DangerousMethods: 'method(.*Controller->(new|create|edit|
update|delete)Action))'

roles:
  User: []
  Administrator: [User]


acls:
  Administrator:
    methods:
      DangerousMethods: GRANT
TEXT HERE
9   Sessions
TEXT HERE
TEXT HERE
TEXT HERE
TEXT HERE
10   Command Line
/**
 * Kickstart a new action controller
 *
 * Generates an Action Controller with the given name in the specified package.
 * In its default mode it will create just the controller containing a sample
 * indexAction.
 *
 * By specifying the --generate-actions flag, this command will also create a
 * set of actions. If no model or repository exists which matches the
 * controller name (for example "CoffeeRepository" for "CoffeeController"),
 * an error will be shown.
 *
 * Likewise the command exits with an error if the specified package does not
 * exist. By using the --generate-related flag, a missing package, model or
 * repository can be created alongside, avoiding such an error.
 *
 * By specifying the --generate-templates flag, this command will also create
 * matching Fluid templates for the actions created. This option can only be
 * used in combination with --generate-actions.
 *
 * The default behavior is to not overwrite any existing code. This can be
 * overridden by specifying the --force flag.
* By specifying the --generate-templates flag, this command will also create
 * matching Fluid templates for the actions created. This option can only be
 * used in combination with --generate-actions.
 *
 * The default behavior is to not overwrite any existing code. This can be
 * overridden by specifying the --force flag.
 *
 * @param string $packageKey The package key of the package for the new controller with
 * @param string $controllerName The name for the new controller. This may also be a com
 * @param boolean $generateActions Also generate index, show, new, create, edit, update
 * @param boolean $generateTemplates Also generate the templates for each action.
 * @param boolean $generateRelated Also create the mentioned package, related model and
 * @param boolean $force Overwrite any existing controller or template code. Regardless
 * @return string
 * @see typo3.kickstart:kickstart:commandcontroller
 */
public function actionControllerCommand($packageKey, $controllerName, $generateActions =
     $subpackageName = '';
     if (strpos('/', $packageKey) !== FALSE) {
         list($packageKey, $subpackageName) = explode('/', $packageKey, 2);
     }
     if (!$this->packageManager->isPackageKeyValid($packageKey)) {
Rossmann
• second biggest drug store
  in Germany
• 5,13 billion € turnover
• 31,000 employees



Customer Database
Amadeus
• world’s biggest
  e-ticket provider
• 217 markets
• 948 million billable
  transactions / year
• 2,7 billion € revenue

Social Media Suite
At a Glance

FLOW3 is a web application platform
 • holistic concept for your apps

 • modular, extensible, package based

 • pedantically clean with focus on quality

 • puts a smile on developer’s faces


 • free & Open Source (LGPL v3)

 • backed by one of the largest Open Source projects
Foundation for the Next Generation CMS


TYPO3 “Phoenix” is the all-new
Enterprise CMS
 • content repository, workspaces,
   versions, i18n, modular UI ...

 • powered by FLOW3

 • compatible code base

 • use TYPO3 features in FLOW3
   standalone apps as you like
FLOW3 1.1 Release
   tomorrow!
Thanks for having me!

Slides:     http://slideshare.net/robertlemke

Examples:   http://github.com/robertlemke

Blog:       http://robertlemke.com

Twitter:    @robertlemke

Feedback:   robert@typo3.org

FLOW3:      http://flow3.typo3.org

More Related Content

Similar to Applications for the Enterprise with PHP (CPEurope)

2012 08-11-flow3-northeast-php
2012 08-11-flow3-northeast-php2012 08-11-flow3-northeast-php
2012 08-11-flow3-northeast-php
Jochen Rau
 
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
 
Tips
TipsTips
Tips
mclee
 

Similar to Applications for the Enterprise with PHP (CPEurope) (20)

Hands on FLOW3 (DPC12)
Hands on FLOW3 (DPC12)Hands on FLOW3 (DPC12)
Hands on FLOW3 (DPC12)
 
Getting Into FLOW3 (DPC12)
Getting Into FLOW3 (DPC12)Getting Into FLOW3 (DPC12)
Getting Into FLOW3 (DPC12)
 
IPCSE12: Hands on FLOW3
IPCSE12: Hands on FLOW3IPCSE12: Hands on FLOW3
IPCSE12: Hands on FLOW3
 
2012 08-11-flow3-northeast-php
2012 08-11-flow3-northeast-php2012 08-11-flow3-northeast-php
2012 08-11-flow3-northeast-php
 
IPCSE12: Getting into FLOW3
IPCSE12: Getting into FLOW3IPCSE12: Getting into FLOW3
IPCSE12: Getting into FLOW3
 
Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0
 
Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0
 
FLOW3 Tutorial - T3CON11 Frankfurt
FLOW3 Tutorial - T3CON11 FrankfurtFLOW3 Tutorial - T3CON11 Frankfurt
FLOW3 Tutorial - T3CON11 Frankfurt
 
Getting Into FLOW3 (TYPO312CA)
Getting Into FLOW3 (TYPO312CA)Getting Into FLOW3 (TYPO312CA)
Getting Into FLOW3 (TYPO312CA)
 
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
TYPO3 Flow: Beyond the Blog Example (Inspiring Flow 2013)
 
Doctrine in FLOW3
Doctrine in FLOW3Doctrine in FLOW3
Doctrine in FLOW3
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
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
 
InspiringCon15: Bringing TYPO3 Legacy Applications into the Flow
InspiringCon15: Bringing TYPO3 Legacy Applications into the FlowInspiringCon15: Bringing TYPO3 Legacy Applications into the Flow
InspiringCon15: Bringing TYPO3 Legacy Applications into the Flow
 
TYPO3 Flow 2.0 Workshop T3BOARD13
TYPO3 Flow 2.0 Workshop T3BOARD13TYPO3 Flow 2.0 Workshop T3BOARD13
TYPO3 Flow 2.0 Workshop T3BOARD13
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Tips
TipsTips
Tips
 
TYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkTYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase framework
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 

More from Robert Lemke

More from Robert Lemke (20)

Neos Content Repository – Git for content
Neos Content Repository – Git for contentNeos Content Repository – Git for content
Neos Content Repository – Git for content
 
A General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPA General Purpose Docker Image for PHP
A General Purpose Docker Image for PHP
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022
 
GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022
 
OpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowOpenID Connect with Neos and Flow
OpenID Connect with Neos and Flow
 
Neos Conference 2019 Keynote
Neos Conference 2019 KeynoteNeos Conference 2019 Keynote
Neos Conference 2019 Keynote
 
A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome Keynote
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRS
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome Keynote
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for Developers
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HH
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Applications for the Enterprise with PHP (CPEurope)

  • 1. Applications for the Enterprise with PHP Solve complex problems with excellence and get back the joy of software development.
  • 2. @robertlemke project founder of FLOW3 / TYPO3 Phoenix co-founder of the TYPO3 Association coach, coder, consultant 36 years old lives in Lübeck, Germany 1 wife, 2 daughters, 1 espresso machine likes drumming
  • 3. PHP
  • 7. The programming language is rarely the problem.
  • 9. I PHP
  • 10. Let me focus on the fun part
  • 11.
  • 13. 1 Controller
  • 15.
  • 16. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; class HelloWorldController extends ActionController { /** * @return string */ public function greetAction() { return '¡Hola mundo!'; } }
  • 18. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; class HelloWorldController extends ActionController { /** * @param string $name The name to mention * @return string */ public function greetAction($name) { return "¡Hola $name!"; } }
  • 19.
  • 20.
  • 21. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; use AcmeDemoDomainModelPerson; class HelloWorldController extends ActionController { /** * @param AcmeDemoDomainModelPerson $person * @return string */ public function greetAction(Person $person) { return "¡Hola " . $person->getName() . "!"; }
  • 22.
  • 23. 2 HTTP
  • 24. Network Working Group R. Fielding Request for Comments: 2616 UC Irvine Obsoletes: 2068 J. Gettys Category: Standards Track Compaq/W3C J. Mogul Compaq H. Frystyk W3C/MIT L. Masinter Xerox P. Leach Microsoft T. Berners-Lee W3C/MIT June 1999 Hypertext Transfer Protocol -- HTTP/1.1 Status of this Memo This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. Please refer to the current edition of the "Internet
  • 25. HTTP/1.1 has been designed to allow implementations of applications /** that do not depend on knowledge of ranges. * Represents a HTTP request */ 4 HTTP Message class Request extends Message { 4.1 Message Types /** * @var string HTTP messages consist of requests from client to server and responses */ from server to client. protected $method = 'GET'; HTTP-message = Request | Response ; HTTP/1.1 messages /** * @var TYPO3FLOW3HttpUri Request (section 5) and Response (section 6) messages use the generic */ message format of RFC 822 [9] for transferring entities (the payload protected $uri; of the message). Both types of message consist of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., /** a line with nothing preceding the CRLF) indicating the end of the * @var TYPO3FLOW3HttpUri header fields, and possibly a message-body. */ protected $baseUri; generic-message = start-line *(message-header CRLF) /** CRLF * @var array [ message-body ] */ start-line = Request-Line | Status-Line protected $arguments;
  • 27. $now = new DateTime(); $response->setLastModified($now);
  • 29. # set cookie in response: $response->setCookie(new Cookie('counter', 1)); # retrieve cookie on next request: $cookie = $request->getCookie('counter');
  • 30. 3 Templating
  • 31. <html lang="en"> <head> <title>Templating</title> </head> <body> Our templating engine is called Fluid </body> </html>
  • 32. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; class HelloWorldController extends ActionController { /** * @param string $name * @return void */ public function greetAction($name) { $this->view->assign('name', $name); } }
  • 33. <html> <head> <title>Fluid Example</title> </head> <body> <p>Hello, {name}!</p> </body> </html>
  • 34. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; use AcmeDemoDomainModelBook; class BookController extends ActionController { /** * @return void */ public function indexAction() { $book = new Book(); $book->setTitle('Manual del Guerrero de la Luz'); $books = array($book); $this->view->assign('books', $books); } }
  • 35. <ul> <f:for each="{books}" as="book"> <li>{book.title}</li> </f:for> </ul>
  • 36. 4 Model
  • 37. public function createAction(Book $book) { if (!$this->securityManager->hasRole('BookAdmin')) { throw new Exception('Not allowed.'); } $statementHandle = $this->databaseHandle->prepare( 'INSERT INTO "books" ("identifier", "title", "isbn") ' . 'VALUES (?, ?, ?)' ); $result = $statementHandle->execute( array($book->getId(), $book->getTitle(), $book->getIsbn()) ); if ($result === FALSE) { throw new Exception('Could not create book.'); } }
  • 38. class Book extends BaseModel { protected $id; protected $title; protected $isbn; … public function __construct() { $this->id = TYPO3FLOW3UtilityAlgorithms::generateUUID(); } … public function getSalesVolume() { if (!$this->securityManager->hasRole('Management')) { throw new Exception('Access Denied'); } $statementHandle = $this->databaseHandle->prepare( 'SELECT "identifier" FROM "orders" WHERE "date">? AND " $result = $statementHandle->execute(array(time() - 604800)); if ($result === FALSE) {
  • 39. Tackling the Heart of Software Development /** Domain-Driven Design * A Book * * @FLOW3Scope(“protot ype”) * @FLOW3Entity A methodology which ... */ class Book { • results in rich domain models /** * @var string */ • provides a common language protected $title; across the project team /** * @var string */ • simplify the design of complex protected $isbn; applications /** * @var string */ protected $description ; FLOW3 is the first PHP framework /** tailored to Domain-Driven Design * @var integer */ protected $price;
  • 40. namespace RoeBooksShopDomainModel; use TYPO3FLOW3Annotations as FLOW3; /** * A Book * * @FLOW3Entity */ class Book { /** * @var string */ protected $title; /** * @var integer */ protected $price;
  • 41. /** * Get the Book's title * * @return string The Book's title */ public function getTitle() { return $this->title; } /** * Sets this Book's title * * @param string $title The Book's title * @return void */ public function setTitle($title) { $this->title = $title; }
  • 42. /** * Get the Book's Sales Volume * * @return integer The Book's sales volume */ public function getSalesVolume() { $time = new DateTime('last month'); $total = $this->bookRepository->calculateTotalSalesSince($time); return $total; }
  • 43. interface RepositoryInterface { /** * Adds an object to this repository. * @param object $object The object to add * @return void */ public function add($object); /** * Removes an object from this repository. * @param object $object The object to remove * @return void */ public function remove($object); /** * Returns all objects of this repository. * @return TYPO3FLOW3PersistenceQueryResultInterface The que */ public function findAll();
  • 44. /** * A repository for Books * * @FLOW3Scope("singleton") */ class BookRepository extends Repository { /** * Returns the total sales volume * * @param DateTime $time */ public function calculateTotalSalesSince(DateTime $time) { # implementation … } }
  • 45. /** * Adds the given new book object to the book repository * * @param AcmeDemoDomainModelBook $newBook A new book to ad * @return void */ public function createAction(Book $newBook) { $this->bookRepository->add($newBook); $this->redirect('index'); }
  • 47. 5 Resources
  • 53. Dependency 6 Injection
  • 54. class Foo { protected static $instance; public function getInstance() { if (self::$instance === NULL) { self::$instance = new self; } return self::$instance; } } class Bar { public function action() { $foo = Foo::getInstance(); } }
  • 55. class ServiceLocator { protected static $services = array(); public function get($serviceName) { return self::$services[$serviceName]; } } class Bar { public function action() { $foo = ServiceLocator::get('Foo'); } }
  • 56. class Bar { /** * @var Foo */ protected $foo; /** * @param Foo $foo */ public function __construct(Foo $foo) { $this->foo = $foo; } /** * @return string */ public function action() { $this->foo->doSomething(); } }
  • 57. class Bar { /** * @var Foo * @FLOW3Inject */ protected $foo; /** * @return string */ public function action() { $this->foo->doSomething(); } }
  • 59. Object Management FLOW3's take on Dependency Injection • one of the first PHP implementations (started in 2006, improved ever since)
  • 60. Object Management FLOW3's take on Dependency Injection • one of the first PHP implementations (started in 2006, improved ever since) • object management for the whole lifecycle of all objects
  • 61. Object Management FLOW3's take on Dependency Injection • one of the first PHP implementations (started in 2006, improved ever since) • object management for the whole lifecycle of all objects • no unnecessary configuration if information can be gatered automatically (autowiring)
  • 62. Object Management FLOW3's take on Dependency Injection • one of the first PHP implementations (started in 2006, improved ever since) • object management for the whole lifecycle of all objects • no unnecessary configuration if information can be gatered automatically (autowiring) • intuitive use and no bad magical surprises
  • 63. Object Management FLOW3's take on Dependency Injection • one of the first PHP implementations (started in 2006, improved ever since) • object management for the whole lifecycle of all objects • no unnecessary configuration if information can be gatered automatically (autowiring) • intuitive use and no bad magical surprises • fast! (like hardcoded or faster)
  • 64. Aspect-Oriented 7 Programming
  • 65. <?php namespace AcmeDemoController; use TYPO3FLOW3MvcControllerActionController; class HelloWorldController extends ActionController { /** * @param string $name The name to mention * @return string */ public function greetAction($name) { return "¡Hola $name!"; } }
  • 66.
  • 67. namespace AcmeDemoAspect; use TYPO3FLOW3AopJoinPoint; use TYPO3FLOW3AnnotationsAround; class BetterWorldAspect { /** * Advice which tweaks the HelloWorld controller * * @param JoinPoint $joinPoint * @Around("method(.*Controller->greetAction())") */ public function someAdvice(JoinPoint $joinPoint) { $name = $joinPoint->getMethodArgument('name'); return sprintf("%s, you're running out of time!", $name); } }
  • 68. Robert, you’re running out of time!
  • 69. 8 Security
  • 70.
  • 71. # # Policy.yaml # resources: methods: DangerousMethods: 'method(.*Controller->(new|create|edit| update|delete)Action))' roles: User: [] Administrator: [User] acls: Administrator: methods: DangerousMethods: GRANT
  • 72.
  • 74. 9 Sessions
  • 79. 10 Command Line
  • 80.
  • 81.
  • 82.
  • 83. /** * Kickstart a new action controller * * Generates an Action Controller with the given name in the specified package. * In its default mode it will create just the controller containing a sample * indexAction. * * By specifying the --generate-actions flag, this command will also create a * set of actions. If no model or repository exists which matches the * controller name (for example "CoffeeRepository" for "CoffeeController"), * an error will be shown. * * Likewise the command exits with an error if the specified package does not * exist. By using the --generate-related flag, a missing package, model or * repository can be created alongside, avoiding such an error. * * By specifying the --generate-templates flag, this command will also create * matching Fluid templates for the actions created. This option can only be * used in combination with --generate-actions. * * The default behavior is to not overwrite any existing code. This can be * overridden by specifying the --force flag.
  • 84. * By specifying the --generate-templates flag, this command will also create * matching Fluid templates for the actions created. This option can only be * used in combination with --generate-actions. * * The default behavior is to not overwrite any existing code. This can be * overridden by specifying the --force flag. * * @param string $packageKey The package key of the package for the new controller with * @param string $controllerName The name for the new controller. This may also be a com * @param boolean $generateActions Also generate index, show, new, create, edit, update * @param boolean $generateTemplates Also generate the templates for each action. * @param boolean $generateRelated Also create the mentioned package, related model and * @param boolean $force Overwrite any existing controller or template code. Regardless * @return string * @see typo3.kickstart:kickstart:commandcontroller */ public function actionControllerCommand($packageKey, $controllerName, $generateActions = $subpackageName = ''; if (strpos('/', $packageKey) !== FALSE) { list($packageKey, $subpackageName) = explode('/', $packageKey, 2); } if (!$this->packageManager->isPackageKeyValid($packageKey)) {
  • 85.
  • 86. Rossmann • second biggest drug store in Germany • 5,13 billion € turnover • 31,000 employees Customer Database
  • 87. Amadeus • world’s biggest e-ticket provider • 217 markets • 948 million billable transactions / year • 2,7 billion € revenue Social Media Suite
  • 88. At a Glance FLOW3 is a web application platform • holistic concept for your apps • modular, extensible, package based • pedantically clean with focus on quality • puts a smile on developer’s faces • free & Open Source (LGPL v3) • backed by one of the largest Open Source projects
  • 89. Foundation for the Next Generation CMS TYPO3 “Phoenix” is the all-new Enterprise CMS • content repository, workspaces, versions, i18n, modular UI ... • powered by FLOW3 • compatible code base • use TYPO3 features in FLOW3 standalone apps as you like
  • 90. FLOW3 1.1 Release tomorrow!
  • 91. Thanks for having me! Slides: http://slideshare.net/robertlemke Examples: http://github.com/robertlemke Blog: http://robertlemke.com Twitter: @robertlemke Feedback: robert@typo3.org FLOW3: http://flow3.typo3.org