Amiro.CMS API Reference
Amiro.Ru / Manual
Loading search...

The AMI class

• Introduction

AMI hub class.

• Class synopsis

AMI {
/* Methods */
// Adds module resource mapping.
public static addModResources ( string $modId, string $type, [ $aParts = null ], [ bool $doCombine = true ] ) returns void;
// Adds/changes mapping for resource.
public static addResource ( string $resId, string $resClass ) returns void;
// Adds resource mapping.
public static addResourceMapping ( $aMapping ) returns void;
// Callback filterring extesion views from extensions array.
public static cbFilterExtViews ( type $extModId ) returns bool;
// Cleans up module extensions.
public static cleanupModExtensions ( string $modId ) returns void;
// Is edit mode enabled.
public static editModeEnabled ( ) returns bool;
// Returns class name prefix by module id.
public static getClassPrefix ( string $modId ) returns string;
// Returns CMS edition.
public static getEdition ( ) returns string;
// Returns module id by its class name.
public static getModId ( string $class ) returns string;
// Returns path to module distributive by its id.
public static getModulePath ( string $moduleId, [ bool $exitOnError = true ], [ string $localPath = 'modules/code' ] ) returns string|null;
// Returns module option value.
public static getOption ( string $modId, [ string $name = '' ] ) returns mixed;
// Returns module lazy option value.
public static getOptionLazy ( string $modId, [ string $name = '' ] ) returns mixed;
// Returns path to installed plugin directory (i. e. '_local/plugins/sample/').
public static getPluginDataPath ( string $pluginId ) returns string;
// Returns plugin option by its id.
public static getPluginOption ( string $pluginId, string $name, [ string $secret = '' ] ) returns mixed;
// Returns path to plugin distributive by its id.
public static getPluginPath ( string $pluginId, [ bool $exitOnError = true ] ) returns string|null;
// Returns module property value.
public static getProperty ( string $modId, [ string $name = '' ] ) returns mixed;
// Returns resource object by resource id.
public static getResource ( string $resId, [ $aArgs = array() ], [ bool $isLazy = false ] ) returns object;
// Returns resource model by resource id.
public static getResourceModel ( string $resId, [ $aArgs = array() ], [ bool $bAsInstance = true ] ) returns object;
// Returns resource singleton by resource id.
public static getSingleton ( string $resId, [ $aArgs = array() ] ) returns object;
// Returns CMS versions.
public static getVersion ( [ mixed $product = false ], [ mixed $type = false ] ) returns mixed;
// Checks whether module is a category module.
public static isCategoryModule ( string $modId ) returns bool;
// Returns true if module option is set and is true.
public static issetAndTrueOption ( string $modId, string $name ) returns bool;
// Returns true if module option is set and is true.
public static issetAndTrueOptionLazy ( string $modId, string $name ) returns bool;
// Returns true if module propert is set and is true.
public static issetAndTrueProperty ( string $modId, string $name ) returns bool;
// Returns true if module option is set.
public static issetOption ( string $modId, string $name ) returns bool;
// Returns true if module option is set.
public static issetOptionLazy ( string $modId, string $name ) returns bool;
// Returns true if module propery is set.
public static issetProperty ( string $modId, string $name ) returns bool;
// Returns true if resource singleton is initialized.
public static isSingletonInitialized ( string $resId ) returns bool;
// Sets new options values, returns array of replaced options with original values.
public static replaceOptions ( string $modId, $aOptions ) returns array;
// Restores global scope modified in the environment setting up entry point. See AMI::saveGlobalScope() for usage example.
public static restoreGlobalScope ( [ string $name = '' ] ) returns void;
// Saves global scope, can be restored via AMI::restoreGlobalScope().
public static saveGlobalScope ( [ string $name = '' ], [ $aScope = null ] ) returns void;
// Saves module options.
public static saveOptions ( string $modId ) returns bool;
// Sets module option value.
public static setOption ( string $modId, string $name, mixed $value ) returns void;
// Sets module option value.
public static setOptionLazy ( string $modId, string $name, mixed $value ) returns void;
// Is toolbar enabled.
public static toolbarEnabled ( ) returns bool;
// Returns date format by locale id.
public getDateFormat ( [ string $locale = 'en' ], [ string $type = 'DB' ] ) returns string;
// Initialize module extensions.
public initModExtensions ( string $modId, [ string $optSrcId = '' ], [ AMI_Mod $oModController = NULL ] ) returns void;
}

