1<?php
2
3
4namespace ComboStrap;
5
6
7use ComboStrap\Meta\Api\Metadata;
8use ComboStrap\Meta\Api\MetadataWikiPath;
9use DateTime;
10
11/**
12
13 * @package ComboStrap
14 * Represents the wiki path of the page resource
15 */
16class PagePath extends MetadataWikiPath
17{
18
19
20
21    public const PROPERTY_NAME = "path";
22
23
24
25    public static function createForPage(ResourceCombo $page): CacheExpirationDate
26    {
27        return (new CacheExpirationDate())
28            ->setResource($page);
29    }
30
31
32    /**
33     * We build to be able to send the value elsewhere
34     * @param $value
35     * @return Metadata
36     */
37    public function setFromStoreValueWithoutException($value): Metadata
38    {
39        try {
40            $value = $this->getResource()->getPathObject()->toWikiPath();
41        } catch (ExceptionCast $e) {
42            $message = "This error should not happen as this is a wiki path";
43            LogUtility::internalError($message);
44            $value = null;
45        }
46        return parent::setFromStoreValueWithoutException($value);
47    }
48
49
50    static public function getName(): string
51    {
52        return self::PROPERTY_NAME;
53    }
54
55
56    public static function getPersistenceType(): string
57    {
58        return Metadata::DERIVED_METADATA;
59    }
60
61
62    public static function getTab(): string
63    {
64        return MetaManagerForm::TAB_REDIRECTION_VALUE;
65    }
66
67    public static function getDescription(): string
68    {
69        return "The path of the page on the file system (in wiki format with the colon `:` as path separator)";
70    }
71
72    public static function getLabel(): string
73    {
74        return "Page Path";
75    }
76
77    public static function isMutable(): bool
78    {
79        return false;
80    }
81
82    public static function getCanonical(): string
83    {
84        return self::PROPERTY_NAME;
85    }
86
87
88    public static function getDrive(): string
89    {
90        return WikiPath::MARKUP_DRIVE;
91    }
92
93    public static function isOnForm(): bool
94    {
95        return true;
96    }
97}
98