v0.9 (Saturday) for PHP5.2+
Key Concept• Intuitiveness• Drivability• Separation of concern• Minimalism
Software Design•    Page Controller•    RESTful     Resource Oriented Architecture•   Resource(Data) Transfer Object•   De...
••   Interface oriented design•                         Keep It Simple and Stupid
•                                   Page                                           Ro                                     ...
•           No Impedance mismatch•   Value    Document    Link•
• UA       (   )• CLI• jQuery
Software Technology  ROA - EDP - AOP - DI - Page
Basic• PHP 5.2+• +PEAR +Zend
•        ROA: Resource Oriented Architecture•        EDP: Event Driven Programing•        @OP: Attribute(Annotation) Orien...
(PoEAA)•    × Front Controller••                     Page                             Layout•    Service Locator•    DI = ...
MVC 3 Components   • Model   • View   • Controller
Bear 3 Components  • Resource  • View  • Page
Resource (Model)Page (Controller)               DB                    File            XML            Page      View     Cl...
Resource Independency
Resource (Model)Page (Controller)               DB                    File            XML              Page      View     ...
DB                        File        XML         Page                               Resource      read User?id=5         ...
•   CLI•
REST
ULC$SS
Client - Server (CS)      Resource               Server                        •           Client        Page
Client - Stateless - Server (CSS)                 Resourceread User?id=5           •             1                        ...
Client - Cache - Stateless - Server (C$SS)                 Resource                           •                Resource Ca...
Uniform - Client - Cache - Stateless - Server (UC$SS)                       Resource          onCreate   onRead   onUpdate...
Uniform - Layered - Client - Cache - Stateless - Server (ULC$SS)             Profile                             Follower  ...
RESTful• REST• REST      RESTful
BEAR RESTful                                                                         Resource    Page                     ...
Resource
Resource                                                                         Resource    Page                         ...
ROA• Resource Oriented Architecture•
ROA•    Addressability•    Statelessness•    Connectedness•    Uniform Interface
••• URI   URN + URL• URL   L   Locater   URI
•••   ”   ”
•••••
•• POST/GET/PUT/DELETE, C/R/U/D
RESTful•=      HTML
Resource in REST(1)http://www.excite.co.jp/weather/japan/area/?prid=4400&arid=4410                           http://yohei-...
Resource in REST(2)•                            Uniform Interface    GET(   PUT(   POST   ), DELETE•
BEAR Resource  BEAR
BEAR Resource                   “user/profile/?user_id=10”                   “post/number.xml”• URI                   “http...
Resource Request    Resource CRUD
Resource Request in REST      •              HTTP            POST/GET/PUT/DELETE                                          ...
Resource Request in BEAR     •   BEAR                            HTTP     •                                      HTTP     ...
Resource  read path/to/readme.txtResource
Resource create ro://self/Shop/Purchace/id=10Resource
Resource  read myOffice://room/reservation                                    Java / Perl / TesResource
Resource   I am not
ID (   )create ro://self/Shop/Purchace/id=10                       ID (   )   HTTP                   (WWW)
Ro
Resource Object                                       −          •                               Ro                       ...
Ro• HTTP• code, header, body• CRUD•
Ro - Property• Code (200 OK, 400 Bad Req, 500 Err)• Header• Body• Link      URI
Resource Code
Resource Code           •                     HTTP                                                                    Reso...
Ro - CRUD Interface                      BEAR     HTTP      SQL• onCreate($values)   create   POST     CREATE• onRead($val...
Resource Option
Template Option     •    $code, $body, $headers         Page$options[template] = user;$params = array(‘uri’ => $uri, ‘opti...
Cache Option            •                    HTML            •                                                        HTML...
Resource Request       /
Resource Request•   “                       ”     set()•   lazy                              onOutput()                   ...
Resource Set Option     value / object / lazy
set ‘value’•                                               string                       body     Page    $resource->read($...
set ‘object’•   view                          set      Page    $resource->read($params)->set(‘user’, ‘object’);     View  ...
set ‘lazy’•    view       Page    $resource->read($params1)->set(‘user’, ‘value’);    $resource->read($params2)->set(‘profi...
AOP
Resource - AOP       •     Ro                         (AOP)       •             phpdoc                                    ...
Advice Type••    Before Advice      After Advice   Around Advice                     onReadonRead                         ...
Annotationrequired
Resource - Annotation•         @required•       400(Bad Request)                               Reource    class App_Ro_Use...
Resource linkonlink
Ro - onLink              •                                   onLink                                                       ...
Resource Link   •class Page_User_Blog_Latest_Comment extends App_Page{  public function onInit(){                         ...
Mock Resource
Mock Resource           •                                                          No Resource                            ...
Pull Resource
Pull by View             •   Page     View       Push                 View     Resource          Pull                     ...
Pull Resource in Page             view                             ”Pull” top/logo                                        ...
Static Resource
Static Resource•                    URI•    CSV, XML, Yaml•
Resource URI    •                                          URI    •    URI = Uniform Resource Indentifier (                ...
Resource Option•• read• create Once Exactly)  POE (POST
Page                                                                         Resource    Page                             ...
Page - Event Driven•1••            ononClick     onInit       onOutput   onActiononInject   onExpection
Page - File Structure                                  1<?phpinclude   ‘App.php’;   App/BEARclass Page_Blog_Entry_Latest e...
Page Output   HTML
Page - output - html  class Page_Blog_Entry_Latest extends App_Page  {    public function onInit(array $args)    {       $...
Page Output   DATA
Page - output   class Page_Blog_Entry_Latest extends App_Page   {     public function onInit(array $args)     {         $r...
Page Form
Form• PEAR::QuickForm•                                     FORM A                                         FORM B••        ...
Page FlowonInject                 onInject onInit                     onInit                    Error            OKonOutpu...
Page - formActionclass Page_Form_Simple extends App_Page{                                          secure      public func...
Page Arguments
Page Arguments     • onInit(array $args)   $args     •                                $this->injectGet(‘id’);$id = $_GET[‘...
Page Flow               injectGet(    $_GET               )  onInject()                 $_COOKIE               injectArg()...
Page Click
Page - Clcik• “Click”   Page• <a>               {a}•                  Click
Active Link Click   Page Classclass Help extends App_Page                                     •   onClick<           >    ...
Redirect Click             •     Click                                                    Page B                          ...
{a} tag•         <a>    •   click        {a click=print}            {/a}    •   val        {a href="/" val=$values}       ...
Page - Cache
Page Cache• Init Cache• Page Cache
Page - Init Cache•   init set•   View               class Page_Today_Index extends App_Page               {               ...
Page - Page Cache• HTTP         class Page_Today_Index extends App_Page         {           public function onInit() {    ...
View                                                                         Resource    Page                             ...
View
View•••• UA
View - Layout             •   page/ layout/ element/  layouts/<html xmlns="http://www.w3.org/1999/xhtml">                 ...
View - Static and Mobile            •                                 YAML            •     {$layout}            •     def...
View - Mobile•                                           .mobile.                tpl•                          UTF-8•    l...
Other Libraries
Image     •         GD(       ),         iMagic(        ),         Cairo(         )                             Cairo     ...
Cache                        Client                                 resource                                   init       ...
Cache - File & APC•••   web           APC>memcached             IP
Cache - Memcached•                        memcached                          cluster     IP                   IP
Auto Loader• require, include••                     PEAR               (PSR-0)  App_DB_Oracle      App/Db/Oracle.php
Java Script• bear.jquery.js BEAR• AJAX• QuickForm AJAX
DI (Dependency Injection)•”   ”•••
DI -class App_Foo extends BEAR_Base{	 public function __construct(array $config)     1.	 {	 	 parent::__construct($config)...
DI -$foo = BEAR::dependency(App_Foo, $config, $options);echo $foo->getBar();•   new             dependency•               ...
DB• BEAR_Query•                           URI      method dsn• DB      SELECT                    LIMIT                    ...
BEAR_Queryclass App_Ro_User_Entry extends App_Ro{    public function onInject()    {        parent::onInject();           ...
DB - Transactionclass App_Ro_User extends App_Ro{  /**   *  * @aspect around App_Aspect_Transaction  */ public function on...
onPull           •    onPull                                                        class App_Ro_User_Blog extends App_Ro ...
ErrorPanda
Dev•••
Dev - Log            Application Log        Smarty Variables               Ajax Log               Registry             $_G...
Dev - Code             PEAR / Zend
BEAR Shell     •   CLI     •   AJAX            web shell     •                phpdoc
Security (1)• XSS           Smaty {$val|escape}• SQL             Mdb2::quote()       Prepared Statement• CSRF (           ...
Security (2) - Form                                         HTML_QuickForm::exportValues()•                      setDefaul...
Security (3) - Log•                       CRUD + URI + Val2009/02/02 12:20AM [00ff] CREATE entry?title=my+big+day2009/02/0...
Security (4) - ACL•”                 ”                   Zend::ACL• ACL
Security (5) - CSRF•• bear.jquery.js   CSRF                    Double-Submit Cookie CSRF defense
Next•            web•       (Android iPhone•    •               (AJAX)    •
Thank you for joining.
BEAR v0.9 (Saturday)
BEAR v0.9 (Saturday)
Upcoming SlideShare
Loading in …5
×

BEAR v0.9 (Saturday)

6,515 views

Published on

BEAR is resource oriented PHP framework.

Published in: Technology

BEAR v0.9 (Saturday)

  1. 1. v0.9 (Saturday) for PHP5.2+
  2. 2. Key Concept• Intuitiveness• Drivability• Separation of concern• Minimalism
  3. 3. Software Design• Page Controller• RESTful Resource Oriented Architecture• Resource(Data) Transfer Object• Dependency Service Locator• BEAR_Base
  4. 4. •• Interface oriented design• Keep It Simple and Stupid
  5. 5. • Page Ro Resource Ro View• App.php• Use Inject AOP @OP Factory Dependency• GoF PoEAA• phpunit
  6. 6. • No Impedance mismatch• Value Document Link•
  7. 7. • UA ( )• CLI• jQuery
  8. 8. Software Technology ROA - EDP - AOP - DI - Page
  9. 9. Basic• PHP 5.2+• +PEAR +Zend
  10. 10. • ROA: Resource Oriented Architecture• EDP: Event Driven Programing• @OP: Attribute(Annotation) Oriented Programing • AOP: Aspect Oriented Programing
  11. 11. (PoEAA)• × Front Controller•• Page Layout• Service Locator• DI = Dependency Injection
  12. 12. MVC 3 Components • Model • View • Controller
  13. 13. Bear 3 Components • Resource • View • Page
  14. 14. Resource (Model)Page (Controller) DB File XML Page View Client Resource CRUD I/F RO read User?id=5 Private CRUD Resource Access Code Header Page Body View GET /user?id=5 Public HTTP Access HTML Bot PC JS JSON Mobile Game iPhone XML
  15. 15. Resource Independency
  16. 16. Resource (Model)Page (Controller) DB File XML Page View Client Resource CRUD I/F RO read User?id=5 Private CRUD Resource Access Code Header Page Body View GET /user?id=5 RO Public HTTP Access HTML Bot PC JS Socket CLI REST JSON Mobile Game iPhone XML
  17. 17. DB File XML Page Resource read User?id=5 RoROA -int Code API -array Headers -array Body CLI / HTTP / Socket Interface Shell Socket REST Java / Perl / Ruby / Python
  18. 18. • CLI•
  19. 19. REST
  20. 20. ULC$SS
  21. 21. Client - Server (CS) Resource Server • Client Page
  22. 22. Client - Stateless - Server (CSS) Resourceread User?id=5 • 1 • set id=5; • get User; • Page
  23. 23. Client - Cache - Stateless - Server (C$SS) Resource • Resource Cache Page
  24. 24. Uniform - Client - Cache - Stateless - Server (UC$SS) Resource onCreate onRead onUpdate onDelete read User?id=5 • getUserName(5) Resource Cache Page
  25. 25. Uniform - Layered - Client - Cache - Stateless - Server (ULC$SS) Profile Follower • Cache Cache User • • • Cache Page
  26. 26. RESTful• REST• REST RESTful
  27. 27. BEAR RESTful Resource Page URIclass Page_User_Index extends App_Page Uniform Interfac Link{ public function onInit(){ DB, XML, Local/Remote Create ... Read ->read($params)->set(); Update } Delete public function onOutput(){ ->display(); } View <html> <body>{$user}</body> </html>
  28. 28. Resource
  29. 29. Resource Resource Page URIclass Page_User_Index extends App_Page Uniform Interfac Link{ public function onInit(){ DB, XML, Local/Remote Create ... Read ->read($params)->set(); Update } Delete public function onOutput(){ ->display(); } View <html> <body>{$user}</body> </html>
  30. 30. ROA• Resource Oriented Architecture•
  31. 31. ROA• Addressability• Statelessness• Connectedness• Uniform Interface
  32. 32. ••• URI URN + URL• URL L Locater URI
  33. 33. ••• ” ”
  34. 34. •••••
  35. 35. •• POST/GET/PUT/DELETE, C/R/U/D
  36. 36. RESTful•= HTML
  37. 37. Resource in REST(1)http://www.excite.co.jp/weather/japan/area/?prid=4400&arid=4410 http://yohei-y.blogspot.com/2005/04/rest-3.html
  38. 38. Resource in REST(2)• Uniform Interface GET( PUT( POST ), DELETE•
  39. 39. BEAR Resource BEAR
  40. 40. BEAR Resource “user/profile/?user_id=10” “post/number.xml”• URI “http://example.com/rss.xml”• CRUD Interface create read update delete• Link user blog
  41. 41. Resource Request Resource CRUD
  42. 42. Resource Request in REST • HTTP POST/GET/PUT/DELETE Resource POST REST Client GET PUT DELETE HTTP/1.1 200 OKGET /user?id=10 HTTP/1.0 Date: Wed, 04 Feb 2009 09:56:24 GMT Server: Apache/2.2.0 (Unix) Content-Type: text/html ...
  43. 43. Resource Request in BEAR • BEAR HTTP • HTTP Page Resource (Ro) Resource POSTCreate class User_Blog extends Page { onCreate GETReadclass User_Index extends App_Page onRead public function onRead($values) PUTUpdate SQL{ Delete { onUpdate DELETE INSERT public function onInit(){ ... onDelete SELECT ... return $row; UPDATE $resource->read($params)->set(); } DELETE } } Ro public function onOutput(){ -Code $this->display(); -Header } -Body
  44. 44. Resource read path/to/readme.txtResource
  45. 45. Resource create ro://self/Shop/Purchace/id=10Resource
  46. 46. Resource read myOffice://room/reservation Java / Perl / TesResource
  47. 47. Resource I am not
  48. 48. ID ( )create ro://self/Shop/Purchace/id=10 ID ( ) HTTP (WWW)
  49. 49. Ro
  50. 50. Resource Object − • Ro Resource Create Page Read class User_Blog extends App_Ro Update {class Page_User_Index extends App_Page Delete public function onRead($values){ { public function onInit(){ ... ... return $row; $resource->read($params)->set(‘user’); } } Ro } return $array; public function onOutput(){ -Code or $this->display(); -Header return $Ro; } -Body
  51. 51. Ro• HTTP• code, header, body• CRUD•
  52. 52. Ro - Property• Code (200 OK, 400 Bad Req, 500 Err)• Header• Body• Link URI
  53. 53. Resource Code
  54. 54. Resource Code • HTTP Resource Page class User_Blog extends {class User_Index extends App_Page public function onRead($values){ { 500 Internal Error public function onInit(){ ... ... return $row; $resource->read($params)->set(); } DB 400 Bad Request } } 200 OK public function onOutput(){ $this->display(); URI }
  55. 55. Ro - CRUD Interface BEAR HTTP SQL• onCreate($values) create POST CREATE• onRead($values) read GET SELECT• onUpdate($values) update PUT UPDATE• onDelete($values) delete DELETE DELETE
  56. 56. Resource Option
  57. 57. Template Option • $code, $body, $headers Page$options[template] = user;$params = array(‘uri’ => $uri, ‘options’ => $options); page template$resource->read($params)->set(‘user); value resource template resource html App/views/elements/user.tpl + =
  58. 58. Cache Option • HTML • HTML <p>{$user}</p> Value Page$options[cache][key] = user;$options[cache][life] = 60;...$resource->read($params)->set(‘user’, ‘object’);
  59. 59. Resource Request /
  60. 60. Resource Request• “ ” set()• lazy onOutput() view PHP$ro = $resource->read($params)->getRo(); Eager$body = $resource->read($params)->getBody();$resource->read($params)->set(‘user’); Lazy (onOutput)$resource->read($params)->set(‘user’, ‘lazy’); Lazy (view)$resource->update($params)->requestOnShutdown(); Lazy (shutdown)
  61. 61. Resource Set Option value / object / lazy
  62. 62. set ‘value’• string body Page $resource->read($params)->set(‘user’, ‘value’); View {$user} without template with template
  63. 63. set ‘object’• view set Page $resource->read($params)->set(‘user’, ‘object’); View as string as array as object {$user} {$user.name} {if $user->getCode() == 200}
  64. 64. set ‘lazy’• view Page $resource->read($params1)->set(‘user’, ‘value’); $resource->read($params2)->set(‘profile’, ‘lazy’); $resource->read($params2)->set(‘friend’, ‘lazy’); View ( UA ) for PC for iPhone for Mobile {$user} {$user} {$user} {$profile} {$profile} {$friend}
  65. 65. AOP
  66. 66. Resource - AOP • Ro (AOP) • phpdoc Before Advice Reourceclass Entry extends App_Ro{ /** * read * * @return array Around Advice * * @aspect before App_Aspect_Auth * @aspect around App_Aspect_Timer */ onRead public function onRead($values) {
  67. 67. Advice Type•• Before Advice After Advice Around Advice onReadonRead onRead Return Advice onRead
  68. 68. Annotationrequired
  69. 69. Resource - Annotation• @required• 400(Bad Request) Reource class App_Ro_User extends App_Ro { /** * create * * @return array * * @required name * @required age */ public function onCreate($values) {
  70. 70. Resource linkonlink
  71. 71. Ro - onLink • onLink Blog Reource User Reource class App_Ro_ User_Blog extends App_Ro {class App_Ro_User extends App_Ro public function onRead($values){ { public function onRead($values) $blogId = $values[‘id’]; { ... ... } return $row; } } public function onLink($values) { $links = array( ‘blog’=>”usr/blog/?id={$values[‘blog_id’]}”); return $links; }}
  72. 72. Resource Link •class Page_User_Blog_Latest_Comment extends App_Page{ public function onInit(){ Fluent Interface ... $resource->read($params)->link(‘blog’)->link(‘latest_entry’)->link(‘comment’)->set(); } ...link(‘comment’)->set()->p();
  73. 73. Mock Resource
  74. 74. Mock Resource • No Resource View Page$options[mock][name] = test;$options[mock][x] = array(name, age, gender);$options[mock][y] = 5;...$resource->read($params)->set();
  75. 75. Pull Resource
  76. 76. Pull by View • Page View Push View Resource Pull Reource class App_Ro_News_Today extends App_Ro { Page public function onRead($values)class Page_User_Index extends App_Page {{ retrun $news public function onOutput(){ } $this->display(); } } Push Pull View {if $showNews} {resource uri=”news/today” template=”news.tpl” values=$today} {resource uri=”socket:://example.com/int_news” template=”news.tpl”} {/if}
  77. 77. Pull Resource in Page view ”Pull” top/logo top/date news/pict top/news ad/media login/status stock/today ad/service media/topic ad/recmd ad/pr
  78. 78. Static Resource
  79. 79. Static Resource• URI• CSV, XML, Yaml•
  80. 80. Resource URI • URI • URI = Uniform Resource Indentifier ( ) Local Class Resource “blog/entry” = “ro://self/blog/entry” class User_Blog extends App_Ro { Pageclass User_Index extends App_Page Remote Class Resource (HTTP){ “http://example.com/blog/entry” Create public function onInit(){ Read Remote Class Resource (Socket) ... Update “socket://example.com/blog/entry” $resource->read($params)->set(); Delete } public function onOutput(){ Local File Resource $this->display(); “blog/entry.xml” } Remote File Resource “http://example.com/blog/entry.xml”
  81. 81. Resource Option•• read• create Once Exactly) POE (POST
  82. 82. Page Resource Page URIclass Page_User_Index extends App_Page Uniform Interfac Link{ public function onInit(){ DB, XML, Local/Remote Create ... Read ->read($params)->set(); Update } Delete public function onOutput(){ ->display(); } View <html> <body>{$user}</body> </html>
  83. 83. Page - Event Driven•1•• ononClick onInit onOutput onActiononInject onExpection
  84. 84. Page - File Structure 1<?phpinclude ‘App.php’; App/BEARclass Page_Blog_Entry_Latest extends App_Page{ public function onInit(array $args) { ... }}BEAR_Main::run(Page_Blog_Entry_Latest);
  85. 85. Page Output HTML
  86. 86. Page - output - html class Page_Blog_Entry_Latest extends App_Page { public function onInit(array $args) { $resource = BEAR::dependency(BEAR_Resource); $uri = Blog/Entry/Latest; URI $values[‘id’] = $args[‘blog_id’]; arguments $options[cache][life] = 60; Cache $options[pager] = 5; Pager // read and set $params = array(uri=>$uri, values=>$values, options=>$options); $resource->read($params)->set(); } What ? {$blog_entry_latest} public function onOutput() {$pager.link} { Convention Over Configuration $this->display(); Where ? page/blog/entry/latest.tpl } }BEAR_Main::run(Page_Blog_Entry_Latest);
  87. 87. Page Output DATA
  88. 88. Page - output class Page_Blog_Entry_Latest extends App_Page { public function onInit(array $args) { $resource = BEAR::dependency(BEAR_Resource); $uri = blog/entry/latest; $values[‘id’] = $args[‘blog_id’]; $options[cache][life] = 60; $options[pager] = 5; // read and set $params = array(uri=>$uri, values=>$values, options=>$options); $resource->read($params)->set(); } public function onOutput() { $this->output(‘json’); }} XML RSS Excel PHP JSON Flash HTMLBEAR_Main::run(Page_Blog_Entry_Latest);
  89. 89. Page Form
  90. 90. Form• PEAR::QuickForm• FORM A FORM B•• PC/ /...) {$form.name.error} {$form.name.html} {$form}
  91. 91. Page FlowonInject onInject onInit onInit Error OKonOutput onOutput onAction
  92. 92. Page - formActionclass Page_Form_Simple extends App_Page{ secure public function onAction(array $submit) { $this->set(submit, $submit); $this->display(simple.action.tpl); }}BEAR_Main::run(Page_Form_Simple);
  93. 93. Page Arguments
  94. 94. Page Arguments • onInit(array $args) $args • $this->injectGet(‘id’);$id = $_GET[‘id]; $this->injectArg(‘id’, 5); CLI/
  95. 95. Page Flow injectGet( $_GET ) onInject() $_COOKIE injectArg() CLI onClick(array $args) onInit(array $args) onOutput()
  96. 96. Page Click
  97. 97. Page - Clcik• “Click” Page• <a> {a}• Click
  98. 98. Active Link Click Page Classclass Help extends App_Page • onClick< > onInit(){ public function onClickUp(){ $this->_order = DESC; } template public function onClickHelp($id){ $this->showHelp($id); {a click=”Up”} {/a} } {a click=”Help” val=$helpId} {/a}public function onInit(){ ... ... }
  99. 99. Redirect Click • Click Page B class Page_Blog_Entry extends App_Page { public function onClickUp($user){ $this->_order = DESC; } Page A$options[click] = up;$options[val] = $user;self::redirect(blog/entry, $options);
  100. 100. {a} tag• <a> • click {a click=print} {/a} • val {a href="/" val=$values} {/a}
  101. 101. Page - Cache
  102. 102. Page Cache• Init Cache• Page Cache
  103. 103. Page - Init Cache• init set• View class Page_Today_Index extends App_Page { public function onInit() { .... $resource->set(‘news’); ... $resource->set(‘weather’); } } $options[‘cache’][type] = init; $options[‘cache’][life] = 600; BEAR_Main::run(Page_Today_Index, $options);
  104. 104. Page - Page Cache• HTTP class Page_Today_Index extends App_Page { public function onInit() { .... $resource->set(‘news’); ... $resource->set(‘weather’); } } $options[‘cache’][type] = page; $options[‘cache’][life] = 600; BEAR_Main::run(Page_Today_Index, $options);
  105. 105. View Resource Page URIclass Page_User_Index extends App_Page Uniform Interfac Link{ public function onInit(){ DB, XML, Local/Remote Create ... Read ->read($params)->set(); Update } Delete public function onOutput(){ ->display(); } View <html> <body>{$user}</body> </html>
  106. 106. View
  107. 107. View•••• UA
  108. 108. View - Layout • page/ layout/ element/ layouts/<html xmlns="http://www.w3.org/1999/xhtml"> Create elements/ <head> Read <title> Update {* *}{$layout.title} Delete <h1>$layout.title</h1> </title> </head> pages/ <body> {* *}{include file="elements/header.tpl"} {foreach item=row from=$entry} {* *}{$content_for_layout} $entry.title<br /> $entry.body<br /> {* *}{$layout.footer} </body></html>
  109. 109. View - Static and Mobile • YAML • {$layout} • default/mobile PC/ • tpl ” ” layout/default.tpl layout/default.mobile.tpl<html><header> <title>{$lauout.title}</title> page/user/blog.yaml</header> default:{$content_for_layout} title: Hello PC World.<body> mobile: title: Hello Mobile World. layout:default.tpl<body>{$layout.title}</body> page/user/blog.tpl page/user/blog.mobile.tpl
  110. 110. View - Mobile• .mobile. tpl• UTF-8• layout/default.tpl layout/default.mobile.tpl page/index.tpl page/index.mobile.tpl
  111. 111. Other Libraries
  112. 112. Image • GD( ), iMagic( ), Cairo( ) Cairo iMagicGD
  113. 113. Cache Client resource init page Unified Cache LayerPEAR:Cache_Lite APC memcached
  114. 114. Cache - File & APC••• web APC>memcached IP
  115. 115. Cache - Memcached• memcached cluster IP IP
  116. 116. Auto Loader• require, include•• PEAR (PSR-0) App_DB_Oracle App/Db/Oracle.php
  117. 117. Java Script• bear.jquery.js BEAR• AJAX• QuickForm AJAX
  118. 118. DI (Dependency Injection)•” ”•••
  119. 119. DI -class App_Foo extends BEAR_Base{ public function __construct(array $config) 1. { parent::__construct($config); } public function onInject() 2. { $this->_bar = BEAR::dependency(App_Bar); } public function getBar(){ 3. return $this->_bar->get(); }} __construct() onInject() factory()
  120. 120. DI -$foo = BEAR::dependency(App_Foo, $config, $options);echo $foo->getBar();• new dependency• array $config1•
  121. 121. DB• BEAR_Query• URI method dsn• DB SELECT LIMIT /Limit• AOP create/update
  122. 122. BEAR_Queryclass App_Ro_User_Entry extends App_Ro{ public function onInject() { parent::onInject(); 0=LIMIT 1=DB $this->_queryConfig[pager] = 1; $this->_queryConfig[perPage] = 5; $this->_query = BEAR::dependency(BEAR_Query, $this->_queryConfig,false); } public function onCreate($values) { $result = $this->_query->insert($values); } $values SQL public function onRead($values) { $values ... return $result = $this->_query->select($sql, $values); } DB LIMIT
  123. 123. DB - Transactionclass App_Ro_User extends App_Ro{ /** * * @aspect around App_Aspect_Transaction */ public function onCreate($values) { $this->_query->insert($values); }
  124. 124. onPull • onPull class App_Ro_User_Blog extends App_Ro {class App_Ro_User_Blog_Entry_Latest extends App_Ro /**{ * * @required user_id */ /** public function onRead($values){} * * @required blog_id */ public function onRead($values){} public function onPull($values) { // ask, map $pull = self::pullLink(user/blog); $values[blog_id] = $pull[id]; return $values }}
  125. 125. ErrorPanda
  126. 126. Dev•••
  127. 127. Dev - Log Application Log Smarty Variables Ajax Log Registry $_GLOBALS Include files
  128. 128. Dev - Code PEAR / Zend
  129. 129. BEAR Shell • CLI • AJAX web shell • phpdoc
  130. 130. Security (1)• XSS Smaty {$val|escape}• SQL Mdb2::quote() Prepared Statement• CSRF ( ) One Time Token Post Once Exactly AJAX Cookie Verify
  131. 131. Security (2) - Form HTML_QuickForm::exportValues()• setDefaults() / setConstants() public function(array $submit){• } ... ” ”Are you sure ? Maybe YES NO
  132. 132. Security (3) - Log• CRUD + URI + Val2009/02/02 12:20AM [00ff] CREATE entry?title=my+big+day2009/02/02 12:30AM [00ff] UPDATECREATE blog?title=great+blog 2009/02/02 12:20AM [00ff] user?name=giro&id=102009/02/02 12:30AM [00ff] DELETE UPDATE user?name=giro&id=10 2009/02/02 12:30AM [00ff] user?id=10 2009/02/02 12:20AM [00ff] CREATE user?name=taro&age=20&gender=m 2009/02/02 12:30AM [00ff] DELETE user?id=10 2009/02/02 12:30AM [00ff] UPDATE user?name=giro&id=10 2009/02/02 12:30AM [00ff] DELETE user?id=10
  133. 133. Security (4) - ACL•” ” Zend::ACL• ACL
  134. 134. Security (5) - CSRF•• bear.jquery.js CSRF Double-Submit Cookie CSRF defense
  135. 135. Next• web• (Android iPhone• • (AJAX) •
  136. 136. Thank you for joining.

×