Generate Library



( ZN >= 4.0.1 )

The Generate :: library has been developed to create controller , models and library schemas faster . The reason for the draft is that the classes that are created are empty. More precisely, it is the skeleton of the class. Examples of use are given below.

 

# Methods


void databases ( Void )
Bool model ( String $ name , Array $ settings = [] )
Bool controller ( String $ name , Array $ settings = [] )
Bool library ( String $ name , Array $ settings = [] )
Bool grandVision ( Mixed $ databases = NULL )
Bool delete ( String $ name , String $ type = 'controller' , String $ app = DEFAULT_PROJECT )
this settings ( Array $ settings )

 

# Settings Parameter


Settings for how the contents of these files will be made when the library , model, or controller is created. The second parameter of the following methods is the array parameter that will contain these settings. Or you can use the settings () method. Let's give some information about the array arguments that this parameter can take.

Tour Key Meaning
String oBJECT The object type is set. This parameter can be set if you want to create an interface or abstract class outside the class.
String namespace Used to define the namespace to the file.
Array user Used to identify the classes that have namespace with use.
String extends The class is used to include the expansion class.
String implements Your class name is used to include namespaces.
Array traits Your classroom is used to add traits.
Array VARs Class is used to define variables.
Array constants Class is used to define constants.
Array functions Your classroom is used to define functions.

 

# Databases ( ZN >= 4.3.0 )


Designed in the Databases / directory is used to implement. See for details .

Parameters

void
return Bool

Console Usage

php zerocore generate-databases

Use of

Generate::databases();

 

# Controller ( ZN> = 4.0.1 )


Used to create the controller file.

Parameters

String $ name File name.
Array $ parameters Contents to include in the file.
return Bool

Console Usage

php zerocore create-controller MyController

Use of

Generate::controller('Example', 
[
    'extends'    => 'Controller',
    'functions'  => ['main', 'test']
]);

Creating on Different Projects

If you want to add a controller in a different project;

Generate::controller('TestLib', 
[
    'application' => 'OtherApp',
    'extends'     => 'Controller',
    'functions'   => ['main', 'test']
]);

 

# Model ( ZN >= 4.0.1 )


Used to create a model file.

Parameters

String $ name File name.
Array $ parameters Contents to include in the file.
return Bool

Console Usage

php zerocore create-model MyModel

Use of

Generate::model('TestLib', 
[
    'extends'    => 'GrandModel',
    'constants'  => ['key' => '"value"']
]);

 

# Library ( ZN> = 4.0.1 )


Used to create a library file.

Parameters

String $ name File name.
Array $ parameters Contents to include in the file.
return Bool

Use of

Generate::library('TestLib', 
[
    'implements' => 'TestLibInterface',
    'extends'    => 'Controller',
    'namespace'  => 'TestExample',
    'use'        => ['Folder', 'File' => 'F'],
    'functions'  => ['main', 'test' => ['a', 'b' => '10', '...args']],
    'constants'  => ['TEST' => '"Test"', 'NUM' => '10'],
    'traits'     => ['abc', 'xxx'],
    'vars'       => ['protected:test' => '10', 'examples', 'test2' => '"Test"' ]
]);
File: Libraries / TestLib.php
namespace TestExample;

use Folder;
use File as F;

class TestLib extends Controller implements TestLibInterface
{
    use abc;
    use xxx;

    const TEST = "Test";
    const NUM = 10;

    protected $test = 10;
    public $examples = 10;
    public $test2 = "Test";

    public function main()
    {
        // Your codes...
    }

    public function test($a, $b = 10, ...$args)
    {
        // Your codes...
    }
}

 

# GrandVision ( ZN >= 4.0.23 )


The use of this method requires that database connections be made first. It makes each of the tables included in the database into a model file and works directly with the tables. After running this method, you can see that the tables of the current database are filed under Models / Visions / directory. For example, if the table name is Users and you accept a model file with this name, you need to use the class name and Vision last element to use it. Like UsersVision :: result () .

Parameters

Mixed $ databases = NULL Database name or names. If the parameter is not specified, the models belonging to the table belonging to the entire database are created.
return void

Console Usage

php zerocore create-grand-vision

Use of

Generate::grandVision();

After running the above method, create table models in Models / Visions / directory. These models are used with the GrandModel extension. In other words, the use of the GrandModel extends to betting on the database section. The contents of the generated file are as follows.

File: Models / Visions / UsersVision.php
namespace VisionsTest;

use GrandModel;

class InternalUsersVision extends GrandModel
{
    const table = 'users';
}

Use of Models

To use these model files created;

output( UsersVision::row() );
output( UsersVision::totalRows() );
output( UsersVision::drop() ); 

Multiple Database Usage

If more than one database needs to be used, it will be necessary to send the parameter if it differs from other settings except database names.

Generate::grandVision
([
    'Test'    => ['user' => 'zn', 'password' => '1234'],
    'Example' => ['user' => 'zero', 'password' => '4242']
]);

In the above example , it is shown that model files of 2 different databases are created with different settings.

The Userstable mentioned above is an example. See the Grand Extension narrative to see which methods can be used with this model file .

 

# Settings ( ZN> = 4.0.1 )


It is an optional method. Can be used instead of parameter 2 .

Parameters

Array $ parameters Contents to include in the file.
return this

Use of

Generate::settings
([ 
    'extends'    => 'GrandModel', 
    'constants'  => ['key' => '"value"'] 
])->model('TestLib');