What about PHP components? Ok, let's create. Part 1. Working with headers.
source link: https://dev.to/maximepihin/what-about-php-components-ok-let-s-create-part-1-working-with-headers-4hgj
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
What about PHP components? Ok, let's create. Part 1. Working with headers.
May 4
・2 min read
I do a lot of programming in PHP and every time something starts that doesn't reach the end, and so on. As a result of thinking, I realized that every time I decide to write my own system, framework or something else, I run into a problem. The problem is that I do everything around for the system to work, and not the system itself, or I write too dependent code. As a result, I decided that it was worth taking the time to write only components that will not depend on something personalized, but can depend on each other. This approach is also a bit weird, but still passing an interface to work is better than initializing another class inside a class. For example, for some component it will be necessary to use a database, but we do not know exactly what methods are there, so we operate with our own interface, where we ask to implement a class with such and such a method. Something we have gone from the topic to abstraction.
And so, I began to make my written projects in pieces. As a result, nothing efficient came out, as there were strong dependencies. I had to write again ... The first component that I decided to implement was working with headers. Why exactly he? Because most of the work is built around the communication between the server and the client. And here, just, you need to work with headers.
For all my components, I decided to adhere to the same logic of organizing the file structure: a folder for interfaces, a folder for exceptions, and the class file itself. The folder with interfaces must contain at least 1 interface for the class. There may be no exceptions in the folder with exceptions, because you don't always need to have personal exceptions.
src/
--- interfaces/
--- --- ClassInterface.php
-------- exceptions/
-------- --- ClassException.php
-------- Class.php
Now let's briefly talk about the methods that are available in the class for working with headers.
- set(array $params)
- add(array $params)
- remove(string $key)
- removeAll()
- has(string $key)
- get(string $key)
- getAll()
I don’t think it’s necessary to give a clear explanation of the methods, but if you are interested, you can look at the GitHub repository. True, now I'm translating my work into English, so don't be too surprised.
And at the end of the part, I want to note that there will be even more classes in the future. I try not to clutter up the post with code, since you can all look at GitHub. You can also download the project from composer packagist.
Recommend
-
110
headers A PHP library for working with HTTP and mail headers Install composer require ivoba/headers Version 2 requires minimum PHP7.1. Usage $header...
-
77
react-router-util Useful components and utilities for working with React Router Install $ npm install reac...
-
44
react-extras - Useful components and utilities for working with React
-
55
README.md react-color-tools
-
14
How to insert React components or direct JSX to Scheduler row headers.
-
4
-
17
The React Mega-Tutorial, Chapter 3: Working with Components
-
5
A few days ago I
-
5
Raymond CamdenDevRel at Adobe, Star Wars nerd, Web/Serverless hacker, lover of good beer and good books. Oh, and cats.
-
1
OverviewHow to customize the Angular Scheduler row headers using Angular components.You can use on onBeforeRowHeaderDomAdd even...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK