class \mpf\base\Object

class \mpf\base\Object

This is the basic class that all the other framework components, and most of the application classes extend.

There are few exceptions like the \mpf\base\Config and \mpf\datasources\sql\PDOConnection.

Attributes
No attributes found for this class!
Methods

public mixed __construct (string[] $config = [])

  • $config

    A list of attribute->value pairs to be applied to this object

This method takes care that config list is applied to object. Config list must be a list that contains class attributes as keys and the value as list values.

Example:


class Test extends \mpf\base\Object{
    public $name = 'Mirel';
}

$test = new Test();
echo $test->name; // result in :Mirel
$testConfig new Test(['name' => 'Nicu']);
echo $testConfig->name; // results in Nicu

This method will also call \mpf\base\Object::init() method that can be overwritten for each class and used as a construct.

public mixed applyConfig (string[] $config)

  • $config

    A list of attribute->value pairs to be applied to this object

This methods applies the selected config list to the class. Is called by {@method:\mpf\base\Object::__construct()) when the class is initialized to apply the config sent as param and the config found in database.

It can also be called at any time to apply more configurations.

Call example:


class User extends \mpf\base\Object{
   public $name;
   public $age;
}

$dan = new User(['name' => 'Dan']);
$dan->applyConfig(['age' => 34]);

echo "User {$dan->name} is {$dan->age} years old!"; // User Dan is 34 years old!

protected mixed init (string[] $config)

  • $config

    Config values that were sent when object was initiated;

This method can be overwritten. It will be called by {@method:\mpf\base\Object::construct()} every time the class is initiated. It will be called after the configuration for the class is applied, also, the configuration sent as a parameter to {@method:\mpf\base\Object::construct()} will also be sent as a parameter here.

Example:


class Test extends \mpf\base\Object{
   protected function init($config){
       echo "Class Test loaded!";
       return parent::init();
   }
}

$t = new Test();
// will print: "Class Test loaded!"

public static string className ()

Get name of the called class as a string.