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

Matthias Noback:
Mocking the network
Apr 04, 2018 @ 16:19:06

Matthias Noback has continued his series about "mocking the edges" in your unit testing with this new post. In it, he talks about mocking "the network", those places where your application reaches out to external services to access data or perform other operations.

In this series, we've discussed several topics already. We talked about persistence and time, the filesystem and randomness. The conclusion for all these areas: whenever you want to "mock" these things, you may look for a solution at the level of programming tools used (use database or filesystem abstraction library, replace built-in PHP functions, etc.). But the better solution is always: add your own abstraction.

[...] The same really is true for the network. You don't want your unit tests to rely on a network connection, or a specific web service to be up and running. [...] The smarter solution again is to introduce your own interface, with its own implementation, and its own integration test. [...] Though this solution would be quite far from traditional mocking I thought it would be interesting to write a bit more about it, since there's also a lot to say.

In his example he shows the use of a file_get_contents call to fetch stock information. He introduces a ExchangeRateService interface with a getFor method to provide structure for the "wrapper" around the network call. He then covers the idea of an "anti-corruption layer" to change up the interface to use models instead of just a string value (code included). He ends the post talking about the inversion of the dependency - the option to have a job pull the value out-of-band and then have the application use that value.

tagged: mock testing unittest network connection interface inversion

Link: https://matthiasnoback.nl/2018/04/mocking-the-network/

SitePoint PHP Blog:
Building a Social Network with Laravel and Stream? Easy!
Apr 19, 2017 @ 18:53:03

Christopher Vundi has continued his series covering the integration of Laravel and the Stream service in this new tutorial. In the first post he showed how to add "follow" handling to the application, complete with a real-time stream event when it happens. In this new post he uses some of the same handling to enhance this to a larger "social network" type application.

In the previous post, we saw how to add the follow functionality to a Laravel app. We also looked at how to configure our app to use Stream. This part will focus on: configuring our models in order to make it possible to track activities, the different types of feeds that Stream provides, getting feeds from Stream [and] rendering the different types of feeds in a view.

He starts in with the "activity field" functionality, a base level object that stores each event that happens in the system and is then relayed to Stream. Then, using the included "feed manager" in the Stream package, he shows how to use built-in feeds and add in a custom feed for follow and unfollow events. The tutorial then walks through the output process of the events, handling of the updates from Stream and routing those back out to the waiting news feed on the frontend.

tagged: social network follow event stream streamio service tutorial series part2

Link: https://www.sitepoint.com/building-social-network-laravel-stream-easy/

SitePoint PHP Blog:
Local Composer for Everyone! A Conference-Friendly Satis Setup
Aug 30, 2016 @ 16:13:30

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial showing you how to set up the Packagist alternative, Satis, in a local network configuration instead of requiring users to still access the external web.

While preparing my technical materials for WebSummerCamp, I realized my workshop would rely on a fairly stable internet connection, as we’d have a lot of ground to cover and a lot of packages to install. Rather than rely on the gods of live demos, or pre-installing everything and ruining the experience, I picked another route.

In this post, I’ll show you how to set up a local Satis instance and have it host the packages over the network it’s currently on, so that everyone who’s also connected to it can put the address into composer.json as a custom repository source, and retrieve all packages from your machine locally – no internet connection required!

He then shows you how to set up the system on a Homestead Improved VM locally, cloning Satis inside of it. He includes an example of the configuration of his required packages and how to build the local repository using this setup. Then, using the built-in PHP web server, he shows the result of the setup and how to access it from other machines. Finally, a few updates are required to the user's composer.json to use the local versions instead of the normal remote connection for the package downloads.

tagged: composer satis local network tutorial setup configuration example

Link: https://www.sitepoint.com/local-composer-for-everyone-a-conference-friendly-satis-setup/

Codecourse.com:
Social Network with PHP: Introduction (Video Series)
Aug 28, 2015 @ 16:50:47

Codecourse.com has released a video series walking you through the creation of a simple social network site with PHP, Laravel and Bootstrap.

[This tutorial shows you how to create] a social network built with Laravel and Bootstrap. Authenticate, add and accept friend requests, post to a timeline, reply to and like statuses.

The videos are pretty "bite sized" at just a few minutes each, but they walk you through all of the code you'll need to get the site up and running as well. There's 36 videos in the playlist but with the playlist on auto-play you'll go through them quickly.

tagged: playlist video tutorial series screencast social network laravel bootstrap

Link: https://www.youtube.com/playlist?list=PLfdtiltiRHWGGxaR6uFtwZnnbcXqyq8JD

SitePoint PHP Blog:
Social Network Authentication: Twitter and Facebook
Jul 21, 2014 @ 16:32:12

The SitePoint PHP blog continues their series of tutorials showing how to authentication your users against various social networks. In the previous post they covered connecting to Google+ and in this latest post they move on to two other popular social networks: Facebook and Twitter.

In the previous parts of this series, we created our initial interfaces, set up our Google+ login functionality and talked about how we can merge our accounts together. In this article, we will integrate Twitter and Facebook within our application. You will see a lot of similarities with the Google+ article, so if you could follow that one easily, you won’t have much trouble with this one. If you haven’t read that article yet, I suggest you read it first before continuing this article.

He starts off with the Twitter authentication, creating a new "SocialLogin" object type for it and defining the three required properties it needs to connect. Code is included to make the OAuth connection, pass along the callback URL and forward on the user to the Twitter site for approval. Code is also included to store the data about the Twitter user in your application. Next up is Facebook. The connection is very similar to the others with only a slight difference in the data that's required. You can find the full code for the tutorial so far in this Github repository.

