Bravo3\Orm\Services\ListManager::add PHP Method

add() public static method

Add an item to a list
public static add ( object $entity, string $property, object $value, string $getter = null, string $setter = null )
$entity object
$property string Property name to add to, not needed if providing both a getter and setter
$value object Value to add
$getter string Custom getter name
$setter string Custom setter name
    public static function add($entity, $property, $value, $getter = null, $setter = null)
    {
        list($getter, $setter) = self::resolveFunctionNames($property, $getter, $setter);
        $arr = $entity->{$getter}();
        if (!$arr) {
            $arr = [];
        }
        $arr[] = $value;
        $entity->{$setter}($arr);
    }

Usage Example

Esempio n. 1
0
 /**
  * Add an asset to the category
  *
  * @param Asset $asset
  * @return $this
  */
 public function addAsset(Asset $asset)
 {
     ListManager::add($this, 'assets', $asset);
     return $this;
 }
All Usage Examples Of Bravo3\Orm\Services\ListManager::add