• Class Methods

// Adds module resource mapping.
public static addModResources ( string $modId, string $type, [ $aParts = null ], [ bool $doCombine = true ] ) returns void;
  • string $modId
    Module id
  • string $type
    Resource type
  • array|null $aParts
    Parts, resource list depending on type:
    • table: array('model', 'model/item', 'model/item/modifier', 'model/list'), array('model', 'model/item', 'model/list') by default;
    • module: array('model', 'controller/adm', 'controller/frn'), no defaults;
    • list/adm: array('controller/adm', 'list_actions/controller/adm', 'list_group_actions/controller/adm', 'view/adm'), array('controller/adm', 'view/adm') by default;
    • form/adm: array('controller/adm', 'view/adm'), the same list by default;
    • filter/adm or other resource type in format {$type/adm}: array('controller/adm', 'model/adm', 'view/adm'), the same list by default.
  • bool $doCombine
    Add class mapping to the first class
  Example:
  •  // ami_sample_mapping.php {
  •  
  •  // Table models
  •  AMI::addModResources($modId'table'));
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/table/model'               => 'AmiSample_Table',
  •  //         $modId . '/table/model/list'          => 'AmiSample_TableList',
  •  //         $modId . '/table/model/item'          => 'AmiSample_TableItem'
  •  //         $modId . '/table/model/item/modifier' => 'AmiSample_TableItemModifier'
  •  //     )
  •  // );
  •  // AMI_Service::addClassMapping(
  •  //     array(
  •  //         'AmiSample_TableItem'  => 'AmiSample_Table',
  •  //         'AmiSample_TableList'  => 'AmiSample_Table'
  •  //     )
  •  // );
  •  
  •  // Module admin controller and module model
  •  AMI::addModResources($modId'module'array('model''controller/adm'));
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/module/model'          => 'AmiSample_State',
  •  //         $modId . '/module/controller/adm' => 'AmiSample_Adm',
  •  //     )
  •  // );
  •  // AMI_Service::addClassMapping(
  •  //     array(
  •  //         'AmiSample_State'  => 'AmiSample_Adm'
  •  //     )
  •  // );
  •  
  •  // Module admin filter controller, model and view
  •  AMI::addModResources($modId'filter/adm');
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/filter/controller/adm' => 'AmiSample_FilterAdm',
  •  //         $modId . '/filter/model/adm'      => 'AmiSample_FilterModelAdm',
  •  //         $modId . '/filter/view/adm'       => 'AmiSample_FilterViewAdm'
  •  //     )
  •  // );
  •  // AMI_Service::addClassMapping(
  •  //     array(
  •  //         'AmiSample_FilterModelAdm' => 'AmiSample_FilterAdm',
  •  //         'AmiSample_FilterViewAdm'  => 'AmiSample_FilterAdm'
  •  //     )
  •  // );
  •  
  •  // Module admin list controller and view
  •  AMI::addModResources($modId'list/adm');
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/list/controller/adm' => 'AmiSample_ListAdm',
  •  //         $modId . '/list/view/adm'       => 'AmiSample_ListViewAdm'
  •  //     )
  •  // );
  •  // AMI_Service::addClassMapping(
  •  //     array(
  •  //         'AmiSample_ListViewAdm' => 'AmiSample_ListAdm'
  •  //     )
  •  // );
  •  
  •  // Module admin form controller and view
  •  AMI::addModResources($modId'form/adm');
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/form/controller/adm' => 'AmiSample_FormAdm',
  •  //         $modId . '/form/view/adm'       => 'AmiSample_FormViewAdm'
  •  //     )
  •  // );
  •  // AMI_Service::addClassMapping(
  •  //     array(
  •  //         'AmiSample_FormViewAdm' => 'AmiSample_FormAdm'
  •  //     )
  •  // );
  •  
  •  // } ami_sample_mapping.php
  •  // ami_sample_specblock.php {
  •  
  •  AMI::addModResources($modId'module'array('model''controller/frn'));
  •  // replaces:
  •  // AMI::addResourceMapping(
  •  //     array(
  •  //         $modId . '/module/controller/frn' => 'AmiSample_Frn'
  •  //     )
  •  // );
  •  
  •  // } ami_sample_specblock.php
