跳转到内容

Phalcon 支持

注意

所有类都以前缀命名Phalcon

支持\Collection

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

    • ArrayAccess
    • ArrayIterator
    • Countable
    • InvalidArgumentException
    • IteratorAggregate
    • JsonSerializable
    • Phalcon\Support\Collection\CollectionInterface
    • Serializable
    • Traversable
  • 继承

  • 实现

    • ArrayAccess
    • CollectionInterface
    • Countable
    • IteratorAggregate
    • JsonSerializable
    • Serializable

Phalcon\Support\Collection是一个增强型的面向对象数组。它实现了: -ArrayAccess - Countable - IteratorAggregate - JsonSerializable - Serializable

它可以在应用程序中需要数据集合的任何部分使用。例如,访问全局变量时就使用了这些实现$_GET, $_POST等等。

@property 数组 $data @property 布尔值 $insensitive @property 数组 $lowerKeys

属性

/**
 * @var array
 */
protected $data;

/**
 * @var bool
 */
protected $insensitive = true;

/**
 * @var array
 */
protected $lowerKeys;

方法

public function __construct( array $data = [], bool $insensitive = bool );
Collection 构造函数。

public function __get( string $element ): mixed;
魔术 getter 方法,用于从集合中获取一个元素

public function __isset( string $element ): bool;
魔术 isset 方法,用于检查某个元素是否存在

public function __serialize(): array;

public function __set( string $element, mixed $value ): void;
魔术 setter 方法,用于为元素分配值

public function __unserialize( array $data ): void;

public function __unset( string $element ): void;
魔术 unset 方法,用于从集合中删除一个元素

public function clear(): void;
清除内部集合

public function count(): int;
计算对象中的元素数量。参见count

public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
从集合中获取元素

public function getIterator(): Traversable;
返回该类的迭代器

public function getKeys( bool $insensitive = bool ): array;
返回键作为数组

public function getValues(): array;
返回值作为数组

public function has( string $element ): bool;
判断集合中是否存在某个元素。

public function init( array $data = [] ): void;
初始化内部数组

public function jsonSerialize(): array;
指定应序列化为 JSON 的数据。参见jsonSerialize

public function offsetExists( mixed $element ): bool;
是否存在偏移量。参见offsetExists

public function offsetGet( mixed $element ): mixed;
获取偏移量。参见offsetGet

public function offsetSet( mixed $offset, mixed $value ): void;
设置偏移量。参见offsetSet

public function offsetUnset( mixed $element ): void;
移除偏移量。参见offsetUnset

public function remove( string $element ): void;
从集合中删除元素

public function serialize(): string | null;
对象的字符串表示形式。参见serialize

public function set( string $element, mixed $value ): void;
在集合中设置一个元素

public function toArray(): array;
以数组格式返回对象

public function toJson( int $options = int ): string;
以 JSON 格式返回对象

默认字符串使用以下选项进行 json_encode

JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES

查看rfc4627

public function unserialize( string $data ): void;
构造对象。参见unserialize

protected function phpJsonEncode( mixed $value, int $flags = int, int $depth = int );
@todo 当我们获取 traits 时将被移除

protected function processKey( string $element ): string;
检查是否需要不区分大小写的键,如果是,则将元素转换为小写

protected function setData( string $element, mixed $value ): void;
内部方法用于设置数据

支持\Collection\CollectionInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Collection
  • 使用

  • 继承

  • 实现

Phalcon\Support\Collection\CollectionInterface

Phalcon\Support\Collection 类的接口

方法

public function __get( string $element ): mixed;
public function __isset( string $element ): bool;
public function __set( string $element, mixed $value ): void;
public function __unset( string $element ): void;
public function clear(): void;
public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
public function getKeys( bool $insensitive = bool ): array;
public function getValues(): array;
public function has( string $element ): bool;
public function init( array $data = [] ): void;
public function remove( string $element ): void;
public function set( string $element, mixed $value ): void;
public function toArray(): array;
public function toJson( int $options = int ): string;

集合对象的异常

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Collection
  • 使用

    • Throwable
  • 继承

    \Exception

  • 实现

