repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.getByPosition
public function getByPosition($pos) { switch ($pos) { case 0: return $this->getId(); break; case 1: return $this->getName(); break; case 2: return $this->getStreet(); break; case 3: return $this->getZip(); break; case 4: return $this->getCity(); break; case 5: return $this->getCountryId(); break; case 6: return $this->getPhone(); break; case 7: return $this->getFax(); break; case 8: return $this->getEmail(); break; case 9: return $this->getLegalform(); break; case 10: return $this->getLogo(); break; case 11: return $this->getCreated(); break; case 12: return $this->getNotes(); break; default: return null; break; } // switch() }
php
public function getByPosition($pos) { switch ($pos) { case 0: return $this->getId(); break; case 1: return $this->getName(); break; case 2: return $this->getStreet(); break; case 3: return $this->getZip(); break; case 4: return $this->getCity(); break; case 5: return $this->getCountryId(); break; case 6: return $this->getPhone(); break; case 7: return $this->getFax(); break; case 8: return $this->getEmail(); break; case 9: return $this->getLegalform(); break; case 10: return $this->getLogo(); break; case 11: return $this->getCreated(); break; case 12: return $this->getNotes(); break; default: return null; break; } // switch() }
[ "public", "function", "getByPosition", "(", "$", "pos", ")", "{", "switch", "(", "$", "pos", ")", "{", "case", "0", ":", "return", "$", "this", "->", "getId", "(", ")", ";", "break", ";", "case", "1", ":", "return", "$", "this", "->", "getName", "(", ")", ";", "break", ";", "case", "2", ":", "return", "$", "this", "->", "getStreet", "(", ")", ";", "break", ";", "case", "3", ":", "return", "$", "this", "->", "getZip", "(", ")", ";", "break", ";", "case", "4", ":", "return", "$", "this", "->", "getCity", "(", ")", ";", "break", ";", "case", "5", ":", "return", "$", "this", "->", "getCountryId", "(", ")", ";", "break", ";", "case", "6", ":", "return", "$", "this", "->", "getPhone", "(", ")", ";", "break", ";", "case", "7", ":", "return", "$", "this", "->", "getFax", "(", ")", ";", "break", ";", "case", "8", ":", "return", "$", "this", "->", "getEmail", "(", ")", ";", "break", ";", "case", "9", ":", "return", "$", "this", "->", "getLegalform", "(", ")", ";", "break", ";", "case", "10", ":", "return", "$", "this", "->", "getLogo", "(", ")", ";", "break", ";", "case", "11", ":", "return", "$", "this", "->", "getCreated", "(", ")", ";", "break", ";", "case", "12", ":", "return", "$", "this", "->", "getNotes", "(", ")", ";", "break", ";", "default", ":", "return", "null", ";", "break", ";", "}", "// switch()", "}" ]
Retrieves a field from the object by Position as specified in the xml schema. Zero-based. @param int $pos position in xml schema @return mixed Value of field at $pos
[ "Retrieves", "a", "field", "from", "the", "object", "by", "Position", "as", "specified", "in", "the", "xml", "schema", ".", "Zero", "-", "based", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1196-L1242
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.toArray
public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['Customer'][$this->getPrimaryKey()])) { return '*RECURSION*'; } $alreadyDumpedObjects['Customer'][$this->getPrimaryKey()] = true; $keys = CustomerPeer::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getName(), $keys[2] => $this->getStreet(), $keys[3] => $this->getZip(), $keys[4] => $this->getCity(), $keys[5] => $this->getCountryId(), $keys[6] => $this->getPhone(), $keys[7] => $this->getFax(), $keys[8] => $this->getEmail(), $keys[9] => $this->getLegalform(), $keys[10] => $this->getLogo(), $keys[11] => $this->getCreated(), $keys[12] => $this->getNotes(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aCountry) { $result['Country'] = $this->aCountry->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->collRemoteApps) { $result['RemoteApps'] = $this->collRemoteApps->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collUserCustomerRelations) { $result['UserCustomerRelations'] = $this->collUserCustomerRelations->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } return $result; }
php
public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['Customer'][$this->getPrimaryKey()])) { return '*RECURSION*'; } $alreadyDumpedObjects['Customer'][$this->getPrimaryKey()] = true; $keys = CustomerPeer::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getName(), $keys[2] => $this->getStreet(), $keys[3] => $this->getZip(), $keys[4] => $this->getCity(), $keys[5] => $this->getCountryId(), $keys[6] => $this->getPhone(), $keys[7] => $this->getFax(), $keys[8] => $this->getEmail(), $keys[9] => $this->getLegalform(), $keys[10] => $this->getLogo(), $keys[11] => $this->getCreated(), $keys[12] => $this->getNotes(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aCountry) { $result['Country'] = $this->aCountry->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->collRemoteApps) { $result['RemoteApps'] = $this->collRemoteApps->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collUserCustomerRelations) { $result['UserCustomerRelations'] = $this->collUserCustomerRelations->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } return $result; }
[ "public", "function", "toArray", "(", "$", "keyType", "=", "BasePeer", "::", "TYPE_PHPNAME", ",", "$", "includeLazyLoadColumns", "=", "true", ",", "$", "alreadyDumpedObjects", "=", "array", "(", ")", ",", "$", "includeForeignObjects", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "alreadyDumpedObjects", "[", "'Customer'", "]", "[", "$", "this", "->", "getPrimaryKey", "(", ")", "]", ")", ")", "{", "return", "'*RECURSION*'", ";", "}", "$", "alreadyDumpedObjects", "[", "'Customer'", "]", "[", "$", "this", "->", "getPrimaryKey", "(", ")", "]", "=", "true", ";", "$", "keys", "=", "CustomerPeer", "::", "getFieldNames", "(", "$", "keyType", ")", ";", "$", "result", "=", "array", "(", "$", "keys", "[", "0", "]", "=>", "$", "this", "->", "getId", "(", ")", ",", "$", "keys", "[", "1", "]", "=>", "$", "this", "->", "getName", "(", ")", ",", "$", "keys", "[", "2", "]", "=>", "$", "this", "->", "getStreet", "(", ")", ",", "$", "keys", "[", "3", "]", "=>", "$", "this", "->", "getZip", "(", ")", ",", "$", "keys", "[", "4", "]", "=>", "$", "this", "->", "getCity", "(", ")", ",", "$", "keys", "[", "5", "]", "=>", "$", "this", "->", "getCountryId", "(", ")", ",", "$", "keys", "[", "6", "]", "=>", "$", "this", "->", "getPhone", "(", ")", ",", "$", "keys", "[", "7", "]", "=>", "$", "this", "->", "getFax", "(", ")", ",", "$", "keys", "[", "8", "]", "=>", "$", "this", "->", "getEmail", "(", ")", ",", "$", "keys", "[", "9", "]", "=>", "$", "this", "->", "getLegalform", "(", ")", ",", "$", "keys", "[", "10", "]", "=>", "$", "this", "->", "getLogo", "(", ")", ",", "$", "keys", "[", "11", "]", "=>", "$", "this", "->", "getCreated", "(", ")", ",", "$", "keys", "[", "12", "]", "=>", "$", "this", "->", "getNotes", "(", ")", ",", ")", ";", "$", "virtualColumns", "=", "$", "this", "->", "virtualColumns", ";", "foreach", "(", "$", "virtualColumns", "as", "$", "key", "=>", "$", "virtualColumn", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "virtualColumn", ";", "}", "if", "(", "$", "includeForeignObjects", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "aCountry", ")", "{", "$", "result", "[", "'Country'", "]", "=", "$", "this", "->", "aCountry", "->", "toArray", "(", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ",", "true", ")", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "collRemoteApps", ")", "{", "$", "result", "[", "'RemoteApps'", "]", "=", "$", "this", "->", "collRemoteApps", "->", "toArray", "(", "null", ",", "true", ",", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ")", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "collUserCustomerRelations", ")", "{", "$", "result", "[", "'UserCustomerRelations'", "]", "=", "$", "this", "->", "collUserCustomerRelations", "->", "toArray", "(", "null", ",", "true", ",", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Exports the object as an array. You can specify the key type of the array by passing one of the class type constants. @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME. @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true. @param array $alreadyDumpedObjects List of objects to skip to avoid recursion @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. @return array an associative array containing the field names (as keys) and field values
[ "Exports", "the", "object", "as", "an", "array", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1259-L1299
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.setByPosition
public function setByPosition($pos, $value) { switch ($pos) { case 0: $this->setId($value); break; case 1: $this->setName($value); break; case 2: $this->setStreet($value); break; case 3: $this->setZip($value); break; case 4: $this->setCity($value); break; case 5: $this->setCountryId($value); break; case 6: $this->setPhone($value); break; case 7: $this->setFax($value); break; case 8: $this->setEmail($value); break; case 9: $this->setLegalform($value); break; case 10: $this->setLogo($value); break; case 11: $this->setCreated($value); break; case 12: $this->setNotes($value); break; } // switch() }
php
public function setByPosition($pos, $value) { switch ($pos) { case 0: $this->setId($value); break; case 1: $this->setName($value); break; case 2: $this->setStreet($value); break; case 3: $this->setZip($value); break; case 4: $this->setCity($value); break; case 5: $this->setCountryId($value); break; case 6: $this->setPhone($value); break; case 7: $this->setFax($value); break; case 8: $this->setEmail($value); break; case 9: $this->setLegalform($value); break; case 10: $this->setLogo($value); break; case 11: $this->setCreated($value); break; case 12: $this->setNotes($value); break; } // switch() }
[ "public", "function", "setByPosition", "(", "$", "pos", ",", "$", "value", ")", "{", "switch", "(", "$", "pos", ")", "{", "case", "0", ":", "$", "this", "->", "setId", "(", "$", "value", ")", ";", "break", ";", "case", "1", ":", "$", "this", "->", "setName", "(", "$", "value", ")", ";", "break", ";", "case", "2", ":", "$", "this", "->", "setStreet", "(", "$", "value", ")", ";", "break", ";", "case", "3", ":", "$", "this", "->", "setZip", "(", "$", "value", ")", ";", "break", ";", "case", "4", ":", "$", "this", "->", "setCity", "(", "$", "value", ")", ";", "break", ";", "case", "5", ":", "$", "this", "->", "setCountryId", "(", "$", "value", ")", ";", "break", ";", "case", "6", ":", "$", "this", "->", "setPhone", "(", "$", "value", ")", ";", "break", ";", "case", "7", ":", "$", "this", "->", "setFax", "(", "$", "value", ")", ";", "break", ";", "case", "8", ":", "$", "this", "->", "setEmail", "(", "$", "value", ")", ";", "break", ";", "case", "9", ":", "$", "this", "->", "setLegalform", "(", "$", "value", ")", ";", "break", ";", "case", "10", ":", "$", "this", "->", "setLogo", "(", "$", "value", ")", ";", "break", ";", "case", "11", ":", "$", "this", "->", "setCreated", "(", "$", "value", ")", ";", "break", ";", "case", "12", ":", "$", "this", "->", "setNotes", "(", "$", "value", ")", ";", "break", ";", "}", "// switch()", "}" ]
Sets a field from the object by Position as specified in the xml schema. Zero-based. @param int $pos position in xml schema @param mixed $value field value @return void
[ "Sets", "a", "field", "from", "the", "object", "by", "Position", "as", "specified", "in", "the", "xml", "schema", ".", "Zero", "-", "based", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1327-L1370
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.fromArray
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = CustomerPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setName($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setStreet($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setZip($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setCity($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setCountryId($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setPhone($arr[$keys[6]]); if (array_key_exists($keys[7], $arr)) $this->setFax($arr[$keys[7]]); if (array_key_exists($keys[8], $arr)) $this->setEmail($arr[$keys[8]]); if (array_key_exists($keys[9], $arr)) $this->setLegalform($arr[$keys[9]]); if (array_key_exists($keys[10], $arr)) $this->setLogo($arr[$keys[10]]); if (array_key_exists($keys[11], $arr)) $this->setCreated($arr[$keys[11]]); if (array_key_exists($keys[12], $arr)) $this->setNotes($arr[$keys[12]]); }
php
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = CustomerPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setName($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setStreet($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setZip($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setCity($arr[$keys[4]]); if (array_key_exists($keys[5], $arr)) $this->setCountryId($arr[$keys[5]]); if (array_key_exists($keys[6], $arr)) $this->setPhone($arr[$keys[6]]); if (array_key_exists($keys[7], $arr)) $this->setFax($arr[$keys[7]]); if (array_key_exists($keys[8], $arr)) $this->setEmail($arr[$keys[8]]); if (array_key_exists($keys[9], $arr)) $this->setLegalform($arr[$keys[9]]); if (array_key_exists($keys[10], $arr)) $this->setLogo($arr[$keys[10]]); if (array_key_exists($keys[11], $arr)) $this->setCreated($arr[$keys[11]]); if (array_key_exists($keys[12], $arr)) $this->setNotes($arr[$keys[12]]); }
[ "public", "function", "fromArray", "(", "$", "arr", ",", "$", "keyType", "=", "BasePeer", "::", "TYPE_PHPNAME", ")", "{", "$", "keys", "=", "CustomerPeer", "::", "getFieldNames", "(", "$", "keyType", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "0", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setId", "(", "$", "arr", "[", "$", "keys", "[", "0", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "1", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setName", "(", "$", "arr", "[", "$", "keys", "[", "1", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "2", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setStreet", "(", "$", "arr", "[", "$", "keys", "[", "2", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "3", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setZip", "(", "$", "arr", "[", "$", "keys", "[", "3", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "4", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setCity", "(", "$", "arr", "[", "$", "keys", "[", "4", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "5", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setCountryId", "(", "$", "arr", "[", "$", "keys", "[", "5", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "6", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setPhone", "(", "$", "arr", "[", "$", "keys", "[", "6", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "7", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setFax", "(", "$", "arr", "[", "$", "keys", "[", "7", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "8", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setEmail", "(", "$", "arr", "[", "$", "keys", "[", "8", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "9", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setLegalform", "(", "$", "arr", "[", "$", "keys", "[", "9", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "10", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setLogo", "(", "$", "arr", "[", "$", "keys", "[", "10", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "11", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setCreated", "(", "$", "arr", "[", "$", "keys", "[", "11", "]", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "12", "]", ",", "$", "arr", ")", ")", "$", "this", "->", "setNotes", "(", "$", "arr", "[", "$", "keys", "[", "12", "]", "]", ")", ";", "}" ]
Populates the object using an array. This is particularly useful when populating an object from one of the request arrays (e.g. $_POST). This method goes through the column names, checking to see whether a matching key exists in populated array. If so the setByName() method is called for that column. You can specify the key type of the array by additionally passing one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. The default key type is the column's BasePeer::TYPE_PHPNAME @param array $arr An array to populate the object from. @param string $keyType The type of keys the array uses. @return void
[ "Populates", "the", "object", "using", "an", "array", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1389-L1406
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.buildCriteria
public function buildCriteria() { $criteria = new Criteria(CustomerPeer::DATABASE_NAME); if ($this->isColumnModified(CustomerPeer::ID)) $criteria->add(CustomerPeer::ID, $this->id); if ($this->isColumnModified(CustomerPeer::NAME)) $criteria->add(CustomerPeer::NAME, $this->name); if ($this->isColumnModified(CustomerPeer::STREET)) $criteria->add(CustomerPeer::STREET, $this->street); if ($this->isColumnModified(CustomerPeer::ZIP)) $criteria->add(CustomerPeer::ZIP, $this->zip); if ($this->isColumnModified(CustomerPeer::CITY)) $criteria->add(CustomerPeer::CITY, $this->city); if ($this->isColumnModified(CustomerPeer::COUNTRY_ID)) $criteria->add(CustomerPeer::COUNTRY_ID, $this->country_id); if ($this->isColumnModified(CustomerPeer::PHONE)) $criteria->add(CustomerPeer::PHONE, $this->phone); if ($this->isColumnModified(CustomerPeer::FAX)) $criteria->add(CustomerPeer::FAX, $this->fax); if ($this->isColumnModified(CustomerPeer::EMAIL)) $criteria->add(CustomerPeer::EMAIL, $this->email); if ($this->isColumnModified(CustomerPeer::LEGALFORM)) $criteria->add(CustomerPeer::LEGALFORM, $this->legalform); if ($this->isColumnModified(CustomerPeer::LOGO)) $criteria->add(CustomerPeer::LOGO, $this->logo); if ($this->isColumnModified(CustomerPeer::CREATED)) $criteria->add(CustomerPeer::CREATED, $this->created); if ($this->isColumnModified(CustomerPeer::NOTES)) $criteria->add(CustomerPeer::NOTES, $this->notes); return $criteria; }
php
public function buildCriteria() { $criteria = new Criteria(CustomerPeer::DATABASE_NAME); if ($this->isColumnModified(CustomerPeer::ID)) $criteria->add(CustomerPeer::ID, $this->id); if ($this->isColumnModified(CustomerPeer::NAME)) $criteria->add(CustomerPeer::NAME, $this->name); if ($this->isColumnModified(CustomerPeer::STREET)) $criteria->add(CustomerPeer::STREET, $this->street); if ($this->isColumnModified(CustomerPeer::ZIP)) $criteria->add(CustomerPeer::ZIP, $this->zip); if ($this->isColumnModified(CustomerPeer::CITY)) $criteria->add(CustomerPeer::CITY, $this->city); if ($this->isColumnModified(CustomerPeer::COUNTRY_ID)) $criteria->add(CustomerPeer::COUNTRY_ID, $this->country_id); if ($this->isColumnModified(CustomerPeer::PHONE)) $criteria->add(CustomerPeer::PHONE, $this->phone); if ($this->isColumnModified(CustomerPeer::FAX)) $criteria->add(CustomerPeer::FAX, $this->fax); if ($this->isColumnModified(CustomerPeer::EMAIL)) $criteria->add(CustomerPeer::EMAIL, $this->email); if ($this->isColumnModified(CustomerPeer::LEGALFORM)) $criteria->add(CustomerPeer::LEGALFORM, $this->legalform); if ($this->isColumnModified(CustomerPeer::LOGO)) $criteria->add(CustomerPeer::LOGO, $this->logo); if ($this->isColumnModified(CustomerPeer::CREATED)) $criteria->add(CustomerPeer::CREATED, $this->created); if ($this->isColumnModified(CustomerPeer::NOTES)) $criteria->add(CustomerPeer::NOTES, $this->notes); return $criteria; }
[ "public", "function", "buildCriteria", "(", ")", "{", "$", "criteria", "=", "new", "Criteria", "(", "CustomerPeer", "::", "DATABASE_NAME", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "ID", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "ID", ",", "$", "this", "->", "id", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "NAME", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "NAME", ",", "$", "this", "->", "name", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "STREET", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "STREET", ",", "$", "this", "->", "street", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "ZIP", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "ZIP", ",", "$", "this", "->", "zip", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "CITY", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "CITY", ",", "$", "this", "->", "city", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "COUNTRY_ID", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "COUNTRY_ID", ",", "$", "this", "->", "country_id", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "PHONE", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "PHONE", ",", "$", "this", "->", "phone", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "FAX", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "FAX", ",", "$", "this", "->", "fax", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "EMAIL", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "EMAIL", ",", "$", "this", "->", "email", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "LEGALFORM", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "LEGALFORM", ",", "$", "this", "->", "legalform", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "LOGO", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "LOGO", ",", "$", "this", "->", "logo", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "CREATED", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "CREATED", ",", "$", "this", "->", "created", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "CustomerPeer", "::", "NOTES", ")", ")", "$", "criteria", "->", "add", "(", "CustomerPeer", "::", "NOTES", ",", "$", "this", "->", "notes", ")", ";", "return", "$", "criteria", ";", "}" ]
Build a Criteria object containing the values of all modified columns in this object. @return Criteria The Criteria object containing all modified values.
[ "Build", "a", "Criteria", "object", "containing", "the", "values", "of", "all", "modified", "columns", "in", "this", "object", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1413-L1432
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.copyInto
public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { $copyObj->setName($this->getName()); $copyObj->setStreet($this->getStreet()); $copyObj->setZip($this->getZip()); $copyObj->setCity($this->getCity()); $copyObj->setCountryId($this->getCountryId()); $copyObj->setPhone($this->getPhone()); $copyObj->setFax($this->getFax()); $copyObj->setEmail($this->getEmail()); $copyObj->setLegalform($this->getLegalform()); $copyObj->setLogo($this->getLogo()); $copyObj->setCreated($this->getCreated()); $copyObj->setNotes($this->getNotes()); if ($deepCopy && !$this->startCopy) { // important: temporarily setNew(false) because this affects the behavior of // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); // store object hash to prevent cycle $this->startCopy = true; foreach ($this->getRemoteApps() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addRemoteApp($relObj->copy($deepCopy)); } } foreach ($this->getUserCustomerRelations() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addUserCustomerRelation($relObj->copy($deepCopy)); } } //unflag object copy $this->startCopy = false; } // if ($deepCopy) if ($makeNew) { $copyObj->setNew(true); $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } }
php
public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { $copyObj->setName($this->getName()); $copyObj->setStreet($this->getStreet()); $copyObj->setZip($this->getZip()); $copyObj->setCity($this->getCity()); $copyObj->setCountryId($this->getCountryId()); $copyObj->setPhone($this->getPhone()); $copyObj->setFax($this->getFax()); $copyObj->setEmail($this->getEmail()); $copyObj->setLegalform($this->getLegalform()); $copyObj->setLogo($this->getLogo()); $copyObj->setCreated($this->getCreated()); $copyObj->setNotes($this->getNotes()); if ($deepCopy && !$this->startCopy) { // important: temporarily setNew(false) because this affects the behavior of // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); // store object hash to prevent cycle $this->startCopy = true; foreach ($this->getRemoteApps() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addRemoteApp($relObj->copy($deepCopy)); } } foreach ($this->getUserCustomerRelations() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addUserCustomerRelation($relObj->copy($deepCopy)); } } //unflag object copy $this->startCopy = false; } // if ($deepCopy) if ($makeNew) { $copyObj->setNew(true); $copyObj->setId(NULL); // this is a auto-increment column, so set to default value } }
[ "public", "function", "copyInto", "(", "$", "copyObj", ",", "$", "deepCopy", "=", "false", ",", "$", "makeNew", "=", "true", ")", "{", "$", "copyObj", "->", "setName", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "$", "copyObj", "->", "setStreet", "(", "$", "this", "->", "getStreet", "(", ")", ")", ";", "$", "copyObj", "->", "setZip", "(", "$", "this", "->", "getZip", "(", ")", ")", ";", "$", "copyObj", "->", "setCity", "(", "$", "this", "->", "getCity", "(", ")", ")", ";", "$", "copyObj", "->", "setCountryId", "(", "$", "this", "->", "getCountryId", "(", ")", ")", ";", "$", "copyObj", "->", "setPhone", "(", "$", "this", "->", "getPhone", "(", ")", ")", ";", "$", "copyObj", "->", "setFax", "(", "$", "this", "->", "getFax", "(", ")", ")", ";", "$", "copyObj", "->", "setEmail", "(", "$", "this", "->", "getEmail", "(", ")", ")", ";", "$", "copyObj", "->", "setLegalform", "(", "$", "this", "->", "getLegalform", "(", ")", ")", ";", "$", "copyObj", "->", "setLogo", "(", "$", "this", "->", "getLogo", "(", ")", ")", ";", "$", "copyObj", "->", "setCreated", "(", "$", "this", "->", "getCreated", "(", ")", ")", ";", "$", "copyObj", "->", "setNotes", "(", "$", "this", "->", "getNotes", "(", ")", ")", ";", "if", "(", "$", "deepCopy", "&&", "!", "$", "this", "->", "startCopy", ")", "{", "// important: temporarily setNew(false) because this affects the behavior of", "// the getter/setter methods for fkey referrer objects.", "$", "copyObj", "->", "setNew", "(", "false", ")", ";", "// store object hash to prevent cycle", "$", "this", "->", "startCopy", "=", "true", ";", "foreach", "(", "$", "this", "->", "getRemoteApps", "(", ")", "as", "$", "relObj", ")", "{", "if", "(", "$", "relObj", "!==", "$", "this", ")", "{", "// ensure that we don't try to copy a reference to ourselves", "$", "copyObj", "->", "addRemoteApp", "(", "$", "relObj", "->", "copy", "(", "$", "deepCopy", ")", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "getUserCustomerRelations", "(", ")", "as", "$", "relObj", ")", "{", "if", "(", "$", "relObj", "!==", "$", "this", ")", "{", "// ensure that we don't try to copy a reference to ourselves", "$", "copyObj", "->", "addUserCustomerRelation", "(", "$", "relObj", "->", "copy", "(", "$", "deepCopy", ")", ")", ";", "}", "}", "//unflag object copy", "$", "this", "->", "startCopy", "=", "false", ";", "}", "// if ($deepCopy)", "if", "(", "$", "makeNew", ")", "{", "$", "copyObj", "->", "setNew", "(", "true", ")", ";", "$", "copyObj", "->", "setId", "(", "NULL", ")", ";", "// this is a auto-increment column, so set to default value", "}", "}" ]
Sets contents of passed object to values from current object. If desired, this method can also make copies of all associated (fkey referrers) objects. @param object $copyObj An object of Customer (or compatible) type. @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. @throws PropelException
[ "Sets", "contents", "of", "passed", "object", "to", "values", "from", "current", "object", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1491-L1533
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.setCountry
public function setCountry(Country $v = null) { if ($v === null) { $this->setCountryId(NULL); } else { $this->setCountryId($v->getId()); } $this->aCountry = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Country object, it will not be re-added. if ($v !== null) { $v->addCustomer($this); } return $this; }
php
public function setCountry(Country $v = null) { if ($v === null) { $this->setCountryId(NULL); } else { $this->setCountryId($v->getId()); } $this->aCountry = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Country object, it will not be re-added. if ($v !== null) { $v->addCustomer($this); } return $this; }
[ "public", "function", "setCountry", "(", "Country", "$", "v", "=", "null", ")", "{", "if", "(", "$", "v", "===", "null", ")", "{", "$", "this", "->", "setCountryId", "(", "NULL", ")", ";", "}", "else", "{", "$", "this", "->", "setCountryId", "(", "$", "v", "->", "getId", "(", ")", ")", ";", "}", "$", "this", "->", "aCountry", "=", "$", "v", ";", "// Add binding for other direction of this n:n relationship.", "// If this object has already been added to the Country object, it will not be re-added.", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "->", "addCustomer", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Declares an association between this object and a Country object. @param Country $v @return Customer The current object (for fluent API support) @throws PropelException
[ "Declares", "an", "association", "between", "this", "object", "and", "a", "Country", "object", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1582-L1600
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.getCountry
public function getCountry(PropelPDO $con = null, $doQuery = true) { if ($this->aCountry === null && ($this->country_id !== null) && $doQuery) { $this->aCountry = CountryQuery::create()->findPk($this->country_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCountry->addCustomers($this); */ } return $this->aCountry; }
php
public function getCountry(PropelPDO $con = null, $doQuery = true) { if ($this->aCountry === null && ($this->country_id !== null) && $doQuery) { $this->aCountry = CountryQuery::create()->findPk($this->country_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCountry->addCustomers($this); */ } return $this->aCountry; }
[ "public", "function", "getCountry", "(", "PropelPDO", "$", "con", "=", "null", ",", "$", "doQuery", "=", "true", ")", "{", "if", "(", "$", "this", "->", "aCountry", "===", "null", "&&", "(", "$", "this", "->", "country_id", "!==", "null", ")", "&&", "$", "doQuery", ")", "{", "$", "this", "->", "aCountry", "=", "CountryQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "this", "->", "country_id", ",", "$", "con", ")", ";", "/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aCountry->addCustomers($this);\n */", "}", "return", "$", "this", "->", "aCountry", ";", "}" ]
Get the associated Country object @param PropelPDO $con Optional Connection object. @param $doQuery Executes a query to get the object if required @return Country The associated Country object. @throws PropelException
[ "Get", "the", "associated", "Country", "object" ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1611-L1625
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.initRemoteApps
public function initRemoteApps($overrideExisting = true) { if (null !== $this->collRemoteApps && !$overrideExisting) { return; } $this->collRemoteApps = new PropelObjectCollection(); $this->collRemoteApps->setModel('RemoteApp'); }
php
public function initRemoteApps($overrideExisting = true) { if (null !== $this->collRemoteApps && !$overrideExisting) { return; } $this->collRemoteApps = new PropelObjectCollection(); $this->collRemoteApps->setModel('RemoteApp'); }
[ "public", "function", "initRemoteApps", "(", "$", "overrideExisting", "=", "true", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "collRemoteApps", "&&", "!", "$", "overrideExisting", ")", "{", "return", ";", "}", "$", "this", "->", "collRemoteApps", "=", "new", "PropelObjectCollection", "(", ")", ";", "$", "this", "->", "collRemoteApps", "->", "setModel", "(", "'RemoteApp'", ")", ";", "}" ]
Initializes the collRemoteApps collection. By default this just sets the collRemoteApps collection to an empty array (like clearcollRemoteApps()); however, you may wish to override this method in your stub class to provide setting appropriate to your application -- for example, setting the initial array to the values stored in database. @param boolean $overrideExisting If set to true, the method call initializes the collection even if it is not empty @return void
[ "Initializes", "the", "collRemoteApps", "collection", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1685-L1692
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.getRemoteApps
public function getRemoteApps($criteria = null, PropelPDO $con = null) { $partial = $this->collRemoteAppsPartial && !$this->isNew(); if (null === $this->collRemoteApps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRemoteApps) { // return empty collection $this->initRemoteApps(); } else { $collRemoteApps = RemoteAppQuery::create(null, $criteria) ->filterByCustomer($this) ->find($con); if (null !== $criteria) { if (false !== $this->collRemoteAppsPartial && count($collRemoteApps)) { $this->initRemoteApps(false); foreach ($collRemoteApps as $obj) { if (false == $this->collRemoteApps->contains($obj)) { $this->collRemoteApps->append($obj); } } $this->collRemoteAppsPartial = true; } $collRemoteApps->getInternalIterator()->rewind(); return $collRemoteApps; } if ($partial && $this->collRemoteApps) { foreach ($this->collRemoteApps as $obj) { if ($obj->isNew()) { $collRemoteApps[] = $obj; } } } $this->collRemoteApps = $collRemoteApps; $this->collRemoteAppsPartial = false; } } return $this->collRemoteApps; }
php
public function getRemoteApps($criteria = null, PropelPDO $con = null) { $partial = $this->collRemoteAppsPartial && !$this->isNew(); if (null === $this->collRemoteApps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRemoteApps) { // return empty collection $this->initRemoteApps(); } else { $collRemoteApps = RemoteAppQuery::create(null, $criteria) ->filterByCustomer($this) ->find($con); if (null !== $criteria) { if (false !== $this->collRemoteAppsPartial && count($collRemoteApps)) { $this->initRemoteApps(false); foreach ($collRemoteApps as $obj) { if (false == $this->collRemoteApps->contains($obj)) { $this->collRemoteApps->append($obj); } } $this->collRemoteAppsPartial = true; } $collRemoteApps->getInternalIterator()->rewind(); return $collRemoteApps; } if ($partial && $this->collRemoteApps) { foreach ($this->collRemoteApps as $obj) { if ($obj->isNew()) { $collRemoteApps[] = $obj; } } } $this->collRemoteApps = $collRemoteApps; $this->collRemoteAppsPartial = false; } } return $this->collRemoteApps; }
[ "public", "function", "getRemoteApps", "(", "$", "criteria", "=", "null", ",", "PropelPDO", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRemoteAppsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRemoteApps", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collRemoteApps", ")", "{", "// return empty collection", "$", "this", "->", "initRemoteApps", "(", ")", ";", "}", "else", "{", "$", "collRemoteApps", "=", "RemoteAppQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", "->", "filterByCustomer", "(", "$", "this", ")", "->", "find", "(", "$", "con", ")", ";", "if", "(", "null", "!==", "$", "criteria", ")", "{", "if", "(", "false", "!==", "$", "this", "->", "collRemoteAppsPartial", "&&", "count", "(", "$", "collRemoteApps", ")", ")", "{", "$", "this", "->", "initRemoteApps", "(", "false", ")", ";", "foreach", "(", "$", "collRemoteApps", "as", "$", "obj", ")", "{", "if", "(", "false", "==", "$", "this", "->", "collRemoteApps", "->", "contains", "(", "$", "obj", ")", ")", "{", "$", "this", "->", "collRemoteApps", "->", "append", "(", "$", "obj", ")", ";", "}", "}", "$", "this", "->", "collRemoteAppsPartial", "=", "true", ";", "}", "$", "collRemoteApps", "->", "getInternalIterator", "(", ")", "->", "rewind", "(", ")", ";", "return", "$", "collRemoteApps", ";", "}", "if", "(", "$", "partial", "&&", "$", "this", "->", "collRemoteApps", ")", "{", "foreach", "(", "$", "this", "->", "collRemoteApps", "as", "$", "obj", ")", "{", "if", "(", "$", "obj", "->", "isNew", "(", ")", ")", "{", "$", "collRemoteApps", "[", "]", "=", "$", "obj", ";", "}", "}", "}", "$", "this", "->", "collRemoteApps", "=", "$", "collRemoteApps", ";", "$", "this", "->", "collRemoteAppsPartial", "=", "false", ";", "}", "}", "return", "$", "this", "->", "collRemoteApps", ";", "}" ]
Gets an array of RemoteApp objects which contain a foreign key that references this object. If the $criteria is not null, it is used to always fetch the results from the database. Otherwise the results are fetched from the database the first time, then cached. Next time the same method is called without $criteria, the cached collection is returned. If this Customer is new, it will return an empty collection or the current collection; the criteria is ignored on a new object. @param Criteria $criteria optional Criteria object to narrow the query @param PropelPDO $con optional connection object @return PropelObjectCollection|RemoteApp[] List of RemoteApp objects @throws PropelException
[ "Gets", "an", "array", "of", "RemoteApp", "objects", "which", "contain", "a", "foreign", "key", "that", "references", "this", "object", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1708-L1751
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.setRemoteApps
public function setRemoteApps(PropelCollection $remoteApps, PropelPDO $con = null) { $remoteAppsToDelete = $this->getRemoteApps(new Criteria(), $con)->diff($remoteApps); $this->remoteAppsScheduledForDeletion = $remoteAppsToDelete; foreach ($remoteAppsToDelete as $remoteAppRemoved) { $remoteAppRemoved->setCustomer(null); } $this->collRemoteApps = null; foreach ($remoteApps as $remoteApp) { $this->addRemoteApp($remoteApp); } $this->collRemoteApps = $remoteApps; $this->collRemoteAppsPartial = false; return $this; }
php
public function setRemoteApps(PropelCollection $remoteApps, PropelPDO $con = null) { $remoteAppsToDelete = $this->getRemoteApps(new Criteria(), $con)->diff($remoteApps); $this->remoteAppsScheduledForDeletion = $remoteAppsToDelete; foreach ($remoteAppsToDelete as $remoteAppRemoved) { $remoteAppRemoved->setCustomer(null); } $this->collRemoteApps = null; foreach ($remoteApps as $remoteApp) { $this->addRemoteApp($remoteApp); } $this->collRemoteApps = $remoteApps; $this->collRemoteAppsPartial = false; return $this; }
[ "public", "function", "setRemoteApps", "(", "PropelCollection", "$", "remoteApps", ",", "PropelPDO", "$", "con", "=", "null", ")", "{", "$", "remoteAppsToDelete", "=", "$", "this", "->", "getRemoteApps", "(", "new", "Criteria", "(", ")", ",", "$", "con", ")", "->", "diff", "(", "$", "remoteApps", ")", ";", "$", "this", "->", "remoteAppsScheduledForDeletion", "=", "$", "remoteAppsToDelete", ";", "foreach", "(", "$", "remoteAppsToDelete", "as", "$", "remoteAppRemoved", ")", "{", "$", "remoteAppRemoved", "->", "setCustomer", "(", "null", ")", ";", "}", "$", "this", "->", "collRemoteApps", "=", "null", ";", "foreach", "(", "$", "remoteApps", "as", "$", "remoteApp", ")", "{", "$", "this", "->", "addRemoteApp", "(", "$", "remoteApp", ")", ";", "}", "$", "this", "->", "collRemoteApps", "=", "$", "remoteApps", ";", "$", "this", "->", "collRemoteAppsPartial", "=", "false", ";", "return", "$", "this", ";", "}" ]
Sets a collection of RemoteApp objects related by a one-to-many relationship to the current object. It will also schedule objects for deletion based on a diff between old objects (aka persisted) and new objects from the given Propel collection. @param PropelCollection $remoteApps A Propel collection. @param PropelPDO $con Optional connection object @return Customer The current object (for fluent API support)
[ "Sets", "a", "collection", "of", "RemoteApp", "objects", "related", "by", "a", "one", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", ".", "It", "will", "also", "schedule", "objects", "for", "deletion", "based", "on", "a", "diff", "between", "old", "objects", "(", "aka", "persisted", ")", "and", "new", "objects", "from", "the", "given", "Propel", "collection", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1763-L1783
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.countRemoteApps
public function countRemoteApps(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collRemoteAppsPartial && !$this->isNew(); if (null === $this->collRemoteApps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRemoteApps) { return 0; } if ($partial && !$criteria) { return count($this->getRemoteApps()); } $query = RemoteAppQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByCustomer($this) ->count($con); } return count($this->collRemoteApps); }
php
public function countRemoteApps(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collRemoteAppsPartial && !$this->isNew(); if (null === $this->collRemoteApps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRemoteApps) { return 0; } if ($partial && !$criteria) { return count($this->getRemoteApps()); } $query = RemoteAppQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByCustomer($this) ->count($con); } return count($this->collRemoteApps); }
[ "public", "function", "countRemoteApps", "(", "Criteria", "$", "criteria", "=", "null", ",", "$", "distinct", "=", "false", ",", "PropelPDO", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRemoteAppsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRemoteApps", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collRemoteApps", ")", "{", "return", "0", ";", "}", "if", "(", "$", "partial", "&&", "!", "$", "criteria", ")", "{", "return", "count", "(", "$", "this", "->", "getRemoteApps", "(", ")", ")", ";", "}", "$", "query", "=", "RemoteAppQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "if", "(", "$", "distinct", ")", "{", "$", "query", "->", "distinct", "(", ")", ";", "}", "return", "$", "query", "->", "filterByCustomer", "(", "$", "this", ")", "->", "count", "(", "$", "con", ")", ";", "}", "return", "count", "(", "$", "this", "->", "collRemoteApps", ")", ";", "}" ]
Returns the number of related RemoteApp objects. @param Criteria $criteria @param boolean $distinct @param PropelPDO $con @return int Count of related RemoteApp objects. @throws PropelException
[ "Returns", "the", "number", "of", "related", "RemoteApp", "objects", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1794-L1816
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.addRemoteApp
public function addRemoteApp(RemoteApp $l) { if ($this->collRemoteApps === null) { $this->initRemoteApps(); $this->collRemoteAppsPartial = true; } if (!in_array($l, $this->collRemoteApps->getArrayCopy(), true)) { // only add it if the **same** object is not already associated $this->doAddRemoteApp($l); if ($this->remoteAppsScheduledForDeletion and $this->remoteAppsScheduledForDeletion->contains($l)) { $this->remoteAppsScheduledForDeletion->remove($this->remoteAppsScheduledForDeletion->search($l)); } } return $this; }
php
public function addRemoteApp(RemoteApp $l) { if ($this->collRemoteApps === null) { $this->initRemoteApps(); $this->collRemoteAppsPartial = true; } if (!in_array($l, $this->collRemoteApps->getArrayCopy(), true)) { // only add it if the **same** object is not already associated $this->doAddRemoteApp($l); if ($this->remoteAppsScheduledForDeletion and $this->remoteAppsScheduledForDeletion->contains($l)) { $this->remoteAppsScheduledForDeletion->remove($this->remoteAppsScheduledForDeletion->search($l)); } } return $this; }
[ "public", "function", "addRemoteApp", "(", "RemoteApp", "$", "l", ")", "{", "if", "(", "$", "this", "->", "collRemoteApps", "===", "null", ")", "{", "$", "this", "->", "initRemoteApps", "(", ")", ";", "$", "this", "->", "collRemoteAppsPartial", "=", "true", ";", "}", "if", "(", "!", "in_array", "(", "$", "l", ",", "$", "this", "->", "collRemoteApps", "->", "getArrayCopy", "(", ")", ",", "true", ")", ")", "{", "// only add it if the **same** object is not already associated", "$", "this", "->", "doAddRemoteApp", "(", "$", "l", ")", ";", "if", "(", "$", "this", "->", "remoteAppsScheduledForDeletion", "and", "$", "this", "->", "remoteAppsScheduledForDeletion", "->", "contains", "(", "$", "l", ")", ")", "{", "$", "this", "->", "remoteAppsScheduledForDeletion", "->", "remove", "(", "$", "this", "->", "remoteAppsScheduledForDeletion", "->", "search", "(", "$", "l", ")", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Method called to associate a RemoteApp object to this object through the RemoteApp foreign key attribute. @param RemoteApp $l RemoteApp @return Customer The current object (for fluent API support)
[ "Method", "called", "to", "associate", "a", "RemoteApp", "object", "to", "this", "object", "through", "the", "RemoteApp", "foreign", "key", "attribute", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1825-L1841
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.initUserCustomerRelations
public function initUserCustomerRelations($overrideExisting = true) { if (null !== $this->collUserCustomerRelations && !$overrideExisting) { return; } $this->collUserCustomerRelations = new PropelObjectCollection(); $this->collUserCustomerRelations->setModel('UserCustomerRelation'); }
php
public function initUserCustomerRelations($overrideExisting = true) { if (null !== $this->collUserCustomerRelations && !$overrideExisting) { return; } $this->collUserCustomerRelations = new PropelObjectCollection(); $this->collUserCustomerRelations->setModel('UserCustomerRelation'); }
[ "public", "function", "initUserCustomerRelations", "(", "$", "overrideExisting", "=", "true", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "collUserCustomerRelations", "&&", "!", "$", "overrideExisting", ")", "{", "return", ";", "}", "$", "this", "->", "collUserCustomerRelations", "=", "new", "PropelObjectCollection", "(", ")", ";", "$", "this", "->", "collUserCustomerRelations", "->", "setModel", "(", "'UserCustomerRelation'", ")", ";", "}" ]
Initializes the collUserCustomerRelations collection. By default this just sets the collUserCustomerRelations collection to an empty array (like clearcollUserCustomerRelations()); however, you may wish to override this method in your stub class to provide setting appropriate to your application -- for example, setting the initial array to the values stored in database. @param boolean $overrideExisting If set to true, the method call initializes the collection even if it is not empty @return void
[ "Initializes", "the", "collUserCustomerRelations", "collection", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1910-L1917
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.setUserCustomerRelations
public function setUserCustomerRelations(PropelCollection $userCustomerRelations, PropelPDO $con = null) { $userCustomerRelationsToDelete = $this->getUserCustomerRelations(new Criteria(), $con)->diff($userCustomerRelations); $this->userCustomerRelationsScheduledForDeletion = $userCustomerRelationsToDelete; foreach ($userCustomerRelationsToDelete as $userCustomerRelationRemoved) { $userCustomerRelationRemoved->setCustomer(null); } $this->collUserCustomerRelations = null; foreach ($userCustomerRelations as $userCustomerRelation) { $this->addUserCustomerRelation($userCustomerRelation); } $this->collUserCustomerRelations = $userCustomerRelations; $this->collUserCustomerRelationsPartial = false; return $this; }
php
public function setUserCustomerRelations(PropelCollection $userCustomerRelations, PropelPDO $con = null) { $userCustomerRelationsToDelete = $this->getUserCustomerRelations(new Criteria(), $con)->diff($userCustomerRelations); $this->userCustomerRelationsScheduledForDeletion = $userCustomerRelationsToDelete; foreach ($userCustomerRelationsToDelete as $userCustomerRelationRemoved) { $userCustomerRelationRemoved->setCustomer(null); } $this->collUserCustomerRelations = null; foreach ($userCustomerRelations as $userCustomerRelation) { $this->addUserCustomerRelation($userCustomerRelation); } $this->collUserCustomerRelations = $userCustomerRelations; $this->collUserCustomerRelationsPartial = false; return $this; }
[ "public", "function", "setUserCustomerRelations", "(", "PropelCollection", "$", "userCustomerRelations", ",", "PropelPDO", "$", "con", "=", "null", ")", "{", "$", "userCustomerRelationsToDelete", "=", "$", "this", "->", "getUserCustomerRelations", "(", "new", "Criteria", "(", ")", ",", "$", "con", ")", "->", "diff", "(", "$", "userCustomerRelations", ")", ";", "$", "this", "->", "userCustomerRelationsScheduledForDeletion", "=", "$", "userCustomerRelationsToDelete", ";", "foreach", "(", "$", "userCustomerRelationsToDelete", "as", "$", "userCustomerRelationRemoved", ")", "{", "$", "userCustomerRelationRemoved", "->", "setCustomer", "(", "null", ")", ";", "}", "$", "this", "->", "collUserCustomerRelations", "=", "null", ";", "foreach", "(", "$", "userCustomerRelations", "as", "$", "userCustomerRelation", ")", "{", "$", "this", "->", "addUserCustomerRelation", "(", "$", "userCustomerRelation", ")", ";", "}", "$", "this", "->", "collUserCustomerRelations", "=", "$", "userCustomerRelations", ";", "$", "this", "->", "collUserCustomerRelationsPartial", "=", "false", ";", "return", "$", "this", ";", "}" ]
Sets a collection of UserCustomerRelation objects related by a one-to-many relationship to the current object. It will also schedule objects for deletion based on a diff between old objects (aka persisted) and new objects from the given Propel collection. @param PropelCollection $userCustomerRelations A Propel collection. @param PropelPDO $con Optional connection object @return Customer The current object (for fluent API support)
[ "Sets", "a", "collection", "of", "UserCustomerRelation", "objects", "related", "by", "a", "one", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", ".", "It", "will", "also", "schedule", "objects", "for", "deletion", "based", "on", "a", "diff", "between", "old", "objects", "(", "aka", "persisted", ")", "and", "new", "objects", "from", "the", "given", "Propel", "collection", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L1988-L2008
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.addUserCustomerRelation
public function addUserCustomerRelation(UserCustomerRelation $l) { if ($this->collUserCustomerRelations === null) { $this->initUserCustomerRelations(); $this->collUserCustomerRelationsPartial = true; } if (!in_array($l, $this->collUserCustomerRelations->getArrayCopy(), true)) { // only add it if the **same** object is not already associated $this->doAddUserCustomerRelation($l); if ($this->userCustomerRelationsScheduledForDeletion and $this->userCustomerRelationsScheduledForDeletion->contains($l)) { $this->userCustomerRelationsScheduledForDeletion->remove($this->userCustomerRelationsScheduledForDeletion->search($l)); } } return $this; }
php
public function addUserCustomerRelation(UserCustomerRelation $l) { if ($this->collUserCustomerRelations === null) { $this->initUserCustomerRelations(); $this->collUserCustomerRelationsPartial = true; } if (!in_array($l, $this->collUserCustomerRelations->getArrayCopy(), true)) { // only add it if the **same** object is not already associated $this->doAddUserCustomerRelation($l); if ($this->userCustomerRelationsScheduledForDeletion and $this->userCustomerRelationsScheduledForDeletion->contains($l)) { $this->userCustomerRelationsScheduledForDeletion->remove($this->userCustomerRelationsScheduledForDeletion->search($l)); } } return $this; }
[ "public", "function", "addUserCustomerRelation", "(", "UserCustomerRelation", "$", "l", ")", "{", "if", "(", "$", "this", "->", "collUserCustomerRelations", "===", "null", ")", "{", "$", "this", "->", "initUserCustomerRelations", "(", ")", ";", "$", "this", "->", "collUserCustomerRelationsPartial", "=", "true", ";", "}", "if", "(", "!", "in_array", "(", "$", "l", ",", "$", "this", "->", "collUserCustomerRelations", "->", "getArrayCopy", "(", ")", ",", "true", ")", ")", "{", "// only add it if the **same** object is not already associated", "$", "this", "->", "doAddUserCustomerRelation", "(", "$", "l", ")", ";", "if", "(", "$", "this", "->", "userCustomerRelationsScheduledForDeletion", "and", "$", "this", "->", "userCustomerRelationsScheduledForDeletion", "->", "contains", "(", "$", "l", ")", ")", "{", "$", "this", "->", "userCustomerRelationsScheduledForDeletion", "->", "remove", "(", "$", "this", "->", "userCustomerRelationsScheduledForDeletion", "->", "search", "(", "$", "l", ")", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Method called to associate a UserCustomerRelation object to this object through the UserCustomerRelation foreign key attribute. @param UserCustomerRelation $l UserCustomerRelation @return Customer The current object (for fluent API support)
[ "Method", "called", "to", "associate", "a", "UserCustomerRelation", "object", "to", "this", "object", "through", "the", "UserCustomerRelation", "foreign", "key", "attribute", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L2050-L2066
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.clear
public function clear() { $this->id = null; $this->name = null; $this->street = null; $this->zip = null; $this->city = null; $this->country_id = null; $this->phone = null; $this->fax = null; $this->email = null; $this->legalform = null; $this->logo = null; $this->created = null; $this->notes = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->alreadyInClearAllReferencesDeep = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
php
public function clear() { $this->id = null; $this->name = null; $this->street = null; $this->zip = null; $this->city = null; $this->country_id = null; $this->phone = null; $this->fax = null; $this->email = null; $this->legalform = null; $this->logo = null; $this->created = null; $this->notes = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->alreadyInClearAllReferencesDeep = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
[ "public", "function", "clear", "(", ")", "{", "$", "this", "->", "id", "=", "null", ";", "$", "this", "->", "name", "=", "null", ";", "$", "this", "->", "street", "=", "null", ";", "$", "this", "->", "zip", "=", "null", ";", "$", "this", "->", "city", "=", "null", ";", "$", "this", "->", "country_id", "=", "null", ";", "$", "this", "->", "phone", "=", "null", ";", "$", "this", "->", "fax", "=", "null", ";", "$", "this", "->", "email", "=", "null", ";", "$", "this", "->", "legalform", "=", "null", ";", "$", "this", "->", "logo", "=", "null", ";", "$", "this", "->", "created", "=", "null", ";", "$", "this", "->", "notes", "=", "null", ";", "$", "this", "->", "alreadyInSave", "=", "false", ";", "$", "this", "->", "alreadyInValidation", "=", "false", ";", "$", "this", "->", "alreadyInClearAllReferencesDeep", "=", "false", ";", "$", "this", "->", "clearAllReferences", "(", ")", ";", "$", "this", "->", "resetModified", "(", ")", ";", "$", "this", "->", "setNew", "(", "true", ")", ";", "$", "this", "->", "setDeleted", "(", "false", ")", ";", "}" ]
Clears the current object and sets all attributes to their default values
[ "Clears", "the", "current", "object", "and", "sets", "all", "attributes", "to", "their", "default", "values" ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L2124-L2146
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseCustomer.php
BaseCustomer.clearAllReferences
public function clearAllReferences($deep = false) { if ($deep && !$this->alreadyInClearAllReferencesDeep) { $this->alreadyInClearAllReferencesDeep = true; if ($this->collRemoteApps) { foreach ($this->collRemoteApps as $o) { $o->clearAllReferences($deep); } } if ($this->collUserCustomerRelations) { foreach ($this->collUserCustomerRelations as $o) { $o->clearAllReferences($deep); } } if ($this->aCountry instanceof Persistent) { $this->aCountry->clearAllReferences($deep); } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) if ($this->collRemoteApps instanceof PropelCollection) { $this->collRemoteApps->clearIterator(); } $this->collRemoteApps = null; if ($this->collUserCustomerRelations instanceof PropelCollection) { $this->collUserCustomerRelations->clearIterator(); } $this->collUserCustomerRelations = null; $this->aCountry = null; }
php
public function clearAllReferences($deep = false) { if ($deep && !$this->alreadyInClearAllReferencesDeep) { $this->alreadyInClearAllReferencesDeep = true; if ($this->collRemoteApps) { foreach ($this->collRemoteApps as $o) { $o->clearAllReferences($deep); } } if ($this->collUserCustomerRelations) { foreach ($this->collUserCustomerRelations as $o) { $o->clearAllReferences($deep); } } if ($this->aCountry instanceof Persistent) { $this->aCountry->clearAllReferences($deep); } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) if ($this->collRemoteApps instanceof PropelCollection) { $this->collRemoteApps->clearIterator(); } $this->collRemoteApps = null; if ($this->collUserCustomerRelations instanceof PropelCollection) { $this->collUserCustomerRelations->clearIterator(); } $this->collUserCustomerRelations = null; $this->aCountry = null; }
[ "public", "function", "clearAllReferences", "(", "$", "deep", "=", "false", ")", "{", "if", "(", "$", "deep", "&&", "!", "$", "this", "->", "alreadyInClearAllReferencesDeep", ")", "{", "$", "this", "->", "alreadyInClearAllReferencesDeep", "=", "true", ";", "if", "(", "$", "this", "->", "collRemoteApps", ")", "{", "foreach", "(", "$", "this", "->", "collRemoteApps", "as", "$", "o", ")", "{", "$", "o", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "}", "if", "(", "$", "this", "->", "collUserCustomerRelations", ")", "{", "foreach", "(", "$", "this", "->", "collUserCustomerRelations", "as", "$", "o", ")", "{", "$", "o", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "}", "if", "(", "$", "this", "->", "aCountry", "instanceof", "Persistent", ")", "{", "$", "this", "->", "aCountry", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "$", "this", "->", "alreadyInClearAllReferencesDeep", "=", "false", ";", "}", "// if ($deep)", "if", "(", "$", "this", "->", "collRemoteApps", "instanceof", "PropelCollection", ")", "{", "$", "this", "->", "collRemoteApps", "->", "clearIterator", "(", ")", ";", "}", "$", "this", "->", "collRemoteApps", "=", "null", ";", "if", "(", "$", "this", "->", "collUserCustomerRelations", "instanceof", "PropelCollection", ")", "{", "$", "this", "->", "collUserCustomerRelations", "->", "clearIterator", "(", ")", ";", "}", "$", "this", "->", "collUserCustomerRelations", "=", "null", ";", "$", "this", "->", "aCountry", "=", "null", ";", "}" ]
Resets all references to other model objects or collections of model objects. This method is a user-space workaround for PHP's inability to garbage collect objects with circular references (even in PHP 5.3). This is currently necessary when using Propel in certain daemon or large-volume/high-memory operations. @param boolean $deep Whether to also clear the references on all referrer objects.
[ "Resets", "all", "references", "to", "other", "model", "objects", "or", "collections", "of", "model", "objects", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCustomer.php#L2157-L2187
comodojo/qotd
src/Qotd.php
Qotd.getQuote
public function getQuote() { if ( is_null($this->quotes) ) return $this->no_quotes_message; return $this->quotes[rand(1,sizeof($this->quotes)-1)]; }
php
public function getQuote() { if ( is_null($this->quotes) ) return $this->no_quotes_message; return $this->quotes[rand(1,sizeof($this->quotes)-1)]; }
[ "public", "function", "getQuote", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "quotes", ")", ")", "return", "$", "this", "->", "no_quotes_message", ";", "return", "$", "this", "->", "quotes", "[", "rand", "(", "1", ",", "sizeof", "(", "$", "this", "->", "quotes", ")", "-", "1", ")", "]", ";", "}" ]
Get single quote @return string
[ "Get", "single", "quote" ]
train
https://github.com/comodojo/qotd/blob/7ef890491e8d3d5d7ba05116f4277708f788ad60/src/Qotd.php#L74-L80
comodojo/qotd
src/Qotd.php
Qotd.getQuotesAsStore
public function getQuotesAsStore() { if ( is_null($this->quotes) ) return array(array('id'=>0, 'quote'=>$this->no_quotes_message)); $return = array(); foreach($this->quotes as $id=>$quote) array_push($return, array('id'=>$id, 'quote'=>$quote)); return $return; }
php
public function getQuotesAsStore() { if ( is_null($this->quotes) ) return array(array('id'=>0, 'quote'=>$this->no_quotes_message)); $return = array(); foreach($this->quotes as $id=>$quote) array_push($return, array('id'=>$id, 'quote'=>$quote)); return $return; }
[ "public", "function", "getQuotesAsStore", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "quotes", ")", ")", "return", "array", "(", "array", "(", "'id'", "=>", "0", ",", "'quote'", "=>", "$", "this", "->", "no_quotes_message", ")", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "quotes", "as", "$", "id", "=>", "$", "quote", ")", "array_push", "(", "$", "return", ",", "array", "(", "'id'", "=>", "$", "id", ",", "'quote'", "=>", "$", "quote", ")", ")", ";", "return", "$", "return", ";", "}" ]
Get all quotes as a store @return array
[ "Get", "all", "quotes", "as", "a", "store" ]
train
https://github.com/comodojo/qotd/blob/7ef890491e8d3d5d7ba05116f4277708f788ad60/src/Qotd.php#L87-L97
anime-db/world-art-filler-bundle
src/Service/Search.php
Search.search
public function search(array $data) { $name = iconv('utf-8', 'cp1251', $data['name']); $url = str_replace('#NAME#', urlencode($name), self::SEARH_URL); $url = str_replace('#SECTOR#', (isset($data['type']) ? $data['type'] : self::DEFAULT_SECTOR), $url); // get list from xpath $dom = $this->browser->getDom($url); $xpath = new \DOMXPath($dom); // if for request is found only one result is produced forwarding $refresh = $xpath->query('//meta[@http-equiv="Refresh"]/@content'); if ($refresh->length) { list(, $url) = explode('url=', $refresh->item(0)->nodeValue, 2); // add http if need if ($url[0] == '/') { $url = $this->browser->getHost().$url; } $name = iconv('cp1251', 'utf-8', $name); if (!preg_match('/id=(?<id>\d+)/', $url, $mat) || !($type = $this->filler->getItemType($url))) { throw new NotFoundHttpException('Incorrect URL for found item'); } return [ new ItemSearch( $name, $this->getLinkForFill($url), $this->filler->getCoverUrl($mat['id'], $type), '' ), ]; } $rows = $xpath->query(self::XPATH_FOR_LIST); $list = []; foreach ($rows as $el) { $link = $xpath->query('a', $el); // has link on source if ($link->length && ($href = $link->item(0)->getAttribute('href')) && ($name = $link->item(0)->nodeValue) && preg_match('/id=(?<id>\d+)/', $href, $mat) && ($type = $this->filler->getItemType($href)) ) { $list[] = new ItemSearch( str_replace(["\r\n", "\n"], ' ', $name), $this->getLinkForFill($this->browser->getHost().'/'.$href), $this->filler->getCoverUrl($mat['id'], $type), trim(str_replace($name, '', $el->nodeValue)), $this->browser->getHost().'/'.$href ); } } return $list; }
php
public function search(array $data) { $name = iconv('utf-8', 'cp1251', $data['name']); $url = str_replace('#NAME#', urlencode($name), self::SEARH_URL); $url = str_replace('#SECTOR#', (isset($data['type']) ? $data['type'] : self::DEFAULT_SECTOR), $url); // get list from xpath $dom = $this->browser->getDom($url); $xpath = new \DOMXPath($dom); // if for request is found only one result is produced forwarding $refresh = $xpath->query('//meta[@http-equiv="Refresh"]/@content'); if ($refresh->length) { list(, $url) = explode('url=', $refresh->item(0)->nodeValue, 2); // add http if need if ($url[0] == '/') { $url = $this->browser->getHost().$url; } $name = iconv('cp1251', 'utf-8', $name); if (!preg_match('/id=(?<id>\d+)/', $url, $mat) || !($type = $this->filler->getItemType($url))) { throw new NotFoundHttpException('Incorrect URL for found item'); } return [ new ItemSearch( $name, $this->getLinkForFill($url), $this->filler->getCoverUrl($mat['id'], $type), '' ), ]; } $rows = $xpath->query(self::XPATH_FOR_LIST); $list = []; foreach ($rows as $el) { $link = $xpath->query('a', $el); // has link on source if ($link->length && ($href = $link->item(0)->getAttribute('href')) && ($name = $link->item(0)->nodeValue) && preg_match('/id=(?<id>\d+)/', $href, $mat) && ($type = $this->filler->getItemType($href)) ) { $list[] = new ItemSearch( str_replace(["\r\n", "\n"], ' ', $name), $this->getLinkForFill($this->browser->getHost().'/'.$href), $this->filler->getCoverUrl($mat['id'], $type), trim(str_replace($name, '', $el->nodeValue)), $this->browser->getHost().'/'.$href ); } } return $list; }
[ "public", "function", "search", "(", "array", "$", "data", ")", "{", "$", "name", "=", "iconv", "(", "'utf-8'", ",", "'cp1251'", ",", "$", "data", "[", "'name'", "]", ")", ";", "$", "url", "=", "str_replace", "(", "'#NAME#'", ",", "urlencode", "(", "$", "name", ")", ",", "self", "::", "SEARH_URL", ")", ";", "$", "url", "=", "str_replace", "(", "'#SECTOR#'", ",", "(", "isset", "(", "$", "data", "[", "'type'", "]", ")", "?", "$", "data", "[", "'type'", "]", ":", "self", "::", "DEFAULT_SECTOR", ")", ",", "$", "url", ")", ";", "// get list from xpath", "$", "dom", "=", "$", "this", "->", "browser", "->", "getDom", "(", "$", "url", ")", ";", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "dom", ")", ";", "// if for request is found only one result is produced forwarding", "$", "refresh", "=", "$", "xpath", "->", "query", "(", "'//meta[@http-equiv=\"Refresh\"]/@content'", ")", ";", "if", "(", "$", "refresh", "->", "length", ")", "{", "list", "(", ",", "$", "url", ")", "=", "explode", "(", "'url='", ",", "$", "refresh", "->", "item", "(", "0", ")", "->", "nodeValue", ",", "2", ")", ";", "// add http if need", "if", "(", "$", "url", "[", "0", "]", "==", "'/'", ")", "{", "$", "url", "=", "$", "this", "->", "browser", "->", "getHost", "(", ")", ".", "$", "url", ";", "}", "$", "name", "=", "iconv", "(", "'cp1251'", ",", "'utf-8'", ",", "$", "name", ")", ";", "if", "(", "!", "preg_match", "(", "'/id=(?<id>\\d+)/'", ",", "$", "url", ",", "$", "mat", ")", "||", "!", "(", "$", "type", "=", "$", "this", "->", "filler", "->", "getItemType", "(", "$", "url", ")", ")", ")", "{", "throw", "new", "NotFoundHttpException", "(", "'Incorrect URL for found item'", ")", ";", "}", "return", "[", "new", "ItemSearch", "(", "$", "name", ",", "$", "this", "->", "getLinkForFill", "(", "$", "url", ")", ",", "$", "this", "->", "filler", "->", "getCoverUrl", "(", "$", "mat", "[", "'id'", "]", ",", "$", "type", ")", ",", "''", ")", ",", "]", ";", "}", "$", "rows", "=", "$", "xpath", "->", "query", "(", "self", "::", "XPATH_FOR_LIST", ")", ";", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "rows", "as", "$", "el", ")", "{", "$", "link", "=", "$", "xpath", "->", "query", "(", "'a'", ",", "$", "el", ")", ";", "// has link on source", "if", "(", "$", "link", "->", "length", "&&", "(", "$", "href", "=", "$", "link", "->", "item", "(", "0", ")", "->", "getAttribute", "(", "'href'", ")", ")", "&&", "(", "$", "name", "=", "$", "link", "->", "item", "(", "0", ")", "->", "nodeValue", ")", "&&", "preg_match", "(", "'/id=(?<id>\\d+)/'", ",", "$", "href", ",", "$", "mat", ")", "&&", "(", "$", "type", "=", "$", "this", "->", "filler", "->", "getItemType", "(", "$", "href", ")", ")", ")", "{", "$", "list", "[", "]", "=", "new", "ItemSearch", "(", "str_replace", "(", "[", "\"\\r\\n\"", ",", "\"\\n\"", "]", ",", "' '", ",", "$", "name", ")", ",", "$", "this", "->", "getLinkForFill", "(", "$", "this", "->", "browser", "->", "getHost", "(", ")", ".", "'/'", ".", "$", "href", ")", ",", "$", "this", "->", "filler", "->", "getCoverUrl", "(", "$", "mat", "[", "'id'", "]", ",", "$", "type", ")", ",", "trim", "(", "str_replace", "(", "$", "name", ",", "''", ",", "$", "el", "->", "nodeValue", ")", ")", ",", "$", "this", "->", "browser", "->", "getHost", "(", ")", ".", "'/'", ".", "$", "href", ")", ";", "}", "}", "return", "$", "list", ";", "}" ]
Search source by name. Return structure <code> [ \AnimeDb\Bundle\CatalogBundle\Plugin\Fill\Search\Item ] </code> @param array $data @return array
[ "Search", "source", "by", "name", "." ]
train
https://github.com/anime-db/world-art-filler-bundle/blob/f2ef4dbd12fe39c18183d1628b5049b8d381e42c/src/Service/Search.php#L119-L174
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.save
public function save(SearchCriteriaInterface $searchCriteria, array $data) : bool { // before save event $eventBeforeName = 'beforeSave'; if ($this->hasObserver($eventBeforeName)) { $eventBefore = $this->eventBuilder ->setName($eventBeforeName) ->setSearchCriteria($searchCriteria) ->setArgumentList([$data]) ->build(); $this->notify($eventBefore); } // execute operation $result = $this->cacheManager->save($searchCriteria, $data); // after save event $eventAfterName = 'afterSave'; if ($this->hasObserver($eventAfterName)) { $eventAfter = $this->eventBuilder ->setName($eventAfterName) ->setSearchCriteria($searchCriteria) ->setArgumentList([$data]) ->setOperationResult($result) ->build(); $this->notify($eventAfter); } return $result; }
php
public function save(SearchCriteriaInterface $searchCriteria, array $data) : bool { // before save event $eventBeforeName = 'beforeSave'; if ($this->hasObserver($eventBeforeName)) { $eventBefore = $this->eventBuilder ->setName($eventBeforeName) ->setSearchCriteria($searchCriteria) ->setArgumentList([$data]) ->build(); $this->notify($eventBefore); } // execute operation $result = $this->cacheManager->save($searchCriteria, $data); // after save event $eventAfterName = 'afterSave'; if ($this->hasObserver($eventAfterName)) { $eventAfter = $this->eventBuilder ->setName($eventAfterName) ->setSearchCriteria($searchCriteria) ->setArgumentList([$data]) ->setOperationResult($result) ->build(); $this->notify($eventAfter); } return $result; }
[ "public", "function", "save", "(", "SearchCriteriaInterface", "$", "searchCriteria", ",", "array", "$", "data", ")", ":", "bool", "{", "// before save event", "$", "eventBeforeName", "=", "'beforeSave'", ";", "if", "(", "$", "this", "->", "hasObserver", "(", "$", "eventBeforeName", ")", ")", "{", "$", "eventBefore", "=", "$", "this", "->", "eventBuilder", "->", "setName", "(", "$", "eventBeforeName", ")", "->", "setSearchCriteria", "(", "$", "searchCriteria", ")", "->", "setArgumentList", "(", "[", "$", "data", "]", ")", "->", "build", "(", ")", ";", "$", "this", "->", "notify", "(", "$", "eventBefore", ")", ";", "}", "// execute operation", "$", "result", "=", "$", "this", "->", "cacheManager", "->", "save", "(", "$", "searchCriteria", ",", "$", "data", ")", ";", "// after save event", "$", "eventAfterName", "=", "'afterSave'", ";", "if", "(", "$", "this", "->", "hasObserver", "(", "$", "eventAfterName", ")", ")", "{", "$", "eventAfter", "=", "$", "this", "->", "eventBuilder", "->", "setName", "(", "$", "eventAfterName", ")", "->", "setSearchCriteria", "(", "$", "searchCriteria", ")", "->", "setArgumentList", "(", "[", "$", "data", "]", ")", "->", "setOperationResult", "(", "$", "result", ")", "->", "build", "(", ")", ";", "$", "this", "->", "notify", "(", "$", "eventAfter", ")", ";", "}", "return", "$", "result", ";", "}" ]
{@inheritdoc} Events: beforeSave, afterSave
[ "{", "@inheritdoc", "}" ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L52-L83
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.attach
public function attach(string $name, ObserverInterface $observer) { $observerList = $this->getObserverList($name); $observerList->attach($observer); }
php
public function attach(string $name, ObserverInterface $observer) { $observerList = $this->getObserverList($name); $observerList->attach($observer); }
[ "public", "function", "attach", "(", "string", "$", "name", ",", "ObserverInterface", "$", "observer", ")", "{", "$", "observerList", "=", "$", "this", "->", "getObserverList", "(", "$", "name", ")", ";", "$", "observerList", "->", "attach", "(", "$", "observer", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L160-L164
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.detach
public function detach(string $name, ObserverInterface $observer) { $observerList = $this->getObserverList($name); $observerList->detach($observer); }
php
public function detach(string $name, ObserverInterface $observer) { $observerList = $this->getObserverList($name); $observerList->detach($observer); }
[ "public", "function", "detach", "(", "string", "$", "name", ",", "ObserverInterface", "$", "observer", ")", "{", "$", "observerList", "=", "$", "this", "->", "getObserverList", "(", "$", "name", ")", ";", "$", "observerList", "->", "detach", "(", "$", "observer", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L169-L173
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.notify
public function notify(EventInterface $event) { $observerList = $this->getObserverList($event->getName()); /** @var \Picamator\CacheManager\Spi\ObserverInterface $item */ foreach ($observerList as $item) { $item->update($this, $event); } }
php
public function notify(EventInterface $event) { $observerList = $this->getObserverList($event->getName()); /** @var \Picamator\CacheManager\Spi\ObserverInterface $item */ foreach ($observerList as $item) { $item->update($this, $event); } }
[ "public", "function", "notify", "(", "EventInterface", "$", "event", ")", "{", "$", "observerList", "=", "$", "this", "->", "getObserverList", "(", "$", "event", "->", "getName", "(", ")", ")", ";", "/** @var \\Picamator\\CacheManager\\Spi\\ObserverInterface $item */", "foreach", "(", "$", "observerList", "as", "$", "item", ")", "{", "$", "item", "->", "update", "(", "$", "this", ",", "$", "event", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L178-L185
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.getObserverList
private function getObserverList(string $name) : \SplObjectStorage { if (empty($this->observerContainer[$name])) { $this->observerContainer[$name] = new \SplObjectStorage(); } return $this->observerContainer[$name]; }
php
private function getObserverList(string $name) : \SplObjectStorage { if (empty($this->observerContainer[$name])) { $this->observerContainer[$name] = new \SplObjectStorage(); } return $this->observerContainer[$name]; }
[ "private", "function", "getObserverList", "(", "string", "$", "name", ")", ":", "\\", "SplObjectStorage", "{", "if", "(", "empty", "(", "$", "this", "->", "observerContainer", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "observerContainer", "[", "$", "name", "]", "=", "new", "\\", "SplObjectStorage", "(", ")", ";", "}", "return", "$", "this", "->", "observerContainer", "[", "$", "name", "]", ";", "}" ]
Retrieve observer list. @param string $name @return \SplObjectStorage
[ "Retrieve", "observer", "list", "." ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L194-L201
picamator/CacheManager
src/CacheManagerSubject.php
CacheManagerSubject.hasObserver
private function hasObserver(string $name) : bool { return !empty($this->observerContainer[$name]) && $this->observerContainer[$name]->count(); }
php
private function hasObserver(string $name) : bool { return !empty($this->observerContainer[$name]) && $this->observerContainer[$name]->count(); }
[ "private", "function", "hasObserver", "(", "string", "$", "name", ")", ":", "bool", "{", "return", "!", "empty", "(", "$", "this", "->", "observerContainer", "[", "$", "name", "]", ")", "&&", "$", "this", "->", "observerContainer", "[", "$", "name", "]", "->", "count", "(", ")", ";", "}" ]
Check whatever observer container has at least one observer. @param string $name @return bool _true_ observer container has at least one observer, _false_ otherwise
[ "Check", "whatever", "observer", "container", "has", "at", "least", "one", "observer", "." ]
train
https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/CacheManagerSubject.php#L210-L213
joseph-walker/vector
src/Lib/Math.php
Math.__sum
protected static function __sum($a) { return array_reduce($a, function ($carry, $item) use ($a) { $carry += $item; return $carry; }, 0); }
php
protected static function __sum($a) { return array_reduce($a, function ($carry, $item) use ($a) { $carry += $item; return $carry; }, 0); }
[ "protected", "static", "function", "__sum", "(", "$", "a", ")", "{", "return", "array_reduce", "(", "$", "a", ",", "function", "(", "$", "carry", ",", "$", "item", ")", "use", "(", "$", "a", ")", "{", "$", "carry", "+=", "$", "item", ";", "return", "$", "carry", ";", "}", ",", "0", ")", ";", "}" ]
Array Sum Add all the numbers of a list together and return their sum. If the given list is empty, returns 0. @example Math::sum([1, 2, 3]); // 6 @example Math::sum([]); // 0 @type Number a => [a] -> a @param array $a List of numbers to add @return number Sum of all the elements of the list
[ "Array", "Sum" ]
train
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Lib/Math.php#L63-L69
joseph-walker/vector
src/Lib/Math.php
Math.__product
protected static function __product($a) { return empty($a) ? 0 : array_reduce($a, function ($carry, $item) use ($a) { $carry *= $item; return $carry; }, 1); }
php
protected static function __product($a) { return empty($a) ? 0 : array_reduce($a, function ($carry, $item) use ($a) { $carry *= $item; return $carry; }, 1); }
[ "protected", "static", "function", "__product", "(", "$", "a", ")", "{", "return", "empty", "(", "$", "a", ")", "?", "0", ":", "array_reduce", "(", "$", "a", ",", "function", "(", "$", "carry", ",", "$", "item", ")", "use", "(", "$", "a", ")", "{", "$", "carry", "*=", "$", "item", ";", "return", "$", "carry", ";", "}", ",", "1", ")", ";", "}" ]
Array Product Returns the product of a list of numbers, i.e. the result of multiplying every element of a list together. Returns 1 for an empty list. @example Math::product([2, 2, 3]); // 12 @example Math::product([]); // 1 @type Number a => [a] -> a @param array $a List of values to multiply @return mixed Product of every value in the list
[ "Array", "Product" ]
train
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Lib/Math.php#L153-L161
joseph-walker/vector
src/Lib/Math.php
Math.__range
protected static function __range($step, $first, $last) { return ($step + $first >= $last) ? [$first] : range($first, $last, $step); }
php
protected static function __range($step, $first, $last) { return ($step + $first >= $last) ? [$first] : range($first, $last, $step); }
[ "protected", "static", "function", "__range", "(", "$", "step", ",", "$", "first", ",", "$", "last", ")", "{", "return", "(", "$", "step", "+", "$", "first", ">=", "$", "last", ")", "?", "[", "$", "first", "]", ":", "range", "(", "$", "first", ",", "$", "last", ",", "$", "step", ")", ";", "}" ]
Number Range Given two values m and n, return all values between m and n in an array, inclusive, with a step size of $step. The list of numbers will start at the first value and approach the second value. @example Math::range(1, 1, 5); // [1, 2, 3, 4, 5] @example Math::range(2, 0, -3); // [0, -2] @example Math::range(0, 0, 0); // [0] @example Math::range(0.1, 0, 0.5); // [0, 0.1, 0.2, 0.3, 0.4, 0.5] @type Number a => a -> a -> a @param number $step The step sizes to take when building the range @param number $first First value in the list @param number $last Last value in the list @return array All the numbers between the first and last argument
[ "Number", "Range" ]
train
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Lib/Math.php#L236-L241
CakeCMS/Core
src/Toolbar/ToolbarItemAction.php
ToolbarItemAction.fetchItem
public function fetchItem() { list ($source, $title, $action, $options) = func_get_args(); return $this->_view->Form->button($title, Hash::merge([ 'icon' => 'trash', 'data-action' => $action, 'button' => 'red lighten-2', 'class' => 'jsProcessDelete', ], (array) $options)); }
php
public function fetchItem() { list ($source, $title, $action, $options) = func_get_args(); return $this->_view->Form->button($title, Hash::merge([ 'icon' => 'trash', 'data-action' => $action, 'button' => 'red lighten-2', 'class' => 'jsProcessDelete', ], (array) $options)); }
[ "public", "function", "fetchItem", "(", ")", "{", "list", "(", "$", "source", ",", "$", "title", ",", "$", "action", ",", "$", "options", ")", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "_view", "->", "Form", "->", "button", "(", "$", "title", ",", "Hash", "::", "merge", "(", "[", "'icon'", "=>", "'trash'", ",", "'data-action'", "=>", "$", "action", ",", "'button'", "=>", "'red lighten-2'", ",", "'class'", "=>", "'jsProcessDelete'", ",", "]", ",", "(", "array", ")", "$", "options", ")", ")", ";", "}" ]
Fetch button id. @return string @SuppressWarnings("unused")
[ "Fetch", "button", "id", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Toolbar/ToolbarItemAction.php#L34-L44
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.avg
public function avg($callback = null): ?float { $sum = 0; $count = 0; foreach ($this->generator as $key => $item) { if ($callback) { $item = $this->accessKey($item, $callback, $key); } $sum += $item; $count++; } // Avoid division by 0 if (!$count) { return null; } return $sum / $count; }
php
public function avg($callback = null): ?float { $sum = 0; $count = 0; foreach ($this->generator as $key => $item) { if ($callback) { $item = $this->accessKey($item, $callback, $key); } $sum += $item; $count++; } // Avoid division by 0 if (!$count) { return null; } return $sum / $count; }
[ "public", "function", "avg", "(", "$", "callback", "=", "null", ")", ":", "?", "float", "{", "$", "sum", "=", "0", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "generator", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "callback", ")", "{", "$", "item", "=", "$", "this", "->", "accessKey", "(", "$", "item", ",", "$", "callback", ",", "$", "key", ")", ";", "}", "$", "sum", "+=", "$", "item", ";", "$", "count", "++", ";", "}", "// Avoid division by 0", "if", "(", "!", "$", "count", ")", "{", "return", "null", ";", "}", "return", "$", "sum", "/", "$", "count", ";", "}" ]
Get the average value of a given key. @param callable|string|null $callback @return mixed @throws \InvalidArgumentException
[ "Get", "the", "average", "value", "of", "a", "given", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L69-L88
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.median
public function median($key = null): ?float { $count = 0; $set = []; foreach ($this->generator as $givenKey => $item) { if ($key) { $item = $this->accessKey($item, $key, $givenKey); } $set[] = $item; $count++; } // Handle empty list if ($count === 0) { return null; } // Sort the full set sort($set); // If the count is divisible by 2, we'll need to get the average of the two if ($count && !($count % 2)) { $id = floor($count / 2) - 1; return ($set[(string)$id] + $set[(string)($id + 1)]) / 2; } return $set[$count / 2]; }
php
public function median($key = null): ?float { $count = 0; $set = []; foreach ($this->generator as $givenKey => $item) { if ($key) { $item = $this->accessKey($item, $key, $givenKey); } $set[] = $item; $count++; } // Handle empty list if ($count === 0) { return null; } // Sort the full set sort($set); // If the count is divisible by 2, we'll need to get the average of the two if ($count && !($count % 2)) { $id = floor($count / 2) - 1; return ($set[(string)$id] + $set[(string)($id + 1)]) / 2; } return $set[$count / 2]; }
[ "public", "function", "median", "(", "$", "key", "=", "null", ")", ":", "?", "float", "{", "$", "count", "=", "0", ";", "$", "set", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "generator", "as", "$", "givenKey", "=>", "$", "item", ")", "{", "if", "(", "$", "key", ")", "{", "$", "item", "=", "$", "this", "->", "accessKey", "(", "$", "item", ",", "$", "key", ",", "$", "givenKey", ")", ";", "}", "$", "set", "[", "]", "=", "$", "item", ";", "$", "count", "++", ";", "}", "// Handle empty list", "if", "(", "$", "count", "===", "0", ")", "{", "return", "null", ";", "}", "// Sort the full set", "sort", "(", "$", "set", ")", ";", "// If the count is divisible by 2, we'll need to get the average of the two", "if", "(", "$", "count", "&&", "!", "(", "$", "count", "%", "2", ")", ")", "{", "$", "id", "=", "floor", "(", "$", "count", "/", "2", ")", "-", "1", ";", "return", "(", "$", "set", "[", "(", "string", ")", "$", "id", "]", "+", "$", "set", "[", "(", "string", ")", "(", "$", "id", "+", "1", ")", "]", ")", "/", "2", ";", "}", "return", "$", "set", "[", "$", "count", "/", "2", "]", ";", "}" ]
Get the median of a given key. Warning: This loads the full dataset into memory @param null $key @return mixed @throws \InvalidArgumentException
[ "Get", "the", "median", "of", "a", "given", "key", ".", "Warning", ":", "This", "loads", "the", "full", "dataset", "into", "memory" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L110-L139
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.mode
public function mode($key = null): ?array { /** @var array $result */ $result = $this->reduce(function ($carry, $value, $valueKey) use ($key) { $item = $value; if ($key) { $item = $this->accessKey($value, $key, $valueKey); } if (!isset($carry[$item])) { $carry[$item] = 0; } $carry[$item]++; return $carry; }, []); if (!count($result)) { return null; } arsort($result); $output = []; $highestCount = 0; foreach ($result as $itemKey => $count) { if (!$highestCount) { $highestCount = $count; } if ($highestCount !== $count) { break; } $output[] = $itemKey; } return $output; }
php
public function mode($key = null): ?array { /** @var array $result */ $result = $this->reduce(function ($carry, $value, $valueKey) use ($key) { $item = $value; if ($key) { $item = $this->accessKey($value, $key, $valueKey); } if (!isset($carry[$item])) { $carry[$item] = 0; } $carry[$item]++; return $carry; }, []); if (!count($result)) { return null; } arsort($result); $output = []; $highestCount = 0; foreach ($result as $itemKey => $count) { if (!$highestCount) { $highestCount = $count; } if ($highestCount !== $count) { break; } $output[] = $itemKey; } return $output; }
[ "public", "function", "mode", "(", "$", "key", "=", "null", ")", ":", "?", "array", "{", "/** @var array $result */", "$", "result", "=", "$", "this", "->", "reduce", "(", "function", "(", "$", "carry", ",", "$", "value", ",", "$", "valueKey", ")", "use", "(", "$", "key", ")", "{", "$", "item", "=", "$", "value", ";", "if", "(", "$", "key", ")", "{", "$", "item", "=", "$", "this", "->", "accessKey", "(", "$", "value", ",", "$", "key", ",", "$", "valueKey", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "carry", "[", "$", "item", "]", ")", ")", "{", "$", "carry", "[", "$", "item", "]", "=", "0", ";", "}", "$", "carry", "[", "$", "item", "]", "++", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "if", "(", "!", "count", "(", "$", "result", ")", ")", "{", "return", "null", ";", "}", "arsort", "(", "$", "result", ")", ";", "$", "output", "=", "[", "]", ";", "$", "highestCount", "=", "0", ";", "foreach", "(", "$", "result", "as", "$", "itemKey", "=>", "$", "count", ")", "{", "if", "(", "!", "$", "highestCount", ")", "{", "$", "highestCount", "=", "$", "count", ";", "}", "if", "(", "$", "highestCount", "!==", "$", "count", ")", "{", "break", ";", "}", "$", "output", "[", "]", "=", "$", "itemKey", ";", "}", "return", "$", "output", ";", "}" ]
Get the mode of a given key. @param mixed $key @return array|null @throws \InvalidArgumentException
[ "Get", "the", "mode", "of", "a", "given", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L148-L188
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.each
public function each(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { $closed = false; foreach ($data as $key => $value) { if ($callback($value, $key) === false) { $closed = true; } yield $key => $value; if ($closed) { break; } } }); }
php
public function each(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { $closed = false; foreach ($data as $key => $value) { if ($callback($value, $key) === false) { $closed = true; } yield $key => $value; if ($closed) { break; } } }); }
[ "public", "function", "each", "(", "callable", "$", "callback", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "callback", ")", "{", "$", "closed", "=", "false", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "callback", "(", "$", "value", ",", "$", "key", ")", "===", "false", ")", "{", "$", "closed", "=", "true", ";", "}", "yield", "$", "key", "=>", "$", "value", ";", "if", "(", "$", "closed", ")", "{", "break", ";", "}", "}", "}", ")", ";", "}" ]
Execute a callback over each item. @param callable $callback @return CollectionInterface
[ "Execute", "a", "callback", "over", "each", "item", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L206-L222
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.except
public function except($keys): CollectionInterface { if (!is_callable($keys)) { if (!is_array($keys)) { $keys = func_get_args(); } $keys = function ($item, $key) use ($keys) { return in_array($key, $keys, false); }; } return $this->wrap(function (Iterator $data) use ($keys) { foreach ($data as $key => $item) { if (!$keys($item, $key)) { yield $key => $item; } } }); }
php
public function except($keys): CollectionInterface { if (!is_callable($keys)) { if (!is_array($keys)) { $keys = func_get_args(); } $keys = function ($item, $key) use ($keys) { return in_array($key, $keys, false); }; } return $this->wrap(function (Iterator $data) use ($keys) { foreach ($data as $key => $item) { if (!$keys($item, $key)) { yield $key => $item; } } }); }
[ "public", "function", "except", "(", "$", "keys", ")", ":", "CollectionInterface", "{", "if", "(", "!", "is_callable", "(", "$", "keys", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "keys", ")", ")", "{", "$", "keys", "=", "func_get_args", "(", ")", ";", "}", "$", "keys", "=", "function", "(", "$", "item", ",", "$", "key", ")", "use", "(", "$", "keys", ")", "{", "return", "in_array", "(", "$", "key", ",", "$", "keys", ",", "false", ")", ";", "}", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "keys", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "!", "$", "keys", "(", "$", "item", ",", "$", "key", ")", ")", "{", "yield", "$", "key", "=>", "$", "item", ";", "}", "}", "}", ")", ";", "}" ]
Get all items except for those with the specified keys. @param mixed $keys @return CollectionInterface
[ "Get", "all", "items", "except", "for", "those", "with", "the", "specified", "keys", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L241-L259
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.filter
public function filter(callable $callback = null): CollectionInterface { if (!$callback) { $callback = function ($item) { return (bool)$item; }; } return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $item) { if ($callback($item, $key)) { yield $key => $item; } } }); }
php
public function filter(callable $callback = null): CollectionInterface { if (!$callback) { $callback = function ($item) { return (bool)$item; }; } return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $item) { if ($callback($item, $key)) { yield $key => $item; } } }); }
[ "public", "function", "filter", "(", "callable", "$", "callback", "=", "null", ")", ":", "CollectionInterface", "{", "if", "(", "!", "$", "callback", ")", "{", "$", "callback", "=", "function", "(", "$", "item", ")", "{", "return", "(", "bool", ")", "$", "item", ";", "}", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "callback", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "callback", "(", "$", "item", ",", "$", "key", ")", ")", "{", "yield", "$", "key", "=>", "$", "item", ";", "}", "}", "}", ")", ";", "}" ]
Run a filter over each of the items. @param callable|null $callback @return CollectionInterface
[ "Run", "a", "filter", "over", "each", "of", "the", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L267-L282
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.when
public function when($value, callable $callback): CollectionInterface { if ($value) { $this->generator = $callback($this)->generator; } return $this; }
php
public function when($value, callable $callback): CollectionInterface { if ($value) { $this->generator = $callback($this)->generator; } return $this; }
[ "public", "function", "when", "(", "$", "value", ",", "callable", "$", "callback", ")", ":", "CollectionInterface", "{", "if", "(", "$", "value", ")", "{", "$", "this", "->", "generator", "=", "$", "callback", "(", "$", "this", ")", "->", "generator", ";", "}", "return", "$", "this", ";", "}" ]
Apply the callback if the value is truthy. @param bool $value @param callable $callback @return mixed
[ "Apply", "the", "callback", "if", "the", "value", "is", "truthy", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L291-L298
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.where
public function where(array $criteria, $strict = false): CollectionInterface { return array_reduce( array_keys($criteria), function (GeneratorCollection $collection, $key) use ($criteria, $strict) { return $collection->filter(function ($item) use ($key, $criteria, $strict) { if ($strict) { return $item[$key] === $criteria[$key]; } return $item[$key] == $criteria[$key]; }); }, $this ); }
php
public function where(array $criteria, $strict = false): CollectionInterface { return array_reduce( array_keys($criteria), function (GeneratorCollection $collection, $key) use ($criteria, $strict) { return $collection->filter(function ($item) use ($key, $criteria, $strict) { if ($strict) { return $item[$key] === $criteria[$key]; } return $item[$key] == $criteria[$key]; }); }, $this ); }
[ "public", "function", "where", "(", "array", "$", "criteria", ",", "$", "strict", "=", "false", ")", ":", "CollectionInterface", "{", "return", "array_reduce", "(", "array_keys", "(", "$", "criteria", ")", ",", "function", "(", "GeneratorCollection", "$", "collection", ",", "$", "key", ")", "use", "(", "$", "criteria", ",", "$", "strict", ")", "{", "return", "$", "collection", "->", "filter", "(", "function", "(", "$", "item", ")", "use", "(", "$", "key", ",", "$", "criteria", ",", "$", "strict", ")", "{", "if", "(", "$", "strict", ")", "{", "return", "$", "item", "[", "$", "key", "]", "===", "$", "criteria", "[", "$", "key", "]", ";", "}", "return", "$", "item", "[", "$", "key", "]", "==", "$", "criteria", "[", "$", "key", "]", ";", "}", ")", ";", "}", ",", "$", "this", ")", ";", "}" ]
Filter items by the given key value pair. @param array $criteria Returns items that match all criteria @param bool $strict @return CollectionInterface
[ "Filter", "items", "by", "the", "given", "key", "value", "pair", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L307-L322
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.whereIn
public function whereIn($key, $values, $strict = false): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $values, $strict) { foreach ($data as $itemKey => $item) { if (in_array($item[$key], $values, $strict)) { yield $itemKey => $item; } } }); }
php
public function whereIn($key, $values, $strict = false): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $values, $strict) { foreach ($data as $itemKey => $item) { if (in_array($item[$key], $values, $strict)) { yield $itemKey => $item; } } }); }
[ "public", "function", "whereIn", "(", "$", "key", ",", "$", "values", ",", "$", "strict", "=", "false", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "key", ",", "$", "values", ",", "$", "strict", ")", "{", "foreach", "(", "$", "data", "as", "$", "itemKey", "=>", "$", "item", ")", "{", "if", "(", "in_array", "(", "$", "item", "[", "$", "key", "]", ",", "$", "values", ",", "$", "strict", ")", ")", "{", "yield", "$", "itemKey", "=>", "$", "item", ";", "}", "}", "}", ")", ";", "}" ]
Filter items by the given key value pair. @param string $key @param mixed $values @param bool $strict @return CollectionInterface
[ "Filter", "items", "by", "the", "given", "key", "value", "pair", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L332-L341
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.first
public function first(callable $callback = null, $default = null) { foreach ($this->generator as $item) { if (!$callback || $callback($item)) { return $item; } } return $default; }
php
public function first(callable $callback = null, $default = null) { foreach ($this->generator as $item) { if (!$callback || $callback($item)) { return $item; } } return $default; }
[ "public", "function", "first", "(", "callable", "$", "callback", "=", "null", ",", "$", "default", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "generator", "as", "$", "item", ")", "{", "if", "(", "!", "$", "callback", "||", "$", "callback", "(", "$", "item", ")", ")", "{", "return", "$", "item", ";", "}", "}", "return", "$", "default", ";", "}" ]
Get the first item from the collection. @param callable|null $callback @param mixed $default @return mixed
[ "Get", "the", "first", "item", "from", "the", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L350-L359
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.flatten
public function flatten($depth = INF): CollectionInterface { return $this->wrap(function (Iterator $data) use ($depth) { $lowerDepth = $depth === INF ? INF : $depth - 1; foreach ($data as $key => $datum) { if ($lowerDepth >= 0 && is_iterable($datum)) { $collection = $this::make($datum); foreach ($collection->flatten($lowerDepth)->getIterator() as $item) { yield $item; } } else { yield $datum; } } }); }
php
public function flatten($depth = INF): CollectionInterface { return $this->wrap(function (Iterator $data) use ($depth) { $lowerDepth = $depth === INF ? INF : $depth - 1; foreach ($data as $key => $datum) { if ($lowerDepth >= 0 && is_iterable($datum)) { $collection = $this::make($datum); foreach ($collection->flatten($lowerDepth)->getIterator() as $item) { yield $item; } } else { yield $datum; } } }); }
[ "public", "function", "flatten", "(", "$", "depth", "=", "INF", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "depth", ")", "{", "$", "lowerDepth", "=", "$", "depth", "===", "INF", "?", "INF", ":", "$", "depth", "-", "1", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "datum", ")", "{", "if", "(", "$", "lowerDepth", ">=", "0", "&&", "is_iterable", "(", "$", "datum", ")", ")", "{", "$", "collection", "=", "$", "this", "::", "make", "(", "$", "datum", ")", ";", "foreach", "(", "$", "collection", "->", "flatten", "(", "$", "lowerDepth", ")", "->", "getIterator", "(", ")", "as", "$", "item", ")", "{", "yield", "$", "item", ";", "}", "}", "else", "{", "yield", "$", "datum", ";", "}", "}", "}", ")", ";", "}" ]
Get a flattened array of the items in the collection. @param int $depth @return CollectionInterface
[ "Get", "a", "flattened", "array", "of", "the", "items", "in", "the", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L367-L383
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.flatMap
public function flatMap(callable $callback, $depth = INF): CollectionInterface { return $this->map($callback)->flatten($depth); }
php
public function flatMap(callable $callback, $depth = INF): CollectionInterface { return $this->map($callback)->flatten($depth); }
[ "public", "function", "flatMap", "(", "callable", "$", "callback", ",", "$", "depth", "=", "INF", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "map", "(", "$", "callback", ")", "->", "flatten", "(", "$", "depth", ")", ";", "}" ]
Map then flatten @param callable $callback @param $depth @return \Buttress\Collection\CollectionInterface
[ "Map", "then", "flatten" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L391-L394
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.flip
public function flip(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $key => $item) { yield $item => $key; } }); }
php
public function flip(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $key => $item) { yield $item => $key; } }); }
[ "public", "function", "flip", "(", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "yield", "$", "item", "=>", "$", "key", ";", "}", "}", ")", ";", "}" ]
Flip the items in the collection. @return CollectionInterface
[ "Flip", "the", "items", "in", "the", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L401-L408
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.forget
public function forget($keys): CollectionInterface { return $this->wrap(function (Iterator $data) use ($keys) { foreach ($data as $key => $item) { if (is_array($keys)) { if (in_array($key, $keys, false)) { continue; } } elseif ($keys === $key) { continue; } yield $key => $item; } }); }
php
public function forget($keys): CollectionInterface { return $this->wrap(function (Iterator $data) use ($keys) { foreach ($data as $key => $item) { if (is_array($keys)) { if (in_array($key, $keys, false)) { continue; } } elseif ($keys === $key) { continue; } yield $key => $item; } }); }
[ "public", "function", "forget", "(", "$", "keys", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "keys", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "is_array", "(", "$", "keys", ")", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "keys", ",", "false", ")", ")", "{", "continue", ";", "}", "}", "elseif", "(", "$", "keys", "===", "$", "key", ")", "{", "continue", ";", "}", "yield", "$", "key", "=>", "$", "item", ";", "}", "}", ")", ";", "}" ]
Remove an item from the collection by key. @param string|array $keys @return CollectionInterface
[ "Remove", "an", "item", "from", "the", "collection", "by", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L416-L431
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.groupBy
public function groupBy($groupBy, $preserveKeys = false, $batch = INF): CollectionInterface { return $this->wrap(function (Iterator $data) use ($preserveKeys, $batch, $groupBy) { $count = 0; $groups = []; foreach ($data as $key => $datum) { $count++; // Fetch the key and make sure there's a group for it /** @var iterable $group */ $group = $this->accessKey($datum, $groupBy, $key); if (!is_iterable($group)) { $group = [$group]; } foreach ($group as $groupName) { if (!isset($groups[$groupName])) { $groups[$groupName] = []; } // Add the data to the proper group if ($preserveKeys) { $groups[$groupName][$key] = $datum; } else { $groups[$groupName][] = $datum; } } // Check batch, if we're full output and reset count if ($batch !== INF && $count > $batch) { foreach ($groups as $group => $groupData) { yield $group => $groupData; } $groups = []; $count = 0; unset($groupData, $group); } } // Yield the remaining batch foreach ($groups as $group => $groupData) { yield $group => $groupData; } }); }
php
public function groupBy($groupBy, $preserveKeys = false, $batch = INF): CollectionInterface { return $this->wrap(function (Iterator $data) use ($preserveKeys, $batch, $groupBy) { $count = 0; $groups = []; foreach ($data as $key => $datum) { $count++; // Fetch the key and make sure there's a group for it /** @var iterable $group */ $group = $this->accessKey($datum, $groupBy, $key); if (!is_iterable($group)) { $group = [$group]; } foreach ($group as $groupName) { if (!isset($groups[$groupName])) { $groups[$groupName] = []; } // Add the data to the proper group if ($preserveKeys) { $groups[$groupName][$key] = $datum; } else { $groups[$groupName][] = $datum; } } // Check batch, if we're full output and reset count if ($batch !== INF && $count > $batch) { foreach ($groups as $group => $groupData) { yield $group => $groupData; } $groups = []; $count = 0; unset($groupData, $group); } } // Yield the remaining batch foreach ($groups as $group => $groupData) { yield $group => $groupData; } }); }
[ "public", "function", "groupBy", "(", "$", "groupBy", ",", "$", "preserveKeys", "=", "false", ",", "$", "batch", "=", "INF", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "preserveKeys", ",", "$", "batch", ",", "$", "groupBy", ")", "{", "$", "count", "=", "0", ";", "$", "groups", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "datum", ")", "{", "$", "count", "++", ";", "// Fetch the key and make sure there's a group for it", "/** @var iterable $group */", "$", "group", "=", "$", "this", "->", "accessKey", "(", "$", "datum", ",", "$", "groupBy", ",", "$", "key", ")", ";", "if", "(", "!", "is_iterable", "(", "$", "group", ")", ")", "{", "$", "group", "=", "[", "$", "group", "]", ";", "}", "foreach", "(", "$", "group", "as", "$", "groupName", ")", "{", "if", "(", "!", "isset", "(", "$", "groups", "[", "$", "groupName", "]", ")", ")", "{", "$", "groups", "[", "$", "groupName", "]", "=", "[", "]", ";", "}", "// Add the data to the proper group", "if", "(", "$", "preserveKeys", ")", "{", "$", "groups", "[", "$", "groupName", "]", "[", "$", "key", "]", "=", "$", "datum", ";", "}", "else", "{", "$", "groups", "[", "$", "groupName", "]", "[", "]", "=", "$", "datum", ";", "}", "}", "// Check batch, if we're full output and reset count", "if", "(", "$", "batch", "!==", "INF", "&&", "$", "count", ">", "$", "batch", ")", "{", "foreach", "(", "$", "groups", "as", "$", "group", "=>", "$", "groupData", ")", "{", "yield", "$", "group", "=>", "$", "groupData", ";", "}", "$", "groups", "=", "[", "]", ";", "$", "count", "=", "0", ";", "unset", "(", "$", "groupData", ",", "$", "group", ")", ";", "}", "}", "// Yield the remaining batch", "foreach", "(", "$", "groups", "as", "$", "group", "=>", "$", "groupData", ")", "{", "yield", "$", "group", "=>", "$", "groupData", ";", "}", "}", ")", ";", "}" ]
Group an associative array by a field or using a callback. Warning: This may require loading the entire data set into memory To reduce memory usage, provide a limited batch size @param callable|string $groupBy @param bool $preserveKeys @param int $batch The size of the batch @return \Buttress\Collection\CollectionInterface @throws \InvalidArgumentException
[ "Group", "an", "associative", "array", "by", "a", "field", "or", "using", "a", "callback", ".", "Warning", ":", "This", "may", "require", "loading", "the", "entire", "data", "set", "into", "memory", "To", "reduce", "memory", "usage", "provide", "a", "limited", "batch", "size" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L444-L491
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.keyBy
public function keyBy($keyBy): CollectionInterface { return $this->wrap(function (Iterator $data) use ($keyBy) { foreach ($data as $key => $value) { yield $this->accessKey($value, $keyBy, $key) => $value; } }); }
php
public function keyBy($keyBy): CollectionInterface { return $this->wrap(function (Iterator $data) use ($keyBy) { foreach ($data as $key => $value) { yield $this->accessKey($value, $keyBy, $key) => $value; } }); }
[ "public", "function", "keyBy", "(", "$", "keyBy", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "keyBy", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "yield", "$", "this", "->", "accessKey", "(", "$", "value", ",", "$", "keyBy", ",", "$", "key", ")", "=>", "$", "value", ";", "}", "}", ")", ";", "}" ]
Key an associative array by a field or using a callback. @param callable|string $keyBy @return CollectionInterface @throws \InvalidArgumentException
[ "Key", "an", "associative", "array", "by", "a", "field", "or", "using", "a", "callback", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L500-L507
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.implode
public function implode($value, $glue = null): string { return $this->reduce(function ($carry, $item) use ($value, $glue) { $currentGlue = $glue; if (is_string($item) && $currentGlue === null) { $currentGlue = $value; } if ($carry) { $carry .= $currentGlue; } if ($value && ($item instanceof ArrayAccess || is_array($item))) { $item = $item[$value]; } return $carry . $item; }, ''); }
php
public function implode($value, $glue = null): string { return $this->reduce(function ($carry, $item) use ($value, $glue) { $currentGlue = $glue; if (is_string($item) && $currentGlue === null) { $currentGlue = $value; } if ($carry) { $carry .= $currentGlue; } if ($value && ($item instanceof ArrayAccess || is_array($item))) { $item = $item[$value]; } return $carry . $item; }, ''); }
[ "public", "function", "implode", "(", "$", "value", ",", "$", "glue", "=", "null", ")", ":", "string", "{", "return", "$", "this", "->", "reduce", "(", "function", "(", "$", "carry", ",", "$", "item", ")", "use", "(", "$", "value", ",", "$", "glue", ")", "{", "$", "currentGlue", "=", "$", "glue", ";", "if", "(", "is_string", "(", "$", "item", ")", "&&", "$", "currentGlue", "===", "null", ")", "{", "$", "currentGlue", "=", "$", "value", ";", "}", "if", "(", "$", "carry", ")", "{", "$", "carry", ".=", "$", "currentGlue", ";", "}", "if", "(", "$", "value", "&&", "(", "$", "item", "instanceof", "ArrayAccess", "||", "is_array", "(", "$", "item", ")", ")", ")", "{", "$", "item", "=", "$", "item", "[", "$", "value", "]", ";", "}", "return", "$", "carry", ".", "$", "item", ";", "}", ",", "''", ")", ";", "}" ]
Concatenate values of a given key as a string. @param string $value @param string $glue @return string
[ "Concatenate", "values", "of", "a", "given", "key", "as", "a", "string", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L516-L533
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.keys
public function keys(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $key => $value) { yield $key; } }); }
php
public function keys(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $key => $value) { yield $key; } }); }
[ "public", "function", "keys", "(", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "yield", "$", "key", ";", "}", "}", ")", ";", "}" ]
Get the keys of the collection items. @return CollectionInterface
[ "Get", "the", "keys", "of", "the", "collection", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L540-L547
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.last
public function last(callable $callback = null, $default = null) { $collection = $callback ? $this->filter($callback) : $this; foreach ($collection->all() as $key => $value) { // Nothing needed here } return isset($value) ? $value : $default; }
php
public function last(callable $callback = null, $default = null) { $collection = $callback ? $this->filter($callback) : $this; foreach ($collection->all() as $key => $value) { // Nothing needed here } return isset($value) ? $value : $default; }
[ "public", "function", "last", "(", "callable", "$", "callback", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "collection", "=", "$", "callback", "?", "$", "this", "->", "filter", "(", "$", "callback", ")", ":", "$", "this", ";", "foreach", "(", "$", "collection", "->", "all", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "// Nothing needed here", "}", "return", "isset", "(", "$", "value", ")", "?", "$", "value", ":", "$", "default", ";", "}" ]
Return the last element @param callable|null $callback if a callback is provided, we will filter the collection using that callback @param mixed $defualt @return mixed
[ "Return", "the", "last", "element" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L556-L565
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.pluck
public function pluck($value, $key = null): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value, $key) { foreach ($data as $dataKey => $datum) { if ($key) { yield $this->accessKey($datum, $key) => $this->accessKey($datum, $value); } else { yield $this->accessKey($datum, $value); } } }); }
php
public function pluck($value, $key = null): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value, $key) { foreach ($data as $dataKey => $datum) { if ($key) { yield $this->accessKey($datum, $key) => $this->accessKey($datum, $value); } else { yield $this->accessKey($datum, $value); } } }); }
[ "public", "function", "pluck", "(", "$", "value", ",", "$", "key", "=", "null", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "value", ",", "$", "key", ")", "{", "foreach", "(", "$", "data", "as", "$", "dataKey", "=>", "$", "datum", ")", "{", "if", "(", "$", "key", ")", "{", "yield", "$", "this", "->", "accessKey", "(", "$", "datum", ",", "$", "key", ")", "=>", "$", "this", "->", "accessKey", "(", "$", "datum", ",", "$", "value", ")", ";", "}", "else", "{", "yield", "$", "this", "->", "accessKey", "(", "$", "datum", ",", "$", "value", ")", ";", "}", "}", "}", ")", ";", "}" ]
Get the values of a given key. @param string $value @param null $key @return CollectionInterface @throws \InvalidArgumentException
[ "Get", "the", "values", "of", "a", "given", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L575-L586
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.accessKey
private function accessKey($mixed, $key, $givenKey = null) { // Handle callable keys, just pass in the mixed and return the result. if (is_callable($key)) { return $key($mixed, $givenKey); } // If it's a string, an array, or accessible through [] if (is_string($mixed) || is_array($mixed) || $mixed instanceof ArrayAccess) { return $mixed[$key]; } // If it's an object if (is_object($mixed)) { return $mixed->{$key}; } // Give up throw new InvalidArgumentException('Invalid object type provided, cannot access key.'); }
php
private function accessKey($mixed, $key, $givenKey = null) { // Handle callable keys, just pass in the mixed and return the result. if (is_callable($key)) { return $key($mixed, $givenKey); } // If it's a string, an array, or accessible through [] if (is_string($mixed) || is_array($mixed) || $mixed instanceof ArrayAccess) { return $mixed[$key]; } // If it's an object if (is_object($mixed)) { return $mixed->{$key}; } // Give up throw new InvalidArgumentException('Invalid object type provided, cannot access key.'); }
[ "private", "function", "accessKey", "(", "$", "mixed", ",", "$", "key", ",", "$", "givenKey", "=", "null", ")", "{", "// Handle callable keys, just pass in the mixed and return the result.", "if", "(", "is_callable", "(", "$", "key", ")", ")", "{", "return", "$", "key", "(", "$", "mixed", ",", "$", "givenKey", ")", ";", "}", "// If it's a string, an array, or accessible through []", "if", "(", "is_string", "(", "$", "mixed", ")", "||", "is_array", "(", "$", "mixed", ")", "||", "$", "mixed", "instanceof", "ArrayAccess", ")", "{", "return", "$", "mixed", "[", "$", "key", "]", ";", "}", "// If it's an object", "if", "(", "is_object", "(", "$", "mixed", ")", ")", "{", "return", "$", "mixed", "->", "{", "$", "key", "}", ";", "}", "// Give up", "throw", "new", "InvalidArgumentException", "(", "'Invalid object type provided, cannot access key.'", ")", ";", "}" ]
Get a value from a mixed key @param mixed $mixed @param mixed $key @param null|string $givenKey @return mixed @throws \InvalidArgumentException
[ "Get", "a", "value", "from", "a", "mixed", "key" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L596-L615
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.map
public function map(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $value) { yield $key => $callback($value, $key); } }); }
php
public function map(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $value) { yield $key => $callback($value, $key); } }); }
[ "public", "function", "map", "(", "callable", "$", "callback", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "callback", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "yield", "$", "key", "=>", "$", "callback", "(", "$", "value", ",", "$", "key", ")", ";", "}", "}", ")", ";", "}" ]
Run a map over each of the items. @param callable $callback @return CollectionInterface
[ "Run", "a", "map", "over", "each", "of", "the", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L623-L630
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.mapWithKeys
public function mapWithKeys(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $value) { /** @var iterable $result */ $result = $callback($value, $key); foreach ($result as $resultKey => $resultValue) { yield $resultKey => $resultValue; } } }); }
php
public function mapWithKeys(callable $callback): CollectionInterface { return $this->wrap(function (Iterator $data) use ($callback) { foreach ($data as $key => $value) { /** @var iterable $result */ $result = $callback($value, $key); foreach ($result as $resultKey => $resultValue) { yield $resultKey => $resultValue; } } }); }
[ "public", "function", "mapWithKeys", "(", "callable", "$", "callback", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "callback", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "/** @var iterable $result */", "$", "result", "=", "$", "callback", "(", "$", "value", ",", "$", "key", ")", ";", "foreach", "(", "$", "result", "as", "$", "resultKey", "=>", "$", "resultValue", ")", "{", "yield", "$", "resultKey", "=>", "$", "resultValue", ";", "}", "}", "}", ")", ";", "}" ]
Run an associative map over each of the items. The callback should return an associative array with a single key/value pair. @param callable $callback @return CollectionInterface
[ "Run", "an", "associative", "map", "over", "each", "of", "the", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L640-L652
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.max
public function max($callback = null) { return $this->reduce(function ($carry, $value, $key) use ($callback) { if ($callback === null) { $result = $value; } else { $result = $this->accessKey($value, $callback, $key); } if ($carry === null || $carry < $result) { return $result; } return $carry; }, null); }
php
public function max($callback = null) { return $this->reduce(function ($carry, $value, $key) use ($callback) { if ($callback === null) { $result = $value; } else { $result = $this->accessKey($value, $callback, $key); } if ($carry === null || $carry < $result) { return $result; } return $carry; }, null); }
[ "public", "function", "max", "(", "$", "callback", "=", "null", ")", "{", "return", "$", "this", "->", "reduce", "(", "function", "(", "$", "carry", ",", "$", "value", ",", "$", "key", ")", "use", "(", "$", "callback", ")", "{", "if", "(", "$", "callback", "===", "null", ")", "{", "$", "result", "=", "$", "value", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "accessKey", "(", "$", "value", ",", "$", "callback", ",", "$", "key", ")", ";", "}", "if", "(", "$", "carry", "===", "null", "||", "$", "carry", "<", "$", "result", ")", "{", "return", "$", "result", ";", "}", "return", "$", "carry", ";", "}", ",", "null", ")", ";", "}" ]
Get the max value of a given key. @param callable|string|null $callback @return mixed @throws \InvalidArgumentException
[ "Get", "the", "max", "value", "of", "a", "given", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L661-L676
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.merge
public function merge($items): CollectionInterface { return $this->wrap(function (Iterator $data) use ($items) { yield from $data; if (is_iterable($items)) { yield from $items; } elseif ($items) { yield $items; } }); }
php
public function merge($items): CollectionInterface { return $this->wrap(function (Iterator $data) use ($items) { yield from $data; if (is_iterable($items)) { yield from $items; } elseif ($items) { yield $items; } }); }
[ "public", "function", "merge", "(", "$", "items", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "items", ")", "{", "yield", "from", "$", "data", ";", "if", "(", "is_iterable", "(", "$", "items", ")", ")", "{", "yield", "from", "$", "items", ";", "}", "elseif", "(", "$", "items", ")", "{", "yield", "$", "items", ";", "}", "}", ")", ";", "}" ]
Merge the collection with the given items. @param mixed $items @return CollectionInterface
[ "Merge", "the", "collection", "with", "the", "given", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L684-L695
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.append
public function append($items, bool $preserveKeys = true): CollectionInterface { return $this->wrap(function (Iterator $data) use ($items, $preserveKeys) { $lists = [$data, self::make($items)]; foreach ($lists as $list) { foreach ($list as $key => $item) { if ($preserveKeys) { yield $key => $item; } else { yield $item; } } } }); }
php
public function append($items, bool $preserveKeys = true): CollectionInterface { return $this->wrap(function (Iterator $data) use ($items, $preserveKeys) { $lists = [$data, self::make($items)]; foreach ($lists as $list) { foreach ($list as $key => $item) { if ($preserveKeys) { yield $key => $item; } else { yield $item; } } } }); }
[ "public", "function", "append", "(", "$", "items", ",", "bool", "$", "preserveKeys", "=", "true", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "items", ",", "$", "preserveKeys", ")", "{", "$", "lists", "=", "[", "$", "data", ",", "self", "::", "make", "(", "$", "items", ")", "]", ";", "foreach", "(", "$", "lists", "as", "$", "list", ")", "{", "foreach", "(", "$", "list", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "preserveKeys", ")", "{", "yield", "$", "key", "=>", "$", "item", ";", "}", "else", "{", "yield", "$", "item", ";", "}", "}", "}", "}", ")", ";", "}" ]
Append items onto this collection @param mixed $items @param bool $preserveKeys @return \Buttress\Collection\CollectionInterface
[ "Append", "items", "onto", "this", "collection" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L704-L719
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.combine
public function combine($values): CollectionInterface { if ($values instanceof IteratorAggregate) { $values = $values->getIterator(); } elseif (is_array($values)) { $values = new ArrayIterator($values); } return $this->wrap(function (Iterator $keys) use ($values) { foreach ($keys as $key) { yield $key => $values->current(); $values->next(); } }); }
php
public function combine($values): CollectionInterface { if ($values instanceof IteratorAggregate) { $values = $values->getIterator(); } elseif (is_array($values)) { $values = new ArrayIterator($values); } return $this->wrap(function (Iterator $keys) use ($values) { foreach ($keys as $key) { yield $key => $values->current(); $values->next(); } }); }
[ "public", "function", "combine", "(", "$", "values", ")", ":", "CollectionInterface", "{", "if", "(", "$", "values", "instanceof", "IteratorAggregate", ")", "{", "$", "values", "=", "$", "values", "->", "getIterator", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "new", "ArrayIterator", "(", "$", "values", ")", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "keys", ")", "use", "(", "$", "values", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "yield", "$", "key", "=>", "$", "values", "->", "current", "(", ")", ";", "$", "values", "->", "next", "(", ")", ";", "}", "}", ")", ";", "}" ]
Create a collection by using this collection for keys and another for its values. @param mixed $values @return CollectionInterface
[ "Create", "a", "collection", "by", "using", "this", "collection", "for", "keys", "and", "another", "for", "its", "values", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L727-L741
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.nth
public function nth($step, $offset = 0): CollectionInterface { return $this->wrap(function (Iterator $data) use ($step, $offset) { while ($offset && $data->valid()) { $data->next(); $offset--; } while ($data->valid()) { yield $data->current(); $skip = $step; while ($skip--) { $data->next(); } } }); }
php
public function nth($step, $offset = 0): CollectionInterface { return $this->wrap(function (Iterator $data) use ($step, $offset) { while ($offset && $data->valid()) { $data->next(); $offset--; } while ($data->valid()) { yield $data->current(); $skip = $step; while ($skip--) { $data->next(); } } }); }
[ "public", "function", "nth", "(", "$", "step", ",", "$", "offset", "=", "0", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "step", ",", "$", "offset", ")", "{", "while", "(", "$", "offset", "&&", "$", "data", "->", "valid", "(", ")", ")", "{", "$", "data", "->", "next", "(", ")", ";", "$", "offset", "--", ";", "}", "while", "(", "$", "data", "->", "valid", "(", ")", ")", "{", "yield", "$", "data", "->", "current", "(", ")", ";", "$", "skip", "=", "$", "step", ";", "while", "(", "$", "skip", "--", ")", "{", "$", "data", "->", "next", "(", ")", ";", "}", "}", "}", ")", ";", "}" ]
Create a new collection consisting of every n-th element. @param int $step @param int $offset @return CollectionInterface
[ "Create", "a", "new", "collection", "consisting", "of", "every", "n", "-", "th", "element", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L780-L797
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.only
public function only($keys): CollectionInterface { $args = func_get_args(); if (count($args) === 1) { $args = reset($args); } if ($args === null) { return $this; } return $this->wrap(function (Iterator $data) use ($args) { foreach ($data as $key => $datum) { if (in_array($key, $args, false)) { yield $key => $datum; } } }); }
php
public function only($keys): CollectionInterface { $args = func_get_args(); if (count($args) === 1) { $args = reset($args); } if ($args === null) { return $this; } return $this->wrap(function (Iterator $data) use ($args) { foreach ($data as $key => $datum) { if (in_array($key, $args, false)) { yield $key => $datum; } } }); }
[ "public", "function", "only", "(", "$", "keys", ")", ":", "CollectionInterface", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", "===", "1", ")", "{", "$", "args", "=", "reset", "(", "$", "args", ")", ";", "}", "if", "(", "$", "args", "===", "null", ")", "{", "return", "$", "this", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "args", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "datum", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "args", ",", "false", ")", ")", "{", "yield", "$", "key", "=>", "$", "datum", ";", "}", "}", "}", ")", ";", "}" ]
Get the items with the specified keys. @param mixed $keys @return CollectionInterface
[ "Get", "the", "items", "with", "the", "specified", "keys", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L805-L823
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.forPage
public function forPage(int $page, int $perPage): CollectionInterface { $page--; $offset = $page * $perPage; return $this->slice($offset, $perPage); }
php
public function forPage(int $page, int $perPage): CollectionInterface { $page--; $offset = $page * $perPage; return $this->slice($offset, $perPage); }
[ "public", "function", "forPage", "(", "int", "$", "page", ",", "int", "$", "perPage", ")", ":", "CollectionInterface", "{", "$", "page", "--", ";", "$", "offset", "=", "$", "page", "*", "$", "perPage", ";", "return", "$", "this", "->", "slice", "(", "$", "offset", ",", "$", "perPage", ")", ";", "}" ]
"Paginate" the collection by slicing it into a smaller collection. @param int $page @param int $perPage @return CollectionInterface @throws \InvalidArgumentException
[ "Paginate", "the", "collection", "by", "slicing", "it", "into", "a", "smaller", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L833-L839
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.partition
public function partition($callback): array { $partitions = [[], []]; foreach ($this->generator as $key => $item) { if ($this->accessKey($item, $callback, $key)) { $partitions[0][$key] = $item; } else { $partitions[1][$key] = $item; } } return array_map(function ($value) { return $this::make($value); }, $partitions); }
php
public function partition($callback): array { $partitions = [[], []]; foreach ($this->generator as $key => $item) { if ($this->accessKey($item, $callback, $key)) { $partitions[0][$key] = $item; } else { $partitions[1][$key] = $item; } } return array_map(function ($value) { return $this::make($value); }, $partitions); }
[ "public", "function", "partition", "(", "$", "callback", ")", ":", "array", "{", "$", "partitions", "=", "[", "[", "]", ",", "[", "]", "]", ";", "foreach", "(", "$", "this", "->", "generator", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "this", "->", "accessKey", "(", "$", "item", ",", "$", "callback", ",", "$", "key", ")", ")", "{", "$", "partitions", "[", "0", "]", "[", "$", "key", "]", "=", "$", "item", ";", "}", "else", "{", "$", "partitions", "[", "1", "]", "[", "$", "key", "]", "=", "$", "item", ";", "}", "}", "return", "array_map", "(", "function", "(", "$", "value", ")", "{", "return", "$", "this", "::", "make", "(", "$", "value", ")", ";", "}", ",", "$", "partitions", ")", ";", "}" ]
Partition the collection into two arrays using the given callback or key. @param callable|string $callback @return array [ $partition1, $partition2 ] @throws \InvalidArgumentException
[ "Partition", "the", "collection", "into", "two", "arrays", "using", "the", "given", "callback", "or", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L848-L862
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.prepend
public function prepend($value, $passedKey = null): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value, $passedKey) { if ($passedKey) { yield $passedKey => $value; } else { yield $value; } foreach ($data as $key => $value) { if ($passedKey) { yield $key => $value; } else { yield $value; } } }); }
php
public function prepend($value, $passedKey = null): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value, $passedKey) { if ($passedKey) { yield $passedKey => $value; } else { yield $value; } foreach ($data as $key => $value) { if ($passedKey) { yield $key => $value; } else { yield $value; } } }); }
[ "public", "function", "prepend", "(", "$", "value", ",", "$", "passedKey", "=", "null", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "value", ",", "$", "passedKey", ")", "{", "if", "(", "$", "passedKey", ")", "{", "yield", "$", "passedKey", "=>", "$", "value", ";", "}", "else", "{", "yield", "$", "value", ";", "}", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "passedKey", ")", "{", "yield", "$", "key", "=>", "$", "value", ";", "}", "else", "{", "yield", "$", "value", ";", "}", "}", "}", ")", ";", "}" ]
Push an item onto the beginning of the collection. @param mixed $value @param mixed $passedKey @return CollectionInterface
[ "Push", "an", "item", "onto", "the", "beginning", "of", "the", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L882-L899
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.push
public function push($value): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value) { foreach ($data as $key => $item) { yield $key => $item; } yield $value; }); }
php
public function push($value): CollectionInterface { return $this->wrap(function (Iterator $data) use ($value) { foreach ($data as $key => $item) { yield $key => $item; } yield $value; }); }
[ "public", "function", "push", "(", "$", "value", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "value", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "yield", "$", "key", "=>", "$", "item", ";", "}", "yield", "$", "value", ";", "}", ")", ";", "}" ]
Push an item onto the end of the collection. @param mixed $value @return CollectionInterface
[ "Push", "an", "item", "onto", "the", "end", "of", "the", "collection", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L907-L916
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.put
public function put($key, $value): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $value) { $replaced = false; foreach ($data as $dataKey => $datum) { if ($key === $dataKey) { yield $key => $value; $replaced = true; } else { yield $dataKey => $datum; } } if (!$replaced) { yield $key => $value; } }); }
php
public function put($key, $value): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $value) { $replaced = false; foreach ($data as $dataKey => $datum) { if ($key === $dataKey) { yield $key => $value; $replaced = true; } else { yield $dataKey => $datum; } } if (!$replaced) { yield $key => $value; } }); }
[ "public", "function", "put", "(", "$", "key", ",", "$", "value", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "key", ",", "$", "value", ")", "{", "$", "replaced", "=", "false", ";", "foreach", "(", "$", "data", "as", "$", "dataKey", "=>", "$", "datum", ")", "{", "if", "(", "$", "key", "===", "$", "dataKey", ")", "{", "yield", "$", "key", "=>", "$", "value", ";", "$", "replaced", "=", "true", ";", "}", "else", "{", "yield", "$", "dataKey", "=>", "$", "datum", ";", "}", "}", "if", "(", "!", "$", "replaced", ")", "{", "yield", "$", "key", "=>", "$", "value", ";", "}", "}", ")", ";", "}" ]
Put an item in the collection by key. @param mixed $key @param mixed $value @return CollectionInterface
[ "Put", "an", "item", "in", "the", "collection", "by", "key", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L925-L943
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.reduce
public function reduce(callable $callback, $initial = null) { foreach ($this->generator as $key => $value) { $initial = $callback($initial, $value, $key); } return $initial; }
php
public function reduce(callable $callback, $initial = null) { foreach ($this->generator as $key => $value) { $initial = $callback($initial, $value, $key); } return $initial; }
[ "public", "function", "reduce", "(", "callable", "$", "callback", ",", "$", "initial", "=", "null", ")", "{", "foreach", "(", "$", "this", "->", "generator", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "initial", "=", "$", "callback", "(", "$", "initial", ",", "$", "value", ",", "$", "key", ")", ";", "}", "return", "$", "initial", ";", "}" ]
Reduce the collection to a single value. @param callable $callback @param mixed $initial @return mixed
[ "Reduce", "the", "collection", "to", "a", "single", "value", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L952-L959
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.reject
public function reject($callback): CollectionInterface { return $this->filter(function ($item, $key) use ($callback) { if (is_callable($callback)) { return !$callback($item, $key); } if (null === $item || is_scalar($item)) { return $item !== $callback; } return !$this->accessKey($item, $callback, $key); }); }
php
public function reject($callback): CollectionInterface { return $this->filter(function ($item, $key) use ($callback) { if (is_callable($callback)) { return !$callback($item, $key); } if (null === $item || is_scalar($item)) { return $item !== $callback; } return !$this->accessKey($item, $callback, $key); }); }
[ "public", "function", "reject", "(", "$", "callback", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "filter", "(", "function", "(", "$", "item", ",", "$", "key", ")", "use", "(", "$", "callback", ")", "{", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "return", "!", "$", "callback", "(", "$", "item", ",", "$", "key", ")", ";", "}", "if", "(", "null", "===", "$", "item", "||", "is_scalar", "(", "$", "item", ")", ")", "{", "return", "$", "item", "!==", "$", "callback", ";", "}", "return", "!", "$", "this", "->", "accessKey", "(", "$", "item", ",", "$", "callback", ",", "$", "key", ")", ";", "}", ")", ";", "}" ]
Create a collection of all elements that do not pass a given truth test. @param callable|mixed $callback @return CollectionInterface @throws \InvalidArgumentException
[ "Create", "a", "collection", "of", "all", "elements", "that", "do", "not", "pass", "a", "given", "truth", "test", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L968-L981
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.slice
public function slice($offset, $length = null): CollectionInterface { if ($length < 0) { throw new InvalidArgumentException('Negative slice lengths are not supported'); } $result = $this; if ($offset < 0) { $result = $this->take($offset); } elseif ($offset > 0) { $result = $this->offset($offset); } if ($length !== null) { $result = $result->take($length); } return $result; }
php
public function slice($offset, $length = null): CollectionInterface { if ($length < 0) { throw new InvalidArgumentException('Negative slice lengths are not supported'); } $result = $this; if ($offset < 0) { $result = $this->take($offset); } elseif ($offset > 0) { $result = $this->offset($offset); } if ($length !== null) { $result = $result->take($length); } return $result; }
[ "public", "function", "slice", "(", "$", "offset", ",", "$", "length", "=", "null", ")", ":", "CollectionInterface", "{", "if", "(", "$", "length", "<", "0", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Negative slice lengths are not supported'", ")", ";", "}", "$", "result", "=", "$", "this", ";", "if", "(", "$", "offset", "<", "0", ")", "{", "$", "result", "=", "$", "this", "->", "take", "(", "$", "offset", ")", ";", "}", "elseif", "(", "$", "offset", ">", "0", ")", "{", "$", "result", "=", "$", "this", "->", "offset", "(", "$", "offset", ")", ";", "}", "if", "(", "$", "length", "!==", "null", ")", "{", "$", "result", "=", "$", "result", "->", "take", "(", "$", "length", ")", ";", "}", "return", "$", "result", ";", "}" ]
Slice the underlying collection array. @param int $offset @param int $length @return CollectionInterface @throws \InvalidArgumentException
[ "Slice", "the", "underlying", "collection", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L991-L1009
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.offset
private function offset($offset): CollectionInterface { return $this->wrap(function (Iterator $iterator) use ($offset) { while ($offset-- > 0 && $iterator->valid()) { $iterator->next(); } while ($iterator->valid()) { yield $iterator->key() => $iterator->current(); $iterator->next(); } }); }
php
private function offset($offset): CollectionInterface { return $this->wrap(function (Iterator $iterator) use ($offset) { while ($offset-- > 0 && $iterator->valid()) { $iterator->next(); } while ($iterator->valid()) { yield $iterator->key() => $iterator->current(); $iterator->next(); } }); }
[ "private", "function", "offset", "(", "$", "offset", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "iterator", ")", "use", "(", "$", "offset", ")", "{", "while", "(", "$", "offset", "--", ">", "0", "&&", "$", "iterator", "->", "valid", "(", ")", ")", "{", "$", "iterator", "->", "next", "(", ")", ";", "}", "while", "(", "$", "iterator", "->", "valid", "(", ")", ")", "{", "yield", "$", "iterator", "->", "key", "(", ")", "=>", "$", "iterator", "->", "current", "(", ")", ";", "$", "iterator", "->", "next", "(", ")", ";", "}", "}", ")", ";", "}" ]
Get items past an offset @param $offset @return CollectionInterface
[ "Get", "items", "past", "an", "offset" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1016-L1028
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.chunk
public function chunk($size): CollectionInterface { if (!($size > 0)) { return $this::make([]); } return $this->wrap(function (Iterator $data) use ($size) { $chunk = []; $count = 0; foreach ($data as $key => $item) { $chunk[$key] = $item; $count++; if ($count >= $size) { yield $this::make($chunk); $chunk = []; $count = 0; } } if ($count) { yield $this::make($chunk); } }); }
php
public function chunk($size): CollectionInterface { if (!($size > 0)) { return $this::make([]); } return $this->wrap(function (Iterator $data) use ($size) { $chunk = []; $count = 0; foreach ($data as $key => $item) { $chunk[$key] = $item; $count++; if ($count >= $size) { yield $this::make($chunk); $chunk = []; $count = 0; } } if ($count) { yield $this::make($chunk); } }); }
[ "public", "function", "chunk", "(", "$", "size", ")", ":", "CollectionInterface", "{", "if", "(", "!", "(", "$", "size", ">", "0", ")", ")", "{", "return", "$", "this", "::", "make", "(", "[", "]", ")", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "size", ")", "{", "$", "chunk", "=", "[", "]", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "chunk", "[", "$", "key", "]", "=", "$", "item", ";", "$", "count", "++", ";", "if", "(", "$", "count", ">=", "$", "size", ")", "{", "yield", "$", "this", "::", "make", "(", "$", "chunk", ")", ";", "$", "chunk", "=", "[", "]", ";", "$", "count", "=", "0", ";", "}", "}", "if", "(", "$", "count", ")", "{", "yield", "$", "this", "::", "make", "(", "$", "chunk", ")", ";", "}", "}", ")", ";", "}" ]
Chunk the underlying collection array. @param int $size @return CollectionInterface
[ "Chunk", "the", "underlying", "collection", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1036-L1059
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.splice
public function splice($offset, $length = null, $replacement = []): CollectionInterface { if (!is_iterable($replacement)) { $replacement = [$replacement]; } return $this->wrap(function (Iterator $data) use ($offset, $length, $replacement) { // Handle offset while ($data->valid() && $offset) { yield $data->current(); $data->next(); $offset--; } // If we're given a null length, lets just remove the item at that point if ($length === null) { $length = 1; } // Skip $length while ($data->valid() && $length) { $data->next(); $length--; } // Yield the replacements foreach ($replacement as $key => $item) { yield $item; } // Yield the remaining items while ($data->valid()) { yield $data->current(); $data->next(); } }); }
php
public function splice($offset, $length = null, $replacement = []): CollectionInterface { if (!is_iterable($replacement)) { $replacement = [$replacement]; } return $this->wrap(function (Iterator $data) use ($offset, $length, $replacement) { // Handle offset while ($data->valid() && $offset) { yield $data->current(); $data->next(); $offset--; } // If we're given a null length, lets just remove the item at that point if ($length === null) { $length = 1; } // Skip $length while ($data->valid() && $length) { $data->next(); $length--; } // Yield the replacements foreach ($replacement as $key => $item) { yield $item; } // Yield the remaining items while ($data->valid()) { yield $data->current(); $data->next(); } }); }
[ "public", "function", "splice", "(", "$", "offset", ",", "$", "length", "=", "null", ",", "$", "replacement", "=", "[", "]", ")", ":", "CollectionInterface", "{", "if", "(", "!", "is_iterable", "(", "$", "replacement", ")", ")", "{", "$", "replacement", "=", "[", "$", "replacement", "]", ";", "}", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "offset", ",", "$", "length", ",", "$", "replacement", ")", "{", "// Handle offset", "while", "(", "$", "data", "->", "valid", "(", ")", "&&", "$", "offset", ")", "{", "yield", "$", "data", "->", "current", "(", ")", ";", "$", "data", "->", "next", "(", ")", ";", "$", "offset", "--", ";", "}", "// If we're given a null length, lets just remove the item at that point", "if", "(", "$", "length", "===", "null", ")", "{", "$", "length", "=", "1", ";", "}", "// Skip $length", "while", "(", "$", "data", "->", "valid", "(", ")", "&&", "$", "length", ")", "{", "$", "data", "->", "next", "(", ")", ";", "$", "length", "--", ";", "}", "// Yield the replacements", "foreach", "(", "$", "replacement", "as", "$", "key", "=>", "$", "item", ")", "{", "yield", "$", "item", ";", "}", "// Yield the remaining items", "while", "(", "$", "data", "->", "valid", "(", ")", ")", "{", "yield", "$", "data", "->", "current", "(", ")", ";", "$", "data", "->", "next", "(", ")", ";", "}", "}", ")", ";", "}" ]
Splice a portion of the underlying collection array. @param int $offset @param int|null $length @param mixed $replacement @return CollectionInterface
[ "Splice", "a", "portion", "of", "the", "underlying", "collection", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1069-L1105
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.sum
public function sum($callback = null): float { return $this->reduce(function ($carry, $value, $key) use ($callback) { $value = $callback === null ? $value : $this->accessKey($value, $callback, $key); return $carry + $value; }, 0); }
php
public function sum($callback = null): float { return $this->reduce(function ($carry, $value, $key) use ($callback) { $value = $callback === null ? $value : $this->accessKey($value, $callback, $key); return $carry + $value; }, 0); }
[ "public", "function", "sum", "(", "$", "callback", "=", "null", ")", ":", "float", "{", "return", "$", "this", "->", "reduce", "(", "function", "(", "$", "carry", ",", "$", "value", ",", "$", "key", ")", "use", "(", "$", "callback", ")", "{", "$", "value", "=", "$", "callback", "===", "null", "?", "$", "value", ":", "$", "this", "->", "accessKey", "(", "$", "value", ",", "$", "callback", ",", "$", "key", ")", ";", "return", "$", "carry", "+", "$", "value", ";", "}", ",", "0", ")", ";", "}" ]
Get the sum of the given values. @param callable|string|null $callback @return float @throws \InvalidArgumentException
[ "Get", "the", "sum", "of", "the", "given", "values", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1114-L1120
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.take
public function take($limit): CollectionInterface { if ($limit >= 0) { return $this->takeFirst($limit); } else { return $this->takeLast(abs($limit)); } }
php
public function take($limit): CollectionInterface { if ($limit >= 0) { return $this->takeFirst($limit); } else { return $this->takeLast(abs($limit)); } }
[ "public", "function", "take", "(", "$", "limit", ")", ":", "CollectionInterface", "{", "if", "(", "$", "limit", ">=", "0", ")", "{", "return", "$", "this", "->", "takeFirst", "(", "$", "limit", ")", ";", "}", "else", "{", "return", "$", "this", "->", "takeLast", "(", "abs", "(", "$", "limit", ")", ")", ";", "}", "}" ]
Take the first or last {$limit} items. @param int $limit @return CollectionInterface
[ "Take", "the", "first", "or", "last", "{", "$limit", "}", "items", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1128-L1135
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.takeFirst
public function takeFirst(int $count) { return $this->wrap(function (Iterator $data) use ($count) { $first = true; while ($count-- && $data->valid()) { if (!$first) { $data->next(); } yield $data->key() => $data->current(); $first = false; } }); }
php
public function takeFirst(int $count) { return $this->wrap(function (Iterator $data) use ($count) { $first = true; while ($count-- && $data->valid()) { if (!$first) { $data->next(); } yield $data->key() => $data->current(); $first = false; } }); }
[ "public", "function", "takeFirst", "(", "int", "$", "count", ")", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "count", ")", "{", "$", "first", "=", "true", ";", "while", "(", "$", "count", "--", "&&", "$", "data", "->", "valid", "(", ")", ")", "{", "if", "(", "!", "$", "first", ")", "{", "$", "data", "->", "next", "(", ")", ";", "}", "yield", "$", "data", "->", "key", "(", ")", "=>", "$", "data", "->", "current", "(", ")", ";", "$", "first", "=", "false", ";", "}", "}", ")", ";", "}" ]
Take items from the beginning of the collection @param int $count @return \Buttress\Collection\CollectionInterface
[ "Take", "items", "from", "the", "beginning", "of", "the", "collection" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1143-L1157
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.takeLast
public function takeLast(int $count) { return $this->wrap(function (Iterator $data) use ($count) { // From the end of the collection $limit = max(0, $count); $chunk = []; foreach ($data as $key => $datum) { $chunk[] = [$key, $datum]; if (count($chunk) > $limit) { array_shift($chunk); } } foreach ($chunk as $item) { [$key, $datum] = $item; yield $key => $datum; } }); }
php
public function takeLast(int $count) { return $this->wrap(function (Iterator $data) use ($count) { // From the end of the collection $limit = max(0, $count); $chunk = []; foreach ($data as $key => $datum) { $chunk[] = [$key, $datum]; if (count($chunk) > $limit) { array_shift($chunk); } } foreach ($chunk as $item) { [$key, $datum] = $item; yield $key => $datum; } }); }
[ "public", "function", "takeLast", "(", "int", "$", "count", ")", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "count", ")", "{", "// From the end of the collection", "$", "limit", "=", "max", "(", "0", ",", "$", "count", ")", ";", "$", "chunk", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "datum", ")", "{", "$", "chunk", "[", "]", "=", "[", "$", "key", ",", "$", "datum", "]", ";", "if", "(", "count", "(", "$", "chunk", ")", ">", "$", "limit", ")", "{", "array_shift", "(", "$", "chunk", ")", ";", "}", "}", "foreach", "(", "$", "chunk", "as", "$", "item", ")", "{", "[", "$", "key", ",", "$", "datum", "]", "=", "$", "item", ";", "yield", "$", "key", "=>", "$", "datum", ";", "}", "}", ")", ";", "}" ]
Take items from the end of the collection @param int $count @return \Buttress\Collection\CollectionInterface
[ "Take", "items", "from", "the", "end", "of", "the", "collection" ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1165-L1184
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.unique
public function unique($key = null, $strict = false): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $strict) { $tracker = []; foreach ($data as $dataKey => $datum) { $compare = $datum; if ($key) { $compare = is_callable($key) ? $key($datum, $dataKey) : $datum[$key]; } if (!in_array($compare, $tracker, $strict)) { yield $dataKey => $datum; $tracker[] = $compare; } } }); }
php
public function unique($key = null, $strict = false): CollectionInterface { return $this->wrap(function (Iterator $data) use ($key, $strict) { $tracker = []; foreach ($data as $dataKey => $datum) { $compare = $datum; if ($key) { $compare = is_callable($key) ? $key($datum, $dataKey) : $datum[$key]; } if (!in_array($compare, $tracker, $strict)) { yield $dataKey => $datum; $tracker[] = $compare; } } }); }
[ "public", "function", "unique", "(", "$", "key", "=", "null", ",", "$", "strict", "=", "false", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "key", ",", "$", "strict", ")", "{", "$", "tracker", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "dataKey", "=>", "$", "datum", ")", "{", "$", "compare", "=", "$", "datum", ";", "if", "(", "$", "key", ")", "{", "$", "compare", "=", "is_callable", "(", "$", "key", ")", "?", "$", "key", "(", "$", "datum", ",", "$", "dataKey", ")", ":", "$", "datum", "[", "$", "key", "]", ";", "}", "if", "(", "!", "in_array", "(", "$", "compare", ",", "$", "tracker", ",", "$", "strict", ")", ")", "{", "yield", "$", "dataKey", "=>", "$", "datum", ";", "$", "tracker", "[", "]", "=", "$", "compare", ";", "}", "}", "}", ")", ";", "}" ]
Return only unique items from the collection array. @param string|callable|null $key @param bool $strict @return CollectionInterface
[ "Return", "only", "unique", "items", "from", "the", "collection", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1216-L1233
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.values
public function values(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $item) { yield $item; } }); }
php
public function values(): CollectionInterface { return $this->wrap(function (Iterator $data) { foreach ($data as $item) { yield $item; } }); }
[ "public", "function", "values", "(", ")", ":", "CollectionInterface", "{", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "item", ")", "{", "yield", "$", "item", ";", "}", "}", ")", ";", "}" ]
Reset the keys on the underlying array. @return CollectionInterface
[ "Reset", "the", "keys", "on", "the", "underlying", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1240-L1247
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.zip
public function zip($items): CollectionInterface { $items = array_map(function ($items) { if ($items instanceof IteratorAggregate) { return $items->getIterator(); } if (is_array($items)) { return new ArrayIterator($items); } return $items; }, func_get_args()); return $this->wrap(function (Iterator $data) use ($items) { foreach ($data as $key => $datum) { $result = [$datum]; /** @var Iterator $item */ foreach ($items as $item) { $result[] = $item->current(); $item->next(); } yield $key => $this::make($result); } }); }
php
public function zip($items): CollectionInterface { $items = array_map(function ($items) { if ($items instanceof IteratorAggregate) { return $items->getIterator(); } if (is_array($items)) { return new ArrayIterator($items); } return $items; }, func_get_args()); return $this->wrap(function (Iterator $data) use ($items) { foreach ($data as $key => $datum) { $result = [$datum]; /** @var Iterator $item */ foreach ($items as $item) { $result[] = $item->current(); $item->next(); } yield $key => $this::make($result); } }); }
[ "public", "function", "zip", "(", "$", "items", ")", ":", "CollectionInterface", "{", "$", "items", "=", "array_map", "(", "function", "(", "$", "items", ")", "{", "if", "(", "$", "items", "instanceof", "IteratorAggregate", ")", "{", "return", "$", "items", "->", "getIterator", "(", ")", ";", "}", "if", "(", "is_array", "(", "$", "items", ")", ")", "{", "return", "new", "ArrayIterator", "(", "$", "items", ")", ";", "}", "return", "$", "items", ";", "}", ",", "func_get_args", "(", ")", ")", ";", "return", "$", "this", "->", "wrap", "(", "function", "(", "Iterator", "$", "data", ")", "use", "(", "$", "items", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "datum", ")", "{", "$", "result", "=", "[", "$", "datum", "]", ";", "/** @var Iterator $item */", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "result", "[", "]", "=", "$", "item", "->", "current", "(", ")", ";", "$", "item", "->", "next", "(", ")", ";", "}", "yield", "$", "key", "=>", "$", "this", "::", "make", "(", "$", "result", ")", ";", "}", "}", ")", ";", "}" ]
Zip the collection together with one or more arrays. e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]] @param mixed ...$items @return CollectionInterface
[ "Zip", "the", "collection", "together", "with", "one", "or", "more", "arrays", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1258-L1285
buttress/collecterator
src/GeneratorCollection.php
GeneratorCollection.toArray
public function toArray(): array { $generator = function (Iterator $data) { foreach ($data as $key => $item) { if ($item instanceof JsonSerializable) { $item = $item->jsonSerialize(); } yield $key => $item; } }; return iterator_to_array($generator($this->generator)); }
php
public function toArray(): array { $generator = function (Iterator $data) { foreach ($data as $key => $item) { if ($item instanceof JsonSerializable) { $item = $item->jsonSerialize(); } yield $key => $item; } }; return iterator_to_array($generator($this->generator)); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "$", "generator", "=", "function", "(", "Iterator", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "$", "item", "instanceof", "JsonSerializable", ")", "{", "$", "item", "=", "$", "item", "->", "jsonSerialize", "(", ")", ";", "}", "yield", "$", "key", "=>", "$", "item", ";", "}", "}", ";", "return", "iterator_to_array", "(", "$", "generator", "(", "$", "this", "->", "generator", ")", ")", ";", "}" ]
Get the collection of items as a plain array. @return array
[ "Get", "the", "collection", "of", "items", "as", "a", "plain", "array", "." ]
train
https://github.com/buttress/collecterator/blob/21e761c9c0457d85b5ec62d11051de2a62c3ee34/src/GeneratorCollection.php#L1292-L1304
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respond
public function respond(array $data = [], array $headers = []): JsonResponse { $meta = [ 'meta' => [ 'server_time' => time(), 'server_timezone' => date_default_timezone_get(), 'api_version' => 'v1', ], ]; return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers); }
php
public function respond(array $data = [], array $headers = []): JsonResponse { $meta = [ 'meta' => [ 'server_time' => time(), 'server_timezone' => date_default_timezone_get(), 'api_version' => 'v1', ], ]; return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers); }
[ "public", "function", "respond", "(", "array", "$", "data", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ")", ":", "JsonResponse", "{", "$", "meta", "=", "[", "'meta'", "=>", "[", "'server_time'", "=>", "time", "(", ")", ",", "'server_timezone'", "=>", "date_default_timezone_get", "(", ")", ",", "'api_version'", "=>", "'v1'", ",", "]", ",", "]", ";", "return", "response", "(", ")", "->", "json", "(", "array_merge", "(", "$", "data", ",", "$", "meta", ")", ",", "$", "this", "->", "getStatusCode", "(", ")", ",", "$", "headers", ")", ";", "}" ]
Return JSON encoded response. @param array $data @param array $headers @return \Illuminate\Http\JsonResponse
[ "Return", "JSON", "encoded", "response", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L53-L64
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondWithError
public function respondWithError($code = null, $message = null, array $data = []): JsonResponse { return $this->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'exception' => $data, ]); }
php
public function respondWithError($code = null, $message = null, array $data = []): JsonResponse { return $this->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'exception' => $data, ]); }
[ "public", "function", "respondWithError", "(", "$", "code", "=", "null", ",", "$", "message", "=", "null", ",", "array", "$", "data", "=", "[", "]", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "respond", "(", "[", "'status'", "=>", "[", "'type'", "=>", "'error'", ",", "'message'", "=>", "$", "this", "->", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ",", "'code'", "=>", "$", "code", ",", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'exception'", "=>", "$", "data", ",", "]", ")", ";", "}" ]
Return response with error. @param null $code @param null $message @param array $data @return JsonResponse
[ "Return", "response", "with", "error", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L75-L86
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondWithFailure
public function respondWithFailure($code = null, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_BAD_REQUEST)->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
php
public function respondWithFailure($code = null, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_BAD_REQUEST)->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
[ "public", "function", "respondWithFailure", "(", "$", "code", "=", "null", ",", "array", "$", "data", "=", "[", "]", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_BAD_REQUEST", ")", "->", "respond", "(", "[", "'status'", "=>", "[", "'type'", "=>", "'error'", ",", "'message'", "=>", "$", "this", "->", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ",", "'code'", "=>", "$", "code", ",", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'data'", "=>", "$", "data", ",", "]", ")", ";", "}" ]
Returns 400 / Bad request. @param null $code @param array $data @param null $message @return \Illuminate\Http\JsonResponse
[ "Returns", "400", "/", "Bad", "request", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L97-L108
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondUnauthorized
public function respondUnauthorized($message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_UNAUTHORIZED) ->respondWithError(ApiResponse::CODE_NOT_AUTHORIZED, $message); }
php
public function respondUnauthorized($message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_UNAUTHORIZED) ->respondWithError(ApiResponse::CODE_NOT_AUTHORIZED, $message); }
[ "public", "function", "respondUnauthorized", "(", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_UNAUTHORIZED", ")", "->", "respondWithError", "(", "ApiResponse", "::", "CODE_NOT_AUTHORIZED", ",", "$", "message", ")", ";", "}" ]
Returns 401 / Unauthorized. @param string $message @return \Illuminate\Http\JsonResponse
[ "Returns", "401", "/", "Unauthorized", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L117-L121
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondForbidden
public function respondForbidden($message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_FORBIDDEN) ->respondWithError(ApiResponse::CODE_FORBIDDEN, $message); }
php
public function respondForbidden($message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_FORBIDDEN) ->respondWithError(ApiResponse::CODE_FORBIDDEN, $message); }
[ "public", "function", "respondForbidden", "(", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_FORBIDDEN", ")", "->", "respondWithError", "(", "ApiResponse", "::", "CODE_FORBIDDEN", ",", "$", "message", ")", ";", "}" ]
Returns 403 / Forbidden. @param string $message @return \Illuminate\Http\JsonResponse
[ "Returns", "403", "/", "Forbidden", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L130-L134
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondNotFound
public function respondNotFound($code = ApiResponse::CODE_NOT_FOUND, $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_NOT_FOUND) ->respondWithError($code, $message); }
php
public function respondNotFound($code = ApiResponse::CODE_NOT_FOUND, $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_NOT_FOUND) ->respondWithError($code, $message); }
[ "public", "function", "respondNotFound", "(", "$", "code", "=", "ApiResponse", "::", "CODE_NOT_FOUND", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_NOT_FOUND", ")", "->", "respondWithError", "(", "$", "code", ",", "$", "message", ")", ";", "}" ]
Returns 404 / Resource not found response. @param int $code @param null $message @return \Illuminate\Http\JsonResponse
[ "Returns", "404", "/", "Resource", "not", "found", "response", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L144-L148
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondValidationError
public function respondValidationError( $code = ApiResponse::CODE_VALIDATION_ERROR, array $errors = [], $message = null ): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY) ->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'errors' => $errors, ]); }
php
public function respondValidationError( $code = ApiResponse::CODE_VALIDATION_ERROR, array $errors = [], $message = null ): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY) ->respond([ 'status' => [ 'type' => 'error', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'errors' => $errors, ]); }
[ "public", "function", "respondValidationError", "(", "$", "code", "=", "ApiResponse", "::", "CODE_VALIDATION_ERROR", ",", "array", "$", "errors", "=", "[", "]", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_UNPROCESSABLE_ENTITY", ")", "->", "respond", "(", "[", "'status'", "=>", "[", "'type'", "=>", "'error'", ",", "'message'", "=>", "$", "this", "->", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ",", "'code'", "=>", "$", "code", ",", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'errors'", "=>", "$", "errors", ",", "]", ")", ";", "}" ]
Returns 422 / Unprocessable entity response. @param int $code @param array $errors @param string $message @return \Illuminate\Http\JsonResponse
[ "Returns", "422", "/", "Unprocessable", "entity", "response", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L159-L174
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondInternalError
public function respondInternalError($code = ApiResponse::CODE_API_ERROR, $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_INTERNAL_SERVER_ERROR) ->respondWithError($code, $message); }
php
public function respondInternalError($code = ApiResponse::CODE_API_ERROR, $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_INTERNAL_SERVER_ERROR) ->respondWithError($code, $message); }
[ "public", "function", "respondInternalError", "(", "$", "code", "=", "ApiResponse", "::", "CODE_API_ERROR", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_INTERNAL_SERVER_ERROR", ")", "->", "respondWithError", "(", "$", "code", ",", "$", "message", ")", ";", "}" ]
Returns 500 / Internal server error occurred. @param int $code @param null $message @return \Illuminate\Http\JsonResponse
[ "Returns", "500", "/", "Internal", "server", "error", "occurred", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L184-L188
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondWithSuccess
public function respondWithSuccess(array $data = []): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_OK)->respond([ 'status' => [ 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
php
public function respondWithSuccess(array $data = []): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_OK)->respond([ 'status' => [ 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
[ "public", "function", "respondWithSuccess", "(", "array", "$", "data", "=", "[", "]", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_OK", ")", "->", "respond", "(", "[", "'status'", "=>", "[", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'data'", "=>", "$", "data", ",", "]", ")", ";", "}" ]
Returns 200 response with data. @param array $data @return \Illuminate\Http\JsonResponse
[ "Returns", "200", "response", "with", "data", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L197-L205
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondCreated
public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([ 'status' => [ 'type' => 'success', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
php
public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([ 'status' => [ 'type' => 'success', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
[ "public", "function", "respondCreated", "(", "$", "code", "=", "ApiResponse", "::", "CODE_SUCCESS", ",", "array", "$", "data", "=", "[", "]", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_CREATED", ")", "->", "respond", "(", "[", "'status'", "=>", "[", "'type'", "=>", "'success'", ",", "'message'", "=>", "$", "this", "->", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ",", "'code'", "=>", "$", "code", ",", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'data'", "=>", "$", "data", ",", "]", ")", ";", "}" ]
Returns 201 response with data. @param int $code @param array $data @param null $message @return \Illuminate\Http\JsonResponse
[ "Returns", "201", "response", "with", "data", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L216-L227
iocaste/microservice-foundation
src/Http/Responds.php
Responds.respondDeleted
public function respondDeleted($code = ApiResponse::CODE_DELETED, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_NO_CONTENT)->respond([ 'status' => [ 'type' => 'success', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
php
public function respondDeleted($code = ApiResponse::CODE_DELETED, array $data = [], $message = null): JsonResponse { return $this->setStatusCode(IlluminateResponse::HTTP_NO_CONTENT)->respond([ 'status' => [ 'type' => 'success', 'message' => $this->getDefaultMessage($code, $message), 'code' => $code, 'http_code' => $this->getStatusCode(), ], 'data' => $data, ]); }
[ "public", "function", "respondDeleted", "(", "$", "code", "=", "ApiResponse", "::", "CODE_DELETED", ",", "array", "$", "data", "=", "[", "]", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "$", "this", "->", "setStatusCode", "(", "IlluminateResponse", "::", "HTTP_NO_CONTENT", ")", "->", "respond", "(", "[", "'status'", "=>", "[", "'type'", "=>", "'success'", ",", "'message'", "=>", "$", "this", "->", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ",", "'code'", "=>", "$", "code", ",", "'http_code'", "=>", "$", "this", "->", "getStatusCode", "(", ")", ",", "]", ",", "'data'", "=>", "$", "data", ",", "]", ")", ";", "}" ]
Returns 204 response, enacted but the response does not include an entity. @param int $code @param array $data @param string $message @return \Illuminate\Http\JsonResponse
[ "Returns", "204", "response", "enacted", "but", "the", "response", "does", "not", "include", "an", "entity", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L238-L249
iocaste/microservice-foundation
src/Http/Responds.php
Responds.getDefaultMessage
protected function getDefaultMessage($code, $message): string { if ($code !== null && $message === null) { return ApiResponse::$statusTexts[$code]['message']; } return $message; }
php
protected function getDefaultMessage($code, $message): string { if ($code !== null && $message === null) { return ApiResponse::$statusTexts[$code]['message']; } return $message; }
[ "protected", "function", "getDefaultMessage", "(", "$", "code", ",", "$", "message", ")", ":", "string", "{", "if", "(", "$", "code", "!==", "null", "&&", "$", "message", "===", "null", ")", "{", "return", "ApiResponse", "::", "$", "statusTexts", "[", "$", "code", "]", "[", "'message'", "]", ";", "}", "return", "$", "message", ";", "}" ]
Checks if specified code already has default message. @param $code @param $message @return string
[ "Checks", "if", "specified", "code", "already", "has", "default", "message", "." ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Http/Responds.php#L259-L266
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.addStatements
public function addStatements(array $statements) { foreach ($statements as $key => $statement) { $this->addStatement($key, $statement); } return $this; }
php
public function addStatements(array $statements) { foreach ($statements as $key => $statement) { $this->addStatement($key, $statement); } return $this; }
[ "public", "function", "addStatements", "(", "array", "$", "statements", ")", "{", "foreach", "(", "$", "statements", "as", "$", "key", "=>", "$", "statement", ")", "{", "$", "this", "->", "addStatement", "(", "$", "key", ",", "$", "statement", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L215-L221
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatAttributes
public function formatAttributes(array $attributes) { foreach ($attributes as $key => $attr) { if ($attr instanceof Closure) { $attributes[$key] = call_user_func($attr, $this); } else if ($this->hasKeyword($attr)) { $attributes[$key] = $this->getKeyword($attr); } else if ($attr === true) { $attributes[$key] = $this->getKeyword($key); } else { $attributes[$key] = (string) $attr; } } return $attributes; }
php
public function formatAttributes(array $attributes) { foreach ($attributes as $key => $attr) { if ($attr instanceof Closure) { $attributes[$key] = call_user_func($attr, $this); } else if ($this->hasKeyword($attr)) { $attributes[$key] = $this->getKeyword($attr); } else if ($attr === true) { $attributes[$key] = $this->getKeyword($key); } else { $attributes[$key] = (string) $attr; } } return $attributes; }
[ "public", "function", "formatAttributes", "(", "array", "$", "attributes", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "attr", ")", "{", "if", "(", "$", "attr", "instanceof", "Closure", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "call_user_func", "(", "$", "attr", ",", "$", "this", ")", ";", "}", "else", "if", "(", "$", "this", "->", "hasKeyword", "(", "$", "attr", ")", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "this", "->", "getKeyword", "(", "$", "attr", ")", ";", "}", "else", "if", "(", "$", "attr", "===", "true", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "this", "->", "getKeyword", "(", "$", "key", ")", ";", "}", "else", "{", "$", "attributes", "[", "$", "key", "]", "=", "(", "string", ")", "$", "attr", ";", "}", "}", "return", "$", "attributes", ";", "}" ]
Prepare the list of attributes for rendering. If an attribute is found within a keyword, use the keyword. @param array $attributes @return array
[ "Prepare", "the", "list", "of", "attributes", "for", "rendering", ".", "If", "an", "attribute", "is", "found", "within", "a", "keyword", "use", "the", "keyword", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L230-L247
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatColumns
public function formatColumns(Schema $schema) { $columns = []; foreach ($schema->getColumns() as $column => $options) { $dataType = $this->getDriver()->getType($options['type']); $options = $options + $dataType->getDefaultOptions(); $type = $options['type']; if (!empty($options['length'])) { $type .= '(' . $options['length'] . ')'; } $output = [$this->quote($column), strtoupper($type)]; // Integers if (!empty($options['unsigned'])) { $output[] = $this->getKeyword(self::UNSIGNED); } if (!empty($options['zerofill'])) { $output[] = $this->getKeyword(self::ZEROFILL); } // Strings if (!empty($options['charset'])) { $output[] = sprintf($this->getClause(self::CHARACTER_SET), $options['charset']); } if (!empty($options['collate'])) { $output[] = sprintf($this->getClause(self::COLLATE), $options['collate']); } // Primary and uniques can't be null if (!empty($options['primary']) || !empty($options['unique'])) { $output[] = $this->getKeyword(self::NOT_NULL); } else { $output[] = $this->getKeyword(empty($options['null']) ? self::NOT_NULL : self::NULL); } if (array_key_exists('default', $options)) { $output[] = $this->formatDefault($options['default']); } if (!empty($options['ai'])) { $output[] = $this->getKeyword(self::AUTO_INCREMENT); } if (!empty($options['comment'])) { $output[] = sprintf($this->getClause(self::COMMENT), $this->getDriver()->escape(substr($options['comment'], 0, 255))); } $columns[] = trim(implode(' ', $output)); } return implode(",\n", $columns); }
php
public function formatColumns(Schema $schema) { $columns = []; foreach ($schema->getColumns() as $column => $options) { $dataType = $this->getDriver()->getType($options['type']); $options = $options + $dataType->getDefaultOptions(); $type = $options['type']; if (!empty($options['length'])) { $type .= '(' . $options['length'] . ')'; } $output = [$this->quote($column), strtoupper($type)]; // Integers if (!empty($options['unsigned'])) { $output[] = $this->getKeyword(self::UNSIGNED); } if (!empty($options['zerofill'])) { $output[] = $this->getKeyword(self::ZEROFILL); } // Strings if (!empty($options['charset'])) { $output[] = sprintf($this->getClause(self::CHARACTER_SET), $options['charset']); } if (!empty($options['collate'])) { $output[] = sprintf($this->getClause(self::COLLATE), $options['collate']); } // Primary and uniques can't be null if (!empty($options['primary']) || !empty($options['unique'])) { $output[] = $this->getKeyword(self::NOT_NULL); } else { $output[] = $this->getKeyword(empty($options['null']) ? self::NOT_NULL : self::NULL); } if (array_key_exists('default', $options)) { $output[] = $this->formatDefault($options['default']); } if (!empty($options['ai'])) { $output[] = $this->getKeyword(self::AUTO_INCREMENT); } if (!empty($options['comment'])) { $output[] = sprintf($this->getClause(self::COMMENT), $this->getDriver()->escape(substr($options['comment'], 0, 255))); } $columns[] = trim(implode(' ', $output)); } return implode(",\n", $columns); }
[ "public", "function", "formatColumns", "(", "Schema", "$", "schema", ")", "{", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "schema", "->", "getColumns", "(", ")", "as", "$", "column", "=>", "$", "options", ")", "{", "$", "dataType", "=", "$", "this", "->", "getDriver", "(", ")", "->", "getType", "(", "$", "options", "[", "'type'", "]", ")", ";", "$", "options", "=", "$", "options", "+", "$", "dataType", "->", "getDefaultOptions", "(", ")", ";", "$", "type", "=", "$", "options", "[", "'type'", "]", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'length'", "]", ")", ")", "{", "$", "type", ".=", "'('", ".", "$", "options", "[", "'length'", "]", ".", "')'", ";", "}", "$", "output", "=", "[", "$", "this", "->", "quote", "(", "$", "column", ")", ",", "strtoupper", "(", "$", "type", ")", "]", ";", "// Integers", "if", "(", "!", "empty", "(", "$", "options", "[", "'unsigned'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getKeyword", "(", "self", "::", "UNSIGNED", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'zerofill'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getKeyword", "(", "self", "::", "ZEROFILL", ")", ";", "}", "// Strings", "if", "(", "!", "empty", "(", "$", "options", "[", "'charset'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "CHARACTER_SET", ")", ",", "$", "options", "[", "'charset'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'collate'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "COLLATE", ")", ",", "$", "options", "[", "'collate'", "]", ")", ";", "}", "// Primary and uniques can't be null", "if", "(", "!", "empty", "(", "$", "options", "[", "'primary'", "]", ")", "||", "!", "empty", "(", "$", "options", "[", "'unique'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getKeyword", "(", "self", "::", "NOT_NULL", ")", ";", "}", "else", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getKeyword", "(", "empty", "(", "$", "options", "[", "'null'", "]", ")", "?", "self", "::", "NOT_NULL", ":", "self", "::", "NULL", ")", ";", "}", "if", "(", "array_key_exists", "(", "'default'", ",", "$", "options", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "formatDefault", "(", "$", "options", "[", "'default'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'ai'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getKeyword", "(", "self", "::", "AUTO_INCREMENT", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'comment'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "COMMENT", ")", ",", "$", "this", "->", "getDriver", "(", ")", "->", "escape", "(", "substr", "(", "$", "options", "[", "'comment'", "]", ",", "0", ",", "255", ")", ")", ")", ";", "}", "$", "columns", "[", "]", "=", "trim", "(", "implode", "(", "' '", ",", "$", "output", ")", ")", ";", "}", "return", "implode", "(", "\",\\n\"", ",", "$", "columns", ")", ";", "}" ]
Format columns for a table schema. @param \Titon\Db\Driver\Schema $schema @return string
[ "Format", "columns", "for", "a", "table", "schema", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L255-L311
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatCompounds
public function formatCompounds(array $queries) { if (!$queries) { return ''; } // @codeCoverageIgnoreStart if (!method_exists($this, 'buildSelect')) { throw new UnsupportedQueryStatementException('Unions require a buildSelect() method'); } // @codeCoverageIgnoreEnd $output = []; foreach ($queries as $query) { $attributes = $query->getAttributes(); $clause = sprintf($this->getClause($attributes['compound']), trim($this->buildSelect($query), ';')); $attributes = $this->formatAttributes($attributes); if (empty($attributes['flag'])) { $attributes['flag'] = ''; } $output[] = str_replace('{flag}', $attributes['flag'], $clause); } return implode(' ', $output); }
php
public function formatCompounds(array $queries) { if (!$queries) { return ''; } // @codeCoverageIgnoreStart if (!method_exists($this, 'buildSelect')) { throw new UnsupportedQueryStatementException('Unions require a buildSelect() method'); } // @codeCoverageIgnoreEnd $output = []; foreach ($queries as $query) { $attributes = $query->getAttributes(); $clause = sprintf($this->getClause($attributes['compound']), trim($this->buildSelect($query), ';')); $attributes = $this->formatAttributes($attributes); if (empty($attributes['flag'])) { $attributes['flag'] = ''; } $output[] = str_replace('{flag}', $attributes['flag'], $clause); } return implode(' ', $output); }
[ "public", "function", "formatCompounds", "(", "array", "$", "queries", ")", "{", "if", "(", "!", "$", "queries", ")", "{", "return", "''", ";", "}", "// @codeCoverageIgnoreStart", "if", "(", "!", "method_exists", "(", "$", "this", ",", "'buildSelect'", ")", ")", "{", "throw", "new", "UnsupportedQueryStatementException", "(", "'Unions require a buildSelect() method'", ")", ";", "}", "// @codeCoverageIgnoreEnd", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "queries", "as", "$", "query", ")", "{", "$", "attributes", "=", "$", "query", "->", "getAttributes", "(", ")", ";", "$", "clause", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "$", "attributes", "[", "'compound'", "]", ")", ",", "trim", "(", "$", "this", "->", "buildSelect", "(", "$", "query", ")", ",", "';'", ")", ")", ";", "$", "attributes", "=", "$", "this", "->", "formatAttributes", "(", "$", "attributes", ")", ";", "if", "(", "empty", "(", "$", "attributes", "[", "'flag'", "]", ")", ")", "{", "$", "attributes", "[", "'flag'", "]", "=", "''", ";", "}", "$", "output", "[", "]", "=", "str_replace", "(", "'{flag}'", ",", "$", "attributes", "[", "'flag'", "]", ",", "$", "clause", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "output", ")", ";", "}" ]
Format compound queries: union, intersect, exclude. @param \Titon\Db\Query[] $queries @return string @throws \Titon\Db\Exception\UnsupportedQueryStatementException
[ "Format", "compound", "queries", ":", "union", "intersect", "exclude", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L320-L347
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatDefault
public function formatDefault($value) { if ($value === '') { return ''; } if ($value instanceof Closure) { $value = call_user_func($value, $this); } else if (is_string($value) || $value === null) { $value = $this->getDriver()->escape($value); } return sprintf($this->getClause(self::DEFAULT_TO), $value); }
php
public function formatDefault($value) { if ($value === '') { return ''; } if ($value instanceof Closure) { $value = call_user_func($value, $this); } else if (is_string($value) || $value === null) { $value = $this->getDriver()->escape($value); } return sprintf($this->getClause(self::DEFAULT_TO), $value); }
[ "public", "function", "formatDefault", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "''", ")", "{", "return", "''", ";", "}", "if", "(", "$", "value", "instanceof", "Closure", ")", "{", "$", "value", "=", "call_user_func", "(", "$", "value", ",", "$", "this", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "value", ")", "||", "$", "value", "===", "null", ")", "{", "$", "value", "=", "$", "this", "->", "getDriver", "(", ")", "->", "escape", "(", "$", "value", ")", ";", "}", "return", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "DEFAULT_TO", ")", ",", "$", "value", ")", ";", "}" ]
Format the default value of a column. @param mixed $value @return string
[ "Format", "the", "default", "value", "of", "a", "column", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L355-L368
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatExpression
public function formatExpression(Expr $expr) { $field = $expr->getField(); $operator = $expr->getOperator(); $value = $expr->getValue(); if ($operator === Expr::AS_ALIAS) { return sprintf($this->getClause(self::AS_ALIAS), $this->quote($field), $this->quote($value)); // No value to use so exit early } else if (!$expr->useValue() && !($operator === Expr::NULL || $operator === Expr::NOT_NULL)) { return $this->quote($field); } $isSubQuery = ($value instanceof SubQuery); // Function as field if ($field instanceof Func) { $field = $this->formatFunction($field); // Raw expression as field } else if ($field instanceof RawExpr) { $field = $field->getValue(); // Regular clause } else { $field = $this->quote($field); } // IN has special case if ($operator === Expr::IN || $operator === Expr::NOT_IN) { if ($isSubQuery) { $clause = sprintf($this->getClause($operator), $field, '?'); $clause = str_replace(['(', ')'], '', $clause); } else { $clause = sprintf($this->getClause($operator), $field, implode(', ', array_fill(0, count($value), '?'))); } // Operators with clauses } else if ($this->hasClause($operator)) { $clause = sprintf($this->getClause($operator), $field); // Basic operator } else { $clause = sprintf($this->getClause(self::EXPRESSION), $field, $operator); } // Replace ? with sub-query statement if ($isSubQuery) { /** @type \Titon\Db\Query\SubQuery $value */ // EXISTS and NOT EXISTS doesn't have a field or operator if (in_array($value->getFilter(), [SubQuery::EXISTS, SubQuery::NOT_EXISTS], true)) { $clause = $this->formatSubQuery($value); } else { $clause = str_replace('?', $this->formatSubQuery($value), $clause); } } return $clause; }
php
public function formatExpression(Expr $expr) { $field = $expr->getField(); $operator = $expr->getOperator(); $value = $expr->getValue(); if ($operator === Expr::AS_ALIAS) { return sprintf($this->getClause(self::AS_ALIAS), $this->quote($field), $this->quote($value)); // No value to use so exit early } else if (!$expr->useValue() && !($operator === Expr::NULL || $operator === Expr::NOT_NULL)) { return $this->quote($field); } $isSubQuery = ($value instanceof SubQuery); // Function as field if ($field instanceof Func) { $field = $this->formatFunction($field); // Raw expression as field } else if ($field instanceof RawExpr) { $field = $field->getValue(); // Regular clause } else { $field = $this->quote($field); } // IN has special case if ($operator === Expr::IN || $operator === Expr::NOT_IN) { if ($isSubQuery) { $clause = sprintf($this->getClause($operator), $field, '?'); $clause = str_replace(['(', ')'], '', $clause); } else { $clause = sprintf($this->getClause($operator), $field, implode(', ', array_fill(0, count($value), '?'))); } // Operators with clauses } else if ($this->hasClause($operator)) { $clause = sprintf($this->getClause($operator), $field); // Basic operator } else { $clause = sprintf($this->getClause(self::EXPRESSION), $field, $operator); } // Replace ? with sub-query statement if ($isSubQuery) { /** @type \Titon\Db\Query\SubQuery $value */ // EXISTS and NOT EXISTS doesn't have a field or operator if (in_array($value->getFilter(), [SubQuery::EXISTS, SubQuery::NOT_EXISTS], true)) { $clause = $this->formatSubQuery($value); } else { $clause = str_replace('?', $this->formatSubQuery($value), $clause); } } return $clause; }
[ "public", "function", "formatExpression", "(", "Expr", "$", "expr", ")", "{", "$", "field", "=", "$", "expr", "->", "getField", "(", ")", ";", "$", "operator", "=", "$", "expr", "->", "getOperator", "(", ")", ";", "$", "value", "=", "$", "expr", "->", "getValue", "(", ")", ";", "if", "(", "$", "operator", "===", "Expr", "::", "AS_ALIAS", ")", "{", "return", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "AS_ALIAS", ")", ",", "$", "this", "->", "quote", "(", "$", "field", ")", ",", "$", "this", "->", "quote", "(", "$", "value", ")", ")", ";", "// No value to use so exit early", "}", "else", "if", "(", "!", "$", "expr", "->", "useValue", "(", ")", "&&", "!", "(", "$", "operator", "===", "Expr", "::", "NULL", "||", "$", "operator", "===", "Expr", "::", "NOT_NULL", ")", ")", "{", "return", "$", "this", "->", "quote", "(", "$", "field", ")", ";", "}", "$", "isSubQuery", "=", "(", "$", "value", "instanceof", "SubQuery", ")", ";", "// Function as field", "if", "(", "$", "field", "instanceof", "Func", ")", "{", "$", "field", "=", "$", "this", "->", "formatFunction", "(", "$", "field", ")", ";", "// Raw expression as field", "}", "else", "if", "(", "$", "field", "instanceof", "RawExpr", ")", "{", "$", "field", "=", "$", "field", "->", "getValue", "(", ")", ";", "// Regular clause", "}", "else", "{", "$", "field", "=", "$", "this", "->", "quote", "(", "$", "field", ")", ";", "}", "// IN has special case", "if", "(", "$", "operator", "===", "Expr", "::", "IN", "||", "$", "operator", "===", "Expr", "::", "NOT_IN", ")", "{", "if", "(", "$", "isSubQuery", ")", "{", "$", "clause", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "$", "operator", ")", ",", "$", "field", ",", "'?'", ")", ";", "$", "clause", "=", "str_replace", "(", "[", "'('", ",", "')'", "]", ",", "''", ",", "$", "clause", ")", ";", "}", "else", "{", "$", "clause", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "$", "operator", ")", ",", "$", "field", ",", "implode", "(", "', '", ",", "array_fill", "(", "0", ",", "count", "(", "$", "value", ")", ",", "'?'", ")", ")", ")", ";", "}", "// Operators with clauses", "}", "else", "if", "(", "$", "this", "->", "hasClause", "(", "$", "operator", ")", ")", "{", "$", "clause", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "$", "operator", ")", ",", "$", "field", ")", ";", "// Basic operator", "}", "else", "{", "$", "clause", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "EXPRESSION", ")", ",", "$", "field", ",", "$", "operator", ")", ";", "}", "// Replace ? with sub-query statement", "if", "(", "$", "isSubQuery", ")", "{", "/** @type \\Titon\\Db\\Query\\SubQuery $value */", "// EXISTS and NOT EXISTS doesn't have a field or operator", "if", "(", "in_array", "(", "$", "value", "->", "getFilter", "(", ")", ",", "[", "SubQuery", "::", "EXISTS", ",", "SubQuery", "::", "NOT_EXISTS", "]", ",", "true", ")", ")", "{", "$", "clause", "=", "$", "this", "->", "formatSubQuery", "(", "$", "value", ")", ";", "}", "else", "{", "$", "clause", "=", "str_replace", "(", "'?'", ",", "$", "this", "->", "formatSubQuery", "(", "$", "value", ")", ",", "$", "clause", ")", ";", "}", "}", "return", "$", "clause", ";", "}" ]
Format database expressions. @param \Titon\Db\Query\Expr $expr @return string
[ "Format", "database", "expressions", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L376-L436
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatFields
public function formatFields(Query $query) { $joins = $query->getJoins(); $type = $query->getType(); switch ($type) { case Query::INSERT: case Query::MULTI_INSERT: $fields = $query->getData(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for insert query'); } if ($type === Query::MULTI_INSERT) { $fields = $fields[0]; } return '(' . $this->quoteList(array_keys($fields)) . ')'; break; case Query::SELECT: $fields = $query->getFields(); if ($joins) { $columns = $this->formatSelectFields($fields, $query->getRepository()->getAlias()); foreach ($joins as $join) { $fields = $join->getFields(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for join query'); } $columns = array_merge($columns, $this->formatSelectFields($fields, $join->getAlias())); } } else { $columns = $this->formatSelectFields($fields); } return implode(', ', $columns); break; case Query::UPDATE: $fields = $query->getData(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for update query'); } if ($joins) { $values = $this->formatUpdateFields($fields, $query->getRepository()->getAlias()); foreach ($joins as $join) { $values = array_merge($values, $this->formatUpdateFields($join->getFields(), $join->getAlias())); } } else { $values = $this->formatUpdateFields($fields); } return implode(', ', $values); break; case Query::CREATE_INDEX: $fields = $query->getData(); $columns = []; foreach ($fields as $column => $data) { if (is_numeric($column)) { $column = $data; $data = []; } if (is_numeric($data)) { $data = ['length' => $data, 'order' => '', 'collate' => '']; } else if (is_string($data)) { $data = ['length' => '', 'order' => $data, 'collate' => '']; } $column = $this->quote($column); if (!empty($data['length'])) { $column .= sprintf($this->getClause(self::GROUP), $data['length']); } if (!empty($data['collate'])) { $column .= ' ' . sprintf($this->getClause(self::COLLATE), $data['collate']); } if (!empty($data['order'])) { $column .= ' ' . $this->getKeyword($data['order']); } $columns[] = $column; } return implode(', ', $columns); break; } return ''; }
php
public function formatFields(Query $query) { $joins = $query->getJoins(); $type = $query->getType(); switch ($type) { case Query::INSERT: case Query::MULTI_INSERT: $fields = $query->getData(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for insert query'); } if ($type === Query::MULTI_INSERT) { $fields = $fields[0]; } return '(' . $this->quoteList(array_keys($fields)) . ')'; break; case Query::SELECT: $fields = $query->getFields(); if ($joins) { $columns = $this->formatSelectFields($fields, $query->getRepository()->getAlias()); foreach ($joins as $join) { $fields = $join->getFields(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for join query'); } $columns = array_merge($columns, $this->formatSelectFields($fields, $join->getAlias())); } } else { $columns = $this->formatSelectFields($fields); } return implode(', ', $columns); break; case Query::UPDATE: $fields = $query->getData(); if (empty($fields)) { throw new InvalidQueryException('Missing field data for update query'); } if ($joins) { $values = $this->formatUpdateFields($fields, $query->getRepository()->getAlias()); foreach ($joins as $join) { $values = array_merge($values, $this->formatUpdateFields($join->getFields(), $join->getAlias())); } } else { $values = $this->formatUpdateFields($fields); } return implode(', ', $values); break; case Query::CREATE_INDEX: $fields = $query->getData(); $columns = []; foreach ($fields as $column => $data) { if (is_numeric($column)) { $column = $data; $data = []; } if (is_numeric($data)) { $data = ['length' => $data, 'order' => '', 'collate' => '']; } else if (is_string($data)) { $data = ['length' => '', 'order' => $data, 'collate' => '']; } $column = $this->quote($column); if (!empty($data['length'])) { $column .= sprintf($this->getClause(self::GROUP), $data['length']); } if (!empty($data['collate'])) { $column .= ' ' . sprintf($this->getClause(self::COLLATE), $data['collate']); } if (!empty($data['order'])) { $column .= ' ' . $this->getKeyword($data['order']); } $columns[] = $column; } return implode(', ', $columns); break; } return ''; }
[ "public", "function", "formatFields", "(", "Query", "$", "query", ")", "{", "$", "joins", "=", "$", "query", "->", "getJoins", "(", ")", ";", "$", "type", "=", "$", "query", "->", "getType", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "Query", "::", "INSERT", ":", "case", "Query", "::", "MULTI_INSERT", ":", "$", "fields", "=", "$", "query", "->", "getData", "(", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "throw", "new", "InvalidQueryException", "(", "'Missing field data for insert query'", ")", ";", "}", "if", "(", "$", "type", "===", "Query", "::", "MULTI_INSERT", ")", "{", "$", "fields", "=", "$", "fields", "[", "0", "]", ";", "}", "return", "'('", ".", "$", "this", "->", "quoteList", "(", "array_keys", "(", "$", "fields", ")", ")", ".", "')'", ";", "break", ";", "case", "Query", "::", "SELECT", ":", "$", "fields", "=", "$", "query", "->", "getFields", "(", ")", ";", "if", "(", "$", "joins", ")", "{", "$", "columns", "=", "$", "this", "->", "formatSelectFields", "(", "$", "fields", ",", "$", "query", "->", "getRepository", "(", ")", "->", "getAlias", "(", ")", ")", ";", "foreach", "(", "$", "joins", "as", "$", "join", ")", "{", "$", "fields", "=", "$", "join", "->", "getFields", "(", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "throw", "new", "InvalidQueryException", "(", "'Missing field data for join query'", ")", ";", "}", "$", "columns", "=", "array_merge", "(", "$", "columns", ",", "$", "this", "->", "formatSelectFields", "(", "$", "fields", ",", "$", "join", "->", "getAlias", "(", ")", ")", ")", ";", "}", "}", "else", "{", "$", "columns", "=", "$", "this", "->", "formatSelectFields", "(", "$", "fields", ")", ";", "}", "return", "implode", "(", "', '", ",", "$", "columns", ")", ";", "break", ";", "case", "Query", "::", "UPDATE", ":", "$", "fields", "=", "$", "query", "->", "getData", "(", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "throw", "new", "InvalidQueryException", "(", "'Missing field data for update query'", ")", ";", "}", "if", "(", "$", "joins", ")", "{", "$", "values", "=", "$", "this", "->", "formatUpdateFields", "(", "$", "fields", ",", "$", "query", "->", "getRepository", "(", ")", "->", "getAlias", "(", ")", ")", ";", "foreach", "(", "$", "joins", "as", "$", "join", ")", "{", "$", "values", "=", "array_merge", "(", "$", "values", ",", "$", "this", "->", "formatUpdateFields", "(", "$", "join", "->", "getFields", "(", ")", ",", "$", "join", "->", "getAlias", "(", ")", ")", ")", ";", "}", "}", "else", "{", "$", "values", "=", "$", "this", "->", "formatUpdateFields", "(", "$", "fields", ")", ";", "}", "return", "implode", "(", "', '", ",", "$", "values", ")", ";", "break", ";", "case", "Query", "::", "CREATE_INDEX", ":", "$", "fields", "=", "$", "query", "->", "getData", "(", ")", ";", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "column", "=>", "$", "data", ")", "{", "if", "(", "is_numeric", "(", "$", "column", ")", ")", "{", "$", "column", "=", "$", "data", ";", "$", "data", "=", "[", "]", ";", "}", "if", "(", "is_numeric", "(", "$", "data", ")", ")", "{", "$", "data", "=", "[", "'length'", "=>", "$", "data", ",", "'order'", "=>", "''", ",", "'collate'", "=>", "''", "]", ";", "}", "else", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "data", "=", "[", "'length'", "=>", "''", ",", "'order'", "=>", "$", "data", ",", "'collate'", "=>", "''", "]", ";", "}", "$", "column", "=", "$", "this", "->", "quote", "(", "$", "column", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'length'", "]", ")", ")", "{", "$", "column", ".=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "GROUP", ")", ",", "$", "data", "[", "'length'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'collate'", "]", ")", ")", "{", "$", "column", ".=", "' '", ".", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "COLLATE", ")", ",", "$", "data", "[", "'collate'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'order'", "]", ")", ")", "{", "$", "column", ".=", "' '", ".", "$", "this", "->", "getKeyword", "(", "$", "data", "[", "'order'", "]", ")", ";", "}", "$", "columns", "[", "]", "=", "$", "column", ";", "}", "return", "implode", "(", "', '", ",", "$", "columns", ")", ";", "break", ";", "}", "return", "''", ";", "}" ]
Format the fields structure depending on the type of query. @param \Titon\Db\Query $query @return string @throws \Titon\Db\Exception\InvalidQueryException
[ "Format", "the", "fields", "structure", "depending", "on", "the", "type", "of", "query", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L445-L545
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatSelectFields
public function formatSelectFields(array $fields, $alias = null) { $columns = []; $quotedAlias = $alias ? $this->quote($alias) . '.' : ''; $virtualJoins = $this->getConfig('virtualJoins'); if (empty($fields)) { $columns[] = $quotedAlias . '*'; } else { foreach ($fields as $field) { if ($field instanceof Func) { $columns[] = $this->formatFunction($field); } else if ($field instanceof Expr) { $columns[] = $this->formatExpression($field); } else if ($field instanceof RawExpr) { $columns[] = $field->getValue(); // must come after other expressions } else if ($field instanceof SubQuery) { $columns[] = $this->formatSubQuery($field); } else if (preg_match('/^(.*?)\s+AS\s+(.*?)$/i', $field, $matches)) { $columns[] = sprintf($this->getClause(self::AS_ALIAS), $quotedAlias . $this->quote($matches[1]), $this->quote($matches[2])); // Alias the field for drivers that don't support PDO::getColumnMeta() } else if ($virtualJoins && $alias) { $columns[] = sprintf($this->getClause(self::AS_ALIAS), $quotedAlias . $this->quote($field), $alias . '__' . $field); } else { $columns[] = $quotedAlias . $this->quote($field); } } } return $columns; }
php
public function formatSelectFields(array $fields, $alias = null) { $columns = []; $quotedAlias = $alias ? $this->quote($alias) . '.' : ''; $virtualJoins = $this->getConfig('virtualJoins'); if (empty($fields)) { $columns[] = $quotedAlias . '*'; } else { foreach ($fields as $field) { if ($field instanceof Func) { $columns[] = $this->formatFunction($field); } else if ($field instanceof Expr) { $columns[] = $this->formatExpression($field); } else if ($field instanceof RawExpr) { $columns[] = $field->getValue(); // must come after other expressions } else if ($field instanceof SubQuery) { $columns[] = $this->formatSubQuery($field); } else if (preg_match('/^(.*?)\s+AS\s+(.*?)$/i', $field, $matches)) { $columns[] = sprintf($this->getClause(self::AS_ALIAS), $quotedAlias . $this->quote($matches[1]), $this->quote($matches[2])); // Alias the field for drivers that don't support PDO::getColumnMeta() } else if ($virtualJoins && $alias) { $columns[] = sprintf($this->getClause(self::AS_ALIAS), $quotedAlias . $this->quote($field), $alias . '__' . $field); } else { $columns[] = $quotedAlias . $this->quote($field); } } } return $columns; }
[ "public", "function", "formatSelectFields", "(", "array", "$", "fields", ",", "$", "alias", "=", "null", ")", "{", "$", "columns", "=", "[", "]", ";", "$", "quotedAlias", "=", "$", "alias", "?", "$", "this", "->", "quote", "(", "$", "alias", ")", ".", "'.'", ":", "''", ";", "$", "virtualJoins", "=", "$", "this", "->", "getConfig", "(", "'virtualJoins'", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "$", "columns", "[", "]", "=", "$", "quotedAlias", ".", "'*'", ";", "}", "else", "{", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "$", "field", "instanceof", "Func", ")", "{", "$", "columns", "[", "]", "=", "$", "this", "->", "formatFunction", "(", "$", "field", ")", ";", "}", "else", "if", "(", "$", "field", "instanceof", "Expr", ")", "{", "$", "columns", "[", "]", "=", "$", "this", "->", "formatExpression", "(", "$", "field", ")", ";", "}", "else", "if", "(", "$", "field", "instanceof", "RawExpr", ")", "{", "$", "columns", "[", "]", "=", "$", "field", "->", "getValue", "(", ")", ";", "// must come after other expressions", "}", "else", "if", "(", "$", "field", "instanceof", "SubQuery", ")", "{", "$", "columns", "[", "]", "=", "$", "this", "->", "formatSubQuery", "(", "$", "field", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'/^(.*?)\\s+AS\\s+(.*?)$/i'", ",", "$", "field", ",", "$", "matches", ")", ")", "{", "$", "columns", "[", "]", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "AS_ALIAS", ")", ",", "$", "quotedAlias", ".", "$", "this", "->", "quote", "(", "$", "matches", "[", "1", "]", ")", ",", "$", "this", "->", "quote", "(", "$", "matches", "[", "2", "]", ")", ")", ";", "// Alias the field for drivers that don't support PDO::getColumnMeta()", "}", "else", "if", "(", "$", "virtualJoins", "&&", "$", "alias", ")", "{", "$", "columns", "[", "]", "=", "sprintf", "(", "$", "this", "->", "getClause", "(", "self", "::", "AS_ALIAS", ")", ",", "$", "quotedAlias", ".", "$", "this", "->", "quote", "(", "$", "field", ")", ",", "$", "alias", ".", "'__'", ".", "$", "field", ")", ";", "}", "else", "{", "$", "columns", "[", "]", "=", "$", "quotedAlias", ".", "$", "this", "->", "quote", "(", "$", "field", ")", ";", "}", "}", "}", "return", "$", "columns", ";", "}" ]
Format a list of fields for a SELECT statement and apply an optional alias. @param array $fields @param string $alias @return array
[ "Format", "a", "list", "of", "fields", "for", "a", "SELECT", "statement", "and", "apply", "an", "optional", "alias", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L554-L590
titon/db
src/Titon/Db/Driver/Dialect/AbstractDialect.php
AbstractDialect.formatUpdateFields
public function formatUpdateFields(array $fields, $alias = null) { $columns = []; if ($alias) { $alias = $this->quote($alias) . '.'; } foreach ($fields as $key => $value) { if ($value instanceof Expr) { $columns[] = $alias . $this->quote($key) . ' = ' . $this->formatExpression($value); } else { $columns[] = $alias . $this->quote($key) . ' = ?'; } } return $columns; }
php
public function formatUpdateFields(array $fields, $alias = null) { $columns = []; if ($alias) { $alias = $this->quote($alias) . '.'; } foreach ($fields as $key => $value) { if ($value instanceof Expr) { $columns[] = $alias . $this->quote($key) . ' = ' . $this->formatExpression($value); } else { $columns[] = $alias . $this->quote($key) . ' = ?'; } } return $columns; }
[ "public", "function", "formatUpdateFields", "(", "array", "$", "fields", ",", "$", "alias", "=", "null", ")", "{", "$", "columns", "=", "[", "]", ";", "if", "(", "$", "alias", ")", "{", "$", "alias", "=", "$", "this", "->", "quote", "(", "$", "alias", ")", ".", "'.'", ";", "}", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Expr", ")", "{", "$", "columns", "[", "]", "=", "$", "alias", ".", "$", "this", "->", "quote", "(", "$", "key", ")", ".", "' = '", ".", "$", "this", "->", "formatExpression", "(", "$", "value", ")", ";", "}", "else", "{", "$", "columns", "[", "]", "=", "$", "alias", ".", "$", "this", "->", "quote", "(", "$", "key", ")", ".", "' = ?'", ";", "}", "}", "return", "$", "columns", ";", "}" ]
Format a list of fields for a SELECT statement and apply an optional alias. @param array $fields @param string $alias @return array
[ "Format", "a", "list", "of", "fields", "for", "a", "SELECT", "statement", "and", "apply", "an", "optional", "alias", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L599-L616