for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @license MIT
* @author Igor Sorokin <[email protected]>
*/
namespace Dspbee\Bundle\Data;
* Initialize class properties from array.
*
* Class TDataFilter
* @package Dspbee\Core
trait TDataInit
{
* Init class members.
* @param array $data
public function initFromArray(array $data)
foreach ($data as $name => $value) {
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
call_user_func_array([$this, $method], [$value]);
} else {
if (property_exists(get_called_class(), $name)) {
$this->$name = $value;
}
* Init class members from $_POST array.
* @param null $callback
public function initFromPost($callback = null)
$input = filter_input_array(INPUT_POST);
if (null !== $callback) {
$input = array_map($callback, $input);
$this->initFromArray($input);
* Get item property.
* @param $name
* @param $argumentList
* @return null
public function __call($name, $argumentList)
return $this->$name;
return null;