for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* DecimalConstraintBuilder class file
*/
namespace Graviton\SchemaBundle\Constraint\Builder;
use Graviton\RestBundle\Model\DocumentModel;
use Graviton\SchemaBundle\Document\Schema;
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://swisscom.ch
class DecimalConstraintBuilder implements ConstraintBuilderInterface
{
* the pattern to use
*
* @var string
private $pattern = '^[+\-]?\d+(\.\d{0,4})?$';
* if this builder supports a given constraint
* @param string $type Field type
* @param array $options Options
* @return bool
public function supportsConstraint($type, array $options = [])
return ($type === 'Decimal' || substr($type, -9) == '\\Decimal' /* temporary to support some locked bundles */);
}
* Adds constraints to the property
* @param string $fieldName field name
* @param Schema $property property
* @param DocumentModel $model parent model
* @param array $options the constraint options
* @return Schema the modified property
public function buildConstraint($fieldName, Schema $property, DocumentModel $model, array $options)
if ($property->getType() == 'string') {
$property->setRegexPattern($this->pattern);
return $property;