承接 mariuslundgard/php-util 相关项目开发

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

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

mariuslundgard/php-util

Composer 安装命令:

composer require mariuslundgard/php-util

包简介

A utility library for PHP 5.3+.

README 文档

README

Build Status Coverage Status

Latest Stable Version

Utility functions and classes for PHP.

Examples

The Util\Dictionary class

Usage example:

<?php

require 'vendor/autoload.php';

use Util\Dictionary;

$dict = new Dictionary([
	'path.to.item'    => 123,
	'path.to.another' => 124,
]);

echo json_encode($dict->get()); // -> { "path": { "to": { "item": 123, "another": "124 " }}}
echo $dict['path.to.item'];     // -> 123

Using a Dictionary object for filesystem representation.

use Util\Dictionary;

$rootDir = dirname(__DIR__);

$dir = new RecursiveDirectoryIterator($rootDir);
$iter = new RecursiveIteratorIterator($dir);
$regex = new RegexIterator($iter, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);

$phpFiles = new Dictionary([], [
    'delimiter' => '/',
]);

foreach ($regex as $key => $file) {
    $phpFiles[trim(realpath($file[0]), '/')] = 'Modified '.time_elapsed_string(filemtime($file[0]));
}

echo '<pre>';
echo json_encode($phpFiles[trim($rootDir, '/')], JSON_PRETTY_PRINT);
echo '</pre>';

// {
//     "example": {
//         "index.php": "Modified 13 hours ago"
//     },
//     "src": {
//         "array.php": "Modified 9 hours ago",
//         "object.php": "Modified 20 days ago",
//         "string.php": "Modified 2 days ago",
//         "time.php": "Modified 7 hours ago",
//         "Util": {
//             "Dictionary.php": "Modified 5 seconds ago"
//         }
//     },
//     ...

Using a Dictionary object for application configuration.

use Util\Dictionary;

class MyApplication
{
    protected $config;

    public function __construct(array $config = [])
    {
        $this->config = new Dictionary($config);
    }

    public function __get($property)
    {
        switch ($property) {

            case 'config':
                return $this->config;

            default:
                throw new Exception('Unknown application property: '.$property);
        }
    }

    public function configure(array $config)
    {
        $this->config->merge($config);

        return $this;
    }
}

$app = (new App())
    ->configure([
        'db.user' => 'root',
        'db.pass' => 'test',
    ]);

echo $app->config['db.user'];         // root
echo json_encode($app->config['db']); // { "user": "root", "pass": "test" }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固