lbreme/lexepa-srl
Composer 安装命令:
composer require lbreme/lexepa-srl
包简介
Class for lexing and parsing a serialized string in PHP
关键字:
README 文档
README
Library for lexing and parsing a serialized string in PHP.
Installing Lexepa-Srl
First, get Composer, if you don't already use it.
Next, run the following command inside the directory of your project:
composer require lbreme/lexepa-srl
How does it work?
The Lexepa-Srl library analyzes any text string coming from the result of a serialization in PHP. During the analysis a series of callback functions are called to which are passed as arguments the elements that constitute the serialized string.
We clarify with an example, which is contained in the file class-example-srl.php, which to make it work is to copy in the root of your project:
/*
We create a class derived from the Lexepa_Srl_Abstract class, which implements all the
callback functions that will be called by the analysis of the serialized string
*/
class Example_Srl extends Lexepa_Srl_Abstract
{
/**
* Begin of parsing
*
* @param string $string Original string to unserialize.
* @param int $offset Initial offset.
*/
public function begin_parsing( $string, $offset ) {
echo 'String serialized: ' . $string . '<br />';
}
/**
* String length value found
*
* @param string $string_length String length value.
* @param int $offset Offset of the string length value found.
*/
public function string_length( $string_length, $offset )
{
echo 'String length: ' . $string_length . '<br />';
}
/**
* String value found
*
* @param string $string_value String value.
* @param int $offset Offset of the string value found.
*/
public function string_value( $string_value, $offset )
{
echo 'String value: ' . $string_value . '<br />';
}
/**
* Integer value found
*
* @param string $integer_value Integer value.
* @param int $offset Offset of the integer value found.
*/
public function integer_value( $integer_value, $offset )
{
echo 'Integer value: ' . $integer_value . '<br />';
}
/**
* Decimal value found
*
* @param string $decimal_value Decimal value.
* @param int $offset Offset of the decimal value found.
*/
public function decimal_value( $decimal_value, $offset ) {
echo 'Decimal value: ' . $decimal_value . '<br />';
}
/**
* Boolean value found
*
* @param string $boolean_value It can be '0' or '1'.
* @param int $offset Offset of the boolean value found.
*/
public function boolean_value( $boolean_value, $offset ) {
echo 'Boolean value: ' . $boolean_value . '<br />';
}
/**
* Null value found
*
*/
public function null_value() {
echo 'Null value found' . '<br />';
}
/**
* Number of items of the array found
*
* @param string $items_num Number of items.
* @param int $offset Offset of the number of items found.
*/
public function array_items_num( $items_num, $offset ) {
echo 'Number of items of the array: ' . $items_num . '<br />';
}
/**
* End of parsing
*
* @param bool $parsing_result True if the string is unserializable.
*/
public function end_parsing( $parse_result )
{
if ( $parse_result ) {
echo 'Good job!' . '<br />';
} else {
echo 'There was an error' . '<br />';
}
}
/**
* Set error parsing the string.
*
* @param string $error Error parsing the string.
*/
public function set_error( $error )
{
echo $error . '<br />';
}
}
$example_srl = new Example_Srl();
/*
We instantiate the Lexepa-Srl library class, passing as arguments the $example_srl object
containing the callback functions and the serialized string
*/
$lexepa_srl = new Lexepa_Srl( $example_srl, $myArraySerialized );
// Let's start the analysis
$lexepa_srl->parse_srl();
The result of this example is as follows:
String serialized: a:5:{s:4:"key1";s:22:"This is my first value";s:4:"key2";s:23:"This is my second value";s:4:"key3";i:20;s:4:"key4";b:1;s:4:"key5";N;}
Number of items of the array: 5
String length: 4
String value: key1
String length: 22
String value: This is my first value
String length: 4
String value: key2
String length: 23
String value: This is my second value
String length: 4
String value: key3
Integer value: 20
String length: 4
String value: key4
Boolean value: 1
String length: 4
String value: key5
Null value found
Good job!
The callback functions implemented by the Lexepa_Srl_Abstract class are contained and documented in the interface file class-lexepa-srl-interface.php
The Lexepa_Srl library was created by taking as reference the following document that specifies how an object is serialized in PHP:
https://www.phpinternalsbook.com/php5/classes_objects/serialization.html
lbreme/lexepa-srl 适用场景与选型建议
lbreme/lexepa-srl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「serialize」 「parser」 「lexer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lbreme/lexepa-srl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lbreme/lexepa-srl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lbreme/lexepa-srl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Transform data structures
Lightweight PHP library that allows exchanging binary data with Qt programs (QDataStream)
A simple library for make Lexer and Parsers to build a language
An MT940 bank statement parser for PHP
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-12