This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
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
10 changed files
with
339 additions
and
259 deletions.
There are no files selected for viewing
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2015 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\Resource\Description; | ||
|
||
class Description | ||
{ | ||
private $descriptors = []; | ||
private $payloadType; | ||
|
||
public function __construct($payloadType) | ||
{ | ||
$this->payloadType = $payloadType; | ||
} | ||
|
||
/** | ||
* Return the descriptors value for the given key. | ||
* | ||
* The key should be one of the constants defined in this class. | ||
* | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function get($key) | ||
{ | ||
if (!isset($this->descriptors[$key])) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Descriptor "%s" not supported for payload type "%s". Supported descriptors: "%s"', | ||
$key, | ||
$this->payloadType, | ||
implode('", "', array_keys($this->descriptors)) | ||
)); | ||
} | ||
|
||
return $this->descriptors[$key]; | ||
} | ||
|
||
/** | ||
* Set value for descriptors key. | ||
* | ||
* - It is possible to overwrite existing keys. | ||
* | ||
* - To help ensure interoperability, where possible, the key should be the | ||
* value of one of the appropriate constants defined in the MetadescriptorsKey | ||
* class. | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
*/ | ||
public function set($key, $value) | ||
{ | ||
$this->descriptors[$key] = $value; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Component\Resource\Description; | ||
|
||
use Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource; | ||
|
||
interface DescriptionEnricherInterface | ||
{ | ||
/** | ||
* Enrich the payload description. | ||
* | ||
* @param Description $description | ||
* @param object $payload | ||
* | ||
* @return Description | ||
*/ | ||
public function enrich(Description $description, $payload); | ||
|
||
/** | ||
* Return true if the provider supports the given type. | ||
* | ||
* @param CmfResource $resource | ||
* | ||
* @return bool | ||
*/ | ||
public function supports(CmfResource $resource); | ||
} |
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,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2015 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\Resource\Description; | ||
|
||
use Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource; | ||
|
||
class DescriptionFactory | ||
{ | ||
private $enrichers = []; | ||
|
||
/** | ||
* @param array $enrichers | ||
*/ | ||
public function __construct(array $enrichers) | ||
{ | ||
$this->enrichers = $enrichers; | ||
} | ||
|
||
/** | ||
* Return a description of the given (CMF) Resource. | ||
* | ||
* @param CmfResource $resource | ||
*/ | ||
public function getPayloadDescriptionFor(CmfResource $resource) | ||
{ | ||
$type = $resource->getPayloadType(); | ||
$payload = $resource->getPayload(); | ||
$description = new Description($type); | ||
|
||
foreach ($this->enrichers as $enricher) { | ||
if (false === $enricher->supports($resource)) { | ||
continue; | ||
} | ||
|
||
$enricher->enrich($description, $payload); | ||
} | ||
|
||
return $description; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2015 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Component\Resource\Description; | ||
|
||
class Descriptor | ||
{ | ||
/** | ||
* Alias for the resource type for example `app.page`. | ||
*/ | ||
const TYPE_ALIAS = 'type.alias'; | ||
|
||
/** | ||
* Humanized representation of the resource type. | ||
*/ | ||
const TYPE_TITLE = 'type.title'; | ||
|
||
/** | ||
* Title of the actual payload, e.g. "My Blog Post" | ||
*/ | ||
const PAYLOAD_TITLE = 'title'; | ||
|
||
/** | ||
* Keys to be used to store link values for HTML. | ||
*/ | ||
const LINK_EDIT_HTML = 'link.edit.html'; | ||
const LINK_CREATE_HTML = 'link.create.html'; | ||
const LINK_UPDATE_HTML = 'link.update.html'; | ||
const LINK_REMOVE_HTML = 'link.remove.html'; | ||
const LINK_SHOW_HTML = 'link.show.html'; | ||
|
||
/** | ||
* Keys to be used to store link values for REST. | ||
*/ | ||
const LINK_EDIT_REST = 'link.edit.rest'; | ||
const LINK_CREATE_REST = 'link.create.rest'; | ||
const LINK_UPDATE_REST = 'link.update.rest'; | ||
const LINK_REMOVE_REST = 'link.remove.rest'; | ||
const LINK_SHOW_REST = 'link.show.rest'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.