Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlomanf committed Jul 13, 2022
1 parent f025f63 commit 17b8c2d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Document_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class Document_Type
/**
* The slug of this document type.
* This will be visible in all document permalinks.
* Set through the `__set` method and can not be changed once set.
*
* @access private
*
Expand All @@ -21,32 +22,36 @@ abstract class Document_Type
private $slug = '';

/**
* Constructor.
* Can be over-ridden by subclasses.
* Getter.
*
* @since 1.0.0
*
* @param string $slug The slug for this document type.
* @param string $key Key.
*
* @return mixed Value.
*/
public function __construct( string $slug )
final public function __get( $key )
{
$this->slug = $slug;
if ( 'slug' === $key )
{
return $this->slug;
}
}

/**
* Getter.
* Setter.
* Only used to set the slug, which can only be set once.
*
* @since 1.0.0
* @since 1.1.0
*
* @param string $key Key.
*
* @return mixed Value.
* @param mixed $value Value.
*/
final public function __get( $key )
final public function __set( $key, $value )
{
if ( 'slug' === $key )
if ( 'slug' === $key && empty( $this->slug ) )
{
return $this->slug;
$this->slug = $value;
}
}

Expand Down
32 changes: 32 additions & 0 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class Environment
*/
private $user_cache = array();

/**
* Arbitrary data for this environment.
* Set through the setter method.
*
* @access private
*
* @since 1.1.0
* @var array
*/
private $data = array();

/**
* Constructor.
*
Expand Down Expand Up @@ -339,6 +350,27 @@ public function __get( $key )
{
return $this->current_user;
}

if ( $key === 'data' )
{
return $this->data;
}

return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
}

/**
* Setter.
* Used to set arbitrary data.
*
* @since 1.1.0
*
* @param string $key Key.
* @param mixed $value Value.
*/
public function __set( $key, $value )
{
$this->data[ $key ] = $value;
}

/**
Expand Down

0 comments on commit 17b8c2d

Please sign in to comment.