SlideShare une entreprise Scribd logo
1  sur  67
Stephan Schmidt, 1&1 Internet AG Component and Event-Driven Architectures Building Flexible Applications in PHP5
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The speaker ,[object Object],[object Object],[object Object],[object Object]
Desktop Applications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Web Applications ,[object Object],[object Object],[object Object],[object Object]
Web Applications Web server generates HTML form needs to restore state extract request generate new form Client renders page user enters data renders page sends HTML sends new request sends updated HTML
Web Applications ,[object Object],[object Object],[object Object],[object Object],[object Object]
Web Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Web Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Web Components ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ASP.NET Way ,[object Object],[object Object],<form  runat=&quot;server&quot; > <asp:Button id=&quot;Button1&quot; runat=&quot;server&quot;   Text=&quot;Click Me&quot;>   </asp:Button> </form>
The ASP.NET Way ,[object Object],[object Object],[object Object]
ASP.Net Web Matrix
User Interaction ,[object Object],[object Object],[object Object]
ASP.NET: Event Handling public class WebForm1 : System.Web.UI.Page{   protected System.Web.UI.WebControls.Button Button1; // Handler for onClick   private void Button1_ClickHandler (object sender,    System.EventArgs e) {   Response.Write( &quot;You clicked Button1&quot; );   } // register the    override protected void OnInit(EventArgs e) { this.Button1.Click += new   System.EventHandler(this.Button1_ClickHandler);   base.OnInit(e);   } }
Java Server Faces ,[object Object],[object Object],[object Object],[object Object],[object Object]
Java Server Faces ,[object Object],[object Object],[object Object],[object Object],[object Object]
JSF Example <%@ page contentType=&quot;text/html&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot;   prefix=&quot;h&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot;   prefix=&quot;f&quot; %> <f:view> <h:form> Name: <h:inputText id=&quot;name&quot; size=&quot;8&quot;/> Pass: <h:inputSecret id=&quot;pass&quot; size=&quot;8&quot;/> <h:commandButton value=&quot;Login&quot; action=&quot;#{authHandler.login}&quot;/> </h:form> </f:view>
JSF Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Components in PHP ,[object Object],[object Object],[object Object],[object Object]
patForms ,[object Object],[object Object],[object Object],[object Object],[object Object]
patForms Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
patForms Page Structure Form Renderer Elements Element Validation Rules Filters Observers Child elements
patForms Example $form = patForms::createForm(); $form->setAttribute('name', 'myForm'); $username = array( 'required'  => 'yes', 'display'  => 'yes', 'edit'  => 'yes', 'label'  => 'Username', 'description' => 'Enter your username here.', 'default'  => '', 'maxlength'  => '15', 'minlength'  => '4', 'title'  => 'Username', ); $user = $form->createElement('user', 'String',  $username); $form->addElement($user);
patForms Example // more elements are created and added …… $renderer = patForms::createRenderer('Array'); $renderer-> $form->setRenderer($renderer); $form->setAutoValidate('mySubmitVar'); if ($form->isSubmitted()) { // check for errors } $elements = $form->renderForm(); // insert the elements in the HTML template
patForms Example <form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;example.php&quot;> Username<br /> <input id=&quot;pfo1&quot; name=&quot;user&quot; type=&quot;text&quot; title=&quot;Username&quot; value=&quot;&quot; maxlength=&quot;15&quot; /> <br /> Password<br /> <input id=&quot;pfo2&quot; name=&quot;pass&quot; type=&quot;password&quot; title=&quot;Password&quot; value=&quot;&quot; maxlength=&quot;15&quot; /> <br /> <input id=&quot;pfo3&quot; type=&quot;submit&quot; name=&quot;save&quot; value=&quot;Save form&quot;/> </form>
patForms Parser ,[object Object],[object Object],[object Object],[object Object]
patForms Example 2 <div> Username:<br /> <patForms:String name=&quot;username&quot; required=&quot;yes&quot; description=&quot;Please enter your name here&quot; size=&quot;8&quot; maxlength=&quot;8&quot; accesskey=&quot;U&quot; /> <br /> Password:<br /> <patForms:String name=&quot;password&quot; type=&quot;password&quot;  required=&quot;yes&quot; size=&quot;6&quot; maxlength=&quot;6&quot;  accesskey=&quot;P&quot; /> </div>
patForms Example 2 patForms_Parser::setNamespace('patForms'); patForms_Parser::setCacheDir('cache'); $form =& patForms_Parser::createFormFromTemplate(  'SimpleRenderer',  'templates/example_parser_simple.fhtml', 'templates/example_parser_simple.html' ); $form->setAutoValidate('save'); $form->registerEventHandler('onSuccess',  'handleUserInput'); $form->registerEventHandler('onError',  'displayErrors'); print $form->renderForm();
Interaction with PHP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
patForms Example 3 <patForms:Enum name=&quot;heroDC&quot; required=&quot;yes&quot;   label=&quot;DC-Heroes&quot;> <patForms:Datasource type=&quot;custom&quot;> <hero:getDatasource id=&quot;DC&quot;/> </patForms:Datasource> </patForms:Enum> class Datasource_DC { public function getValues() { // open DB connection and fetch the // possible values from the database } }
patForms Example 3 class heroHandler { public function getDatasource($attributes,$content){ $dsName =  'Datasource_'.$attributes['id']; return new $dsName; } } $parser = patForms_Parser::createParser(…); $heroHandler = new heroHandler; $parser->addNamespace('hero', $heroHandler); $parser->parseFile( 'form.fhtml'); $form = $parser->getForm(); $form->setRenderer($parser); $content = $form->renderForm();
PRADO ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PRADO Example <html> <head> <title>Hello, world!</title> </head> <body> <com:TForm> <com:TButton Text=&quot;Click me&quot; OnClick=&quot;clickMe&quot; /> </com:TForm> </body> </html> class HomePage extends TPage { public function clickMe($sender,$param) { $sender->Text=&quot;Hello, world!; } }
PRADO Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <application state=&quot;debug&quot;> <request default=&quot;HomePage&quot; /> <session enabled=&quot;true&quot; /> <vsmanager enabled=&quot;true&quot; /> <alias name=&quot;Pages&quot; path=&quot;.&quot; /> <using namespace=&quot;System.Web.UI.WebControls&quot; /> <using namespace=&quot;Pages&quot; /> </application> require_once '/path/to/prado.php'; $app = pradoGetApplication('helloworld.spec'); $app->run();
PRADO Component ,[object Object],[object Object],<component> <property name=&quot;Text&quot; get=&quot;getText&quot; set=&quot;setText&quot;  type=&quot;string&quot; /> … more properties… <event name=&quot;OnClick&quot; /> <event name=&quot;OnCommand&quot; /> </component>
Problems ,[object Object],[object Object],[object Object]
Event-based development ,[object Object],[object Object],[object Object]
Example ,[object Object],Auth-Container Logger triggers event registers for &quot;onLogin&quot; informs listener onLogin onLogin
Advantages of events ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cocoa's Notification Center ,[object Object],[object Object],[object Object],[object Object],[object Object]
Notification ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Notification Center ,[object Object],[object Object],[object Object]
Notification Queue ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PEAR::Event_Dispatcher ,[object Object],[object Object],[object Object],[object Object],[object Object]
The Auth class class Auth { private $dispatcher = null; private $username = null; public function __construct() { } public function login($user, $pass) { // your auth code goes here $this->username = $user; $this->dispatcher->post($this, 'onLogin'); } public function getUsername() { return $this->username; } }
Adding the dispatcher class Auth { private $disp = null; private $username = null; public function __construct() { $this->disp = Event_Dispatcher::getInstance(); } public function login($user, $pass) { // your auth code goes here $this->username = $user; $this->disp->post($this, 'onLogin'); } public function getUsername() { return $this->username; } }
The Logger class UserLogger { var $fp; public function __construct($fname) { $this->fp = fopen($fname, 'a'); } public function __destruct() { fclose($this->fp); } public function append($event) { $data = array( date('Y-m-d H:s:s', time()), $event->getNotificationName(), $event->getNotificationObject()->getUsername() ); fputs($this->fp, implode('|', $data) . &quot;&quot;); } }
The Glue $auth  = new Auth(); $logger = new UserLogger('./user.log'); $dispatcher = Event_Dispatcher::getInstance(); $dispatcher->addObserver(array($logger, 'append'),  'onLogin'); $auth->login('schst', 'secret'); 2005-04-30 21:34:34|onLogin|schst
Adding a second event ,[object Object],class Auth { … public function logout() { // your logout code goes here $this->disp->post($this, 'onLogout'); $this->username = null; } } $dispatcher->addObserver(array($logger, 'append'),  'onLogout');
Catch'em all ,[object Object],$dispatcher = Event_Dispatcher::getInstance(); $dispatcher->addObserver(array($logger, 'append')); 2005-04-30 22:43:43|onLogin|schst 2005-04-30 22:43:43|onLogout|schst
Example 2 ,[object Object],Auth-Container Logger triggers event registers for &quot;onLogin&quot; BlackList-Check registers for &quot;onLogin&quot; cancel cancel onLogin onLogin
Canceling events ,[object Object],[object Object],[object Object],[object Object]
Canceling events function blacklist($event) { $uname = $event->getNotificationObject()->getUsername(); if ($uname == 'schst') { $event->cancelNotification(); } } $dispatcher = Event_Dispatcher::getInstance(); $dispatcher->addObserver('blacklist', 'onLogin'); $dispatcher->addObserver(array($logger, 'append')); $auth->login('schst', 'secret'); $auth->login('luckec', 'pass'); 2005-04-30 22:49:49|onLogin|luckec
Canceling events ,[object Object],public function login($user, $pass) { // your auth code goes here $this->username = $user; $event = $this->disp->post($this, 'onLogin'); if ($event->isNotificationCancelled()) { $this->username = null; } }
Logging blocked users ,[object Object],function blacklist($event) { $uname =   $event->getNotificationObject()->getUsername(); if ($uname == 'schst') { $event->cancelNotification(); $disp = Event_Dispatcher::getInstance(); $disp->post($event->getNotificationObject(),  'onBlocked'); } } 2005-04-30 22:28:28|onBlocked|schst 2005-04-30 22:28:28|onLogin|luckec
Event bubbling ,[object Object],dispatcher A dispatcher B sender application observers observers onLogin onLogin onOrder onOrder
Event bubbling ,[object Object],$disp1 = Event_Dispatcher::getInstance('foo'); $disp2 = Event_Dispatcher::getInstance('bar'); Dispatchers can be nested: $disp2->addNestedDispatcher($disp1); Notifications will be broadcasted: $disp2->post($this, 'onBar');
Event bubbling Example ,[object Object],class Auth { private $disp = null; private $username = null; public function __construct($type) { $this->disp =  Event_Dispatcher::getInstance($type); $global = Event_Dispatcher::getInstance(); $this->disp->addNestedDispatcher($global); } … }
Event bubbling Example $authDB  = new Auth('DB'); $authLDAP = new Auth('LDAP'); $logger  = new UserLogger('./user.log'); $dbLogger  = new UserLogger('./user-db.log'); $ldapLogger = new UserLogger('./user-ldap.log'); $global = Event_Dispatcher::getInstance(); $global->addObserver(array($logger, 'append')); $db = Event_Dispatcher::getInstance('DB'); $db->addObserver(array($dbLogger, 'append')); $ldap = Event_Dispatcher::getInstance('LDAP'); $ldap->addObserver(array($ldapLogger, 'append')); $authDB->login('schst', 'secret'); $authLDAP->login('luckec', 'pass');
patPortal ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
patPortal Example ,[object Object],[object Object],[object Object],[object Object],[object Object]
patPortal Example <event:event name=&quot;onPageNotFound&quot;> <event:listener name=&quot;Redirect&quot; cancelEvent=&quot;true&quot;> <event:params> <event:param name=&quot;path&quot; value=&quot;HomePage&quot;/> </event:params> </event:listener> private function callPage($path) { if (!$this->sitemap->pageExists($path)) { $event = $this->eventManager->raiseEvent ('PageNotFound', $path); $path  = $event->getContext(); if (!$event->isCancelled()) { … handle the error internally… } } }
patPortal built-in events ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
patPortal custom events ,[object Object],$this->eventManager->raiseEvent( 'EventName', $context); Events triggered by the request: <request:request type=&quot;HTTP&quot;> <request:properties> <request:property name=&quot;argh&quot; trigger=&quot;ArghReceived&quot;/> <request:property name=&quot;__action&quot;  match=&quot;/^Logout$/i&quot; trigger=&quot;Logout&quot;/> </request:properties> </request:request>
Further Reading ,[object Object],[object Object],[object Object],[object Object],[object Object]
The end ,[object Object],[object Object],[object Object],[object Object],Stephan Schmidt, 1&1 Internet AG

Contenu connexe

Tendances (20)

Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
Php
PhpPhp
Php
 
lf-2003_01-0269
lf-2003_01-0269lf-2003_01-0269
lf-2003_01-0269
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
PHP
PHPPHP
PHP
 
PDF Localization
PDF  LocalizationPDF  Localization
PDF Localization
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 

Similaire à Component and Event-Driven Architectures in PHP

Similaire à Component and Event-Driven Architectures in PHP (20)

Struts2
Struts2Struts2
Struts2
 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Getting the Most Out of OpenSocial Gadgets
Getting the Most Out of OpenSocial GadgetsGetting the Most Out of OpenSocial Gadgets
Getting the Most Out of OpenSocial Gadgets
 
Lecture3
Lecture3Lecture3
Lecture3
 
CIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NETCIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NET
 
2310 b 04
2310 b 042310 b 04
2310 b 04
 
Flex For Flash Developers Ff 2006 Final
Flex For Flash Developers Ff 2006 FinalFlex For Flash Developers Ff 2006 Final
Flex For Flash Developers Ff 2006 Final
 
JavaScript
JavaScriptJavaScript
JavaScript
 
ASP_NET Features
ASP_NET FeaturesASP_NET Features
ASP_NET Features
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page Creation
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
HTML5 Fundamentals
HTML5 FundamentalsHTML5 Fundamentals
HTML5 Fundamentals
 
Krazykoder struts2 plugins
Krazykoder struts2 pluginsKrazykoder struts2 plugins
Krazykoder struts2 plugins
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Ajaxppt
AjaxpptAjaxppt
Ajaxppt
 
Ajaxppt
AjaxpptAjaxppt
Ajaxppt
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 

Plus de Stephan Schmidt

Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesStephan Schmidt
 
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen solltenStephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen solltenStephan Schmidt
 
Continuous Integration mit Jenkins
Continuous Integration mit JenkinsContinuous Integration mit Jenkins
Continuous Integration mit JenkinsStephan Schmidt
 
Die Kunst des Software Design - Java
Die Kunst des Software Design - JavaDie Kunst des Software Design - Java
Die Kunst des Software Design - JavaStephan Schmidt
 
Der Erfolgreiche Programmierer
Der Erfolgreiche ProgrammiererDer Erfolgreiche Programmierer
Der Erfolgreiche ProgrammiererStephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.Stephan Schmidt
 
Die Kunst Des Software Design
Die Kunst Des Software DesignDie Kunst Des Software Design
Die Kunst Des Software DesignStephan Schmidt
 
Software-Entwicklung Im Team
Software-Entwicklung Im TeamSoftware-Entwicklung Im Team
Software-Entwicklung Im TeamStephan Schmidt
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5Stephan Schmidt
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPStephan Schmidt
 
XML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit FlashXML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit FlashStephan Schmidt
 
Interprozesskommunikation mit PHP
Interprozesskommunikation mit PHPInterprozesskommunikation mit PHP
Interprozesskommunikation mit PHPStephan Schmidt
 
Dynamische Websites mit XML
Dynamische Websites mit XMLDynamische Websites mit XML
Dynamische Websites mit XMLStephan Schmidt
 
Web 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface LibraryWeb 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface LibraryStephan Schmidt
 

Plus de Stephan Schmidt (17)

Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
 
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
 
Continuous Integration mit Jenkins
Continuous Integration mit JenkinsContinuous Integration mit Jenkins
Continuous Integration mit Jenkins
 
Die Kunst des Software Design - Java
Die Kunst des Software Design - JavaDie Kunst des Software Design - Java
Die Kunst des Software Design - Java
 
PHP mit Paul Bocuse
PHP mit Paul BocusePHP mit Paul Bocuse
PHP mit Paul Bocuse
 
Der Erfolgreiche Programmierer
Der Erfolgreiche ProgrammiererDer Erfolgreiche Programmierer
Der Erfolgreiche Programmierer
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
 
Die Kunst Des Software Design
Die Kunst Des Software DesignDie Kunst Des Software Design
Die Kunst Des Software Design
 
Software-Entwicklung Im Team
Software-Entwicklung Im TeamSoftware-Entwicklung Im Team
Software-Entwicklung Im Team
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
 
XML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit FlashXML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit Flash
 
Interprozesskommunikation mit PHP
Interprozesskommunikation mit PHPInterprozesskommunikation mit PHP
Interprozesskommunikation mit PHP
 
PHP im High End
PHP im High EndPHP im High End
PHP im High End
 
Dynamische Websites mit XML
Dynamische Websites mit XMLDynamische Websites mit XML
Dynamische Websites mit XML
 
Web 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface LibraryWeb 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface Library
 

Dernier

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 

Dernier (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 

Component and Event-Driven Architectures in PHP

  • 1. Stephan Schmidt, 1&1 Internet AG Component and Event-Driven Architectures Building Flexible Applications in PHP5
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Web Applications Web server generates HTML form needs to restore state extract request generate new form Client renders page user enters data renders page sends HTML sends new request sends updated HTML
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 14.
  • 15. ASP.NET: Event Handling public class WebForm1 : System.Web.UI.Page{ protected System.Web.UI.WebControls.Button Button1; // Handler for onClick private void Button1_ClickHandler (object sender, System.EventArgs e) { Response.Write( &quot;You clicked Button1&quot; ); } // register the override protected void OnInit(EventArgs e) { this.Button1.Click += new System.EventHandler(this.Button1_ClickHandler); base.OnInit(e); } }
  • 16.
  • 17.
  • 18. JSF Example <%@ page contentType=&quot;text/html&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %> <%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %> <f:view> <h:form> Name: <h:inputText id=&quot;name&quot; size=&quot;8&quot;/> Pass: <h:inputSecret id=&quot;pass&quot; size=&quot;8&quot;/> <h:commandButton value=&quot;Login&quot; action=&quot;#{authHandler.login}&quot;/> </h:form> </f:view>
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. patForms Page Structure Form Renderer Elements Element Validation Rules Filters Observers Child elements
  • 24. patForms Example $form = patForms::createForm(); $form->setAttribute('name', 'myForm'); $username = array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Username', 'description' => 'Enter your username here.', 'default' => '', 'maxlength' => '15', 'minlength' => '4', 'title' => 'Username', ); $user = $form->createElement('user', 'String', $username); $form->addElement($user);
  • 25. patForms Example // more elements are created and added …… $renderer = patForms::createRenderer('Array'); $renderer-> $form->setRenderer($renderer); $form->setAutoValidate('mySubmitVar'); if ($form->isSubmitted()) { // check for errors } $elements = $form->renderForm(); // insert the elements in the HTML template
  • 26. patForms Example <form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;example.php&quot;> Username<br /> <input id=&quot;pfo1&quot; name=&quot;user&quot; type=&quot;text&quot; title=&quot;Username&quot; value=&quot;&quot; maxlength=&quot;15&quot; /> <br /> Password<br /> <input id=&quot;pfo2&quot; name=&quot;pass&quot; type=&quot;password&quot; title=&quot;Password&quot; value=&quot;&quot; maxlength=&quot;15&quot; /> <br /> <input id=&quot;pfo3&quot; type=&quot;submit&quot; name=&quot;save&quot; value=&quot;Save form&quot;/> </form>
  • 27.
  • 28. patForms Example 2 <div> Username:<br /> <patForms:String name=&quot;username&quot; required=&quot;yes&quot; description=&quot;Please enter your name here&quot; size=&quot;8&quot; maxlength=&quot;8&quot; accesskey=&quot;U&quot; /> <br /> Password:<br /> <patForms:String name=&quot;password&quot; type=&quot;password&quot; required=&quot;yes&quot; size=&quot;6&quot; maxlength=&quot;6&quot; accesskey=&quot;P&quot; /> </div>
  • 29. patForms Example 2 patForms_Parser::setNamespace('patForms'); patForms_Parser::setCacheDir('cache'); $form =& patForms_Parser::createFormFromTemplate( 'SimpleRenderer', 'templates/example_parser_simple.fhtml', 'templates/example_parser_simple.html' ); $form->setAutoValidate('save'); $form->registerEventHandler('onSuccess', 'handleUserInput'); $form->registerEventHandler('onError', 'displayErrors'); print $form->renderForm();
  • 30.
  • 31. patForms Example 3 <patForms:Enum name=&quot;heroDC&quot; required=&quot;yes&quot; label=&quot;DC-Heroes&quot;> <patForms:Datasource type=&quot;custom&quot;> <hero:getDatasource id=&quot;DC&quot;/> </patForms:Datasource> </patForms:Enum> class Datasource_DC { public function getValues() { // open DB connection and fetch the // possible values from the database } }
  • 32. patForms Example 3 class heroHandler { public function getDatasource($attributes,$content){ $dsName = 'Datasource_'.$attributes['id']; return new $dsName; } } $parser = patForms_Parser::createParser(…); $heroHandler = new heroHandler; $parser->addNamespace('hero', $heroHandler); $parser->parseFile( 'form.fhtml'); $form = $parser->getForm(); $form->setRenderer($parser); $content = $form->renderForm();
  • 33.
  • 34. PRADO Example <html> <head> <title>Hello, world!</title> </head> <body> <com:TForm> <com:TButton Text=&quot;Click me&quot; OnClick=&quot;clickMe&quot; /> </com:TForm> </body> </html> class HomePage extends TPage { public function clickMe($sender,$param) { $sender->Text=&quot;Hello, world!; } }
  • 35. PRADO Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <application state=&quot;debug&quot;> <request default=&quot;HomePage&quot; /> <session enabled=&quot;true&quot; /> <vsmanager enabled=&quot;true&quot; /> <alias name=&quot;Pages&quot; path=&quot;.&quot; /> <using namespace=&quot;System.Web.UI.WebControls&quot; /> <using namespace=&quot;Pages&quot; /> </application> require_once '/path/to/prado.php'; $app = pradoGetApplication('helloworld.spec'); $app->run();
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. The Auth class class Auth { private $dispatcher = null; private $username = null; public function __construct() { } public function login($user, $pass) { // your auth code goes here $this->username = $user; $this->dispatcher->post($this, 'onLogin'); } public function getUsername() { return $this->username; } }
  • 47. Adding the dispatcher class Auth { private $disp = null; private $username = null; public function __construct() { $this->disp = Event_Dispatcher::getInstance(); } public function login($user, $pass) { // your auth code goes here $this->username = $user; $this->disp->post($this, 'onLogin'); } public function getUsername() { return $this->username; } }
  • 48. The Logger class UserLogger { var $fp; public function __construct($fname) { $this->fp = fopen($fname, 'a'); } public function __destruct() { fclose($this->fp); } public function append($event) { $data = array( date('Y-m-d H:s:s', time()), $event->getNotificationName(), $event->getNotificationObject()->getUsername() ); fputs($this->fp, implode('|', $data) . &quot;&quot;); } }
  • 49. The Glue $auth = new Auth(); $logger = new UserLogger('./user.log'); $dispatcher = Event_Dispatcher::getInstance(); $dispatcher->addObserver(array($logger, 'append'), 'onLogin'); $auth->login('schst', 'secret'); 2005-04-30 21:34:34|onLogin|schst
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. Canceling events function blacklist($event) { $uname = $event->getNotificationObject()->getUsername(); if ($uname == 'schst') { $event->cancelNotification(); } } $dispatcher = Event_Dispatcher::getInstance(); $dispatcher->addObserver('blacklist', 'onLogin'); $dispatcher->addObserver(array($logger, 'append')); $auth->login('schst', 'secret'); $auth->login('luckec', 'pass'); 2005-04-30 22:49:49|onLogin|luckec
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. Event bubbling Example $authDB = new Auth('DB'); $authLDAP = new Auth('LDAP'); $logger = new UserLogger('./user.log'); $dbLogger = new UserLogger('./user-db.log'); $ldapLogger = new UserLogger('./user-ldap.log'); $global = Event_Dispatcher::getInstance(); $global->addObserver(array($logger, 'append')); $db = Event_Dispatcher::getInstance('DB'); $db->addObserver(array($dbLogger, 'append')); $ldap = Event_Dispatcher::getInstance('LDAP'); $ldap->addObserver(array($ldapLogger, 'append')); $authDB->login('schst', 'secret'); $authLDAP->login('luckec', 'pass');
  • 61.
  • 62.
  • 63. patPortal Example <event:event name=&quot;onPageNotFound&quot;> <event:listener name=&quot;Redirect&quot; cancelEvent=&quot;true&quot;> <event:params> <event:param name=&quot;path&quot; value=&quot;HomePage&quot;/> </event:params> </event:listener> private function callPage($path) { if (!$this->sitemap->pageExists($path)) { $event = $this->eventManager->raiseEvent ('PageNotFound', $path); $path = $event->getContext(); if (!$event->isCancelled()) { … handle the error internally… } } }
  • 64.
  • 65.
  • 66.
  • 67.