Skip to content

Commit

Permalink
[general] Use global date provider for doctrine timestampable (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 29, 2024
1 parent 25360b5 commit ea6869e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
8 changes: 8 additions & 0 deletions src/DI/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/UI/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @copyright https://www.fastybird.com
* @author Adam Kadlec <adam.kadlec@fastybird.com>
* @package FastyBird:ApplicationLibrary!
* @subpackage Caching
* @subpackage UI
* @since 1.0.0
*
* @date 08.03.20
Expand Down
54 changes: 54 additions & 0 deletions src/Utilities/DateTimeProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types = 1);

/**
* TemplateFactory.php
*
* @license More in LICENSE.md
* @copyright https://www.fastybird.com
* @author Adam Kadlec <adam.kadlec@fastybird.com>
* @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 <adam.kadlec@fastybird.com>
*/
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();
}

}

0 comments on commit ea6869e

Please sign in to comment.