Exceptions for the Collection object

只读集合对象

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Collection
  • 使用

    • Phalcon\Support\Collection
  • 继承

    Collection

  • 实现

A read only Collection object

方法

public function remove( string $element ): void;
从集合中删除元素

public function set( string $element, mixed $value ): void;
在集合中设置一个元素

支持\Debug

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

    • ErrorException
    • Phalcon\Support\Debug\Exception
    • ReflectionClass
    • ReflectionException
    • ReflectionFunction
    • Throwable
  • 继承

  • 实现

为 Phalcon 应用程序提供调试功能

属性

/**
 * @var array
 */
protected $blacklist;

/**
 * @var array
 */
protected $data;

/**
 * @var bool
 */
protected $hideDocumentRoot = false;

/**
 * @var bool
 */
protected static $isActive = false;

/**
 * @var bool
 */
protected $showBackTrace = true;

/**
 * @var bool
 */
protected $showFileFragment = false;

/**
 * @var bool
 */
protected $showFiles = true;

/**
 * @var string
    */
protected $uri = https://assets.phalcon.io/debug/5.0.x/;

/**
 * @var Version
 */
private $version;

方法

public function __construct();
构造函数设置一个可复用的版本对象

public function clearVars(): Debug;
清除之前添加的所有变量

public function debugVar( mixed $varz ): Debug;
添加一个变量到调试输出中

public function getCssSources(): string;
返回 CSS 资源

public function getJsSources(): string;
返回 JavaScript 资源

public function getVersion(): string;
生成指向当前版本文档的链接

public function halt(): void;
显示回溯信息并暂停请求

@throws Exception

public function listen( bool $exceptions = bool, bool $lowSeverity = bool ): Debug;
监听未捕获的异常、非静默通知或警告

public function listenExceptions(): Debug;
监听未捕获的异常

public function listenLowSeverity(): Debug;
监听非静默的通知或警告

public function onUncaughtException( \Throwable $exception ): bool;
处理未捕获的异常

public function onUncaughtLowSeverity( mixed $severity, mixed $message, mixed $file, mixed $line ): void;
当出现通知或警告时抛出异常

public function renderHtml( \Throwable $exception ): string;
将异常渲染为 HTML 格式。

public function setBlacklist( array $blacklist ): Debug;
设置是否显示异常回溯中的文件

public function setShowBackTrace( bool $showBackTrace ): Debug;
设置是否显示异常回溯中的文件

public function setShowFileFragment( bool $showFileFragment ): Debug;
设置文件是否必须完整打开并在输出中显示,还是只显示与异常相关的部分

public function setShowFiles( bool $showFiles ): Debug;
设置回溯中的文件是否显示在输出中

public function setUri( string $uri ): Debug;
更改静态资源的基础 URI

protected function escapeString( string $value ): string;
使用 htmlentities 转义字符串

protected function getArrayDump( array $argument, mixed $n = int ): string | null;
生成数组的递归表示形式

protected function getVarDump( mixed $variable ): string;
生成变量的字符串表示形式

final protected function showTraceItem( int $n, array $trace ): string;
显示一个回溯项

支持\Debug\Dump

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Debug
  • 使用

    • Phalcon\Di\Di
    • Phalcon\Support\Helper\Json\Encode
    • Reflection
    • ReflectionClass
    • ReflectionProperty
    • stdClass
  • 继承

  • 实现

转储关于变量的信息

$foo = 123;

echo (new \Phalcon\Debug\Dump())->variable($foo, "foo");
$foo = "string";
$bar = ["key" => "value"];
$baz = new stdClass();

echo (new \Phalcon\Debug\Dump())->variables($foo, $bar, $baz);

属性

/**
 * @var bool
 */
protected $detailed = false;

/**
 * @var array
 */
protected $methods;

/**
 * @var array
 */
protected $styles;

/**
 * @var Encode
 */
private $encode;

方法

public function __construct( array $styles = [], bool $detailed = bool );
Phalcon\Debug\Dump 构造函数

