The latest release of PHP has created a massive spark among developers, needless to say how popular a back-end scripting language it is. With this course, you'll get a deep insight into 3 cool projects that are built on PHP, and you'll learn different ways to improve your development.
Once you're familiar with setting up your environment and using the basic syntax of PHP, we'll begin with an entry-level project, where we'll show you how to build a URL shortener. You'll understand how to make effective use of MVC and how to connect up to the database. From there, we'll show you how to automate testing for our project and how to create functional tests. Next, we'll jump on to building an authentication platform, where you'll be introduced to Test Driven Development and CRUD, to create persistence storage. We'll show you the beauty of using the REST API and you'll also learn how to alleviate the load on the database. Finally, we'll build a social sharing platform, where we'll tighten the security and let users interact with each other in real-time.
With this course in your hands, you'll be confident of the practical use cases of PHP and will be ready to take your development skills to the next level.
About the Author
Michael Lively has worked in a variety of roles in the software development industry for over 15 years, from developer to development director. He has worked on a variety of different projects and a variety of different technologies over that time, from small home-grown sites serving a handful of regular users to large enterprise platforms serving millions of consumers.
His current job is with Slickdeals.net, the largest and most trusted deal sharing community and a routine presence in the top 100 sites in the US. In addition to his professional work, he has been an active member of the PHP open source community. Some of his contributions include the database extension for PHPUnit and an alternative mocking framework for PHP called Phake.
In this video, we will walk through creating a brand new PHP development environment that we will be using throughout the course.
We need an editor that allows us to easily update our projects and integrates well with how vagrant works. We will install PhpStorm. PhpStorm is a commercial solution that has excellent integration with vagrant.
As mentioned before, PhpStorm is a commercial solution. Some developers may not want to pay for an editor. NetBeans is a free solution that is not as feature filled but will get the job done.
We want to build a simple website. We will see how PHP can be used to create a simple form and process that form.
We need to store the data submitted by forms for more than just a single page request. We can use PHP's built-in session handling to do this for us.
PHP has a large number of functions to cover a vast array of functionality. It can sometimes get difficult to navigate through them. Using PHP's documentation, you can start to understand the functionality available for you through PHP and its many extensions.
We know how to store data for a session, but how can we persist data for longer? Using PHP's PDO extension and a SQLite database, we can store data in an external database for use later.
We have built up a fair amount of code now and some of it is duplicated across files. We are going to use classes to isolate some core concepts of our project to make them easier to reuse.
We need to learn how to set up actual projects. We will use PHPStorm, composer, and our VM to create a new project for our shortener.
We need a well-defined and flexible way to add content and functionality to our site. We can use the MVC pattern to achieve this.
Our site accepts any data right now, either when submitting a URL or when viewing a URL. This could cause weird errors on our part that we probably don't want to see. This can be fixed by implementing code in the model and controller to validate the state of objects.
We have a working form, but it is saving data only to the session. To make our application useful, we need it to record data to the database instead.
The only thing missing now is the ability of our application to redirect users using the short URLs. We will implement this functionality in our MVC framework with some help from PuPHPet's default configuration for nginx.
If we want to write unit tests, we need to install a proper unit testing library. We will install PHPUnit, the most widely used unit testing framework for PHP.
Now that we have PHPUnit installed and working, we need to learn how to use it. We will use our UrlEntity as an example to see how we can build an effective unit test.
The first class that we tested was a simple class with really no dependencies. However, our remaining classes have dependencies that make setting up a test difficult. We will use a mocking framework to help us simplify the setup of these dependencies.
We have learned how to use mock objects to test classes with code dependencies. Now we need to learn how to test classes with database dependencies. We can leverage PHPUnit's database testing extension to simplify the testing of our database interaction in the repository.
We can now test most of the types of classes we will find in our applications. However, we need a way to validate that our various units work together properly. We will use Selenium to create functional tests that will allow us to test our website from end-to-end.
Now that we have an understanding of all the fundamental building blocks of testing, we need to learn how to apply those to our projects. Using a new project, we will apply a test-driven development approach to ensure proper coverage of our project with functional tests.
With our feature test for user management in place, we need to get started on our code. We will use our feature test to help guide the development of the entire user management feature.
Now that we have our first feature under our belt, we need to expand our functionality. We are going to use the user management code as an example to quickly implement group management.
Most of ourcurrent implementation of group management is identical, Instead of continuing on with copy-and-paste programming, we should generalize the CRUD functionality in our system and abstract into a separate class that can easily be reused.
Now that we have a base set of classes for implementing CRUD for an entity in our system we should start taking advantage of it. We will use our CRUD classes to create management functionality for permissions.
We now have a fully functional management interface for users, groups, and permissions. Now we need a way to secure our interface. What better way to set up accounts for our user management system than to use the authentication management system itself? To do this, we will add authentication and access control to our system.
A common need for many projects is a lightweight, easy to understand, easy to maintain API. We can leverage RESTful API architecture to provide such an API for clients.
We now have a solid strategy to build a REST API and a test to make sure we complete it, but we don't have an implementation. We are going to leverage our existing domain model to create a new API controller
Set up our MySQL server so we can login and use it from the application.
We are now leveraging our database for all of our data. Before too long it is likely that we will start seeing bottlenecks form in our database. Leveraging Memcache we can increase the amount of head room we have in MySQL by offloading reads from the database to a quicker memcache solution.
We now have a performant database but we are still stuck using files to hold our sessions. We will leverage MySQL to move session storage to a shareable database.
As developers, we should try to spend enough time on things that are unique to our product or business. We can use frameworks such as Silex to help free up time from solving common issues.
We want to find an easier way of logging in to our system. We can use Google's OAuth implementation to allow Google logins for credentials on our site.
We can log in with Google now, but Google may not give us all of the data we need. We need to allow attaching of data to the users provided by Google's OAuth data.
We need to start working on allowing URLs to be shared. Using a web crawler/scraper, we can pull rich data down into our database for URLs that we post.
Now that we have a URL crawling service, we need to integrate it with the site.
We are collecting URLs, but in doing so we have introduced a potential bottleneck to our web requests. We are going to re-implement our URL service using an external job queue.
Now that we are collecting URL data, we need a way to display it to our users. We will use long polling to ensure that our users have the best experience possible.
We are able to easily add content to our site. Now we need to learn how to search for users. We will use Elasticsearch to augment our database and make it easier to find users in our system.
We can find users we know about with Elasticsearch. Now we need a way to discover new users. We will implement a simple algorithm to find users sharing the same URL as us.
Now that we can discover users, we need a way to follow them. We will introduce following and unfollowing in this section.
Now that users can see each other's URLs, we should create a way for a user to comment on a URL.
There are a lot of things happening on our site now and it would be great to have a feed of these events. We will use domain events to help create feed items to communicate important events to our users.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.