miniMVC/sys/core/traits/jsobject.php

61 lines
1.2 KiB
PHP
Raw Normal View History

2012-05-21 14:58:58 -04:00
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
2012-05-22 11:11:36 -04:00
namespace miniMVC;
2012-05-21 14:58:58 -04:00
/**
* Parent trait of base class, contains much of the magic
*
* @package miniMVC
* @subpackage System
*/
trait JSObject {
use Generic;
/**
* Constructor for creating the objects
*
* @param array $members
* @return void
*/
public function __construct($members = [])
{
// Add the passed parameters to the object
foreach($members as $name => &$value)
{
$this->$name = $value;
}
}
// --------------------------------------------------------------------------
/**
* PHP magic method to facilitate dynamic methods
*
* @param string $name
* @param array $params
*/
public function __call($name, $params = [])
{
if (is_callable($this->$name))
{
//Call the dynamic function
return call_user_func_array($this->$name, $params);
}
}
}
// End of JSObject.php