Centralizing Upload Logic
…code somewhere else:
in the new() action.
That's why I like to isolate my upload logic into a service class. In the Service/
directory - or really anywhere - create a new class: how about UploaderHelper?
This class will handle all things related to uploading files…
Container to the Rescue
…the only code we
need to touch outside of BattleManager is right here inside Container.
We don't need to go anywhere else - like battle.php - and change anything.
We just say $container->getBattleManager() and the Container class will
take care of all of the…
Making an Argument Available to All Controllers
…it’s so important, that we want to be able to
have an $isMac argument in any controller function anywhere in the
system. This won’t come from a routing wildcard like normal - we’ll figure
this out by reading the User-Agent.
As an…
Symfony Magic: Replace the _controller
…without borders
or boundaries. Let’s prove it.
We know that Symfony reads the _controller key in the request attributes
and executes that as the controller. This is set by the RouterListener
but it could be set anywhere.
Let’s go adventuring!. UserAgentSubscriber listens to…
Redirecting the Full Page from a Frame
…you
want to navigate the entire window to a confirmation page.
So let's make our frame-redirecting system something that we can use anywhere.
Here's the plan: if a turbo-frame - like the turbo-frame in _modal.html.twig -
has a data-turbo…
Globally Disable Buttons on Form Submit
…form on our site by leveraging an event that Turbo dispatches.
In your editor, open up assets/turbo/turbo-helper.js. Anywhere in the constructor,
listen to a new event: document.addEventListener('turbo:submit-start'). Pass this
an arrow function with an event argument. Inside…
Ajax-Powered HTML Updates & a CSS Transition
…item element also has a removing class, change the
opacity to zero. Thanks to the transition, that change will happen gradually.
And where does this removing class come from? Good question! We are going
to add it.
Back in the controller, right at the beginning…
Storing Private Files
…Open the
config/packages/oneup_flysystem.yaml file. Copy the public_uploads_adapter, paste
and call it private_uploads_adapter. You can store the files anywhere, as long
as it's not in public/. But, the var/ directory is sort of meant for this type…
Using Objects and Array Keys
…print the title, just
say pageData.title. To print the summary, use the same trick!
This can be used anywhere, like in an if statement in exactly the same way:
So if you ever need data from an array, the . operator is your answer!
The…
Setting the UUID on POST
…be ignored.
How can I be so sure? Well, look at the User class: $uuid is not settable
anywhere. It's not an argument to the constructor and there's no setUuid()
method:
Time to change that!
Let's describe the behavior we want in…
Completely Custom Resource
…really, an API resource can be any object that pulls data from... anywhere!
So instead of adding un-persisted $isMe and $isMvp fields to User:
We could have created a totally different non-entity class - like UserApiResource - with
exactly the fields in our API.
And…
Data Persister Decoration
…that object. Usually, this means that we're saving an entity
object to the database via Doctrine. But we could "save" an object anywhere, like
by sending the data to another API, or putting it into Redis or ElasticSearch.
ApiPlatform doesn't really care. These…
Microservices Gone Wrong
…it.
How we built it. Where we ran into significant trouble, and where everything
worked well. And this is my puppy Adda who's going to help me on some of these
transitionary slides.
So let's jump into the background. I walked in to…
Back to the Basics (Symfony local Web Server)
…logs, especially for the production environments
and there's some kind of a problem I need to debug the problem, it's kind of
hard to figure out where the problem is and where you got your exception. So
here we make it very clear…
Fetching the User In a Service
…built a long time
ago, like 3 screencasts ago. Click on any article. Then, click anywhere on the
web debug toolbar to open the profiler. Find the "Logs" section and click on
"Info & Errors". There it is!
They are talking about bacon again!
This is…
Customizing Errors & Logout
…use usernames!? That's... confusing.
There are two ways to control these error messages. The first is by throwing
a very special exception class from anywhere in your authenticator. It's called
CustomUserMessageAuthenticationException. When you do this, you can create your
own message. We'll…
Bonus! LoggerTrait & Setter Injection
…take that code and move it into
its own service class.
Since this is such an important skill, let's do it: in the Service/ directory -
though we could put this anywhere - create a new class: SlackClient:
Give it a public function called, how about…
Symfony 4: Let's Launch!
…excited. Why? Because nothing
makes me happier than sitting down to work inside a framework where coding is actually
fun, and where I can build features fast, but without sacrificing quality. Well,
maybe I'd be even happier doing all of that on a beach..…
Clearing the Database
…In a Symfony 4 Flex application, you
should create a config/packages/test/doctrine.yaml file since this will contain
Doctrine configuration that you only want to use in the test environment.
Inside, anywhere, add doctrine, dbal then url set to
sqlite:///%kernel.project_dir…
x
513