// Adds/changes mapping for resource.
public static addResource ( string $resId, string $resClass ) returns void;
  • string $resId
    Resource id
  • string $resClass
    Resource class mapping
// Adds resource mapping.
public static addResourceMapping ( $aMapping ) returns void;
  • array $aMapping
    Array having resource ids as keys and class names as values
All CMS entities should be described as resources. See ami_server.php for usage example.
// Callback filterring extesion views from extensions array.
public static cbFilterExtViews ( type $extModId ) returns bool;
  • type $extModId
    Extension module Id
// Cleans up module extensions.
public static cleanupModExtensions ( string $modId ) returns void;
  • string $modId
    Module Id
// Is edit mode enabled.
public static editModeEnabled ( ) returns bool;
// Returns class name prefix by module id.
public static getClassPrefix ( string $modId ) returns string;
  • string $modId
    Module id
Tags:
since 5.12.0
// Returns CMS edition.
public static getEdition ( ) returns string;
Full environment required.
Tags:
since 6.0.2
// Returns module id by its class name.
public static getModId ( string $class ) returns string;
  • string $class
    Class name
// Returns path to module distributive by its id.
public static getModulePath ( string $moduleId, [ bool $exitOnError = true ], [ string $localPath = 'modules/code' ] ) returns string|null;
  • string $moduleId
    Module id
  • bool $exitOnError
    Flag specifying exit on error, since 5.12.4
  • string $localPath
    Path to the local modules directory
Tags:
deprecated 5.14.4
since 5.12.4
// Returns module option value.
public static getOption ( string $modId, [ string $name = '' ] ) returns mixed;
  • string $modId
    Module id
  • string $name
    Module option name
// Returns module lazy option value.
public static getOptionLazy ( string $modId, [ string $name = '' ] ) returns mixed;
  • string $modId
    Module id
  • string $name
    Module option name
Tags:
since 7.0.0
// Returns path to installed plugin directory (i. e. '_local/plugins/sample/').
public static getPluginDataPath ( string $pluginId ) returns string;
  • string $pluginId
    Plugin id
Tags:
see ami_resp.php
// Returns plugin option by its id.
public static getPluginOption ( string $pluginId, string $name, [ string $secret = '' ] ) returns mixed;
  • string $pluginId
    Plugin id
  • string $name
    Option name
  • string $secret
    Secret key to avoid unauthorized access to plugin options if set from options.php using $api->setOption('secret', 'Secret key')
  Example:
// Returns path to plugin distributive by its id.
public static getPluginPath ( string $pluginId, [ bool $exitOnError = true ] ) returns string|null;
  • string $pluginId
    Plugin id
  • bool $exitOnError
    Flag specifying exit on error, since 5.12.4
Tags:
see ami_resp.php
// Returns module property value.
public static getProperty ( string $modId, [ string $name = '' ] ) returns mixed;
  • string $modId
    Module id
  • string $name
    Module property name
Could be called in full environment context only.
Tags:
since 6.0.2
// Returns resource object by resource id.
public static getResource ( string $resId, [ $aArgs = array() ], [ bool $isLazy = false ] ) returns object;
  • string $resId
    Resource id
  • array $aArgs
    Arguments passed to constructor
  • bool $isLazy
    Specifies to create object after first call
// Returns resource model by resource id.
public static getResourceModel ( string $resId, [ $aArgs = array() ], [ bool $bAsInstance = true ] ) returns object;
  • string $resId
    Resource id
  • array $aArgs
    Arguments passed to constructor
  • bool $bAsInstance
    Return resource model as instance
Appends '/model' tail to passed resource id. Can return resource model as instance or singleton.
// Returns resource singleton by resource id.
public static getSingleton ( string $resId, [ $aArgs = array() ] ) returns object;
  • string $resId
    Resource id
  • array $aArgs
    Arguments passed to getInstance() method or to the constructor
