gasol

0 notes

PHP Manual in VIM

網路上提供的tags都太舊了,所以就自已動手產生吧!我今天在FreeBSD上做了一遍,現在用Mac寫文章,所以這邊就以Mac的環境說一下流程,我不太清楚Mac OS X Server和XCode預設裝了哪些東西,所以我把環境列上來提供參考:

操作環境Mac OS X Server v10.6.7
XCode 4.0.2
PHP 5.3.4
一、安裝PEAR
Mac OS X Server出廠就有LAMP stack的環境了,但PHP沒編—with-pear,所以要自已裝,基本上是照著pear官網的文件,但我沒有加_-d detect_unicode=0。_
$ curl http://pear.php.net/go-pear.phar > go-pear.phar
$ sudo php -q go-pear.phar

Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type ‘all’ to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix) : /usr/local
2. Temporary directory for processing : /tmp/pear/install
3. Temporary directory for downloads : /tmp/pear/install
4. Binaries directory : /usr/local/bin
5. PHP code directory ($php_dir) : /usr/local/share/pear
6. Documentation directory : /usr/local/docs
7. Data directory : /usr/local/data
8. User-modifiable configuration files directory : /usr/local/cfg
9. Public Web Files directory : /usr/local/www
10. Tests directory : /usr/local/tests
11. Name of configuration file : /Users/gasol/.pearrc

1-11, ‘all’ or Enter to continue:預設會裝在個人的home目錄,這邊我把prefix改成/usr/local,如果是裝在別的地方,注意一下PATH要找的到pear,最後會詢問是否要在php.ini把pear的路徑加在include_path。
裝完再用pear裝待會兒會用到的PhD和XML_Parser
$ sudo pear install doc.php.net/phd_php
Did not download optional dependencies: phpdocs/PhD_PEAR, phpdocs/PhD_IDE, use —alldeps to download automatically
phpdocs/PhD_PHP can optionally use PHP extension “haru”
phpdocs/PhD can optionally use package “phpdocs/PhD_PEAR”
phpdocs/PhD can optionally use package “phpdocs/PhD_IDE”
phpdocs/PhD can optionally use PHP extension “haru”
phpdocs/PhD_Generic can optionally use PHP extension “haru”
downloading PhD_PHP-1.1.0.tgz …
Starting to download PhD_PHP-1.1.0.tgz (24,067 bytes)
……..done: 24,067 bytes
downloading PhD-1.1.0.tgz …
Starting to download PhD-1.1.0.tgz (42,303 bytes)
…done: 42,303 bytes
downloading PhD_Generic-1.1.0.tgz …
Starting to download PhD_Generic-1.1.0.tgz (28,104 bytes)
…done: 28,104 bytes
install ok: channel://doc.php.net/PhD_Generic-1.1.0
install ok: channel://doc.php.net/PhD-1.1.0
install ok: channel://doc.php.net/PhD_PHP-1.1.0

$ sudo pear install XML_Parser
downloading XML_Parser-1.3.4.tgz …
Starting to download XML_Parser-1.3.4.tgz (16,040 bytes)
……done: 16,040 bytes
install ok: channel://pear.php.net/XML_Parser-1.3.4
詳細安裝方式可以參考 https://wiki.php.net/doc/phd/install

二、從SVN Repository產生PHP Documentation.

svn co http://svn.php.net/repository/phpdoc/modules/doc-en phpdoc
… ignore …
A phpdoc/en/features/figures/simple-array.png
A phpdoc/en/features/figures/simple-array2.png
A phpdoc/en/features/figures/leak-array.png
A phpdoc/en/features/commandline.xml
A phpdoc/en/features/sessions.xml
A phpdoc/en/features/gc.xml
A phpdoc/en/features/remote-files.xml
A phpdoc/en/features/cookies.xml
A phpdoc/en/features/http-auth.xml
A phpdoc/en/features/xforms.xml
U phpdoc/en
Checked out external at revision 311445.

Checked out revision 311445.
會clone一堆xml下來,接著執行./build.sh
$ cd phpdoc
phpdoc/ $ ./build.sh
configure.php: $Id: configure.php 310808 2011-05-06 16:11:39Z bjori $
PHP version: 5.3.4

LibXML 2.7.4+ added a ‘feature’ to break things, typically namespace related, and unfortunately we must require it.
For a few related details, see: http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg777646.html
Please recompile PHP with a LibXML version 2.7.4 or greater. Version detected: 2.7.3
Or, pass in —disable-libxml-check if doing so feels safe.

Checking for source directory… /Users/gasol/tmp/phpdoc/doc-base
Checking for output filename… /Users/gasol/tmp/phpdoc/doc-base/.manual.xml
Checking whether to include CHM… no
Checking for PHP executable… /usr/bin/php
Checking for language to build… en
Checking whether the language is supported… yes
Checking for partial build… no
Checking whether to enable detailed XML error messages… yes
Checking libxml version… 2.7.3
Checking whether to enable detailed error reporting (may segfault)… yes
Checking whether to optimize out the DTD (performance gain, but segfaults)… yes
Generating /Users/gasol/tmp/phpdoc/doc-base/manual.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/install-unix.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/install-win.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/developer.template.xml… done
Generating /Users/gasol/tmp/phpdoc/doc-base/entities/version.ent… done
Generating /Users/gasol/tmp/phpdoc/doc-base/scripts/file-entities.php… done
Iterating over extension specific version files… OK
Saving it… OK
Creating file /Users/gasol/tmp/phpdoc/doc-base/entities/file-entities.ent… done
Checking for if we should generate a simplified file… no
Checking whether to save an invalid .manual.xml… no
Loading and parsing manual.xml… done.
Validating manual.xml… done.

