1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<?php
/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ICanBoogie\Session;
use ICanBoogie\SessionFlash;
/**
* @property array $reference A reference to the session array.
*/
trait SegmentTrait
{
/**
* @inheritdoc
*/
public function offsetExists($offset)
{
return isset($this->get_reference()[$offset]);
}
/**
* @inheritdoc
*/
public function &offsetGet($offset)
{
return $this->get_reference()[$offset];
}
/**
* @inheritdoc
*/
public function offsetSet($offset, $value)
{
$this->get_reference()[$offset] = $value;
}
/**
* @inheritdoc
*/
public function offsetUnset($offset)
{
unset($this->get_reference()[$offset]);
}
/**
* Return a property value.
*
* **Note:** We override the method as to be able to return {@link $reference} as a reference
* and not a value.
*
* @param string $name Property name.
*
* @return mixed
*/
public function &__get($name)
{
if ($name === 'reference')
{
return $this->get_reference();
}
$result = $this->accessor_get($name);
return $result;
}
/**
* Return the segment reference.
*
* @return array
*/
abstract protected function &get_reference();
/**
* Return a session flash.
*
* @return SessionFlash
*/
abstract protected function get_flash();
/**
* Returns the value of an inaccessible property.
*
* @param string $property
*
* @return mixed
*
* @see \ICanBoogie\Accessor\AccessorTrait::accessor_get()
*/
abstract protected function accessor_get($property);
}