Console Command

Console commands can be used to create controller, route and entities and it can also be used to view application information such as list of controllers, routes, entities and more.

Commands can also be used for creating CRON job, all GET routes are executable from console commands.

Nishchay console commands are executed by php nishchay {follow up commands}. Executing php nishchay prints list of supported commands and its description.

Command Help

Just execute php nishchay without any follow up command and help for console command will be printed. This will print all supported command along with how each command can used with one or more optional parameter.

Framework version

Framework version is displayed using php nishchay -v command. Here -v also has two more alias, v and -version. Once you execute command below information will be printed:

  • Version number
  • Version name
Route

route command is used to find all routes defined in application. This list can be filtered based on its controller, context and regex pattern. All route with HTTP method GET allowed can be executed by this command.

Using route we can find below information related to route:

  • Path as defined in @Route annotation.
  • HTTP methods for which route needs to be executed.
  • Route's controller class name
  • Route's method name
List all routes

To list all routes in an application execute route command without any parameter.

php nishchay route
Routes belongs to specific controller

Lists of all routes defined in specific controller.

php nishchay route -controller {name}

Here controllerClass must be full class path. As class path contains \ (slash), classPath must be passed in single or double quote. If you pass class which is not controller or it does not exists then command will gives an error.

Route information by its path name

We can also view route information by its path name as defined @Route annotation.

php nishchay route -name {pathName}
Route information by url

To route information by any URL, just pass URL after php nishchay route This is helpful when you have large application or starting coding already developed application for the first time as it will gives all information which is required to locate route.

php nishchay route {path}
Execute route

To execute route we only need to pass url and then -run.

Note: Only route which supports GET request can be executed using route command.

php nishchay route {path} -run
List route by regular expression

Upon passing regular expression. This regular expression will be run for each route path name and it will list all routes which matches regular expression.

php nishchay route -match {RegexPattern}
Event defined for route

We can also find events which can be execute before or after route. This will list events defined for route, route's scope (if it has been defined on route) and route's context.

php nishchay route {path} -event
Error handler defined for route

Lists all handlers defined for route. This will list all handlers defined for route, route's scope (if it has been defined on route) and route's context.

php nishchay route {path} -handler
Controller

Controller command is used find all controller defined in an application, annotation defined on controller class or method. It can also be used to create empty controller, CRUD controller and controllers based on template.

List controller

Running controller command without any parameter lists all controllers defined in application. This prints information as shown below

  • Controller full class path
  • Context it belongs to
  • Number of route exists in controller
php nishchay controller
Specific controller information

Passing controller full class path after controller command prints information of controller same as above command.

php nishchay controller {class}
Annotation defined on controller class

Passing -annotation following controller class will lists all annotation defined on controller class. This will print annotation name and parameter syntax.

php nishchay controller {class} -annotation
Annotation defined on controller method

We can also find list of annotations defined on controller method. To view this information just use below command:

php nishchay {class} -annotation -method {method}
Create empty controller

When we create empty controller using console command, Controller with specified class will be created at appropriate location based on full class name. Required annotation also be created on class declaration.

Created controller will comes with one method called toDo along with syntax for route annotation. This skelton method is shown below:

/**
* Route(path='toDo')
*/
public function toDo()
{
   // REMOVE OR EDIT THIS ROUTE
}

Command to create empty controller is shown below:

php nishchay controller -create {name}
Create CRUD controller

To create controller which have create, update, delete and read operation. We just need to pass -crud parameter after class name.

php nishchay controller -create {name} -crud

When we execute above command, Nishchay will ask for route. Nishchay will not check if route already exists or not, it will directly creates controller with route prefix as entered by us. Below method with route will be created upon successful execution of command.

Method Route HTTP
index [routePrefix]/ GET
create [routePrefix]/ POST
fetch [routePrefix]/{id} GET
update [routePrefix]/{id} PUT
delete [routePrefix]/{id} DELETE
Create controller from template

Apart from creating empty or crud controller, Nishchay also has predefined controllers which can be created using -template parameter.

Some templates have more than one controller, in that case Nishchay will ask us to create all controller or specific controller. If we choose specific then before creating each controller console will be prompted with answer yes or no for each controller creation. If there are multiple controllers in template then specify namespace within which all controllers need to be created or pass class name in case template having only one controller.

php nishchay controller -create {name} -template {templateName}

We can create controllers from following list templates.

Template name Class list
employee
  • Employee
  • Attendance
hostel
  • Hostel
  • Fees
  • Building
  • Room
  • Guest
Entity

Using console command we can also find list of entities exists in an application. We can also find list of properties, derived properties, triggers of specific entity. Console command also allows creating empty, CRUD entity or entity from template.

List all entities

Just passing entity command without any parameter will list all entities exists in an application.

php nishchay entity

This will print full class name with table name it is mapped to in DB.

Entity properties

To find out list of properties and its data type just pass {class} -property.

php nishchay entity {class} -property
Derived properties
php nishchay entity {class} -derived

Upon executing above command, it will print derived properties of entity class. If there is no derived properties exist in entity class then will print error: Derived property not found for: {class}.

Identity property

Identity property is property which uniquely identifies each record in entity class, to know identity property of any entity class use below command.

php nishchay entity {class} -identity
Triggers

Just like other command to find properties, derived property and etc, trigger can be found by passing -trigger parameter.

php nishchay entity {class} -trigger

This will print details related to trigger like its callback method name, for which it is defined for(insert, update, remove), when it need to be executed and its priority.

Create empty entity

Creating empty entity means class with only one property which is identity property of class. This class also has @entity annotation defined on it and it will be mapped to table name as base class name.

Suppose we are creating an empty entity called UserAddress then its identity property will be created with userAddressId. Command to create empty entity is shown below.

php nishchay entity -create {name}
Create CRUD entity

CRUD entity means it will have following properties along with identity property.

Property name Data type Use
createdAt datetime Date and time when record was inserted into table
createdBy int Id of use who inserted record
updatedAt datetime Date and time when record was ;ast updated. This should be changed on every update
updatedBy int Id of user who last updated record
deletedAt datetime Date and time when record was deleted. This should be changed when record is soft deleted
deletedBy int Id of user who has deleted record
isDeleted boolean Whether record is soft delete. Default to _false_

Command to create CRUD entity is shown below:

php nishchay entity -create {name} -crud
Create Entity from template

Entities can also be created using template. There can be multiple or single entity in template. If there are multiple entities in template, console asks us whether we want create all of entities or specific. Command to create entity from template is shown below.

php nishchay entity -create {name} -template {templateName}

If template has only one entity then pass only namespace or pass entity full class name. For template which creates multiple entities, those entities will be created in provided namespace.

Template name Class list
employee
  • Employee
  • Attendance
  • Salary
  • Appraisal
hostel
  • Hostel
  • Fees
  • Furniture
  • Building
  • Room
  • Guest
  • Mess
  • Visitor
category Category
tree Tree
user
  • User
  • UserPassword
  • Session
  • UserPrivacy
  • PrivacyMember
  • UserPermission
activity
  • Activity
  • AfftectedEntity
  • AfftectedProperty
message
  • Thread
  • ThreadMember
  • Message
  • MessageAttachment
post
  • Post
  • PostCategory
  • Attachment
  • Comment
asset
  • Asset
  • LifeCycle
Generate new entity

To create new entity just execute below command:

php nishchay entity -generate -new

When above command is executed, generate will first ask for entity name. Then it will keep asking new each property which needs to be created. First property is considered as identity of entity and its data auto chosen as int.

Once all properties are entered, type q and Enter to finish creating entity.

Generate entities from DB

To create entities for all tables in DB, use below command:

php nishchay entity -generate -db

Upon executing above command, generator will first ask whether you want create entities for all table or specific. If we choose specific then it will keep asking before creating entity of table. If don't want to create entity of specific table, enter n.

By default entities are created from default database connection. If want to create entities from specific database connection, just database connection after command:

php nishchay entity -generate -db {connectionName}
Generate entity form DB specific table

To create entity of specific table, use below command:

php nishchay entity -generate -table name

This will create entity for provided table name from default database connection. To create entity from specific database connection, pass connection name after command:

php nishchay entity -generate -table name {connectionName}
Events

Events are executed before & after controller & route. These events can be defined for global, scope and context. Using console command we can find events belongs to global, scope or context.

List all events

To view all events defined within application execute below command.

php nishchay event
Context events

Events belongs to specific context can be found by passing context parameter with context name.

php nishchay event -context {contextName}
Scope events

Events belongs to specific scope can be found by passing scope parameter with scope name.

php nishchay event -scope {scopeName}
Global events

Just passing -global following event command lists events defined for global.

php nishchay event -global
Form: Generate

Using console command we can create form from entity class. To create it use below command:

php nishchay form -generate -entity {name}

This will create form class with all form field method from entity properties. It also adds validation based on property required, data type and other validation if any defined on it.

Prototype

When we create prototype using console command it creates following things:

  1. Entity
  2. Form
  3. Controller along with CRUD implementation.

Prototype can be created new or from database table name.

New prototype

To create new prototype use below command:

php nishchay prototype -generate -new  

Upon executing above command, generator will first create entity by asking for entity name and it will keep asking for each property which needs to be created. This process is similar to creating new entity.

Once entity is create, generator will create form class based on this entity. At the end controller will be created with CRUD operation using CRUD prototype which will have following things already implemented.

  1. List records along with its pagination
  2. View record
  3. Create record
  4. Update record
  5. Delete record
from entity

To create prototype form entity, rather interactive command as explained above. Use below command:

php nishchay prototype -generate -table {name}

By default this will create prototype from default database connection. To create from specific database connection, use below command:

php nishchay prototype -generate -table {name} {connectionName}