Pimcore\Placeholder::detectPlaceholders PHP Method

detectPlaceholders() public method

Detects the Placeholders in a string and returns an array with the placeholder information
public detectPlaceholders ( string $contentString, null | array $params, $document = null ) : array
$contentString string
$params null | array
return array
    public function detectPlaceholders($contentString, $params, $document = null)
    {
        $placeholderStack = [];
        $regex = "/" . self::$placeholderPrefix . "([a-z_]+)\\(([a-z_0-9]+)[\\s,]*(.*?)\\)" . self::$placeholderSuffix . "/is";
        preg_match_all($regex, $contentString, $matches);
        if (is_array($matches[1])) {
            foreach ($matches[1] as $key => $match) {
                $placeholderString = $matches[0][$key];
                //placeholder string
                $placeholderClass = $matches[1][$key];
                //placeholder php class
                $placeholderKey = $matches[2][$key];
                //key for the dynamic param
                $placeholderConfigString = $matches[3][$key];
                if ($placeholderConfigString) {
                    //try to create the json config object
                    try {
                        $configJsonString = str_replace([""", "'"], '"', $placeholderConfigString);
                        $placeholderConfig = new \Zend_Config_Json($configJsonString, null, ['ignoreconstants' => true]);
                    } catch (\Exception $e) {
                        Logger::warn('PlaceholderConfig is not a valid JSON string. PlaceholderConfig for ' . $placeholderClass . ' ignored.');
                        continue;
                    }
                } else {
                    //create an empty config object if no config object was passed
                    $placeholderConfig = new \Zend_Config_Json("{}");
                }
                $placeholderStack[] = ['placeholderString' => $placeholderString, 'placeholderClass' => $placeholderClass, 'placeholderKey' => $placeholderKey, 'placeholderConfig' => $placeholderConfig, 'document' => $document, 'params' => $params, 'contentString' => $contentString];
            }
        }
        return $placeholderStack;
    }