class FieldPresenceEnhancer in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony-cmf/routing/Enhancer/FieldPresenceEnhancer.php \Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer
This enhancer sets a field to a fixed value. You can specify a source field name to only set the target field if the source is present.
@author David Buchmann
Hierarchy
- class \Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer implements RouteEnhancerInterface
Expanded class hierarchy of FieldPresenceEnhancer
1 file declares its use of FieldPresenceEnhancer
- FieldPresenceEnhancerTest.php in vendor/
symfony-cmf/ routing/ Tests/ Enhancer/ FieldPresenceEnhancerTest.php
File
- vendor/
symfony-cmf/ routing/ Enhancer/ FieldPresenceEnhancer.php, line 22
Namespace
Symfony\Cmf\Component\Routing\EnhancerView source
class FieldPresenceEnhancer implements RouteEnhancerInterface {
/**
* Field name for the source field that must exist. If null, the target
* field is always set if not already present.
*
* @var string|null
*/
protected $source;
/**
* Field name to write the value into.
*
* @var string
*/
protected $target;
/**
* Value to set the target field to.
*
* @var string
*/
private $value;
/**
* @param null|string $source the field name of the class, null to disable the check
* @param string $target the field name to set from the map
* @param string $value value to set target field to if source field exists
*/
public function __construct($source, $target, $value) {
$this->source = $source;
$this->target = $target;
$this->value = $value;
}
/**
* {@inheritDoc}
*/
public function enhance(array $defaults, Request $request) {
if (isset($defaults[$this->target])) {
// no need to do anything
return $defaults;
}
if (null !== $this->source && !isset($defaults[$this->source])) {
return $defaults;
}
$defaults[$this->target] = $this->value;
return $defaults;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldPresenceEnhancer:: |
protected | property | Field name for the source field that must exist. If null, the target field is always set if not already present. | |
FieldPresenceEnhancer:: |
protected | property | Field name to write the value into. | |
FieldPresenceEnhancer:: |
private | property | Value to set the target field to. | |
FieldPresenceEnhancer:: |
public | function |
Update the defaults based on its own data and the request. Overrides RouteEnhancerInterface:: |
|
FieldPresenceEnhancer:: |
public | function |