DS Log
In my blog, I delve into the world of programming web technologies, Linux, Unix-like, and graphic design using free tools on Linux.
KINGCODE
KingCode Editor (ex Texty Editor) is my project developed using Java Swing. Project is still in development and in beta version. I plan to add additional features focused for PYTHON, PHP, JAVA, C, JS and BASH.
Read more ↗
VUE on Linux
In this guide, I'll walk you through the step-by-step process of setting up Vue.js on your Linux system, empowering you to create dynamic and interactive web applications. Let's harness the power of Vue.js together on the Linux platform!
Read more ↗
Symfony PHP
Dive into the world of Symfony PHP with this comprehensive introduction. In this guide, you'll learn the essential steps to create and manage posts and users, empowering you to build dynamic web applications with ease.
Read more ↗
Trying Linux from Windows
How to set up a PHP development server on Ubuntu 22.04
Text editors
List of text editors for developers.
Read more ↗
Fonts
Important fonts everyone needs to know.
Read more ↗
Try Linux from Windows
Here are some quick videos I made showing how to try out Linux Mint on Windows.
Read more ↗
Saturday, August 10, 2024
Composer
Composer is a powerful tool designed for managing and installing packages for the PHP programming language. It operates similarly to npm for JavaScript or the pacman package manager for Linux, enabling users to effortlessly install PHP libraries and tools directly from the command line. With Composer, developers can easily manage dependencies, ensuring their projects are up-to-date and well-organized.
In this text, I will focus solely on the aspects that I personally consider important.
Where are the packages?
Packagist is a site where you can find Composer packages. There we can search and add our own scripts or projects.
How do we install the package?
Let's create a directory and open a terminal in it. For example, let's install the
milon/barcode package:
🚀 composer require milon/barcode
...and this looks like:
How do we add library to our code?
Let's make 'index.php' and in it:
<?php
require __DIR__ . "/vendor/autoload.php";
use \Milon\Barcode\DNS1D;
$d = new DNS1D();
$d->setStorPath(__DIR__.'/cache/');
echo $d->getBarcodeHTML('9780691147727', 'EAN13');
Open the PHP dev-server with:
php -S localhost:9999
How to make a Composer project?
Let's prepare the project structure:
mkdir ./rex
cd ./rex
We create 'composer.json' with the command 'composer init'. Press [Enter] on all questions:
composer init
Let's create 'index.php':
touch ./rex/index.php
With data:
<?php
require __DIR__ . "/vendor/autoload.php";
use Ddd\Rex\Dog;
$pas = new Dog();
$pas->bark();
Then we create a test class in the 'src' directory:
touch ./src/Dog.php
Enter in the file 'Dog.php':
<?php
namespace Ddd\Rex;
class Dog
{
function bark()
{
echo "Bark!";
}
}
And finally, to restore the Composer autoload list (we must be in the project root path, where 'composer.json' is also):
composer dump-autoload
We reopen (shut down the one from before) the PHP dev-server with:
php -S localhost:9999
If everything is ok, "Bark" will be displayed.