Event Hooks
…
And this means that we can use standard Symfony event subscribers to totally kick
EasyAdminBundle's butt!
Create a new Event directory... though, this could live anywhere. Then, how about,
EasyAdminSubscriber. Event subscribers always implement EventSubscriberInterface:
I'll go to the "Code"->"Generate" menu…
Configuring the Encoder in security.yml
…me how you want to encode the passwords. I can't
read your mind - I'm just a PHP framework.
Remember how I kept saying we would encrypt the passwords with bcrypt? Do you remember
actually configuring that anywhere? Nope! We need to do that.…
The Drupal Console & Route Cache
…in your terminal. Next, move
it into a global bin directory so that you can simply type drupal from anywhere
in the terminal:
Hello Drupal Console! Now try drupal list:
This shows a huge list of all of the commands you can run. There is…
Keeping Problem types Consistent
…t want to mess up the title. Heck, I don't even
want to have to write the title anywhere - can't it be guessed based on the type?
I think so - let's just create a map from the type, to its associated title…
An Aside: Dependency Injection Parameters
…server can have their own. So we set parameters
here and use them anywhere else.
Adding More Parameters¶
But technically, we can add parameters to any configuration file. Go back
to config.yml and add a new parameters key anywhere in the file. Below
it…
Restricting Edit Access to Owners
…we’ll just deny access. And remember, you can deny
access anywhere in your app just by throwing the special AccessDeniedException.
Since we’ll need the same security logic in editAction, updateAction
and deleteAction, let’s create a private function called enforceOwnerSecurity
that holds it…
Functional Testing
…app/ directory.
And hey! There’s a phpunit.xml.dist file there already for it to read. This
tells phpunit how to bootstrap and where to find our tests.
But we see a few errors. If you look closely, you’ll see that it’s…
Custom Block View
…definition. Then we're going to map that to a template via block_views.
For step 1, open our netgen_layouts.yaml file and, really anywhere, add
block_definitions. This config can be used to create totally new blocks or
change options on existing blocks…
Contentful: Loading Data from an External CMS
…what we're doing, it's a pretty quick process and would give us a
lot of power on our site.
But one of the beautiful things about Layouts is that our value types can come from
anywhere: a Doctrine Entity, data on an external…
Processing Streams by Hand for Fun & Profit
…then
the HTML is passed to the Turbo Stream system... and it works its magic. But in
theory, you could grab some Turbo Stream HTML from anywhere and tell the Stream
system to process it. And... it's kind of fun!
Head to the homepage…
Exception Handling
…about the unhappy path. Well, our
entire application is wrapped in this try-catch block. So, if an exception
is thrown from anywhere, this will catch it. The $catch argument is true
by default, so we're not going to hit this finishRequest() line. Nope…
Custom Transport Serializer
…your transport. Creating a custom serializer
is... actually a very pleasant experience.
Inside of our src/Messenger/ directory... though this class could live anywhere..
let's create a new PHP class called ExternalJsonMessengerSerializer. The only
rule is that this needs to implement SerializerInterface. But, careful…
Registering & Autoloading a Custom Matcher
…reuse them across multiple spec
files - that's a bummer. Fortunately, phpspec is awesome and so - of course - it does
have a way to create a matcher that can be used anywhere. And... what's
even better is that there are a lot of great…
RAD with Symfony 3.3
…the goal: create an event listener that adds a header to every response.
Step 1: create an EventSubscriber directory - though this could live anywhere -
and a file inside called AddNiceHeaderEventSubscriber:
Event subscribers always look the same: they must implement EventSubscriberInterface:
I'll go to the…
Making all Services Private
…making this change is safe! We just created all of these service ids
a minute ago and they're not being used anywhere yet, definitely not with $container->get().
The exception is the last two services: we might be fetching these services directly
from the…
Array, Set and ES2016
…loads, we call loadRepLogs():
This fetches an array of repLog data via AJAX and then calls _addRow() on each
to add the
elements to the table.
But once we add the table rows... we don't actually store those repLog objects
anywhere. Yep, we…
The Clever Criteria System
…this with a Criteria,
say addCriteria(self::createExpensiveCriteria()). Now that we're in a QueryBuilder,
we can do the normal stuff, like setMaxResults($limit). Want to do an orderBy
or an andWhere? Go for it. And of course, you can finish this with
getQuery()->getResult():…
Adding a Search + the Request Object
…QueryBuilder for now.
Now for the magic. If we have a search, add an andWhere() that checks if
the lower case name of our Starship part is like our search. I know it looks
a bit funky, but that's because PostgreSQL is case-sensitive…
The QueryBuilder
…That is exactly what we wrote before! So, no surprise,
if we remove that dd() and refresh... we're back to working! It's just that easy.
Okay, we have the QueryBuilder basics down. Let's get more complex by adding
andWhere() and orWhere() next.
Custom Queries
…t need any arguments, and I'm going to simplify a bit. Let's
say andWhere('a.publishedAt IS NOT NULL'):
You can totally see how close this is to normal SQL. You can even put OR statements
inside the string, like a.publishedAt IS…
x
513
Whoops, an error! Please, try again later.