BEAR

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    BEAR - Presentation Transcript

    1. Resource oriented PHP5 framework. ROA - EDP - AOP - DI - Page
    2. Technology • ROA = Resource Oriented Architecture • EDP = Event driven Programing • AOP = Aspect Oriented Programing • DI = Dependency Injection • Page Oriented Design
    3. Features • • DI+AOP • • Dev • 100% UTF-8 • Strict PHP5 OOP + • (PEAR / Zend / Smarty) • CLI,
    4. 3 components • Page (Controller) • Resource (Model) • View
    5. Page, Resouces, and View • Page Resource CRUD View set Resource Page URI class Page_User_Index extends App_Page Uniform Interfac Link { public function onInit(){ DB, XML, Local/Remote Create ... Read $resource->read($params)->set(); Update } Delete public function onOutput(){ $this->display(); } View <html> <body>{$user}</body> </html>
    6. Page
    7. Page - Event Driven •1 • • on onClick onInit onOutput onAction onInject onExpection
    8. Page - File Structure 1 <?php include ‘App.php’; App/BEAR class Page_Blog_Entry_Latest extends App_Page { public function onInit(array $args) { ... } } BEAR_Main::run('Page_Blog_Entry_Latest');
    9. Page Output HTML
    10. 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');
    11. Page Output DATA
    12. 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 HTML BEAR_Main::run('Page_Blog_Entry_Latest');
    13. Page Form
    14. Form • PEAR::QuickForm FORM A • FORM B • {$form.name.error} {$form.name.html} {$form}
    15. Page Flow onInject onInject onInit onInit Error OK onOutput onOutput onAction
    16. Page - formAction class 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');
    17. Page Arguments
    18. Page Arguments • onInit(array $args) $args • $this->injectGet(‘id’); $id = $_GET[‘id]; $this->injectArg(‘id’, 5); CLI/
    19. Page Flow injectGet( $_GET ) onInject() $_COOKIE injectArg() CLI onClick(array $args) onInit(array $args) onOutput()
    20. Page Click
    21. Page - Clcik • “Click” Page • <a> {a} • Click
    22. Active Link Click Page Class class 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(){ ... ... }
    23. 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);
    24. {a} tag • <a> • click {a click=print} {/a} • val {a href="/" val=$values} {/a}
    25. Page - Cache
    26. Page Cache • Init Cache • Page Cache
    27. Page - Init Cache • init set • View class Page_Today_Index extends App_Page { public function onInit() { .... $resource->set(‘news’); ... $resource->set(‘weather’); } } $options = ('type'=>'init', 'life' => 600); BEAR_Main::run('Page_Today_Index', $options);
    28. Page - Page Cache • HTTP class Page_Today_Index extends App_Page { public function onInit() { .... $resource->set(‘news’); ... $resource->set(‘weather’); } } $options = ('type'=>'page', 'life' => 600); BEAR_Main::run('Page_Today_Index', $options);
    29. Resource
    30. 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
    31. Resource in REST(2) • Uniform Interface GET( PUT( POST ), DELETE •
    32. BEAR Resource BEAR
    33. 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
    34. Resource Request Resource CRUD
    35. Resource Request in REST • HTTP POST/GET/PUT/DELETE Resource POST REST Client GET PUT DELETE HTTP/1.1 200 OK GET /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 ...
    36. Resource Request in BEAR • BEAR HTTP • HTTP Page Resource Resource Object Resource POSTCreate class User_Blog extends Page { onCreate GETRead class User_Index extends App_Page onRead public function onRead($values) PUTUpdate SQL { Delete { onUpdate DELETE CREATE public function onInit(){ ... onDelete SELECT ... return $row; UPDATE $resource->read($params)->set(); } DELETE } } Ro public function onOutput(){ -Code $this->display(); -Header } -Body
    37. Ro
    38. 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(); } } Ro } return $array; public function onOutput(){ -Code or $this->display(); -Header return $Ro; } -Body
    39. Ro • HTTP • code, header, body • CRUD •
    40. Ro - Property • Code (200 OK, 400 Bad Req, 500 Err) • Header • Body • Link URI
    41. Resource Code
    42. Resource Code • HTTP Resource Page class User_Blog extends { class User_Index extends App_Page public function onRead($values) { { 500 Error public function onInit(){ ... ... return $row; $resource->read($params)->set(); } DB 400 Bad Request } } 200 OK public function onOutput(){ $this->display(); URI }
    43. 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
    44. AOP
    45. Resource - AOP • Ro (AOP) • phpdoc Before Advice Reource class Entry extends App_Ro { /** * read * * @return array Around Advice * * @aspect before Auth * @aspect around Timer */ onRead public function onRead($values) {
    46. Advice Type • • Before Advice After Advice Around Advice onRead onRead onRead Return Advice onRead
    47. Annotation required
    48. 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) {
    49. Resource link onlink
    50. 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; } }
    51. 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();
    52. Mock Resource
    53. 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();
    54. Pull Resource
    55. 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}
    56. 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
    57. Resource Pull Link
    58. Pull Resource • Pull • DNS id=100 ! entry_id=100 required blog_id blog_id=5 required user_id $_GET id=10 ?user_id=10
    59. 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 } }
    60. Static Resource
    61. Static Resource • URI • CSV, XML, Yaml •
    62. Resource Server • • BEAR
    63. Resource URI • URI • URI = Uniform Resource Indentifier ( ) Local Class Resource “blog/entry” class User_Blog extends App_Ro { Page class 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://blog/entry.xml”
    64. Resource Option • • read • create Once Exactly) POE (POST
    65. ROA
    66. ROA ROA 4 • Addressability • Statelessness • Connectedness • Uniform interface REST ( )
    67. ROA in BEAR • –Addressability $uri = ‘User/Profile’; • –Statelessness ->read($params); • –Connectedness ->link(‘blog’); • –Uniform interface
    68. View
    69. View • • • •
    70. View - Layout • page/ layout/ element/ layouts/ Create <html xmlns="http://www.w3.org/1999/xhtml"> elements/ <head> Read <title> Update Delete <h1>$layout.title</h1> {* *}{$layout.title} </title> </head> pages/ <body> {* *}{include file="elements/header.tpl"} {foreach item=row from=$entry} {* *}{$content_for_layout} $entry.title<br /> {* *}{$layout.footer} $entry.body<br /> </body> </html>
    71. 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
    72. View - Mobile • .mobile. tpl • UTF-8 • layout/default.tpl layout/default.mobile.tpl page/index.tpl page/index.mobile.tpl
    73. Other Libraries
    74. Image • GD( ), iMagic( ), Cairo( ) Cairo iMagic GD
    75. Cache Client resource init page Unified Cache Layer PEAR:Cache_Lite APC memcached
    76. Cache - File & APC • • • web APC>memcached IP
    77. Cache - Memcached • memcached cluster IP IP
    78. Auto Loader • require, include • • PEAR App_DB_Oracle App/Db/Oracle.php
    79. Java Script • bear.jquery.js BEAR • AJAX • QuickForm AJAX
    80. DI (Dependency Injection) •” ” • • •
    81. 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()
    82. DI - $foo = BEAR::dependency('App_Foo', $config, $options); echo $foo->getBar(); • new dependency • array $config1 •
    83. DB • BEAR_Query SQL • URI method dsn • DB LIMIT • AOP
    84. BEAR_Query class 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); }
    85. DB - Transaction class App_Ro_User extends App_Ro { /** * * @aspect around App_Aspect_Transaction */ public function onCreate($values) { $this->_query->insert($values); }
    86. 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 } }
    87. Error Panda
    88. Dev Page • • • •
    89. Dev - Log Application Log Smarty Variables Ajax Log Registry $_GLOBALS Include files
    90. Dev - Code PEAR / Zend
    91. BEAR Shell • CLI • AJAX web shell • phpdoc
    92. Security (1) • XSS Smaty {$val|escape} • SQL Mdb2::quote() Prepared Statement • CSRF ( ) One Time Token Post Once Exactly AJAX Cookie Verify
    93. Security (2) - Form HTML_QuickForm::exportValues() • setDefaults() / setConstants() public function(array $submit){ • } ... ” ” Are you sure ? Maybe YES NO
    94. Security (3) - Log • CRUD + URI + Val 2009/02/02 12:20AM [00ff] CREATE entry?title=my+big+day 2009/02/02 12:30AM [00ff] UPDATECREATE blog?title=great+blog 2009/02/02 12:20AM [00ff] user?name=giro&id=10 2009/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
    95. Security (4) - ACL •” ” Zend::ACL • ACL
    96. Thank you.
    SlideShare Zeitgeist 2009

    + akihito.koriyamaakihito.koriyama Nominate

    custom

    703 views, 0 favs, 2 embeds more stats

    BEAR is resource oriented PHP5 framework.

    ROA + more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 703
      • 630 on SlideShare
      • 73 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 72 views on http://www.bear-project.net
    • 1 views on http://static.slidesharecdn.com

    more

    All embeds
    • 72 views on http://www.bear-project.net
    • 1 views on http://static.slidesharecdn.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories