Events

ClassyFile emits several events to allow you to extend the basic functionality of this library.

classyfile.before_generate_classes

This event is emitted after the file finder has been setup and before checkign each php file. The event will contain the following values - 'finder': File finder used to get all the php files in the given directory.

classyfile.after_generate_classes

This event is emitted at the end of the process and before the array containing all the generated classes is returned. The event will contain the following values: - 'finder': File finder used to get all the php files in the given directory. - 'generatedClasses': an array containing all the code for the classes generated by the process.

classyfile.before_traverse

This event is emitted after the file has been opened and parsed. The event will contain the following values:

  • 'statements': an array containing all the statements in the file.
  • 'create_namespace': boolean value with selected option to create name spaces.
  • 'offset': path offset used to generate the namespace.
  • 'length': used to determine how many sections of the path to use starting at the given offset.

All values can be modified by the listeners.

classyfile.before_get_class

This event is emitted before the new class is generated and saved. This allow us to make modifications to the generated class. The event will contain the following values:

  • Class statement (subject): Class_ statement. This can be retrieved from the event like such: $event->getStatement().
  • 'namespace': string containing the current namespace. Empty if no namespace was set.
  • 'file_location': place where the new class will be saved.
  • 'uses': any use statements to be added to the class.

classyfile.after_get_class

This event is emitted after the new class is generated. This allow us to make modifications to the class after it has been added to the tempalte. This is where the plugin to save the classes to a files system get's triggered. The event will contain the following values:

  • Class statement (subject): Class_ statement. This can be retrieved from the event like such: $event->getStatement().
  • 'code': the generated code
  • 'file_location': place where the new class will be saved.