BEAR (Sunday)
   PHP 5.3+ /5.4
1. namespace
1. namespace


use couponAppAuth as couponAuth;

use blogAppAuth as blogAuth;

read ro:://coupon/User?id=1
read ro:://blog/User?id=1
2. DI
Say goodbye to
BEAR::Dependency()
Say hello to
BEARDi::Container();
ra .Di
             Au
          by
      red
P owe
Dependency Injection
  the JSR 330 way

       DI
namespace BEARTestexampleAppLog;



/**                                             Singleton
  * BEAR
  *                                             Prototype
  * @Scope("singleton")               @Scope
  */                                            Session
class Log
{                                               Application
     /**
      * Reource
      *
      * @Inject                       @Inject   Property Injection
      *
      * @var Resource
      */
     private $resource;

    /**
     * Di
     *
     * @Inject
     *
     * @var Di
     */
    private $di;

    /**
     * Init
*
 * @var Di
 */
private $di;

/**
  * Init
  *
  * @PostConstruct
                                @PostConstruct Initialization
  */
public function onInit()
{
     $this->inited = true;
}

/**
  * @PreDestoroy                @PreDestory   Finalization
  */
public function onEnd()
{
}

/**
  * @Inject                     @Inject Setter Injection
  *
  * @param Db $db
  */
public function setDb(Db $db)
{
}
}

/**
  * @PreDestoroy                @PreDestory       Finalization
  */
public function onEnd()
{
}

/**
  * @Inject                     @Inject Setter Injection
  *
  * @param Db $db
  */
public function setDb(Db $db)
{
}

/**
  * @Inject
  * @Named("user=admin_user,db=test_db") @Named
  *
  * @param Db $db
  *
  */
public function setDouble(User $user, Db $db)
{
     $this->db = $db;
}
2. Annotation
•
•
•
/**
  * Blog info
  *
  * @Template(user.tpl)
  * @Cache(life=0)          Inversion of Control
  * @Pager(item=10)
  * @Pull(“ro://self/User/Login”)
  */
public function onRead($values)
{
     $this->set();
}




         @Pull
3.More Resource Oriented
App_Main::run($class);
App_Main::run($class);
$params = $di->get(‘params’)->setOption($option);
$page = $di->factory('testappAppPageHelloWorld');
$ro = $di->get('main')->request($page, $params)->getRo();
$ro->output();




                                                            Ro
3.Resource Interface
Page
                                 Ro


function request(Ro $ro, Params $params)

function output(Ro $ro)
Page
                                 Ro


function request(Ro $ro, Params $params)
Page
                                 Ro


function request(Ro $ro, Params $params)
Main
Page

                                    Page
                                    Ro


   function request(Ro $ro, Params $params)

   function output(Ro $ro)
PageAdapter::request(Ro $ro, Params $params);




Main
Page

                                               Page
                                               Ro


   function request(Ro $ro, Params $params)

   function output(Ro $ro)
PageAdapter::request(Ro $ro, Params $params);




Main
Page

                                               Page
                                               Ro


   function request(Ro $ro, Params $params)

   function output(Ro $ro)
mod_php


Web




                Apache         Page
                               Ro


      Web

      Apache   PHP
Resource Interface
                                       pageAdapter::request($page, $params);



                                                                  roAdapter::request($page, $params);



                                                                  read User?id=1
          GET /User?id=1      request($page, $params);         request($ro, $params);


Browser                    Main                      Page                          Ro
               HTTP                       $ro                           $ro
          $ro->output();




                                                                                   Ro
•

•   Page   Page
4.CQRS
CQRS
Command and Query
   Responsibility
    Segregation
CQS:




       -Bertrand Meyer
            http://d.hatena.ne.jp/digitalsoul/20100712/1278886009
CQRS + REST = ?
CQS:                                             DELETE
                                               UPDATE
                                              CREATE

                                              READ




                                         REST GET
                                    Side Effect FREE

       -Bertrand Meyer
              http://d.hatena.ne.jp/digitalsoul/20100712/1278886009
          DDD/Side -Effect-Free Functions - Java EE
CQRS + REST = BEAR
NoSQL
          QUERY
       read User?id=1




                               <h2>koriym</h2>
     Client                    <ul>
                               <li>name: Koriama</li>
                                                        Representation
                               </ul>




        COMMAND                                            Resource
update User?id=1&name=koriym

                                          RDB (MySQL)
NoSQL
           QUERY
        read User?id=1
Query    Command
                Query
                         Command


                                <h2>koriym</h2>
Command                        Query
     Client                     <ul>
                                <li>name: Koriama</li>
                                </ul>




          COMMAND         PC ,iPhone               AJAX   ...
  update User?id=1&name=koriym

                                           RDB (MySQL)
5.Compatibility
Compatibility
• Saturday(for 5.2)

•                     (=Shared nothing)
                                A

• Ro
•
                                ...
CM gtalk
                                        realtime
                         observe
                                    GUI MVC




         6.RealTime
$this->set(‘user’, $user, ‘realtime’);

$this->set(‘user’, $user, ‘ajax’);




                                                  bi ted
                                                Or
                                             by
                                         red
                                   P owe
7.Multi Language
       PHP Page      Java Resource


Objective-C Client   PHP Resource


                                                    hr ift
                                               b y T
                                      we red
                                    Po
8. Online editor
fully supported

                                 di tor
                            A ceE
                       by
                   red
              Powe
design memo at
https://gist.github.com/1111850

BEAR (Suday) design

  • 1.
    BEAR (Sunday) PHP 5.3+ /5.4
  • 2.
  • 3.
    1. namespace use couponAppAuthas couponAuth; use blogAppAuth as blogAuth; read ro:://coupon/User?id=1 read ro:://blog/User?id=1
  • 4.
  • 5.
  • 6.
  • 8.
    ra .Di Au by red P owe
  • 10.
    Dependency Injection the JSR 330 way DI
  • 11.
    namespace BEARTestexampleAppLog; /** Singleton * BEAR * Prototype * @Scope("singleton") @Scope */ Session class Log { Application /** * Reource * * @Inject @Inject Property Injection * * @var Resource */ private $resource; /** * Di * * @Inject * * @var Di */ private $di; /** * Init
  • 12.
    * * @varDi */ private $di; /** * Init * * @PostConstruct @PostConstruct Initialization */ public function onInit() { $this->inited = true; } /** * @PreDestoroy @PreDestory Finalization */ public function onEnd() { } /** * @Inject @Inject Setter Injection * * @param Db $db */ public function setDb(Db $db) { }
  • 13.
    } /** *@PreDestoroy @PreDestory Finalization */ public function onEnd() { } /** * @Inject @Inject Setter Injection * * @param Db $db */ public function setDb(Db $db) { } /** * @Inject * @Named("user=admin_user,db=test_db") @Named * * @param Db $db * */ public function setDouble(User $user, Db $db) { $this->db = $db; }
  • 14.
  • 15.
  • 16.
    /** *Blog info * * @Template(user.tpl) * @Cache(life=0) Inversion of Control * @Pager(item=10) * @Pull(“ro://self/User/Login”) */ public function onRead($values) { $this->set(); } @Pull
  • 17.
  • 18.
  • 19.
  • 20.
    $params = $di->get(‘params’)->setOption($option); $page= $di->factory('testappAppPageHelloWorld'); $ro = $di->get('main')->request($page, $params)->getRo(); $ro->output(); Ro
  • 21.
  • 22.
    Page Ro function request(Ro $ro, Params $params) function output(Ro $ro)
  • 23.
    Page Ro function request(Ro $ro, Params $params)
  • 24.
    Page Ro function request(Ro $ro, Params $params)
  • 25.
    Main Page Page Ro function request(Ro $ro, Params $params) function output(Ro $ro)
  • 26.
    PageAdapter::request(Ro $ro, Params$params); Main Page Page Ro function request(Ro $ro, Params $params) function output(Ro $ro)
  • 27.
    PageAdapter::request(Ro $ro, Params$params); Main Page Page Ro function request(Ro $ro, Params $params) function output(Ro $ro)
  • 28.
    mod_php Web Apache Page Ro Web Apache PHP
  • 29.
    Resource Interface pageAdapter::request($page, $params); roAdapter::request($page, $params); read User?id=1 GET /User?id=1 request($page, $params); request($ro, $params); Browser Main Page Ro HTTP $ro $ro $ro->output(); Ro
  • 30.
    • • Page Page
  • 31.
  • 32.
    CQRS Command and Query Responsibility Segregation
  • 33.
    CQS: -Bertrand Meyer http://d.hatena.ne.jp/digitalsoul/20100712/1278886009
  • 36.
  • 37.
    CQS: DELETE UPDATE CREATE READ REST GET Side Effect FREE -Bertrand Meyer http://d.hatena.ne.jp/digitalsoul/20100712/1278886009 DDD/Side -Effect-Free Functions - Java EE
  • 38.
  • 39.
    NoSQL QUERY read User?id=1 <h2>koriym</h2> Client <ul> <li>name: Koriama</li> Representation </ul> COMMAND Resource update User?id=1&name=koriym RDB (MySQL)
  • 40.
    NoSQL QUERY read User?id=1 Query Command Query Command <h2>koriym</h2> Command Query Client <ul> <li>name: Koriama</li> </ul> COMMAND PC ,iPhone AJAX ... update User?id=1&name=koriym RDB (MySQL)
  • 41.
  • 42.
    Compatibility • Saturday(for 5.2) • (=Shared nothing) A • Ro • ...
  • 43.
    CM gtalk realtime observe GUI MVC 6.RealTime $this->set(‘user’, $user, ‘realtime’); $this->set(‘user’, $user, ‘ajax’); bi ted Or by red P owe
  • 44.
    7.Multi Language PHP Page Java Resource Objective-C Client PHP Resource hr ift b y T we red Po
  • 45.
    8. Online editor fullysupported di tor A ceE by red Powe
  • 46.