How to Build Your Own Dependency Injection Container

A search for “dependency injection container” on packagist currently provides over 95 pages of results. It is safe to say that this particular “wheel” has been invented.

However, no chef ever learned to cook using only ready meals. Likewise, no developer ever learned programming using only “ready code”.
In this article, we are going to learn how to make a simple dependency injection container package. All of the code written in this article, plus PHPDoc annotations and unit tests with 100% coverage is available at this GitHub repository. It is also listed on Packagist.
Planning Our Dependency Injection Container
Let us start by planning what it is that we want our container to do. A good start is to split “Dependency Injection Container” into two roles, “Dependency Injection” and “Container”.
The two most common methods for accomplishing dependency injection is through constructor injection or setter injection. That is, passing class dependencies through constructor arguments or method calls. If our container is going to be able to instantiate and contain services, it needs to be able to do both of these.
To be a container, it has to be able to store and retrieve instances of services. This is quite a trivial task compared to creating the services, but it is still worth some consideration. The container-interop package provides a set of interfaces that containers can implement. The primary interface is the ContainerInterface that defines two methods, one for retrieving a service and one for testing if a service has been defined.
interface ContainerInterface

public function get($id);
public function has($id);

Learning From Other Dependency Injection Containers
The Symfony Dependency Injection Container allows us to define services in a variety of different ways. In YAML, the configuration for a container might look like this:
# …
mailer.transport: sendmail

class: Mailer
arguments: [“%mailer.transport%”]
class: NewsletterManager
– [setMailer, [“@mailer”]]

Continue reading %How to Build Your Own Dependency Injection Container%

via Reme Le Hane

Quick Tip: Installing React Native

React Native has fast become one of the hottest frameworks for building cross platform mobile apps. Based on JavaScript and Facebook’s React Library it focuses on performance and tight integration with the native platforms supports. With Facebook invested in the framework and React’s learn once, write anywhere philosophy, React has a bright future.
Continue reading %Quick Tip: Installing React Native%

via Reme Le Hane

Prep for 3 Essential Security Certifications for $30

In the IT industry, the right certifications are your foot in the door of a highly lucrative career in security and ethical hacking. So make sure you’re ready to ace three of the most essential certification exams—CompTIA Security+, Certified Ethical Hacker (CEH), and Cisco’s CCNA Security. We’ve got LearnSmart’s $1,895 IT Security & Ethical Hacking Certification Training course for just $29.99 at SitePoint Shop.
Get your CompTIA Security+, Certified Ethical Hacker (CEH), and Cisco’s CCNA Security certifications with this test prep bundle. You’ll learn about keyloggers, spyware, and password cracking, figuring out how to secure businesses against an attack in the process. Best of all, it only takes 1-3 hours a week of following along with the training—you’ll be ready for all three certification exams within 4-6 weeks. A new career in a month? Not bad at all.
Launch your new career by next month. Get LearnSmart’s IT Security & Ethical Hacking Certification Training course for $29.99.
Continue reading %Prep for 3 Essential Security Certifications for $30%

via Reme Le Hane

Web Development Reading List #124: Responsibility, Bash Tooling, And Flexbox Order

I often think about our responsibility as web developers. I compare our job to a health worker, to a craftsman, and I realize that we have a pretty easy job in most cases. Usually, nobody’s life will be affected if a website is not available for a couple of minutes or hours.

But there are some cases where this could happen. People start coding app interfaces for health application with web technologies, people start connecting health services to the web, and people also rely on websites for their own safety. And that’s why I think we should feel responsible for our users. And by making choices that are ethical and user-centered, we create a better web for everyone.
The post Web Development Reading List #124: Responsibility, Bash Tooling, And Flexbox Order appeared first on Smashing Magazine.

via Reme Le Hane

Getting Started with Microservices Using Syncano’s Codeboxes

This article was sponsored by Syncano. Thank you for supporting the sponsors who make SitePoint possible.
Syncano is a really fascinating platform that gives you a hand with the backend and middleware of applications. We had a look at the capabilities of Syncano in my last article on How to Build a Daily Affirmations SMS Service with Stripe & Syncano where we put together a service that sent out daily SMS affirmations in a subscription service. All the backend and middleware is taken care of by Syncano. Very neat!
In this article, we are going to focus on Syncano’s concept of CodeBoxes more closely — what CodeBoxes are, how we make and run them in Syncano, and how we can connect them to external APIs. We’ll put together a demo using GitHub’s API to showcase just what is possible.
What is a CodeBox?
A CodeBox is a snippet of code that can be run in the cloud in a number of ways. Each CodeBox is intended to provide a single piece of our web application puzzle — one bit of functionality that contributes to the app as a whole.
To provide specifics about what we’d like the CodeBox to do in our web application, we can pass in arguments to a CodeBox, just as you would pass in arguments to a HTTP request. For example, we could have a CodeBox that looks up song lyrics stored in a database. It would accept two parameters, the song name and artist. A sample input for that CodeBox could be “Jack Sparrow” and “The Lonely Island”. The CodeBox would run using those parameters and provide the song lyrics if it knew the song. If not, it’d return a message saying it couldn’t find them.
One of my favourite things about CodeBoxes is that they can be created in a number of different languages. Syncano supports CodeBoxes written in Python, Golang, Node.js, Swift and Ruby. Not only that — CodeBoxes written in different languages can all work together to create a functioning web application. It is incredibly flexible!
The Code
For those who would like to follow along with the examples, the working code is available on GitHub. Use it, enjoy it, expand it — do as you wish.
How to Create a CodeBox
To illustrate the use of CodeBoxes in a Syncano application, we’ll be putting together a really simple app that looks up pull requests from a GitHub repo. It’s about time we had a way to keep an eye on how our GitHub team projects are going right?
To begin, we head to the Syncano Dashboard and create a new app. If you’re totally new to Syncano and need a bit of guidance on this, have a look at the previous SitePoint article on Syncano — it should help you out.
Then, we head to the “CodeBoxes” section on the left and click either of the icons with a plus on it to create a new CodeBox:

Then, in the popup box that appears:
Enter in a title for your CodeBox – This can be a short but clear label to help you find it in the Dashboard, e.g. “Find GitHub Pull Requests”.
Enter in a description for your CodeBox – This isn’t needed but I prefer to use it to include more details on exactly how the CodeBox is going to work, e.g. “Looks up and filters pull requests from a GitHub repo”.
Choose the runtime environment you’d prefer to work in – In this article, we’ll be using Node.js, so if you’d like to follow along directly, choose that one!
Click “Confirm” to create that CodeBox!
Once you have created your CodeBox, Syncano should bring you straight to the CodeBox editing screen. You’ll see a blank page with the text # Start coding!. We should follow that instruction and put something simple in there as an initial test run.

Running a CodeBox
Enter in a simple console.log() statement and then click the run button to the right to give it a test run:

Then, if we scroll down the page, we find a result screen with the successful output:

Continue reading %Getting Started with Microservices Using Syncano’s Codeboxes%

via Reme Le Hane

Free Fonts With Personality

Typography can make all the difference. However, if your project has to get along on a very limited budget and you need to rely on free fonts, good ones are never easy to find. Luckily, we stumbled across some real gems lately.

The following fonts can be downloaded for free and are bound to give your project — both private and/or commercial — a classy finishing touch.
The post Free Fonts With Personality appeared first on Smashing Magazine.

via Reme Le Hane