Download the PHP package webchemistry/stimulus without Composer
On this page you can find all versions of the php package webchemistry/stimulus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package stimulus
Installation
composer require webchemistry/stimulus
Set up extractor and generators
First, set up extractor and generator. Namespaced identifiers also supported.
Code with comments (copy-paste code is below):
copy-paste code:
How files are generated
Class JavascriptSourceExtractor uses javascript comments for generating.
Each controller must be annotated with @controller, actions with @action and their parameters with @param, values, classes and targets with @property.
my_controller.js
This PHP class is generated:
By default, each property is required, if we want to make optional we have several ways:
- add
?to the end of property name:@property {String} stringValue? - add
{ optional }to the 3rd section (options) of property:@property {String} stringValue {optional} - add hasser
@property {Boolean} hasStringValue
Javascript types and PHP types
webchemisty/stimulus introduces stricter environment for writting application. Nowadays, everyone use static analysis (at least they should) so correct types are crucial.
Library converts javascript types in the following way:
Number => int|float narrowing is achieved by options (3rd section) { number: int } \
Array and Object => mixed[] \
Boolean => bool \
String => string \
other => mixed
Arrays: \
String[] => string[] \
Number[] => array<int|float> narrowing: { number: float } \
Bool[] => bool[] \
other => mixed[]
Custom types
Sometimes we need overriding comment types @param ... and types method(... $type)
fot this there is options type and commentType e.g. { type: mixed, commentType: "array<string, resource>" }
Action parameters
Stimulus 3 introduced parameters for actions. For generating just use intersection type or just object type.
Usage in PHP
Usage in Latte
Controller as service
Sometimes we want to inject other services:
All versions of stimulus with dependencies
nette/php-generator Version ^3.5.0 || ^4.0.0
nette/finder Version ^2.5 || ^3.0
utilitte/php Version ^1.5
webchemistry/simple-json Version ^1.1.0
typertion/php Version ^1.0