PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Database / Concerns / HasDictionary.php
kirki / libraries / framework / Database / Concerns Last commit date
ExecuteQueries.php 1 month ago GuardAttributes.php 1 month ago HasAttributes.php 1 month ago HasDictionary.php 1 month ago HasRelationships.php 1 month ago HasTimestamps.php 1 month ago RelationshipQueries.php 1 month ago
HasDictionary.php
43 lines
1 <?php
2
3 /**
4 * Trait providing dictionary key normalization for model collections.
5 * Converts attribute keys to strings via __toString or casting, throwing on unsupported types.
6 * Ensures collection merge and lookup use consistent primary-key indexing.
7 *
8 * @package Framework
9 * @subpackage Database\Concerns
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Database\Concerns;
13
14 \defined('ABSPATH') || exit;
15 use InvalidArgumentException;
16 trait HasDictionary
17 {
18 /**
19 * Get the dictionary key for the attribute.
20 *
21 * @param mixed $attribute The attribute to get the key for
22 *
23 * @return string The dictionary key
24 *
25 * @throws \InvalidArgumentException
26 *
27 * @since 1.0.0
28 */
29 protected function get_dictionary_key($attribute)
30 {
31 if (\is_null($attribute) || \is_string($attribute) || \is_int($attribute)) {
32 return $attribute;
33 }
34 if (\is_object($attribute)) {
35 if (\method_exists($attribute, '__toString')) {
36 return $attribute->__toString();
37 }
38 throw new InvalidArgumentException('Attribute must be a string, integer, or object with a __toString method.');
39 }
40 return (string) $attribute;
41 }
42 }
43