eZ\Publish\Core\Persistence\TransformationProcessor::transform PHP Метод

transform() публичный Метод

Transform the given string using the given rules. If no rules are specified, all available rules will be used for the transformation.
public transform ( string $string, array $ruleNames = [] ) : string
$string string
$ruleNames array
Результат string
    public function transform($string, array $ruleNames = array())
    {
        $rules = $this->getRules();
        foreach ($ruleNames ?: array_keys($rules) as $ruleName) {
            if (!isset($rules[$ruleName])) {
                // Just continue on unknown rules, or should we throw an error
                // here?
                continue;
            }
            foreach ($rules[$ruleName] as $rule) {
                $string = preg_replace_callback($rule['regexp'], $rule['callback'], $string);
            }
        }
        return $string;
    }

Usage Example

Пример #1
0
 /**
  * Converts given $text into a URL slug consisting of URL valid characters.
  * For non-Unicode setups this means character in the range a-z, numbers and _, for Unicode
  * setups it means all characters except space, &, ;, /, :, =, ?, [, ], (, ), -.
  *
  * Invalid characters are converted to -.
  *
  * Example with a non-Unicode setup
  *
  * 'My car' => 'My-car'
  * 'What is this?' => 'What-is-this'
  * 'This & that' => 'This-that'
  * 'myfile.tpl' => 'Myfile-tpl',
  * 'øæå' => 'oeaeaa'
  *
  * @param string $text
  * @param string $defaultText
  * @param string|null $transformation
  *
  * @return string
  */
 public function convert($text, $defaultText = '_1', $transformation = null)
 {
     if (!isset($transformation)) {
         $transformation = $this->configuration['transformation'];
     }
     if (strlen($text) === 0) {
         $text = $defaultText;
     }
     if (isset($this->configuration['transformationGroups'][$transformation]['commands']) && !empty($this->configuration['transformationGroups'][$transformation]['commands'])) {
         $text = $this->transformationProcessor->transform($text, $this->configuration['transformationGroups'][$transformation]['commands']);
     }
     return $this->cleanupText($text, $this->configuration['transformationGroups'][$transformation]['cleanupMethod']);
 }
All Usage Examples Of eZ\Publish\Core\Persistence\TransformationProcessor::transform