Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,26 @@ public static function create(
*/
public static function fromString(Text $configString)
{
$quotation = false;
$text = '';
while (false === $configString->eof()) {
$char = $configString->getChar();
if ('{' === $char) {
if (!$quotation && ('"' === $char || "'" === $char)) {
$quotation = $char;
$text .= $char;
$configString->inc();
continue;
}
if ($quotation && $quotation === $char) {
$quotation = false;
$text .= $char;
$configString->inc();
continue;
}
if ('{' === $char && !$quotation) {
return self::newDirectiveWithScope($text, $configString);
}
if (';' === $char) {
if (';' === $char && !$quotation) {
return self::newDirectiveWithoutScope($text, $configString);
}
$text .= $char;
Expand Down Expand Up @@ -171,7 +184,7 @@ private static function processText($text)
}

private static function checkKeyValue($text) {
if (1 === preg_match('#^([a-zA-Z0-9._/+-]*)\s+([^;{]+)$#', $text, $matches)) {
if (1 === preg_match('#^([a-zA-Z0-9._/+-]*)\s+(.+)$#s', $text, $matches)) {
return array($matches[1], rtrim($matches[2]));
}
return false;
Expand Down
17 changes: 17 additions & 0 deletions src/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ public function getDirectiveByKey($key)
return null;
}

/**
* returns all directives searched by key as an array, for example return all server
*
* @param string $key
* @return array
*/
public function getAllDirectivesByKey($key)
{
$reusult = array();
foreach($this->directives as $dir) {
if ($key == $dir->getName()) {
$reusult[] = $dir;
}
}
return $reusult;
}

public function getDirective($key)
{
$dir = null;
Expand Down