PDA

View Full Version : نحوه کار کلاس facade تو لاراول ۴ چطوریه؟



mojtaba.baghban
شنبه 10 فروردین 1392, 14:41 عصر
نحوه کار کلاس facade تو لاراول ۴ چطوریه؟
یه لاراول کار اگه لطف کنه جواب بده ممنون میشم

mojtaba.baghban
شنبه 10 فروردین 1392, 20:48 عصر
تو سایت daylerees (http://daylerees.com/2012/09/13/laravel-the-bright-future/) دلیل استفاده از facade رو اینجوری توضیح داده:


Laravel 4 was a real challenge for Taylor. In the previous instalment of Laravel, each component used static methods for clean syntax. Our users are fans of this clean syntax, but the static methods create issues for testing. Modifying instances and mocking can be tricky with these types of classes.

To overcome these problems Laravel’s components are instances that exist within the Laravel 4 $app container object. As an example, component methods now look like :

$app['component']->methodName(); with the component accessible as an array index, using the ArrayAccess interface, this could also be accessed as $app->component->methodName();.

However this presents a new problem, our code is now less expressive, and would be harder to migrate from previous framework versions. Fortunately Taylor thought of using the Facade structural design pattern to provide short-cuts to these components using syntax that is more familiar. The above component can now be accessed using the Facade Component::methodName(); just as with Laravel 3.

Many components have Facades which emulate the syntax found in Laravel 3, which will allow for easy migration to the new framework, while maintaining the testing benefits, since the Facades are simply short-cuts to the instantiated components.

ولی هنوز کامل نمی‌دونم می‌خوام یکی که حرفه‌ای‌تره لطف کنه برام بازش کنه.
مثلا چرا کلاس Html بدون استفاده از facade پیاده‌سازی شده ولی مثلا Form با استفاده از facade پیاده‌سازی شده.
Facade فهم برنامه رو سخت کرده. نمی‌فهممش.
یکی لطف کنه توضیح بده
ممنون

Javidhb
یک شنبه 11 فروردین 1392, 00:22 صبح
سلام،

لاراول بخاطر اینکه که سینتکسش خوشگل و راحت و تر تمیز باشه از کلاس، متد و ... static زیاد استفاده میکنه. مشکل این کار اینه که تست برنامه سخت یا غیره ممکن میشه. به همین دلیل از طراحی Facade استفاده کرده که هم بتونه سادگی سینتکس رو حفظ کنه هم تست برنامه دچار مشکل نشه.


با دانلود ویدئو توی صفحه زیر میتونید اطلاعات خوبی راجع به لاراول و facade بدست بیارید:

https://tutsplus.com/lesson/when-they-say-laravel-shouldnt-use-static-methods/

اینجا هم راجع به طراحی facade توضیح داده:

http://www.litfuel.net/plush/?postid=35

mojtaba.baghban
یک شنبه 11 فروردین 1392, 01:17 صبح
ممنون از جوابت.
چرا کلاس Html بدون استفاده از facade پیاده‌سازی شده ولی مثلا Form با استفاده از facade پیاده‌سازی شده.

Javidhb
یک شنبه 11 فروردین 1392, 02:25 صبح
من فقط لاراول 4 بتای 1 رو اون اوایل دانلود کردم و دیدم ... ولی کلا زیاد نمیشه دنبال منطق خاصی واسه کاراشون گشت چون میزان تغییرات خیلی زیاده ... شاید دارن کلاس HTML رو تست میکنه (آخرین بار تیلور توی تویت.ر راجع به یه کلاس/ایده واسه کلاس FORM میگشت!)

اما همه کلاسها از لایه Facade استفاده خواهند کرد....

blognevis
سه شنبه 14 خرداد 1392, 10:48 صبح
سلام

دوستان کسی اموزش فارسی لارول را نداره برای ما بگذاره؟
تشکر