public function all(): string;
variables() 方法的别名

public function getDetailed(): bool;

public function one( mixed $variable, string $name = null ): string;
variable() 方法的别名

public function setDetailed( bool $detailed ): void;

public function setStyles( array $styles = [] ): array;
为变量类型设置样式

public function toJson( mixed $variable ): string;
返回关于单个变量的信息的 JSON 字符串。

$foo = [
    "key" => "value",
];

echo (new \Phalcon\Debug\Dump())->toJson($foo);

$foo = new stdClass();
$foo->bar = "buz";

echo (new \Phalcon\Debug\Dump())->toJson($foo);

public function variable( mixed $variable, string $name = null ): string;
返回关于单个变量的信息的 HTML 字符串。

echo (new \Phalcon\Debug\Dump())->variable($foo, "foo");

public function variables(): string;
返回关于任意数量变量的调试信息的 HTML 字符串,每个变量都被包裹在 "pre" 标签中。

$foo = "string";
$bar = ["key" => "value"];
$baz = new stdClass();

echo (new \Phalcon\Debug\Dump())->variables($foo, $bar, $baz);

protected function getStyle( string $type ): string;
获取类型样式

protected function output( mixed $variable, string $name = null, int $tab = int ): string;
准备一个关于单个变量信息的 HTML 字符串。

支持\调试\异常

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Debug
  • 使用

  • 继承

    \Exception

  • 实现

在 Phalcon\Debug 中抛出的异常将使用此类

支持\异常

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

  • 继承

    \Exception

  • 实现

Phalcon\Support\Exception

支持\Helper\Arr\AbstractArrAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

提供用于 Arr 命名空间的辅助方法的抽象类。一旦 Zephir 支持,可以将其移至 trait。

@todo 等待支持时移至 trait

方法

protected function toFilter( array $collection, mixed $method = null ): array;
过滤集合的辅助方法

支持\Helper\Arr\Blacklist

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

按键黑名单过滤:通过从黑名单元素获得的键排除数组中的元素

方法

public function __invoke( array $collection, array $blackList ): array;

支持\Helper\Arr\Chunk

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

将数组分割为指定大小的更小数组。

方法

public function __invoke( array $collection, int $size, bool $preserveKeys = bool ): array;

支持\Helper\Arr\Filter

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

使用 array_filter 对集合进行过滤,并在定义了可调用对象时使用它。

方法

public function __invoke( array $collection, mixed $method = null ): mixed;

支持\Helper\Arr\First

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回集合的第一个元素。如果传入了一个可调用对象,则返回第一个验证为 true 的元素

方法

public function __invoke( array $collection, mixed $method = null ): mixed;

支持\Helper\Arr\FirstKey

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回集合中第一个元素的键。如果传入了一个可调用对象,则返回第一个验证为 true 的元素的键

方法

public function __invoke( array $collection, mixed $method = null ): mixed;

支持\Helper\Arr\Flatten

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

将数组扁平化到一个层级深度,除非另有说明。$deep被设置为true

方法

public function __invoke( array $collection, bool $deep = bool ): array;

支持\Helper\Arr\Get

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

通过键获取数组元素,如果不存在则返回默认值。它还允许使用特定类型对返回值进行强制转换。settype内部使用

方法

public function __invoke( array $collection, mixed $index, mixed $defaultValue = null, string $cast = null ): mixed;

支持\Helper\Arr\Group

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

根据传入的可调用对象对数组元素进行分组

方法

public function __invoke( array $collection, mixed $method ): array;

支持\Helper\Arr\Has

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

检查数组是否具有特定键的元素并返回结果。true/false根据情况返回相应的布尔值。

方法

public function __invoke( array $collection, mixed $index ): bool;

支持\Helper\Arr\IsUnique

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

检查扁平列表是否有重复值。如果有重复值则返回 true,否则返回 false。

方法

public function __invoke( array $collection ): bool;

支持\Helper\Arr\Last

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回集合的最后一个元素。如果传入了一个可调用对象,则返回第一个验证为 true 的元素

方法

public function __invoke( array $collection, mixed $method = null ): mixed;

