Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
v9.26.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamison Valenta committed Sep 2, 2022
1 parent 71be468 commit a07d641
Show file tree
Hide file tree
Showing 31 changed files with 18,662 additions and 0 deletions.
109 changes: 109 additions & 0 deletions src/Collect/Conditionable/HigherOrderWhenProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace Tightenco\Collect\Conditionable;

class HigherOrderWhenProxy
{
/**
* The target being conditionally operated on.
*
* @var mixed
*/
protected $target;

/**
* The condition for proxying.
*
* @var bool
*/
protected $condition;

/**
* Indicates whether the proxy has a condition.
*
* @var bool
*/
protected $hasCondition = false;

/**
* Determine whether the condition should be negated.
*
* @var bool
*/
protected $negateConditionOnCapture;

/**
* Create a new proxy instance.
*
* @param mixed $target
* @return void
*/
public function __construct($target)
{
$this->target = $target;
}

/**
* Set the condition on the proxy.
*
* @param bool $condition
* @return $this
*/
public function condition($condition)
{
[$this->condition, $this->hasCondition] = [$condition, true];

return $this;
}

/**
* Indicate that the condition should be negated.
*
* @return $this
*/
public function negateConditionOnCapture()
{
$this->negateConditionOnCapture = true;

return $this;
}

/**
* Proxy accessing an attribute onto the target.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (! $this->hasCondition) {
$condition = $this->target->{$key};

return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition);
}

return $this->condition
? $this->target->{$key}
: $this->target;
}

/**
* Proxy a method call on the target.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
if (! $this->hasCondition) {
$condition = $this->target->{$method}(...$parameters);

return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition);
}

return $this->condition
? $this->target->{$method}(...$parameters)
: $this->target;
}
}
17 changes: 17 additions & 0 deletions src/Collect/Contracts/Support/Arrayable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Tightenco\Collect\Contracts\Support;

/**
* @template TKey of array-key
* @template TValue
*/
interface Arrayable
{
/**
* Get the instance as an array.
*
* @return array<TKey, TValue>
*/
public function toArray();
}
14 changes: 14 additions & 0 deletions src/Collect/Contracts/Support/CanBeEscapedWhenCastToString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tightenco\Collect\Contracts\Support;

interface CanBeEscapedWhenCastToString
{
/**
* Indicate that the object's string representation should be escaped when __toString is invoked.
*
* @param bool $escape
* @return $this
*/
public function escapeWhenCastingToString($escape = true);
}
13 changes: 13 additions & 0 deletions src/Collect/Contracts/Support/Htmlable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Tightenco\Collect\Contracts\Support;

interface Htmlable
{
/**
* Get content as a string of HTML.
*
* @return string
*/
public function toHtml();
}
14 changes: 14 additions & 0 deletions src/Collect/Contracts/Support/Jsonable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tightenco\Collect\Contracts\Support;

interface Jsonable
{
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0);
}
Loading

0 comments on commit a07d641

Please sign in to comment.