Skip to content

Commit

Permalink
Revert "remove src/Metadata/Field.php"
Browse files Browse the repository at this point in the history
This reverts commit 7529b08.

This change was a horrible mistake, the Metadata loader has
nothing to do with mapping! Mapping is the process of making
a relationship between two component (like a DB schema to an
object graph). Metadata is about loading configuration for a system.
But it's not mandatory.
  • Loading branch information
sstok committed Jul 17, 2015
1 parent 3acd003 commit e2bc90e
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 135 deletions.
4 changes: 2 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ and easier to use.
* The `Rollerworks\Component\Search\Formatter\TransformFormatter` is removed,
transforming is now performed in the InputProcessor.

* `Rollerworks\Component\Search\Metadata\Field` is removed,
use `Rollerworks\Component\Search\Mapping\SearchField` instead.
* The `Rollerworks\Component\Search\Mapping\Field` class is deprecated and will be
removed in 2.0 use `Rollerworks\Component\Search\Metadata\SearchField` instead.

* The methods `supportValueType()` and `setValueTypeSupport()` were added
to `Rollerworks\Component\Search\FieldConfigInterface`. If you implemented
Expand Down
12 changes: 6 additions & 6 deletions doc/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ or as a separate file using either YAML or XML.

For this example the JmsMetadata loader is used.

The ``FileLocator`` will try to guess the the mapping config-dir by
The ``FileLocator`` will try to guess the the metadata config-dir by
matching the namespace prefix to the given Model class-name.

In the example below the Model class ``Acme\Store\Model\Product``
Expand All @@ -34,7 +34,7 @@ and tries to find the corresponding class-name ``Product`` as either ``Product.y
use Metadata\MetadataFactory;
use Doctrine\Common\Annotations\Reader;
use Rollerworks\Component\Search\Metadata\JmsMetadataReader;
use Rollerworks\Component\Search\Metadata\Driver as MappingDriver;
use Rollerworks\Component\Search\Metadata\Driver as MetadataDriver;
$locator = new FileLocator(array(
'Acme\Store\Model' => 'src/Acme/Store/Resources/Rollerworks/Search/',
Expand All @@ -45,9 +45,9 @@ and tries to find the corresponding class-name ``Product`` as either ``Product.y
// See: https://github.com/schmittjoh/metadata/tree/master/src/Metadata/Cache
$driver = new DriverChain(array(
new MappingDriver\AnnotationDriver(),
new MappingDriver\XmlFileDriver($locator),
new MappingDriver\YamlFileDriver($locator),
new MetadataDriver\AnnotationDriver(),
new MetadataDriver\XmlFileDriver($locator),
new MetadataDriver\YamlFileDriver($locator),
));
$metadataFactory = new JmsMetadataReader(new MetadataFactory($driver));
Expand All @@ -61,7 +61,7 @@ and tries to find the corresponding class-name ``Product`` as either ``Product.y
namespace Acme\Store\Model;
use Rollerworks\Component\Search\Mapping as Search;
use Rollerworks\Component\Search\Metadata as Search;
class Product
{
Expand Down
132 changes: 5 additions & 127 deletions src/Mapping/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace Rollerworks\Component\Search\Mapping;

use Rollerworks\Component\Search\Exception\BadMethodCallException;
use Rollerworks\Component\Search\Exception\InvalidArgumentException;
use Rollerworks\Component\Search\Metadata\Field as MetadataField;

/**
* Annotation class for search fields.
Expand All @@ -21,131 +20,10 @@
*
* @Annotation
* @Target({"PROPERTY"})
*
* @deprecated This class is deprecated since 1.0beta5 and will be removed 2.0,
* use `Rollerworks\Component\Search\Metadata\SearchField` instead
*/
class Field
class Field extends MetadataField
{
/**
* @var string
*/
private $name;

/**
* @var string
*/
private $type;

/**
* @var array
*/
private $options = [];

/**
* Constructor.
*
* @param array $data An array of key/value parameters
*
* @throws BadMethodCallException
* @throws InvalidArgumentException
*/
public function __construct(array $data)
{
$this->name = null;
$this->type = null;
$this->required = false;
$this->options = [];

if (isset($data['value'])) {
$data['name'] = $data['value'];
unset($data['value']);
}

foreach ($data as $key => $value) {
$method = 'set'.ucfirst($key);

if (!method_exists($this, $method)) {
throw new BadMethodCallException(
sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this))
);
}

$this->$method($value);
}

if (null === $this->name) {
throw new InvalidArgumentException(
sprintf('Property "%s" on annotation "%s" is required.', 'name', get_class($this))
);
}

if (null === $this->type) {
throw new InvalidArgumentException(
sprintf('Property "%s" on annotation "%s" is required.', 'type', get_class($this))
);
}
}

/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0.
* Use a custom validator instead.
*/
public function setRequired($required)
{
}

/**
* @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0.
* Use a custom validator instead.
*/
public function isRequired()
{
return false;
}

/**
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @param array $options
*/
public function setOptions(array $options)
{
$this->options = $options;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}
152 changes: 152 additions & 0 deletions src/Metadata/Field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

/*
* This file is part of the RollerworksSearch Component package.
*
* (c) Sebastiaan Stok <s.stok@rollerscapes.net>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Rollerworks\Component\Search\Metadata;

use Rollerworks\Component\Search\Exception\BadMethodCallException;
use Rollerworks\Component\Search\Exception\InvalidArgumentException;

/**
* Annotation class for search fields.
*
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
*
* @Annotation
* @Target({"PROPERTY"})
*/
class Field
{

/**
* @var string
*/
private $name;

/**
* @var string
*/
private $type;

/**
* @var array
*/
private $options = [];

/**
* Constructor.
*
* @param array $data An array of key/value parameters
*
* @throws BadMethodCallException
* @throws InvalidArgumentException
*/
public function __construct(array $data)
{
$this->name = null;
$this->type = null;
$this->required = false;
$this->options = [];

if (isset($data['value'])) {
$data['name'] = $data['value'];
unset($data['value']);
}

foreach ($data as $key => $value) {
$method = 'set'.ucfirst($key);

if (!method_exists($this, $method)) {
throw new BadMethodCallException(
sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this))
);
}

$this->$method($value);
}

if (null === $this->name) {
throw new InvalidArgumentException(
sprintf('Property "%s" on annotation "%s" is required.', 'name', get_class($this))
);
}

if (null === $this->type) {
throw new InvalidArgumentException(
sprintf('Property "%s" on annotation "%s" is required.', 'type', get_class($this))
);
}
}

/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0.
* Use a custom validator instead.
*/
public function setRequired($required)
{
}

/**
* @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0.
* Use a custom validator instead.
*/
public function isRequired()
{
return false;
}

/**
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @param array $options
*/
public function setOptions(array $options)
{
$this->options = $options;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}

0 comments on commit e2bc90e

Please sign in to comment.