PHP code example of flsouto / obj2cli

1. Go to this page and download the library: Download flsouto/obj2cli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flsouto / obj2cli example snippets


 // my_app.php

ction say_hello(){
		echo "Hello!";
	}

	function say($what){
		echo $what;
	}

}

obj2cli(new MyApp());


$ php my_app.php

 
 MyApp{
	
	function generate_file_name($name, $ext='txt'){
		echo $name.'.'.$ext;
	}

}

obj2cli(new MyApp());



s MyApp{
	
	function multiply($number){
		return new Multiply($number);
	}

}

class Multiply{

	var $number;

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

	function by($number2){
		echo $this->number * $number2;
	}

}

obj2cli(new MyApp());

// ...
class Multiply{

	var $number;

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

	// Customize name of context
	function getObj2cliName(){
		return "Multiply $this->number....";
	}

	function by($number2){
		echo $this->number * $number2;
	}

}
//...

$ php run.php /path/to/file.php MyClass arg1 arg2
MyClass> 

$ php run.php /path/to/vendor/autoload.php SomeClass arg1 arg2
SomeClass>