Skip to content

Commit

Permalink
Expand documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratadox committed Feb 11, 2018
1 parent d77f41b commit c3fb1eb
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/Instruction/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@
/**
* Indicates that a closure should be called to hydrate this property.
*
* @todo make final
* @package Stratadox\Hydrate
* @author Stratadox
*/
class Call implements InstructsHowToMap
{
private $function;

// @todo make private
public function __construct(Closure $function)
{
$this->function = $function;
}

public static function the(Closure $function)
/**
* Create a closure call instruction for the property.
*
* @param Closure $function The anonymous function to call while hydrating
* this property.
* @return Call The instruction object.
*/
public static function the(Closure $function) : Call
{
return new Call($function);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Instruction/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ final class Has
{
private function __construct() {}

/**
* Define a has-one relationship with another class.
*
* @param string $class The fully qualified class name.
* @param FindsKeys|null $key The input array offset (optional)
* @return DefinesRelationships The relationship definition.
*/
public static function one(
string $class,
FindsKeys $key = null
Expand All @@ -27,6 +34,13 @@ public static function one(
return HasOne::ofThe($class, $key);
}

/**
* Define a has-many relationship with another class.
*
* @param string $class The fully qualified class name.
* @param FindsKeys|null $key The input array offset (optional)
* @return DefinesRelationships The relationship definition.
*/
public static function many(
string $class,
FindsKeys $key = null
Expand Down
8 changes: 7 additions & 1 deletion src/Instruction/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ private function __construct($key)
$this->key = $key;
}

public static function key(string $key)
/**
* Indicates that the data for this property can be found in a different key.
*
* @param string $key The offset to use in the input array.
* @return In The instruction object.
*/
public static function key(string $key) : In
{
return new In($key);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Instruction/Relation/Choose.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ private function __construct(MakesMap $class)
$this->class = $class;
}

/**
* Creates a new option to choose from.
*
* @param string $class The fully qualified name of the class that can
* be chosen.
* @return RepresentsChoice The object representation of the choice.
*/
public static function the(string $class) : RepresentsChoice
{
return new Choose(Mapper::forThe($class));
Expand Down
26 changes: 23 additions & 3 deletions src/Instruction/Relation/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Stratadox\Proxy\ProducesProxyLoaders;

/**
* Defines a relationship with another class.
*
* @package Stratadox\Hydrate
* @author Stratadox
*/
Expand All @@ -23,15 +25,15 @@ abstract class Relationship implements DefinesRelationships
protected $class;
/** @var FindsKeys */
protected $key;
/** @var ?string */
/** @var string|null */
protected $container;
/** @var ?ProducesProxyLoaders */
/** @var ProducesProxyLoaders|null */
protected $loader;
/** @var bool */
protected $shouldNest = false;
/** @var InstructsHowToMap[] */
protected $properties = [];
/** @var ?string */
/** @var string|null */
protected $decisionKey;
/** @var RepresentsChoice[] */
protected $choices = [];
Expand All @@ -42,6 +44,13 @@ final protected function __construct(string $class, FindsKeys $key = null)
$this->key = $key;
}

/**
* Define a new relationship with another class.
*
* @param string $class The fully qualified class name.
* @param FindsKeys|null $key The input array offset (optional)
* @return DefinesRelationships The relationship definition.
*/
public static function ofThe(
string $class,
FindsKeys $key = null
Expand Down Expand Up @@ -92,11 +101,22 @@ public function selectBy(
return $inst;
}

/**
* Returns the key if one was provided, defaulting to the property name.
*
* @param string $property The property name to use as fallback.
* @return string The key to use as offset for the input data.
*/
protected function keyOr(string $property) : string
{
return $this->key ? $this->key->find() : $property;
}

/**
* Produces a mapped hydrator according to the relationship configuration.
*
* @return Hydrates The hydrator for the relationship mapping.
*/
protected function hydrator() : Hydrates
{
if (isset($this->decisionKey)) {
Expand Down
6 changes: 6 additions & 0 deletions src/NoContainerAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*/
final class NoContainerAvailable extends BadMethodCall implements InvalidMapperConfiguration
{
/**
* Produce an exception for when there is no container defined for a class.
*.
* @param string $class The class that is missing a container.
* @return self The exception object.
*/
public static function for(string $class) : self
{
return new self(sprintf(
Expand Down
6 changes: 6 additions & 0 deletions src/NoLoaderAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*/
final class NoLoaderAvailable extends BadMethodCall implements InvalidMapperConfiguration
{
/**
* Produce an exception for when there is no loader defined for a class.
*.
* @param string $class The class that is missing a loader.
* @return self The exception object.
*/
public static function for(string $class) : self
{
return new self(sprintf(
Expand Down

0 comments on commit c3fb1eb

Please sign in to comment.