jeffpacks/cody
最新稳定版本:1.0.0-alpha.3
Composer 安装命令:
composer require jeffpacks/cody
包简介
Library for creating PHP code with PHP code
README 文档
README
Cody is a PHP package for generating PHP files.
Requirements
This library requires PHP >= 7.4.
Installing
Composer
- Run
composer require jeffpacks/codyin your shell
Download
If you've downloaded or received the jeffpacks/cody package manually, you may place it anywhere in your file system and call require_once('/path/to/cody/autoload.php') in your code to start using it.
Concept
Cody lets you create a code "project" and populate it with PHP classes, interfaces and traits. Once your code has created the project, the project can be exported to the file system as a codebase.
In Cody, namespaces are the starting point for creating classes, interfaces, traits and sub-namespaces.
Examples
The jeffpacks\cody\Cody::createProject() method creates and returns a new Project instance.
<?php require_once('vendor/autoload.php'); # Using Composer to load Cody use jeffpacks\cody\Cody; # Create project $project = Cody::createProject('', 'acme\\webshop'); # Gotta escape them backslashes $projectNamespace = $project->getNamespace(); # This is the project namespace, "acme\webshop" $interfaces = $projectNamespace->createNamespace('interfaces'); # We'll put our interfaces in the "acme\webshop\interfaces" namespace $customer = $interfaces->createInterface('Customer'); $customer->setDescription('Represents a web-shop customer'); $customer->createMethod('getName')->setDescription('Provides the full name of the customer')->setReturnTypes('string'); $customer->createMethod('getAddress')->setDescription('Provides the postal address of the customer')->setReturnTypes('string'); $user = $interfaces->createInterface('User'); $user->setDescription('Represents a web-shop user'); $user->createMethod('getUsername')->setDescription('Provides the username of the user')->setReturnTypes('string'); $user->createMethod('getPasswordHash')->setDescription('Provides the hashed password of the user')->setReturnTypes('string'); $client = $projectNamespace->createClass('Client')->setDescription('Represents a web-shop client'); $client->implement($customer); $client->implement($user); $client->createVariable('name', 'string|null'); # pipe style $client->createVariable('address', '?string'); # nullable style $client->createVariable('username', ['string', 'null']); # array style $client->createVariable('passwordHash', '?string'); $client->getMethod('getName')->setBody('return $this->name;') $client->getMethod('getAddress')->setBody('return $this->address;') $client->getMethod('getUsername')->setBody('return $this->username;') $client->getMethod('getPasswordHash')->setBody('return $this->passwordHash;') $project->export()->toDirectory('/tmp/')->run();
Authors
- Johan Fredrik Varen – github.com/jeffpacks
License
Cody is the proprietary work of and property of Johan Fredrik Varen. Copyright Johan Fredrik Varen 2023.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-02