public function setVariable($name, $value)
    {
        switch ($name) {
            case 'date':
                try {
                    if ($value instanceof \DateTime) {
                        $this->offsetSet('date', $value);
                    } else {
                        if (is_numeric($value)) {
                            $this->offsetSet('date', (new \DateTime())->setTimestamp($value));
                        } else {
                            if (is_string($value)) {
                                $this->offsetSet('date', new \DateTime($value));
                            }
                        }
                    }
                } catch (Exception $e) {
                    throw new Exception(sprintf("Expected date string in page ID: '%s'", $this->getId()));
                }
                break;
            case 'draft':
                if ($value === true) {
                    $this->offsetSet('published', false);
                }
                break;
            default:
                $this->offsetSet($name, $value);
        }

        return $this;
    }
public function setVariable($name, $value)
    {
        switch ($name) {
            case 'date':
                try {
                    if ($value instanceof \DateTime) {
                        $this->offsetSet('date', $value);
                    } else {
                        if (is_numeric($value)) {
                            $this->offsetSet('date', (new \DateTime())->setTimestamp($value));
                        } else {
                            if (is_string($value)) {
                                $this->offsetSet('date', new \DateTime($value));
                            }
                        }
                    }
                } catch (Exception $e) {
                    throw new Exception(sprintf("Expected date string in page ID: '%s'", $this->getId()));
                }
                break;
            case 'draft':
                if ($value === true) {
                    $this->offsetSet('published', false);
                }
                break;
            default:
                $this->offsetSet($name, $value);
        }

        return $this;
    }
public function setVariable ( $ name , $ value ) { switch ( $ name ) { case 'date' : try { if ( $ value instanceof \ DateTime ) { $ this -> offsetSet ( 'date' , $ value ) ; } else { if ( is_numeric ( $ value ) ) { $ this -> offsetSet ( 'date' , ( new \ DateTime ( ) ) -> setTimestamp ( $ value ) ) ; } else { if ( is_string ( $ value ) ) { $ this -> offsetSet ( 'date' , new \ DateTime ( $ value ) ) ; } } } } catch ( Exception $ e ) { throw new Exception ( sprintf ( "Expected date string in page ID: '%s'" , $ this -> getId ( ) ) ) ; } break ; case 'draft' : if ( $ value === true ) { $ this -> offsetSet ( 'published' , false ) ; } break ; default : $ this -> offsetSet ( $ name , $ value ) ; } return $ this ; }
Set a variable.

@param $name
@param $value

@throws Exception

@return $this
Set a variable .