8000 Add more nullsafe operators by nicolas-grekas · Pull Request #44659 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add more nullsafe operators #44659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ee211c4
[VarDumper] add more "transient-on-macos" groups
nicolas-grekas Dec 15, 2021
6617be4
[HttpKernel] fix how configuring log-level and status-code by excepti…
nicolas-grekas Dec 15, 2021
6bcc3cb
Revert "feature #41989 [Cache] make `LockRegistry` use semaphores whe…
nicolas-grekas Dec 16, 2021
b968514
[Cache] disable lock on CLI
nicolas-grekas Dec 16, 2021
06b25c7
[HttpClient] Fix tracing requests made after calling withOptions()
nicolas-grekas Dec 16, 2021
981cb0c
Remove pointless assignment
derrabus Dec 16, 2021
6312ef2
minor #44674 [Messenger] Remove pointless assignment (derrabus)
nicolas-grekas Dec 16, 2021
d737dab
fix merge
nicolas-grekas Dec 16, 2021
6e3b711
CS fixes
nicolas-grekas Dec 16, 2021
f1914c0
minor #44679 CS fixes (nicolas-grekas)
nicolas-grekas Dec 16, 2021
311dc83
bug #44669 [Cache] disable lock on CLI (nicolas-grekas)
nicolas-grekas Dec 16, 2021
0812726
[Cache] Fix saving items with no expiration through ProxyAdapter
sbelyshkin Dec 12, 2021
aaa18df
bug #44577 [Cache] Fix proxy no expiration to the Redis (Sergey Belys…
nicolas-grekas Dec 16, 2021
7e26952
Merge branch '4.4' into 5.3
nicolas-grekas Dec 16, 2021
ad3010b
[5.3] cs fixes
nicolas-grekas Dec 16, 2021
f190e9e
bug #44671 [HttpClient] Fix tracing requests made after calling withO…
nicolas-grekas Dec 16, 2021
61be138
Merge branch '5.3' into 5.4
nicolas-grekas Dec 16, 2021
b6d4480
[5.4] cs fixes
nicolas-grekas Dec 16, 2021
eb60956
bug #44667 [Cache] Revert "feature #41989 make `LockRegistry` use se…
nicolas-grekas Dec 16, 2021
646c33f
bug #44649 [HttpKernel] fix how configuring log-level and status-code…
nicolas-grekas Dec 16, 2021
eb749ec
Merge branch '5.4' into 6.0
nicolas-grekas Dec 16, 2021
d5534b0
[6.0] cs fixes
nicolas-grekas Dec 16, 2021
5eb8777
Merge branch '6.0' into 6.1
nicolas-grekas Dec 16, 2021
56f908a
Add more nullsafe operators
nicolas-grekas Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\LockRegistry;
use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter;

/**
Expand Down Expand Up @@ -198,24 +196,6 @@ public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags
$this->assertFalse($item->isHit());
}

public function testLog()
{
$lockFiles = LockRegistry::setFiles([__FILE__]);

$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->atLeastOnce())
->method($this->anything());

$cache = new TagAwareAdapter(new ArrayAdapter());
$cache->setLogger($logger);

// Computing will produce at least one log
$cache->get('foo', static function (): string { return 'ccc'; });

LockRegistry::setFiles($lockFiles);
}

/**
* @return MockObject&PruneableCacheInterface
*/
Expand Down
16 changes: 14 additions & 2 deletions src/Symfony/Component/Cache/Traits/ContractsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ContractsTrait
doGet as private contractsGet;
}

private $callbackWrapper = [LockRegistry::class, 'compute'];
private $callbackWrapper;
private $computing = [];

/**
Expand All @@ -41,8 +41,16 @@ trait ContractsTrait
*/
public function setCallbackWrapper(?callable $callbackWrapper): callable
{
if (!isset($this->callbackWrapper)) {
$this->callbackWrapper = \Closure::fromCallable([LockRegistry::class, 'compute']);

if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$this->setCallbackWrapper(null);
}
}

$previousWrapper = $this->callbackWrapper;
$this->callbackWrapper = $callbackWrapper ?? function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) {
$this->callbackWrapper = $callbackWrapper ?? static function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata, ?LoggerInterface $logger) {
return $callback($item, $save);
};

Expand Down Expand Up @@ -82,6 +90,10 @@ static function (CacheItem $item, float $startTime, ?array &$metadata) {
$this->computing[$key] = $key;
$startTime = microtime(true);

if (!isset($this->callbackWrapper)) {
$this->setCallbackWrapper($this->setCallbackWrapper(null));
}

try {
$value = ($this->callbackWrapper)($callback, $item, $save, $pool, function (CacheItem $item) use ($setMetadata, $startTime, &$metadata) {
$setMetadata($item, $startTime, $metadata);
Expand Down
0