Library Integration



ZN Framework offers many libraries to make your operations easier. Additionally, you may want to include and use your own library or libraries that you are used to using externally. This integration process is very easy. All you have to do is download your library and drag and drop it to the corresponding directory in ZN Framework. You can have your external libraries in 2 places in ZN Framework.

Dizin: Projects/Any/Libraires/
Dizin: External/Libraries/

Libraries created in these directories become available in the project without any settings.

 

 

# Section Headings


# Project Libraries
# External Libraries
# Composer Libraries

Installation with Devtools

# Alias Name
# Class Map

Extending the Scan Area

 

 

# Project Libraries


Directory: Projects/ProjectDirectory/Libraries/

It is the directory where your libraries specific to your projects will be found.

 

 

# External Libraries


Directory: External/Libraries/

Libraries you add in this directory will be valid for all projects. Thus, you can use your libraries that do not change from project to project by throwing them into this directory.

 

 

# Composer Libraries


Packages downloaded with Composer can be used without any settings.

packagist -> symfony/translation

For example, you have downloaded the above symfony/translation package, and after this you can see that the directory where the project is located is a directory named vendor/ and the directory and files of the downloaded package are created. If you want to turn off this feature or specify a different directory, you can perform the operations through the configuration file whose path is specified below.

File: Settings/Autoloader.php
'composer' => true

Eğer vendor/ dizini yerine farlı bir dizin veya yol kullanılıyorsa bu anahtara autoload.php dosyasının konumunu tanımlanır.

'composer' => 'External/vendor/autoload.php'
Installation with Devtools

If the Devtools is installed, you can download it from the menu below.

URL: yoursite.com/Devtools/packages

 

 

# Alias Name


You can alias the classes in the ZN Framework for easy access. Use the file below for configuration.

File: Settings/Autoloader.php -> aliases

Configuration

array $aliases = ['alias name' => 'origin name']
An array of classes to be nicknamed. Definitions are made as alias -> origin.
'aliases' => 
[
    # alias name                 => origin name
    'Project\Controllers\Import' => 'Import',
    'U'                          => 'User'
];

In the example above, we have stated that we can now use the Import:: library as U:: without defining it in controllers with use and the User:: library.

File: Controllers/Home.php
<?php namespace Project\Controllers;

class Home extends Controller
{
    public function main()
    {
        Import::view('example'); # artık use ile tanımlanmaya ihtiyaç duymuyor.
    }
}
Info: Giving aliases does not prevent classes from being used with their original names.

 

 

# Class Map


The path information is written to the map.php file included in each project so that the classes included in the ZN Framework can be called automatically. After the filename of a class is written to the map.php file, no rewriting is done if the class name is changed without changing the filename. In such cases, the $this->restart() method is run just before the class call in the relevant controller, and it is rewritten to the map.php file. Or you can manually delete the map.php file. This file is rebuilt in the next run phase. The location of the class map file is as follows.

File: Projects/ProjectDirectory/map.php

If class creation cannot be performed due to the situation mentioned above, you can recreate this file in the corresponding controller as shown in the example below.

File: Controllers/Home.php
public function main()
{
    $this->restart();

    Example::run();
}
Extending the Scan Area

The auto installer's class scan area scans Controllers/, Models/, Commands/ and Libraries/ directories by default. In addition to these directories, you can define other directories that you want to be crawled.

File: Settings/Autoloader.php -> classMap

Configuration

array $classMap = ['directory']
The array of directories to be scanned.
'classMap' => 
[
    'MyClasses/',
    LIBRARIES_DIR,
    EXTERNAL_LIBRARIES_DIR,
    CONTROLLERS_DIR,
    EXTERNAL_CONTROLLERS_DIR,
    MODELS_DIR,
    EXTERNAL_MODELS_DIR,
    COMMANDS_DIR,
    EXTERNAL_COMMANDS_DIR
];

In the example above, we have added another directory named MyClasses/ in addition to the directories specified by default for scanning. So the classes you create in MyClasses/ directory will now be loaded automatically.