支持\Helper\Arr\LastKey

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回集合中最后一个元素的键。如果传入了一个可调用对象,则返回第一个验证为 true 的元素的键

方法

public function __invoke( array $collection, mixed $method = null ): mixed;

支持\Helper\Arr\Order

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

按对象的属性对数组或对象集合进行排序。它支持升序/降序排序,以及与ksortkrsort

常量

const ORDER_ASC = 1;
const ORDER_DESC = 2;

方法

public function __invoke( array $collection, mixed $attribute, int $order = static-constant-access, int $flags = int ): array;

所使用的标志相同的支持。

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

返回基于集合值的一个子集

方法

public function __invoke( array $collection, string $element ): array;

支持\Helper\Arr\Set

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

设置一个数组元素。使用键是可选的。

方法

public function __invoke( array $collection, mixed $value, mixed $index = null ): array;

支持\Helper\Arr\SliceLeft

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

返回一个新数组,从左侧移除了 n 个元素。

方法

public function __invoke( array $collection, int $elements = int ): array;

支持\Helper\Arr\SliceRight

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

返回一个新数组,从右侧移除了 n 个元素。

方法

public function __invoke( array $collection, int $elements = int ): array;

支持\Helper\Arr\Split

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

返回一个新数组,其中集合的键作为一个元素,值作为另一个元素。

方法

public function __invoke( array $collection ): array;

支持\Helper\Arr\ToObject

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

  • 实现

返回传递的数组作为对象。

方法

public function __invoke( array $collection ): object;

支持\Helper\Arr\ValidateAll

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回true如果提供的函数返回true对于集合的所有元素,false

方法

public function __invoke( array $collection, mixed $method ): bool;

支持\Helper\Arr\ValidateAny

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

返回true如果提供的函数返回true对于集合中至少一个元素,false

方法

public function __invoke( array $collection, mixed $method ): bool;

支持\Helper\Arr\Whitelist

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Arr
  • 使用

  • 继承

    AbstractArr

  • 实现

按键白名单过滤:通过从白名单元素获得的键来筛选数组元素

方法

public function __invoke( array $collection, array $whiteList ): array;

支持\Helper\Exception

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper
  • 使用

  • 继承

    \Exception

  • 实现

  • Phalcon\Support\Exception */

支持\Helper\File\Basename

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\File
  • 使用

  • 继承

  • 实现

从给定路径获取文件名,功能等同于 PHP 的basename()但它支持非 ASCII 编码。PHP 的basename()不正确支持流或者以非 US-ASCII 字符开头的文件名。

方法

public function __invoke( string $uri, string $suffix = null ): string;
@see https://bugs.php.net/bug.php?id=37738

支持\Helper\Json\Decode

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Json
  • 使用

    • InvalidArgumentException
  • 继承

  • 实现

使用json_decode解码字符串,如果 JSON 数据无法解码,则抛出异常

如果未为 json_encode 指定选项,将使用以下选项

JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES

如果在选项中定义了 JSON_THROW_ON_ERROR,则在发生错误时会抛出 JsonException。否则,任何错误都会抛出 InvalidArgumentException

方法

public function __invoke( string $data, bool $associative = bool, int $depth = int, int $options = int );

支持\Helper\Json\Encode

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Json
  • 使用

    • InvalidArgumentException
  • 继承

  • 实现

使用json_encode编码字符串,如果 JSON 数据无法编码,则抛出异常

如果未为 json_encode 指定选项,将使用以下选项

JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES

如果在选项中定义了 JSON_THROW_ON_ERROR,则在发生错误时会抛出 JsonException。否则,任何错误都会抛出 InvalidArgumentException

@see https://www.ietf.org/rfc/rfc4627.txt

方法

public function __invoke( mixed $data, int $options = int, int $depth = int ): string;

支持\Helper\Number\IsBetween

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Number
  • 使用

  • 继承

  • 实现

检查数字是否在某个范围内

方法

public function __invoke( int $value, int $start, int $end ): bool;

支持\Helper\Str\AbstractStrAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

