Jackalope\Item::setDirty PHP Method

setDirty() public method

Tell this item that it is dirty and needs to be refreshed
public setDirty ( boolean $keepChanges = false, $targetState = false )
$keepChanges boolean whether to keep changes when reloading or not
    public function setDirty($keepChanges = false, $targetState = false)
    {
        if (false === $targetState) {
            $targetState = $keepChanges ? $this->getState() : self::STATE_CLEAN;
        }
        switch ($targetState) {
            case self::STATE_DIRTY:
                break;
            case self::STATE_CLEAN:
            case self::STATE_MODIFIED:
                $this->postDirtyState = $targetState;
                break;
            default:
                throw new RepositoryException('Setting item ' . $this->path . ' dirty in state ' . $this->getState() . ' is not expected');
        }
        $this->keepChanges = $keepChanges;
        $this->setState(self::STATE_DIRTY);
    }

Usage Example

Example #1
0
 /**
  * Overwrite to set the properties dirty as well.
  *
  * @private
  */
 public function setDirty($keepChanges = false, $targetState = false)
 {
     parent::setDirty($keepChanges, $targetState);
     foreach ($this->properties as $property) {
         if ($keepChanges && self::STATE_NEW !== $property->getState()) {
             // if we want to keep changes, we do not want to set new properties dirty.
             $property->setDirty($keepChanges, $targetState);
         }
     }
 }