All good. Saving .manual.xml… done.
All you have to do now is run ‘phd -d /Users/gasol/tmp/phpdoc/doc-base/.manual.xml’
If the script hangs here, you can abort with ^C.
(Run `nice php configure.php` next time!)

PHP will segfault now :) - Don’t worry though, the .manual.xml has been saved :D
[23:42:04 - Heads up ] Creating output directory..
[23:42:04 - Indexing ] Indexing…
[23:44:02 - Indexing ] Indexing done
[23:44:02 - Rendering Style ] Running full build
[23:44:03 - Rendering Format ] Starting PHP-Chunked-XHTML rendering
[23:46:30 - Rendering Format ] Writing search indexes..
[23:46:30 - Rendering Format ] Index written
[23:46:30 - Rendering Format ] Finished rendering
結束後就可以看到日期是今天最新的PHP Documentation.


三、把HTML轉換成VIM helptags

作者的網頁下載Parser,這隻script年代有點久遠,所以我加了點料 patch讓它可以順利執行

在phpdoc的上一層目錄執行parser2.php
$ curl http://blog.planetxml.de/uploads/source/php/phpdoc/parser2.php.txt > parser2.php
$ patch -p1 pathogen的話要把pathogen#helptags()拿掉,它會自動執行helptags把tags檔覆蓋過去,我個人是用pathogen擺在$HOME/.vim/bundle/phpdoc/doc底下,接著在.vimrc加上一行autocmd BufNewFile,BufRead *.php set keywordprg=”help”就大功告成了!

最後,開一個php檔到處在funciton按K測試看看吧,在沒有雙瑩幕的環境,用這方法看manual可以結省不少切換視窗的時間,helptags的應用可以參考李果正 - 大家來學VIM 12.5.2節
http://dlvr.it/T67ZV

0 notes

Using Reflection to get private property value in PHP

說在前頭,此方法破壞了OO封裝的原則,多數的狀況下是不適用的!用這方法前請確定你了解,而且需要它!不然結果會很恐怖的。

PHP 5的Property Visibility [http://php.net/manual/en/language.oop5.visibility.php]提供_public_, _protected_, _private_三個keyword來封裝資料,property一旦宣告了private,就代表它與世隔絕,要存取它可以另外透過getter accessor,然後magic就在此黑盒子裡面發生了!

今天碰到一個狀況,在Thrift [http://thrift.apache.org/]的PHP Library裡,我必需存取一個宣告為private但沒有getter的property,@ronnywang [http://twitter.com/ronnywang]告訴了我有PHP Reflection [http://www.php.net/manual/en/book.reflection.php],我就在這裡找到答案了,透過ReflectionProperty的setAccessible就可以輕鬆的達到這個需求。

http://dlvr.it/SmmTy

0 notes

Incoming call

今天接到苔哥來電,看到來電內心就在想「久久沒有聯絡,來電必定有事」!但我沒意料是個不好的消息,大學常混在一起的同學父親因癌症過世了!消息來得太突然,所以其實我並沒有太大的反應,加上最近飽受牙痛所苦,心情到是還蠻平靜的起伏沒有很大,最後電話結束後約好假日要一起下去看同學目前的狀況,就只是這樣,因為白天上班其實沒有太多絲緒來思考工作外的事物。

下班時,騎車回家等紅燈的時後想起我阿公前陣子也得了癌症,醫生說狀況並不是很樂觀,我想起當時那時後的心境,心情也很低落,而且開始思考以前沒有思考過的問題,人生的精華片段已經來到中間了,開始面對了生老病死的後三個字,很現實的問題,逃也逃不掉!但總要去面對它,希望大家多珍惜身邊的人,悲傷過後記住一件事,回憶並沒有被帶走,它是最好的禮物。

我計劃明年就要搬回家跟父母一起住了,然後通勤到台北上班!這個想法已經很久了,因為我漸漸的了解我也開始在跟時間賽跑了…

0 notes

終於官方的Google Reader的Android App也出了,在此之前都是用NewsRob!但吊詭的是為啥下載次數小於50,但評分有976這麼多,難得這是你知、我知、大家知的密秘?

終於官方的Google Reader的Android App也出了,在此之前都是用NewsRob!但吊詭的是為啥下載次數小於50,但評分有976這麼多,難得這是你知、我知、大家知的密秘?

0 notes

國家CTO

今天在PTT上看到鄉民在討論國民兩黨的CF!不知道我是不是比較偏綠,就是綠色的比較對胃口,不論口味,綠黨的網軍實力是比較堅強的這點無誤…

如果網軍的實力拿來擴展政府部門單位的IT業務,學習美帝的軟實力,公開API讓全民來開發才是正姐啊,不知道這點小希望哪位能聽進去,美國有CTO帶領政府IT發展,台灣呢?