提供用于 Str 命名空间的辅助方法的抽象类。一旦 Zephir 支持,可以将其移至 trait。

@todo 等待支持时移至 trait

方法

protected function toEndsWith( string $haystack, string $needle, bool $ignoreCase = bool ): bool;
检查一个字符串是否以给定字符串结束

protected function toInterpolate( string $input, array $context = [], string $left = string, string $right = string ): string;
将上下文值插入消息占位符中

@see https://www.php-fig.org/psr/psr-3/ 第1.2节 Message

protected function toLower( string $text, string $encoding = string ): string;
使用 mbstring 将字符串转为小写

protected function toStartsWith( string $haystack, string $needle, bool $ignoreCase = bool ): bool;
检查一个字符串是否以给定字符串开始

protected function toUpper( string $text, string $encoding = string ): string;
使用 mbstring 将字符串转为大写

支持\Helper\Str\Camelize

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    PascalCase

  • 实现

将字符串转换为 UpperCamelCase 或 lowerCamelCase

方法

public function __invoke( string $text, string $delimiters = null, bool $lowerFirst = bool ): string;

支持\Helper\Str\Concat

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

    • Phalcon\Support\Helper\Exception
  • 继承

    AbstractStr

  • 实现

使用分隔符仅一次连接字符串,避免连接处重复

方法

public function __invoke(): string;

支持\Helper\Str\CountVowels

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

返回所提供字符串中的元音数量。使用正则表达式计算字符串中的元音(A,E,I,O,U)数量。

方法

public function __invoke( string $text ): int;

Support\Helper\Str\Decapitalize

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

将字符串的第一个字母小写,然后将其与字符串的其余部分组合在一起。如果要保留字符串的其余部分,请省略upperRest参数;若将其设置为true,则将字符串其余部分转换为大写。

方法

public function __invoke( string $text, bool $upperRest = bool, string $encoding = string ): string;

Support\Helper\Str\Decrement

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

从字符串末尾移除一个数字,或者如果该数字已经存在则将其减一

方法

public function __invoke( string $text, string $separator = string ): string;

Support\Helper\Str\DirFromFile

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

接受一个文件名(不带扩展名),并返回计算后的目录结构,文件名位于最后

方法

public function __invoke( string $file ): string;

Support\Helper\Str\DirSeparator

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

接受一个目录名称,并确保其以DIRECTORY_SEPARATOR结尾

方法

public function __invoke( string $directory ): string;

Support\Helper\Str\Dynamic

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

    • RuntimeException
  • 继承

  • 实现

根据模板生成随机文本。模板由左右定界符定义,并且可以包含由分隔符分隔的值

方法

public function __invoke( string $text, string $leftDelimiter = string, string $rightDelimiter = string, string $separator = string ): string;

Support\Helper\Str\EndsWith

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

检查一个字符串是否以给定字符串结束

方法

public function __invoke( string $haystack, string $needle, bool $ignoreCase = bool ): bool;

Support\Helper\Str\FirstBetween

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

返回参数start和end所指定的两个字符串之间的第一个字符串。

方法

public function __invoke( string $text, string $start, string $end ): string;

Support\Helper\Str\Friendly

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

    • Phalcon\Support\Helper\Exception
  • 继承

    AbstractStr

  • 实现

将文本转换为适合URL使用的格式。将常见的带重音字符替换为其对应的拉丁字母。如果传递了replace字符串或数组,也将使用它将这些字符替换为空格。

方法

public function __invoke( string $text, string $separator = string, bool $lowercase = bool, mixed $replace = null ): string;

Support\Helper\Str\Humanize

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

让下划线或短横线连接的文本变得易于阅读

方法

public function __invoke( string $text ): string;

Support\Helper\Str\Includes

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

判断一个字符串是否包含另一个字符串

方法

public function __invoke( string $haystack, string $needle ): bool;

Support\Helper\Str\Increment

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

在字符串末尾添加一个数字,或者如果该数字已经存在则将其加一

方法

public function __invoke( string $text, string $separator = string ): string;

Support\Helper\Str\Interpolate

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

将上下文值插入到消息占位符中。默认情况下,左右标记是%

@see https://www.php-fig.org/psr/psr-3/ 第1.2节 Message

方法

public function __invoke( string $message, array $context = [], string $leftToken = string, string $rightToken = string ): string;

Support\Helper\Str\IsAnagram

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

比较两个字符串并返回true如果两个字符串是变位词,false

方法

public function __invoke( string $first, string $second ): bool;

Support\Helper\Str\IsLower

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

返回true如果给定字符串全部为小写,false

方法

public function __invoke( string $text, string $encoding = string ): bool;

Support\Helper\Str\IsPalindrome

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

返回true如果给定字符串为回文,false

方法

public function __invoke( string $text ): bool;

Support\Helper\Str\IsUpper

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

返回true如果给定字符串全部为大写,false

方法

public function __invoke( string $text, string $encoding = string ): bool;

Support\Helper\Str\KebabCase

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    PascalCase

  • 实现

将字符串转换为kebab-case风格

方法

public function __invoke( string $text, string $delimiters = null ): string;

Support\Helper\Str\Len

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

使用以下方式计算字符串长度:mb_strlen

方法

public function __invoke( string $text, string $encoding = string ): int;

Support\Helper\Str\Lower

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

使用mbstring将字符串转换为小写

方法

public function __invoke( string $text, string $encoding = string ): string;

Support\Helper\Str\PascalCase

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

将字符串转换为PascalCase风格

方法

public function __invoke( string $text, string $delimiters = null ): string;
protected function processArray( string $text, string $delimiters = null ): array;

Support\Helper\Str\Prefix

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

使用提供的前缀对文本进行前缀添加

方法

public function __invoke( mixed $text, string $prefix ): string;

Support\Helper\Str\Random

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

根据给定类型生成随机字符串。类型是RANDOM_*常量之一

常量

const RANDOM_ALNUM = 0;
const RANDOM_ALPHA = 1;
const RANDOM_DISTINCT = 5;
const RANDOM_HEXDEC = 2;
const RANDOM_NOZERO = 4;
const RANDOM_NUMERIC = 3;

方法

public function __invoke( int $type = static-constant-access, int $length = int ): string;

Support\Helper\Str\ReduceSlashes

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

将字符串中的多个斜杠减少为单个斜杠

方法

public function __invoke( string $text ): string;

Support\Helper\Str\SnakeCase

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    PascalCase

  • 实现

将字符串转换为snake_case风格

方法

public function __invoke( string $text, string $delimiters = null ): string;

Support\Helper\Str\StartsWith

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

检查一个字符串是否以给定字符串开始

方法

public function __invoke( string $haystack, string $needle, bool $ignoreCase = bool ): bool;

Support\Helper\Str\Suffix

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

使用提供的后缀对文本进行后缀添加

方法

public function __invoke( mixed $text, string $suffix ): string;

Support\Helper\Str\Ucwords

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

大写每个单词的首字母

方法

public function __invoke( string $text, string $encoding = string ): string;

Support\Helper\Str\Uncamelize

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

将字符串转换为非驼峰式风格

方法

public function __invoke( string $text, string $delimiter = string ): string;

Support\Helper\Str\Underscore

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

  • 实现

用下划线代替空格来表示文本

方法

public function __invoke( string $text ): string;

Support\Helper\Str\Upper

GitHub上的源码

  • 命名空间

    • Phalcon\Support\Helper\Str
  • 使用

  • 继承

    AbstractStr

  • 实现

使用mbstring将字符串转换为大写

方法

public function __invoke( string $text, string $encoding = string ): string;

Support\HelperFactory

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

    • Phalcon\Factory\AbstractFactory
  • 继承

    AbstractFactory

  • 实现

Helper的ServiceLocator实现

