示例#1
0
 /**
  * {@inheritdoc}
  */
 public function search($element)
 {
     if ($element instanceof ActiveRecordInterface) {
         $hashCode = $element->hashCode();
         foreach ($this as $pos => $obj) {
             if ($hashCode === $obj->hashCode()) {
                 return $pos;
             }
         }
         return false;
     } else {
         return parent::search($element);
     }
 }
示例#2
0
 public function testSearch()
 {
     $col = new Collection();
     $this->assertFalse($col->search('bar1'), 'search() returns false on an empty collection');
     $data = array('bar1', 'bar2', 'bar3');
     $col = new Collection($data);
     $this->assertEquals(1, $col->search('bar2'), 'search() returns the key when the element exists');
     $this->assertFalse($col->search('bar4'), 'search() returns false when the element does not exist');
 }
 /**
  * {@inheritdoc}
  */
 public function search($element)
 {
     if ($element instanceof ActiveRecordInterface) {
         if (null !== ($elt = $this->getIdenticalObject($element))) {
             $element = $elt;
         }
     }
     return parent::search($element);
 }