PHP code example of shinepress / globals

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

    

shinepress / globals example snippets


use ShinePress\Framework\Module;
use ShinePress\Globals\RegisterGlobal;

#[RegisterGlobal('module')] // registers as $module
#[RegisterGlobal] // registers as $ExampleModule
class ExampleModule extends Module {

	public function hello(): string {
		return 'world';
	}
}

ExampleModule::register();

global $module;
print $module->hello();
// prints: 'world'

global $ExampleModule;
print $ExampleModule->hell();
// prints: 'world'

use ShinePress\Framework\Module;
use ShinePress\Globals\RegisterGlobal;

class ExampleModule extends Module {

	#[RegisterGlobal('testProperty')]
	public string $myProperty = 'foo';
}

ExampleModule::register();

global $testProperty;
print $testProperty;
// prints: 'foo';

$testProperty = 'bar';
print ExampleModule::instance()->myProperty;
// prints: 'bar'

use ShinePress\Framework\Module;
use ShinePress\Globals\RegisterGlobal;

class ExampleModule extends Module {

	#[RegisterGlobal('TEST_CONSTANT')]
	public const MY_CONSTANT = 'foobar';
}

ExampleModule::register();

print TEST_CONSTANT;
// prints: 'foobar'

use ShinePress\Framework\Module;
use ShinePress\Globals\RegisterGlobal;

class ExampleModule extends Module {

	#[RegisterGlobal('toLowercase')]
	public function lowercase(string $input): string {
		return strtolower($input);
	}

	#[RegisterGlobal('toUppercase')]
	public function uppercase(string $input): string {
		return strtoupper($input);
	}
}

ExampleModule::register();

print toLowercase('HELLOWORLD');
// prints: 'helloworld'

print toUppercase('helloworld');
// prints: 'HELLOWORLD'