Example #1
0
 /**
  * Constructor
  * @param Configuration $configuration
  * @param string $localTable
  * @param string $localColumn
  * @param string $remoteTable
  * @param string $remoteColumn
  * @param string $type
  * @param string $rawChanges
  */
 public function __construct(Configuration $configuration, $localTable, $localColumn, $remoteTable, $remoteColumn, $type, $rawChanges)
 {
     $this->setLocalTable($localTable);
     $this->setLocalColumn($localColumn);
     $this->setRemoteTable($remoteTable);
     $this->setRemoteColumn($remoteColumn);
     $this->setRemoteModel($configuration->getRootNamespace() . '\\Models\\' . $configuration->getModelSubNamespace() . '\\' . ucfirst($this->getRemoteTable()));
     $this->setRelationshipType($type);
     $this->setAction('NO_ACTION');
     if (preg_match_all('@ON (?P<actionType>(DELETE|UPDATE)+) (?P<action>(SET NULL|NO ACTION|CASCADE))@', $rawChanges, $subMatches)) {
         $length = sizeOf($subMatches[0]);
         $changes = array();
         for ($i = 0; $i < $length; $i++) {
             $changes[$subMatches['actionType'][$i]] = $subMatches['action'][$i];
         }
         $action = 'NO_ACTION';
         if (isset($changes['DELETE']) && $changes['DELETE'] == 'SET NULL') {
             $this->setNullable(true);
             $action = 'NO_ACTION';
         } elseif (isset($changes['DELETE']) && $changes['DELETE'] == 'CASCADE') {
             $action = 'ACTION_CASCADE';
         }
         $this->setAction($action);
     }
 }