Ava Lite

Ava framework ကို ရေးပြီးတာတော့ ကြာပြီ။ ဒါပေမယ့် bluehost မှာ တင်တော့ ပြဿနာ တက်တာပဲ။ ဘာလို့လည်းဆိုတော့ memory usages အရမ်းများနေလို့။ ဘာကြောင့်များတာလဲလို့ code ကို ကြည့်လိုက်တော့ class ကို recursive ဖြစ်နေတာတွေ့ ရတယ်။

[php] $this->load=$this; [/php]

အဲဒါက အဓိက ပြဿနာပဲ။ အဲဒီ recursive က dead lock ဖြစ်သွားပြီး memory limit ပြည့်သွားတာ။ အစက hosting ကို သွားပြီး အပြစ်တင်သေးတယ်။ ဒါပေမယ့် ကိုယ့်ဘာသာ code ကို သေချာပြန်စစ်တော့ အဲဒီ နေရာက ပြဿနာ တက်ပါလေရော။ ပြန်ပြင်မယ်ဆိုတော့လည်း လက်ရှိ ရေးထားတဲ့ အပိုင်းတွေကို အကုန်လိုက်မပြင်ချင်ဘူး။ application folder က အပိုင်းကို မပြင်ရအောင် core တစ်ခုလုံး ပြင်ဖို့ ကြိုးစားရကော။ သို့သော် မရ။ ဘယ်လို ရေးရမယ်ဆိုတဲ့ idea ကို ကောင်းကောင်းမရဘူး။ Google ကလိုက်ရှာတော့လည်း မတွေ့ဘူး။ တော်တော်များများက $this->load=$this; နဲ့ ရေးထားတဲ့ tutorial တွေ အရမ်းများနေတယ်။

မဖြစ်သေးပါဘူး။ light version ကနေ စရေးရမယ်ဆိုပြီး စဖြစ်လိုက်တာပဲ။ ရေးမယ်တာ ပြောတာ။ ဘယ်က စရမှန်း မသိ။ UML တွေ ဆွဲကြည့်ရင်းနဲ့ သဘောတစ်ခုပေါက်သွားတာက Singleton ကို ငါ သုံးသင့်တာပဲ ဆိုပြီး သဘောပေါက်သွားတယ်။ Objective-c ကို အဲမှာ ကျေးဇူးတင်ရမယ်။ Objective-C လေ့လာရင်းနဲ့ memory တွေ အတတ်နိုင်ဆုံး နည်းအောင် ဘယ်လိုရေးသင့်လဲဆိုတာကို စဉ်းစားတတ်လာတာ။ iPhone 3Gs လို memory နည်းနည်းလေးမှာ ဘယ်လိုမျိုး သုံးရင် အဆင်ပြေမလဲဆိုတာကို ထည့်သွင်းစဉ်းစားလာရတာကြောင့်လည်း ပါတယ်။ အဲဒါက လက်ရှိ Ava framework ကို ပြန်ပြင်ဖို့ အများကြီး အထောက်အပံ့လာဖြစ်တယ်။ Core တစ်ခုလုံးကို Singleton ထားပြီး အဲဒီမှာပဲ initialize လုပ်သွားရင် သက်သာသွားမယ်။ recursive မဖြစ်တော့ဘူး။

နောက်တချက်က Loader ကို ခေါ်တဲ့ အခါမှာ Passing by Reference နဲ့ အသုံးပြုရင် ပိုသက်သာသွားမယ်။ class ကို ခဏခဏ load ခေါ်နေစရာ မလိုတော့ဘူး။ ဒီတော့ ဒီလို ရေးဖြစ်သွားမယ်။

controller.php မှာ load ကို ဒီလိုခေါ်လိုက်တယ်။
[php]$this->load =& load_class(‘Loader’);[/php]

ပြီးတော့ load_class အတွက် function ထဲမှာ

[php]
function &load_class($class)
{
static $objects = array();

if($class==’Loader’)
{
$name="Ava_Loader";
}
// Does the class exist? If so, we’re done…
if (isset($objects[$name]))
{
return $objects[$name];
}

$objects[$class] =& instantiate_class(new $name());
return $objects[$class];
}

function &instantiate_class(&$class_object)
{
return $class_object;
}
[/php]

By Reference နဲ့ပဲ ခေါ်လိုက်တာကြောင့် loader class က အဆင်ပြေသွားပြီ။ နောက်ပြီး model class ကိုလည်း ပြန်ပြောင်းရသေးတယ်။ model class မှာ တစ်ခု ထပ်စဉ်းစားရတာက လက်ရှိ controller က ခေါ်ထားတဲ့ ဟာတွေပဲ ပြန်ပြီး ခေါ်လို့ရရမယ်။ ဥပမာ controller က model1 ကို ခေါ်ထားတော့ model2 ထဲမှာ model1 ကို ထပ်ခေါ်စရာမလိုပဲ တိုက်ရိုက် ခေါ်လို့ရရမယ်။

