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.
Libraries created in these directories become available in the project without any settings.
# Section Headings
# Project Libraries
# External Libraries
# Composer Libraries# Alias Name
# Class Map
# Project Libraries
It is the directory where your libraries specific to your projects will be found.
# 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.
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.
'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'
If the Devtools is installed, you can download it from the menu below.
# Alias Name
You can alias the classes in the ZN Framework for easy access. Use the file below for configuration.
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.
<?php namespace Project\Controllers;
class Home extends Controller
{
public function main()
{
Import::view('example'); # artık use ile tanımlanmaya ihtiyaç duymuyor.
}
}
# 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.
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.
public function main()
{
$this->restart();
Example::run();
}
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.
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.