PHP code example of constant-null / backstubber
1. Go to this page and download the library: Download constant-null/backstubber 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/ */
constant-null / backstubber example snippets
class DummyClass
{
protected $captain = DummyCaptain;
protected $officers = DummyOfficers;
protected $crew = DummyCrew;
}
use ConstantNull/Backstubber/FileGenerator as Generator;
$generator = new Generator();
$generator->useStub('some/path/to/stubs/DummyStarship.stub')
->set('DummyOfficers', ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'])
->set('DummyCaptain', 'James T. Kirk')
->set('DummyCrew', 430)
...
// or pass an array
->set([
'DummyOfficers' => ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'],
'DummyCaptain' => 'James T. Kirk',
'DummyCrew' => 430
])
...
// saving new file
->generate('path/to/generated/classes/EnterpriseClass.php');
protected $captain = 'James T. Kirk';
protected $officers = ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'];
protected $crew = 430;
use ConstantNull/Backstubber/FileGenerator as Generator;
$generator = new Generator();
$generator->useStub('some/path/to/stubs/DummyStarship.stub')
->set('DummyOfficers', ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'])
->set('DummyCaptain', 'James T. Kirk')
->set('DummyCrew', 430)
// newly added methods
->setRaw('DummyClass', 'Enterprise')
->setRaw('DummyClassNamespace', 'Federation\\Ships')
// or pass an array
->setRaw([
'DummyClass' => 'Enterprise',
'DummyClassNamespace' => 'Federation\\Ships'
])
// saving new file
->generate('path/to/generated/classes/EnterpriseClass.php');
namespace Federation\Ships;
class Enterprise
{
protected $captain = 'James T. Kirk';
protected $officers = ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'];
protected $crew = 430;
}
use ConstantNull/Backstubber/FileGenerator as Generator;
$generator = new Generator();
$generator->useStub('some/path/to/stubs/DummyStarship.stub')
->withPrefix('Dummy')
->set('Officers', ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'])
->set('Captain', 'James T. Kirk')
->set('Crew', 430)
// newly added methods
->setRaw('Class', 'Enterprise')
->setRaw('ClassNamespace', 'Federation\\Ships')
// saving new file
->generate('path/to/generated/classes/EnterpriseClass.php');
namespace {{ namespace }};
class {{ class }}
{
protected $captain = {{ captain }};
protected $officers = {{ officers }};
protected $crew = {{ crew }};
}
use ConstantNull/Backstubber/FileGenerator as Generator;
$generator = new Generator();
$generator->useStub('some/path/to/stubs/DummyStarship.stub')
// set delimiters
->withDelimiters('{{', '}}')
// assign substitutions
->set('officers', ['James T Kirk', 'Mr. Spock', 'Scott Montgomery'])
->set('captain', 'James T. Kirk')
->set('crew', 430)
->setRaw('class', 'Enterprise')
->setRaw('namespace', 'Federation\\Ships')
// saving new file
->generate('path/to/generated/classes/EnterpriseClass.php');
...
$officers = [
'Captain' => 'Jean Luc Picard',
'First officer' => 'William T. Riker',
'Tactical Officer' => 'Tasha Yar'
];
$generator->set('officers', $officers)
$officers = [
'Captain' => 'Jean Luc Picard',
'First officer' => 'William T. Riker',
'Tactical Officer' => 'Tasha Yar'
];
$ php composer.phar update