PHP Classes

PHP Action Class: Create objects that execute actions dynamically

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 92 All time: 9,919 This week: 660Up
Version License PHP version Categories
action 1.0.0Custom (specified...7.1Language, PHP 7
Description 

Author

This package can create objects that execute actions dynamically.

It can take as parameter a string with the name of a global function or a static function of a class.

The package returns an object that has a function that can execute an action by calling the function with the name that was passed as parameter to the package.

Picture of Eduardo Luz
  Performance   Level  
Name: Eduardo Luz <contact>
Classes: 2 packages by
Country: Canada Canada
Age: 48
All time rank: 235754 in Canada Canada
Week rank: 288 Up5 in Canada Canada Up

Documentation

Action

Introduction

This class intends to make programatic and dynamic functions calls.

How to use

To use the Action class, just use the factory method, to build a new object, passing the parameters to use on this function. At the end, just execute the instance's exec method, passing optionally the additional parameters.

The URI patterns you can use are:

| Type | Example | | --------------- | ---------------------- | | Simple function | 'mySampleFunction()' | | Class method | '\namespace\MyClass::functionName()' | | REST call* | 'POST;https://user!password@my_domain.com:8081/api/v99/xpto?v1=1&v2=2#xpto' |

  • Not implemented yet

Simple function

Make a call to a global function.

Example


function multiply($x,$y) {
    return $x * $y;
}

$action = Action::factory('multiply()');

$response = $action->exec(2,5);

// result = 10

Class method

Instantiate a class object, and execute the assigned method.

Constructor

If your class have a constructor method, and require any parameter, you can suply it on 3rd parameter of factory method:


$action = Action::factory('MyClass::myFunction()',[],['constructor'=>[1,'string',false]]);


On above the case, the values 1, 'string' and false will be applied on MyClass constructor.

Examples


class MyClass {


    public function myFunction($id, $fieldName) {
        // ...
        return [
            'id' => $id,
            'field_name'=> $fieldName
        ];
    }

}


$action = Action::factory('MyClass::myFunction()', [1, 'name']);

$response = $action->exec();

print_r($response);
 

Will display:

Array 
(
    [id] => 1
    [field_name] => name
)


  Files folder image Files (23)  
File Role Description
Files folder imagebin (1 file)
Files folder imagedoc (1 file)
Files folder imagesrc (6 files, 1 directory)
Files folder imagetests-public (1 file)
Files folder imagetests-src (1 file)
Files folder imagetests (2 directories)
Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
Accessible without login Plain text file bootstrap_test.php Aux. Auxiliary script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data

  Files folder image Files (23)  /  bin  
File Role Description
  Accessible without login Plain text file run_integration_tests.sh Data Auxiliary data

  Files folder image Files (23)  /  doc  
File Role Description
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (23)  /  src  
File Role Description
Files folder imageexception (2 files)
  Plain text file Action.php Class Class source
  Plain text file ActionClassMethod.php Class Class source
  Plain text file ActionRegularFunction.php Class Class source
  Plain text file ActionRemoteAPICall.php Class Class source
  Plain text file DBAccessible.php Class Class source
  Plain text file Parameters.php Class Class source

  Files folder image Files (23)  /  src  /  exception  
File Role Description
  Plain text file FunctionNotFoundException.php Class Class source
  Plain text file InvalidURIException.php Class Class source

  Files folder image Files (23)  /  tests-public  
File Role Description
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (23)  /  tests-src  
File Role Description
  Plain text file Server.php Class Class source

  Files folder image Files (23)  /  tests  
File Role Description
Files folder imageintegration (1 file)
Files folder imageunit (5 files)

  Files folder image Files (23)  /  tests  /  integration  
File Role Description
  Plain text file ActionRemoteAPICallTest.php Class Class source

  Files folder image Files (23)  /  tests  /  unit  
File Role Description
  Plain text file ActionClassMethodTest.php Class Class source
  Plain text file ActionRegularFunctionTest.php Class Class source
  Plain text file ActionRemoteAPICallTest.php Class Class source
  Plain text file ActionTest.php Class Class source
  Plain text file ParametersTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:92
This week:0
All time:9,919
This week:660Up