@method string basename(string $uri, string $suffix = null) @method array blacklist(array $collection, array $blackList) @method string camelize(string $text, string $delimiters = null, bool $lowerFirst = false) @method array chunk(array $collection, int $size, bool $preserveKeys = false) @method string concat(string $delimiter, string $first, string $second, string ...$arguments) @method int countVowels(string $text) @method string decapitalize(string $text, bool $upperRest = false, string $encoding = 'UTF-8') @method string decode(string $data, bool $associative = false, int $depth = 512, int $options = 0) @method string decrement(string $text, string $separator = '') @method string dirFromFile(string $file) @method string dirSeparator(string $directory) @method string dynamic(string $text, string $leftDelimiter = "{", string $rightDelimiter = "}", string $separator = "|") @method string encode($data, int $options = 0, int $depth = 512) @method bool endsWith(string $haystack, string $needle, bool $ignoreCase = true) @method mixed filter(array $collection, callable|null $method) @method mixed first(array $collection, callable $method = null) @method string firstBetween(string $text, string $start, string $end) @method mixed firstKey(array $collection, callable $method = null) @method string friendly(string $text, string $separator = '-', bool $lowercase = true, $replace = null) @method array flatten(array $collection, bool $deep = false) @method mixed get(array $collection, $index, $defaultValue = null, string $cast = null) @method array group(array $collection, $method) @method bool has(array $collection, $index) @method string humanize(string $text) @method bool includes(string $haystack, string $needle) @method string increment(string $text, string $separator = '') @method string interpolate(string $message, array $context = [], string $leftToken = "%", string $rightToken = "%") @method bool isAnagram(string $first, string $second) @method bool isBetween(int $value, int $start, int $end) @method bool isLower(string $text, string $encoding = 'UTF-8') @method bool isPalindrome(string $text) @method bool isUnique(array $collection) @method bool isUpper(string $text, string $encoding = 'UTF-8') @method string kebabCase(string $text, string $delimiters = null) @method mixed last(array $collection, callable $method = null) @method mixed lastKey(array $collection, callable $method = null) @method int len(string $text, string $encoding = 'UTF-8') @method string lower(string $text, string $encoding = 'UTF-8') @method array order(array $collection, $attribute, string $order = 'asc') @method string pascalCase(string $text, string $delimiters = null) @method array pluck(array $collection, string $element) @method string prefix($text, string $prefix) @method string random(int $type = 0, int $length = 8) @method string reduceSlashes(string $text) @method array set(array $collection, $value, $index = null) @method array sliceLeft(array $collection, int $elements = 1) @method array sliceRight(array $collection, int $elements = 1) @method string snakeCase(string $text, string $delimiters = null) @method array split(array $collection) @method bool startsWith(string $haystack, string $needle, bool $ignoreCase = true) @method string suffix($text, string $suffix) @method object toObject(array $collection) @method bool validateAll(array $collection, callable $method) @method bool validateAny(array $collection, callable $method) @method string ucwords(string $text, string $encoding = 'UTF-8') @method string uncamelize(string $text, string $delimiters = '_') @method string underscore(string $text) @method string upper(string $text, string $encoding = 'UTF-8') @method array whitelist(array $collection, array $whiteList)

方法

public function __call( string $name, array $arguments );

public function __construct( array $services = [] );
FactoryTrait 构造函数。

public function newInstance( string $name );
protected function getExceptionClass(): string;

protected function getServices(): array;
返回可用的适配器

Support\RegistryFinal

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

    • Phalcon\Support\Collection
    • Traversable
  • 继承

    Collection

  • 实现

Phalcon\Registry

注册表是用于在应用程序空间中存储对象和值的容器。通过在注册表中存储值,可以确保相同对象在整个应用程序中始终可用。

$registry = new \Phalcon\Registry();

// Set value
$registry->something = "something";
// or
$registry["something"] = "something";

// Get value
$value = $registry->something;
// or
$value = $registry["something"];

// Check if the key exists
$exists = isset($registry->something);
// or
$exists = isset($registry["something"]);

// Unset
unset($registry->something);
// or
unset($registry["something"]);

除了 ArrayAccess 外,Phalcon\Registry 还实现了 Countable(count($registry) 将返回注册表中的元素数量)、Serializable 和 Iterator(您可以使用 foreach 循环遍历注册表)接口。对于 PHP 5.4 及以上版本,还实现了 JsonSerializable 接口。

