Skip to content

Commit e71624f

Browse files
authored
Merge pull request #18 from alwaysblank/14-refactor-for-internal-keys
2 parents 40285cc + 2920629 commit e71624f

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/Brief.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,14 @@ protected function getHighestOrder()
644644
*/
645645
public function get($key)
646646
{
647-
if (is_int($key)) {
648-
return $this->getByOrder($key);
649-
} elseif (is_string($key)) {
650-
return $this->getByKey($this->getAuthoritativeName($key));
647+
$internalKey = $this->resolveInternalKey($key);
648+
if ($internalKey === null) {
649+
return null;
651650
}
652651

653-
return null;
652+
return is_int($internalKey)
653+
? $this->getByOrder($internalKey)
654+
: $this->getByKey($internalKey);
654655
}
655656

656657
/**
@@ -884,4 +885,22 @@ public function isNotEmpty()
884885
{
885886
return !$this->isEmpty();
886887
}
888+
889+
/**
890+
* This returns the *internal* key used to store this data.
891+
*
892+
* @param string|int $key
893+
*
894+
* @return string|int|null
895+
*/
896+
protected function resolveInternalKey($key) {
897+
if (is_int($key)) {
898+
$ordered = $this->getOrdered();
899+
return isset($ordered[$key]) ? $key : null;
900+
} elseif (is_string($key)) {
901+
return $this->getAuthoritativeName($key);
902+
}
903+
904+
return null;
905+
}
887906
}

0 commit comments

Comments
 (0)