public function __invoke($input) { if (null === $input) { return null; } $data = explode(',', trim($data, '()')); $locationId = \Bond\nullify($data[0]); $contactId = \Bond\nullify($data[1]); $orderDetailId = \Bond\nullify($data[2]); $data = array('locationId' => $locationId ? intval($locationId) : null, 'contactId' => $contactId ? intval($contactId) : null, 'orderDetailId' => $orderDetailId ? intval($orderDetailId) : null, 'propertiesId' => (int) $data[3]); return new StockStateEntity($data); }
public function testNullify() { $value = new stdClass(); $this->assertSame($value, \Bond\nullify($value)); $value = 'spanner'; $this->assertSame($value, \Bond\nullify($value)); $value = ' !'; $this->assertSame($value, \Bond\nullify($value)); $value = ' '; $this->assertNull(\Bond\nullify($value)); $value = ''; $this->assertNull(\Bond\nullify($value)); $value = null; $this->assertNull(\Bond\nullify($value)); }
public function parse(QuoteInterface $quoting) { // store of subsituted variables $substitutions = []; // for closure // this might not be required for postgres 5.4 $data = $this->data; $sql = preg_replace_callback('/% ([a-zA-Z1-9_]+) : (?: ( identifier| in| int| oid| text| citext| enum| timestamp| array| json| char\\([\\d]+\\)| varbit| bool| bytea )? (\\[\\])? ) (?:\\|([^%]+))? %/x', function ($matches) use($quoting, $substitutions, $data) { $namedKey = $matches[1]; // check we got everything we need if (!array_key_exists($namedKey, $data)) { throw new MissingArgumentException("Query does not have the named property `{$namedKey}`."); } // this been done before? if (!array_key_exists($namedKey, $substitutions)) { $isArray = (isset($matches[3]) and $matches[3] == '[]'); // coerse to type $coercedToType = \Bond\nullify(isset($matches[2]) ? $matches[2] : null); $modifier = new Modifier($quoting, $coercedToType, $isArray); // casting and transformers if (isset($matches[4])) { $this->processStringTransformers($matches[4], $modifier); // $modifier->addFromString( $matches[4] ); } // get the final value $substitutions[$namedKey] = $modifier->exec($data[$namedKey]); } return $substitutions[$namedKey]; }, $this->sqlGet()); return $sql; }