Commit a697adec authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:tractor: feat(dev-manual) Use short array syntax in source code examples

issue #26
Showing with 72 additions and 72 deletions
+72 -72
......@@ -192,7 +192,7 @@ Use uppercase for constants/defines and _ to separate if there is more than one
Arrays
------
Arrays must be declared using the long notation syntax (``array()``).
Arrays must be declared using the short syntax (``[]``).
PHP specific
......@@ -248,10 +248,10 @@ Examples:
$a = "Hello $foo";
//use single quotes for array keys
$tab = array(
$tab = [
'lastname' => 'john',
'firstname' => 'doe'
);
'firstname' => 'doe',
];
//Do not use concatenation to optimize PHP7
//note that you cannot use functions call in {}
......
......@@ -117,12 +117,12 @@ That would look like :
new CompositeAttribute (
_('Informations for ftp login'),
'ftpLoginInfo',
array(
[
new StringAttribute (_('Login'), _('Login for FTP'), 'ftpLogin'),
new StringAttribute (_('Password'), _('Password for FTP'), 'ftpPassword'),
new StringAttribute (_('Host'), _('Host for FTP'), 'ftpHost'),
new IntAttribute (_('Port'), _('Port for FTP'), 'ftpPort', FALSE, 0, FALSE, 21),
),
],
'ftp://%[^@:]:%[^@:]@%[^@:]:%d', // sscanf format
'ftp://%s:%s@%s:%d' // sprintf format
)
......
......@@ -166,7 +166,7 @@ An other method, often simpler, is to modify your attributes after being constru
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
$array = array('node1','node2'); // some dummy array
$array = ['node1','node2']; // some dummy array
// After simplePlugin constructor, you must access attributes by their ldap name
$this->attributesAccess['myattributeLdapName']->setChoices($array);
}
......@@ -190,14 +190,14 @@ It's quite easy to do, all you have to do is adding a 'template' key to the sect
.. code-block:: php
'my_section' => array(
'my_section' => [
'name' => _('Great Section'),
'attrs' => array(
'attrs' => [
new StringAttribute (_('Something'), _('This attribute does nothing'), 'someThing', FALSE, 'DefaultValue'),
// other attributes…
),
],
'template' => get_template_path('my_section_template.tpl', TRUE, dirname(__FILE__))
),
],
You need to use get_template_path as above in order to get an absolute path for the tpl file.
In this template file, you need to copy simpleplugin_section.tpl, the default template.
......@@ -228,14 +228,14 @@ For this, you can use the **setManagedAttributes** method as follow:
.. code-block:: php
$this->attributesAccess['boolean']->setManagedAttributes(
array(
'disable' => array (
FALSE => array (
[
'disable' => [
FALSE => [
'attribute1',
'attribute2',
)
)
)
]
]
]
);
'disable' means that the attributes will be disabled but still saved into the LDAP.
......@@ -246,19 +246,19 @@ You can also use this method with selectattributes:
.. code-block:: php
$this->attributesAccess['select']->setManagedAttributes(
array(
'multiplevalues' => array ('darkcolors' => array('blue','black')),
'erase' => array (
'darkcolors' => array (
[
'multiplevalues' => ['darkcolors' => ['blue','black']],
'erase' => [
'darkcolors' => [
'attribute1',
'attribute2',
),
'yellow' => array (
],
'yellow' => [
'attribute3',
'attribute4',
),
)
)
],
]
]
);
Note the **multiplevalues** special key in order to specify several values that disable the same attributes.
......@@ -45,7 +45,7 @@ You can also create a new menu section in this attribute using the following syn
.. code-block:: php
<?php
array('mysection' => array('name' => _('My section'), 'priority' => 100))
['mysection' => ['name' => _('My section'), 'priority' => 100]]
Replace *mysection* with a lowercase id for your section and *My section* with the name to display in the menu.
......@@ -90,16 +90,16 @@ For instance, this is the plObjectType of the user class:
.. code-block:: php
<?php
'plObjectType' => array(
'user' => array(
'plObjectType' => [
'user' => [
'name' => _('User'),
'description' => _('User account'),
'mainAttr' => 'uid',
'nameAttr' => 'cn',
'icon' => 'geticon.php?context=types&icon=user&size=16',
'ou' => get_ou('userRDN'),
)
),
]
],
plForeignKeys
-------------
......@@ -112,20 +112,20 @@ The syntax for this is:
.. code-block:: php
<?php
'plForeignKeys' => array(
'myfield' => array(
array('class', 'hisfield', 'filter'),
)
)
'plForeignKeys' => [
'myfield' => [
['class', 'hisfield', 'filter'],
]
],
But you can omit *filter* most of the time (defaults to '*myfield*=%oldvalue%') and *hisfield* if it is the *dn*, and if there is only one field you are referring to you can omit the array, so for our department example this gives us:
.. code-block:: php
<?php
'plForeignKeys' => array(
'plForeignKeys' => [
'manager' => 'user'
)
]
Which is pretty straight forward.
......@@ -144,11 +144,11 @@ If you do need to specify ACL categories, you can create an acl category by spec
.. code-block:: php
<?php
'plCategory' => array(
'acl' => array(
'description' => _('ACL'),
'objectClass' => array('gosaAcl','gosaRole')
)
),
'plCategory' => [
'acl' => [
'description' => _('ACL'),
'objectClass' => ['gosaAcl','gosaRole']
]
],
An ACL category only contains a description and a list of LDAP objectClasses (for some historical reason)
......@@ -42,26 +42,26 @@ This is the code for an empty plugin:
var $displayHeader = FALSE;
// We need this function that returns some information about the plugin
static function plInfo ()
static function plInfo (): array
{
return array(
return [
'plShortName' => _('Demo Plugin'),
'plTitle' => _('Demo Plugin informations'),
'plDescription' => _('Edit some useless personal information'),
'plSelfModify' => TRUE, // Does this plugin have an owner that might be able to edit its entry
'plObjectType' => array('user'),
'plObjectClass' => array('demoPlugin'),
'plObjectType' => ['user'],
'plObjectClass' => ['demoPlugin'],
// simplePlugin can generate the ACL list for us
'plProvidedAcls' => parent::generatePlProvidedAcls(self::getAttributesInfo())
);
];
}
// The main function : information about attributes
static function getAttributesInfo ()
static function getAttributesInfo (): array
{
return array(
);
return [
];
}
}
......@@ -92,20 +92,20 @@ Example
// The main function : information about attributes
static function getAttributesInfo ()
{
return array(
return [
// Attributes are grouped by section
'section1' => array(
'section1' => [
'name' => _('Hair Information'),
'attrs' => array(
new SetAttribute( // This attribute is multi-valuated
'attrs' => [
new SetAttribute( // This attribute is multi-valuated
new SelectAttribute (
_('Color'), // Label of the attribute
_('Color of the hair'), // Description
'hairColor', // LDAP name
TRUE, // Mandatory
array('blond','black','brown'), // [SelectAttribute] Choices
"", // We don't set any default value, it will be the first one
array('Blond','Black','Brown') // [SelectAttribute] Output choices
['blond','black','brown'], // [SelectAttribute] Choices
'', // We don't set any default value, it will be the first one
['Blond','Black','Brown'] // [SelectAttribute] Output choices
)
),
new FloatAttribute (
......@@ -117,11 +117,11 @@ Example
FALSE, // [FloatAttribute] No maximum value
10 // [FloatAttribute] Default value
),
)
),
'section2' => array(
]
],
'section2' => [
'name' => _('Bicycle'),
'attrs' => array(
'attrs' => [
new StringAttribute (
_('Brand'), // Label
_('Brand of the bicycle'), // Description
......@@ -136,26 +136,26 @@ Example
FALSE, // Not mandatory
FALSE // Default value
),
)
),
'ftp' => array(
]
],
'ftp' => [
'name' => _('FTP informations'),
'attrs' => array(
'attrs' => [
new CompositeAttribute (
_('Informations for ftp login'),
'ftpLoginInfo',
array(
[
new StringAttribute (_('Login'), _('Login for FTP'), 'ftpLogin'),
new StringAttribute (_('Password'), _('Password for FTP'), 'ftpPassword'),
new StringAttribute (_('Host'), _('Host for FTP'), 'ftpHost'),
new IntAttribute (_('Port'), _('Port for FTP'), 'ftpPort', FALSE, 0, FALSE, 21),
),
],
'ftp://%[^@:]:%[^@:]@%[^@:]:%d', // scanf format
'ftp://%s:%s@%s:%d' // printf format
)
)
),
);
]
],
];
}
As you can see, attribute constructor take 5 arguments being label, description,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment