Skip to content

Commit

Permalink
Fix template caching, allow app to be released (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Jan 5, 2023
1 parent 9041368 commit 5d1bf4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Atk4\Data\Model;
use Atk4\Ui\Exception;
use Atk4\Ui\Form;
use Atk4\Ui\Table;
use Mvorisek\Atk4\Hintable\Data\HintablePropertyDef;

try {
Expand Down Expand Up @@ -269,6 +270,7 @@ protected function init(): void
'type' => 'string',
'ui' => [
'form' => [Form\Control\Line::class],
'table' => [Table\Column\CountryFlag::class],
],
])
->addField($this->fieldName()->client_country, Country::hinting()->fieldName()->name);
Expand Down
8 changes: 7 additions & 1 deletion src/HtmlTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,13 @@ protected function parseTemplate(string $str): void
$this->tagTrees = [];
try {
$this->tagTrees[self::TOP_TAG] = $this->parseTemplateTree($inputReversed);
self::$_parseCache[$cKey] = $this->tagTrees;
$tagTrees = $this->tagTrees;
\Closure::bind(function () use ($tagTrees) {
foreach ($tagTrees as $tagTree) {
$tagTree->parentTemplate = null; // @phpstan-ignore-line
}
}, null, TagTree::class)();
self::$_parseCache[$cKey] = $tagTrees;
} finally {
$this->tagTrees = null; // @phpstan-ignore-line
}
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Column/CountryFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
class CountryFlag extends Table\Column
{
/** Name of country code model field (in ISO 3166-1 alpha-2 format) */
public string $codeField;
public ?string $codeField = null;

/** Optional name of model field which contains full country name. */
public ?string $nameField = null;

public function getHtmlTags(Model $row, ?Field $field): array
{
$countryCode = $row->get($this->codeField);
$countryCode = $row->get($this->codeField ?? $field->shortName);
$countryName = $this->nameField ? $row->get($this->nameField) : null;

return [
Expand Down

0 comments on commit 5d1bf4c

Please sign in to comment.