Worker CLI
OwnWork provides the worker script as its command-line manager for application components, development serving, view transpilation, and view-cache management.
Run commands from the project root.
Command Help
Running:
php workerprints the available commands and their options.
The currently registered commands are:
make
serve
transpile
clear:viewcache`make`
The make command generates application components from the templates under:
resources/template/General syntax:
php worker make <type> <name>Supported component types are:
controller
middleware
service
model
viewFor example:
php worker make controller UserController
php worker make middleware AuthMiddleware
php worker make service UserService
php worker make model UserModel
php worker make view users/indexThe worker creates the corresponding application file using the component's template.
Generate a Controller
php worker make controller UserControllerThe controller is created under:
app/Controller/using:
resources/template/Controller.phpGenerate Middleware
php worker make middleware AuthMiddlewareThe middleware is created under:
app/Middleware/using:
resources/template/Middleware.phpGenerate a Service
php worker make service UserServiceThe service is created under:
app/Service/using:
resources/template/Service.phpGenerate a Model
php worker make model UserModelThe model is created under:
app/Model/using:
resources/template/Model.phpGenerate a View
php worker make view users/indexViews are created under:
resources/views/using:
resources/template/View.php The worker creates the requested name as a PHP view file. View templates intended for OwnWork's templating system use the .temp.php convention.
Component Names
The worker takes the component name from the third argument:
php worker make controller UserControllerInternally, the worker uses that name when creating the file and replaces:
DEFAULT_NAMEin the corresponding template.
If a component name is not supplied, the worker prompts for it interactively.
Existing Components
The worker checks whether the target file already exists.
If it does, the worker does not overwrite it and reports that the component already exists.
Start the Development Server
Run:
php worker serveThe default port is:
8000The worker starts PHP's built-in development server with:
--server=localhost:8000
--docroot=publicA different port can be supplied:
php worker serve 8080The resulting server uses:
http://localhost:8080The default command therefore corresponds to:
http://localhost:8000Transpile Views
Run:
php worker transpileThe worker uses Coretex's templater to scan and compile OwnWork view templates.
Source templates are stored in:
resources/views/Compiled views are stored in:
storage/views/The worker also maintains:
storage/views.jsonwhich contains the mapping used by the view system.
Continuous Transpilation
Without a numeric argument or build, the transpiler runs as a watcher.
php worker transpileIt waits for view changes and retranspiles when changes are detected.
The worker checks the view state periodically and clears the view cache before recompiling changed templates.
Production Transpilation
The transpiler accepts a numeric argument specifying how many transpilation operations should occur:
php worker transpile 1 A special build argument performs a production-style build:
php worker transpile buildThe build operation:
scan storage
↓
scan resources
↓
compile views
↓
write storage/views.jsonUnlike the normal watcher mode, the build operation exits after compilation.
Clear View Cache
Compiled view files can be removed with:
php worker clear:viewcacheThe command clears files inside:
storage/views/It does not remove the source templates under:
resources/views/After clearing the cache, views can be regenerated with:
php worker transpileComposer Development Commands
The project also defines Composer scripts.
Development server:
composer run devView transpilation:
composer run transpile The dev Composer script starts PHP's development server on port 8000.
The transpile script invokes:
php worker transpilenpm Development Workflow
When the optional Node.js tooling is installed, the project also provides an npm development workflow.
Install dependencies:
npm iThen:
npm run devThe npm development workflow can run the project's development tooling together rather than manually starting each process.
Command Reference
| Command | Purpose |
|---|---|
php worker |
Display worker help |
php worker make controller <name> |
Generate a controller |
php worker make middleware <name> |
Generate middleware |
php worker make service <name> |
Generate a service |
php worker make model <name> |
Generate a model |
php worker make view <name> |
Generate a view |
php worker serve |
Start the development server on port 8000 |
php worker serve <port> |
Start the development server on a custom port |
php worker transpile |
Watch and transpile views |
php worker transpile <number> |
Run a limited number of transpilation operations |
php worker transpile build |
Build compiled views and exit |
php worker clear:viewcache |
Clear compiled view files |
composer run dev |
Start the Composer development server |
composer run transpile |
Run the view transpiler |
npm run dev |
Run the npm development workflow |
Worker Flow
The worker provides the main development operations around the application:
worker
│
┌──────────────┼──────────────┐
↓ ↓ ↓
make serve transpile
│ │ │
↓ ↓ ↓
app components PHP server resources/views
│
↓
storage/viewsThe worker itself is a lightweight command manager; application behavior remains in the generated application classes and the underlying OwnWork/Coretex components.
configuration/environment.md