public function testConstructWithString() { $set = new Text(); $this->assertSame((string) $set, ''); $set = new Text('6'); $this->assertSame((string) $set, '6'); $filthyString = '"\\$%\\-:9'; $set = new Text(Set::escape($filthyString)); $this->assertSame($set->intervals[0][0], $filthyString); $this->assertTrue($set->contains(array($filthyString))); $set = new Text('-B'); $this->assertSame((string) $set, '-B'); $set = new Text('9-'); $this->assertSame((string) $set, '9-'); $set = new Text('1,2,3'); $this->assertSame((string) $set, '1,2,3'); $set = new Text('1,,'); $this->assertSame((string) $set, '1'); $set = new Text('1,1,1'); $this->assertSame((string) $set, '1'); $set = new Text('A-Z'); $this->assertSame((string) $set, 'A-Z'); }
/** * {@inheritDoc} */ public function invert() { // we can't invert a text set if it has any 'values' (ie, non range intervals) in it // check for these and throw a error if we have any foreach ($this->intervals as $interval) { if ($interval[0] === $interval[1] and $interval[0] !== null) { throw new \RuntimeException("I'm sorry I can't invert the text set('{$this}') because it contains values."); } } return parent::invert(); }
/** * Lookup a entity based on it's 'primary key' or key column when passed a set. * This will always return a Container * @return Bond\Container */ public function findBySet(Set $keySet) { // the simplest thing that possibly works // there're a lot of fairly easy performance gains to doing this differently. // this can be speeded up lots. Think interval intersection with value explosion. $multiton = $this->makeNewContainer(); // persisted foreach ($this->instancesPersisted as $key => $entity) { if ($keySet->contains($key)) { $multiton->add($entity); } } // unpersisted foreach ($this->instancesUnpersisted as $entity) { if ($keySet->contains($entity->keyGet($entity))) { $multiton->add($entity); } } $persisted = parent::findBySet($keySet); return $this->makeNewContainer()->add($multiton, $persisted); }
/** * Lookup a entity based on it's 'primary key' or key column when passed a set. * This will always return a Container * @return Container */ public function findBySet(Set $keySet) { $dataTypes = $this->dataTypesGet(DataType::PRIMARY_KEYS); if (count($dataTypes) == 0) { throw new \EntityPrimar("No primary keys for this entity. Don't know what key(s) to lookup on. Sorry."); } $identifiers = array(); foreach ($dataTypes as $dataType) { $identifiers[] = $this->db->quoteIdent($dataType->name); } $keySet->sqlIdentifierSet(implode("||'" . Base::KEY_SEPARATOR . "'||", $identifiers)); // lookup data $query = new Query(sprintf("SELECT * FROM ONLY %s WHERE %s", $this->db->quoteIdent($this->__get('table')), '%keySet:%'), array('keySet' => $keySet)); $result = $this->db->query($query); $datas = $result->fetch(Result::FLATTEN_PREVENT); return $this->initByDatas($datas); }
/** * {@inheritDoc} */ public function count() { $output = parent::count(); foreach ($this->intervals as $interval) { if ($interval[0] === null or $interval[1] === null) { return null; } else { $output += $interval[1] - $interval[0] + 1; # add the 1 because the interval is inclusive } } return $output; }