CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ConnectionManager
  • ConnectionRegistry
  • FactoryLocator
  • Paginator
  • QueryCacher
  • ResultSetDecorator
  • RulesChecker

Interfaces

  • ConnectionInterface
  • EntityInterface
  • FixtureInterface
  • InvalidPropertyInterface
  • PaginatorInterface
  • QueryInterface
  • RepositoryInterface
  • ResultSetInterface
  • SchemaInterface
  • TableSchemaInterface

Traits

  • EntityTrait
  • ModelAwareTrait
  • QueryTrait
  • RulesAwareTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.7
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Datasource;
 16: 
 17: use ArrayObject;
 18: use Cake\Event\EventDispatcherInterface;
 19: 
 20: /**
 21:  * A trait that allows a class to build and apply application.
 22:  * rules.
 23:  *
 24:  * If the implementing class also implements EventAwareTrait, then
 25:  * events will be emitted when rules are checked.
 26:  *
 27:  * The implementing class is expected to define the `RULES_CLASS` constant
 28:  * if they need to customize which class is used for rules objects.
 29:  */
 30: trait RulesAwareTrait
 31: {
 32: 
 33:     /**
 34:      * The domain rules to be applied to entities saved by this table
 35:      *
 36:      * @var \Cake\Datasource\RulesChecker
 37:      */
 38:     protected $_rulesChecker;
 39: 
 40:     /**
 41:      * Returns whether or not the passed entity complies with all the rules stored in
 42:      * the rules checker.
 43:      *
 44:      * @param \Cake\Datasource\EntityInterface $entity The entity to check for validity.
 45:      * @param string $operation The operation being run. Either 'create', 'update' or 'delete'.
 46:      * @param \ArrayObject|array|null $options The options To be passed to the rules.
 47:      * @return bool
 48:      */
 49:     public function checkRules(EntityInterface $entity, $operation = RulesChecker::CREATE, $options = null)
 50:     {
 51:         $rules = $this->rulesChecker();
 52:         $options = $options ?: new ArrayObject();
 53:         $options = is_array($options) ? new ArrayObject($options) : $options;
 54:         $hasEvents = ($this instanceof EventDispatcherInterface);
 55: 
 56:         if ($hasEvents) {
 57:             $event = $this->dispatchEvent(
 58:                 'Model.beforeRules',
 59:                 compact('entity', 'options', 'operation')
 60:             );
 61:             if ($event->isStopped()) {
 62:                 return $event->getResult();
 63:             }
 64:         }
 65: 
 66:         $result = $rules->check($entity, $operation, $options->getArrayCopy());
 67: 
 68:         if ($hasEvents) {
 69:             $event = $this->dispatchEvent(
 70:                 'Model.afterRules',
 71:                 compact('entity', 'options', 'result', 'operation')
 72:             );
 73: 
 74:             if ($event->isStopped()) {
 75:                 return $event->getResult();
 76:             }
 77:         }
 78: 
 79:         return $result;
 80:     }
 81: 
 82:     /**
 83:      * Returns the RulesChecker for this instance.
 84:      *
 85:      * A RulesChecker object is used to test an entity for validity
 86:      * on rules that may involve complex logic or data that
 87:      * needs to be fetched from relevant datasources.
 88:      *
 89:      * @see \Cake\Datasource\RulesChecker
 90:      * @return \Cake\Datasource\RulesChecker
 91:      */
 92:     public function rulesChecker()
 93:     {
 94:         if ($this->_rulesChecker !== null) {
 95:             return $this->_rulesChecker;
 96:         }
 97:         $class = defined('static::RULES_CLASS') ? static::RULES_CLASS : 'Cake\Datasource\RulesChecker';
 98:         $this->_rulesChecker = $this->buildRules(new $class(['repository' => $this]));
 99:         $this->dispatchEvent('Model.buildRules', ['rules' => $this->_rulesChecker]);
100: 
101:         return $this->_rulesChecker;
102:     }
103: 
104:     /**
105:      * Returns a RulesChecker object after modifying the one that was supplied.
106:      *
107:      * Subclasses should override this method in order to initialize the rules to be applied to
108:      * entities saved by this instance.
109:      *
110:      * @param \Cake\Datasource\RulesChecker $rules The rules object to be modified.
111:      * @return \Cake\Datasource\RulesChecker
112:      */
113:     public function buildRules(RulesChecker $rules)
114:     {
115:         return $rules;
116:     }
117: }
118: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs