-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
206 additions
and
901 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
system/src/Grav/Framework/Object/AbstractObjectCollection.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* @package Grav\Framework\Object | ||
* | ||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Framework\Object; | ||
|
||
use RocketTheme\Toolbox\ArrayTraits\ArrayAccessWithGetters; | ||
use RocketTheme\Toolbox\ArrayTraits\Export; | ||
|
||
/** | ||
* Object class. | ||
* | ||
* @package Grav\Framework\Object | ||
*/ | ||
class Object implements ObjectInterface | ||
{ | ||
use ObjectTrait, ArrayAccessWithGetters, Export; | ||
|
||
/** | ||
* Properties of the object. | ||
* @var array | ||
*/ | ||
protected $items; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @param array $elements | ||
* @param string $key | ||
*/ | ||
public function __construct(array $elements = [], $key = null) | ||
{ | ||
|
||
$this->items = $elements; | ||
$this->key = $key !== null ? $key : $this->getKey(); | ||
|
||
if ($this->key === null) { | ||
throw new \InvalidArgumentException('Object cannot be created without assigning a key'); | ||
} | ||
} | ||
|
||
/** | ||
* Implements JsonSerializable interface. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return ['key' => $this->getKey(), 'object' => $this->toArray()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @package Grav\Framework\Object | ||
* | ||
* @copyright Copyright (C) 2014 - 2017 RocketTheme, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Framework\Object; | ||
|
||
use Grav\Framework\Collection\ArrayCollection; | ||
|
||
/** | ||
* Object Collection | ||
* @package Grav\Framework\Object | ||
*/ | ||
class ObjectCollection extends ArrayCollection implements ObjectCollectionInterface | ||
{ | ||
use ObjectCollectionTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @param array $elements | ||
* @param string $key | ||
*/ | ||
public function __construct(array $elements = [], $key = null) | ||
{ | ||
parent::__construct($elements); | ||
|
||
$this->key = $key !== null ? $key : $this->getKey(); | ||
|
||
if ($this->key === null) { | ||
throw new \InvalidArgumentException('Object cannot be created without assigning a key'); | ||
} | ||
} | ||
|
||
/** | ||
* Implements JsonSerializable interface. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return ['key' => $this->getKey(), 'objects' => $this->toArray()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.