DEV Community

Cover image for My PHP Toolkit to Build a (quite) Frameworkless App
Boris Jamot ✊ /
Boris Jamot ✊ /

Posted on • Updated on • Originally published at mamyn0va.github.io

My PHP Toolkit to Build a (quite) Frameworkless App

Hey, let me introduce you some of the libraries & tools I've been using in many PHP projects running in production.

I'm used to build my own framework by picking up libs in the below list each time I start a new PHP project. But to be honest, I must admit that I still use a micro-framework for basic HTTP stuff: Slim.

📝 I use no ORM and I mainly build backend apps with Web APIs.

Libraries

1. Slim Framework

slim

🙋 Purpose: Micro-Framework intended to build Web APIs
🌠 GitHub stars: 9,475
🔗 URL: slimphp/slim

2. Slim Framework CSRF protection middleware

GitHub logo slimphp / Slim-Csrf

Slim Framework CSRF protection middleware

Slim Framework CSRF Protection

Build Status Coverage Status

This repository contains a Slim Framework CSRF protection PSR-15 middleware. CSRF protection applies to all unsafe HTTP requests (POST, PUT, DELETE, PATCH).

You can fetch the latest CSRF token's name and value from the Request object with its getAttribute() method. By default, the CSRF token's name is stored in the csrf_name attribute, and the CSRF token's value is stored in the csrf_value attribute.

Install

Via Composer

$ composer require slim/csrf
Enter fullscreen mode Exit fullscreen mode

Requires Slim 4.0.0 or newer.

Usage

In most cases you want to register Slim\Csrf for all routes, however, as it is middleware, you can also register it for a subset of routes.

Register for all routes

use DI\Container
use Slim\Csrf\Guard
use Slim\Factory\AppFactory
require __DIR__ . '/vendor/autoload.php'
// Start PHP session
session_start();

// Create Container
$container = new Container();
AppFactory
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: Protect your GUI pages with a CSRF token
🌠 GitHub stars: 201
🔗 URL: slimphp/csrf

3. Slim Framework Flash Messages

GitHub logo slimphp / Slim-Flash

Slim Framework flash messages service provider

Slim Framework Flash Messages

Build Status

This repository contains a Slim Framework Flash messages service provider. This enables you to define transient messages that persist only from the current request to the next request.

Install

Via Composer

$ composer require slim/flash
Enter fullscreen mode Exit fullscreen mode

Requires Slim 3.0.0 or newer.

Usage

// Start PHP session
session_start()
$app = new \Slim\App()
// Fetch DI Container
$container = $app->getContainer()
// Register provider
$container['flash'] = function () {
    return new \Slim\Flash\Messages()
};

