Download - Phalcon phpconftw2012
![Page 1: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/1.jpg)
Phalcon PHP Framework The Fastest Faster PHP Framework
阿土伯
![Page 2: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/2.jpg)
about:me
! 目前為 ViViPOS Co., Ltd 技術總監 ! 利用 javascript 寫 〞收銀機〞(傳統產業,全新感受)
! CoCo 都可、50嵐、歇腳亭、Yamaha 、星聚點 KTV
! #3 commiHer of cphalcon repository
! PHP / Javascript / Java Programmer (目前移情於 Scala )
! hHps://twiHer.com/racklin
! hHps://www.facebook.com/racklin1002
! hHp://racklin.blogspot.tw/ (生小孩後就變癈墟)
![Page 3: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/3.jpg)
議題
! PhalconPHP Framework 介紹
! PhalconPHP Kernel 介紹
! DEMO c9s ValidaWonKit porWng as php extension
![Page 4: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/4.jpg)
Programmers 共同的罩門
! 速度最快!
! 使用資源最小!
! 跨平台!
![Page 5: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/5.jpg)
Programmers 共同的罩門
! 速度最快!
! 使用資源最小!
! 跨平台!
所以大家來聽 PhalconPHP
![Page 6: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/6.jpg)
為什麼快
! Fibonacci 40 (費式數列) hHp://bit.ly/Pk8HkJ
Language Times
C with –O2 0m0.202s
java 0m1.305s
scala 0m1.808s
nodejs 0m2.872s
Ruby (1.9.x) 0m37.404s
Php (5.4) 1m17.728s
Python (2.7.2) 1m17.979s
Ruby (1.8.x) 3m35.135s
Php (5.3) 6m17.192s
![Page 7: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/7.jpg)
Fibonacci 40
0
100
200
300
400
500
c with -‐O2
java scala nodejs ruby 1.9.2
php 5.4 ruby 1.8.x
php 5.3
![Page 8: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/8.jpg)
所以結論…
下一個專案要用 c / c++ 來寫 web
![Page 9: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/9.jpg)
Raphters ! A web framework for C
![Page 10: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/10.jpg)
WOW! COOOOOOL~ 看起來好像很容易!
![Page 11: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/11.jpg)
除了慣C哥
大部份人打完招呼不知道要做什麼…..
![Page 12: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/12.jpg)
PHP 沒救了?
![Page 13: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/13.jpg)
Fibonacci as php extension
![Page 14: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/14.jpg)
Fibonacci as php extension
0m0.79s 馬上變成第二名
![Page 15: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/15.jpg)
Fibonacci 圖表
0 50
100 150 200 250 300 350 400 450
c with -‐O2 java scala nodejs ruby 1.9.2 php 5.4 ruby 1.8.x php 5.3 php ext
![Page 16: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/16.jpg)
速度只要出問題, C 都能搞定
![Page 17: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/17.jpg)
漂亮的平衡
A PHP web framework delivered as a C extension
![Page 18: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/18.jpg)
PHP extension frameworks
PhalconPHP Yaf
![Page 19: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/19.jpg)
為什麼不是 Yaf
! Underscore Class Name ( 目標 PHP 5.2 和以上版本)
! Document 實在不多
! Sample Codes 更少
![Page 20: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/20.jpg)
為什麼不是 Yaf
! Underscore Class Name ( 目標 PHP 5.2 和以上版本)
! Document 實在不多
! Sample Codes 更少
! Yet Another Framework (Yaf) 這專案名稱我不喜歡 很怕將來會出一個 What The Framework (WTx)
![Page 21: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/21.jpg)
Frameworks benchmark
![Page 22: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/22.jpg)
Frameworks memory usage
![Page 23: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/23.jpg)
PhalconPHP benefits
! PHP Extension – Faster
! Phalcon all Components are loosely coupled
! Low-‐Level OpWmizaWons
! Using c-‐language ORM for PHP
! PHQL – lemon parser (SQLite)
! Well-‐documented
![Page 24: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/24.jpg)
PhalconPHP 0.5 news
! Namespaces
! Class Loader – 相容於 PSR-‐0
! Dependency Injec8on
! Events Manager
! PDO Database Adapters ! * 支援 SQLite. ! * PostgreSQL 支援 Mul8-‐Schemas
! * CLI Applica8ons
! Micro Applica8ons
! Full stack frameworks
![Page 25: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/25.jpg)
PhalconPHP 0.6
! Object-‐Document Mapper -‐ MongoDB
! Volt: Template Engine -‐ inspired on Twig
! PS. 11/2 Released
![Page 26: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/26.jpg)
Class Loader Dependency InjecWon
Events Manager
Flexible Extensible Plugin-‐able
![Page 27: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/27.jpg)
Class Loader
! 盡可能不用使用 include / require .
! registerNamespaces – PSR-‐0 相容
! registerPrefixes
! registerClasses
! registerDirectories
![Page 28: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/28.jpg)
Using Class Loader
![Page 29: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/29.jpg)
Composer • 類似 PEAR 的套件管理工具,但更方便! 像是 npm / brew 。 • Install Composer
• IniWal project
• Require / Install libraries
• Update libraries
$ curl -‐s hHps://getcomposer.org/installer | php
$ composer.phar init
$ composer.phar require [vendor/name]
$ composer.phar update
![Page 30: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/30.jpg)
Composer Autoloading
• 只要加一行在你的程式中 require 'vendor/autoload.php';
hHps://packagist.org/
![Page 31: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/31.jpg)
Phalcon Class Loader + Composer Autloading
! Phalcon and Composer 都是使用 spl_autoload_register , spl_autoload_register 相當聰明,載入類別後會中斷執行,不會重覆載入
! 註冊 多個 autoload handlers 是安全的
! 所以只要在 Phalcon Class Loader 前先加上一行即可
require 'vendor/autoload.php’;
![Page 32: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/32.jpg)
Dependency InjecWon
! \Phalcon\DI 實作了 IoC 設計模式,幫助寫出可擴充性、易於測試、維護的程式碼。
! PhalconPHP 內部大量利用 DI 將各元件串接起來。
![Page 33: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/33.jpg)
Dependency InjecWon
! 產生新的物件或單例(Singleton) - get / getShared
! 傳參數給 Constructor
! Lazy loading ! 物件只有在被取得時才會產生
! Magic ! 如果沒有註冊,會自動試著找同樣的 Class Name
! 如果可以,全部利用 DI 來產生您的類別實例。
![Page 34: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/34.jpg)
DI 範例 (set)
![Page 35: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/35.jpg)
DI 範例 (get)
! 取得物件 $request = $di-‐>get("request");
! 透過 magic method $request = $di-‐>getRequest();
! Singleton $request = $di-‐>getShared("request");
! 傳參數給 constructor $component = $di-‐>get("MyComponent", array("some-‐parameter", "other"))
![Page 36: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/36.jpg)
Events Manager
! Web GUI 程式中,我們大量使用 Events 。 ! DOM Events
! Events Manager -‐ fire event , aHach listener
! Event Type Using colon : as namespace separator.
![Page 37: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/37.jpg)
DEMO
! Using Class Loader / Dependency InjecWon / Events Manager for plugin-‐able applicaWons.
! Linux Upstart init daemon like demo hHp://upstart.ubuntu.com/ (replacement for the venerable System-‐V init)
! Shopping-‐Cart Plugin-‐able PromoWons .
![Page 38: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/38.jpg)
Micro Framework
! Simple and ResTul
! Frameworks ! RubyàSinatra, Cuba
! PythonàFlask, Pyramid ! PHP àSilex, Slim ! Java àNapalm
![Page 39: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/39.jpg)
Micro Example
Not Found Handler
![Page 40: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/40.jpg)
Full Stack Framework
! MVC Architecture
! Router / Dispatcher
! View Helper / Template Engine
! Filtering Data
! Session
! Cache
! ACL
! Logging
! I18n/l10n
![Page 41: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/41.jpg)
Models CreaWng Models
By default model “Robots” will refer to the table “robots”.
![Page 42: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/42.jpg)
Models Finding Records
![Page 43: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/43.jpg)
Models Save changes
![Page 44: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/44.jpg)
Models Finding with condiWons , order and Limit
![Page 45: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/45.jpg)
Models
! RelaWons
![Page 46: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/46.jpg)
Models
! RelaWons
![Page 47: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/47.jpg)
Models
! RelaWons
![Page 48: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/48.jpg)
Models -‐ Criteria
! Similar To ! Doctrine QueryBuilder ! Yii Query Object
! Provides a fluent API.
![Page 49: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/49.jpg)
PHQL
! Similar To ! Doctrine DQL ! Hibernate HQL
! Phalcon Query Language is a high level, object oriented SQL dialect.
! High performance, Phalcon provides a parser that uses the same technology as SQLite. (lemon parser) hHp://www.sqlite.org/src/doc/trunk/doc/lemon.html
![Page 50: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/50.jpg)
PHQL
Select Records
Select Records with namespaces
![Page 51: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/51.jpg)
Controller
![Page 52: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/52.jpg)
View Helpers
! WriWng and maintaining HTML markup can quickly
Document type
Produced
![Page 53: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/53.jpg)
Template Engine -‐ Volt
! Volt is an ultra-‐fast and designer friendly templaWng language wriHen in C , inspired on Twig.
![Page 54: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/54.jpg)
Console ApplicaWon
! CLI Components
! cronjobs
! Daemon ApplicaWon ! Long-‐life applicaWon , using supervisor and kill yourself.
! Job Workers ! Using supervisor and kill yourself.
![Page 55: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/55.jpg)
CLI Launcher
![Page 56: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/56.jpg)
CLI MainTask
Php console.php // MainTask::mainAcWon
Php console.php main test // MainTask::testAcWon
![Page 57: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/57.jpg)
CLI DEMO
![Page 58: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/58.jpg)
PhalconPHP Kernel
! hHps://github.com/racklin/phalcon_kernel
! 由 cphalcon 中抽離出來的專案。
! 提供大量基於 Zend API 的巨集/工具。
! 簡化 php extension 開發。
![Page 59: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/59.jpg)
Why Extension
! Driver / Adapter
! Low-‐level NaWve Code Libraries
! Performance
! EncapsulaWon / InformaWon Hidden ! For Developer ! For Customers
![Page 60: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/60.jpg)
zval
![Page 61: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/61.jpg)
c: zval *a 相當於 php: $a
![Page 62: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/62.jpg)
Data Types
Long Boolean Double String value
ZVAL_LONG() ZVAL_BOOL() ZVAL_DOUBLE() ZVAL_STRING()
NULL
ZVAL_NULL()
Create macro
![Page 63: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/63.jpg)
Data Types
Long Boolean Double String value String Length
Z_LVAL() Z_BVAL() Z_DVAL() Z_STRVAL() Z_STRLEN()
Z_LVAL_P() Z_BVAL_P() Z_DVAL_P() Z_STRVAL_P() Z_STRLEN_P()
HashTable Object
Z_ARRVAL() Z_OBJVAL()
Z_ARRVAL_P() Z_OBJVAL_P()
GeHer and IdenWfy macro
Iden8fy BOOL Long Double String NULL
Z_TYPE() IS_BOOL IS_LONG IS_DOUBLE IS_STRING IS_NULL
Z_TYPE_P()
![Page 64: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/64.jpg)
Return Types
Macro Type
RETURN_FALSE / RETURN_TRUE Boolean
RETURN_NULL() NULL
RETURN_LONG() Long
RETURN_DOUBLE() Double
RETURN_STRING() String
RETURN_CTOR() RETURN_CCTOR() RETURN_NCTOR()
ZVAL (Phalcon)
![Page 65: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/65.jpg)
Memory Management
! Phalcon Memory Management 簡化了 Zend Memory Managemant.
! PHALCON_MM_GROW() 建立一個 phalcon memory entry 結構
! PHALCON_INIT_VAR / PHALCON_ALLOC_ZVAL_MM 建立並配置記憶體給 zval 並將其設為 null, 且將其指標的指標存至 phalcon memory entry.
! PHALCON_MM_RESTORE 釋放所有經由 PHALCON_INIT_VAR 配置且 refcount =1 的記憶體
![Page 66: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/66.jpg)
Phalcon MM Bad Parts
! PHALCON_ALLOC_ZVAL_MM or PHALCON_INIT_VAR ! 如果你 trace source code 二者差別只在於一個是先將 zval
pointer pointer 放入 memory entry 再設定初始值。一個是先設定初始值再將 zval pointer pointer 放入 memory entry ….
! PHALCON_INIT_VAR 3488 lines ! PHALCON_ALLOC_ZVAL_MM 468 lines
![Page 67: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/67.jpg)
MM Sample
![Page 68: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/68.jpg)
String
! ZVAL_STRING() – Zend API
! concat_funcWon – Zend API
! Concat macro
PHALCON_INIT_VAR(month); ZVAL_STRING(month, "2012", 1); PHALCON_INIT_VAR(today_is); ZVAL_STRING(today_is, "Today is", 1);
PHALCON_INIT_VAR(first_part); concat_funcWon(first_part, today_is, month);
PHALCON_INIT_VAR(today); PHALCON_CONCAT_SVSV(today, "Today is", month, " ", day);
![Page 69: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/69.jpg)
Concat Macros #define PHALCON_CONCAT_SV(result, op1, op2) \ #define PHALCON_CONCAT_SVS(result, op1, op2, op3) \ #define PHALCON_CONCAT_SVSV(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_SVSVS(result, op1, op2, op3, op4, op5) \ #define PHALCON_CONCAT_SVSVSV(result, op1, op2, op3, op4, op5, op6) \ #define PHALCON_CONCAT_SVSVSVS(result, op1, op2, op3, op4, op5, op6, op7) \ #define PHALCON_CONCAT_SVSVV(result, op1, op2, op3, op4, op5) \ #define PHALCON_CONCAT_SVV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VS(result, op1, op2) \ #define PHALCON_CONCAT_VSV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VSVS(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_VSVSVS(result, op1, op2, op3, op4, op5, op6) \ #define PHALCON_CONCAT_VSVSVSV(result, op1, op2, op3, op4, op5, op6, op7) \ #define PHALCON_CONCAT_VV(result, op1, op2) \ #define PHALCON_CONCAT_VVSV(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_VVV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VVVVV(result, op1, op2, op3, op4, op5) \
![Page 70: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/70.jpg)
Arrays
! array_init(zval*) – iniWal as array
! Add to array ! add_next_index_long / add_next_index_double ! add_next_index_bool / add_next_index_stringl
! Get (index type) (*string length) ! phalcon_array_fetch_long / phalcon_array_fetch_string
! Update (index type) (*string length) ! phalcon_array_update_long / phalcon_array_update_string
! Isset / unset (*string size) ! phalcon_array_isset_long / phalcon_array_isset_string ! phalcon_array_unset / phalcon_array_unset_string
![Page 71: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/71.jpg)
Phalcon Arrays Bad Parts
! PHP String is Binary-‐Safe ! String Length = Actually String Length ! String Size = String Length + 1 bytes(\0)
! Arrays fetch and update using String Length
! Arrays isset and unset using String Size
! Phalcon_array_unset not phalcon_array_unset_long
![Page 72: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/72.jpg)
Call FuncWons
! PHALCON_CALL_FUNC 呼叫 PHP funcWon ,有回傳值
! PHALCON_CALL_FUNC_NORETURN 呼叫 PHP funcWon ,沒有回傳值
! PHALCON_CALL_FUNC_PARAMS_1 呼叫 PHP funcWon 並傳一個參數,有回傳值
! PHALCON_CALL_FUNC_PARAMS_1_NORETURN 呼叫 PHP funcWon 並傳一個參數,沒有回傳值
! 目前巨集定義到傳 3 個參數
![Page 73: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/73.jpg)
Call FuncWons
PHP Code
![Page 74: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/74.jpg)
Call FuncWons
![Page 75: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/75.jpg)
Call Methods
! PHALCON_CALL_METHOD 呼叫 PHP funcWon ,有回傳值
! PHALCON_CALL_METHOD_NORETURN 呼叫 PHP funcWon ,沒有回傳值
! PHALCON_CALL_METHOD_PARAMS_1 呼叫 PHP funcWon 並傳一個參數,有回傳值
! PHALCON_CALL_METHOD_PARAMS_1_NORETURN 呼叫 PHP funcWon 並傳一個參數,沒有回傳值
! 目前巨集定義到傳 5 個參數
![Page 76: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/76.jpg)
Call Methods
![Page 77: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/77.jpg)
Object ProperWes
! Update Property ! phalcon_update_property_long ! phalcon_update_property_bool ! phalcon_update_property_null ! phalcon_update_property_zval /
phalcon_update_property_zval_zval
! Read Property ! phalcon_read_property / phalcon_read_property_zval
! Isset Property ! phalcon_isset_property / phalcon_isset_property_zval
![Page 78: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/78.jpg)
PHP Style WriWng c extension
![Page 79: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/79.jpg)
c9s ValidaWonKit hHps://github.com/c9s/ValidaWonKit
c extension DEMO
![Page 80: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/80.jpg)
References
! Slide: hHps://speakerdeck.com/racklin/phalcon-‐php-‐framework-‐and-‐phalcon-‐kernel-‐introducWon-‐phpcon�w2012
! Sample code: hHps://github.com/racklin/phpcon�w2012_phalcon
! PhalconPHP internal: hHp://internals.phalconphp.com/en/latest/index.html
![Page 81: Phalcon phpconftw2012](https://reader034.vdocuments.net/reader034/viewer/2022050808/558bc316d8b42ad74b8b45e5/html5/thumbnails/81.jpg)
Thank You