jameslevi/silhouette 问题修复 & 功能扩展

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

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

jameslevi/silhouette

Composer 安装命令:

composer require jameslevi/silhouette

包简介

Is a simple configuration management library that supports multiple configuration file formats.

关键字:

README 文档

README

Is a simple configuration management library that supports multiple configuration file formats.

Features

  1. Supports php array and json format.
  2. Facade implementation to beautifully access your configuration data.
  3. Easy integration with other frameworks or even without framework at all.

Installation

  1. You can install via composer.
composer require jameslevi/silhouette
  1. Include the autoloader at the upper part of your code.
require_once __DIR__.'/vendor/autoload.php';

Getting Started

  1. Import the config class into your project.
use Graphite\Component\Silhouette\Config;
  1. Create a new config file in php or json. But for this example let's try a php file that returns an array.
<?php

return [
  'enable'      => true,
  'port'        => 3306,
  'host'        => 'localhost',
  'username'    => 'root',
  'password'    => 'abcd',
  'database'    => 'users',
  'max-rows'    => 10000,
];
  1. Instantiate a new config object.
$db = new Config(__DIR__ . "/config/db.php");
  1. You can now get data using "get" method.
$db->get('enable'); // This will return true.

You can also get data using object keys.

$db->username; // This will return "root".
  1. You can also set add new value into your config.
$db->add('charset', 'utf-8'); // This will add "charset" as new config data.
  1. You can edit config data using "set" method.
$db->set('database', 'photos'); // This will change the value of the key database.

You can also set data using object keys.

$db->database = 'photos'; // This will change the value of database from "users" to "photos".
  1. You can check if keyword exists using "has" method.
$db->has('password'); // Returns true.
  1. You can remove a configuration data using "remove" method.
$db->remove('enable'); // This will remove "enable" from your configuration object.
  1. You can return your configuration data in array.
$db->toArray();
  1. You can also return json format of your configuration data.
$db->toJson();

Config Injection

You can also make a config object without loading a config file.

$db = new Config([
  'enable'      => true,
  'port'        => 3306,
  'host'        => 'localhost',
  'username'    => 'root',
  'password'    => 'abcd',
  'database'    => 'users',
  'max-rows'    => 10000,
]);

Facade

  1. Create a class that extends silhouette facade class then override the parent constructor by passing the config path.
<?php

namespace App\Config;

use Graphite\Component\Silhouette\Facade;

class DB extends Facade
{
    public function __construct()
    {
        parent::__construct('config/db.php');
    }
}
  1. You can now get each configurations by calling it's static methods.
DB::enable() // Returns the value of enable property.

You must call properties that are in snake case to camel case.

DB::maxRows() // Returns the value 10000.
  1. You can edit configuration value by providing the first argument of the method called.
DB::enable(false) // Change the value of "enable" to false.
  1. You can add, edit or delete configuration data using config "context".
DB::context()->add('min_rows', 100); // This will add new configuration property.
DB::context()->set('min_rows', 110); // This will set the value of "min_rows".
DB::context()->remove('min-rows'); // This will remove "min_rows" from the data object.

Muted Configuration Object

Configuration objects that only returns data.

// Create a new database configuration object.
$config = new Config(__DIR__ . '/config/db.php', true);

// You cannot add new data to your muted configuration.
$config->add('driver', 'mysql');

You can also mute config object in facade.

<?php

namespace App\Config;

use Graphite\Component\Silhouette\Facade;

class DB extends Facade
{
    public function __construct()
    {
        parent::__construct('config/db.php', true);
    }
}

Contribution

For issues, concerns and suggestions, you can email James Crisostomo via nerdlabenterprise@gmail.com.

License

This package is an open-sourced software licensed under MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固