Tag Archives: Content Management System

“Auto Load” Method and Singleton Pattern helps to manage resource in appRain

12 Oct

It’s really easy to load a class in appRain. We don’t need to include the class but it attach on demand. “On demand” means when we create first instance of the class then system automatically include the class in the system.

But!

There are some common conversion to construct the class. Here is some guide line

1) The class name must be given with the combination of it’s directory path. Let say we have a class in:

development/plugin/paypal/standard.php

Then class name must be

Development_Plugin_Paypal_Standard

2. Class name must be in lower case.

Here each underscore ( _ ) is used as a directory separator so we must use it carefully.Once we have create the class the installation is done. It will be attached in the system when we will create it’s first instance. We can create the class object like

$object = new Development_Plugin_Paypal_Standard()

But appRain recommend in different way..

For plug-in it will be : $obj = App::Plugin(‘Paypal_Standard’);
For helper it will be : $obj = App::Helper(‘Paypal_Standard’);

But in some case if we need to create class object directly then we can use like
$obj = App::__Obj(‘Development_Plugin_Paypal_Standard’);

Because, in this way the system manage the resource in Singleton Pattern so that, It hepls not to over load resource any more.

😀

Easy way to pass value by using Magic Methods in appRain?

12 Oct

In appRain we can avoid some unnecessary hassle to pass value using Magic Methods.

What is magic methods?
A magic method does not have a physical existence in Project code. We use this to pass value from one scope to another scope. Each magic method has a pair of two methods.
1) First method set value that always start with a keyword “set”. For example :

$this->setFirstName("Jhon");


2) Second method retrieve value and it start with a keyword “get”. For example:

$this->getFirstName();


This method return value set by $this->setFirstName() and if value is not set then it return null value.

The “set” method always return reference it’s self class so that we can create a chain of call like bellow

$obj->setFirstName('Jhon')
     ->setLastName('Regan')
     ->setAge('29');

What is the Problem of argument passing technique?
It’s really boring to pass lots of value in different scope by function parameters be cause it fixed developers in a frame. In some cases if parameters become optional then it’s taught to manage the sequence.
For example:

$obj->fx(
          "param 1" ,
           "param 2" ,
           //-----------
           //------------
           "param n")


Let say in above example we like to skip param-1 but pass param-1 so you have to pass a default value in param-1 to maintain the sequence.

So, How does magic method help?
It’s really an amazing utility that we get form magic methods. Let say we have a function that we us to format product information, we can use magic method to set values like:

$this->setProductId(5)
      ->setPrice(“22.99”)
      ->setShipping('Corporate')
      ->setUserId(755)
      ->setInvoiceId(100000045)
      ->formatData();


So we have create a chain of five magic methods to pass value and finally called formatData() method and in we will retrieve value like $this->getPrice() or $this->getUserId(). Now if we don’t like pass Invoice id simply you can comment it out or next time if we need to pass another value then simply we will add that another magic methods. And for the new change we don’t need to re-write function definition.

Show some Examples:
There are some good example when we save data in model like bellow:

See we can add/remove filed easily if needed. Let’s say we have create a plugin for authorize.net payment process were we have to pass bunch of parameters. We can do that simple like bellow.

$payment = App::Helper('Authorizedotnet');

// Batch - 1
$payment->setXLogin('[LOGIN]')
              ->setXTranKey('[Key]')
              ->setXVersion('[Version]')
              ->setXDelimData('[DELIM_DATA'])
              ->setXDelimChar('[DELIM_CHAR]')
              ->setXRelayResponse('[RELAY_RESPONSE]')
              ->setXType(['Type'])
              ->setXMethod('[METHOD]');
// Batch - 2
$processor->setXTestRequest('TRUE');

// Batch - 3		
$processor->setShippingAddress('[Shipping_Address]')
               ->formatPaymentData();		


In this example we have set data in different steps and inside class we can catch it like bellow:

$post_values = array(
        "x_login"                    => $this->getXLogin(),
        "x_tran_key"               => $this->getXTranKey(),
        "x_version"	                => $this->getXVersion(),
        "x_test_request"          => $this->getXTestRequest(),
        "x_delim_data"            => $this->getXDelimData(),
        "x_delim_char"            => $this->getXDelimChar(),
        "x_relay_response"      => $this->getXRelayResponse(),
        "x_type"                     => $this->getXType(),
        "x_method"                 => $this->getXMethod(),
        "x_card_num"              => $this->getXCardNum(),
        "x_exp_date"               => $this->getXExpDate(),
        "x_amount"	                 => $this->getXAmount(),
        "x_description"             => $this->getXDescription(),
        "x_first_name"             => $this->getXFirstName(),
        "x_last_name"              => $this->getXLastName(),
        "x_address"                 => $this->getXAddress(),
        "x_state"                     => $this->getXState(),
        "x_zip"                        => $this->getXZip());


So, It’s pretty helpful to pass data or push it for a certain period.

How to Install appRain(CMF)

8 Oct

Here is a video explained how to install appRain Content Management Framework.