K4:Registration of Unit Classes
From In-Portal Developers Guide
(→Подмена классов: дополнение) |
Current revision (02:37, 28 November 2010) (view source) (minor change) |
||
(6 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
{{toc | category = Unit Configs | sortkey = 001.001}} | {{toc | category = Unit Configs | sortkey = 001.001}} | ||
- | + | To use a particular class in <code>In-Portal</code>, it must first be registered. Class registration is a process, the result of which is that <code>In-Portal</code> learns about: | |
- | * | + | * The name of the class; |
- | * | + | * The location of the file where the class is written; |
- | * <code>pseudo</code> | + | * The <code>pseudo</code> that's going to be used when referring to an object of the class. |
- | {{InfoBox|'''<code>pseudo</code>''' - | + | {{InfoBox|'''<code>pseudo</code>''' - a keyword that can be used from any place in <code>In-Portal</code> application to get an object of a class that's registered under the <code>pseudo</code>.}} |
- | == | + | |
- | + | == Getting an Object == | |
+ | The '''<code>kApplication::recallObject</code>''' can be used to get an object, for example: | ||
<source lang="php"> | <source lang="php"> | ||
$price =& $this->Application->recallObject('price'); | $price =& $this->Application->recallObject('price'); | ||
Line 14: | Line 15: | ||
</source> | </source> | ||
- | + | In order for <code>auto-complete</code> to work in [http://www.zend.com/products/zend_studio Zend Studio], it's necessary to put a specially formatted comment after getting an object. The general form of this kind of comment is: | |
<source lang="php"> | <source lang="php"> | ||
/* @var $variable_name ClassName */ | /* @var $variable_name ClassName */ | ||
</source> | </source> | ||
- | == | + | == Registering a Class == |
- | + | In a [[K4:Unit Configs|configuration file]] there are a number of options with similar formats for the purpose of registering classes in <code>K4</code>: | |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! Option Name || Corresponding <code>pseudo</code> |
|- | |- | ||
| {{ConfigProperty|ItemClass|array}} || <code><prefix></code> | | {{ConfigProperty|ItemClass|array}} || <code><prefix></code> | ||
Line 36: | Line 37: | ||
|} | |} | ||
- | + | In the above table, "<code><prefix></code>" is the value of the [[K4:Unit Configs#Prefix|Prefix]] option in a configuration file. The value of each above option (except '''<code>RegisterClasses</code>''') is an array of the following format: | |
<source lang="php"> | <source lang="php"> | ||
Array ( | Array ( | ||
Line 46: | Line 47: | ||
</source> | </source> | ||
- | + | All of the keys in this array, except '''<code>require_classes</code>''', are required. However, the value of some of the keys can be empty. | |
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! Name|| Description |
|- | |- | ||
- | | {{ConfigProperty|class|string}} || | + | | {{ConfigProperty|class|string}} || Name of the class being registered (new of new class or system class). |
|- | |- | ||
- | | {{ConfigProperty|file|string}} || | + | | {{ConfigProperty|file|string}} || Name of the file where the class is written (one file per class); if empty, then it's assumed that a system class is being used. |
|- | |- | ||
- | | {{ConfigProperty|build_event|string}} || | + | | {{ConfigProperty|build_event|string}} || Event from [[EventHandler:About|event handlers]], used for initializing copies of the class being registered (i.e. an object). In other words, this is a class constructor, which is located in the [[EventHandler:About|event handler]]. |
|- | |- | ||
- | | {{ConfigProperty|require_classes|mixed}} || | + | | {{ConfigProperty|require_classes|mixed}} || Name of the class(es), which must be loaded before using this class. If one class is indicated, then the value of the key can be a String. If several classes are indicated, then the value of the key must be an Array. |
|} | |} | ||
- | {{TipBox| | + | {{TipBox|The value of '''all''' keys (except [[#build_event|build_event]]) of this array must follow [[K4:Назначение имён|naming conventions]] rules]].}} |
- | == | + | == Substituting Classes == |
- | + | There are cases when one or more classes used in the system must be substituted. To do this, the <code>RegisterClasses</code> key is used. When registering or substituting a class, in the <code>RegisterClasses</code> key it's required to indicate an additional <code>pseudo</code> key. In this case it must be set because it's not known automatically (like in all of the previously described situations). | |
<source lang="php"> | <source lang="php"> | ||
'RegisterClasses' => Array ( | 'RegisterClasses' => Array ( | ||
- | Array ('pseudo' => 'u_TagProcessor', 'class' => 'EUserTagProcessor', 'file' => 'e_user_tp.php'), // | + | Array ('pseudo' => 'u_TagProcessor', 'class' => 'EUserTagProcessor', 'file' => 'e_user_tp.php'), // substitute a user tag processor |
- | Array ('pseudo' => 'PermissionsHelper', 'class' => 'ЕPermissionsHelper', 'file' => 'e_permission_helper.php'), // | + | Array ('pseudo' => 'PermissionsHelper', 'class' => 'ЕPermissionsHelper', 'file' => 'e_permission_helper.php'), // substitute a class helper |
) | ) | ||
</source> | </source> | ||
- | * | + | * When substituting a class the "<code>pseudo</code>" must be set with which the original (i.e. the one being substituted) class was registered. |
- | * | + | * Registration of the substitute class must be done after registration of the original class. This requirement is automatically fulfilled if class substitution is done in the "<code>custom/units/sections/sections_config.php</code>" file. |
+ | |||
+ | == Standard Classes == | ||
+ | The following standard classes are available: | ||
+ | * '''<code>kDBItem</code>''' - class for working with '''one''' database record; | ||
+ | * '''<code>kDBList</code>''' - class for displaying the contents of a database table (filters, per-page, etc.); | ||
+ | * '''<code>kDBEventHandler</code>''' - class for processing standard events from lists and edit forms; | ||
+ | * '''<code>kDBTagProcessor</code>''' - class for processing standard tags used for displaying information; | ||
+ | * '''<code>kEventHandler</code>''' - root class for all event handlers (use only with the goal of reducing memory usage); | ||
+ | The value of the [[#file|file]] key should be empty for standard classes. | ||
+ | |||
+ | [[en:{{FULLPAGENAME}}]] | ||
+ | [[ru:K4:Регистрация классов]] | ||
- | + | Translated from: [http://guide.in-portal.org/rus/index.php?title=K4:%D0%A0%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B0%D1%86%D0%B8%D1%8F_%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%BE%D0%B2&oldid=1070 revision 1070] | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + |
Current revision
| ||
---|---|---|
Статьи в этой категории | ||
|
To use a particular class in In-Portal
, it must first be registered. Class registration is a process, the result of which is that In-Portal
learns about:
- The name of the class;
- The location of the file where the class is written;
- The
pseudo
that's going to be used when referring to an object of the class.
pseudo - a keyword that can be used from any place in In-Portal application to get an object of a class that's registered under the pseudo .
|
Contents |
Getting an Object
The kApplication::recallObject
can be used to get an object, for example:
$price =& $this->Application->recallObject('price'); /* @var $price kDBItem */
In order for auto-complete
to work in Zend Studio, it's necessary to put a specially formatted comment after getting an object. The general form of this kind of comment is:
/* @var $variable_name ClassName */
Registering a Class
In a configuration file there are a number of options with similar formats for the purpose of registering classes in K4
:
Option Name | Corresponding pseudo
|
---|---|
ItemClass (array) | <prefix>
|
ListClass (array) | <prefix>_List
|
EventHandlerClass (array) | <prefix>_EventHandler
|
TagProcessorClass (array) | <prefix>_TagProcessor
|
RegisterClasses (array) | Задаётся в ручную в ключе "pseudo ".
|
In the above table, "<prefix>
" is the value of the Prefix option in a configuration file. The value of each above option (except RegisterClasses
) is an array of the following format:
Array ( 'class' => 'ClassName', 'file' => 'FileName', 'build_event' => 'BuildEventName', 'require_classes' => 'RequiredClassName' )
All of the keys in this array, except require_classes
, are required. However, the value of some of the keys can be empty.
Name | Description |
---|---|
class (string) | Name of the class being registered (new of new class or system class). |
file (string) | Name of the file where the class is written (one file per class); if empty, then it's assumed that a system class is being used. |
build_event (string) | Event from event handlers, used for initializing copies of the class being registered (i.e. an object). In other words, this is a class constructor, which is located in the event handler. |
require_classes (mixed) | Name of the class(es), which must be loaded before using this class. If one class is indicated, then the value of the key can be a String. If several classes are indicated, then the value of the key must be an Array. |
The value of all keys (except build_event) of this array must follow naming conventions rules]]. |
Substituting Classes
There are cases when one or more classes used in the system must be substituted. To do this, the RegisterClasses
key is used. When registering or substituting a class, in the RegisterClasses
key it's required to indicate an additional pseudo
key. In this case it must be set because it's not known automatically (like in all of the previously described situations).
'RegisterClasses' => Array ( Array ('pseudo' => 'u_TagProcessor', 'class' => 'EUserTagProcessor', 'file' => 'e_user_tp.php'), // substitute a user tag processor Array ('pseudo' => 'PermissionsHelper', 'class' => 'ЕPermissionsHelper', 'file' => 'e_permission_helper.php'), // substitute a class helper )
- When substituting a class the "
pseudo
" must be set with which the original (i.e. the one being substituted) class was registered. - Registration of the substitute class must be done after registration of the original class. This requirement is automatically fulfilled if class substitution is done in the "
custom/units/sections/sections_config.php
" file.
Standard Classes
The following standard classes are available:
-
kDBItem
- class for working with one database record; -
kDBList
- class for displaying the contents of a database table (filters, per-page, etc.); -
kDBEventHandler
- class for processing standard events from lists and edit forms; -
kDBTagProcessor
- class for processing standard tags used for displaying information; -
kEventHandler
- root class for all event handlers (use only with the goal of reducing memory usage);
The value of the file key should be empty for standard classes.
Translated from: revision 1070