// Returns CMS versions.
public static getVersion ( [ mixed $product = false ], [ mixed $type = false ] ) returns mixed;
  • mixed $product
    Product
  • mixed $type
    Type
AMI::getVersion($product) returns all versions for a specific product
AMI::getVersion() returns all versions in an array
// Checks whether module is a category module.
public static isCategoryModule ( string $modId ) returns bool;
  • string $modId
    Module id
// Returns true if module option is set and is true.
public static issetAndTrueOption ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module option name
// Returns true if module option is set and is true.
public static issetAndTrueOptionLazy ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module option name
Tags:
since 7.0.0
// Returns true if module propert is set and is true.
public static issetAndTrueProperty ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module property name
Tags:
since 6.0.2
// Returns true if module option is set.
public static issetOption ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module option name
// Returns true if module option is set.
public static issetOptionLazy ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module option name
Tags:
since 7.0.0
// Returns true if module propery is set.
public static issetProperty ( string $modId, string $name ) returns bool;
  • string $modId
    Module id
  • string $name
    Module property name
Tags:
since 6.0.2
// Returns true if resource singleton is initialized.
public static isSingletonInitialized ( string $resId ) returns bool;
  • string $resId
    Resource id
Tags:
since 5.14.4
// Sets new options values, returns array of replaced options with original values.
public static replaceOptions ( string $modId, $aOptions ) returns array;
  • string $modId
    Module id
  • array $aOptions
    Array of option names and new values
Tags:
since 6.0.2
// Restores global scope modified in the environment setting up entry point. See AMI::saveGlobalScope() for usage example.
public static restoreGlobalScope ( [ string $name = '' ] ) returns void;
  • string $name
    Scope name
Tags:
see AMI::saveGlobalScope()
see ami_env.php
since 5.12.4
// Saves global scope, can be restored via AMI::restoreGlobalScope().
public static saveGlobalScope ( [ string $name = '' ], [ $aScope = null ] ) returns void;
  • string $name
    Scope name, empty by default
  • array $aScope
    Array to store as a global scope
  Example:
  •  $AMI_ENV_SETTINGS array('external_call' => true);
  •  require 'ami_env.php';
  •  
  •  $db new MyDBClass();
  •  
  •  // get_class($db) === 'MyDBClass'
  •  
  •  AMI::saveGlobalScope('Dummy');
  •  AMI::restoreGlobalScope('Amiro');
  •  
  •  // get_class($db) !== 'MyDBClass'
  •  
  •  AMI::restoreGlobalScope('Dummy');
  •  
  •  // get_class($db) === 'MyDBClass'
Tags:
see AMI::restoreGlobalScope()
see ami_env.php
since 5.12.4
// Saves module options.
public static saveOptions ( string $modId ) returns bool;
  • string $modId
    Module id
Tags:
since 6.0.2
// Sets module option value.
public static setOption ( string $modId, string $name, mixed $value ) returns void;
  • string $modId
    Module id
  • string $name
    Module option name
  • mixed $value
    Module option value, null to unset
Tags:
since 5.12.0
// Sets module option value.
public static setOptionLazy ( string $modId, string $name, mixed $value ) returns void;
  • string $modId
    Module id
  • string $name
    Module option name
  • mixed $value
    Module option value, null to unset
Tags:
since 7.0.0
// Is toolbar enabled.
public static toolbarEnabled ( ) returns bool;
// Returns date format by locale id.
public getDateFormat ( [ string $locale = 'en' ], [ string $type = 'DB' ] ) returns string;
  • string $locale
    Locale id
  • string $type
    Format type: 'DB'|'DB_DATE'|'DB_TIME'|'PHP'|'PHP_DATE'|'PHP_TIME'
The method returns php or database date/time format according to given locale.
// Initialize module extensions.
public initModExtensions ( string $modId, [ string $optSrcId = '' ], [ AMI_Mod $oModController = NULL ] ) returns void;
  • string $modId
    Module Id
  • string $optSrcId
    Reserved, will be describe later
  • AMI_Mod $oModController
    Module controller (since 6.0.2)