PHP Classes

PHP Global Class Functions Hack Pack: Generate functions to call given class objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 159 This week: 1All time: 8,976 This week: 560Up
Version License PHP version Categories
hackpack 0.1GNU General Publi...5PHP 5, Language
Description 

Author

This class can generate functions to call given class objects.

It take a list of classes and with function names and generate global functions that will create objects of the given classes when called.

The classes may have associated name spaces to disambiguate when there are classes of the same name in different name spaces.

Innovation Award
PHP Programming Innovation award nominee
January 2017
Number 12


Prize: One downloadable e-book of choice by O'Reilly
When you need to call static functions of classes of a different namespaces, you may need to type long class function names including the class namespace.

This class provides a solution to simplify the problem by providing means registered functions with a simple function name of the class object.

Manuel Lemos
Picture of Omar Andrés Barbosa Ortiz
  Performance   Level  
Name: Omar Andrés Barbosa ... is available for providing paid consulting. Contact Omar Andrés Barbosa ... .
Classes: 3 packages by
Country: Colombia Colombia
Age: ???
All time rank: 380922 in Colombia Colombia
Week rank: 416 Up2 in Colombia Colombia Up
Innovation award
Innovation award
Nominee: 2x

Documentation

HackPack: This package allows calling classes in function style, through the use of a PHP hack.

Installation

To install via composer (http://getcomposer.org/), place the following in your composer.json file:

{
    "require": {
        "barbosa/hackpack": "dev-master"
    }
}

or download package from github.com:

http://github.com/barbosa89/hackpack

Configuration

Consider the following folder structure:

/project
    /src
        MainClass.php
        Router.php
        TextProcessing.php
        Request.php
        services.php
    /test

The services.php file, returns an array with an alias and the corresponding namespace and the following sintax:


<?php 

/
 * file: services.php
 */

return [

    'router' => Some\Namespace\Router::class,
    'text' => Some\Namespace\TextProcessing::class,
    'request' => Some\Namespace\Request::class  

];

In the MainClass.php file, invoke to ServiceLoader::load() method:


<?php

namespace Some\Namespace;

use Barbosa\HackPack\ServiceLoader;

class MainClass
{
    public function __construct
    {
        $services = require 'services.php';
        ServiceLoader::load($services);
    }
}

The ServiceLoader::load() method loads the objects in function style, wich are available in the application.

Now you can invoke services in functions style from anywhere in the application. Example:

<?php

namespace Some\Namespace;

use Barbosa\HackPack\ServiceLoader;

class MainClass
{
    public function __construct
    {
        $aliases = require 'services.php';
        ServiceLoader::load($services);
    }

    public function resolveUri($uri)
    {
        return request()->parseUri($uri);
    }
}

The object name in function style, depends on the name assigned in the array. This is an alternative to Packager Library.

Examples

# Pass parameters to the constructor
request($uri)->parseUri();

# Pass parameters to methods
request()->parseUri($uri);

# Chaining of methods
request()->parseUri($uri)->getResult();

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

Thanks...

Omar Andrés Barbosa


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONDUCT.md Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file ServiceLoader.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageSimulations (3 files)
Files folder imageUnit (1 file)

  Files folder image Files  /  tests  /  Simulations  
File Role Description
  Plain text file Request.php Class Class source
  Plain text file Router.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file ServiceLoaderTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:159
This week:1
All time:8,976
This week:560Up