Notes from SymfonyOnline June 2023 - day 2
Keynote: The Scheduler Component - Nicolas Grekas
- SF is developed 7 merges per day on avg
$path ??= '/'
(assign/
value to$path
only if itsnull
, docs)- SF uses
both phpstan and psalmpsalm, about phpstan - not sure (type annotations are similar in both tools) - ossf/scorecard
- new components: Scheduler, AsserMapper, RemoteEvent, Webhook
- Fabien's presentations on speakerdeck.com
- selected features / goodies:
#[MapQueryParameter]
(map?page=2
to action arg)#[MapRequestPayload]
(map request body to DTO)- domain exception to response status code:
#[WithHttpStatus]
#[PasswordStrength]
Clear-Site-Data: cookies
#[AsAlias]
- if you have many impls of interface, allows to decide which one to inject- lazy proxies (services) out of the box (!)
Asynchronous juggling with Symfony HttpClient - Allison Guilhem
- example of:
- how to transclude/aggregate response data of many HTTP requests "behind" only one - to start fetching sooner for perf needs
- you can start HTTP requests even before receiving full response from previous one
- fetching multiple pages of data in parallel but on the surface initiating only one (for performance gains)
- SF HTTP client is flexible in async mode: allows for custom chunk (stream) processing logic:
- dip your toes: AsyncDecoratorTrait
- but more flexible:
<custom-generator> / callable
+ AsyncContext + AsyncResponse
- halaxa/json-machine - process raw json data without full JSON decoding
Decouple Your Apps with Symfony Messenger - Alexander M. Turek
- what people do - serialize message as json and write message consumer / worker in different language
- postgresql listen query is made every 1 or few secs just to keep connection alive
- mysql transport polls db when waiting for messages - not recommended
- remote event - all about sending events to external systems using messenger
Design your API for the future - Titouan Galopin
- selency: transition microservice to monolith architecture
- how ensure api is reliable while adding new features, api is a contract with your users
- designing api is similar to designing reusable PHP library
- characteristics of good API:
- be stable across time
- provide migration paths
- communicate to consumers
- decouple input/output from your internals
- say no to automatic serialization, use DTOs, transform from/to them manually
- fractal.thephpleague.com
- keep your input DTOs loose / flexible / no type hints or mixed at most / keep fields public
- what matters in input DTOs: field names, validation attributes - prefer validation errors for type errors
- usage of
#[MapRequestPayload]
- use readonly classes for DTOs
- versioning techniques:
- in host name (subdomain)
- path prefix
- HTTP header:
Accept: application/vnd.selency.v1+json
- migration path:
- i'm on v1 and want to get v2 - as API consumer how can I learn what I have to do to upgrade?
- first deprecate, then on next major: break BC
- selency/openapi
- different approach of defining OpenAPI schema (different from Api Platform)
- it does not use Entities but open/input schemas defined in PHP code
- DTOs vs transformer
- DTO - stores data and does not have behavior
- transformer - is like serializer but with manual control - takes care of subresources linking, value conversions
- deprecations of whole endpoint - can be communicated as Sunset HTTP header
DDD (Debugger Driven Development) - Carlos Granados
- ray - paid tool remote dump on steroids
- fastdebug - side project, new tool, optimized just for debugging (xdebug does more)
- xdebug - still awesome, lookup XDEBUG_MODE=trigger
Working with Pull Requests - Malte Wunsch
- try to make process fast
- code ages better than comments
- PR description: what, why - skip how (code tells how)
- as reviewer:
- skip gatekeeping for perfection
- improve by one grade, do not overwhelm feedback
- principles, code examples, precise links
- nonviolent communication book
- Alexandra Hill (article, video, video)
- as the author:
- reply to all comments (even with just emoji, before the actual re-work)
- if you got question - think if code could be clearer (code should be self-explainable)
- use looking emoji - sign that comment was read by you and you are looking into it
- if in doubt, ask reviewer:
- what would help?
- can you be more specific?
- explicitly call for next round
- remember to say thanks
- give benefit of a doubt to reviewer (you will be reading code more times than writing it, reviewer is better reader)
Modern UIs with UX, a little JS & Zero Node - Ryan Weaver
- browser is your new build system :) (finally!)
- Asset Mapper component / tool:
- versioned filenames
- using / importing 3rd party package
- actually generating importmap in HTML
/asset
logical path - non public path, converted to public and versioned path- in dev: internal SF listener serves files from
/asset
(non-public) path - in prod: files are dumped to public asset path by
asset-map:compile
command - no npm, no node_modules, no nothing
- js:
asset-map:require
adds packages toimportmap.php
- js:
asset-map:require <package> --download
(downloads to/assets/vendor
) - css:
url(<logical-path>)
works - use paths relative to/assets
logical path asset-map:require
does not work for CSS packages- SASS/TS/etc works by using their dedicated cli tools - see docs
- no minification and combining files anymore - and it's on purpose
- 30 days of hotwire - twitter
- live components - still experimental, communication between components:
emit()
- lookup invoice creator demo - complex example of using live components
- to avoid need of treeshaking - import specific parts of libraries in JS:
lodash/some-specific-submodule