Replaces parameters in path template with their values from restriction.

@param string $pathTemplate
@param Restriction $restriction
@returns string
@throws InvalidArgumentException when some mandatory parameter is missing in restriction
428523
public function build($pathTemplate, Restriction $restriction)
	{
		$matches = [];
		preg_match_all("/\\{(.*?)\\}/", $pathTemplate, $matches);
		$matchedParameters = end($matches);

		$required = [];
		$parameters = [];
		foreach ($matchedParameters as $parameter) {
			if (substr($parameter, 0, 1) == '?') {
				$parameters = explode(',', str_replace('?', '', $parameter));
			}
			else {
				if (($p = $restriction->getParameter($parameter)) === NULL) {
					$required[] = $parameter;
				} else {
					$pathTemplate = str_replace('{' . $parameter . '}', $p, $pathTemplate);
				}
			}
		}

		if (!empty($required)) {
			$message = 'Empty required parameters: ' . implode(', ', $required);
			throw new InvalidArgumentException($message);
		}

		if (($pos = strpos($pathTemplate, '{?')) !== FALSE) {
			$pathTemplate = substr($pathTemplate, 0, $pos);
			$first = TRUE;
			foreach ($parameters as $qParameter) {
				$p = $restriction->getParameter($qParameter);
				if ($p !== NULL) {
					$pathTemplate .= ($first ? '?' : '&') . $qParameter . '=' . rawurlencode($p);
					$first = FALSE;
				}
			}
		}

		return $pathTemplate;
	}
1254892
public function setTemplate($template)
    {
        if (Format::isUri($template) === true || (gettype($template) === 'string' && empty($template) === true)) {
            $this->template = $template;
        } else {
            $msg = "The given template '${template}' is not a valid URI.";
            throw new InvalidArgumentException($msg);
        }
    }
437395
public function lookup($context, $path, $require = false)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException("Passed lookup path is empty.");
        }
        if (empty($context)) {
            throw new \InvalidArgumentException("Specified context is empty while resolving path " . json_encode($path));
        }
        return PropertyAccessor::getByPath($context, $this->path($path), $require);
    }
1100873
private function filterPath($path): string
    {
        if (! is_string($path)) {
            throw new \InvalidArgumentException('Path must be a string');
        }

        return preg_replace_callback(
            '/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/]++|%(?![A-Fa-f0-9]{2}))/',
            [$this, 'rawurlencodeMatchZero'],
            $path
        );
    }
237546
public function copyTemplateDirectoryAndGetPath(
        string $pathToProjectRoot,
        string $templatePath,
        string $destPath
    ): string {
        $realTemplatePath = realpath($templatePath);
        if (false === $realTemplatePath) {
            throw new DoctrineStaticMetaException('path ' . $templatePath . ' does not exist');
        }

        $relativeDestPath = $this->filesystem->makePathRelative($destPath, $pathToProjectRoot);
        $subDirectories   = explode('/', $relativeDestPath);
        $path             = $this->createSubDirectoriesAndGetPath($pathToProjectRoot, $subDirectories);
        $this->filesystem->mirror($realTemplatePath, $path);
        $this->fileCreationTransaction::setPathCreated($path);

        return $path;
    }
215524
public function getProtectedHeaderParameter(string $key)
    {
        if ($this->hasProtectedHeaderParameter($key)) {
            return $this->getProtectedHeader()[$key];
        }

        throw new \InvalidArgumentException(\sprintf('The protected header "%s" does not exist', $key));
    }
1008352
protected function resolvePath($pathPropertyName, array $extras = [])
    {
        $resolvedPaths = $this->getResolvedPaths();
        $basePath = base_path();
        $publicPath = public_path();
        $extras = array_merge(compact('basePath', 'publicPath'), $extras);

        return Util::template($resolvedPaths[ $pathPropertyName ], $extras);
    }
228102
public function pathValue($key)
    {
        if (!isset($this->keyToIndexMap[$key]) || !$this->values[$this->keyToIndexMap[$key]] instanceof Path) {
            throw new \InvalidArgumentException(sprintf('value for %s is not of type %s', $key, 'PATH'));
        }

        return $this->value($key);
    }
