Miscellaneous Flashcards

(40 cards)

1
Q

Which PSR does Cache-Component follow?

A

PSR-6 & PSR-16

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which interfaces/classes does the PSR-6 Cache-Component include?

A
  • CacheException
  • CacheItemInterface
  • CacheItemPoolInterface
  • InvalidArgumentException
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How will a value be set for a cache-item?

A

Within the method “get”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How will a value be selected for a cache-item?

A

Within the method “get”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is stampede protection?

A

Protecting cold cache from being written by multiple clients at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 2 ways of symfony’s stampede protection?

A
  1. lock
  2. refresh before expiring
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Whats the difference between PSR-6 and PSR-16?

A

PSR-16 is the simplified and more performant way of caching, while PSR-6 allows more complex possibilities for caching (e.g. getItem, getDeferred etc.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which Interfaces / Classes do the cache-contracts (PSR-16) include?

A
  • CacheInterface
  • ItemInterface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are ways to react on events?

A

EventSubscriber
EventListener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which interfaces / classes are part of the event-dispatcher component?

A
  • EventDispatcherInterface (to dispatch the event)
  • EventSubscriberInterface
  • Event
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which PSR defines the event-dispatcher component?

A

PSR-14
https://www.php-fig.org/psr/psr-14/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which method is implemented in the EventSubscriberInterface?

A

::getSubscribedEvents()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are ways to make an EventListener to listen to an Event?

A

EventListener
Registering with ->addEventListener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to add priority to an Event-listener / -subscriber?

A

with the parameter $priority

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you make sure the DI-Container is configured in a valid way?

A
php bin/console lint:container
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are 2 ways to access services lazily from the DI-Container instead of using autowiring?

A
  • service locator
  • public service (not best practice)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How and where can global parameters be configured?

A

In the services.yaml / services.php in the section “parameters:”

parameters:
    app.admin_email:'something@example.com'
18
Q

How can globally configured parameters be used in other configuration files?

A

config/packages/some_package.yaml

some_package:
    # any string surrounded by two % is replaced by that parameter value
    email_address: '%app.admin_email%'
19
Q

Where are additional packages being configured?

A
your-project/
├─ config/
│  ├─ packages/
20
Q

Where can the service container be configured?

A
your-project/
├─ config/
│  └─ services.yaml
21
Q

Where can routes be configured?

A
your-project/
├─ config/
│  ├─ routes.yaml
22
Q

Which configuration formats does symfony support?

23
Q

How is the current environment defined in symfony?

A

Via the “APP_ENV” variable in the current .env

24
Q

How can you store and show custom data inside the toolbar?

A

Create an own datacollector by using the DataCollectorInterface

25
How does tag-based cache invalidation work?
When getting a cache-item, tags can be added in its responsible callback. E.g: ``` $item = $cache->get('cache_key', function (ItemInterface $item): string { // add one or more tags $item->tag('tag_1'); $item->tag(['tag_2', 'tag_3']); return $cachedValue; }); ``` The cache can then be invalidated via the tag: ```$cache->invalidateTags(['tag_1', 'tag_3']);``` Alternatively, of course you can still delete the item via its cache-key: ```$cache->delete('cache_key');``` To be able to store tags, you need to use a TagAwareAdapter, for example like this: ``` use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter; $cache = new TagAwareAdapter( // Adapter for cached items new FilesystemAdapter(), // Adapter for tags new RedisAdapter('redis://localhost') ); ``` In this example, the tags are saved in redis, but the actual cache items in the FileSystem.
26
Which cache invalidation methods are possible?
- tag-based invalidation - by expiration
27
How can you lint an expression of the expression language?
``` $expressionLanguage = new ExpressionLanguage(); // does not throw a SyntaxError because the unknown variables and functions are ignored $expressionLanguage->lint('1 + 2', [])```
28
How can you ignore errors when linting an expression of the expression language?
``` $expressionLanguage = new ExpressionLanguage(); // does not throw a SyntaxError because the unknown variables and functions are ignored $expressionLanguage->lint('unknown_var + unknown_function()', [], Parser::IGNORE_UNKNOWN_VARIABLES | Parser::IGNORE_UNKNOWN_FUNCTIONS); ```
29
How can you provide a configured cache to the expression language?
``` $cache = new RedisAdapter(...); $expressionLanguage = new ExpressionLanguage($cache); ```
30
How do you escape a backslash in expression language in a string?
With 3 leading backslashes
31
How do you escape a backslash in expression language in a regex?
With 7 leading backslashes
32
Whats the difference between the method mustRun() and run() in the process component?
mustRun() throws an exception if an error happens
33
How can you start running a process asynchronously?
```$process->start()```
34
How can you check if a process is still running?
```$process->isRunning()```
35
How can you stop at a specific line of code until the process is finished?
```$process->wait()```
36
How can you wait for a process to fulfill a specific condition?
``` $process->waitUntil(function ($type, $output): bool { return $output === 'Ready. Waiting for commands...'; }); ```
37
How can you stop a running process?
``` $process->stop() ```
38
Whats the default timeout of a process?
60 seconds
39
How can you set the following: 1. the overall timeout for a process 2. the timeout for a process for being idle (not outputting anything)
``` $process->setTimeout(3600); $process->setIdleTimeout(60); $process->run(); ```
40
How can you serialize objects inside twig?
```{{ person|serialize(format = 'json') }}```