$app->get('/foo', function ($req, $res, $args) {
    // Set flash message for next request
    $this->flash->addMessage('Test', 'This is a message');

    // Redirect
    return $res->withStatus(302)->withHeader('Location', '/bar');
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: This enables you to define transient messages that persist only from the current request to the next request
🌠 GitHub stars: 104
🔗 URL: slimphp/flash

4. Twig

twig

🙋 Purpose: A very popular template engine that integrates well with Slim (slimphp/twig-view)
🌠 GitHub stars: 5,705
🔗 URL: twigphp/twig

5. Monolog

GitHub logo Seldaek / monolog

Sends your logs to files, sockets, inboxes, databases and various web services

Monolog - Logging for PHP Continuous Integration

Total Downloads Latest Stable Version

Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers below. Special handlers allow you to build advanced logging strategies.

This library implements the PSR-3 interface that you can type-hint against in your own libraries to keep a maximum of interoperability. You can also use it in your applications to make sure you can always use another compatible logger at a later time As of 1.11.0 Monolog public APIs will also accept PSR-3 log levels Internally Monolog still uses its own level scheme since it predates PSR-3.

Installation

Install the latest version with

$ composer require monolog/monolog
Enter fullscreen mode Exit fullscreen mode

Basic Usage

<?php
use Monolog\Logger
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: Sends your logs to files, sockets, inboxes, databases and various web services
🌠 GitHub stars: 13,388
🔗 URL: seldaek/monolog

6. Zend ACL permissions




🙋 Purpose: Provides a lightweight and flexible access control list (ACL) implementation for privileges management
🌠 GitHub stars: 55
🔗 URL: zendframework/zend-permissions-acl

7. Guzzle

GitHub logo guzzle / guzzle

Guzzle, an extensible PHP HTTP client

Guzzle

Guzzle, PHP HTTP client

Latest Version Build Status Total Downloads

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services.

  • Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data etc...
  • Can send both synchronous and asynchronous requests using the same interface.
  • Uses PSR-7 interfaces for requests, responses, and streams. This allows you to utilize other PSR-7 compatible libraries with Guzzle.
  • Supports PSR-18 allowing interoperability between other PSR-18 HTTP Clients.
  • Abstracts away the underlying HTTP transport, allowing you to write environment and transport agnostic code; i.e., no hard dependency on cURL PHP streams, sockets, or non-blocking event loops.
  • Middleware system allows you to augment and compose client behavior.
$client = new \GuzzleHttp\Client()
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle')
echo $response->getStatusCode(); 
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services
🌠 GitHub stars: 15,355
🔗 URL: guzzlehttp/guzzle

8. PDO

🙋 Purpose: PHP extension to build and execute secured SQL prepared statements
🔗 URL: PDO

9. Zend XML-RPC

GitHub logo zendframework / zend-xmlrpc

XmlRpc component from Zend Framework

zend-xmlrpc

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-xmlrpc.

Build Status Coverage Status

From its home page, XML-RPC is described as a ”...remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.”

Zend\XmlRpc provides support for both consuming remote XML-RPC services and building new XML-RPC servers.




🙋 Purpose: Provides support for both consuming remote XML-RPC services and building new XML-RPC servers
🌠 GitHub stars: 14
🔗 URL: zendframework/zend-xmlrpc

10. PHPMailer

GitHub logo PHPMailer / PHPMailer

The classic email sending library for PHP

PHPMailer

PHPMailer – A full-featured email creation and transfer class for PHP

Test status Latest Stable Version Total Downloads Latest Unstable Version License API Docs

Features

  • Probably the world's most popular code for sending email from PHP!
  • Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
  • Integrated SMTP support – send without a local mail server
  • Send emails with multiple To, CC, BCC and Reply-to addresses
  • Multipart/alternative emails for mail clients that do not read HTML email
  • Add attachments, including inline
  • Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
  • SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SMTPS and SMTP+STARTTLS transports
  • Validates email addresses automatically
  • Protects against header injection attacks
  • Error messages in over 50 languages!
  • DKIM and S/MIME signing support
  • Compatible with PHP 5.5 and later, including PHP 8.0
  • Namespaced to prevent name clashes
  • Much more!

Why you might need it

Many PHP developers need to send email from their code. The only…

🙋 Purpose: A full-featured email creation and transfer class for PHP
🌠 GitHub stars: 12,422
🔗 URL: phpmailer/phpmailer

11. Firebase / PHP-JWT

GitHub logo firebase / php-jwt

PHP package for JWT

Build Status Latest Stable Version Total Downloads License

PHP-JWT

A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519.

Installation

Use composer to manage your dependencies and download PHP-JWT:

composer require firebase/php-jwt
Enter fullscreen mode Exit fullscreen mode

Example

<?php
use \Firebase\JWT\JWT
$key = "example_key"
$payload = array(
    "iss" => "http://example.org"
    "aud" => "http://example.com"
    "iat" => 1356999524,
    "nbf" => 1357000000
);

/**
 * IMPORTANT:
 * You must specify supported algorithms for your application. See
 * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
 * for a list of spec-compliant algorithms.
 */
$jwt = JWT::encode($payload, $key);
$decoded = JWT::decode($jwt, $key, array('HS256'));

print_r($decoded);

/*
 NOTE: This will now be an object instead of an associative array. To get
 an associative array, you will need to cast it
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: A simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to RFC 7519
🌠 GitHub stars: 4,574
🔗 URL: firebase/php-jwt

12. Hassankhan / Config

GitHub logo hassankhan / config

Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

Config

Latest version Software License Build Status Coverage Status Quality Score Total Downloads Gitter

Config is a file configuration loader that supports PHP, INI, XML, JSON YML, Properties and serialized files and strings.

Requirements

Config requires PHP 5.5.9+.

IMPORTANT: If you want to use YAML files or strings, require the Symfony Yaml component in your composer.json.

Installation

The supported way of installing Config is via Composer.

$ composer require hassankhan/config
Enter fullscreen mode Exit fullscreen mode

Usage

Config is designed to be very simple and straightforward to use. All you can do with it is load, get, and set.

Loading files

The Config object can be created via the factory method load(), or by direct instantiation:

use Noodlehaus\Config
use Noodlehaus\Parser\Json
// Load a single file
$conf = Config::load('config.json')
$conf = new Config('config.json');

// Load values from multiple files
$conf = new Config(['config.json', 'config.xml']);

//
Enter fullscreen mode Exit fullscreen mode

🙋 Purpose: Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
🌠 GitHub stars: 749
🔗 URL: hassankhan/config

Tools

As a PHP craftsman, the tools below are mandatory in my toolkit. Most of them (except shellcheck) are installable through composer, which allows you to add them as dev dependencies to your project's composer.json.

1. Composer

composer

🙋 Purpose: Essential PHP dependency manager, and much more
🌠 GitHub stars: 18,049
🔗 URL: Composer

2. PHPUnit

phpunit

🙋 Purpose: Awesome unit tests framework with mocking features
🌠 GitHub stars: 12,785
🔗 URL: PHPUnit

3. PHP Code Sniffer

GitHub logo squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

About

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Build Status Build Status Code consistency Join the chat at https://gitter.im/squizlabs/PHP_CodeSniffer

Requirements

PHP_CodeSniffer requires PHP version 5.4.0 or greater, although individual sniffs may have additional requirements such as external applications and scripts. See the Configuration Options manual page for a list of these requirements.

If you're using PHP_CodeSniffer as part of a team, or you're running it on a CI server, you may want to configure your project's settings using a configuration file.

Installation

The easiest way to get started with PHP_CodeSniffer is to download the Phar files for each of the commands:

# Download using curl
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
# Or download using

🙋 Purpose: Static analysis tool to detect & fix coding standard violations
🌠 GitHub stars: 5,915
🔗 URL: squizlabs/php_codesniffer

4. PHP Mess Detector aka phpmd

phpmd

🙋 Purpose: Static analysis tool to detect code smells, bad design, bugs, unused parameters, etc.
🌠 GitHub stars: 1,315
🔗 URL: phpmd/phpmd

5. PHP Coding Standard Fixer aka php-cs-fixer

php-cs-fixer

🙋 Purpose: Automatically fixes coding standard violations
🌠 GitHub stars: 7,036
🔗 URL: friendsofphp/php-cs-fixer

6. SensioLabs Security Checker

security-checker

🙋 Purpose: The SensioLabs Security Checker is a command line tool that checks if your application uses dependencies with known security vulnerabilities
🌠 GitHub stars: 1,397
🔗 URL: sensiolabs/security-checker

7. XML Linter

GitHub logo sclable / xml-lint

A php tool to lint and validate xml files from the commandline.

Sclable XML Lint

A php tool to lint and validate xml files from the commandline.

Build Status Latest Stable Version Total Downloads License

XML Lint checks the syntax of any xml files and validates the file against the XSD schema defined in the file.

Usage

Installation with Composer

If you'd like to include this library in your project with composer, simply run:

composer require "sclable/xml-lint"

Command Line Usage

To lint a single xml file:

vendor/bin/xmllint path/to/file.xml

To lint a directory and all its subdirectories:

vendor/bin/xmllint path/to/dir

Help

xmllint has built in cli help screen:

vendor/bin/xmllint --help

Options

  • -v be verbose, display the filename of the current file to lint
  • -r 0 don't search recursive (if the argument is a directory)
  • -e name exclude files or directories containing 'name'
  • -s skip the xsd validation

Changelog

For the changelog see the CHANGELOG file

License

For the license and copyright see the LICENSE file




🙋 Purpose: A PHP tool to lint and validate XML files from the command line
🌠 GitHub stars: 6
🔗 URL: sclable/xml-lint

8. YAML Linter

GitHub logo j13k / yaml-lint

Compact command line utility for checking YAML file syntax

yaml-lint

Latest Version on Packagist Software License Total Downloads Scrutinizer Code Quality

A compact command line utility for checking YAML file syntax. Uses the parsing facility of the Symfony Yaml Component.

Usage

usage: yaml-lint [options] [input source]
  input source    Path to file, or "-" to read from standard input
  -q, --quiet     Restrict output to syntax errors
  -h, --help      Display this help
  -V, --version   Display application version

ℹ️ Note that only single files or standard input are supported in the current stable release, 1.1.3.

📢 Experimental support for multiple files is available in 1.1.x-dev.

Install

Install as a project component with Composer (executable from the project's vendor/bin directory):

composer require j13k/yaml-lint
Enter fullscreen mode Exit fullscreen mode

Typically a binary edition (yaml-lint.phar) is also available for download with each release. This embeds the latest stable version of the Symfony Yaml component that is current at the time of the release.

Change log

Please see CHANGELOG for information on what has changed recently.

🙋 Purpose: Compact command line utility for checking YAML file syntax
🌠 GitHub stars: 3
🔗 URL: j13k/yaml-lint

9. Dockerfile Linter

NPM Build Status

dockerfile-lint

A rule based 'linter' for Dockerfiles. The linter rules can be used to check file syntax as well as arbitrary semantic and best practice attributes determined by the rule file writer The linter can also be used to check LABEL rules against docker images.

Table of Contents

Quickstart

  1. Change to directory where you have a Dockerfile
  2. run
  • Atomic CLI

        atomic run projectatomic/dockerfile-lint
        atomic run projectatomic/dockerfile-lint image <imageid&gt
    
  • Docker CLI

        docker run -it --rm -v $PWD:/root/ \
               projectatomic/dockerfile-lint \
               dockerfile_lint [-f Dockerfile]
    
        docker run -it --rm -v $PWD:/root/  \
               -v /var/run/docker.sock:/var/run/docker.sock \
               projectatomic/dockerfile-lint \
               dockerfile_lint  image <imageid>
    

By default, the linter runs in strict mode (errors and/or warnings result in non-zero return code). Run the command with -p or --permissive to…

🙋 Purpose: Rule based Dockerfile linter
🌠 GitHub stars: 259
🔗 URL: projectatomic/dockerfile_lint

10. Shellcheck

GitHub logo koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts

Build Status

ShellCheck - A shell script static analysis tool

ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts:

Screenshot of a terminal showing problematic shell script lines highlighted

The goals of ShellCheck are

  • To point out and clarify typical beginner's syntax issues that cause a shell to give cryptic error messages.

  • To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.

  • To point out subtle caveats, corner cases and pitfalls that may cause an advanced user's otherwise working script to fail under future circumstances.

See the gallery of bad code for examples of what ShellCheck can help you identify!

Table of Contents

🙋 Purpose: A static analysis tool for shell scripts
🌠 GitHub stars: 13,440
🔗 URL: koalaman/shellcheck

11. Swagger CLI

swagger-cli

🙋 Purpose: Validate Swagger/OpenAPI files in JSON or YAML format
🌠 GitHub stars: 125
🔗 URL: APIDevTools/swagger-cli


All these tools can be run automatically:

  • in your IDE
  • in a git hook
  • in your CI/CD pipeline

If you want to go further, please have a look at one of my former articles:

Thanks for reading.

See ya!

Top comments (7)

Collapse
 
biros profile image
Boris Jamot ✊ /

I'm used to build small to medium apps with something like 50kLoC.
I have no specific strategy so I usually end up with big routes files.
As you may know, Slim routes take a closure to handle the request and give the response:

$app = new \Slim\App();
$app->any('/books/[{id}]', function ($request, $response, $args) {
    // do the stuff here
});

Instead of having a big routes file, we have the possibility to define a controller class and to pass it to the \Slim\App:

$app = new \Slim\App();
$app->any('/books', BookController::class);

I never tried that but it's well described in the official doc.

Collapse
 
hsemix profile image
Hamid Semix

You could install a DI container and do something like this

 $app->get('/books', 'BookController@getBooks');
Collapse
 
kip13 profile image
kip

Good libraries/tools/complements to work in a PHP project !

You said this

I use no ORM and I mainly build backend apps with Web APIs.

Could you explain me how you manage in an API a dynamic filter with a resource that have relation with othe(s) table(s) ?

I would like to recommend this tools too:

thephpleague / fractal

Output complex, flexible, AJAX/RESTful data structures.

Fractal

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON. Think of this as a view layer for your JSON/YAML/etc.

When building an API it is common for people to just grab stuff from the database and pass it to json_encode(). This might be passable for "trivial" APIs but if they are in use by the public or used by mobile applications then this will quickly lead to inconsistent output.

Goals

  • Create a protective shield between source data and output, so schema changes do not affect users
  • Systematic type-casting of data, to avoid foreach()ing through and (bool)ing everything
  • Include (a.k.a embedding, nesting or side-loading) relationships for complex data structures
  • Work with standards like HAL and JSON-API but also allow custom serialization
  • Support the pagination of data results, for small and large data sets…

thephpleague / flysystem

Abstraction for local and remote filesystems

League\Flysystem

Author Build Status Coverage Status Quality Score Software License Packagist Version Total Downloads Build status

SensioLabsInsight

Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

Become a Patron

Goals

  • Have a generic API for handling common tasks across multiple file storage engines.
  • Have consistent output which you can rely on.
  • Integrate well with other packages/frameworks.
  • Be cacheable.
  • Emulate directories in systems that don't support them, like AwsS3.
  • Support third party plugins.
  • Make it easy to test your filesystem interactions.
  • Support streams for big file handling.

Installation

composer require league/flysystem

Documentation

Check out the documentation

Community Integrations

Want to get started quickly? Check out some of these integrations:

Adapters

Core

  • Ftp
  • Local
  • NullAdapter

Officially Supported

violet-php / streaming-json-encoder

PHP library for iteratively encoding large JSON documents piece by piece

Streaming JSON Encoder

Streaming JSON Encoder is a PHP library that provides a set of classes to help with encoding JSON in a streaming manner, i.e. allowing you to encode the JSON document bit by bit rather than encoding the whole document at once. Compared to the built in json_encode function, there are two main advantages:

  • You will not need to load the entire data set into memory, as the encoder supports iterating over both arrays and any kind of iterators, like generators, for example.
  • You will not need to load the entire resulting JSON document into the memory, since the JSON document will be encoded value by value and it's possible to output the encoded document piece by piece.

In other words, the Streaming JSON Encoder can provide the greatest benefit when you need to handle large data sets that may otherwise take up too much memory to process.

nikic / iter

Iteration primitives using generators

Iteration primitives using generators

This library implements iteration primitives like map() and filter() using generators. To a large part this serves as a repository for small examples of generator usage, but of course the functions are also practically quite useful.

All functions in this library accept arbitrary iterables, i.e. arrays traversables, iterators and aggregates, which makes it quite different from functions like array_map() (which only accept arrays) and the SPL iterators (which usually only accept iterators, not even aggregates). The operations are of course lazy.

Install

To install with composer:

composer require nikic/iter

Functionality

A small usage example for the map() and range() functions:

<?php
use iter\fn;
require 'path/to/vendor/autoload.php';

$nums = iter\range(1, 10);
$numsTimesTen = iter\map(fn\operator('*', 10), $nums);
// => iter(10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

You can find…

thecodingmachine / safe

All PHP functions, rewritten to throw exceptions instead of returning false

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Coverage Status

Safe PHP

Work in progress

A set of core PHP functions rewritten to throw exceptions instead of returning false when an error is encountered.

The problem

Most PHP core functions were written before exception handling was added to the language. Therefore, most PHP functions do not throw exceptions. Instead, they return false in case of error.

But most of us are too lazy to check explicitly for every single return of every core PHP function.

// This code is incorrect. Twice.
// "file_get_contents" can return false if the file does not exists
// "json_decode" can return false if the file content is not valid JSON
$content = file_get_contents('foobar.json');
$foobar = json_decode($content);

The correct version of this code would be:

$content = file_get_contents('foobar.json');
if ($content === false) {
    throw new FileLoadingException('Could not load

paragonie / easydb

Easy-to-use PDO wrapper for PHP projects.

EasyDB - Simple Database Abstraction Layer

Build Status Latest Stable Version Latest Unstable Version License Downloads

PDO lacks brevity and simplicity; EasyDB makes separating data from instructions easy (and aesthetically pleasing).

EasyDB was created by Paragon Initiative Enterprises as part of our effort to encourage better application security practices.

Check out our other open source projects too.

If you're looking for a full-fledged query builder, check out Latitude and Aura.SqlQuery which can be used with EasyDB.

If you'd like to use EasyDB but cache prepared statements in memory for multiple queries (i.e. to reduce database round-trips), check out our EasyDB-Cache wrapper class.

Installing EasyDB

First, get Composer, if you don't already use it.

Next, run the following command:

/path/to/your/local/composer.phar require paragonie/easydb:^2

If you've installed Composer in /usr/bin, you can replace /path/to/your/local/composer.phar with just composer.

Why Use EasyDB? Because it's cleaner!

Let's refactor a dangerous PHP snippet that previously used string concatenation to pass user input instead…

Collapse
 
biros profile image
Boris Jamot ✊ /

I didn't know these libs and it sounds great.
I know that thephpleague do a great job for PHP.

Regarding the ORM, I don't use it and I prefer building the SQL queries by myself. I use a mapper layer for that which is responsible for the DTO stuff. When several tables are required, I just use a JOIN statement.
It's not ideal but even with ORM, I don't see any clean way to do that.
The problem is with REST. I have to give a chance to GraphQL 😉

Collapse
 
david_j_eddy profile image
David J Eddy

Great list Boris! While I knew many of these it is good to see some I was not aware of. Would you have time to checkout a little library I put together?

davidjeddy / normie

Wrapper library that provides normalized function interfaces for the PHP standard library.

Normie

Badges

Build Status License codecov

Latest Stable Version Latest Unstable Version composer.lock

Scrutinizer Code Quality Build Status Code Coverage Code Intelligence Status

Monthly Downloads Daily Downloads Total Downloads

Contributors

Description

Normie (short for Normalizer) attempts to make using the PHP Standard Library (SPL) function calls more consistent by implementing a norm_{function name}() wrapper function declarations. This library DOES NOT over ride the SPL functions in any way.

Examples

Function parameter order examples.

Arrays fn()

Normie array functions follow the 'array source X, operator Y (callback,key, needle, etc), other parameters are Z' mentality. The complete list of array functions are viewable here.

SPL: array array_map ( callable $callback, array $arr1, array $_ = null) { }

Normie: array norm_array_map( array $array, callable $callback, array $userdata = null): array

Strings fn()

Normie string functions follow the 'Search X string or Y target, replace with Z string' mentality. The complete list of string functions are viewable here.

SPL: array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )

Collapse
 
biros profile image
Boris Jamot ✊ /

Hi David,

I don't use the SPL that much and honestly, its lack of consistency doesn't bother me.
I hope PHP8 will move this in the right way.

Anyway, you made a great job for the community by providing this library.

Collapse
 
marconicolodi profile image
Marco Nicolodi

Lean & Elegant