About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:code_generators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
development:code_generators [2018/02/07 20:53] demiankatzdevelopment:code_generators [2018/10/24 15:27] – [Usage] demiankatz
Line 154: Line 154:
 Successfully updated /.../module/MyModule/config/module.config.php Successfully updated /.../module/MyModule/config/module.config.php
 Successfully updated /.../module/MyModule/config/module.config.php Successfully updated /.../module/MyModule/config/module.config.php
 +</code>
 +
 +===== Creating New Plugins =====
 +
 +:!: This feature was introduced in VuFind 5.1.
 +
 +If you want to create a new [[development:plugins|plugin]] for VuFind, you can use the 'plugin' generator to create a stub class and (if necessary) factory and automatically update the relevant module configuration.
 +
 +==== Usage ====
 +
 +<code bash>
 +cd $VUFIND_HOME
 +php public/index.php generate plugin MyModule\\PluginType\\PluginName [optional factory name]
 +</code>
 +
 +  * MyModule\\PluginType\\PluginName is the name of the class you wish to create. The generator will use the first part of the class name to determine which module it belongs in (since modules correspond to namespaces); it will use the last part of the class name to name the class being defined; it will use the middle part to identify what type of plugin is being created and to set up configuration accordingly. Obviously, if you specify a class name that does not correspond with a standard VuFind plugin type, the generator will fail.
 +  * [optional factory name] may be included to specify the name of an existing factory that should be used to construct your plugin. For example, if your class will not have any dependencies, you can use the simple Zend\\ServiceManager\\Factory\\InvokableFactory to construct the object in a simple fashion. If you do not specify a factory name, the generator will create a factory automatically, naming it by taking your class name and appending "Factory" on the end.
 +
 +==== Notes ====
 +:!: Be sure that MyModule already exists and is included in your VUFIND_LOCAL_MODULES environment variable, or the generator may not work correctly. If MyModule does not yet exist, you can re-run VuFind's install.php script to create it.
 +
 +:!: If things don't work right away after generating code, you may need to clear your local/cache directory to get rid of outdated configurations.
 +
 +==== Example ====
 +
 +Suppose you want to create a new ILS driver for your home-grown system. You could begin like this:
 +
 +<code bash>
 +cd $VUFIND_HOME
 +php public/index.php generate plugin MyModule\\ILS\\Driver\\MyLocalSystem
 +</code>
 +
 +The output should look something like this:
 +
 +<code>
 +Saved file: /home/dkatz/vufind3/module/MyModule/src/MyModule/ILS/Driver/MyLocalSystem.php
 +Saved file: /home/dkatz/vufind3/module/MyModule/src/MyModule/ILS/Driver/MyLocalSystemFactory.php
 +Created backup: /home/dkatz/vufind3/module/MyModule/config/module.config.php.1540394754.bak
 +Successfully updated /home/dkatz/vufind3/module/MyModule/config/module.config.php
 +Successfully updated /home/dkatz/vufind3/module/MyModule/config/module.config.php
 </code> </code>
 ---- struct data ---- ---- struct data ----
 ---- ----
  
development/code_generators.txt · Last modified: 2023/11/09 21:19 by demiankatz