PHP code example of carloswph / mainframe

1. Go to this page and download the library: Download carloswph/mainframe 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/ */

    

carloswph / mainframe example snippets


use Mainframe\Container;

on __construct() {}

	public function print($string)
	{
		echo $string;
	}

	public function method()
	{
		echo 'C';
	}
}

class B
{
	public function __construct() {}

	public function print()
	{
		echo 'B';
	}

	public function load()
	{
		echo 'Do something';
	}
}

$container = new Container(['class_a' => new A()]); // Class A instance injected as Container array
$container->add('class_b', new B()); // Class B instance being injected after instantiation, through add()

$container->print(); // Calls only class B print()
$container->print('Test'); // Calls both class A and B print() methods
$container->method(); // Calls class A method()
$container->terminal('class_a', 'print', 'Test'); // Calls specifically class A print() and pass 'Test' as argument