Skip to content

Latest commit

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Classiphpy

Classiphpy is a PHP library designed to read definition data, and generate corresponding class structures. Classiphpy thinks of this process in terms of a DefinitionInterface and a ProcessorInterface. DefinitionInterfaces describe the expectations of the data you are parsing, validating this and providing an array of DefinitionInterface object. ProcessorInterface interpret the definitions generated in the the DefinitionInterface and generate File class data to match. Individual use cases should be described as 1 or more DefinitionInterface classes to ready your data for processing. The file definitions generated during processing and then available to be written to disk via the DefaultOutput class, or you may write another Output class as necessary for non-file-writing use-cases.

##Example The DefaultDefinition class included in Classiphpy expects an input along these lines:

<?php$data = [
"defaults" => [
"namespace" => "EclipseGc"
],
"classes" => [
"Person" => [
"properties" => [
"first" => [
'type' => 'string',
'description' => 'The first name of the person.',
],
"last" => [
'type' => 'string',
'description' => 'the last name of the person.',
]
],
"namespace" => "EclipseGc\\Person",
],
"Animal" => [
"properties" => [
"kingdom" => [
'type' => 'string',
'description' => 'The kingdom to which the animal belongs.'
],
"phylum" => [
'type' => 'string',
'description' => 'The phylum to which the animal belongs.'
],
"genus" => [
'type' => 'string',
'description' => 'The genus to which the animal belongs.'
],
"species" => [
'type' => 'string',
'description' => 'The species to which the animal belongs.'
],
],
"namespace" => "EclipseGc\\Animal",
]
]
];

Run through the PSR4PhpProcessor class and this json would generate the following PHP.

<?phpnamespaceEclipseGc\Animal;
class Animal
{
/** * @var string species * The species to which the animal belongs. */protected$species;
/** * @var string genus * The genus to which the animal belongs. */protected$genus;
/** * @var string phylum * The phylum to which the animal belongs. */protected$phylum;
/** * @var string kingdom * The kingdom to which the animal belongs. */protected$kingdom;
/** * @param string kingdom * The kingdom to which the animal belongs. * * @param string phylum * The phylum to which the animal belongs. * * @param string genus * The genus to which the animal belongs. * * @param string species * The species to which the animal belongs. */publicfunction__construct($kingdom, $phylum, $genus, $species)
{
$this->kingdom = $kingdom;
$this->phylum = $phylum;
$this->genus = $genus;
$this->species = $species;
}
/** * Gets the kingdom value. */publicfunctiongetKingdom()
{
return$this->kingdom;
}
/** * Gets the phylum value. */publicfunctiongetPhylum()
{
return$this->phylum;
}
/** * Gets the genus value. */publicfunctiongetGenus()
{
return$this->genus;
}
/** * Gets the species value. */publicfunctiongetSpecies()
{
return$this->species;
}
}

##Getting started In the above example, to actually bootstrap this, we'd only need to inform the Classiphpy class which definition(s) we wish to use, and hand it an instance of our Output class. We then instantiate a processor of our choosing (these could be nested with a decorator pattern to add additional files beyond what our DefinitionInterface classes are expected to generate) and Classiphpy generates the file structures and writes them to disk.

<?php$output = new \Classiphpy\Output\DefaultOutput('/tmp/classiphpy');
$test = newClassiphpy(['\Classiphpy\Definition\DefaultDefinition'], $output);
$processor = new \Classiphpy\Processor\PSR4PhpProcessor('src');
$test->build($data, $processor);
?>

About

No description, website, or topics provided.

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages