hasBehavior() 공개 메소드

Check if a behavior with the given alias has been loaded.
public hasBehavior ( string $name ) : boolean
$name string The behavior alias to check.
리턴 boolean Whether or not the behavior exists.
예제 #1
0
 /**
  * Do some checks on the table which has been passed to make sure that it has what we need
  *
  * @param string $table The table
  * @return void
  */
 protected function checkTable($table)
 {
     try {
         $this->Table = $this->loadModel($table);
     } catch (Exception $e) {
         $this->out(__('<error>' . $e->getMessage() . '</error>'));
         exit;
     }
     if (get_class($this->Table) === 'AppModel') {
         $this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>'));
         exit;
     }
     if (!$this->Table->hasBehavior('Proffer')) {
         $out = __("<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>");
         $this->out($out);
         exit;
     }
     $config = $this->Table->behaviors()->Proffer->config();
     foreach ($config as $field => $settings) {
         if (!$this->Table->hasField($field)) {
             $out = __("<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>");
             $this->out($out);
             exit;
         }
         if (!$this->Table->hasField($settings['dir'])) {
             $out = __("<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>");
             $this->out($out);
             exit;
         }
     }
 }
 /**
  * Loads the User behavior for the user model if it is not already loaded
  *
  * @return void
  */
 public function loadUserBehaviour()
 {
     if ($this->_config['autoloadBehavior'] && !$this->UserTable->hasBehavior('UserTools.User')) {
         if (is_array($this->_config['autoloadBehavior'])) {
             $this->UserTable->addBehavior('Burzum/UserTools.User', $this->_config['autoloadBehavior']);
         } else {
             $this->UserTable->addBehavior('Burzum/UserTools.User');
         }
     }
 }