Projet

Général

Profil

Révision 950416da

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/rules/includes/rules.core.inc
7 7

  
8 8
// This is not necessary as the classes are autoloaded via the registry. However
9 9
// it saves some possible update headaches until the registry is rebuilt.
10
// @todo
11
//   Remove for a future release.
10
// @todo Remove for a future release.
12 11
require_once dirname(__FILE__) . '/faces.inc';
13 12

  
14 13
/**
......
29 28

  
30 29
  /**
31 30
   * Overridden.
31
   *
32 32
   * @see DrupalDefaultEntityController::attachLoad()
33 33
   */
34 34
  protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
35
    // Retrieve stdClass records and turn them in rules objects stored in 'data'
35
    // Retrieve stdClass records and store them as rules objects in 'data'.
36 36
    $ids = array_keys($queried_entities);
37 37
    $result = db_select('rules_tags')
38 38
      ->fields('rules_tags', array('id', 'tag'))
......
68 68

  
69 69
  /**
70 70
   * Override to support having events and tags as conditions.
71
   * @see EntityAPIController::applyConditions($entities, $conditions)
71
   *
72
   * @see EntityAPIController::applyConditions()
72 73
   * @see rules_query_rules_config_load_multiple_alter()
73 74
   */
74 75
  protected function applyConditions($entities, $conditions = array()) {
......
106 107
   * @param $export
107 108
   *   A serialized string in JSON format as produced by the
108 109
   *   RulesPlugin::export() method, or the PHP export as usual PHP array.
110
   * @param string $error_msg
111
   *   The error message.
109 112
   */
110 113
  public function import($export, &$error_msg = '') {
111 114
    $export = is_array($export) ? $export : drupal_json_decode($export);
......
202 205
    foreach ($rules_config->events() as $event) {
203 206
      db_insert('rules_trigger')
204 207
        ->fields(array(
205
        'id' => $rules_config->id,
206
        'event' => $event,
207
      ))
208
      ->execute();
208
          'id' => $rules_config->id,
209
          'event' => $event,
210
        ))
211
        ->execute();
209 212
    }
210 213
  }
211 214

  
......
217 220
      foreach ($rules_config->dependencies as $dependency) {
218 221
        db_insert('rules_dependencies')
219 222
          ->fields(array(
220
          'id' => $rules_config->id,
221
          'module' => $dependency,
222
        ))
223
        ->execute();
223
            'id' => $rules_config->id,
224
            'module' => $dependency,
225
          ))
226
          ->execute();
224 227
      }
225 228
    }
226 229
  }
227 230

  
228 231
  /**
229 232
   * Overridden to support tags and events in $conditions.
233
   *
230 234
   * @see EntityAPIControllerExportable::buildQuery()
231 235
   */
232 236
  protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
......
234 238
    $query_conditions =& $query->conditions();
