Home  >  Article  >  Backend Development  >  Creating my first PHP Package

Creating my first PHP Package

WBOY
WBOYOriginal
2024-09-12 10:20:50514browse

Creating my first PHP Package

Hello Devs,

I recently had the crazy idea of developing a PHP package for logging errors in scripts.

What inspired me?

As I started on building my very first package, the experience was nothing short of thrilling. The first question that I asked myself was "Why should I create this?" The answer soon followed.
I wanted a command-line tool that not only logs errors but does so in a vibrant, visually engaging way. With that in my mind, I opened my favorite code editor, turned to the PHP documentation, and began turning this idea into reality.

What does it do?

The package is simple and effective. It logs messages in PHP Scripts and presents them in a beautiful, colorful format, making debugging not only easier but also more enjoyable! You can check it out on Packagist ckoumpis/php-prompt

Code Samples

Here's a quick example of how you can use it:

Console::log("Hello from ckoumpis/php-prompt!");
Console::success("Operation successful!");
Console::error("An error occurred!");
Console::warning("Warning");Console::blue("This is a blue message");
Console::magenta("This is a magenta message");
Console::cyan("Cyan message for notification");

Progress Bars and Spinners

The package also includes progress bars and spinners for better feedback in long running scripts:

for($i = 1; $i <= $total; $i++) {
    ProgressBar::display($i, $total);
    usleep(10000);
}

Or with steps

ProgressBar::withSteps(1, 10, 1);

For Spinners

for($i = 0; $i < 10; $i++) {
    Spinner::spin();
    sleep(1);
}

Or with Steps

Spinner::withSteps(0, 10, 1);

Collaboration

I welcome anyone to contribute in the project. I would love for others to join me in making this tool even better. Together we can build something cool and useful.

The above is the detailed content of Creating my first PHP Package. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn