Forem

Hanane Kacemi
Hanane Kacemi

Posted on

2 2

100 days of code - Day 1

Hello,
I decided to participate on "100DaysOfCode" challenge. To start I'm choosing "Create your own PHP Framework" tutorial, available on symfony website : https://symfony.com/doc/current/create_framework/index.html

In the introduction section of this tutorial they asked a question : "why would someone choose to create its own framework instead of using existing ones ?

well, for me, the main raison is : I want to learn more about low level architecture of frameworks.

So, What do we need for this mission :D ?

  • PHP 7.4 or later
  • web server : nginx, apache, php's built in server (I am unsing xampp)
  • OOP knowledge
  • Composer to install third-party component

Part 1 : Http Foundation Component :

When we create a web app, we assume that we will have a communication between a client and the server, the client sends a request and the server returns a response.

In PHP, the request is represented by global variables ($_GET, $_POST, $_FILE, $_COOKIE, $_SESSION…) and the response is generated by functions (echo, header, setcookie, …).

HttpFoundation component replaces these default PHP global variables and functions by an object-oriented layer.

we can add this component to our project via :
composer require symfony/http-foundation

There are two main classes : Request and Response

These are some main functions of Request Class :

$request->getPathInfo(); // the URI being requested (e.g. /about) minus any query parameters

// retrieve GET and POST variables respectively
$request->query->get('foo');
$request->request->get('bar', 'default value if bar does not exist');

// retrieve SERVER variables
$request->server->get('HTTP_HOST');

// retrieves an instance of UploadedFile identified by foo
$request->files->get('foo');

// retrieve a COOKIE value
$request->cookies->get('PHPSESSID');

// retrieve an HTTP request header, with normalized, lowercase keys
$request->headers->get('host');
$request->headers->get('content-type');

$request->getMethod();    // GET, POST, PUT, DELETE, HEAD
$request->getLanguages(); // an array of languages the client accepts
Enter fullscreen mode Exit fullscreen mode

And below are those of Response Class :

$response = new Response();

$response->setContent('Hello world!');
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'text/html');

// configure the HTTP cache headers
$response->setMaxAge(10);
Enter fullscreen mode Exit fullscreen mode

That's all for today,
Feel free to comment for any suggestions/questions
Have a nice day

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay