@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | public function testRegisterBindings(): void |
| 23 | 23 | { |
| 24 | 24 | $listenerName = 'foo'; |
| 25 | - $events1 = [$listenerName => [fn () => null]]; |
|
| 26 | - $events2 = [$listenerName => [fn () => null]]; |
|
| 25 | + $events1 = [$listenerName => [fn() => null]]; |
|
| 26 | + $events2 = [$listenerName => [fn() => null]]; |
|
| 27 | 27 | |
| 28 | 28 | $this->sut->setBaseEvents($events1); |
| 29 | 29 | $this->sut->setModuleEvents($events2); |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | public function testRegisterBindingsMixed(): void |
| 45 | 45 | { |
| 46 | 46 | $listenerName1 = 'foo'; |
| 47 | - $events1 = [$listenerName1 => [fn () => null]]; |
|
| 47 | + $events1 = [$listenerName1 => [fn() => null]]; |
|
| 48 | 48 | |
| 49 | 49 | $listenerName2 = 'bar'; |
| 50 | - $events2 = [$listenerName2 => [fn () => null]]; |
|
| 50 | + $events2 = [$listenerName2 => [fn() => null]]; |
|
| 51 | 51 | |
| 52 | 52 | $this->sut->setBaseEvents($events1); |
| 53 | 53 | $this->sut->setModuleEvents($events2); |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $sessionData = &$this->sessionData; |
| 35 | 35 | $this->sessionMock->expects($this->any())->method('has')->willReturnCallback( |
| 36 | - fn ($key) => isset($sessionData[$key]) |
|
| 36 | + fn($key) => isset($sessionData[$key]) |
|
| 37 | 37 | ); |
| 38 | 38 | $this->sessionMock->expects($this->any())->method('get')->willReturnCallback( |
| 39 | - fn ($key) => $sessionData[$key] ?? '' |
|
| 39 | + fn($key) => $sessionData[$key] ?? '' |
|
| 40 | 40 | ); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | $sessionMock = $this->createMock(Session::class); |
| 65 | 65 | |
| 66 | 66 | $sessionMock->expects($this->any())->method('has')->willReturnCallback( |
| 67 | - fn ($key) => isset($sessionData[$key]) |
|
| 67 | + fn($key) => isset($sessionData[$key]) |
|
| 68 | 68 | ); |
| 69 | 69 | $sessionMock->expects($this->any())->method('get')->willReturnCallback( |
| 70 | - fn ($key) => $sessionData[$key] ?? '' |
|
| 70 | + fn($key) => $sessionData[$key] ?? '' |
|
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | 73 | $sut = new UserBlock($sessionMock); |
@@ -273,7 +273,7 @@ |
||
| 273 | 273 | { |
| 274 | 274 | $this->sut = new Uploader($this->filesystemMock); |
| 275 | 275 | |
| 276 | - $fooPathFactory = fn ($filename) => "/foo-base-dir/$filename"; |
|
| 276 | + $fooPathFactory = fn($filename) => "/foo-base-dir/$filename"; |
|
| 277 | 277 | |
| 278 | 278 | $key = 'foo'; |
| 279 | 279 | $path = 'example.foo'; |
@@ -39,162 +39,3 @@ |
||
| 39 | 39 | * %2$s - nodes (filters) |
| 40 | 40 | */ |
| 41 | 41 | protected const DEFAULT_TEMPLATE = <<<'EOT' |
| 42 | - <div class="hidable"> |
|
| 43 | - <p class="hider">%1$s</p> |
|
| 44 | - <div class="hidee">%2$s</div> |
|
| 45 | - </div> |
|
| 46 | - EOT; |
|
| 47 | - |
|
| 48 | - protected string $template = self::DEFAULT_TEMPLATE; |
|
| 49 | - |
|
| 50 | - /** @var IFilter[] */ |
|
| 51 | - protected array $nodes = []; |
|
| 52 | - |
|
| 53 | - protected string $nodeClass = IFilter::class; |
|
| 54 | - |
|
| 55 | - protected Action $hiderBtn; |
|
| 56 | - |
|
| 57 | - protected Action $filterBtn; |
|
| 58 | - |
|
| 59 | - protected Action $resetBtn; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Filters constructor. |
|
| 63 | - * |
|
| 64 | - * @param string[] $intents |
|
| 65 | - * @param Attributes|null $attributes |
|
| 66 | - * @param string|null $tag |
|
| 67 | - */ |
|
| 68 | - public function __construct(array $intents = [], ?Attributes $attributes = null, ?string $tag = null) |
|
| 69 | - { |
|
| 70 | - parent::__construct(null, $intents, $attributes, $tag); |
|
| 71 | - |
|
| 72 | - $this->hiderBtn = new Action(static::BTN_CONTENT_FILTERS, [Action::INTENT_INFO]); |
|
| 73 | - $this->filterBtn = new Action(static::BTN_CONTENT_FILTER, [Action::INTENT_PRIMARY], static::ATTRIBUTES_SEARCH); |
|
| 74 | - $this->resetBtn = new Action(static::BTN_CONTENT_RESET, [Action::INTENT_SECONDARY], static::ATTRIBUTES_RESET); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param array $params |
|
| 79 | - * |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setParams(array $params): Filters |
|
| 83 | - { |
|
| 84 | - foreach ($this->nodes as $filter) { |
|
| 85 | - $filter->setParams($params); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $baseUrl |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getUrl(string $baseUrl): string |
|
| 97 | - { |
|
| 98 | - $queryParts = []; |
|
| 99 | - foreach ($this->nodes as $filter) { |
|
| 100 | - $queryPart = $filter->getQueryPart(); |
|
| 101 | - if (!$queryPart) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $queryParts[] = $queryPart; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (empty($queryParts)) { |
|
| 109 | - return $baseUrl; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return sprintf('%s%s&', $baseUrl, implode('&', $queryParts)); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getWhereConditions(): array |
|
| 119 | - { |
|
| 120 | - $conditions = []; |
|
| 121 | - foreach ($this->nodes as $filter) { |
|
| 122 | - $conditions = array_merge($conditions, $filter->getWhereConditions()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $conditions; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return array<string,string> |
|
| 130 | - */ |
|
| 131 | - public function getSqlParams(): array |
|
| 132 | - { |
|
| 133 | - $params = []; |
|
| 134 | - foreach ($this->nodes as $filter) { |
|
| 135 | - $params = array_merge($params, $filter->getQueryParams()); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $params; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return INode[] |
|
| 143 | - */ |
|
| 144 | - public function getExtendedNodes(): array |
|
| 145 | - { |
|
| 146 | - return array_merge([$this->hiderBtn, $this->filterBtn, $this->resetBtn], $this->getNodes()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $template |
|
| 151 | - * |
|
| 152 | - * @return INode |
|
| 153 | - */ |
|
| 154 | - public function setTemplate(string $template): INode |
|
| 155 | - { |
|
| 156 | - $this->template = $template; |
|
| 157 | - |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function __toString(): string |
|
| 165 | - { |
|
| 166 | - $nodes = Collection::__toString(); |
|
| 167 | - |
|
| 168 | - $form = sprintf(self::WITH_CONTENT_TAG, $this->tag, $nodes, new Attributes( [Html5::ATTR_CLASS => 'filter-form'])); |
|
| 169 | - |
|
| 170 | - return sprintf( |
|
| 171 | - $this->template, |
|
| 172 | - (string)$this->hiderBtn, |
|
| 173 | - $form |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return Action |
|
| 179 | - */ |
|
| 180 | - public function getHiderBtn(): Action |
|
| 181 | - { |
|
| 182 | - return $this->hiderBtn; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Action |
|
| 187 | - */ |
|
| 188 | - public function getFilterBtn(): Action |
|
| 189 | - { |
|
| 190 | - return $this->filterBtn; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return Action |
|
| 195 | - */ |
|
| 196 | - public function getResetBtn(): Action |
|
| 197 | - { |
|
| 198 | - return $this->resetBtn; |
|
| 199 | - } |
|
| 200 | -} |
|
@@ -39,162 +39,3 @@ |
||
| 39 | 39 | * %2$s - nodes (filters) |
| 40 | 40 | */ |
| 41 | 41 | protected const DEFAULT_TEMPLATE = <<<'EOT' |
| 42 | - <div class="hidable"> |
|
| 43 | - <p class="hider">%1$s</p> |
|
| 44 | - <div class="hidee">%2$s</div> |
|
| 45 | - </div> |
|
| 46 | - EOT; |
|
| 47 | - |
|
| 48 | - protected string $template = self::DEFAULT_TEMPLATE; |
|
| 49 | - |
|
| 50 | - /** @var IFilter[] */ |
|
| 51 | - protected array $nodes = []; |
|
| 52 | - |
|
| 53 | - protected string $nodeClass = IFilter::class; |
|
| 54 | - |
|
| 55 | - protected Action $hiderBtn; |
|
| 56 | - |
|
| 57 | - protected Action $filterBtn; |
|
| 58 | - |
|
| 59 | - protected Action $resetBtn; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Filters constructor. |
|
| 63 | - * |
|
| 64 | - * @param string[] $intents |
|
| 65 | - * @param Attributes|null $attributes |
|
| 66 | - * @param string|null $tag |
|
| 67 | - */ |
|
| 68 | - public function __construct(array $intents = [], ?Attributes $attributes = null, ?string $tag = null) |
|
| 69 | - { |
|
| 70 | - parent::__construct(null, $intents, $attributes, $tag); |
|
| 71 | - |
|
| 72 | - $this->hiderBtn = new Action(static::BTN_CONTENT_FILTERS, [Action::INTENT_INFO]); |
|
| 73 | - $this->filterBtn = new Action(static::BTN_CONTENT_FILTER, [Action::INTENT_PRIMARY], static::ATTRIBUTES_SEARCH); |
|
| 74 | - $this->resetBtn = new Action(static::BTN_CONTENT_RESET, [Action::INTENT_SECONDARY], static::ATTRIBUTES_RESET); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param array $params |
|
| 79 | - * |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setParams(array $params): Filters |
|
| 83 | - { |
|
| 84 | - foreach ($this->nodes as $filter) { |
|
| 85 | - $filter->setParams($params); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $baseUrl |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getUrl(string $baseUrl): string |
|
| 97 | - { |
|
| 98 | - $queryParts = []; |
|
| 99 | - foreach ($this->nodes as $filter) { |
|
| 100 | - $queryPart = $filter->getQueryPart(); |
|
| 101 | - if (!$queryPart) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $queryParts[] = $queryPart; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (empty($queryParts)) { |
|
| 109 | - return $baseUrl; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return sprintf('%s%s&', $baseUrl, implode('&', $queryParts)); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getWhereConditions(): array |
|
| 119 | - { |
|
| 120 | - $conditions = []; |
|
| 121 | - foreach ($this->nodes as $filter) { |
|
| 122 | - $conditions = array_merge($conditions, $filter->getWhereConditions()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $conditions; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return array<string,string> |
|
| 130 | - */ |
|
| 131 | - public function getSqlParams(): array |
|
| 132 | - { |
|
| 133 | - $params = []; |
|
| 134 | - foreach ($this->nodes as $filter) { |
|
| 135 | - $params = array_merge($params, $filter->getQueryParams()); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $params; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return INode[] |
|
| 143 | - */ |
|
| 144 | - public function getExtendedNodes(): array |
|
| 145 | - { |
|
| 146 | - return array_merge([$this->hiderBtn, $this->filterBtn, $this->resetBtn], $this->getNodes()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $template |
|
| 151 | - * |
|
| 152 | - * @return INode |
|
| 153 | - */ |
|
| 154 | - public function setTemplate(string $template): INode |
|
| 155 | - { |
|
| 156 | - $this->template = $template; |
|
| 157 | - |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function __toString(): string |
|
| 165 | - { |
|
| 166 | - $nodes = Collection::__toString(); |
|
| 167 | - |
|
| 168 | - $form = sprintf(self::WITH_CONTENT_TAG, $this->tag, $nodes, new Attributes( [Html5::ATTR_CLASS => 'filter-form'])); |
|
| 169 | - |
|
| 170 | - return sprintf( |
|
| 171 | - $this->template, |
|
| 172 | - (string)$this->hiderBtn, |
|
| 173 | - $form |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return Action |
|
| 179 | - */ |
|
| 180 | - public function getHiderBtn(): Action |
|
| 181 | - { |
|
| 182 | - return $this->hiderBtn; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Action |
|
| 187 | - */ |
|
| 188 | - public function getFilterBtn(): Action |
|
| 189 | - { |
|
| 190 | - return $this->filterBtn; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return Action |
|
| 195 | - */ |
|
| 196 | - public function getResetBtn(): Action |
|
| 197 | - { |
|
| 198 | - return $this->resetBtn; |
|
| 199 | - } |
|
| 200 | -} |
|
@@ -39,162 +39,3 @@ |
||
| 39 | 39 | * %2$s - nodes (filters) |
| 40 | 40 | */ |
| 41 | 41 | protected const DEFAULT_TEMPLATE = <<<'EOT' |
| 42 | - <div class="hidable"> |
|
| 43 | - <p class="hider">%1$s</p> |
|
| 44 | - <div class="hidee">%2$s</div> |
|
| 45 | - </div> |
|
| 46 | - EOT; |
|
| 47 | - |
|
| 48 | - protected string $template = self::DEFAULT_TEMPLATE; |
|
| 49 | - |
|
| 50 | - /** @var IFilter[] */ |
|
| 51 | - protected array $nodes = []; |
|
| 52 | - |
|
| 53 | - protected string $nodeClass = IFilter::class; |
|
| 54 | - |
|
| 55 | - protected Action $hiderBtn; |
|
| 56 | - |
|
| 57 | - protected Action $filterBtn; |
|
| 58 | - |
|
| 59 | - protected Action $resetBtn; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Filters constructor. |
|
| 63 | - * |
|
| 64 | - * @param string[] $intents |
|
| 65 | - * @param Attributes|null $attributes |
|
| 66 | - * @param string|null $tag |
|
| 67 | - */ |
|
| 68 | - public function __construct(array $intents = [], ?Attributes $attributes = null, ?string $tag = null) |
|
| 69 | - { |
|
| 70 | - parent::__construct(null, $intents, $attributes, $tag); |
|
| 71 | - |
|
| 72 | - $this->hiderBtn = new Action(static::BTN_CONTENT_FILTERS, [Action::INTENT_INFO]); |
|
| 73 | - $this->filterBtn = new Action(static::BTN_CONTENT_FILTER, [Action::INTENT_PRIMARY], static::ATTRIBUTES_SEARCH); |
|
| 74 | - $this->resetBtn = new Action(static::BTN_CONTENT_RESET, [Action::INTENT_SECONDARY], static::ATTRIBUTES_RESET); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param array $params |
|
| 79 | - * |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setParams(array $params): Filters |
|
| 83 | - { |
|
| 84 | - foreach ($this->nodes as $filter) { |
|
| 85 | - $filter->setParams($params); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $baseUrl |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getUrl(string $baseUrl): string |
|
| 97 | - { |
|
| 98 | - $queryParts = []; |
|
| 99 | - foreach ($this->nodes as $filter) { |
|
| 100 | - $queryPart = $filter->getQueryPart(); |
|
| 101 | - if (!$queryPart) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $queryParts[] = $queryPart; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (empty($queryParts)) { |
|
| 109 | - return $baseUrl; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return sprintf('%s%s&', $baseUrl, implode('&', $queryParts)); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getWhereConditions(): array |
|
| 119 | - { |
|
| 120 | - $conditions = []; |
|
| 121 | - foreach ($this->nodes as $filter) { |
|
| 122 | - $conditions = array_merge($conditions, $filter->getWhereConditions()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $conditions; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return array<string,string> |
|
| 130 | - */ |
|
| 131 | - public function getSqlParams(): array |
|
| 132 | - { |
|
| 133 | - $params = []; |
|
| 134 | - foreach ($this->nodes as $filter) { |
|
| 135 | - $params = array_merge($params, $filter->getQueryParams()); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $params; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return INode[] |
|
| 143 | - */ |
|
| 144 | - public function getExtendedNodes(): array |
|
| 145 | - { |
|
| 146 | - return array_merge([$this->hiderBtn, $this->filterBtn, $this->resetBtn], $this->getNodes()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $template |
|
| 151 | - * |
|
| 152 | - * @return INode |
|
| 153 | - */ |
|
| 154 | - public function setTemplate(string $template): INode |
|
| 155 | - { |
|
| 156 | - $this->template = $template; |
|
| 157 | - |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function __toString(): string |
|
| 165 | - { |
|
| 166 | - $nodes = Collection::__toString(); |
|
| 167 | - |
|
| 168 | - $form = sprintf(self::WITH_CONTENT_TAG, $this->tag, $nodes, new Attributes( [Html5::ATTR_CLASS => 'filter-form'])); |
|
| 169 | - |
|
| 170 | - return sprintf( |
|
| 171 | - $this->template, |
|
| 172 | - (string)$this->hiderBtn, |
|
| 173 | - $form |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return Action |
|
| 179 | - */ |
|
| 180 | - public function getHiderBtn(): Action |
|
| 181 | - { |
|
| 182 | - return $this->hiderBtn; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Action |
|
| 187 | - */ |
|
| 188 | - public function getFilterBtn(): Action |
|
| 189 | - { |
|
| 190 | - return $this->filterBtn; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return Action |
|
| 195 | - */ |
|
| 196 | - public function getResetBtn(): Action |
|
| 197 | - { |
|
| 198 | - return $this->resetBtn; |
|
| 199 | - } |
|
| 200 | -} |
|
@@ -39,162 +39,3 @@ |
||
| 39 | 39 | * %2$s - nodes (filters) |
| 40 | 40 | */ |
| 41 | 41 | protected const DEFAULT_TEMPLATE = <<<'EOT' |
| 42 | - <div class="hidable"> |
|
| 43 | - <p class="hider">%1$s</p> |
|
| 44 | - <div class="hidee">%2$s</div> |
|
| 45 | - </div> |
|
| 46 | - EOT; |
|
| 47 | - |
|
| 48 | - protected string $template = self::DEFAULT_TEMPLATE; |
|
| 49 | - |
|
| 50 | - /** @var IFilter[] */ |
|
| 51 | - protected array $nodes = []; |
|
| 52 | - |
|
| 53 | - protected string $nodeClass = IFilter::class; |
|
| 54 | - |
|
| 55 | - protected Action $hiderBtn; |
|
| 56 | - |
|
| 57 | - protected Action $filterBtn; |
|
| 58 | - |
|
| 59 | - protected Action $resetBtn; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Filters constructor. |
|
| 63 | - * |
|
| 64 | - * @param string[] $intents |
|
| 65 | - * @param Attributes|null $attributes |
|
| 66 | - * @param string|null $tag |
|
| 67 | - */ |
|
| 68 | - public function __construct(array $intents = [], ?Attributes $attributes = null, ?string $tag = null) |
|
| 69 | - { |
|
| 70 | - parent::__construct(null, $intents, $attributes, $tag); |
|
| 71 | - |
|
| 72 | - $this->hiderBtn = new Action(static::BTN_CONTENT_FILTERS, [Action::INTENT_INFO]); |
|
| 73 | - $this->filterBtn = new Action(static::BTN_CONTENT_FILTER, [Action::INTENT_PRIMARY], static::ATTRIBUTES_SEARCH); |
|
| 74 | - $this->resetBtn = new Action(static::BTN_CONTENT_RESET, [Action::INTENT_SECONDARY], static::ATTRIBUTES_RESET); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param array $params |
|
| 79 | - * |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setParams(array $params): Filters |
|
| 83 | - { |
|
| 84 | - foreach ($this->nodes as $filter) { |
|
| 85 | - $filter->setParams($params); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $baseUrl |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getUrl(string $baseUrl): string |
|
| 97 | - { |
|
| 98 | - $queryParts = []; |
|
| 99 | - foreach ($this->nodes as $filter) { |
|
| 100 | - $queryPart = $filter->getQueryPart(); |
|
| 101 | - if (!$queryPart) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $queryParts[] = $queryPart; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (empty($queryParts)) { |
|
| 109 | - return $baseUrl; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return sprintf('%s%s&', $baseUrl, implode('&', $queryParts)); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getWhereConditions(): array |
|
| 119 | - { |
|
| 120 | - $conditions = []; |
|
| 121 | - foreach ($this->nodes as $filter) { |
|
| 122 | - $conditions = array_merge($conditions, $filter->getWhereConditions()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $conditions; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return array<string,string> |
|
| 130 | - */ |
|
| 131 | - public function getSqlParams(): array |
|
| 132 | - { |
|
| 133 | - $params = []; |
|
| 134 | - foreach ($this->nodes as $filter) { |
|
| 135 | - $params = array_merge($params, $filter->getQueryParams()); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $params; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return INode[] |
|
| 143 | - */ |
|
| 144 | - public function getExtendedNodes(): array |
|
| 145 | - { |
|
| 146 | - return array_merge([$this->hiderBtn, $this->filterBtn, $this->resetBtn], $this->getNodes()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $template |
|
| 151 | - * |
|
| 152 | - * @return INode |
|
| 153 | - */ |
|
| 154 | - public function setTemplate(string $template): INode |
|
| 155 | - { |
|
| 156 | - $this->template = $template; |
|
| 157 | - |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function __toString(): string |
|
| 165 | - { |
|
| 166 | - $nodes = Collection::__toString(); |
|
| 167 | - |
|
| 168 | - $form = sprintf(self::WITH_CONTENT_TAG, $this->tag, $nodes, new Attributes( [Html5::ATTR_CLASS => 'filter-form'])); |
|
| 169 | - |
|
| 170 | - return sprintf( |
|
| 171 | - $this->template, |
|
| 172 | - (string)$this->hiderBtn, |
|
| 173 | - $form |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return Action |
|
| 179 | - */ |
|
| 180 | - public function getHiderBtn(): Action |
|
| 181 | - { |
|
| 182 | - return $this->hiderBtn; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Action |
|
| 187 | - */ |
|
| 188 | - public function getFilterBtn(): Action |
|
| 189 | - { |
|
| 190 | - return $this->filterBtn; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return Action |
|
| 195 | - */ |
|
| 196 | - public function getResetBtn(): Action |
|
| 197 | - { |
|
| 198 | - return $this->resetBtn; |
|
| 199 | - } |
|
| 200 | -} |
|
@@ -39,162 +39,3 @@ |
||
| 39 | 39 | * %2$s - nodes (filters) |
| 40 | 40 | */ |
| 41 | 41 | protected const DEFAULT_TEMPLATE = <<<'EOT' |
| 42 | - <div class="hidable"> |
|
| 43 | - <p class="hider">%1$s</p> |
|
| 44 | - <div class="hidee">%2$s</div> |
|
| 45 | - </div> |
|
| 46 | - EOT; |
|
| 47 | - |
|
| 48 | - protected string $template = self::DEFAULT_TEMPLATE; |
|
| 49 | - |
|
| 50 | - /** @var IFilter[] */ |
|
| 51 | - protected array $nodes = []; |
|
| 52 | - |
|
| 53 | - protected string $nodeClass = IFilter::class; |
|
| 54 | - |
|
| 55 | - protected Action $hiderBtn; |
|
| 56 | - |
|
| 57 | - protected Action $filterBtn; |
|
| 58 | - |
|
| 59 | - protected Action $resetBtn; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Filters constructor. |
|
| 63 | - * |
|
| 64 | - * @param string[] $intents |
|
| 65 | - * @param Attributes|null $attributes |
|
| 66 | - * @param string|null $tag |
|
| 67 | - */ |
|
| 68 | - public function __construct(array $intents = [], ?Attributes $attributes = null, ?string $tag = null) |
|
| 69 | - { |
|
| 70 | - parent::__construct(null, $intents, $attributes, $tag); |
|
| 71 | - |
|
| 72 | - $this->hiderBtn = new Action(static::BTN_CONTENT_FILTERS, [Action::INTENT_INFO]); |
|
| 73 | - $this->filterBtn = new Action(static::BTN_CONTENT_FILTER, [Action::INTENT_PRIMARY], static::ATTRIBUTES_SEARCH); |
|
| 74 | - $this->resetBtn = new Action(static::BTN_CONTENT_RESET, [Action::INTENT_SECONDARY], static::ATTRIBUTES_RESET); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param array $params |
|
| 79 | - * |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setParams(array $params): Filters |
|
| 83 | - { |
|
| 84 | - foreach ($this->nodes as $filter) { |
|
| 85 | - $filter->setParams($params); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $baseUrl |
|
| 93 | - * |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getUrl(string $baseUrl): string |
|
| 97 | - { |
|
| 98 | - $queryParts = []; |
|
| 99 | - foreach ($this->nodes as $filter) { |
|
| 100 | - $queryPart = $filter->getQueryPart(); |
|
| 101 | - if (!$queryPart) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $queryParts[] = $queryPart; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (empty($queryParts)) { |
|
| 109 | - return $baseUrl; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return sprintf('%s%s&', $baseUrl, implode('&', $queryParts)); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getWhereConditions(): array |
|
| 119 | - { |
|
| 120 | - $conditions = []; |
|
| 121 | - foreach ($this->nodes as $filter) { |
|
| 122 | - $conditions = array_merge($conditions, $filter->getWhereConditions()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $conditions; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return array<string,string> |
|
| 130 | - */ |
|
| 131 | - public function getSqlParams(): array |
|
| 132 | - { |
|
| 133 | - $params = []; |
|
| 134 | - foreach ($this->nodes as $filter) { |
|
| 135 | - $params = array_merge($params, $filter->getQueryParams()); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $params; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return INode[] |
|
| 143 | - */ |
|
| 144 | - public function getExtendedNodes(): array |
|
| 145 | - { |
|
| 146 | - return array_merge([$this->hiderBtn, $this->filterBtn, $this->resetBtn], $this->getNodes()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $template |
|
| 151 | - * |
|
| 152 | - * @return INode |
|
| 153 | - */ |
|
| 154 | - public function setTemplate(string $template): INode |
|
| 155 | - { |
|
| 156 | - $this->template = $template; |
|
| 157 | - |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function __toString(): string |
|
| 165 | - { |
|
| 166 | - $nodes = Collection::__toString(); |
|
| 167 | - |
|
| 168 | - $form = sprintf(self::WITH_CONTENT_TAG, $this->tag, $nodes, new Attributes( [Html5::ATTR_CLASS => 'filter-form'])); |
|
| 169 | - |
|
| 170 | - return sprintf( |
|
| 171 | - $this->template, |
|
| 172 | - (string)$this->hiderBtn, |
|
| 173 | - $form |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return Action |
|
| 179 | - */ |
|
| 180 | - public function getHiderBtn(): Action |
|
| 181 | - { |
|
| 182 | - return $this->hiderBtn; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Action |
|
| 187 | - */ |
|
| 188 | - public function getFilterBtn(): Action |
|
| 189 | - { |
|
| 190 | - return $this->filterBtn; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return Action |
|
| 195 | - */ |
|
| 196 | - public function getResetBtn(): Action |
|
| 197 | - { |
|
| 198 | - return $this->resetBtn; |
|
| 199 | - } |
|
| 200 | -} |
|