PHP Classes

PHP Action Class: Create objects that execute actions dynamically

Recommend this page to a friend!
  Info   View files Documentation   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 91 All time: 9,893 This week: 148Up
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: 47
All time rank: 235754 in Canada Canada
Week rank: 312 Up11 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  
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  /  bin  
File Role Description
  Accessible without login Plain text file run_integration_tests.sh Data Auxiliary data

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

  Files folder image Files  /  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  /  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  /  tests-public  
File Role Description
  Accessible without login Plain text file index.php Example Example script

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

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

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

  Files folder image Files  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:91
This week:0
All time:9,893
This week:148Up