PHP code example of shinepress / framework

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


use ShinePress\Framework\Module;

class MyModule extends Module {
	
	protected function initialize(): void {
		// runs during constructor
	}

	protected function prepare(): void {
		// runs before registration
	}

	protected function cleanup(): void {
		// runs after registration
	}
}

// register the module
MyModule::register();


use ShinePress\Framework\Attribute\MethodAttributeInterface;
use ShinePress\Framework\Module;
use Attribute;
use ReflectionMethod;

#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class ActionHook implements MethodAttributeInterface {
	private string $name;
	private int $priority;

	public function __construct(string $name, int $priority = 10) {
		$this->name = $name;
		$this->priority = $priority;
	}

	public function register(Module $module, ReflectionMethod $method): void;
		add_action(
			$this->name,
			[$module, $method->getName()],
			$this->priority,
			$method->getNumberOfParameters(),
		);
	}
}

class MyModule extends Module {

	#[ActionHook('save_post', 20)]
	public function onSavePost($post_id, $post, $update): void {
		// do something...
	}
}

MyModule::register();