Commit 36857561 authored by Tomas Lang's avatar Tomas Lang

Entity: alternative for magic functions like addTo* - call addTo(*)

parent da625a73
......@@ -5,6 +5,9 @@ namespace LeanMapperWorkflow;
use LeanMapper\Relationship\HasMany;
use LeanMapper\Filtering;
use LeanMapper\Fluent;
use InvalidArgumentException;
use Nette\Callback;
use Nette\Utils\Strings;
abstract class Entity extends \LeanMapper\Entity
......@@ -13,10 +16,19 @@ abstract class Entity extends \LeanMapper\Entity
/**
* @param string $name
* @param array $arguments
*
* @throws InvalidArgumentException
*/
public function __call($name, array $arguments)
{
if (substr($name, 0, 10) === 'getCountOf')
if (in_array($name, ['addTo', 'removeFrom', 'removeAll', 'replaceAll', 'getCountOf']))
{
if (count($arguments) === 0) {
throw new InvalidArgumentException("Method '$name' in entity " . get_called_class() . " expects at least one argument with target column name.");
}
return $this->__call($name . Strings::firstUpper(array_shift($arguments)), $arguments);
} elseif (substr($name, 0, 10) === 'getCountOf')
{
$property = $this->getCurrentReflection()->getEntityProperty(lcfirst(substr($name, 10)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment