c9s
林佑安的技術博客 Yo-An Lin。
2012年2月24日星期五
Roller Router for PHP5.3
花了一些時間實作一個 Router - Roller , 可獨立使用的元件。
這個速度上應該夠用(快)了。 內建 closure serializer 跟 apc cache, 重新載入 routes 相當快。
除了附上文件之外,也有完整的 Unit test ,穩定度應該足夠。
要整合 Framework Console Tool 只需另外調用內建的 Console Dumper 就可以將 Router Rules 列印出來。
需求: PHP5.3, ezc/ConsoleTools
2012年1月8日星期日
[PHP] GenPHP 釋出 - 程式碼產生器
GenPHP 是筆者參考 Perl 的 Module::Setup 以及 Ruby newgem 等專案,並予以改進所設計的 PHP Code Generator,此產生器不一定要產生 PHP 程式碼,透過 Twig 樣板引擎以及內建的 Operation ,可以產生任何專案需要的檔案,如專案程式碼、專案內的 Controller, Model, Action、一整個資料夾結構或任何設定檔、文字檔等等,且可建置複雜的檔案建置。
只要定義好 Flavor ,就可以依據各種 Flavor 產生你所需要的檔案,每個 Flavor 也可以設定相依性,互相取得資料。舉例來說, project Flavor 可以相依 phpunit flavor , ANT flavor 等 flavor 。
除此之外,你可以將各種 Flavor 分開放置,可以設定為全域的 Flavor ,或是某專案內才使用的 Flavor,你也可透過路徑將 Flavor 安裝至你的 Home Flavor 資料夾內。
GenPHP 也可以用來產生 Asset ,你可以將你常用的 Asset 放於 Flavor 內的 Resource 路徑,有需要便可即時產生出來。
這是第一個版本的釋出,接下來的版本將會支援個人化的設定檔,可設定偏好 copyright string, author email, author name 使用之 license 等。
專案網址:
https://github.com/c9s/GenPHP
只要定義好 Flavor ,就可以依據各種 Flavor 產生你所需要的檔案,每個 Flavor 也可以設定相依性,互相取得資料。舉例來說, project Flavor 可以相依 phpunit flavor , ANT flavor 等 flavor 。
除此之外,你可以將各種 Flavor 分開放置,可以設定為全域的 Flavor ,或是某專案內才使用的 Flavor,你也可透過路徑將 Flavor 安裝至你的 Home Flavor 資料夾內。
GenPHP 也可以用來產生 Asset ,你可以將你常用的 Asset 放於 Flavor 內的 Resource 路徑,有需要便可即時產生出來。
這是第一個版本的釋出,接下來的版本將會支援個人化的設定檔,可設定偏好 copyright string, author email, author name 使用之 license 等。
專案網址:
https://github.com/c9s/GenPHP
2011年12月27日星期二
[PHP] 如何使用 Onion 建置 PEAR 套件
以往要建置 PEAR 套件,得先研究 package.xml 的規格,然後使用一個超過 200 多行的樣板一行一行修改,若是檔案一多,更是麻煩。
因此 Onion https://github.com/c9s/Onion 是為了解決 PEAR 套件建置所提供的方案。
首先請確認你的程式碼目錄結構
測試相關的檔案可放置於 tests/,一般來說都是使用 PHPUnit 作為測試框架,你也可以使用 PHPUnit_TestMore 來幫助你簡化測試程式碼。
接著即可建立 package.ini 來建置 PEAR 套件。
於套件目錄下,編輯 package.ini 檔案
你也可以透過 PEAR Installer 直接安裝該套件:
Onion on GitHub: https://github.com/c9s/Onion
因此 Onion https://github.com/c9s/Onion 是為了解決 PEAR 套件建置所提供的方案。
首先請確認你的程式碼目錄結構
- src/ 類別目錄
- doc/ 文件目錄
- tests/ 單元測試目錄
<?php
namespace Foo;
class Bar {
}
應該被放置在 src/Foo/Bar.php 檔案中。測試相關的檔案可放置於 tests/,一般來說都是使用 PHPUnit 作為測試框架,你也可以使用 PHPUnit_TestMore 來幫助你簡化測試程式碼。
接著即可建立 package.ini 來建置 PEAR 套件。
於套件目錄下,編輯 package.ini 檔案
[package]
name = PacakgeName
version = 0.0.1
desc = description here
summary = summary here
author = Author Name <your_email@email.com>
如果你的套件相依其他 PEAR 模組,可接著定義:[require]
pear.twig-project.org/Twig = 1.0.1
格式為:{PEAR Channel Host}/{Package Name} = {Version Expression}
接著,將 Onion.phar 抓取下來裝置於你的系統中:$ wget https://github.com/c9s/Onion/raw/master/onion.phar
$ chmod +x onion.phar
$ ./onion.phar -d build
即可建置 PEAR 套件檔案。 PackageName-0.0.1.tgz 就會被產生出來。你也可以透過 PEAR Installer 直接安裝該套件:
$ sudo pear install -f package.xml
若你希望將相依性安裝至該套件目錄,且不需要 root 權限,你可以執行:$ ./onion.phar -d bundle
相依套件就會被安裝至 vendor/pear 內。Onion on GitHub: https://github.com/c9s/Onion
2011年12月25日星期日
[PHP] Onion For PEAR: 發佈 Onion 0.0.10 bundle 功能
我們目前釋出了 Onion 0.0.10-alpha 的版本,這個版本包含了 bundle 的功能,可以將 PEAR 的相依套件安裝至目前目錄的 vendor 目錄底下,且不需要相依 PEAR Installer 或是 Pyrus。
你可以在 package.ini 內定義好 PEAR 套件的所有相依性,然後執行 onion.phar -d bundle 的命令,Onion 會將所有套件安裝至本地目錄下,且不需要 Root 權限就可以做到。
目前,Onion 是利用 bundle 指令,將 Onion 自己的相依套件全部安裝至 vendor/pear ,然後使用 Onion 自己的 compile 命令,將本身程式碼、相依程式碼、自動類別載入器打包成 phar 的執行檔。
你也可以使用 Onion 來編譯你自己的 phar 函式庫或是執行檔。你可以參考原始碼內的 scripts/compile.sh 命令。
因為 Pyrus 沒有把 Package.xml 剖析器類別、PEAR 頻道探索器等文件寫好,也因為他不是獨立的元件,所以我為 Onion 寫了一個內建的 PEAR 頻道探索器 (PEAR Channel) 以及簡單的 package.xml 剖析器,來處理 PEAR 套件的安裝程序。 這些東西運作的相當快,不過 Channel 的資訊還未被快取起來,只要快取的部份處理好後,速度會比現在更快。
我已經測試了一些 Symfony, PHPUnit, PHPSpec, PEAR 套件,大多數都運作的挺順利,但是可能還有一些 Bug ,如果你遇到了,請發送一個 Issue 給我,Onion 專案是建置在 GitHub 上頭。
Patches, Feature requests are welcomed.
Here is the screenshot:
Related Tweets:
https://twitter.com/#!/yuya_takeyama/status/150642017003778050
https://twitter.com/#!/yuya_takeyama/status/150627664917577728
https://twitter.com/#!/yuya_takeyama/status/150619889244180481
Onion For PHP: Announcing Onion 0.0.10 bundle feature
We currently released Onion 0.0.10-alpha, this version introduced a bundle feature, which can install PEAR package dependencies into a vendor directory.
You can define your PEAR package dependencies in package.ini, and run onion.phar -d bundle, onion will install dependencies locally, and root permission is not needed.
Currently, Onion is using bundle command to install Onion's dependencies, and run onion compile command to compile src/, vendor/pear/ and a SPLClassLoader into a phar file.
You can also use Onion to compile your library into a plain library phar file or executable phar file, you can check the script "scripts/compile.sh".
Since Pyrus didn't document much of its PackageXml parser and Channel Discover, and it's not independent component, I wrote a built-in PEAR channel discover and a simple package.xml parser for this, which is pretty fast already. but the channel information is not cached yet. Once the cache stuff is done, this could be more faster than current one.
I've tested many PEAR packages from Symfony, PHPUnit, PHPSpec, most of them works fine, but may have some bugs still, If you encountered, please send an issue on GitHub/Onion repository.
Onion project is hosted on GitHub, patches and feature request are welcomed.
Here is the screenshot:
Related Tweets:
https://twitter.com/#!/yuya_takeyama/status/150642017003778050
https://twitter.com/#!/yuya_takeyama/status/150627664917577728
https://twitter.com/#!/yuya_takeyama/status/150619889244180481
訂閱:
文章 (Atom)