အဲဒီတော့ အကုန်လုံးကို ပြန်ပြီး assign လုပ်လိုက်တယ်။

[php]
function _assign_libraries($use_reference = TRUE)
{
$Ava =& get_instance();
foreach (array_keys(get_object_vars($Ava)) as $key)
{
if ( ! isset($this->$key) AND $key != $this->_parent_name)
{
// In some cases using references can cause
// problems so we’ll conditionally use them
if ($use_reference == TRUE)
{
$this->$key = NULL; // Needed to prevent reference errors with some configurations
$this->$key =& $Ava->$key;
}
else
{
$this->$key = $Ava->$key;
}
}
}
}
[/php]

Model လိုမျိုး view မှာလည်း အဲဒီ အတိုင်းပဲ။ ဒါကြောင့် view ကိုခေါ်တဲ့ အခါမှာ ပြန်ပြီး assign လုပ်ပေးဖို့လိုတယ်။

[php]
$_ava_Ava =& get_instance();
foreach (get_object_vars($_ava_Ava) as $_ava_key => $_ava_var)
{
if ( ! isset($this->$_ava_key))
{
$this->$_ava_key =& $_ava_Ava->$_ava_key;
}
}
[/php]

လက်ရှိ Base class ကို singleton အနေနဲ့ သုံးလိုက်တာဟာ ပြဿနာတွေ အများကြီး ပြေလည်သွားတယ်။ UML ဆွဲတုန်းက idea သာ ရတာ။ ခက်တာက ဘယ်လို ရေးရမှန်းမသိ။ ကိုယ့်ဘာသာကိုယ်တောင် ရှက်မိတယ်။ PHP ကို သိရုံပဲ သိသေးပါလား ဆိုပြီး တွေးမိလေရဲ့။ By Reference တွေနဲ့ ဘယ်အချိန်မှာ ဘယ်လို ခေါ်ရေးရမှန်း မသိဘူး။ ဒါနဲ့ CodeIgniter ရဲ့ မူရင်း code ကို အသေးစိတ် လိုက်ဖတ်ရင်းနဲ့ သူရေးထားတာ သဘောပေါက်လာတာ။ အခု လက်ရှိ code တွေအကုန်လုံးက CodeIgniter က code တွေကို မှီငြမ်းထားတာပါပဲ။

ဒီနေ့တော့ lite version လေး ပြီးတာ ကျေနပ်သွားတယ်။ မနက်ဖြန်ဆိုရင်တော့ Ava Framework ကို စလို့ရပြီ။ core တစ်ခုလုံးကိုတော့ အစ အဆုံးပြန်ပြင်ရေးရမယ်။ အဲဒါပြီးမှပဲ Ava Documentation ကို သေချာအောင် ပြန်ပြီး ရေးရမယ်။ အခုတော့ http://www.avaframework.com ဆိုပြီး domain name ပဲ ဝယ်ထားတယ်။ Ava framework လေးကိုတော့ သေသေချာချာ လေးလုပ်ဖို့ စဉ်းစားထားတယ်။ Ornagai ကို ava နဲ့ ပြန်ပြင်ဖို့ စဉ်းစားထားတာကြောင့်လည်း ပါတာပေါ့။ ဒါနဲ့ Ava ဆိုတာက အဝ နော်။ အာဗ မဟုတ်ဘူး။ အင်းဝမြို့ နာမည်ကို အစွဲပြုပြီး အဝ လို့ ပေးထားလိုက်တာ။

ပထမဆုံး ပေးခဲ့တဲ့ နာမည်က Apiwork ။ နောက်တော့ Nifty ။ ပြီးတော့ Nod ။ နောက်ဆုံး အဝ ဆိုတဲ့ နာမည်လေးနဲ့မှ စိတ်ကျေနပ်သွားတာနဲ့ အဝ ဆိုပြီး ပဲ ပေးလိုက်တာ။ lite version ကို စမ်းကြည့်ပါ။ လိုတာတွေ ရှိလည်း ပြောပါ။ lite version က MVC design pattern ကို apply လုပ်ထားတာပဲ ရှိပါတယ်။ ဘာ function မှ မပါဘူး။ လုံးဝ foundation core အဆင့်ပေါ့။ framework ကိုယ်ပိုင် ရေးချင်တဲ့သူတွေအတွက် အရမ်းကို ကောင်းမွန်တဲ့ core လို့ပဲ ဆိုရမှာပေါ့။ နောက်ပြီး သုံးထားတာက MIT license ပါ။ ဒါကြောင့် လွတ်လွတ်လပ်လပ် သုံးလို့ရတယ်။ ပြင်လို့ရပါတယ်။

2 Comments

  1. K says:

    ကျွန်တော်က Ava ကို အဘ လို့ဖတ်နေတာ။ အခုမှ အဝမှန်းသိတော့တယ်။ :)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.