208353
protected function getActionConstantsForClass($classNamespace, $restriction)
    {
        $constants = [];
        /** @var \Claroline\CoreBundle\Event\Log\LogGenericEvent $reflectionClass */
        $reflectionClass = new \ReflectionClass($classNamespace);

        if (!$reflectionClass->isAbstract()) {
            if ($restriction
                && ($restrictions = $classNamespace::getRestriction())
                && 1 === count($restrictions)
                && (LogGenericEvent::DISPLAYED_ADMIN === $restrictions[0]
                    || LogGenericEvent::PLATFORM_EVENT_TYPE === $restrictions[0])
                && $restriction !== $restrictions[0]) {
                return $constants; // event is admin only
            }

            $classConstants = $reflectionClass->getConstants();

            foreach ($classConstants as $key => $classConstant) {
                if (preg_match('/^ACTION/', $key)) {
                    $constants[] = $classConstant;
                }
            }
        }

        return $constants;
    }
171673
public function getSortedEventsForFilter($restriction = null)
    {
        $textEvents = $this->getEvents($restriction);
        $allTranslatedText = $this->translator->trans('all', [], 'log');
        $sortedEvents = [];
        $genericResourceEvents = [];
        $genericResourceEvents['all'] = 'all';
        $sortedEvents[$allTranslatedText] = 'all';
        $tempResourceEvents = [];

        foreach ($textEvents as $textEvent) {
            $explodeTextEvents = explode('-', $textEvent);
            $shortTextEvent = $explodeTextEvents[0].'-'.$explodeTextEvents[1];
            $eventTrans = $this->translator->trans($explodeTextEvents[0], [], 'log');

            if ('resource' === $explodeTextEvents[0]) {
                $tempResourceEvents['all'][$allTranslatedText] = $explodeTextEvents[0];
            } else {
                $sortedEvents[$eventTrans][$explodeTextEvents[0].': '.$allTranslatedText] = $explodeTextEvents[0];
            }

            if ('resource' === $explodeTextEvents[0]) {
                if (isset($explodeTextEvents[2])) {
                    $tempResourceEvents[$explodeTextEvents[1]][$this->translator->trans(
                        'log_'.$textEvent.'_filter', [], 'log'
                    )] = $textEvent;
                } else {
                    $genericResourceEvents[$explodeTextEvents[1]] = $shortTextEvent;
                }
            } elseif (isset($explodeTextEvents[2])) {
                $sortedEvents[$eventTrans][$this->translator->trans(
                    'log_'.$textEvent.'_filter', [], 'log'
                )] = $textEvent;
            } else {
                $sortedEvents[$eventTrans][$this->translator->trans(
                    'log_'.$shortTextEvent.'_filter', [], 'log'
                )] = $shortTextEvent;
            }
        }

        $resourceTrans = $this->translator->trans('resource', [], 'platform');

        // adding resource types that don't define specific event classes
        $remainingTypes = $this->om
            ->getRepository('ClarolineCoreBundle:Resource\ResourceType')
            ->findTypeNamesNotIn(array_keys($tempResourceEvents));

        foreach ($remainingTypes as $type) {
            $tempResourceEvents[$type['name']] = [];
        }

        foreach (array_keys($tempResourceEvents) as $sortedKey) {
            $keyTrans = $this->translator->trans($sortedKey, [], 'resource');

            foreach ($genericResourceEvents as $genericEvent) {
                $logTrans = $this->translator->trans(
                    'all' === $genericEvent ? $genericEvent : 'log_'.$genericEvent.'_filter',
                        [],
                        'log'
                    );

                $genericEvent = ('all' === $genericEvent) ? 'resource' : $genericEvent;

                if ('all' !== $sortedKey) {
                    $sortedEvents[$resourceTrans][$keyTrans][$keyTrans.': '.$logTrans] = '[['.$sortedKey.']]'.$genericEvent;
                } else {
                    $sortedEvents[$resourceTrans][$allTranslatedText]['resource: '.$logTrans] = $genericEvent;
                }
            }

            if ('all' !== $sortedKey) {
                foreach ($tempResourceEvents[$sortedKey] as $resourceEventKey => $resourceEventValue) {
                    $sortedEvents[$resourceTrans][$keyTrans][$resourceEventKey] = $resourceEventValue;
                }
            }
        }

        return $sortedEvents;
    }
