Yii Events, why do we need intermediate method without 'on' prefix

Hi, learning Yii events I did not understood existence of one useless method. All Yii and third party

extension use both beforeSave and onBeforeSave as following:




abstract class CActiveRecord extends CModel

{

   ...

   public function insert($attributes=null)

   {

       ...

       if($this->beforeSave())

       ...

   }


   protected function beforeSave()

   {

      if($this->hasEventHandler('onBeforeSave'))

      {

         $event=new CModelEvent($this);

         $this->onBeforeSave($event);

         return $event->isValid;

      }

      else

         return true;

   }


   public function onBeforeSave($event)

   {

      $this->raiseEvent('onBeforeSave',$event);

   }


}



So why do we need beforeSave here. One could write as following:




abstract class CActiveRecord extends CModel

{

   ...

   public function insert($attributes=null)

   {

       ...

       if($this->onBeforeSave())

       ...

   }


   public function onBeforeSave($event)

   {

      if($this->hasEventHandler('onBeforeSave'))

      {

         $event=new CModelEvent($this);

         $this->raiseEvent('onBeforeSave',$event);

         return $event->isValid;

      }

      else

         return true;

   }

}



As you may notice beforeSave() is just a wrapper for the event method to raise. It returns boolean result and its main goal is to give you a place to implement you logic if needed (in concret model of course). onBeforeSave method belongs to list methods available in Yii and you should not change the body of that method. It’s about additional abstraction layer.