Download - PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Transcript
Page 1: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

What's New InWhat's New In

Yii2 & PHP5.5Yii2 & PHP5.5

Petra Novandi BarusChief Technology Officer

UrbanIndo.com

PHP Indonesia MeetupPHP Indonesia Meetup

Page 2: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Who Am IWho Am I

● 2009 Graduated from Informatics Eng. ITB– Activities: OS and Internet programming lecture assistant, table

tennis unit, etc.

● 2011 Graduated from Master Informatics Eng. ITB– Specialize in distributed systems and parallel programming

● 2011 Recruited as CTO for UrbanIndo.com

Contact Me:- mail: [email protected] twitter: @petrabarus- linkedin: http://linkedin.com/in/petrabarus

Page 3: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

UrbanIndoUrbanIndo● A real-estate marketplace for Indonesia: house, land,

apartment, commercial, room.

● Board members consist of professionals from Silicon Valley: Apple, Google, Yahoo.

● Launched November 2011

● Got investment from East Ventures 4 months later

● Got investment from Gree Ventures & IMJ Fenox in 2013

● Currently listing

– 16 thousand registered users

– 7 thousand agents

– 100 thousand properties

Page 4: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

UrbanIndo Technology StackUrbanIndo Technology Stack

elasticsearchelasticsearch

Page 5: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

What I'm Going To Talk AboutWhat I'm Going To Talk About

●Yii2● PHP 5.5

(Not really related with Yii2, just filling some time for the Iftar)

Page 6: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Let's talk about Yii firstLet's talk about Yii first

● A macro PHP framework● A lot of functionalities● Great design● Easy to extend● Easy to configure

● But hard learning-curve

Page 7: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Yii FeaturesYii Features

● MVC● DAO, Active Record, Database Migration● Authentication/Authorization● Skinning/Theming● Web Services● I18n, L10N● Cache● And many more

Page 8: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Yii2Yii2

● Yii2 is now in public preview.– It's not even alpha– Don't use it for production– Not all functionalities from Yii1.1 has been

imported.

● Supports PHP5.3+● Most of the changes are in redesigning the

architecture.

Page 9: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

What's new in What's new in Yii2?Yii2?

Page 10: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

NamespaceNamespace

● Actually Yii1.1 has support namespace usage in user's code (since 1.1.5) using autoloading

● For PHP5.3+ usage only (Yii1.1 still supports PHP5.2)

● Support PSR-0

Better IDE support

Can easily be mistaken with other Strings

Page 11: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

NamespaceNamespace

● Yii1.1 classes has to be in global namespaces

● To prevent conflict, allclasses in Yii1.1 use 'C' prefix.

Page 12: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Namespace in Yii2Namespace in Yii2

● Better namespace organization– e.g. we used to have–

– No more longclass name

Page 13: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 14: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 15: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Components and ObjectComponents and Object

● In Yii1.1, we have CComponents– Getter/Setter through magic __get, __set, __call– Behavior– Event.

● In Yii2 we have Object and Component– Object, basic data structure, getter/setter,

toArray, object configuration, className (added in PHP5.5).

– Component, extends Object, added event and behavior

Page 16: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Object ConfigurationObject Configuration

● In Yii1.1●

● In Yii2

Page 17: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Event HandlerEvent Handler

● More straightforward using jQuery-like event handler

Page 18: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

View ObjectView Object

● In Yii1.1 'view' is implemented as plain php file.

Page 19: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 20: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

View ObjectView Object

● In Yii2, the view is implemented as a View object

Page 21: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

View ObjectView Object

● Controller and Widget now accessed as View's context

● Easily do view-rendering every where, not just in controller

● CClientScript responsibility is now part of View object.

● Fragment cache moved from Controller to View object

● Supports multiple non-native renderer like Smarty and Twig

Page 22: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ModelsModels

● Yii2 introduces formName– Yii1.1 uses hardcoded class name

Page 23: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ModelsModels

Page 24: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ModelModel

● Easy loading (mass attribute assignment from $_POST or $_GET)

Page 25: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ModelModel

● Mass object assignment, e.g. Tabular Input

Page 26: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

WidgetsWidgets

● In Yii1.1, Widget helps a lot. But declaring one can give great pain.

● Bad IDE support

Page 27: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

WidgetsWidgets

● In Yii2, added className() method (PHP5.3) and begin(), end() method.

Page 28: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Query BuilderQuery Builder

● Query builder stands alone

Page 29: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ActiveRecordActiveRecord

● Relation now done via getter instead of relations() method

● Getter returns ActiveQuery that extends Query

Page 30: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 31: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

ActiveRecordActiveRecord

● Method find() replaces method model() which returns ActiveQuery instance instead of the extended CactiveRecord model instance.

Page 32: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Many MoreMany More

● Assets Bundling● Static Helpers● ActiveForm● Auto Quoting Column Names● User and Identity● Better URL Management

Page 33: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

More to comeMore to come

● Better Extension management● Response/Request● Integration with Composer● Widgets (Menu, Pager, Captcha)● NoSQL wrapper● MessageQueue wrapper

Page 34: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

WarningWarning

● Yii2 is still in heavy development● It's not even in Alpha phase● What I talk about right now can be obsolete

next week● Fork the github

– http://github.com/yiisoft/yii2

● Try installing● Put your idea and your fix

Page 35: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

What's new in What's new in PHP 5.5PHP 5.5

Not really related with Yii2, just filling some time

Page 36: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

What's NewWhat's New

● Generators● “Finally” Keyword● Password Hashing API● Bundled OPcode cache● Class name to scalar● Array dereferencing● And many more...

Page 37: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

GeneratorGenerator

● Simple iterator without implementing “Iterator” interface

● Iterate result without building array in memory– Exceed memory limit– Time consuming

● Introduces the keyword 'yield'

Page 38: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 39: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 40: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

'Finally' keyword'Finally' keyword

● Just like the one in Java● Mostly concerns with resource handling

– Prevent resource leaking

● Block in `finally` will be executed no matter if the exception caught or not

Page 41: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 42: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Page 43: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Bundled Zend OpCacheBundled Zend OpCache

● is ZendOptimizerPlus by Zend

– https://github.com/zendtech/ZendOptimizerPlus

– provides faster PHP execution through opcode caching andoptimization

– storing precompiled script bytecode in the shared memory

● There is also APC (Alternative PHP Cache)

– not really maintainable● Zend OpCache is now bundled with PHP5.5

– You can still install it in PHP5.2, PHP5.3, PHP5.4

Page 44: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

http://www.slideshare.net/jpauli/php55-new-features-23608435

Page 45: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Password Hashing APIPassword Hashing API

● password_hash()– Can set the algorithm, the cost, the salt– The value returned will contain the algorithm, the

cost, the salt, and the hash itself.– Only need 1 storage (or 1 column in table).

● password_verify()– Only take the plain password and the hash result

Page 46: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Thank You!Thank You!

Page 47: PHP Indonesia Meetup - What's New in Yii2 and PHP5.5

Just for your information :)

We have a lot of opportunities- Web engineer- Front-end engineer- Mobile app engineer- Data scientist

- Internship

Send your resume to [email protected]