Skip to content

Commit c3ef15a

Browse files
committed
Update Metable.php
1 parent 91aa160 commit c3ef15a

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Kodeine/Metable/Metable.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public function hasMeta($key): bool {
9696
if ( is_string( $key ) && preg_match( '/[,|]/is', $key ) ) {
9797
$key = preg_split( '/ ?[,|] ?/', $key );
9898
}
99-
$setMeta = 'hasMeta' . ucfirst( gettype( $key ) );
99+
$hasMeta = 'hasMeta' . ucfirst( gettype( $key ) );
100100

101-
return $this->$setMeta( $key );
101+
return $this->$hasMeta( $key );
102102
}
103103

104104
protected function hasMetaString($key): bool {
@@ -218,6 +218,7 @@ public function getDefaultMetaValue($key) {
218218
}
219219

220220
protected function getMetaString($key, $default = null) {
221+
$key = strtolower( $key );
221222
$meta = $this->getMetaData()->get( $key );
222223

223224
if ( is_null( $meta ) || $meta->isMarkedForDeletion() ) {
@@ -230,16 +231,18 @@ protected function getMetaString($key, $default = null) {
230231

231232
protected function getMetaArray($keys, $default = null): BaseCollection {
232233
$collection = new BaseCollection();
233-
$flipped = array_flip( $keys );
234-
foreach ($this->getMetaData() as $meta) {
235-
if ( ! $meta->isMarkedForDeletion() && isset( $flipped[$meta->key] ) ) {
236-
unset( $flipped[$meta->key] );
237-
$collection->put( $meta->key, $meta->value );
234+
235+
foreach ($keys as $key) {
236+
$key = strtolower( $key );
237+
if ( $this->hasMeta( $key ) ) {
238+
$meta = $this->getMetaData()[$key];
239+
if ( ! $meta->isMarkedForDeletion() ) {
240+
$collection->put( $key, $meta->value );
241+
continue;
242+
}
238243
}
239-
}
240-
// If there are any keys left in $flipped, it means they are not set. so fill them with default values.
241-
// Default values set in defaultMetaValues property take precedence over default values passed to this method
242-
foreach ($flipped as $key => $value) {
244+
// Key does not exist, so it's value will be the default value
245+
// Default values set in defaultMetaValues property take precedence over default value passed to this method
243246
$defaultValue = $this->getDefaultMetaValue( $key );
244247
if ( is_null( $defaultValue ) ) {
245248
if ( is_array( $default ) ) {

0 commit comments

Comments
 (0)