Example #1
0
 /**
  *
  * @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;
 }