1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\Validator\Util; 13 14/** 15 * Contains utility methods for dealing with property paths. 16 * 17 * For more extensive functionality, use Symfony's PropertyAccess component. 18 * 19 * @author Bernhard Schussek <bschussek@gmail.com> 20 */ 21class PropertyPath 22{ 23 /** 24 * Appends a path to a given property path. 25 * 26 * If the base path is empty, the appended path will be returned unchanged. 27 * If the base path is not empty, and the appended path starts with a 28 * squared opening bracket ("["), the concatenation of the two paths is 29 * returned. Otherwise, the concatenation of the two paths is returned, 30 * separated by a dot ("."). 31 * 32 * @param string $basePath The base path 33 * @param string $subPath The path to append 34 * 35 * @return string The concatenation of the two property paths 36 */ 37 public static function append($basePath, $subPath) 38 { 39 $subPath = (string) $subPath; 40 if ('' !== $subPath) { 41 if ('[' === $subPath[0]) { 42 return $basePath.$subPath; 43 } 44 45 return '' !== $basePath ? $basePath.'.'.$subPath : $subPath; 46 } 47 48 return $basePath; 49 } 50 51 /** 52 * Not instantiable. 53 */ 54 private function __construct() 55 { 56 } 57} 58