|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright since 2007 PrestaShop SA and Contributors |
| 4 | + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA |
| 5 | + * |
| 6 | + * NOTICE OF LICENSE |
| 7 | + * |
| 8 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 9 | + * that is bundled with this package in the file LICENSE.md. |
| 10 | + * It is also available through the world-wide-web at this URL: |
| 11 | + * https://opensource.org/licenses/OSL-3.0 |
| 12 | + * If you did not receive a copy of the license and are unable to |
| 13 | + * obtain it through the world-wide-web, please send an email |
| 14 | + * to [email protected] so we can send you a copy immediately. |
| 15 | + * |
| 16 | + * DISCLAIMER |
| 17 | + * |
| 18 | + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer |
| 19 | + * versions in the future. If you wish to customize PrestaShop for your |
| 20 | + * needs please refer to https://devdocs.prestashop.com/ for more information. |
| 21 | + * |
| 22 | + * @author PrestaShop SA and Contributors <[email protected]> |
| 23 | + * @copyright Since 2007 PrestaShop SA and Contributors |
| 24 | + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 25 | + */ |
| 26 | + |
| 27 | +namespace PrestaShopBundleInfiniteRunBug; |
| 28 | + |
| 29 | +class XmlLoader |
| 30 | +{ |
| 31 | + |
| 32 | + protected $data_path; |
| 33 | + |
| 34 | + public function getEntityInfo($entity, $exists) |
| 35 | + { |
| 36 | + $info = [ |
| 37 | + 'config' => [ |
| 38 | + 'id' => '', |
| 39 | + 'primary' => '', |
| 40 | + 'class' => '', |
| 41 | + 'sql' => '', |
| 42 | + 'ordersql' => '', |
| 43 | + 'image' => '', |
| 44 | + 'null' => '', |
| 45 | + ], |
| 46 | + 'fields' => [], |
| 47 | + ]; |
| 48 | + |
| 49 | + if (!$exists) { |
| 50 | + return $info; |
| 51 | + } |
| 52 | + |
| 53 | + $xml = @simplexml_load_file($this->data_path . $entity . '.xml', 'SimplexmlElement'); |
| 54 | + if (!$xml) { |
| 55 | + return $info; |
| 56 | + } |
| 57 | + |
| 58 | + if ($xml->fields['id']) { |
| 59 | + $info['config']['id'] = (string) $xml->fields['id']; |
| 60 | + } |
| 61 | + |
| 62 | + if ($xml->fields['primary']) { |
| 63 | + $info['config']['primary'] = (string) $xml->fields['primary']; |
| 64 | + } |
| 65 | + |
| 66 | + if ($xml->fields['class']) { |
| 67 | + $info['config']['class'] = (string) $xml->fields['class']; |
| 68 | + } |
| 69 | + |
| 70 | + if ($xml->fields['sql']) { |
| 71 | + $info['config']['sql'] = (string) $xml->fields['sql']; |
| 72 | + } |
| 73 | + |
| 74 | + if ($xml->fields['ordersql']) { |
| 75 | + $info['config']['ordersql'] = (string) $xml->fields['ordersql']; |
| 76 | + } |
| 77 | + |
| 78 | + if ($xml->fields['null']) { |
| 79 | + $info['config']['null'] = (string) $xml->fields['null']; |
| 80 | + } |
| 81 | + |
| 82 | + if ($xml->fields['image']) { |
| 83 | + $info['config']['image'] = (string) $xml->fields['image']; |
| 84 | + } |
| 85 | + |
| 86 | + foreach ($xml->fields->field as $field) { |
| 87 | + $column = (string) $field['name']; |
| 88 | + $info['fields'][$column] = []; |
| 89 | + if (isset($field['relation'])) { |
| 90 | + $info['fields'][$column]['relation'] = (string) $field['relation']; |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + return $info; |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments