第26回PHP勉強会

Preview:

Citation preview

eXtreme Hardcore PHP Development

Seasar.PHP明日から始める

~PHP4がサポート終了しても泣かない人たちへ~

eXtreme Hardcore PHP Development

自己紹介

• yonekawa 

• Seasar.PHPコミッタ 

• 昼はPHP4 夜はPHP5

eXtreme Hardcore PHP Development

eXtreme Hardcore PHP Development

eXtreme Hardcore PHP Development

• PHP4のサポート切れが2007年12月31日

• 徐々にPHP5へ移行する必要がある

• フレームワークもPHP4 Compatibleにこだわる必要はない

eXtreme Hardcore PHP Development

Seasar.PHP

• 元々は Javaのフレームワーク

• S2Containerというプロダクトを基本に様々なプロダクトをPHPに移植

• PHP5限定

eXtreme Hardcore PHP Development

S2Container.PHP5

S2Dao.PHP5 S2AnA.PHP5

S2Base.PHP5

eXtreme Hardcore PHP Development

S2Container.PHP5

eXtreme Hardcore PHP Development

DI × AOP

eXtreme Hardcore PHP Development

<component name=”server” class=”EchoServer”> <aspect> <component class=”S2Container_TraceInterceptor” /> </aspect></component>

$container = S2ContainerFactory::crate(‘app.dicon’);$server = $container->getComponent(‘server’);

eXtreme Hardcore PHP Development

オートバインディング

eXtreme Hardcore PHP Development

class EchoServer { private $message;

public function __construct(Message $m) { $this->message = $m; }}

<component name=”impl” class=”MessageImpl” />

<component class=”EchoServer” autoBinding=”auto”><!-- <arg>impl</arg> --></component>

eXtreme Hardcore PHP Development

InterType

eXtreme Hardcore PHP Development

class Employee { private $id; private $name; private $product;

// no getter & no setter...}

eXtreme Hardcore PHP Development

<component name=”propertyInterType” class=”S2Container_PropertyInterType” />

<component name=”Employee”> <interType>propertyInterType</interType></component>

$emp = $container->getComponent(‘Employee’);$emp->setName(‘yonekawa’);echo $emp->getName(); // => yonekawa

eXtreme Hardcore PHP Development

S2Dao.PHP5

eXtreme Hardcore PHP Development

1. Entityクラス定義2. Daoインタフェース定義3. コンポーネント登録

eXtreme Hardcore PHP Development

class Employee{ const TABLE = ‘employee’; private $id; private $name; private $product;

public function getId() { return $this->id; } public function setId($id) { $this->id = $id; } ...}

eXtreme Hardcore PHP Development

interface EmployeeDao{ const BEAN = ‘Employee’;

public function insert(Employee $employee); public function update(Employee $employee); public function delete(Employee $employee);

public function getAllEmployeesList();}

eXtreme Hardcore PHP Development

<component name=”EmployeeDao”> <aspect>dao.interceptor</aspect></component>

eXtreme Hardcore PHP Development

2 Way SQL

eXtreme Hardcore PHP Development

interface EmployeeDao{ const BEAN = ‘Employee’; public function getEmployeesByIdList($id);}

eXtreme Hardcore PHP Development

EmployeeDao_getEmployeesByIdList.sql

SELECT * FROM employee WHERE id = /*id*/1

eXtreme Hardcore PHP Development

Return Type

eXtreme Hardcore PHP Development

EntityArrayYAMLJSON

eXtreme Hardcore PHP Development

$result = $dao->getEmployeeByIdJson(1)echo $result;

[{"Employee": {"id":"1", "ID":"1", "name":"yonekawa", "NAME":"yonekawa", "product":"S2AnA.PHP5", "PRODUCT":"S2AnA.PHP5"}}]

eXtreme Hardcore PHP Development

public function getEmployeeById($id);

/** * @return json */

eXtreme Hardcore PHP Development

S2AnA.PHP5

eXtreme Hardcore PHP Development

対象Component

承認interceptor

認証Context

Client

call()

Exception!!承認OK 承認NGReturn

認証情報

Throw

eXtreme Hardcore PHP Development

S2Base.PHP5

eXtreme Hardcore PHP Development

$ s2base project

$ ls projectapp build.xml config lib test var vendor

eXtreme Hardcore PHP Development

eXtreme Hardcore PHP Development

eXtreme Hardcore PHP Development

既存フレームワークとの連携

eXtreme Hardcore PHP Development

with Symfonywith PRADO

with Zend Framework

eXtreme Hardcore PHP Development

まとめ

• SQL外出しできるS2Dao.PHP5はかなり強力

• S2Base.PHP5で面倒なファイルは自動生成

• ZF連携はSeasar.PHPの他にも色々ついてお得

eXtreme Hardcore PHP Development

Coming Soon...

• ApplicationContextdiconファイルレスの DI & AOP

• Class Injectioninterface レスの DI & AOP