承接 shinepress/globals 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shinepress/globals

最新稳定版本:1.0.0

Composer 安装命令:

composer require shinepress/globals

包简介

Allow ShinePress modules to register global functions and variables.

README 文档

README

License Latest Version PHP Version Main Status Release Status Develop Status

Description

Add-on for shinepress/framework to allow registering of global variables, functions, and constants for use outside of modules.

Installation

The recommendend installation method is with composer:

$ composer require shinepress/globals

Usage

Add the 'RegisterGlobal' attribute to any module class/property/constant/method to register it into the global namespace.

Module Instance

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'

Module Property

Assigns a reference to the indicated class property to the global variable regardless of visibility.

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'

Module Constant

Defines a global constant with the value of the class constant regardless of visibility.

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'

Module Method

Creates a closure reference to the indicated method and assigns it to a function in the global scope.

Note: the relies on eval, with all the associated downsides.

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'

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-19