コード例 #1
0
ファイル: ListOperation.php プロジェクト: evaneos/berthe
 /**
  *
  * @param FetcherOperation $operation
  *
  * @return \Berthe\Fetcher\Operation\ListOperation
  */
 public function addOperation(FetcherOperation $operation)
 {
     $groupName = $operation->getGroupName();
     if ($groupName != null && $groupName != $this->groupName) {
         $this->operations[$groupName] = $operation;
     } else {
         $this->operations[] = $operation;
     }
     return $this;
 }
コード例 #2
0
ファイル: Fetcher.php プロジェクト: evaneos/berthe
 /**
  *
  * @param FetcherOperation $operation
  * @throws \InvalidArgumentException
  *
  * @return \Berthe\Fetcher
  */
 protected function addFilterOperation(FetcherOperation $operation)
 {
     $newOperation = $operation;
     $groupName = $operation->getGroupName();
     $previousOperation = $this->rootOperation->getOperation($groupName);
     //If there's already an operation for that group
     if ($previousOperation != null) {
         $groupFilterOperator = $this->getFilterOperator($groupName);
         $createNewList = true;
         if ($previousOperation instanceof ListOperation) {
             //If the previous operation is a list containing the groupName, we don't create a new list
             $subOperations = $previousOperation->getOperations();
             foreach ($subOperations as $subOperation) {
                 if ($subOperation->getGroupName() == $groupName) {
                     $createNewList = false;
                     break;
                 }
             }
         }
         if ($createNewList) {
             //We crate a list operation with the name of the group
             $newOperation = new ListOperation($groupFilterOperator, $groupName);
             //We add the retrieved operation to the new operation created
             $newOperation->addOperation($previousOperation);
         } else {
             $newOperation = $previousOperation;
         }
         //We add the new operation to the list operation retrieved/created
         $newOperation->addOperation($operation);
     }
     //If it's the first for its group, we keep it unchanged
     $this->rootOperation->addOperation($newOperation);
     return $this;
 }