986697
public function registerTemplate(TemplateInterface $template)
    {
        $templateName = $template->getName();
        $parts = explode('/', $templateName);

        if (count($parts) !== 2) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Template name "%s" is not formatted properly, should be like "domain/template-name"',
                    $templateName
                )
            );
        }

        list($domain, $name) = $parts;

        $this->templates[$domain][$name] = $template;
    }
342525
public static function lookupByPath($path)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException('Argument "path" cannot be empty');
        }

        foreach (self::$methods_config as $key => $val) {
            if ($val['path'] === $path) {
                return $val;
            }
        }

        return null;
    }
224907
public function loadTranslations($key, $pathToIniFile)
    {
        $path = $pathToIniFile;
        if(!is_file($path)) {
            throw new \InvalidArgumentException(sprintf("Translation file not found into path %s", $path));
        } else {
            $this->translations[$key] = parse_ini_file($path,true);
        }
    }
138089
public static function replaceTpl($content, array $placeholders = null, Template $template)
    {
        $template = clone $template;
        $template->removeAllPlaceholders();

        return $template->replace($content, $placeholders);
    }
70021
public static ResourceName create(PathTemplate template, String path) {
    ImmutableMap<String, String> values = template.match(path);
    if (values == null) {
      throw new ValidationException("path '%s' does not match template '%s'", path, template);
    }
    return new ResourceName(template, values, null);
  }
1118274
public function getEventsForApiFilter($restriction = null)
    {
        $resourceOption = 'resource';
        $allOption = 'all';
        $eventNames = $this->getEvents($restriction);
        sort($eventNames);
        $sortedEvents = ['all' => 'all'];
        $genericResourceEvents = ['all' => 'all'];
        $tempResourceEvents = ['all' => []];

        foreach ($eventNames as $eventName) {
            $eventNameChunks = explode('-', $eventName);
            $eventKey = "log_${eventName}_filter";

            if ($eventNameChunks[0] !== 'clacoformbundle' && !isset($sortedEvents[$eventNameChunks[0]])) {
                $sortedEvents[$eventNameChunks[0]] = ['all' => "${eventNameChunks[0]}::all"];
            }

            if ($resourceOption === $eventNameChunks[0]) {
                if (isset($eventNameChunks[2])) {
                    $tempResourceEvents[$eventNameChunks[1]][$eventKey] = $eventName;
                } else {
                    $genericResourceEvents[$eventKey] = $eventName;
                }
            } elseif ($eventNameChunks[0] === 'clacoformbundle') {
                $tempResourceEvents[$eventNameChunks[0]][$eventKey] = $eventName;
            } else {
                $sortedEvents[$eventNameChunks[0]][$eventKey] = $eventName;
            }
        }

        // adding resource types that don't define specific event classes
        $sortedEvents[$resourceOption][$allOption] = [];
        $remainingTypes = $this->om
            ->getRepository('ClarolineCoreBundle:Resource\ResourceType')
            ->findTypeNamesNotIn(array_keys($tempResourceEvents));

        foreach ($remainingTypes as $type) {
            $tempResourceEvents[$type['name']] = [];
        }

        foreach (array_keys($tempResourceEvents) as $resourceType) {
            if ($resourceType === 'resource_shortcut') {
                continue;
            }

            foreach ($genericResourceEvents as $genericEventKey => $genericEventName) {
                $eventPrefix = '';
                if ($allOption !== $resourceType) {
                    $eventPrefix = "${resourceOption}::${resourceType}::";
                }
                if ($allOption === $resourceType && $genericEventName === $allOption) {
                    $eventPrefix = "${resourceOption}::";
                }
                $sortedEvents[$resourceOption][$resourceType][$genericEventKey] = $eventPrefix.$genericEventName;
            }

            if ($allOption !== $resourceType) {
                foreach ($tempResourceEvents[$resourceType] as $resourceEventKey => $resourceEventName) {
                    $sortedEvents[$resourceOption][$resourceType][$resourceEventKey] = $resourceEventName;
                }
            }
        }

        return $this->formatEventsTableForApi($sortedEvents);
    }
610491
public function templatePath($path = null)
    {
        deprecationWarning('ViewBuilder::templatePath() is deprecated. Use ViewBuilder::setTemplatePath() or ViewBuilder::getTemplatePath() instead.');
        if ($path !== null) {
            return $this->setTemplatePath($path);
        }

        return $this->getTemplatePath();
    }