miniMVC/sys/core/mm.php

72 lines
1.5 KiB
PHP
Raw Normal View History

2012-05-16 16:47:36 -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-16 16:47:36 -04:00
/**
* Class for standalone JSObject objects
*
* @package miniMVC
* @subpackage System
*/
2012-05-22 11:11:36 -04:00
class MM extends \ArrayObject {
2012-05-16 16:47:36 -04:00
use JSObject;
/**
* Create the ArrayObject/JSObject hybrid object
*
* @param array
*/
public function __construct($members = [])
{
parent::__construct($members);
// Add the passed parameters to the object
2012-05-18 13:52:12 -04:00
foreach ($members as $name => &$value)
2012-05-16 16:47:36 -04:00
{
$this->$name = $value;
}
}
// --------------------------------------------------------------------------
/**
* Allow calling of array methods on the object and
* dynamic methods
*
* @param string $name
* @param array $params
* @return mixed
*/
public function __call($name, $params = [])
{
// Allow array operations on the object
if (substr($name, 0, 6) === 'array_' && is_callable($name))
{
$args = array_merge($this->getArrayCopy(), $args);
return call_user_func_array($name, $args);
}
// Allow dynamic method calls
2012-05-18 13:52:12 -04:00
if (is_callable($this->$name))
2012-05-16 16:47:36 -04:00
{
//Call the dynamic function
return call_user_func_array($this->$name, $params);
}
}
}
// End of MM.php