code/model/entity/composite.php
public function insert($entity, $status = null)
    {
        if(!$entity instanceof ModelEntityInterface)
        {
            if (!is_array($entity) && !$entity instanceof \Traversable)
            {
                throw new \InvalidArgumentException(sprintf(
                    'Entity must be an array or an object implementing the Traversable interface; received "%s"', gettype($entity)
                ));
            }

            if($this->_prototypable)
            {
                if(!$this->_prototype instanceof ModelEntityInterface)
                {
                    $identifier = $this->getIdentifier()->toArray();
                    $identifier['path'] = array('model', 'entity');
                    $identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);

                    //The entity default options
                    $options = array(
                        'identity_key' => $this->getIdentityKey()
                    );

                    $this->_prototype = $this->getObject($identifier, $options);
                }

                $prototype = clone $this->_prototype;
                $prototype->setStatus($status);
                $prototype->setProperties($entity, $prototype->isNew());

                $entity = $prototype;
            }
            else
            {
                $identifier = $this->getIdentifier()->toArray();
                $identifier['path'] = array('model', 'entity');
                $identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);

                //The entity default options
                $options = array(
                    'data'         => $entity,
                    'status'       => $status,
                    'identity_key' => $this->getIdentityKey()
                );

                $entity = $this->getObject($identifier, $options);
            }
        }

        //Insert the entity into the collection
        $this->__entities->insert($entity);

        return $this;
    }
public function insert($entity, $status = null)
    {
        if(!$entity instanceof ModelEntityInterface)
        {
            if (!is_array($entity) && !$entity instanceof \Traversable)
            {
                throw new \InvalidArgumentException(sprintf(
                    'Entity must be an array or an object implementing the Traversable interface; received "%s"', gettype($entity)
                ));
            }

            if($this->_prototypable)
            {
                if(!$this->_prototype instanceof ModelEntityInterface)
                {
                    $identifier = $this->getIdentifier()->toArray();
                    $identifier['path'] = array('model', 'entity');
                    $identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);

                    //The entity default options
                    $options = array(
                        'identity_key' => $this->getIdentityKey()
                    );

                    $this->_prototype = $this->getObject($identifier, $options);
                }

                $prototype = clone $this->_prototype;
                $prototype->setStatus($status);
                $prototype->setProperties($entity, $prototype->isNew());

                $entity = $prototype;
            }
            else
            {
                $identifier = $this->getIdentifier()->toArray();
                $identifier['path'] = array('model', 'entity');
                $identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);

                //The entity default options
                $options = array(
                    'data'         => $entity,
                    'status'       => $status,
                    'identity_key' => $this->getIdentityKey()
                );

                $entity = $this->getObject($identifier, $options);
            }
        }

        //Insert the entity into the collection
        $this->__entities->insert($entity);

        return $this;
    }
public function insert ( $ entity , $ status = null ) { if ( ! $ entity instanceof ModelEntityInterface ) { if ( ! is_array ( $ entity ) && ! $ entity instanceof \ Traversable ) { throw new \ InvalidArgumentException ( sprintf ( 'Entity must be an array or an object implementing the Traversable interface; received "%s"' , gettype ( $ entity ) ) ) ; } if ( $ this -> _prototypable ) { if ( ! $ this -> _prototype instanceof ModelEntityInterface ) { $ identifier = $ this -> getIdentifier ( ) -> toArray ( ) ; $ identifier [ 'path' ] = array ( 'model' , 'entity' ) ; $ identifier [ 'name' ] = StringInflector :: singularize ( $ this -> getIdentifier ( ) -> name ) ; //The entity default options $ options = array ( 'identity_key' => $ this -> getIdentityKey ( ) ) ; $ this -> _prototype = $ this -> getObject ( $ identifier , $ options ) ; } $ prototype = clone $ this -> _prototype ; $ prototype -> setStatus ( $ status ) ; $ prototype -> setProperties ( $ entity , $ prototype -> isNew ( ) ) ; $ entity = $ prototype ; } else { $ identifier = $ this -> getIdentifier ( ) -> toArray ( ) ; $ identifier [ 'path' ] = array ( 'model' , 'entity' ) ; $ identifier [ 'name' ] = StringInflector :: singularize ( $ this -> getIdentifier ( ) -> name ) ; //The entity default options $ options = array ( 'data' => $ entity , 'status' => $ status , 'identity_key' => $ this -> getIdentityKey ( ) ) ; $ entity = $ this -> getObject ( $ identifier , $ options ) ; } } //Insert the entity into the collection $ this -> __entities -> insert ( $ entity ) ; return $ this ; }
Insert a new entity

This function will either clone a entity prototype or create a new instance of the entity object for each
entity being inserted. By default the entity will be cloned. The entity will be stored by it's identity_key
if set or otherwise by it's object handle.

@param   ModelEntityInterface|array $entity  A ModelEntityInterface object or an array of entity properties
@param   string  $status     The entity status
@return  ModelEntityComposite
Insert a new entity