📜 ⬆️ ⬇️

Mikron. PHP ORM

Simple things should be simple, and complex things - possible)
(Larry Wall)

You can download the distribution kit from the repository: bitbucket.org/sciner/mikron-php-orm
Installation instructions are a bit lower, or you can take it from the distribution itself along the path /mikron/admin/help/install.txt

What it is and what it allows:


These lines perfectly characterize the concept embodied in Mikron. Six months ago I started developing my own php-orm system. At the moment, I realized a lot of things, I think, the time has come to bring the product to the public.
')
Mikron, allows you to design and manage multiple sites at once. Naturally for each site is allocated a separate folder, database, and more.

What begins:


Designing a site begins with a description of the entities in the schema file (s). Entities are described in XML files. The system can have an unlimited number of such files. There is a possibility of their dynamic loading by the method
$mikron -> Schema -> Add ( $file , $schema_name ) ;
. As a result, all entities are simultaneously compiled, i.e. DB mapping and classes are created. All classes are inherited from the base in which the main methods are implemented. Each entity has a set of fields that can be of a different type.
There are own types of fields ORM, picture, password ...
As a field type, an entity can have another entity (parent), or a collection of entities (child list).
Also the field “ENUM” described may be a type of field.

Configuration:


The schema file is a UTF-8 encoded XML file. The schema file describes reference books and entities.

Example of describing the entity "Message":
< entity name ="T_MESSAGE" description ="" inmenu ="/" displayname ="{{USER}}" >
< field name ="contacts" type ="varchar(64)" description ="E-mail" validator ="required: true" />
< field name ="user" type ="T_USER" description ="" hidden ="1" default ="mikron:user()" />
< field name ="state" type ="STATES" description ="" hidden ="1" default ="1" />
< field name ="dt" type ="datetime" description ="" hidden ="1" default ="now()" />
</ entity ></ code >
< entity name ="T_MESSAGE" description ="" inmenu ="/" displayname ="{{USER}}" >
< field name ="contacts" type ="varchar(64)" description ="E-mail" validator ="required: true" />
< field name ="user" type ="T_USER" description ="" hidden ="1" default ="mikron:user()" />
< field name ="state" type ="STATES" description ="" hidden ="1" default ="1" />
< field name ="dt" type ="datetime" description ="" hidden ="1" default ="now()" />
</ entity ></ code >

An example of the description of the directory:
< code > < enum name ="STATES" description ="" >
< element name ="active" value ="1" description ="" />
< element name ="hidden" value ="2" description ="" />
< element name ="deleted" value ="3" description ="" hidden ="1" />
< element name ="closed" value ="4" description ="" hidden ="1" />
</ enum >

where the hidden attribute of the element element means the visibility of the element in the list on the edit form.

Key features:


Mikron has a bunch of built-in modules that are loaded as needed in the following way:
$mikron -> Modules -> LoadModule ( 'slidewindow' ) ;
. The system also has its own executable instructions engine, compatible with Smarty.

At any time there is an opportunity to make a backup of the entire site, as well as restore the site from a backup for this, the menu option [System] → [Export, import]

The system supports morphological search. Called as follows:
$mikron -> EntityManager -> search ( " " ) ;

Returns an array with initialized entities of all types that support the search.

Database Abstraction:


Selection of an array of entities of a certain type:
$res = $mikron -> Queries -> Query ( "T_USER" , [ aId = null ] , [ Criteria / Criterion ] ,) ;

Selection of one instance of a certain type of entity:
$ < code > user = $mikron -> Queries -> QueryOne ( "T_USER" ) ;
If the entity could not be loaded, the function returns null.
An example of building a criterion:
$cr = new Criteria ( ) ; <br/>
$cr -> Add ( new Criterion ( 'user' , $user -> id ) ) ; <br/>
$cr -> Add ( new Criterion ( 'message/recipient' , $user -> id ) ) ; <br/>
$links = $mikron -> Queries -> Query ( 'MESSAGE_LINK' , null , $cr ) ;

Paginated output support:
$cr = new Criteria ( ) ; <br/>
$cr -> Add ( new Criterion ( 'user' , $user -> id ) ) ; <br/>
$paginator = new MikronPaginator ( 'meslinks' , 10 ) ; <br/>
$links = $mikron -> Queries -> Query ( 'MESSAGE_LINK' , null , $cr , null , $paginator ) ; <br/>
$mikron -> EntityManager -> ShowList ( $links ) ; <br/>
$paginator -> Draw ( ) ;

Work with entities:


Creating a new entity instance:
$user = new T_USER ( ) ;

Reading an entity from the database knowing the ID:
$user = new T_USER ( $id ) ;

Calling an automatic form for creating or editing an entity instance:
$mikron -> EntityManager -> ShowForm ( new T_USER ( ) ) ;

Outputting an entity using an arbitrary pattern:
echo $user -> toStringEx ( ' {name}<br />: {country/name}<br />ID : {country->value}' ) ;

This shows that within the template, the output of the values ​​of parent-attributes is indicated by indicating the path to them. For example, here {country / name} displays the name of the country, and displays the object's {country-> value} identifier.
An example of creating, saving and reading an entity:
$user = new T_USER ( ) ; <br/>
$user -> login -> value = "SCINER" ; <br/>
$user -> password -> value = "123" ; <br/>
$user -> contacts -> value = "sciner@yandex.ru" ; <br/>
$user -> Save ( ) ; <br/>
$addeduser = new T_USER ( $user -> id ) ;

Short way to read an entity attribute:
// <br/>
$mes = new MESSAGE_LINK ( 3 ) ; <br/>
// <br/>
echo $mes -> message -> value -> recipient -> value -> country -> value -> name -> value ; <br/>
// <br/>
echo $mes -> getValue ( 'message/recipient/country/name' ) ;

Access and security:


The system is organized access control using such a thing as a role, which is implemented as a T_ROLE entity. You can check whether the current user has a role using this method:
$mikron -> Users -> CurrentUser ( ) -> hasRole ( 'patient' ) ;

Access control is carried out in the administrator module in the System \ Access menu;
PS I will not tell everything at once here. But after registration, I plan to show and tell everything here, as well as answer all questions. I really want to develop Mikron collective intelligence. Thank you in advance

Source: https://habr.com/ru/post/75715/


All Articles