Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed May 24, 2016
1 parent fdd8ff6 commit 16c5c92
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 259 deletions.
62 changes: 62 additions & 0 deletions Description/Description.php
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;
}
}
27 changes: 27 additions & 0 deletions Description/DescriptionEnricherInterface.php
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);
}
49 changes: 49 additions & 0 deletions Description/DescriptionFactory.php
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;
}
}
48 changes: 48 additions & 0 deletions Description/Descriptor.php
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';
}
68 changes: 0 additions & 68 deletions Metadata/PayloadMetadata.php

This file was deleted.

22 changes: 0 additions & 22 deletions Metadata/PayloadMetadataFactoryInterface.php

This file was deleted.

92 changes: 0 additions & 92 deletions Metadata/SonataMetadataFactory.php

This file was deleted.

Loading

0 comments on commit 16c5c92

Please sign in to comment.