Skip to content
Merged

fix #96

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
4 changes: 2 additions & 2 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
### Class: Rudra\Annotation\ParamsExtractor
| Visibility | Function |
|:-----------|:---------|
| public | `getParams(array $exploded, string $assignment): array`<br>--------------------------------------------------------------\|<br>Parses an array of parameter strings into an associative array<br>--------------------------------------------------------------\|<br>Преобразует массив строк с параметрами в ассоциативный массив<br>--------------------------------------------------------------\|<br>------------------------------------------------------------------------------------\|<br>`from: "param1, param2 = 'param2', param3={param1;param2:'param2'}"`<br>`to: ["param1", "param2" => "param2", "param3" => ["param1", "param2" => "param2"]]`<br>------------------------------------------------------------------------------------\| |
| private | `handleData(string $data, array $exploded): ?array`<br>--------------------------------------------\|<br>Parses data into `key => value` pairs<br>--------------------------------------------\|<br>Преобразует данные в пары `ключ => значение`<br>--------------------------------------------\|<br>⚠️ IMPORTANT / ВАЖНО:<br>--------------------------------------------\|<br>Values inside arrays (curly braces) must not<br>contain the array assignment mark (`:`)<br>--------------------------------------------\|<br>Значения внутри массивов (фигурные скобки)<br>не должны содержать знак присваивания (`:`)<br>--------------------------------------------\| |
| public | `getParams(array $exploded, string $assignment): array`<br>--------------------------------------------------------------<br>Parses an array of parameter strings into an associative array<br>--------------------------------------------------------------<br>Преобразует массив строк с параметрами в ассоциативный массив<br>--------------------------------------------------------------<br>------------------------------------------------------------------------------------<br>`from: "param1, param2 = 'param2', param3={param1;param2:'param2'}"`<br>`to: ["param1", "param2" => "param2", "param3" => ["param1", "param2" => "param2"]]`<br>------------------------------------------------------------------------------------ |
| private | `handleData(string $data, array $exploded): ?array`<br>--------------------------------------------<br>Parses data into `key => value` pairs<br>--------------------------------------------<br>Преобразует данные в пары `ключ => значение`<br>--------------------------------------------<br>⚠️ IMPORTANT / ВАЖНО:<br>--------------------------------------------<br>Values inside arrays (curly braces) must not<br>contain the array assignment mark (`:`)<br>--------------------------------------------<br>Значения внутри массивов (фигурные скобки)<br>не должны содержать знак присваивания (`:`)<br>-------------------------------------------- |


---
Expand Down
28 changes: 14 additions & 14 deletions src/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
class Annotation implements AnnotationInterface
{
/**
* ----------------------|
* ----------------------
* Parameter separator
* ----------------------|
* ----------------------
* Разделитель параметров
* ----------------------|
* ----------------------
*
* --------------------------------------------------------|
* --------------------------------------------------------
* in the line ',', example: key='param', key2='param2'
* in the array ';', example: {key:'param'; key2:'param2'}
* --------------------------------------------------------|
* --------------------------------------------------------
*/
public const array DELIMITER = ["string" => ',', "array" => ';'];

/**
* -----------------|
* -----------------
* Assignment mark
* -----------------|
* -----------------
* Знак присваивания
* -----------------|
* -----------------
*
* ----------------------------------------|
* ----------------------------------------
* in the line '=', example: key='param'
* in the array ':', example: {key:'param'}
* ----------------------------------------|
* ----------------------------------------
*/
public const array ASSIGNMENT = ["string" => '=', "array" => ':'];

Expand Down Expand Up @@ -113,20 +113,20 @@ private function parseAnnotations(string $docBlock): array
$annotations = [];

/**
* --------------------------------------------------------------------------------------|
* --------------------------------------------------------------------------------------
* $matches[0][0] - @Annotation(param1, param2='param2', param3={param1;param2:'param2'})
* $matches[1][0] - Annotation
* $matches[2][0] - param1, param2 = 'param2', param3={param1;param2:'param2'}
* --------------------------------------------------------------------------------------|
* --------------------------------------------------------------------------------------
*/
if (preg_match_all("/@([A-Za-z_-]+)\((.*)?\)/", $docBlock, $matches)) {
$count = count($matches[0]);
$extractor = new ParamsExtractor();

/**
* ----------------------------------------------------------------------------------------------------------------------|
* ----------------------------------------------------------------------------------------------------------------------
* $annotations = ["Annotation" => [[0 => "param1", "param2" => "param2", "param3" => ["param1", "param2" => "param2"]]]]
* ----------------------------------------------------------------------------------------------------------------------|
* ----------------------------------------------------------------------------------------------------------------------
*/
for ($i = 0; $i < $count; $i++) {
$annotations[$matches[1][$i]][] = $extractor->getParams(
Expand Down
38 changes: 19 additions & 19 deletions src/ParamsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
class ParamsExtractor
{
/**
* --------------------------------------------------------------|
* --------------------------------------------------------------
* Parses an array of parameter strings into an associative array
* --------------------------------------------------------------|
* --------------------------------------------------------------
* Преобразует массив строк с параметрами в ассоциативный массив
* --------------------------------------------------------------|
* --------------------------------------------------------------
*
* ------------------------------------------------------------------------------------|
* ------------------------------------------------------------------------------------
* `from: "param1, param2 = 'param2', param3={param1;param2:'param2'}"`
* `to: ["param1", "param2" => "param2", "param3" => ["param1", "param2" => "param2"]]`
* ------------------------------------------------------------------------------------|
* ------------------------------------------------------------------------------------
*
* @param array $exploded
* @param string $assignment
Expand All @@ -45,20 +45,20 @@ public function getParams(array $exploded, string $assignment): array
}

/**
* --------------------------------------------|
* --------------------------------------------
* Parses data into `key => value` pairs
* --------------------------------------------|
* --------------------------------------------
* Преобразует данные в пары `ключ => значение`
* --------------------------------------------|
* --------------------------------------------
*
* ⚠️ IMPORTANT / ВАЖНО:
* --------------------------------------------|
* --------------------------------------------
* Values inside arrays (curly braces) must not
* contain the array assignment mark (`:`)
* --------------------------------------------|
* --------------------------------------------
* Значения внутри массивов (фигурные скобки)
* не должны содержать знак присваивания (`:`)
* --------------------------------------------|
* --------------------------------------------
*
* @param string $data
* @param array $exploded
Expand All @@ -68,11 +68,11 @@ public function getParams(array $exploded, string $assignment): array
private function handleData(string $data, array $exploded): ?array
{
/**
* --------------------------------------------------------------|
* --------------------------------------------------------------
* If in data an array of type param3={param1;param2:'param2'}
* --------------------------------------------------------------|
* --------------------------------------------------------------
* Если в данных есть массив типа param3={param1;param2:'param2'}
* --------------------------------------------------------------|
* --------------------------------------------------------------
*/
if (preg_match("/=\s*{/", $data) && preg_match("/{(.*)}/", $exploded[1], $matches)) {
return [
Expand All @@ -84,15 +84,15 @@ private function handleData(string $data, array $exploded): ?array
}

/**
* ---------------------------------------|
* ---------------------------------------
* Remove quotation marks around parameter
* ---------------------------------------|
* ---------------------------------------
* Удаляет кавычки вокруг параметра
* ---------------------------------------|
* ---------------------------------------
*
* ----------------------|
* ----------------------
* matches[1] = 'param2';
* ----------------------|
* ----------------------
*/
if (preg_match("/'(.*)'/", $exploded[1], $matches)) {
return [trim($exploded[0]) => $matches[1]];
Expand Down
Loading