Phalcon\Registry 非常快速(通常比用户空间实现的任何注册表都要快);但这也带来了一定代价:Phalcon\Registry 是一个 final 类,不能被继承。

虽然 Phalcon\Registry 暴露了如 __get()、offsetGet()、count() 等方法,但不建议手动调用它们(这些方法主要存在是为了匹配注册表所实现的接口):$registry->__get("property") 比 $registry->property 慢很多倍。

所有魔术方法(JsonSerializable 除外)内部都是通过对象处理器或类似技术实现的:这允许绕过相对较慢的方法调用。

方法

final public function __construct( array $data = [] );
构造函数

final public function __get( string $element ): mixed;
魔术 getter 方法,用于从集合中获取一个元素

final public function __isset( string $element ): bool;
魔术 isset 方法,用于检查某个元素是否存在

final public function __set( string $element, mixed $value ): void;
魔术 setter 方法,用于为元素分配值

final public function __unset( string $element ): void;
魔术 unset 方法,用于从集合中删除一个元素

final public function clear(): void;
清除内部集合

final public function count(): int;
计算对象的元素数量

@link https://php.net/manual/en/countable.count.php

final public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
从集合中获取元素

final public function getIterator(): Traversable;
返回该类的迭代器

final public function has( string $element ): bool;
判断集合中是否存在某个元素。

final public function init( array $data = [] ): void;
初始化内部数组

final public function jsonSerialize(): array;
指定应序列化为 JSON 的数据

@link https://php.net/manual/en/jsonserializable.jsonserialize.php

final public function offsetExists( mixed $element ): bool;
检查偏移位置是否存在

@link https://php.net/manual/en/arrayaccess.offsetexists.php

final public function offsetGet( mixed $element ): mixed;
要检索的偏移位置

@link https://php.net/manual/en/arrayaccess.offsetget.php

final public function offsetSet( mixed $offset, mixed $value ): void;
要设置的偏移位置

@link https://php.net/manual/en/arrayaccess.offsetset.php

final public function offsetUnset( mixed $element ): void;
要取消设置的偏移位置

@link https://php.net/manual/en/arrayaccess.offsetunset.php

final public function remove( string $element ): void;
从集合中删除元素

final public function serialize(): string | null;
对象的字符串表示形式

@link https://php.net/manual/en/serializable.serialize.php

final public function set( string $element, mixed $value ): void;
在集合中设置一个元素

final public function toArray(): array;
以数组格式返回对象

final public function toJson( int $options = int ): string;
以 JSON 格式返回对象

默认字符串使用以下选项进行 json_encode

JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES

@see https://www.ietf.org/rfc/rfc4627.txt

final public function unserialize( string $data ): void;
构造对象

@link https://php.net/manual/en/serializable.unserialize.php

Support\Version

GitHub上的源码

  • 命名空间

    • Phalcon\Support
  • 使用

  • 继承

  • 实现

此类允许获取框架的安装版本

常量

const VERSION_MAJOR = 0;
const VERSION_MEDIUM = 1;
const VERSION_MINOR = 2;
const VERSION_SPECIAL = 3;
const VERSION_SPECIAL_NUMBER = 4;

方法

public function get(): string;
返回当前版本(字符串)

echo (new Phalcon\Version())->get();

public function getId(): string;
返回数字格式的当前版本

echo (new Phalcon\Version())->getId();

public function getPart( int $part ): string;
返回版本的特定部分。如果传递了错误参数,则将返回完整版本

echo (new Phalcon\Version())->getPart(Phalcon\Version::VERSION_MAJOR);

protected function getVersion(): array;
设置版本号的区域。格式如下:ABBCCDE

A - 主版本号 B - 中版本号(两位数) C - 次版本号(两位数) D - 特殊发布版本:1 = alpha,2 = beta,3 = RC,4 = 稳定版 E - 特殊发布子版本,例如 RC1、Beta2 等。

无噪 Logo
无噪文档
25 年 6 月翻译
版本号 5.9
文档源↗