php-strict/struct 问题修复 & 功能扩展

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

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

php-strict/struct

Composer 安装命令:

composer require php-strict/struct

包简介

Implementation of composite type for PHP.

README 文档

README

Software License Build Status codecov Codacy Badge

Implementation of composite type for PHP.

Contains methods to create from associated array, JSON string or another Struct, with/without type cast.

Requirements

  • PHP >= 7.1

Install

Install with Composer:

composer require php-strict/struct

Usage

Define your own composite type by extending Struct class:

use PhpStrict\Struct\Struct

class Book extends Struct
{
    /**
     * @var string
     */
    public $author = '';
    
    /**
     * @var string
     */
    public $title = '';
    
    /**
     * @var string
     */
    public $isbn = '';
    
    /**
     * @var int
     */
    public $pages = 0;
    
    /**
     * @var bool
     */
    public $publicated = false;
    
    /**
     * @var array
     */
    public $tags = [];
}

Now you can fill your strcuture with data:

//book with classic assign data to class fields
$book1 = new Book();
$book1->author = 'Author Name';
$book1->title = 'Book title 1';
$book1->isbn = '000-0-000-00000-0';
$book1->pages = 240;
$book1->publicated = true;
$book1->tags = ['fantastic', 'space', 'detective'];

//another book with data through array
$book2 = new Book([
    'author' => 'Author Name',
    'title' => 'Book title 2',
    'isbn' => '000-0-000-00000-0',
    'pages' => 156,
    'publicated' => true,
    'tags' => ['drama', 'nature'],
]);

//another book with data through JSON
$json = '{"author":"Author Name","title":"Book title 3","isbn":"000-0-000-00000-0","pages":156,"publicated":true,"tags":["comedy","city"]}';
$book3 = new Book($json);

//book, based on existing book
$book4 = new Book($book1);
$book4->title = 'Book title 4';

See examples dir.

Tests

To execute the test suite, you'll need Codeception.

vendor\bin\codecept run

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2019-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固