PHP code example of jeffpacks / cody

1. Go to this page and download the library: Download jeffpacks/cody library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeffpacks / cody example snippets



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();