定制 vboivin/superglobals 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vboivin/superglobals

最新稳定版本:v2.0.0

Composer 安装命令:

composer require vboivin/superglobals

包简介

Type-safe access to php superglobals

README 文档

README

CI

Type-safe access to php superglobals.

Components

Server

Class representing the $_SERVER superglobal.

Example of accessing 'REQUEST_METHOD' on $_SERVER:

use type Superglobals\Server;

$server = new Server();
$server->$REQUEST_METHOD; // 'GET', 'HEAD', 'POST', 'PUT', etc. or null

Example of using the raw $_SERVER superglobal:

use type Superglobals\Server;

$unsafeServer = Server::_UNSAFE();
$unsafeServer['REQUEST_METHOD']; // 'GET', 'HEAD', 'PUT', etc. or null
$unsafeServer['UNKNOWN_VARIABLE']; // Could be anything

Get

Class representing the $_GET superglobal.

Example of using $_GET with a user defined query string:

use type Superglobals\{Get, QueryString, QueryVariable};

<<QueryString>>
final class PersonQuery {
    <<QueryVariable>> public ?int $age;
    <<QueryVariable>> public ?string $name;
}

$query = new Get(PersonQuery::class);
$query?->data?->age; // Do something with the person's age
$query?->data?->name; // Do something with the person's name

Post

Class representing the $_POST superglobal.

Example of using $_POST with a user defined form:

use type Superglobals\{Form, FormVariable, Post};

<<Form>>
final class SignupForm {
    <<FormVariable>> public ?int $age;
    <<FormVariable>> public ?string $name;
    <<FormVariable>> public ?string $email;
}

$form = new Post(SignupForm::class);
$form?->data?->age; // Do something with the person's age
$form?->data?->name; // Do something with the person's name
$form?->data?->email; // Do something with the person's email

Cookies

Class representing the $_COOKIE superglobal.

Example of using $_COOKIE with user defined cookies:

use type Superglobals\{Cookie, Cookies, CookiesData};

<<CookiesData>>
final class MyCookies {
    <<Cookie>> public ?string $foo;
    <<Cookie>> public ?int $bar;
    <<Cookie>> public ?float $baz;
}

$cookies = new Cookies(MyCookies::class);
$fooCookie = $cookies?->data?->foo; // Do something with the data within cookie 'foo'
$barCookie = $cookies?->data?->bar; // Do something with the data within cookie 'bar'
$bazCookie = $cookies?->data?->baz; // Do something with the data within cookie 'baz'

Session

Class representing the $_SESSION superglobal.

Example of using $_SESSION with user defined properties:

use type Superglobals\{Session, SessionData, SessionVariable};

<<SessionData>>
final class MySession {
    <<SessionVariable>> public ?string $savedID;
    <<SessionVariable>> public ?string $lastPageSeen;
}

$session = new Session(MySession::class);
$session?->data?->savedID; // Do something with the session's saved ID
$session?->data?->lastPageSeen; // Do something with the session's last seen page

SuperglobalException

This exception is thrown when you are not using a class attribute on the class being instantiated by one of the superglobals class defined in this library.

Here is an example using $_POST:

use type Superglobals\{Form, FormVariable, Post};

// INVALID CODE
final class InvalidSignupForm {
    <<FormVariable>> public ?string $name;
}
$invalidForm = new Post(InvalidSignupForm::class); // An exception will be thrown here

// VALID CODE
<<Form>>
final class ValidSignupForm {
    <<FormVariable>> public ?string $name;
}
$validForm = new Post(ValidSignupForm::class); // No exception thrown here

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  2. Commit your Changes (git commit -m 'Add some AmazingFeature')
  3. Push to the Branch (git push origin feature/AmazingFeature)
  4. Open a Pull Request

License

Superglobals is MIT-licensed.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固