tagged: social network authentication tutorial series twitter facebook

Link: http://www.sitepoint.com/social-network-authentication-twitter-facebook/

SitePoint PHP Blog:
Social Network Authentication: Merging Accounts
Jul 16, 2014 @ 17:19:07

The SitePoint PHP blog continues their series looking at authenticating your application against other social networking services with this new post discussing the merging of accounts. This merging allows you to determine if the same user is using more than one account to log into your system.

If you allow users to sign up through different social networks and perhaps your own registration system, there is a good chance some users will have multiple accounts. How annoying can it be for a user who signed up through Facebook earlier, to come back later and log in through Twitter because he thought he used that one? We can prevent this by letting the user merge manually or try to use an automatic system to try and identify duplicated users.

He tracks the information about the users in two different database tables, one for the user themselves and another representing that user's provider (the social network). He gives an overview of two methods you could use for merging these accounts: either doing it manually by suggesting it to the user or trying to do it automatically based on the data you already have.

tagged: social network authentication tutorial series merge accounts

Link: http://www.sitepoint.com/social-network-authentication-merging-accounts/

SitePoint PHP Blog:
Social Network Authentication - Setup & Google+
Jul 15, 2014 @ 16:12:06

The SitePoint PHP blog has posted the first two parts of a "Social Network Authentication" series looking at connecting your application with social network systems. In these first two posts they help you get things set up to connect to the remote systems and create an actual connection to Google+.

Almost every website which contains a log in option, also contains ways to log in through different social networks. In this series of articles, we will take a look at how we can make sure that our visitor can log in through Google+ and eventually other networks like Twitter and Facebook. In the final article, we will have a close look at how we can make sure users don’t have different accounts due to the fact that they used different social networks. We will create a framework agnostic package which can easily handle users from different social networks. In this part, we will have a look at our basic setup.

The first tutorial helps you get things all set up and takes the first steps in making the "SocialLogin" package. In the second tutorial they use this package structure to create a Google+ specific instance, making the OAuth connection as simple as calling a method, loading a URL and handling the response.

tagged: social network authentication tutorial series googleplus

Link: http://www.sitepoint.com/series/using-social-networks-as-a-login-system/

PHPMaster.com:
Manage Complexity with the Facade Pattern
Jun 11, 2013 @ 16:54:25

On PHPMaster.com today a new tutorial has been posted about using the Facade design pattern to help reduce the complexity of your application. It can help interface between other pieces of code an make using them simpler (a "facade" on top of them).

Design patterns are built to standardize solutions for common problems faced in software development. [...] Facade is a design pattern used in almost every web application, but often without knowing. The term “design pattern” creates a mental image of something complex and difficult to understand. Even though this can be true sometimes, the Facade pattern is simple to implementation. Let’s see what Facade is and what it does to help us write good code.

A simple example is given to help make the concept of a facade clearer - the process behind borrowing a book. As borrowing and returning a book could involve multiple library types, they use a facade to provide a common interface to all of them. With the concrete example in place, they then move on to the official definition of the pattern and two more "real world" examples: authentication against multiple social networks and working with WordPress meta functions.

tagged: designpattern facade tutorial social network interface

Link: http://phpmaster.com/manage-complexity-with-the-facade-pattern

thePHP.cc:
Do No Enter!
Nov 23, 2012 @ 16:37:44

In a new post to the PHP.cc site today Arne Blankerts reminds us that not all security is about writing good code and handing data correctly - it's also about the systems they run on.

What seems to be so obvious for road traffic and its rules seems to be less obvious for many web developers. They tend to slack on defining (and monitoring) what is happening at the application level as well as the infrastructure level of their application. It is not enough to run a default install of your operating system of choice, add whatever services you need, and hope for the best. Considering the amount of money as well as damage to reputation, either directly due to fraud and abuse or indirectly by time lost to recover a hacked system or software, the "let's hope for the best" approach is of arguable quality. And we are not even considering general bugs here.

He mentions configuring the server, OS and network to ensure a higher level of security, noting that no matter how much work is put into secure code, if the attacker can get to points on the system they shouldn't, your app is still vulnerable.

But how can you tell if someone is actually trying to break in? Pretty much exactly as the police does for road traffic: with speed checks and by patrolling. A properly configured firewall will show as well as inhibit any unauthorized communication within the network and all you need to do is monitor the vital signs of your infrastructure.
tagged: server operatingsystem security network firewall

Link:

Phil Sturgeon's Blog:
NinjAuth: The Social Integration Package PHP has been dying for
Sep 19, 2011 @ 13:59:31

New on his blog Phil Sturgeon has a post about the social integration package PHP has been dying for - NinjAuth. It has hooks for OAuth and OAuth2 connections and makes it simple to use them completely abstracted.

In the past I have never needed to implement oAuth into a PHP project. I have done it in Rails and boy it was easy thanks to OmniAuth. OmniAuth abstracts away so much of the grunt work that it takes about 5 minutes to add a new social network to your site, and 4 of those minutes are spent signing up for the API keys. What options do we have in the world of PHP? A bunch of screwy hacks or provider specific classes like TwitterOAuth. I don't want to hunt down 20 libraries with different methods, I want to get a key, bang it in and go to the pub. Well, now I can!

The fuel-oauth and fuel-oauth2 packages to drive its backend. He includes a code snippet showing how to configure the providers (complete with keys needed for auth) including Facebook, Flickr, GitHub, YouTube and - of course - Twitter. You can grab the latest version of this library from Phil's github account.

tagged: ninjauth social network oauth oauth2 integration codeigniter fuelphp

Link:


Trending Topics: