Shanty_Mongo_Document::setProperty PHP Method

setProperty() public method

Set a property
public setProperty ( mixed $property, mixed $value )
$property mixed
$value mixed
    public function setProperty($property, $value)
    {
        $validators = $this->getValidators($property);
        // Throw exception if value is not valid
        if (!is_null($value) && !$validators->isValid($value)) {
            require_once 'Shanty/Mongo/Exception.php';
            throw new Shanty_Mongo_Exception(implode($validators->getMessages(), "\n"));
        }
        // Unset property
        if (is_null($value)) {
            $this->_data[$property] = null;
            return;
        }
        if ($value instanceof Shanty_Mongo_Document && !$this->hasRequirement($property, 'AsReference')) {
            if (!$value->isNewDocument() || !$value->isRootDocument()) {
                $documentClass = get_class($value);
                $value = new $documentClass($value->export(), array('new' => false, 'pathToDocument' => $this->getPathToProperty($property)));
            } else {
                $value->setPathToDocument($this->getPathToProperty($property));
            }
            $value->setConfigAttribute('connectionGroup', $this->getConfigAttribute('connectionGroup'));
            $value->setConfigAttribute('db', $this->getConfigAttribute('db'));
            $value->setConfigAttribute('collection', $this->getConfigAttribute('collection'));
            $value->setConfigAttribute('criteria', $this->getCriteria());
            $value->applyRequirements($this->getRequirements($property . '.'));
        }
        // Filter value
        $value = $this->getFilters($property)->filter($value);
        $this->_data[$property] = $value;
    }