ocolin/global-type 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ocolin/global-type

最新稳定版本:v2.0.0

Composer 安装命令:

composer require ocolin/global-type

包简介

Simple library for making sure global variables are of a specific type

README 文档

README

Description

GlobalType is a simple library that allows type checks on global arrays. Because by default the array elements are mixed, one has to check the element type before using. This library makes it easier to tell PHP what type you are expecting from a global array.

Requirements

The only requirement is PHP version 8.0 or higher.

Installation

composer require ocolin/global-type

Usage

Available Classes

GlobalType has a class for each of the PHP Globals:

Class Global
COOKIE::class $_COOKIE
ENV::class $_ENV
FILES::class $_FILES
GET::class $_GET
GLOBALS::class $GLOBALS
POST::class $_POST
REQUEST::class $_REQUEST
SERVER::class $_SERVER
SESSION::class $_SESSION

Available Methods

Every class shares the same functions which are used on the classes corresponding PHP Global

Method Description
getString Return a string or '' if not found.
getStringNull Return a string or null if not found.
getInt Return an int or 0 if not found.
getIntNull Return an int or null if not found.
getFloat Return a float or 0.0 if not found.
getFloatNull Return a float of null if not found.
getBool Return a bool or false if not found.
getBoolNull Return a bool or null if not found.
getArray Return an array or [] if not found.
getArrayNull Return an array or null if not found.
getObject Return same object or null if not found.

Arguments

Both the Null and non-Null methods take a name parameter, while the Null methods only take a name argument.

  • name - The name of the array key in the targeted PHP global.
  • default - If the element is not found or the type does not match, you can return a default value of your choice.

Basic Usage

use Ocolin\GlobalType\GET;
$_GET['parameter'] = 'value';

$value = GET::getString( name: 'parameter' );
// string(5) "value"

$value = GET::getInt( name: 'parameter' );
// int(0)

$value = GET::getIntNull( name: 'parameter' );
// NULL

$value = GET::getInt( name: 'parameter', default: 777 );
//int(777)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固