<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>ueblog &#187; symfony</title>
	<atom:link href="http://ueblog.natural-wave.com/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://ueblog.natural-wave.com</link>
	<description>Web関連のネタを中心に役立つ情報を配信しています。</description>
	<lastBuildDate>Wed, 11 Jan 2012 00:51:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/tag/symfony/feed/" />
		<item>
		<title>PHPの軽量フレームワーク「Codeigniter」導入</title>
		<link>http://ueblog.natural-wave.com/2011/02/13/introduction-codeigniter/</link>
		<comments>http://ueblog.natural-wave.com/2011/02/13/introduction-codeigniter/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 15:04:10 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/?p=760</guid>
		<description><![CDATA[久々の更新。 Codeigniterという、PHP製のフレームワークがとてもいい感じだったのでご紹介。 軽量、そして学習コストの低さ 日本のCodeigniterユーザ会のページにもありますが、導入がとても簡単、シンプルな構成と規約で覚えておくことがかなり少]]></description>
			<content:encoded><![CDATA[<p><a href="http://codeigniter.com/"><img src="http://ueblog.natural-wave.com/wp-content/uploads/2011/02/picture-2.png" title="picture-2" width="222" height="77" class="size-full wp-image-762 alignright" /></a>久々の更新。</p>
<p><a href="http://codeigniter.com/" target="_blank">Codeigniter</a>という、PHP製のフレームワークがとてもいい感じだったのでご紹介。</p>
<h3>軽量、そして学習コストの低さ</h3>
<p><a href="http://codeigniter.jp/" target="_blank">日本のCodeigniterユーザ会のページ</a>にもありますが、導入がとても簡単、シンプルな構成と規約で覚えておくことがかなり少なく、最近のRuby on Rails似のフレームワークのようなフルスタックな機能は切り捨てている分、動作がかなり高速というのが特徴のようです。またPHP4でも動作します。（つい先日リリースされた、Codeigniter2よりPHP5以上を必要とする。）</p>
<h3>インストール</h3>
<p>インストールは本当にとても簡単。</p>
<p><a href="http://codeigniter.com/downloads/" target="_blank">http://codeigniter.com/downloads/</a></p>
<p>上記のダウンロードサイトより、ダウンロードしZIPファイルを解凍、公開ディレクトリ（DocumentRoot）以下に配置するだけです。下記のような構成になります。</p>
<blockquote><p>www/index.php        ←    すべてこのindex.php経由で呼ばれる<br />
www/application/    ←　Controller,View,Modelなど開発者が触るところ<br />
www/system/　　　←　フレームワーク本体（触らない）</p></blockquote>
<p>PEARなどで必要とするライブラリもなく、このアーカイブ内だけで動作できるので、制限の多いレンタルサーバにも導入しやすいと思います。</p>
<h3>Getting Started!</h3>
<p>早速、コーディングしたいところですが、簡単とはいえ、いくつかのルールは覚えておく必要があります。</p>
<p><a href="http://codeigniter.com/user_guide/" target="_blank">Codeigniter User Guide</a></p>
<p><a href="http://codeigniter.jp/user_guide_ja/" target="_blank">CodeIgniter ユーザガイド 日本語版</a></p>
<p>上記のユーザガイドのチュートリアルを簡単に眺めるだけですぐに理解できると思います。日本語の方は現在のところ、Codeigniter1.7のガイド（現在翻訳中のようです）のため、記述が違いがありますが、（例えば、Controller→CI_Controllerをextendするとか）大きな流れは変わりません。</p>
<h3>機能</h3>
<p>DBとの連携、セッション管理、暗号化、メール、フォームValidateなどなど、最低限の機能は揃っています。またヘルパー等による拡張も可能です。</p>
<h3>情報源</h3>
<p>フレームワーク選びで重要なことが、「マニュアルが豊富」「どれだけのユーザが利用してるか」が挙げられると思いますが、マニュアルに関しては上記であげた公式サイトのユーザガイドが分かりやすく問題ないと思います。また利用してるユーザ数は、単純なGoogleのインデックス数でみると、、</p>
<p><a href="http://www.google.co.jp/search?aq=f&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=symfony&amp;qscrl=1" target="_blank">Symfony</a> →  約 5,290,000 件</p>
<p><a href="http://www.google.co.jp/search?hl=ja&amp;safe=off&amp;qscrl=1&amp;q=cakephp&amp;aq=f&amp;aqi=g10&amp;aql=&amp;oq=" target="_blank">CakePHP</a> →　約 3,790,000 件</p>
<p><a href="http://www.google.co.jp/search?hl=ja&amp;safe=off&amp;qscrl=1&amp;q=Codeigniter&amp;btnG=%E6%A4%9C%E7%B4%A2&amp;aq=f&amp;aqi=g10&amp;aql=&amp;oq=" target="_blank">Codeigniter</a> →　約 2,220,000 件</p>
<p>CakePHPやSymfonyといったフレームワークには少ないですが、Codeigniterについて書かれたブログも結構増えてきているように見えます。まあ、困ったときは本体のソースもそんなに大きくないのでソースを読むのも、そんなに苦ではないでしょう。</p>
<p>日本語のフォーラムもこの2011年2月下旬より公開されるようです。</p>
<h3>最後に</h3>
<p>PHPを使って簡単に実装したい、既存のPHPソースを新たに書き直したい、プロジェクトが新しいメンバーで構成されていて経験が異なる等、様々な場面で活躍できるフレームワークです。</p>
<p>私自身もPHPで実装するときはSymfonyを選んでましたが、プロジェクトの規模や一緒に開発するメンバーの経験などを考慮して、このCodeigniterも選択肢としてかなり良いと思いました。</p>
<p>※追記</p>
<p>2011/2/19に<a href="http://cicon.codeigniter.jp/2011/" target="_blank">日本初となるCodeigniterカンファレンス</a>が行われるようです。</p>
<p>行きたいなー。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2011/02/13/introduction-codeigniter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2011/02/13/introduction-codeigniter/" />
	</item>
		<item>
		<title>symfony＋MAMPでdoctrine:buildできない時の対策</title>
		<link>http://ueblog.natural-wave.com/2010/07/11/symfony-mamp-doctrine-build/</link>
		<comments>http://ueblog.natural-wave.com/2010/07/11/symfony-mamp-doctrine-build/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 08:49:16 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/?p=681</guid>
		<description><![CDATA[久々にsymfonyネタ。 MACのLAMP環境である、MAMP上でsymfonyを動かしていて、symfonyコマンドでdoctrineのタスクを実行する際、DB接続を必要とする場合、下記のようなエラーになることがある。 Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /Applications/MAMP/bin/php5.3/symfony-1.4.4/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470 PDO Connection Error: SQLSTATE[HY000] [2002] No such file or directory UNIXソケットを使用した、mysql接続に失敗しているため、database.ymlにてソケットの位置を指]]></description>
			<content:encoded><![CDATA[<p>久々にsymfonyネタ。</p>
<p>MACのLAMP環境である、MAMP上でsymfonyを動かしていて、symfonyコマンドでdoctrineのタスクを実行する際、DB接続を必要とする場合、下記のようなエラーになることがある。</p>
<blockquote><p>Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /Applications/MAMP/bin/php5.3/symfony-1.4.4/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470</p>
<p>PDO Connection Error: SQLSTATE[HY000] [2002] No such file or directory</p></blockquote>
<p>UNIXソケットを使用した、mysql接続に失敗しているため、database.ymlにてソケットの位置を指定してあげれば上手くいく。</p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">all:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; doctrine:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; class: sfDoctrineDatabase</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; param:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; dsn: <span style="color:#CC0000;">'mysql:host=localhost;dbname=sample;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; port:&nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">8889</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; username: sample</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; password: sample </div>
</li>
</ol>
</div>
</div>
</div>
<p>
「dbname」の指定のあとに、「unix_socket」を指定してあげればうまくいった。</p>
<p>ちょっとはまったので参考までに。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2010/07/11/symfony-mamp-doctrine-build/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2010/07/11/symfony-mamp-doctrine-build/" />
	</item>
		<item>
		<title>VMware Player＋CentOS＋EclipseでPHPの開発環境を作る</title>
		<link>http://ueblog.natural-wave.com/2009/04/04/vmware-centos-eclipse-php/</link>
		<comments>http://ueblog.natural-wave.com/2009/04/04/vmware-centos-eclipse-php/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 01:31:59 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[サーバ]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/?p=365</guid>
		<description><![CDATA[いまさら？な感じもするが、快適な開発環境を作るべく、Windows上にLinuxの仮想環境を用意し、PHPの開発環境を作ってみることにした。 利用したソフトウェアとバージョンは下記になる。 VMware Player2.5 Windows Vista(ホスト) Cent OS 5.2（ゲスト） Apache mysql PHP Eclipse3.3 VMware Playerのインストール VMware Playerのインストール自]]></description>
			<content:encoded><![CDATA[<p>いまさら？な感じもするが、快適な開発環境を作るべく、Windows上にLinuxの仮想環境を用意し、PHPの開発環境を作ってみることにした。</p>
<p>利用したソフトウェアとバージョンは下記になる。</p>
<ul>
<li>VMware Player2.5</li>
<li>Windows Vista(ホスト)</li>
<li>Cent OS 5.2（ゲスト）</li>
<li>Apache</li>
<li>mysql</li>
<li>PHP</li>
<li>Eclipse3.3</li>
</ul>
<h3 class="PostLine">VMware Playerのインストール</h3>
<p>VMware Playerのインストール自体はとても簡単。</p>
<p><a href="http://www.vmware.com/jp/products/player/" target="_blank">VMware Player 、仮想マシン、仮想PC - VMware</a></p>
<p>上記からダウンロードしたファイルを実行すればOK。ダウンロードする前にメールアドレスやアンケートがあるので答えておく。</p>
<p>インストール後は再起動を求められるので、再起動しておこう。</p>
<h3 class="PostLine">Cent OSのインストール</h3>
<p>CentOSのインストールする前に、VMwareのディスクイメージを作成する必要があるので、下記サイトで情報を入力しダウンロードする。</p>
<p><a href="http://www.easyvmx.com/">EasyVMX!: Virtual Machine Creator</a></p>
<p>EaxyVMX V2.0というアイコンをクリックし、下記の情報を入力し、「Create Virtual Machine」ボタンを押すとzipファイルをダウンロードできるようになる。</p>
<table style="height: 110px;" border="1" cellspacing="0" cellpadding="2" width="405">
<tbody>
<tr>
<td width="161" valign="top">Virtual Machine Name</td>
<td width="208" valign="top">CentOS5.2　　（なんでもOK）</td>
</tr>
<tr>
<td width="161" valign="top">Select GuestOS</td>
<td width="208" valign="top">Redhat Enterprise Linux 4</td>
</tr>
<tr>
<td width="161" valign="top">Memory Size</td>
<td width="208" valign="top">320MB (適度な値に設定)</td>
</tr>
<tr>
<td width="161" valign="top"># of CPUs</td>
<td width="208" valign="top">1CPU</td>
</tr>
<tr>
<td width="161" valign="top">Disk #1</td>
<td width="208" valign="top">Disk Size 4.7GB(Fits on a DVS)(適度な値に設定)</td>
</tr>
<tr>
<td width="161" valign="top">Shared Folder #</td>
<td width="208" valign="top">ホスト、ゲストOS間でファイル共有したい場合はチェック。</td>
</tr>
</tbody>
</table>
<p>次にCentOSのファイルイメージをミラーサイトからダウンロードする。</p>
<p><a href="http://ftp.riken.jp/Linux/centos/5/isos/i386/" target="_blank">http://ftp.riken.jp/Linux/centos/5/isos/i386/</a></p>
<blockquote><p>CentOS-5.2-i386-bin-DVD.iso</p></blockquote>
<p>EaxyVMXで作成したZIPにある「CentOS5.2.vmx」に上記で落としたCentOSのイメージファイルを指定するように下記の部分をテキストエディタで編集する。</p>
<blockquote><p># Settings for physical CDROM drive<br />
ide1:0.present = "TRUE"<br />
ide1:0.deviceType = "<span style="color: #ff0000;">cdrom-image</span>"<br />
ide1:0.startConnected = "TRUE"<br />
ide1:0.fileName = "<span style="color: #ff0000;">C:\CentOS5.2\CentOS-5.2-i386-bin-DVD.iso</span>"<br />
ide1:0.autodetect = "TRUE"</p></blockquote>
<p>赤色の部分が編集する部分で、fileName部分は落としたファイルの場所を指定する。</p>
<p>ここまでの準備ができればやっとインストールに入ることができる。</p>
<p>上記の「CentOS5.2.vmx」をダブルクリックで実行すると、VMwareが立ち上がり、CentOSのインストールウィザードが表示されるだろう。</p>
<p>詳しいCentOSのインストール方法は下記が詳しい。</p>
<p><a href="http://www.memolica.com/200903/entry160.html" target="_blank">VMwareとCentOSで簡単CMSテスト環境構築(3) - memolica * 小さな会社で働いている人のメモ</a></p>
<p><a href="http://centossrv.com/">CentOSで自宅サーバー構築</a></p>
<p>ポイントとしては、今回Eclipseをインストールするので、GUIのGNOMEかKDEをインストールしてしまおうということくらい。あとはお好みで。</p>
<h3 class="PostLine">VMware Toolsのインストール</h3>
<p>VMware Player2.5からは、VMware Toolsが添付されないということで、共有フォルダやコピーアンドペーストが利用できる、VMware Toolsをインストールしておく。</p>
<p><a href="http://register.vmware.com/content/download-108.html" target="_blank">Download VMware Server</a></p>
<p>tar.gzバイナリの中から、「linux.iso」を抜き出し、またその中から「VMWARETO.TGZ」というファイルを解凍して出てくる、RPMファイルを利用してインストールする。</p>
<p>詳しい説明は下記。</p>
<p><a href="http://homepage3.nifty.com/nasunu-i/VMware/Fedora7.htm#ToolsInstall" target="_blank">VMware Player に Fedora7 をゲストＯＳとしてインストール。VMware Tools (VMwareTools)のインストール</a></p>
<p>コピーアンドペーストを有効にするには、vmware-toolboxを常駐させる必要があるので端末などで下記のコマンドを打つ必要がある。</p>
<blockquote><p># vmware-toolbox &amp;</p></blockquote>
<p>あとはキーボードレイアウトの変更、解像度の設定など最適な環境にしておく。</p>
<h3 class="PostLine">(L)AMP環境のインストール</h3>
<p>PHP、MYSQL、APACHEをyumですべていれてしまう。ついでにsymfonyも。</p>
<blockquote><p># yum install php php-pear php-mbstring php-mysql php-gd php-xml</p>
<p># yum install httpd</p>
<p># yum install mysql-server</p>
<p># pear upgrade PEAR</p>
<p># pear channel-discover pear.symfony-project.com</p>
<p># pear <span id="searchword">install</span> <span id="searchword">symfony</span>/symfony-1.0.20</p></blockquote>
<h3 class="PostLine">Eclipseのインストール</h3>
<p>まずはjdkをインストールするためにrpmをダウンロードしインストール</p>
<p><a href="http://java.sun.com/javase/ja/6/download.html" target="_blank">Java SE ダウンロード - Sun Developer Network (SDN)</a></p>
<p>RPMのJDKを選択しダウンロードしたファイルを実行する。</p>
<blockquote><p># chmod a+x jdk-6u13-linux-i586-rpm.bin</p>
<p># ./jdk-6u13-linux-i586-rpm.bin</p></blockquote>
<p>Eclipseは<a href="http://downloads.zend.com/pdt/all-in-one/" target="_blank">zendのall in one PDT</a>のものを、日本語化は<a href="http://mergedoc.sourceforge.jp/" target="_blank">Plieades</a>からそれぞれダウンロードして展開する。</p>
<blockquote><p># tar xvfz pdt-2.0.0GA_debugger-5.2.15.v20081217-all-in-one-linux-gtk.tar.gz</p>
<p># mv pleiades_1.3.0.zip eclipse/</p>
<p># unzip pleiades_1.3.0.zip</p>
<p># mv /usr/local/src/eclipse /usr/local/</p></blockquote>
<p>eclipseディレクトリにある、eclipse.iniの一番下に下記を追記。</p>
<blockquote><p>-javaagent:plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar</p></blockquote>
<p>Eclipseを実行</p>
<blockquote><p># /usr/local/eclipse/eclipse -vm /usr/java/jdk1.6.0_13/bin/java</p></blockquote>
<p>あとはEclipseの設定をするだけ。</p>
<p>VMwareというより、CentOSのGNOMEのキーボード設定や日本語環境を整備するのに少し手間取ったが、とても簡単に仮想開発環境を作成できた。</p>
<p>これはとても便利だ。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2009/04/04/vmware-centos-eclipse-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2009/04/04/vmware-centos-eclipse-php/" />
	</item>
		<item>
		<title>symfonyのジョブ管理プラグイン「sfJobQueuePlugin」</title>
		<link>http://ueblog.natural-wave.com/2008/07/19/sfjobqueueplugin/</link>
		<comments>http://ueblog.natural-wave.com/2008/07/19/sfjobqueueplugin/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 13:21:00 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/07/19/sfjobqueueplugin/</guid>
		<description><![CDATA[Javaでいう「ActiveMQ」、Perlでいう「TheSchwartz」みたいなジョブキューサーバ的なもので、PHPから簡単に利用できるものがないかと探していると、symfonyのプラグインとしてありました。 その名も「sfJobQueuePlugin」です。 まあ、何がやりたいかと言うと、、Webサーバの処理等]]></description>
			<content:encoded><![CDATA[<p>Javaでいう「<strong>ActiveMQ</strong>」、Perlでいう「<strong>TheSchwartz</strong>」みたいなジョブキューサーバ的なもので、PHPから簡単に利用できるものがないかと探していると、symfonyのプラグインとしてありました。</p>
<p>その名も「<a href="http://trac.symfony-project.org/wiki/sfJobQueuePlugin" target="_blank">sfJobQueuePlugin</a>」です。</p>
<p>まあ、何がやりたいかと言うと、、Webサーバの処理等ですぐ処理しなくてもよいような処理や、Webプロセスとしてやるには時間がかかってしまったり、重たい処理なんかを、ジョブキューサーバにリクエストしておいて、非同期に処理させたい場合なんかに利用したいんですね。</p>
<p>例えば、メール大量送信処理とか、CSVや画像のアップロード処理なんかをキューにリクエストを送っておいて、非同期で処理⇒何かしらの手段で通知！みたいな感じをしたい時とかを想定してます。</p>
<p>さっそく、インストールしてみることに。</p>
<h3  class="PostLine">インストール</h3>
<p>いつものプラグインインストールと同じで、プロジェクトディレクトリ下で下記のコマンドを。</p>
<blockquote><p>symfony plugin-install http://plugins.symfony-project.com/sfJobQueuePlugin</p></blockquote>
<p>そして、sfJobQueuePluginで利用されるテーブルを作成するため、propelのビルドを行います。</p>
<blockquote><p>symfony propel-build-all</p></blockquote>
<p>ジョブ、キューはDBで管理してるようです。</p>
<p>そして<br />
<img src='http://ueblog.natural-wave.com/wp-content/uploads/2008/07/s-sfjobqueueplugin_admin_panel.jpg' alt='sfJobQueuePlugin管理ツール' /><br />
こんな、キューを管理するインターフェースがあるので、settings.ymlに宣言しましょう。</p>
<p>apps/[application]/config/settings.yml</p>
<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-6">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">all:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; .<span style="">settings</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; enabled_modules:&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>default, sfJob, sfJobQueue<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
あとはキャッシュクリア（symfony cc）して<br />
「http://domain/[application].php/sfJobQueue」にアクセスすれば、管理画面が見れる。</p>
<p>最後に、ジョブを管理するデーモンのようなものを立ち上げておく必要があるようだ。</p>
<blockquote><p>symfony sfqueue-start-queuemanager [application]</p></blockquote>
<p>停止するには、上記プロセスをKILLしてしまえばよい。</p>
<h3  class="PostLine">ジョブタイプの作成</h3>
<p>まずは、処理させる内容（ジョブタイプ）を作成する。</p>
<p>作成するには、sfJobHandlerを継承して、runメソッドを実装したクラスを作成する。配置は、lib以下などにおいて置くと勝手にJobHandlerとして認識してくれる。また、呼び出し側からパラメータを受け取ることもできる。</p>
<p>あるパスの画像から、サムネイル画像を作成するサンプルは下記のような感じだ。</p>
<div class="igBar"><span id="lphp-7"><a href="#" onclick="javascript:showPlainTxt('php-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-7">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> sfMakeImageJobHandler extends sfJobHandler</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> getParamFields<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'path'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> run<span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a> <span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; try</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$thumbnail</span> = <span style="color:#000000; font-weight:bold;">new</span> sfThumbnail<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">150</span>, <span style="color:#CC66CC;color:#800000;">150</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$thumbnail</span>-&gt;<span style="color:#006600;">loadFile</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'path'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$thumbnail</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/tmp/test.jpg'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//TODO ユーザに通知メールとか！</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> sfJob::<span style="color:#006600;">SUCCESS</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; catch <span style="color:#006600; font-weight:bold;">&#40;</span>Exception <span style="color:#0000FF;">$e</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; throw <span style="color:#0000FF;">$e</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
「sfMakeImageJobHandler」というクラスを作成したが、実際にジョブを呼び出すときは、sfとJobHandlerが省略されて「MakeImage」と言う名前になる。</p>
<p>ちなみに、runメソッド内で、Exceptionをthrowすれば、管理コンソールのログからthrowしたものが見れる。またデフォルトでは、/tmp下に「sfJobQueuePlugin.log」というものがあり、Jobの実行状態を見ることができる。</p>
<h3  class="PostLine">キューの作成とジョブ</h3>
<p>上記のようなジョブタイプを呼び出す、キューとジョブの作成をする。</p>
<p>キューはUnixでいう、1プロセスのようなもので、同時処理したい場合は複数のキューを作成すればよい。そして、キューに対してジョブを複数結びつけることができる。</p>
<p>actionクラス等から簡単にキューの作成とジョブの結びつけができる。</p>
<p>キューの作成とジョブの結びつけサンプル</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//キューの作成</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span> = <span style="color:#000000; font-weight:bold;">new</span> sfJobQueue<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">setName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'image queue'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">setSchedulerName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'fifo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//既存のキューを呼び出すにはキューの名前で呼び出す。</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span> = sfJobQueuePeer::<span style="color:#006600;">retrieveByQueueName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'image queue'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//ジョブの結びつけ</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">addJob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'MakeImage'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'path'</span> =&gt; <span style="color:#FF0000;">'/tmp/aaa.gif'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//すぐに実行！</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">setRequestedStatus</span><span style="color:#006600; font-weight:bold;">&#40;</span>sfJobQueue::<span style="color:#006600;">RUNNING</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$queue</span>-&gt;<span style="color:#006600;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>簡単に紹介したが、このほかにも実行のスケジューリングができたり、ロギングの操作、ジョブキューに利用するメモリの調整等の機能もある。</p>
<p>詳しくは公式のプラグインページで「<a href="http://trac.symfony-project.org/wiki/sfJobQueuePlugin" target="_blank">sfJobQueuePlugin</a>」</p>
<p>シンプルではあるが、なかなか使い道がありそうだ。</p>
<p>非同期処理は、Webのサーバサイド処理でかなり重宝されるのではないか。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/07/19/sfjobqueueplugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/07/19/sfjobqueueplugin/" />
	</item>
		<item>
		<title>さくらインターネットでsymfonyをインストール</title>
		<link>http://ueblog.natural-wave.com/2008/06/15/sakura-symfony/</link>
		<comments>http://ueblog.natural-wave.com/2008/06/15/sakura-symfony/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 13:32:50 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[さくら]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/06/15/sakura-symfony/</guid>
		<description><![CDATA[さくらインターネットでsymfonyをインストールしてみた。 さくらインターネットでもPHP5が利用できるようになっているので、さくらインターネットコントロールパネルの「PHPのバージョン選択」で、PHP5を選択しておこう。 インストールする]]></description>
			<content:encoded><![CDATA[<p>さくらインターネットで<strong>symfony</strong>をインストールしてみた。</p>
<p>さくらインターネットでもPHP5が利用できるようになっているので、さくらインターネットコントロールパネルの「PHPのバージョン選択」で、PHP5を選択しておこう。</p>
<p>インストールする場所を「$HOME/local」とする。sshでサーバに入り下記のディレクトリを作成。</p>
<blockquote><p>$ mkdir local/</p></blockquote>
<p>まずはPEARをインストールするために、スクリプトをダウンロードし実行。</p>
<blockquote><p>$ curl http://pear.php.net/go-pear > go-pear.php<br />
$ php go-pear.php</p></blockquote>
<p>下記のような選択となるので「1」のprefixのみを変更する。</p>
<blockquote><p> 1. Installation prefix ($prefix) : /home/[account名]/local<br />
 2. Temporary files directory     : $prefix/temp<br />
 3. Binaries directory            : $prefix/bin<br />
 4. PHP code directory ($php_dir) : $prefix/PEAR<br />
 5. Documentation base directory  : $php_dir/docs<br />
 6. Data base directory           : $php_dir/data<br />
 7. Tests base directory          : $php_dir/tests</p></blockquote>
<p>次にphp.iniの書き換えはできないので、「n」を選択。</p>
<blockquote><p>Would you like to alter php.ini </usr/local/php-5.2.5/lib/php.ini>? [Y/n] : n</p></blockquote>
<p>これでPEARのインストール完了。あとは自身のシェルを書き換え、新しくインストールしたpearコマンドにパスを通す。</p>
<blockquote><p>#bash,zshなら<br />
export PATH=/bin:<strong>$HOME/local/bin</strong>:$PATH<br />
#csh,tcshなら<br />
set path = (/sbin /bin <strong>$HOME/local/bin</strong> $HOME/bin /usr/local/bin)</p></blockquote>
<p>ポイントとしては、サーバにある「/usr/local/bin/pear」をよまないように、先に「local/bin」を設定している部分だ。</p>
<p>PATHを設定し、pearのバージョンを確認する。</p>
<blockquote><p>$ source ~/.zshrc<br />
$ pear -V<br />
PEAR Version: 1.7.2<br />
PHP Version: 5.2.5<br />
Zend Engine Version: 2.2.0</p></blockquote>
<p>PHPのバージョンが5になってれば正解だ。</p>
<p>ここから、symfonyのインストール</p>
<blockquote><p>$ pear channel-discover pear.symfony-project.com<br />
$ pear install symfony/symfony<br />
$ symfony -V<br />
X-Powered-By: PHP/5.2.5<br />
Content-type: text/html</p>
<p>symfony version 1.0.16</p></blockquote>
<p>これで完了！</p>
<h3>プロジェクトの作成</h3>
<p>さて、実際にプロジェクトの作成をしてみよう。</p>
<blockquote><p>$ mkdir -p ~/symfony/sample<br />
$ cd symfony/sample<br />
$ symfony init-project sample<br />
$ symfony init-app frontend
</p></blockquote>
<p>webディレクトリは公開ディレクトリ下に置かなければならないので、シンボリックリンクを利用する。</p>
<blockquote><p>$ ln -s ~/symfony/sample/web ~/www/sample</p></blockquote>
<p>さくらのコントロールパネルにある、「ドメイン設定」で利用したいドメインを「~/www/sample」へ向ける。</p>
<p>.htaccessでOptionsはさくらでは利用できないので、コメントアウトし、RewriteBaseのコメントをはずす。</p>
<blockquote><p>#Options +FollowSymLinks +ExecCGI<br />
RewriteBase /</p></blockquote>
<p>sfの画像やデバッグツールを利用するため、シンボリックリンクを作成。</p>
<blockquote><p>ln -s ~/local/PEAR/data/symfony/web/sf ~/symfony/sample/web/sf</p></blockquote>
<p>で、さくらのphp.iniが「magic_quotes_gpc=on」がデフォルトなので、コントロールパネルの「PHP設定の編集」で</p>
<blockquote><p>magic_quotes_gpc=off</p></blockquote>
<p>を書いておきましょう。</p>
<p>これで設定したドメインにアクセスすると、いつもの「Symfony Project Created」が拝めるでしょう。</p>
<p>パフォーマンスはどうなんでしょう？</p>
<p>感覚的には、<a href="http://ueblog.natural-wave.com/2007/10/31/sakura-ruby-on-rails/">さくらでRails</a>よりは幾分ましだけど、もっさり感はやっぱありますね。。</p>
<p>実用に耐えうるのか。何か作ってみてまた報告します。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/06/15/sakura-symfony/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/06/15/sakura-symfony/" />
	</item>
		<item>
		<title>symfonyで携帯サイト用に出力を半角カナで統一</title>
		<link>http://ueblog.natural-wave.com/2008/06/07/symfony-hankana/</link>
		<comments>http://ueblog.natural-wave.com/2008/06/07/symfony-hankana/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 14:35:28 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/06/07/symfony-hankana/</guid>
		<description><![CDATA[携帯サイトの場合、1行あたりの文字数を増やすため、カタカナは半角で揃えるのが定石。 というわけで、symfonyで気軽にHTML出力を半角カナで統一する方法を探る。 viewの出力時にすべてフィルターをかけるようなイメージでいたが、テンプ]]></description>
			<content:encoded><![CDATA[<p>携帯サイトの場合、1行あたりの文字数を増やすため、カタカナは半角で揃えるのが定石。</p>
<p>というわけで、symfonyで気軽にHTML出力を半角カナで統一する方法を探る。</p>
<p>viewの出力時にすべてフィルターをかけるようなイメージでいたが、テンプレートに直接書くものを半角カナで入力し、actionなどから出力されるオブジェクトに半角カナエスケープをかけるのがスマート？かと思い、作ってみた。</p>
<p>まずは、独自のカナHelper。</p>
<p>lib/helper/EscapingKanaHelper.php</p>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-11">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> esc_entities_kana<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$value</span> = <a href="http://www.php.net/mb_convert_kana"><span style="color:#000066;">mb_convert_kana</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span>, <span style="color:#FF0000;">'k'</span>, <span style="color:#FF0000;">'UTF-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">return</span> <a href="http://www.php.net/is_string"><span style="color:#000066;">is_string</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <a href="http://www.php.net/htmlentities"><span style="color:#000066;">htmlentities</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span>, ENT_QUOTES, sfConfig::<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'sf_charset'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#0000FF;">$value</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/define"><span style="color:#000066;">define</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'ESC_ENTITIES_KANA'</span>, <span style="color:#FF0000;">'esc_entities_kana'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
ESC_ENTITIES関数をそのまま流用し、mb_convert_kana関数を付け加えるような、helperを作成した。</p>
<p>そしてsettings.ymlで宣言する。</p>
<p>apps/config/settings.yml</p>
<div class="igBar"><span id="lcode-12"><a href="#" onclick="javascript:showPlainTxt('code-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-12">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">all:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; .<span style="">settings</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; escaping_strategy:&nbsp; &nbsp; &nbsp; both</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; escaping_method:&nbsp; &nbsp; &nbsp; &nbsp; ESC_ENTITIES_KANA</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; standard_helpers:&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>Partial, Cache, Form, EscapingKana<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>テンプレートに直接、全角カナを書かれてしまうと、統一されないのが難点。</p>
<p>やっぱFilterかな。。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/06/07/symfony-hankana/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/06/07/symfony-hankana/" />
	</item>
		<item>
		<title>symfonyでOpenIDを実装してみた</title>
		<link>http://ueblog.natural-wave.com/2008/05/19/symfony-openid/</link>
		<comments>http://ueblog.natural-wave.com/2008/05/19/symfony-openid/#comments</comments>
		<pubDate>Sun, 18 May 2008 15:28:53 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/05/19/symfony-openid/</guid>
		<description><![CDATA[前々回、OpenIDが流行ってないと書いたが、OpenIDに賛同する気があるなら積極的に実装すべきかと思い、symfonyから簡単にコンシューマー部分を実装してみた。 symfonyにはsfOpenIDPluginという、OpenIDをかなり簡単に実装できるプラグインがあるが、Smart Modeに対応していないこ]]></description>
			<content:encoded><![CDATA[<p>前々回、<a href="http://ueblog.natural-wave.com/2008/05/11/openid/">OpenIDが流行ってない</a>と書いたが、OpenIDに賛同する気があるなら積極的に実装すべきかと思い、symfonyから簡単にコンシューマー部分を実装してみた。</p>
<p>symfonyには<a href="http://trac.symfony-project.com/wiki/sfOpenIDPlugin" target="_blank">sfOpenIDPlugin</a>という、OpenIDをかなり簡単に実装できるプラグインがあるが、Smart Modeに対応していないこと、OpenID 2.0に対応していないこともあり、別のPHPライブラリである、<a href="http://www.openidenabled.com/php-openid/" target="_blank">PHP OpenID Library</a>を利用してみる。</p>
<p>なお、詳しい実装の流れは<a href="http://www.atmarkit.co.jp/fsecurity/rensai/openid01/openid01.html" target="_blank">＠ITのOpenID特集サイト</a>が詳しい。</p>
<p>まずは、 <a href="http://www.openidenabled.com/php-openid/" target="_blank">PHP OpenID Library</a>から2.x.x系のライブラリをダウンロード、解凍した中にある「Auth」ディレクトリをsymfonyプロジェクトの「lib」ディレクトリに配置しておこう。</p>
<p>こんな感じ</p>
<blockquote><p> [project]/apps<br />
[project]/web<br />
.....<br />
[project]/lib/Auth</p></blockquote>
<p>詳しい実装の話は抜きにして、</p>
<p><strong>/openid/login</strong> 　⇒　<strong>/openid/tryauth</strong>　⇒　OpenID供給サイト(Idp) 　⇒　<strong>/openid/finishauth</strong></p>
<p>こんな感じで、太字になっている部分をサイト側は実装すればよい。</p>
<p>まずはmoduleのさくせい。<br />
$ symfony init-module project openid</p>
<p>まずはloginフォーム<br />
loginSuccess.php</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showPlainTxt('php-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> form_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/openid/tryauth'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> form_error<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div&gt;OpenID&lt;/div&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> input_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">''</span>,<a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'size'</span> =&gt; <span style="color:#CC66CC;color:#800000;">40</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> ?&gt;&lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;p&gt;&lt;/p&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div align=<span style="color:#FF0000;">"left"</span>&gt;&lt;?php <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> submit_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'ログイン'</span><span style="color:#006600; font-weight:bold;">&#41;</span> ?&gt;&lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/form&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;p&gt;&lt;/p&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Yahoo IDでログイン'</span>,<span style="color:#FF0000;">'/openid/tryauth?openid_identifier=yahoo.co.jp'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>実装コードは下記のようになった。<br />
action.class.php</p>
<div class="igBar"><span id="lphp-17"><a href="#" onclick="javascript:showPlainTxt('php-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-17">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> openidActions extends sfActions</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;* ログインフォームを表示する処理</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> executeLogin<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">return</span> sfView::<span style="color:#006600;">SUCCESS</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000;">/*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;* ログインフォームからPostされたときのバリデート処理</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> validateTryauth<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// OpenIDライブラリがNoticeを出してしまうため止めてます。</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$er</span> = <a href="http://www.php.net/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$er</span>&gt; E_STRICT<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$er</span> - E_STRICT<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// openid_identifierがユーザの入力したURLが入っている。</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$openid</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequestParameter</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$openid</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// エラー処理は手抜き。。</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// openidの認証ファイルを格納するディレクトリ(DBにもできる)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$store_path</span> = <span style="color:#FF0000;">'/tmp/_php_tmp'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; !<a href="http://www.php.net/mkdir"><span style="color:#000066;">mkdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$store</span> = <span style="color:#000000; font-weight:bold;">new</span> Auth_OpenID_FileStore<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$consumer</span> = <span style="color:#000000; font-weight:bold;">new</span> Auth_OpenID_Consumer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$auth_request</span> = <span style="color:#0000FF;">$consumer</span>-&gt;<span style="color:#006600;">begin</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$openid</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$auth_request</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//認証時に属性が欲しい場合は指定する。</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$sreg_request</span> = Auth_OpenID_SRegRequest::<span style="color:#006600;">build</span><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'nickname'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'fullname'</span>, <span style="color:#FF0000;">'email'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$sreg_request</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$auth_request</span>-&gt;<span style="color:#006600;">addExtension</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$sreg_request</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//OpenID1.0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$auth_request</span>-&gt;<span style="color:#006600;">shouldSendRedirect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// trust_rootは認証されるサイトのURL、return_toは認証後にこちらにリダイレクトするURL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$redirect_url</span> = <span style="color:#0000FF;">$auth_request</span>-&gt;<span style="color:#006600;">redirectURL</span><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">'http://sample.net/'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">'http://sample.net/openid/finishauth'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Auth_OpenID::<span style="color:#006600;">isFailure</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$redirect_url</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">redirect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$redirect_url</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//OpenID2.0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$form_id</span> = <span style="color:#FF0000;">'openid_message'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// trust_rootは認証されるサイトのURL、return_toは認証後にこちらにリダイレクトするURL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$form_html</span> = <span style="color:#0000FF;">$auth_request</span>-&gt;<span style="color:#006600;">formMarkup</span><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">'http://sample.net/'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF0000;">'http://sample.net/openid/finishauth'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#000000; font-weight:bold;">false</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</span> =&gt; <span style="color:#0000FF;">$form_id</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>Auth_OpenID::<span style="color:#006600;">isFailure</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$form_html</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">else</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setAttribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_html'</span>, <span style="color:#0000FF;">$form_html</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setAttribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'form_id'</span>, <span style="color:#0000FF;">$form_id</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#000000; font-weight:bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;* ログインフォームからPostされたときの処理</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> executeTryauth<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> handleErrorTryauth<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">forward</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid'</span>, <span style="color:#FF0000;">'login'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;* Idpからリダイレクトされてからの処理</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> executeFinishauth<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$er</span> = <a href="http://www.php.net/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$er</span>&gt; E_STRICT<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <a href="http://www.php.net/error_reporting"><span style="color:#000066;">error_reporting</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$er</span> - E_STRICT<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$store_path</span> = <span style="color:#FF0000;">'/tmp/_php_tmp'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color:#000066;">file_exists</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; !<a href="http://www.php.net/mkdir"><span style="color:#000066;">mkdir</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">forward</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid'</span>, <span style="color:#FF0000;">'index'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$store</span> = <span style="color:#000000; font-weight:bold;">new</span> Auth_OpenID_FileStore<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store_path</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$consumer</span> = <span style="color:#000000; font-weight:bold;">new</span> Auth_OpenID_Consumer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$store</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$response</span> = <span style="color:#0000FF;">$consumer</span>-&gt;<span style="color:#006600;">complete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'http://sample.net/openid/finishauth'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$response</span>-&gt;<span style="color:#006600;">status</span> == <span style="color:#FF0000;">'cancel'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">forward</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid'</span>, <span style="color:#FF0000;">'index'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">else</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$response</span>-&gt;<span style="color:#006600;">status</span> == <span style="color:#FF0000;">'failure'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setError</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_identifier'</span>, <span style="color:#FF0000;">'error'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">forward</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid'</span>, <span style="color:#FF0000;">'index'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">else</span> <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$response</span>-&gt;<span style="color:#006600;">status</span> == <span style="color:#FF0000;">'success'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//認証されたopenid</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$openid</span> = <span style="color:#0000FF;">$response</span>-&gt;<span style="color:#006600;">getDisplayIdentifier</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//ここに認証処理を書けばよい例えば下記のような感じで。</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getUser</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setAuthenticated</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getUser</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">addCredential</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'editor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">getUser</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="color:#006600;">setAttribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid'</span>, <span style="color:#0000FF;">$openid</span>, <span style="color:#FF0000;">'user'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//どこかにリダイレクトでも</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">redirect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/top/index'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>処理の流れがわかるように、アクションクラスにすべてつめこんでます。</p>
<p>そして、POST送信用に下記のファイルを用意する。<br />
tryauthSuccess.php</p>
<div class="igBar"><span id="lphp-18"><a href="#" onclick="javascript:showPlainTxt('php-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;html&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;body onload=<span style="color:#FF0000;">'document.getElementById(&quot;&lt;?php echo $sf_request-&gt;getAttribute('</span>form_id<span style="color:#FF0000;">') ?&gt;&quot;).submit()'</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$sf_request</span>-&gt;<span style="color:#006600;">getAttribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'openid_html'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/body&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/html&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>これで「yahoo.co.jp」と入力もしくは、リンクをおくだけで認証処理が完了する。</p>
<p>OpenIDの詳細な仕様は知らなくても、流れさえ知ってればある程度は実装できる。</p>
<p>とはいえ、認証部分はサイトの脆弱性に繋がるため、サイトに実装する際はちゃんと理解する必要はあるでしょう。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/05/19/symfony-openid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/05/19/symfony-openid/" />
	</item>
		<item>
		<title>symfonyのテンプレートコード断片化</title>
		<link>http://ueblog.natural-wave.com/2008/05/06/symfony-include/</link>
		<comments>http://ueblog.natural-wave.com/2008/05/06/symfony-include/#comments</comments>
		<pubDate>Mon, 05 May 2008 17:23:59 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/05/06/symfony-include/</guid>
		<description><![CDATA[symfonyにてテンプレートコードの共通化や再利用する方法はいくつかある。今回はそのあたりをまとめてみる。 方法としては、 インクルード(include) パーシャル(partial) コンポーネント(component) コンポーネントスロット(component_slot) スロット(slot) これを一つ一つ見てみる。 イン]]></description>
			<content:encoded><![CDATA[<p>symfonyにてテンプレートコードの共通化や再利用する方法はいくつかある。今回はそのあたりをまとめてみる。</p>
<p>方法としては、</p>
<ol>
<li>インクルード(include)</li>
<li> パーシャル(partial)</li>
<li>コンポーネント(component)</li>
<li>コンポーネントスロット(component_slot)</li>
<li>スロット(slot)</li>
</ol>
<p>これを一つ一つ見てみる。</p>
<h3>インクルード(include)</h3>
<p>共通化されたコードが静的なHTMLだったり、actionなどに依存しないPHPコードくらいなら、include()がよさそう。</p>
<p>共通化したいフッタファイルを、アプリケーション共通のtemplateディレクトリに配置した場合はこんな感じで呼び出す。</p>
<div class="igBar"><span id="lphp-28"><a href="#" onclick="javascript:showPlainTxt('php-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-28">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span>sfConfig::<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'sf_app_template_dir'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">'/footer.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
用途としては、ヘッダ、フッターファイル、静的なメニューなど。</p>
<h3>パーシャル(partial)</h3>
<p>上記のインクルードに、actionからの引数を渡せるようなイメージ。</p>
<p>呼び出し側は下記のように、userオブジェクトをsidebarパーシャルに渡している。</p>
<div class="igBar"><span id="lphp-29"><a href="#" onclick="javascript:showPlainTxt('php-29'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-29">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> include_partial<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'global/sidebar'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'site'</span> =&gt; <span style="color:#0000FF;">$site</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>呼び出される側は_(アンダーバー)から始まるファイル名をつける。上記の呼び出しの場合は、<br />
app/application/template/_sidebar.phpというファイル名になる。</p>
<div class="igBar"><span id="lphp-30"><a href="#" onclick="javascript:showPlainTxt('php-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-30">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">現在のパス：<span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$site</span>-&gt;<span style="color:#006600;">getName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
用途としては、サイドバーにカートの内容を表示したり、動的な部分を部品化するイメージ。</p>
<h3>コンポーネント(component)</h3>
<p>上記のパーシャルよりもさらに独立した動的なロジックが必要な場合。本来のactionとかけ離れた処理をサイドバーなどに表示させるときなどは、サイドバー用の処理とactionの処理を分け、サイドバー用の処理をコンポーネントでまとめるといったことができる。</p>
<p>サイドバーにて、ニュースの一覧記事を取得するような処理を想定した、呼び出し側は下記のようになる。</p>
<div class="igBar"><span id="lphp-31"><a href="#" onclick="javascript:showPlainTxt('php-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-31">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> include_component<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'news'</span>, <span style="color:#FF0000;">'headlines'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'user'</span> =&gt; <span style="color:#0000FF;">$user</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>呼び出される側のロジックは、actionクラスをcomponentクラスとして名前を変更すれば、普段のアクションクラスのようなロジックを書ける。<br />
apps/application/module/news/action/components.class.php</p>
<div class="igBar"><span id="lphp-32"><a href="#" onclick="javascript:showPlainTxt('php-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-32">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> newsComponents extends sfComponents</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; public <span style="color:#000000; font-weight:bold;">function</span> executeHeadlines<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$c</span> = <span style="color:#000000; font-weight:bold;">new</span> Criteria<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$c</span>-&gt;<span style="color:#006600;">addDescendingOrderByColumn</span><span style="color:#006600; font-weight:bold;">&#40;</span>NewsPeer::<span style="color:#006600;">PUBLISHED_AT</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$c</span>-&gt;<span style="color:#006600;">setLimit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">news</span> = NewsPeer::<span style="color:#006600;">doSelect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$c</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
上記の例の場合、テンプレートは下記の位置に配置する。<br />
apps/application/module/news/template/_headlines.php</p>
<p>用途としては、上記のようなサイドバーにてニュースの一覧を表示したりするとき。</p>
<h3>コンポーネントスロット(component_slot)</h3>
<p>上記のコンポーネントにさらに、呼び出しの度に変化するような場合はコンポーネントスロットを利用する。ここが少しややこしい気がするが、呼び出し側は同じでも、view.ymlにより呼び出すロジックを変更できるようなイメージ。</p>
<p>呼び出し側は、layout.phpなどで下記のようになる。</p>
<div class="igBar"><span id="lphp-33"><a href="#" onclick="javascript:showPlainTxt('php-33'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-33">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> include_component_slot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'sidebar'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>app/application/config/view.ymlにはデフォルトのコンポーネントを登録しておく。</p>
<div class="igBar"><span id="lcode-34"><a href="#" onclick="javascript:showPlainTxt('code-34'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-34">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">default:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; components:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sidebar:&nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>menu, default<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
そして、モジュールによって呼び出すロジックが変わる場合は、<br />
app/application/module/foo/view.ymlなどのmodule側のview.ymlを下記のようにしておく。</p>
<div class="igBar"><span id="lcode-35"><a href="#" onclick="javascript:showPlainTxt('code-35'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-35">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">default:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; components:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sidebar:&nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span>menu, user<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
こうすることで、componentのdefaultを呼ぶか、userを呼ぶかなどモジュール、アクションなどにより変更できる。</p>
<h3>スロット(slot)</h3>
<p>いままでのものとはちょっと違うが、1回のレスポンスの中で部品化したい場合に2度同じテンプレートロジックを利用したいときなどに利用できる。</p>
<div class="igBar"><span id="lphp-36"><a href="#" onclick="javascript:showPlainTxt('php-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-36">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> slot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'hoge'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">hoge</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> end_slot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> include_slot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'hoge'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
slotで囲んだhogeがもう一度、下のinclude_slotで呼びだせます。</p>
<p>少しややこしいですが、こうしたテンプレートの部品化は設計にも影響与えてくる部分なのでしっかり見につけておきたい。</p>
<p>しかしこのややこしさ、どうにかならんものか。。。</p>
<p><a href="http://develop.ddo.jp/symfony/book/jp/1.0/view.html" target="_blank">symfony View:テンプレート、レイアウト、パーシャルとコンポーネント</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/05/06/symfony-include/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/05/06/symfony-include/" />
	</item>
		<item>
		<title>memcacheをsymfonyから利用してみる</title>
		<link>http://ueblog.natural-wave.com/2008/03/28/symfony-memcache/</link>
		<comments>http://ueblog.natural-wave.com/2008/03/28/symfony-memcache/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 14:03:39 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/03/28/symfony-memcache/</guid>
		<description><![CDATA[memcacheをsymfonyから利用してみました。 まずはyumを利用してmemcachedをインストールし、起動。 # yum install memcached # chkconfig --level 345 memcached on # /etc/init.d/memcached start phpからmemcacheにアクセスする環境をつくる。 # pecl install memcache php.iniに下記を追加し、apacheを再起動 extension=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/memcache.so 今回はsymfonyから簡単にmemcacheを利用できるプラグイン、sfMemcachePluginを利用する。 $ symfony plugin-install http://plugins.symfony-project.com/sfMemcachePlugin pluginのconfigディレクトリにある、2ファイル]]></description>
			<content:encoded><![CDATA[<p>memcacheをsymfonyから利用してみました。</p>
<p>まずはyumを利用してmemcachedをインストールし、起動。</p>
<blockquote><p># yum install memcached<br />
# chkconfig --level 345 memcached on<br />
# /etc/init.d/memcached start</p></blockquote>
<p>phpからmemcacheにアクセスする環境をつくる。</p>
<blockquote><p>#  pecl install memcache</p>
<p>php.iniに下記を追加し、apacheを再起動<br />
extension=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/memcache.so</p></blockquote>
<p>今回はsymfonyから簡単にmemcacheを利用できるプラグイン、<a href="http://trac.symfony-project.com/wiki/sfMemcachePlugin" target="_blank">sfMemcachePlugin</a>を利用する。</p>
<blockquote><p>$ symfony plugin-install <span class="ext-link"><span class="icon">http://plugins.symfony-project.com/sfMemcachePlugin</span></span></p></blockquote>
<p>pluginのconfigディレクトリにある、2ファイルをアプリケーションのconfigディレクトリにコピー</p>
<blockquote><p>$ cp plugins/sfMemcachePlugin/config/config_handlers.yml apps/app_dir/config/<br />
$ cp plugins/sfMemcachePlugin/config/memcache.yml apps/app_dir/config/</p></blockquote>
<p>memcache.ymlにmemcacheサーバに接続するホストなどの情報を書き換える。</p>
<div class="igBar"><span id="lcode-39"><a href="#" onclick="javascript:showPlainTxt('code-39'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-39">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">all:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; servers:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; default:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; host: localhost</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; port: <span style="color:#800000;color:#800000;">11211</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; timeout: <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; weight: <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; retry_interval: <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; status: <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; buckets:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; default:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; servers: default</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; news:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; servers: default </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>これで準備は完了。あとは利用方法はこんな感じ。</p>
<div class="igBar"><span id="lphp-40"><a href="#" onclick="javascript:showPlainTxt('php-40'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-40">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$namespace</span> = <span style="color:#FF0000;">'sample_namespace'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$key</span>&nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#FF0000;">'key'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$fc</span>&nbsp; &nbsp; &nbsp; &nbsp; = <span style="color:#000000; font-weight:bold;">new</span> sfMemcacheFunctionCache;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$result</span>&nbsp; &nbsp; = <span style="color:#FF0000;">''</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$fc</span>-&gt;<span style="color:#006600;">has</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</span>, <span style="color:#0000FF;">$namespace</span>, <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$result</span> = <span style="color:#0000FF;">$fc</span>-&gt;<span style="color:#006600;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</span>, <span style="color:#0000FF;">$namespace</span>, <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">else</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$result</span> = <span style="color:#FF0000;">'result!!'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$fc</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</span>, <span style="color:#0000FF;">$namespace</span>, <span style="color:#0000FF;">$result</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/03/28/symfony-memcache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/03/28/symfony-memcache/" />
	</item>
		<item>
		<title>symfonyでZend Frameworkのライブラリを使う</title>
		<link>http://ueblog.natural-wave.com/2008/03/24/symfony-zend-framework/</link>
		<comments>http://ueblog.natural-wave.com/2008/03/24/symfony-zend-framework/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 15:46:26 +0000</pubDate>
		<dc:creator>ueblog</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://ueblog.natural-wave.com/2008/03/24/symfony-zend-framework/</guid>
		<description><![CDATA[symfonyでZend Frameworkのライブラリを利用したい。 sfZendPluginっていうのが以前はあったようだが、現在は利用できないようだ。 なので、自分で環境を用意する。 １．まずは、Zend Framework Downloadからソースコードをダウンロードし、適当な場所に配置。今回は/usr/localに置いてみた。 # wget [URL] # cd /usr/local # tar xvfz ZendFramework-1.5.0.tar.gz ]]></description>
			<content:encoded><![CDATA[<p>symfonyでZend Frameworkのライブラリを利用したい。</p>
<p><a href="http://spindrop.us/2007/04/10/sfzendplugin/" target="_blank">sfZendPlugin</a>っていうのが以前はあったようだが、現在は利用できないようだ。</p>
<p>なので、自分で環境を用意する。</p>
<p>１．まずは、<a href="http://framework.zend.com/download" target="_blank">Zend Framework Download</a>からソースコードをダウンロードし、適当な場所に配置。今回は/usr/localに置いてみた。</p>
<blockquote><p># wget [URL]<br />
# cd /usr/local<br />
# tar xvfz ZendFramework-1.5.0.tar.gz</p></blockquote>
<p>２．symfonyプロジェクトのアプリケーションのsettings.ymlに下記を記述。</p>
<div class="igBar"><span id="lcode-42"><a href="#" onclick="javascript:showPlainTxt('code-42'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-42">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">all:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; .<span style="">settings</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; zend_lib_dir:&nbsp; &nbsp;/usr/local/ZendFramework-<span style="color:#800000;color:#800000;">1</span>.<span style="color:#800000;color:#800000;">5</span>.<span style="color:#800000;color:#800000;">0</span>/library</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; autoloading_functions:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; - <span style="color:#006600; font-weight:bold;">&#91;</span>sfZendFrameworkBridge, autoload<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>以上で、requireなどを書かなくても、Zend Frameworkの豊富なライブラリ群を利用可能だ。</p>
<p>Zend自体は、pearコマンドでもインストールできるようだ。</p>
<blockquote><p># pear channel-discover zend.googlecode.com/svn<br />
# pear install zend/zend</p></blockquote>
<p>この場合、pearで配置されるzendのlibraryディレクトリをzend_lib_dirに指定すればよい。</p>
]]></content:encoded>
			<wfw:commentRss>http://ueblog.natural-wave.com/2008/03/24/symfony-zend-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://ueblog.natural-wave.com/2008/03/24/symfony-zend-framework/" />
	</item>
	</channel>
</rss>

