Giter Site home page Giter Site logo

khalyomede / expose Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 24 KB

Expose your classes through functions to speed up your development

Home Page: https://packagist.org/packages/khalyomede/expose

Shell 10.97% Batchfile 2.17% PHP 86.86%
productivity php class function expose speedup development

expose's Introduction

Warning

This package is now abandoned because of security issue regarding a core function of php (more information by following this link).

Expose

PHP from Packagist Packagist Packagist

Expose your classes through functions to speed up your development.

From

$collection = new Collection(['Dreamer', 'Thunderbird', 'Eclipse']);

$items = $collection->all();

To

Expose::make('Collection', 'collect');

$items = collect(['Dreamer', 'Thunderbird', 'Eclipse'])->all();

Summary

Prerequisites

  • PHP version >= 7.0.0

Installation

In your project folder:

composer require khalyomede/expose:1.*

Examples of uses

All the examples are available inside /example folder.

All the examples bellow assume the following classes exists:

class Collection {
  protected $items;

  public function __construct($items) {
    $this->items = $items;
  }

  public function all() {
    return $this->items;
  }
}

class Log {
  protected $message;

  public function __construct($message) {
    $this->message = $message;
  }

  public function error() {
    echo sprintf('Error: %s', $this->message) . PHP_EOL;
  }
}

Example 1: exposing a simple class

use Khalyomede\Expose;

Expose::make('Collection', 'collection');

// or 

Expose::make(Collection::class, 'collection');

$items = collection(['Thunderbird', 'Polaris', 'Eclipse'])->all();

print_($items);

Will display:

Array 
(
  [0] => Thunderbird
  [1] => Polaris
  [2] => Eclipse
)

Example 2: exposing multiple classes at once

use Khalyomede\Expose;

Expose::make([
  [Collection::class, 'collector'],
  [Log::class, 'logging'] // beware of existing functions!
]);

$items = collector(['Thunderbird', 'Polaris', 'Eclipse'])->all();

print_r($items);

logging("duplicate entry 'Dreamer' on line 9")->error();

Will display:

Array
(
  [0] => Thunderbird
  [1] => Polaris
  [2] => Eclipse
)
duplicate entry 'Dreamer' on line 9

Methods definition

make()

Expose the class using its alias a shortcut, and create the related function.

public static function make(string $class_name, string $function_name): void
public static function make(array $exposures): void

Exceptions

InvalidArgumentException:

  • If the first parameter is not a string when using 2 parameters
  • If the second parameter is not a string when using 2 parameters
  • If the function name already exists
  • If the parameter is not an array when using a single parameter
  • If the parameter is not an array of array when using a single parameter
  • If the paramter is not an array of array containing string when using a single parameter
  • If the parameter contains an empty row on its array of array when using a single parameter

Note

This function can exposes static classes as well.

MIT Licence

Expose

Copyright © 2018 Khalyomede

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the oftware, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN CTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

expose's People

Contributors

khalyomede avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.