Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Liam Hammett:
Laravel Blade Helpers
Dec 04, 2018 @ 15:20:36

Liam Hammett has written up a post to his site covering the use and creation of helpers for Laravel's Blade templating. He shows the use of a package he's created to help make using them with custom callbacks simpler.

Laravel’s Blade templating engine offers a ton of convenient directives you can use to make your view files beautiful and abstract anything that may be too complex or verbose to live inside HTML. It even gives a really handy way to add your own custom directives using the Blade::directive(…) method.

However, the callback in custom directives only receives a single parameter?—?the raw string expression from the view file. [...] As this seems to be the most common use case, I put together a package that attempts to help make these helper functions that little bit easier to define without the boilerplate of returning the string or having to consider what an expression may be when creating a directive.

In his package he introduces a new method that defines the name of the method and the name of the function to call. This second option can also be a custom callback function, making it even more flexible.

tagged: laravel blade template helper package custom callback tutorial

Link: https://medium.com/@liamhammett/laravel-blade-helpers-8d710fa31fd9

Laravel News:
Factory Callbacks and Closure-Based Guards in Laravel
Jun 12, 2018 @ 15:40:36

On the Laravel News site, there's an article posted covering the use of factory callbacks and closures in guards in Laravel. This feature was snuck into a recent release and allows you to provide a bit more dynamic functionality to your models and guards.

Two undocumented (before today anyhow) features were recently added to the Laravel 5.6 documentation, and they are both fantastic!

The post details each of the two new additions starting with the factory callbacks allowing you to perform additional tasks when a model is made or created (code examples included). The guard changes allowing closures and the Auth::viaRequest method to define new guard drivers.

tagged: factory callback model closure guard laravel

Link: https://laravel-news.com/factory-callbacks-closure-based-guards

Laravel News:
Inbound Email in Laravel
Aug 15, 2017 @ 16:39:02

The Laravel News site has posted a tutorial showing you how to handle inbound email using the framework and Mailgun's inbound routing feature (essentially webhooks)

I recently needed the ability to receive emails and process attachments on those emails. I love Mailgun for the sending of transactional email, so when I needed to process incoming mail I started digging into Mailgun closer and realized their powerful inbound routing email features!

Come along and learn how you can set up a webhook to process inbound email and secure it within your Laravel applications. We will even use Laravel Valet (or ngrok directly) to test it out locally!

They start by talking about inbound routing: what it is and how it works using a request back from the Mailgun service. They briefly walk you through the setup of a Mailgun account and your DNS to use it for mail service. Next they create a new Laravel project, configure it for email with Mailgun and create the hook the webhook from Mailgun will reach back out to. They use Valet to share it via ngrok and configure the Mailgun account with the resulting URL. The post finishes up showing how to secure the webook via validation middleware and how to test it. They also share a few tips you can potentially use in the controller like using jobs for response handling and working with files.

tagged: tutorial inbound email laravel mailgun webhook callback

Link: https://laravel-news.com/laravel-inbound-email

TutsPlus.com:
Using the Mailgun Store(): A Temporary Mailbox for Your App's Incoming Email
Jun 06, 2016 @ 17:22:39

The TutsPlus.com site has posted a tutorial today showing you how to use the "Store" functionality in Mailgun from your PHP application to temporarily handle your incoming emails.

In today's episode, Mailgun stepped in to sponsor a tutorial about how I integrated its message routing and Store() API to handle replies from users.

For example, when people receive meeting requests from others with Meeting Planner, they may just choose to reply and send a note like they would to a typical email thread. [...] Sounds complicated, but one of Meeting Planner's goals is to reduce the back and forth emails between people about planning and consolidate real-time changes into fewer notifications.

The start by introducing the Mailgun service and, more specifically, the Store() offering it provides. He uses a Yii2 framework based application to show the integration. Once the MX (mail) records are set up correctly it can then hook back in to your mail servers or web application. The code is included to make the migration to hold the notification info, make the POST request back to the application and use background process to handle the mail processing.

tagged: mailgun tutorial store incoming processing temporary callback yii2 example

Link: http://code.tutsplus.com/tutorials/using-the-mailgun-store-a-temporary-mailbox-for-your-apps-incoming-email--cms-26479

SitePoint PHP Blog:
Handle Incoming Email with SendGrid
Aug 27, 2013 @ 15:30:34

On the SitePoint PHP blog today Lukas White has a new tutorial showing you how to handle incoming emails from SendGrid (well, pulled from SendGrid) and translate them into posts for your blog or site.

In this article, I’m going to look at how you might implement an email-to-post feature, using SendGrid. SendGrid is a service for sending email – usually in bulk, but they also offer a less well-publicized feature for handling incoming email. SendGrid can be configured to handle all incoming messages for a given domain by pinging a URI of your choosing, and by implementing a simple webhook, you can act on the incoming mail accordingly.

He bases the simple example off of the Slim framework, creating a structure with a basic database for users and posts. He then goes through the SendGrid interface, pointing out where you add the hostname and URL to call back when a new email comes in. He includes the code to create the callback functionality that accepts the POST request coming from SendGrid. This is then validated and inserted into the database to be pulled out later by the "posts" page. There's also a bit about saving images (or other files) that come in as attachments to the email.

tagged: incoming email sendgrid callback post tutorial image attachment

Link: http://www.sitepoint.com/handle-incoming-email-with-sendgrid/

Setfive.com:
PHP: Some thoughts on using array_* with closures
Mar 19, 2013 @ 15:36:22

On the Setfive site there's a recent post from Ashish Datta about some thoughts around array functions and closures for callback methods.

The other day, I was hacking away on the PHP backend for the “Startup Institute” visualization and I realized it was going to need a good deal of array manipulation. Figuring it was as good a time as any, I decided to try and leverage PHP 5.3+ new closures along with the array_* functions to manipulate the arrays. I’m not well versed with functional programming but I’ve used Underscore.js’s array/collection functions so this is mostly in comparison to that.

He gives a sample data set he's pulling from - basic user data - and goes through a few different actions that can be taken on the data (with code examples for each): sorting, mapping and filtering. He shows the use of closures as the callback methods instead of defining them separately and passing in their names.

tagged: array closure callback example

Link:

Kevin Schroeder:
Would this be a dumb idea for PHP core?
Feb 19, 2013 @ 15:26:55

In this new post to his site Kevin Schroeder thinks out loud and wonders if an idea of his is "a dumb idea" to be included into the PHP core - engine state caching.

I was consulting and I would see significant server resources consumed by bootstrapping the apps. Loading config files, loading dependent classes, setting up dependencies, initializing ACL’s, and the list goes on and on. One of the ways to negate the effect would be to cache a bootstrap object and then pull that object from the cache at the start of the request. However, the problem is that unserialization can actually end up taking more time than the bootstrap process itself.

He wonders if, after the initial bootstrapping happened, a method could be called (his example is "init_engine_state") that would cache the Zend Engine's current state and pass that to a callback function. This would cache everything - objects, variables, classes, etc - all pre-interpreted into memory and make them easy to reuse on future executions. What do you think? Share your thoughts in the comments of the post.

tagged: engine state cache zendengine bootstrap callback

Link:

PHP/Cloudcast:
Getting Started with Stripe Webhooks
Nov 19, 2012 @ 15:20:51

On the PHP/Cloudcast site today they've released another screencast showing you how to integrate your application with Stripe, the popular (and programmer friendly) payment gateway for your applications. This is the third part of their series.

In this, the third episode of PHP Cloud Development Casts, we go through how to integrate Stripe Webhooks in to our PHP applications. We extend the PHP Kohana application we created in episode 2 and show how simple it is to create a webhook and to receive the information and store it in a MySQL database.

Through the use of Stripe's webhooks, you can have a transaction call back to your application on a specified URL and perform further actions. In his example, he shows how to make the request, handling the "payment success" event. He includes all of the code (controller, view, etc) that you'll need to plug into Kohana to make it all work.

tagged: cloudcast screencast stripe tutorial callback webhook kohana

Link:

DZone.com:
The Duck is a Lie
Jun 27, 2012 @ 14:55:22

In this recent post to DZone.com Giorgio Sironi looks at duck typing and compares it in a few different languages (PHP, Ruby and Java). "Duck typing" is where the methods/functions define the structure or common interface rather than being functional.

What follows is my experience with Java, PHP and Ruby. I mainly use PHP as a dynamic language that supports duck typing but also the definition of Java-like interfaces, but does not force any of the two approaches as you can define interfaces whose method arguments accept any variable or not using interfaces at all. Is duck typing that a revolution?

He shares some of the common misconceptions he's seen including the idea that duck typing can help completely different objects work together and that, sometimes, despite naming conventions, functionality was intended to be different. He shows how even interfaces in PHP can be implemented loosely and the "acts as" and "single callback" architecture ideas.

tagged: duck typing interface misconception actsas callback

Link:

Slawek Lukasiewicz's Blog:
New Features in PHP 5.4 - JSON Extension & header_register_callback
Mar 05, 2012 @ 16:16:20

In the first two posts of his "features new to PHP 5.4" series Slawek Lukasiewicz has posted about two things that weren't mentioned very often in most of the 5.4 hit lists - improvements to the JSON extension and the header_register_callback method.

About the JSON extension improvements:

By default, when we pass object to json_encode function, it will return JSON representation of object public properties. [...] PHP 5.4 introduces JsonSerializable interface with JsonSerialize abstract method. After implementing this method we can independently set values used in JSON representation.

Related to the header_register_callback addition

After looking at new functions introduced in PHP 5.4 we can found one called header_register_callback. Using it, we can register callback which will be called before sending output.

The stable version of PHP 5.4 has officially been released, so get out there and grab it and start using these new features now!

tagged: improvement release feature json extension headerregistercallback callback

Link:


Trending Topics: