Onema\ClassyFile\ClassyFile Class Reference

Constructor Documentation

Onema\ClassyFile\ClassyFile::__construct    (   EventDispatcherInterface    $dispatcher = null  )

Parameters

  • EventDispatcherInterface $dispatcher

Exceptions

  • InvalidTemplateException

Public Methods

generateClassFiles

Onema\ClassyFile\ClassyFile::generateClassFiles ($codeDestination, $codeLocation, $offset = 0, $length = 0)

This method is just a wrapper to the generateClasses method. It will add an event subscriber that will save the file to the desired location. The file uses a local file system addapter, but any file system may be used, this way files can be saved to remote locations.

Parameters

  • $codeDestination
  • $codeLocation
  • int $offset
  • int $length

generateClasses

Onema\ClassyFile\ClassyFile::generateClasses( $directoryPath )

This method generates an array containing the classes for each file within the directory path. Classes are broken down into single entries. Classes will be generated using a simple template unless a custom one is set. Several events are triggered during the process allowing users of the class to write their own plugins to extend the behaviour of the code.

Parameters

  • $directoryPath

Returns

  • array

getEventDispatcher

Onema\ClassyFile\ClassyFile::getEventDispatcher ()

Returns

  • EventDispatcher

setEventDispatcher

Onema\ClassyFile\ClassyFile::setEventDispatcher (EventDispatcherInterface $eventDispatcher)

Parameters

  • EventDispatcherInterface $eventDispatcher

setFilesystemAdapter

Onema\ClassyFile\ClassyFile::setFilesystemAdapter (AdapterInterface $filesystemAdapter)

An adapter can be set before calling the generateClassFiles method. This way files can be saved to a remote location. Local adapter is used by default.

Parameters

  • \League\Flysystem\AdapterInterface

setTemplate

Onema\ClassyFile\ClassyFile::setTemplate ($templateCallback, $method = null)        

Parameters

  • callable | object $templateCallback
  • null $method

Exceptions

  • \Onema\ClassyFile\Exception\InvalidTemplateException

Protected Methods

getClass

Onema\ClassyFile\ClassyFile::getClass (Class_  $statement, $namespace, $fileLocation, $uses = '')

Gets a single class generated by the template.

Parameters

  • Class_ $statement
  • string $namespace
  • string $fileLocation
  • string $uses

Returns

  • string $code

traverseStatements

Onema\ClassyFile\ClassyFile::traverseStatements ($statements, $namespaceString = '')

Traverses the main PHP file, checks for namespaces, classes, if statements and use statements. A chain of responsibility could be used here to get rid of the awful if/else statements.

Parameters

  • $statements
  • string $namespaceString

Returns

  • array $code