Initial commit
This commit is contained in:
commit
08a8a71c55
631 changed files with 139902 additions and 0 deletions
54
public/kirby/src/Template/Slots.php
Normal file
54
public/kirby/src/Template/Slots.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Template;
|
||||
|
||||
use Countable;
|
||||
|
||||
/**
|
||||
* The slots collection is simplifying
|
||||
* slot access. Slots can be accessed with
|
||||
* `$slots->heading()` and accessing a non-existing
|
||||
* slot will simply return null.
|
||||
*
|
||||
* @package Kirby Template
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://getkirby.com/license
|
||||
*/
|
||||
class Slots implements Countable
|
||||
{
|
||||
/**
|
||||
* Creates a new slots collection
|
||||
*/
|
||||
public function __construct(
|
||||
protected array $slots
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter for slots;
|
||||
* e.g. `$slots->heading`
|
||||
*/
|
||||
public function __get(string $name): Slot|null
|
||||
{
|
||||
return $this->slots[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter method for slots;
|
||||
* e.g. `$slots->heading()`
|
||||
*/
|
||||
public function __call(string $name, array $args): Slot|null
|
||||
{
|
||||
return $this->__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of defined slots
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->slots);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue