diff --git a/composer.json b/composer.json index 7e1875f..824322a 100644 --- a/composer.json +++ b/composer.json @@ -38,8 +38,10 @@ "contributte/monolog": "^0.5", "cweagans/composer-patches": "^1.7", "doctrine/orm": "2.15.*", + "fastybird/datetime-factory": "^0.6", "fastybird/metadata-library": "dev-main", "fastybird/simple-auth": "^0.14", + "ipub/doctrine-timestampable": "^2.0", "nette/bootstrap": "^3.1", "nette/application": "^3.1", "nette/di": "^3.0", diff --git a/config/common.neon b/config/common.neon index 0f08599..83c081c 100644 --- a/config/common.neon +++ b/config/common.neon @@ -21,6 +21,7 @@ extensions: # contributteCacheDebug : Contributte\Cache\DI\DebugStorageExtension orisaiObjectMapper : OriNette\ObjectMapper\DI\ObjectMapperExtension fbApplicationLibrary : FastyBird\Library\Application\DI\ApplicationExtension + fbDateTimeFactory : FastyBird\DateTimeFactory\DI\DateTimeFactoryExtension ################################## # Nette extensions configuration # diff --git a/src/DI/ApplicationExtension.php b/src/DI/ApplicationExtension.php index fc5a276..c250aba 100644 --- a/src/DI/ApplicationExtension.php +++ b/src/DI/ApplicationExtension.php @@ -21,6 +21,7 @@ use FastyBird\Library\Application\Router; use FastyBird\Library\Application\Subscribers; use FastyBird\Library\Application\UI; +use FastyBird\Library\Application\Utilities; use Monolog; use Nette; use Nette\Bootstrap; @@ -236,6 +237,13 @@ public function loadConfiguration(): void $builder->addDefinition($this->prefix('ui.routes'), new DI\Definitions\ServiceDefinition()) ->setType(Router\AppRouter::class); + + /** + * Utilities + */ + + $builder->addDefinition($this->prefix('utilities.doctrineDateProvider'), new DI\Definitions\ServiceDefinition()) + ->setType(Utilities\DateTimeProvider::class); } /** diff --git a/src/UI/TemplateFactory.php b/src/UI/TemplateFactory.php index 5bdd8f6..a5c7816 100644 --- a/src/UI/TemplateFactory.php +++ b/src/UI/TemplateFactory.php @@ -7,7 +7,7 @@ * @copyright https://www.fastybird.com * @author Adam Kadlec * @package FastyBird:ApplicationLibrary! - * @subpackage Caching + * @subpackage UI * @since 1.0.0 * * @date 08.03.20 diff --git a/src/Utilities/DateTimeProvider.php b/src/Utilities/DateTimeProvider.php new file mode 100644 index 0000000..7939005 --- /dev/null +++ b/src/Utilities/DateTimeProvider.php @@ -0,0 +1,54 @@ + + * @package FastyBird:ApplicationLibrary! + * @subpackage Utilities + * @since 1.0.0 + * + * @date 29.08.24 + */ + +namespace FastyBird\Library\Application\Utilities; + +use DateTimeInterface; +use FastyBird\DateTimeFactory; +use IPub\DoctrineTimestampable\Providers as DoctrineTimestampableProviders; +use Nette\DI; + +/** + * Date provider for doctrine timestampable + * + * @package FastyBird:ApplicationLibrary! + * @subpackage Subscribers + * + * @author Adam Kadlec + */ +readonly class DateTimeProvider implements DoctrineTimestampableProviders\DateProvider +{ + + public function __construct(private DI\Container $container) + { + } + + /** + * @throws DI\MissingServiceException + */ + public function getDate(): DateTimeInterface + { + return $this->container->getByType(DateTimeFactory\Factory::class)->getNow(); + } + + /** + * @throws DI\MissingServiceException + */ + public function getTimestamp(): int + { + return $this->container->getByType(DateTimeFactory\Factory::class)->getNow()->getTimestamp(); + } + +}