承接 nathanburkett/mesa 相关项目开发

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

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

nathanburkett/mesa

Composer 安装命令:

composer require nathanburkett/mesa

包简介

Table-Driven Data Interpretation

README 文档

README

CircleCI codecov

Mesa is a programmatic table builder and/or interpreter.

Installation

composer require nathanburkett/mesa

Usage

Via GeneratesTables Trait

Using the GeneratesTables trait is the simplest way to start consuming tables.

<?php namespace Foo\Bar\Baz;

use NathanBurkett\Mesa\GeneratesTables;

class FooClass
{
    use GeneratesTables;
}

Then build a table by calling:

<?php namespace Foo\Bar\Baz;

use NathanBurkett\Mesa\GeneratesTables;

class FooClass
{
    use GeneratesTables;
    
    public function run(): iterable
    {
        $tableContext = __DIR__ . '/some/php/file.php';

        return $this->generateTable($tableContext);
    } 
}

$tableContext is the data source the table is interpreting.

An optional callable can be passed to generateTable as the 2nd parameter which will be run on each of the table iteration's value and will replace that value.

Example:

<?php
// ./some/php/file.php

return [
    'one' => [
        'name' => 'foo',
    ],
    'two' => [
        'name' => 'bar',
    ],
];
<?php namespace Foo\Bar\Baz;

use NathanBurkett\Mesa\GeneratesTables;

class FooClass
{
    use GeneratesTables;
    
    public function run(): iterable
    {
        $tableContext = __DIR__ . '/some/php/file.php'; // THIS IS WHERE $tableContext COMES FROM

        return $this->generateTable($tableContext, function(array $row, $index) {
            if ($index === 'two') {
                $row['name'] = 'baz';
            }
            
            return $row;
        });
    } 
}

In the above example, $table['two']['name'] would equal 'baz'.

Loaders

The current default behavior of $tableContext passed as the first parameter to GeneratesTables::generateTable() is intended to be an absolute path to a PHP or YAML file. Anything else and FileLoaderFactory will throw an exception.

Other types can be interpreted by extending LoaderFactory and overridding any of the methods and then overriding the GeneratesTables::getLoaderFactory()

<?php namespace Foo\Bar\Baz;

use NathanBurkett\Mesa\GeneratesTables;
use NathanBurkett\Mesa\Loader\LoaderFactoryInterface;

class FooClass
{
    use GeneratesTables;
    
    // ...
    
    protected function getLoaderFactory(): LoaderFactoryInterface
    {
        return new YourNewFactoryLoader();
    }
}

Output

Once data has been read into a table, it will then be output by an OutputStrategy. The default OutputStrategy iterates over the table and yields an index and value via a generator function.

An optional callable can be passed as the 2nd parameter which will be run on each iteration's value and replace that iteration value.

An optional callable can be passed to generateTable as the 2nd parameter which will be run on each of the table iteration's value and will replace that value.

Example:

<?php
// ./some/php/file.php

return [
    'one' => [
        'name' => 'foo',
    ],
    'two' => [
        'name' => 'bar',
    ],
];
<?php namespace Foo\Bar\Baz;

use NathanBurkett\Mesa\GeneratesTables;

class FooClass
{
    use GeneratesTables;
    
    public function run(): iterable
    {
        $tableContext = __DIR__ . '/some/php/file.php'; // THIS IS WHERE $tableContext COMES FROM

        return $this->generateTable($tableContext, function(array $row, $index) {
            if ($index === 'two') {
                $row['name'] = 'baz';
            }
            
            return $row;
        });
    } 
}

In the above example, $table['two']['name'] would equal 'baz'.

An alternate OutputStrategy can be used by overriding GeneratesTables::getOutputStrategy()

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固