235 239
    foreach ($query_conditions as &$condition) {
236 240
      // One entry in $query_conditions is a string with key '#conjunction'.
237
      // @see QueryConditionInterface::conditions().
241
      // @see QueryConditionInterface::conditions()
238 242
      if (is_array($condition)) {
239 243
        // Support using 'tags' => array('tag1', 'tag2') as condition.
240 244
        if ($condition['field'] == 'base.tags') {
......
255 259

  
256 260
  /**
257 261
   * Overridden to also delete tags and events.
262
   *
258 263
   * @see EntityAPIControllerExportable::delete()
259 264
   */
260 265
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
......
305 310

  
306 311
    return $return;
307 312
  }
313

  
308 314
}
309 315

  
310 316
/**
317
 * Base class for RulesExtendables.
318
 *
311 319
 * The RulesExtendable uses the rules cache to setup the defined extenders
312 320
 * and overrides automatically.
313 321
 * As soon faces is used the faces information is autoloaded using setUp().
......
316 324

  
317 325
  /**
318 326
   * The name of the info definitions associated with info about this class.
327
   *
319 328
   * This would be defined abstract, if possible. Common rules hooks with class
320 329
   * info are e.g. plugin_info and data_info.
321 330
   */
......
326 335
   */
327 336
  protected $itemName;
328 337

  
329
  protected $cache, $itemInfo = array();
330

  
338
  protected $cache;
339
  protected $itemInfo = array();
331 340

  
332 341
  public function __construct() {
333 342
    $this->setUp();
......
340 349
    if (isset($this->cache[$this->hook][$this->itemName])) {
341 350
      $this->itemInfo = &$this->cache[$this->hook][$this->itemName];
342 351
    }
343
    // Set up the Faces Extenders
352
    // Set up the Faces Extenders.
344 353
    if (!empty($this->itemInfo['faces_cache'])) {
345 354
      list($this->facesMethods, $this->facesIncludes, $this->faces) = $this->itemInfo['faces_cache'];
346 355
    }
347 356
  }
348 357

  
349 358
  /**
350
   * Force the object to be setUp, this executes setUp() if not done yet.
359
   * Forces the object to be setUp, this executes setUp() if not done yet.
351 360
   */
352 361
  public function forceSetUp() {
353 362
    if (!isset($this->cache) || (!empty($this->itemInfo['faces_cache']) && !$this->faces)) {
......
402 411
   *   The info about the item as specified in the hook.
403 412
   * @param $interface
404 413
   *   The interface to check for.
405
   * @return
414
   *
415
   * @return bool
406 416
   *   Whether it supports the given interface.
407 417
   */
408 418
  public static function itemFacesAs(&$itemInfo, $interface) {
409 419
    return in_array($interface, class_implements($itemInfo['class'])) || isset($itemInfo['faces_cache'][2][$interface]);
410 420
  }
421

  
411 422
}
412 423

  
413 424
/**
......
439 450

  
440 451
  /**
441 452
   * The parent element, if any.
453
   *
442 454
   * @var RulesContainerPlugin
443 455
   */
444 456
  protected $parent = NULL;
445 457

  
446
  protected $cache = NULL, $hook = 'plugin_info';
458
  protected $cache = NULL;
459
  protected $hook = 'plugin_info';
447 460

  
448 461
  /**
449 462
   * Identifies an element inside a configuration.
......
455 468
   */
456 469
  protected $availableVariables;
457 470

  
458

  
459 471
  /**
460 472
   * Sets a new parent element.
461 473
   */
......
533 545
   * Iterate over all elements nested below the current element.
534 546
   *
535 547
   * This helper can be used to recursively iterate over all elements of a
536
   * configuration. To iterate over the children only, just regulary iterate
548
   * configuration. To iterate over the children only, just regularly iterate
537 549
   * over the object.
538 550
   *
539 551
   * @param $mode
......
586 598
  /**
587 599
   * Evaluate the element on a given rules evaluation state.
588 600
   */
589
  abstract function evaluate(RulesState $state);
601
  abstract public function evaluate(RulesState $state);
590 602

  
591 603
  protected static function compare(RulesPlugin $a, RulesPlugin $b) {
592 604
    if ($a->weight == $b->weight) {
......
611 623
  /**
612 624
   * Returns info about parameters needed for executing the configured plugin.
613 625
   *
614
   * @param $optional
626
   * @param bool $optional
615 627
   *   Whether optional parameters should be included.
616 628
   *
617 629
   * @see self::pluginParameterInfo()
......
744 756
  }
745 757

  
746 758
  /**
747
   * Returns asserted additions to the available variable info. Any returned
748
   * info is merged into the variable info, in case the execution flow passes
749
   * the element.
759
   * Returns asserted additions to the available variable info.
760
   *
761
   * Any returned info is merged into the variable info, in case the execution
762
   * flow passes the element.
750 763
   * E.g. this is used to assert the content type of a node if the condition
751
   * is met, such that the per node type properties are available.
764
   * is met, such that the per-node type properties are available.
752 765
   */
753 766
  protected function variableInfoAssertions() {
754 767
    return array();
755 768
  }
756 769

  
757 770
  /**
758
   * Get the name of this plugin instance. The returned name should identify
759
   * the code which drives this plugin.
771
   * Gets the name of this plugin instance.
772
   *
773
   * The returned name should identify the code which drives this plugin.
760 774
   */
761 775
  public function getPluginName() {
762 776
    return $this->itemName;
......
813 827
   * Usually settings get processed automatically, however if $this->settings
814 828
   * has been altered manually after element construction, it needs to be
815 829
   * invoked explicitly with $force set to TRUE.
816
   *
817 830
   */
818 831
  public function processSettings($force = FALSE) {
819 832
    // Process if not done yet.
......
839 852
  }
840 853

  
841 854
  /**
842
   * Makes sure the plugin is configured right, e.g. all needed variables
843
   * are available in the element's scope and dependent modules are enabled.
855
   * Makes sure the plugin is configured right.
856
   *
857
   * "Configured right" means all needed variables are available in the
858
   * element's scope and dependent modules are enabled.
844 859
   *
845
   * @return RulesPlugin
846
   *   Returns $this to support chained usage.
860
   * @return $this
847 861
   *
848 862
   * @throws RulesIntegrityException
849
   *   In case of a failed integraty check, a RulesIntegrityException exception
863
   *   In case of a failed integrity check, a RulesIntegrityException exception
850 864
   *   is thrown.
851 865
   */
852 866
  public function integrityCheck() {
......
901 915
      elseif (!$this->isRoot() && !isset($this->settings[$name]) && empty($info['optional']) && $info['type'] != 'hidden') {
902 916
        throw new RulesIntegrityException(t('Missing configuration for parameter %name.', array('%name' => $name)), array($this, 'parameter', $name));
903 917
      }
904
      //TODO: Make sure used values are allowed. (key/value pairs + allowed values)
918
      // @todo Make sure used values are allowed.
919
      // (key/value pairs + allowed values).
905 920
    }
906 921
  }
907 922

  
908 923
  /**
924
   * Returns the argument for the parameter $name described with $info.
925
   *
909 926
   * Returns the argument as configured in the element settings for the
910 927
   * parameter $name described with $info.
911 928
   *
912
   * @param $name
929
   * @param string $name
913 930
   *   The name of the parameter for which to get the argument.
914 931
   * @param $info
915 932
   *   Info about the parameter.
916 933
   * @param RulesState $state
917 934
   *   The current evaluation state.
918
   * @param $langcode
935
   * @param string $langcode
919 936
   *   (optional) The language code used to get the argument value if the
920 937
   *   argument value should be translated. By default (NULL) the current
921 938
   *   interface language will be used.
......
968 985
    if (!empty($this->settings[$name . ':process'])) {
969 986
      // For processing, make sure the data is unwrapped now.
970 987
      $return = rules_unwrap_data(array($arg), array($info));
971
      // @todo for Drupal 8: Refactor to add the name and language code as
988
      // @todo For Drupal 8: Refactor to add the name and language code as
972 989
      // separate parameter to process().
973 990
      $info['#name'] = $name;
974 991
      $info['#langcode'] = $langcode;
......
1005 1022
  }
1006 1023

  
1007 1024
  /**
1008
   * Apply the given data selector by using the info about available variables.
1009
   * Thus it doesn't require an actual evaluation state.
1025
   * Applies the given data selector.
1026
   *
1027
   * Applies the given data selector by using the info about available
1028
   * variables. Thus it doesn't require an actual evaluation state.
1010 1029
   *
1011
   * @param $selector
1030
   * @param string $selector
1012 1031
   *   The selector string, e.g. "node:author:mail".
1013 1032
   *
1014 1033
   * @return EntityMetadataWrapper
......
1030 1049
            }
1031 1050
          }
1032 1051
        }
1033
        // In case of an exception or we were unable to get a wrapper, return FALSE.
1052
        // Return FALSE if there is no wrappper or we get an exception.
1034 1053
        catch (EntityMetadataWrapperException $e) {
1035 1054
          return FALSE;
1036 1055
        }
......
1065 1084
  }
1066 1085

  
1067 1086
  /**
1068
   * Saves the configuration to the database, regardless whether this is invoked
1069
   * on the rules configuration or a contained rule element.
1087
   * Saves the configuration to the database.
1088
   *
1089
   * The configuration is saved regardless whether this method is invoked on
1090
   * the rules configuration or a contained rule element.
1070 1091
   */
1071 1092
  public function save($name = NULL, $module = 'rules') {
1072 1093
    if (isset($this->parent)) {
......
1096 1117
      // default configurations 'module' points to the module providing the
1097 1118
      // default configuration, so the module via which the rules is configured
1098 1119
      // is stored in the "owner" property.
1099
      // @todo: For Drupal 8 use "owner" for generating machine names also and
1120
      // @todo For Drupal 8 use "owner" for generating machine names also and
1100 1121
      // module only for the modules providing default configurations.
1101 1122
      $this->module = !isset($this->module) || $module != 'rules' ? $module : $this->module;
1102 1123
      if (!isset($this->owner)) {
......
1191 1212
  }
1192 1213

  
1193 1214
  /**
1215
   * Deletes configuration from database.
1216
   *
1194 1217
   * If invoked on a rules configuration it is deleted from database. If
1195 1218
   * invoked on a contained rule element, it's removed from the configuration.
1196 1219
   */
......
1235 1258
   *   A status constant, i.e. one of ENTITY_CUSTOM, ENTITY_IN_CODE,
1236 1259
   *   ENTITY_OVERRIDDEN or ENTITY_FIXED.
1237 1260
   *
1238
   * @return
1261
   * @return bool
1239 1262
   *   TRUE if the configuration has the status, else FALSE.
1240 1263
   *
1241 1264
   * @see entity_has_status()
......
1245 1268
  }
1246 1269

  
1247 1270
  /**
1248
   * Remove circular object references so the PHP garbage collector does its
1249
   * work.
1271
   * Removes circular object references so PHP garbage collector can work.
1250 1272
   */
1251 1273
  public function destroy() {
1252 1274
    parent::destroy();
......
1254 1276
  }
1255 1277

  
1256 1278
  /**
1257
   * Seamlessy invokes the method implemented via faces without having to think
1258
   * about references.
1279
   * Seamlessly invokes the method implemented via faces.
1280
   *
1281
   * Frees the caller from having to think about references.
1259 1282
   */
1260 1283
  public function form(&$form, &$form_state, array $options = array()) {
1261 1284
    $this->__call('form', array(&$form, &$form_state, $options));
......
1339 1362
  /**
1340 1363
   * Exports a rule configuration.
1341 1364
   *
1342
   * @param $prefix
1365
   * @param string $prefix
1343 1366
   *   An optional prefix for each line.
1344
   * @param $php
1367
   * @param bool $php
1345 1368
   *   Optional. Set to TRUE to format the export using PHP arrays. By default
1346 1369
   *   JSON is used.
1370
   *
1347 1371
   * @return
1348
   *   The exported confiugration.
1372
   *   The exported configuration.
1349 1373
   *
1350 1374
   * @see rules_import()
1351 1375
   */
......
1395 1419
  }
1396 1420

  
1397 1421
  /**
1398
   * Finalizies the configuration export by adding general attributes regarding
1399
   * the configuration and returns it in the right format.
1422
   * Finalizes the configuration export.
1423
   *
1424
   * Adds general attributes regarding the configuration and returns it in the
1425
   * right format for export.
1426
   *
1427
   * @param $export
1428
   * @param string $prefix
1429
   *   An optional prefix for each line.
1430
   * @param bool $php
1431
   *   Optional. Set to TRUE to format the export using PHP arrays. By default
1432
   *   JSON is used.
1400 1433
   */
1401 1434
  protected function returnExport($export, $prefix = '', $php = FALSE) {
1402 1435
    $this->ensureNameExists();
......
1442 1475
  public function resetInternalCache() {
1443 1476
    $this->availableVariables = NULL;
1444 1477
  }
1478

  
1445 1479
}
1446 1480

  
1447 1481
/**
1448
 * Defines a common base class for so called "Abstract Plugins" like actions.
1449
 * Thus modules have to provide the concrete plugin implementation.
1482
 * Defines a common base class for so-called "Abstract Plugins" like actions.
1483
 *
1484
 * Modules have to provide the concrete plugin implementation.
1450 1485
 */
1451 1486
abstract class RulesAbstractPlugin extends RulesPlugin {
1452 1487

  
......
1455 1490
  protected $infoLoaded = FALSE;
1456 1491

  
1457 1492
  /**
1458
   * @param $name
1493
   * @param string $name
1459 1494
   *   The plugin implementation's name.
1460
   * @param $info
1495
   * @param $settings
1461 1496
   *   Further information provided about the plugin. Optional.
1462 1497
   * @throws RulesException
1463 1498
   *   If validation of the passed settings fails RulesExceptions are thrown.
1464 1499
   */
1465
  function __construct($name = NULL, $settings = array()) {
1500
  public function __construct($name = NULL, $settings = array()) {
1466 1501
    $this->elementName = $name;
1467 1502
    $this->settings = (array) $settings + array('#_needs_processing' => TRUE);
1468 1503
    $this->setUp();
......
1473 1508
    if (isset($this->cache[$this->itemName . '_info'][$this->elementName])) {
1474 1509
      $this->info = $this->cache[$this->itemName . '_info'][$this->elementName];
1475 1510
      // Remember that the info has been correctly setup.
1476
      // @see self::forceSetup().
1511
      // @see self::forceSetup()
1477 1512
      $this->infoLoaded = TRUE;
1478 1513

  
1479 1514
      // Register the defined class, if any.
......
1653 1688
   */
1654 1689
  abstract protected function executeCallback(array $args, RulesState $state = NULL);
1655 1690

  
1656

  
1657 1691
  public function evaluate(RulesState $state) {
1658 1692
    $this->processSettings();
1659 1693
    try {
......
1677 1711
  }
1678 1712

  
1679 1713
  public function getPluginName() {
1680
    return $this->itemName ." ". $this->elementName;
1714
    return $this->itemName . " " . $this->elementName;
1681 1715
  }
1682 1716

  
1683 1717
  /**
......
1697 1731
    self::includeFiles();
1698 1732

  
1699 1733
    // Get the plugin's own info data.
1700
    $cache[$this->itemName .'_info'] = rules_fetch_data($this->itemName .'_info');
1701
    foreach ($cache[$this->itemName .'_info'] as $name => &$info) {
1734
    $cache[$this->itemName . '_info'] = rules_fetch_data($this->itemName . '_info');
1735
    foreach ($cache[$this->itemName . '_info'] as $name => &$info) {
1702 1736
      $info += array(
1703 1737
        'parameter' => isset($info['arguments']) ? $info['arguments'] : array(),
1704 1738
        'provides' => isset($info['new variables']) ? $info['new variables'] : array(),
......
1716 1750
      // RulesPluginImplInterface.
1717 1751
      unset($this->faces['RulesPluginHandlerInterface']);
1718 1752

  
1719
      // Build up the per plugin implementation faces cache.
1753
      // Build up the per-plugin implementation faces cache.
1720 1754
      foreach ($this->faces as $interface) {
1721 1755
        $methods = $file_names = array();
1722 1756
        $includes = self::getIncludeFiles($info['module']);
......
1739 1773
        // Cache only the plugin implementation specific callbacks.
1740 1774
        $info['faces_cache'][$interface] = array($methods, array_filter($file_names));
1741 1775
      }
1742
      // Filter out interfaces with no overriden methods.
1776
      // Filter out interfaces with no overridden methods.
1743 1777
      $info['faces_cache'] = rules_filter_array($info['faces_cache'], 0, TRUE);
1744 1778
      // We don't need that any more.
1745 1779
      unset($info['callbacks'], $info['base']);
......
1747 1781
  }
1748 1782

  
1749 1783
  /**
1750
   * Makes sure the providing modules' .rules.inc file is included as diverse
1784
   * Loads this module's .rules.inc file.
1785
   *
1786
   * Makes sure the providing modules' .rules.inc file is included, as diverse
1751 1787
   * callbacks may reside in that file.
1752 1788
   */
1753 1789
  protected function loadBasicInclude() {
......
1761 1797
  }
1762 1798

  
1763 1799
  /**
1764
   * Make sure all supported destinations are included.
1800
   * Makes sure all supported destinations are included.
1765 1801
   */
1766 1802
  public static function includeFiles() {
1767 1803
    static $included;
......
1783 1819
        $dirs += $result;
1784 1820
      }
1785 1821
      foreach ($dirs as $module => $directory) {
1786
        foreach (glob(drupal_get_path('module', $module) . "/$directory/*.{inc,php}", GLOB_BRACE) as $filename) {
1787
          include_once $filename;
1822
        $module_path = drupal_get_path('module', $module);
1823
        foreach (array('inc', 'php') as $extension) {
1824
          foreach (glob("$module_path/$directory/*.$extension") as $filename) {
1825
            include_once $filename;
1826
          }
1788 1827
        }
1789 1828
      }
1790 1829
      $included = TRUE;
......
1792 1831
  }
1793 1832

  
1794 1833
  /**
1795
   * Returns all include files for a module. If $all is set to FALSE the
1796
   * $module.rules.inc file isn't added.
1834
   * Returns all include files for a module.
1835
   *
1836
   * @param string $module
1837
   *   The module name.
1838
   * @param bool $all
1839
   *   If FALSE, the $module.rules.inc file isn't added.
1840
   *
1841
   * @return string[]
1842
   *   An array containing the names of all the include files for a module.
1797 1843
   */
1798 1844
  protected static function getIncludeFiles($module, $all = TRUE) {
1799
    $files = (array)module_invoke($module, 'rules_file_info');
1845
    $files = (array) module_invoke($module, 'rules_file_info');
1800 1846
    // Automatically add "$module.rules_forms.inc" and "$module.rules.inc".
1801 1847
    $files[] = $module . '.rules_forms';
1802 1848
    if ($all) {
......
1823 1869
    }
1824 1870
    return $filenames[$function];
1825 1871
  }
1872

  
1826 1873
}
1827 1874

  
1828 1875
/**
1829
 * Interface for objects that can be used as action.
1876
 * Interface for objects that can be used as actions.
1830 1877
 */
1831 1878
interface RulesActionInterface {
1832 1879

  
1833 1880
  /**
1834
   * @return As specified.
1881
   * @return
1882
   *   As specified.
1835 1883
   *
1836 1884
   * @throws RulesEvaluationException
1837 1885
   *   Throws an exception if not all necessary arguments have been provided.
1838 1886
   */
1839 1887
  public function execute();
1888

  
1840 1889
}
1841 1890

  
1842 1891
/**
1843
 * Interface for objects that can be used as condition.
1892
 * Interface for objects that can be used as conditions.
1844 1893
 */
1845 1894
interface RulesConditionInterface {
1846 1895

  
1847 1896
  /**
1848
   * @return Boolean.
1897
   * @return bool
1849 1898
   *
1850 1899
   * @throws RulesEvaluationException
1851 1900
   *   Throws an exception if not all necessary arguments have been provided.
......
1861 1910
   * Returns whether the element is configured to negate the result.
1862 1911
   */
1863 1912
  public function isNegated();
1913

  
1864 1914
}
1865 1915

  
1916
/**
1917
 * Interface for objects that are triggerable.
1918
 */
1866 1919
interface RulesTriggerableInterface {
1867 1920

  
1868 1921
  /**
......
1873 1926
  /**
1874 1927
   * Removes an event from the rule configuration.
1875 1928
   *
1876
   * @param $event
1929
   * @param string $event_name
1877 1930
   *   The name of the (configured) event to remove.
1931
   *
1878 1932
   * @return RulesTriggerableInterface
1879 1933
   *   The object instance itself, to allow chaining.
1880 1934
   */
......
1896 1950
  /**
1897 1951
   * Gets the event settings associated with the given (configured) event.
1898 1952
   *
1899
   * @param $event_name
1953
   * @param string $event_name
1900 1954
   *   The (configured) event's name.
1901 1955
   *
1902 1956
   * @return array|null
......
1922 1976
  /**
1923 1977
   * Processes settings independent from a form submission.
1924 1978
   *
1925
   * Processing results may be stored and accessed on execution time in $settings.
1979
   * Processing results may be stored and accessed on execution time
1980
   * in $settings.
1926 1981
   */
1927 1982
  public function process();
1928 1983

  
......
1954 2009
  public function dependencies();
1955 2010

  
1956 2011
  /**
1957
   * Alter the generated configuration form of the element.
2012
   * Alters the generated configuration form of the element.
1958 2013
   *
1959 2014
   * Validation and processing of the settings should be untied from the form
1960 2015
   * and implemented in validate() and process() wherever it makes sense.
......
1963 2018
   */
1964 2019
  public function form_alter(&$form, $form_state, $options);
1965 2020

  
1966

  
1967 2021
  /**
1968
   * Optionally returns an array of info assertions for the specified
1969
   * parameters. This allows conditions to assert additional metadata, such as
1970
   * info about the fields of a bundle.
2022
   * Returns an array of info assertions for the specified parameters.
2023
   *
2024
   * This allows conditions to assert additional metadata, such as info about
2025
   * the fields of a bundle.
1971 2026
   *
1972 2027
   * @see RulesPlugin::variableInfoAssertions()
1973 2028
   */
......
2006 2061
interface RulesActionHandlerInterface extends RulesPluginHandlerInterface {}
2007 2062

  
2008 2063
/**
2064
 * Interface used for implementing an abstract plugin via Faces.
2009 2065
 *
2010 2066
 * Provides the interface used for implementing an abstract plugin by using
2011 2067
 * the Faces extension mechanism.
......
2013 2069
interface RulesPluginImplInterface extends RulesPluginHandlerInterface {
2014 2070

  
2015 2071
  /**
2016
   * Execute the action or condition making use of the parameters as specified.
2072
   * Executes the action or condition making use of the parameters as specified.
2017 2073
   */
2018 2074
  public function execute();
2075

  
2019 2076
}
2020 2077

  
2021 2078
/**
......
2024 2081
 * @see RulesContainerPlugin::optimize()
2025 2082
 */
2026 2083
interface RulesOptimizationInterface {
2084

  
2027 2085
  /**
2028 2086
   * Optimizes a rule configuration in order to speed up evaluation.
2029 2087
   */
2030 2088
  public function optimize();
2089

  
2031 2090
}
2032 2091

  
2033 2092
/**
......
2056 2115
  }
2057 2116

  
2058 2117
  public function validate() {}
2118

  
2059 2119
  public function process() {}
2120

  
2060 2121
  public function info_alter(&$element_info) {}
2122

  
2061 2123
  public function dependencies() {}
2124

  
2062 2125
  public function form_alter(&$form, $form_state, $options) {}
2126

  
2063 2127
  public function assertions() {}
2128

  
2064 2129
}
2065 2130

  
2066 2131
/**
......
2074 2139
abstract class RulesActionHandlerBase extends RulesPluginHandlerBase implements RulesActionHandlerInterface {}
2075 2140

  
2076 2141
/**
2077
 * Class providing default implementations of the methods of the RulesPluginImplInterface.
2142
 * Provides default implementations of all RulesPluginImplInterface methods.
2078 2143
 *
2079 2144
 * If a plugin implementation does not provide a function for a method, the
2080 2145
 * default method of this class will be invoked.
......
2085 2150
class RulesAbstractPluginDefaults extends RulesPluginHandlerBase implements RulesPluginImplInterface {
2086 2151

  
2087 2152
  public function execute() {
2088
    throw new RulesEvaluationException($this->object->getPluginName() .": Execution implementation is missing.", array(), $this->object, RulesLog::ERROR);
2153
    throw new RulesEvaluationException($this->object->getPluginName() . ": Execution implementation is missing.", array(), $this->object, RulesLog::ERROR);
2089 2154
  }
2155

  
2090 2156
}
2091 2157

  
2092 2158
/**
......
2094 2160
 */
2095 2161
class RulesRecursiveElementIterator extends ArrayIterator implements RecursiveIterator {
2096 2162

  
2097
   public function getChildren() {
2098
     return $this->current()->getIterator();
2099
   }
2163
  public function getChildren() {
2164
    return $this->current()->getIterator();
2165
  }
2166

  
2167
  public function hasChildren() {
2168
    return $this->current() instanceof IteratorAggregate;
2169
  }
2100 2170

  
2101
   public function hasChildren() {
2102
      return $this->current() instanceof IteratorAggregate;
2103
   }
2104 2171
}
2105 2172

  
2106 2173
/**
......
2131 2198
  }
2132 2199

  
2133 2200
  /**
2134
   * Allow access to the children through the iterator.
2201
   * Allows access to the children through the iterator.
2135 2202
   *
2136 2203
   * @return RulesRecursiveElementIterator
2137 2204
   */
......
2193 2260
  }
2194 2261

  
2195 2262
  /**
2263
   * Returns available state variables for an element.
2264
   *
2196 2265
   * Returns info about variables available in the evaluation state for any
2197 2266
   * children elements or if given for a special child element.
2198 2267
   *
......
2235 2304
  }
2236 2305

  
2237 2306
  /**
2307
   * Executes container with the given arguments.
2308
   *
2238 2309
   * Condition containers just return a boolean while action containers return
2239 2310
   * the configured provided variables as an array of variables.
2240 2311
   */
......
2289 2360
  }
2290 2361

  
2291 2362
  /**
2292
   * Override delete to keep the children alive, if possible.
2363
   * Overrides delete to keep the children alive, if possible.
2293 2364
   */
2294 2365
  public function delete($keep_children = TRUE) {
2295 2366
    if (isset($this->parent) && $keep_children) {
......
2307 2378
  /**
2308 2379
   * Sorts all child elements by their weight.
2309 2380
   *
2310
   * @param $deep
2381
   * @param bool $deep
2311 2382
   *   If enabled a deep sort is performed, thus the whole element tree below
2312 2383
   *   this element is sorted.
2313 2384
   */
2314 2385
  public function sortChildren($deep = FALSE) {
2315 2386
    // Make sure the array order is kept in case two children have the same
2316
    // weight by ensuring later childrens would have higher weights.
2387
    // weight by ensuring later children would have higher weights.
2317 2388
    foreach (array_values($this->children) as $i => $child) {
2318 2389
      $child->weight += $i / 1000;
2319 2390
    }
......
2342 2413
  }
2343 2414

  
2344 2415
  /**
2345
   * Determines whether the element should be exported in flat style. Flat style
2346
   * means that the export keys are written directly into the export array,
2347
   * whereas else the export is written into a sub-array.
2416
   * Determines whether the element should be exported in flat style.
2417
   *
2418
   * Flat style means that the export keys are written directly into the export
2419
   * array, whereas else the export is written into a sub-array.
2348 2420
   */
2349 2421
  protected function exportFlat() {
2350 2422
    // By default we always use flat style for plugins without any parameters
......
2406 2478
      $element->optimize();
2407 2479
    }
2408 2480
  }
2481

  
2409 2482
}
2410 2483

  
2411 2484
/**
......
2423 2496
  }
2424 2497

  
2425 2498
  /**
2426
   * Add an action. Pass either an instance of the RulesActionInterface
2427
   * or the arguments as needed by rules_action().
2499
   * Adds an action to the container.
2500
   *
2501
   * Pass in either an instance of the RulesActionInterface or the arguments
2502
   * as needed by rules_action().
2428 2503
   *
2429
   * @return RulesActionContainer
2430
   *   Returns $this to support chained usage.
2504
   * @return $this
2431 2505
   */
2432 2506
  public function action($name, $settings = array()) {
2433 2507
    $action = (is_object($name) && $name instanceof RulesActionInterface) ? $name : rules_action($name, $settings);
......
2459 2533
  }
2460 2534

  
2461 2535
  /**
2536
   * Returns an array of provided variable names.
2537
   *
2462 2538
   * Returns an array of variable names, which are provided by passing through
2463 2539
   * the provided variables of the children.
2464 2540
   */
......
2481 2557
      $this->info['provides'] = $export['PROVIDES VARIABLES'];
2482 2558
    }
2483 2559
  }
2560

  
2484 2561
}
2485 2562

  
2486 2563
/**
......
2491 2568
  protected $negate = FALSE;
2492 2569

  
2493 2570
  /**
2494
   * Add a condition. Pass either an instance of the RulesConditionInterface
2495
   * or the arguments as needed by rules_condition().
2571
   * Adds a condition to the container.
2496 2572
   *
2497
   * @return RulesConditionContainer
2498
   *   Returns $this to support chained usage.
2573
   * Pass in either an instance of the RulesConditionInterface or the arguments
2574
   * as needed by rules_condition().
2575
   *
2576
   * @return $this
2499 2577
   */
2500 2578
  public function condition($name, $settings = array()) {
2501 2579
    $condition = (is_object($name) && $name instanceof RulesConditionInterface) ? $name : rules_condition($name, $settings);
......
2563 2641
    }
2564 2642
    return $vars;
2565 2643
  }
2644

  
2566 2645
}
2567 2646

  
2568 2647
/**
......
2580 2659
   * @return RulesLog
2581 2660
   *   Returns the rules logger instance.
2582 2661
   */
2583
  static function logger() {
2662
  public static function logger() {
2584 2663
    if (!isset(self::$logger)) {
2585 2664
      $class = __CLASS__;
2586 2665
      self::$logger = new $class(variable_get('rules_log_level', self::INFO));
......
2589 2668
  }
2590 2669

  
2591 2670
  protected $log = array();
2592
  protected $logLevel, $line = 0;
2671
  protected $logLevel;
2672
  protected $line = 0;
2593 2673

  
2594 2674
  /**
2595 2675
   * This is a singleton.
......
2616 2696
  /**
2617 2697
   * Checks the log and throws an exception if there were any problems.
2618 2698
   */
2619
  function checkLog($logLevel = self::WARN) {
2699
  public function checkLog($logLevel = self::WARN) {
2620 2700
    foreach ($this->log as $entry) {
2621 2701
      if ($entry[2] >= $logLevel) {
2622 2702
        throw new Exception($this->render());
......
2625 2705
  }
2626 2706

  
2627 2707
  /**
2628
   * Checks the log for (error) messages with a log level equal or higher than the given one.
2708
   * Checks the log for error messages.
2629 2709
   *
2630
   * @return
2710
   * @param int $logLevel
2711
   *   Lowest log level to return. Values lower than $logLevel will not be
2712
   *   returned.
2713
   *
2714
   * @return bool
2631 2715
   *   Whether the an error has been logged.
2632 2716
   */
2633 2717
  public function hasErrors($logLevel = self::WARN) {
......
2673 2757
        // messages here.
2674 2758
        $vars['head'] = t($this->log[$line][0], $this->log[$line][1]);
2675 2759
        if (isset($this->log[$line][5])) {
2676
          $vars['link'] = '[' . l('edit', $this->log[$line][5]) . ']';
2760
          $vars['link'] = '[' . l(t('edit'), $this->log[$line][5]) . ']';
2677 2761
        }
2678 2762
        $vars['log'] = $this->renderHelper($line);
2679 2763
        $output[] = theme('rules_debug_element', $vars);
2680 2764
      }
2681 2765
      else {
2682
        $formatted_diff = round(($this->log[$line][3] - $startTime) * 1000, 3) .' ms';
2683
        $msg = $formatted_diff .' '. t($this->log[$line][0], $this->log[$line][1]);
2766
        $formatted_diff = round(($this->log[$line][3] - $startTime) * 1000, 3) . ' ms';
2767
        $msg = $formatted_diff . ' ' . t($this->log[$line][0], $this->log[$line][1]);
2684 2768
        if ($this->log[$line][2] >= RulesLog::WARN) {
2685 2769
          $level = $this->log[$line][2] == RulesLog::WARN ? 'warn' : 'error';
2686
          $msg = '<span class="rules-debug-' . $level . '">'. $msg .'</span>';
2770
          $msg = '<span class="rules-debug-' . $level . '">' . $msg . '</span>';
2687 2771
        }
2688 2772
        if (isset($this->log[$line][5]) && !isset($this->log[$line][4])) {
2689
          $msg .= ' [' . l('edit', $this->log[$line][5]) . ']';
2773
          $msg .= ' [' . l(t('edit'), $this->log[$line][5]) . ']';
2690 2774
        }
2691 2775
        $output[] = $msg;
2692 2776

  
......
2706 2790
  public function clear() {
2707 2791
    $this->log = array();
2708 2792
  }
2793

  
2709 2794
}
2710 2795

  
2711 2796
/**
2712
 * A common exception for Rules.
2797
 * A base exception class for Rules.
2713 2798
 *
2714
 * This class can be used to catch all exceptions thrown by Rules.
2799
 * This class can be used to catch all exceptions thrown by Rules, and it
2800
 * may be subclassed to describe more specific exceptions.
2715 2801
 */
2716 2802
abstract class RulesException extends Exception {}
2717 2803

  
......
2724 2810
 */
2725 2811
class RulesEvaluationException extends RulesException {
2726 2812

  
2727
  public $msg, $args, $severity, $element, $keys = array();
2813
  public $msg;
2814
  public $args;
2815
  public $severity;
2816
  public $element;
2817
  public $keys = array();
2728 2818

  
2729 2819
  /**
2730
   * @param $msg
2820
   * Constructor.
2821
   *
2822
   * @param string $msg
2731 2823
   *   The exception message containing placeholder as t().
2732
   * @param $args
2824
   * @param array $args
2733 2825
   *   Replacement arguments such as for t().
2734 2826
   * @param $element
2735 2827
   *   The element of a configuration causing the exception or an array
2736 2828
   *   consisting of the element and keys specifying a setting value causing
2737 2829
   *   the exception.
2738
   * @param $severity
2830
   * @param int $severity
2739 2831
   *   The RulesLog severity. Defaults to RulesLog::WARN.
2740 2832
   */
2741
  function __construct($msg, array $args = array(), $element = NULL, $severity = RulesLog::WARN) {
2833
  public function __construct($msg, array $args = array(), $element = NULL, $severity = RulesLog::WARN) {
2742 2834
    $this->element = is_array($element) ? array_shift($element) : $element;
2743 2835
    $this->keys = is_array($element) ? $element : array();
2744 2836
    $this->msg = $msg;
......
2754 2846
        rules_clear_cache();
2755 2847
      }
2756 2848
    }
2757
    // @todo fix _drupal_decode_exception() to use __toString() and override it.
2849
    // @todo Fix _drupal_decode_exception() to use __toString() and override it.
2758 2850
    $this->message = t($this->msg, $this->args);
2759 2851
  }
2852

  
2760 2853
}
2761 2854

  
2762 2855
/**
2763
 * An exception that is thrown for Rules configurations that fail the integrity check.
2856
 * Indicates the Rules configuration failed the integrity check.
2764 2857
 *
2765 2858
 * @see RulesPlugin::integrityCheck()
2766 2859
 */
2767 2860
class RulesIntegrityException extends RulesException {
2768 2861

  
2769
  public $msg, $element, $keys = array();
2862
  public $msg;
2863
  public $element;
2864
  public $keys = array();
2770 2865

  
2771 2866
  /**
2867
   * Constructs a RulesIntegrityException object.
2868
   *
2772 2869
   * @param string $msg
2773 2870
   *   The exception message, already translated.
2774 2871
   * @param $element
2775 2872
   *   The element of a configuration causing the exception or an array
2776 2873
   *   consisting of the element and keys specifying a parameter or provided
2777 2874
   *   variable causing the exception, e.g.
2778
   *   @code array($element, 'parameter', 'node') @endcode.
2875
   *   @code array($element, 'parameter', 'node') @endcode
2779 2876
   */
2780
  function __construct($msg, $element = NULL) {
2877
  public function __construct($msg, $element = NULL) {
2781 2878
    $this->element = is_array($element) ? array_shift($element) : $element;
2782 2879
    $this->keys = is_array($element) ? $element : array();
2783 2880
    parent::__construct($msg);
2784 2881
  }
2882

  
2785 2883
}
2786 2884

  
2787 2885
/**
......
2792 2890
/**
2793 2891
 * Determines the plugin to be used for importing a child element.
2794 2892
 *
2795
 * @param $key
2893
 * @param string $key
2796 2894
 *   The key to look for, e.g. 'OR' or 'DO'.
2797
 * @param $default
2895
 * @param string $default
2798 2896
 *   The default to return if no special plugin can be found.
2799 2897
 */
2800 2898
function _rules_import_get_plugin($key, $default = 'action') {
......
2810 2908
      }
2811 2909
    }
2812 2910
  }
2813
  // Cut of any leading NOT from the key.
2911
  // Cut off any leading NOT from the key.
2814 2912
  if (strpos($key, 'NOT ') === 0) {
2815 2913
    $key = substr($key, 4);
2816 2914
  }

Formats disponibles : Unified diff