- Saved searches
- Use saved searches to filter your results more quickly
- License
- RomanovSci/no-framework-tutorial-ru
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- License
- PatrickLouys/no-framework-tutorial
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Write modern PHP without a framework
- Prerequisites
- Setting up Composer
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
License
RomanovSci/no-framework-tutorial-ru
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Руководство по созданию PHP приложения без фреймворков [Перевод]
Данное руководство предназначено для тех, кто хорошо знаком с PHP, а также с азами ООП. Прежде чем двигаться дальше, рекомендую ознакомится с принципами SOLID, если вы еще не знакомы с ними.
Я видел как многие задавали вопросы в чат-руме на Stack Overflow, насколько хорош фреймворк X и стоит ли использовать его в своих проектах. В большинстве случаев ответ заключался в том, что они должны просто использовать PHP, а не фреймворк. Такой ответ является крайне неприятным, так как многие не знают с чего начать.
Моя цель заключается в создании ресурса, который послужил бы отправной точкой для разработчиков, задающихся вопросом о построении PHP приложения без фреймворков. В некоторых случаях использование фреймворка бессмысленно, и писать приложение с нуля, используя лишь сторонние пакеты, намного проще.
Данный мануал был написан для версии PHP 7.0 или более поздних версий. Перед тем как мы начнем, обновите PHP, если вы используете версию ниже 7.0. Я рекомендую использовать текущую стабильную версию.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A small tutorial to show how to create a PHP application without a framework.
License
PatrickLouys/no-framework-tutorial
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Because this tutorial was so well-received, it inspired me to write a book. The book is a much more up to date version of this tutorial and covers a lot more. Click the link below to check it out (there is also a sample chapter available).
The tutorial is still available in it’s original form below.
Create a PHP application without a framework
If you are new to the language, this tutorial is not for you. This tutorial is aimed at people who have grasped the basics of PHP and know a little bit about object-oriented programming.
You should have at least heard of SOLID. If you are not familiar with it, now would be a good time to familiarize yourself with the principles before you start with the tutorial.
I saw a lot of people coming into the Stack Overflow PHP chatroom and asking if framework X is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don’t know where to start.
So my goal with this is to provide an easy resource that people can be pointed to. In most cases a framework does not make sense and writing an application from scratch with the help of some third party packages is much, much easier than some people think.
This tutorial was written for PHP 7.0 or newer versions. If you are using an older version, please upgrade it before you start. I recommend that you use the current stable version.
So let’s get started right away with the first part.
- Front Controller
- Composer
- Error Handler
- HTTP
- Router
- Dispatching to a Class
- Inversion of Control
- Dependency Injector
- Templating
- Dynamic Pages
- Page Menu
- Frontend
Write modern PHP without a framework
Since the introduction of Composer package manager and the PHP standards, writing PHP became easier and more manageable, whereas in the past you were almost forced to use a framework to maintain your project in a professional matter, nowadays this is not necessary, and today I will show you how to glue together a small API project with basic routing, third party packages, and testing without a framework. There are few reasons why you don’t want to use a framework, you are creating a library, a small app/API, have more control and so forth, depending on your cases you might want to use a framework don’t get me wrong. Our goal is to create a simple Blog Api, each post will have an id, title, and body, you will able to list, create and view a post, we won’t use any database, a simple JSON file that will act as DB should be enough, all request/responses will be in JSON format As you see, there are some fields and features missing, like slug, summary, published date, author, tags, categories and so forth, or ability to delete/update, I decided to not implement those and I’ll briefly explain some classes and code without getting into too much detail to make this article shorter, if you need extra explanation of any step please leave it in the comments and I will do my best to help you there. All code is available in https://gitlab.com/dhgouveia/medium-blog-api
Prerequisites
- PHP 7.0 or greater
- Composer
- Basic knowledge of PHP, classes, composer, MVC pattern
Setting up Composer
The first thing we need to do is create our composer.json needed to add 3rd party packages and manage our project with the autoloading feature, this will make importing classes easier.
Create a folder and type composer init in your terminal and fill the information, it will create the composer.json file for us, then create our basic folder structure with some empty files called index.php , config.php and an empty folder called App
Let’s add the first package by using the command line composer require monolog/monolog:1.25.1 , it creates a vendor folder with the package we just added and a file called autoload.php , this file will contain all the path to the classes we add from 3rd parties and ours, monolog is a package to create logs files that will be used later on
Open index.php and fill it with:
require __DIR__ . '/vendor/autoload.php';