[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of JSON-API. 5 * 6 * (c) Toby Zerner <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Tobscure\JsonApi; 13 14 class Util 15 { 16 /** 17 * Parse relationship paths. 18 * 19 * Given a flat array of relationship paths like: 20 * 21 * ['user', 'user.employer', 'user.employer.country', 'comments'] 22 * 23 * create a nested array of relationship paths one-level deep that can 24 * be passed on to other serializers: 25 * 26 * ['user' => ['employer', 'employer.country'], 'comments' => []] 27 * 28 * @param array $paths 29 * 30 * @return array 31 */ 32 public static function parseRelationshipPaths(array $paths) 33 { 34 $tree = []; 35 36 foreach ($paths as $path) { 37 list($primary, $nested) = array_pad(explode('.', $path, 2), 2, null); 38 39 if (! isset($tree[$primary])) { 40 $tree[$primary] = []; 41 } 42 43 if ($nested) { 44 $tree[$primary][] = $nested; 45 } 46 } 47 48 return $tree; 49 } 50 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |