repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
DocumentPersister.loadReferenceManyWithRepositoryMethod
private function loadReferenceManyWithRepositoryMethod(PersistentCollectionInterface $collection) { $iterator = $this->createReferenceManyWithRepositoryMethodIterator($collection); $mapping = $collection->getMapping(); $documents = $iterator->toArray(); foreach ($documents as $key => $obj) { if ($mapping->type === Type::MAP) { $collection->set($key, $obj); } else { $collection->add($obj); } } }
php
private function loadReferenceManyWithRepositoryMethod(PersistentCollectionInterface $collection) { $iterator = $this->createReferenceManyWithRepositoryMethodIterator($collection); $mapping = $collection->getMapping(); $documents = $iterator->toArray(); foreach ($documents as $key => $obj) { if ($mapping->type === Type::MAP) { $collection->set($key, $obj); } else { $collection->add($obj); } } }
[ "private", "function", "loadReferenceManyWithRepositoryMethod", "(", "PersistentCollectionInterface", "$", "collection", ")", "{", "$", "iterator", "=", "$", "this", "->", "createReferenceManyWithRepositoryMethodIterator", "(", "$", "collection", ")", ";", "$", "mapping", "=", "$", "collection", "->", "getMapping", "(", ")", ";", "$", "documents", "=", "$", "iterator", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "documents", "as", "$", "key", "=>", "$", "obj", ")", "{", "if", "(", "$", "mapping", "->", "type", "===", "Type", "::", "MAP", ")", "{", "$", "collection", "->", "set", "(", "$", "key", ",", "$", "obj", ")", ";", "}", "else", "{", "$", "collection", "->", "add", "(", "$", "obj", ")", ";", "}", "}", "}" ]
Populate a ReferenceMany association with a custom repository method. @param PersistentCollectionInterface $collection @return void
[ "Populate", "a", "ReferenceMany", "association", "with", "a", "custom", "repository", "method", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L565-L577
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
DocumentPersister.lock
public function lock($document, $lockMode) { $qb = $this->dm->createQueryBuilder($this->class->name); $identifier = $this->uow->getDocumentIdentifier($document); $lockMapping = $this->class->lockMetadata; $qb->update(); $qb->setIdentifier($identifier); $qb->attr($lockMapping->name)->set($lockMode); $qb->getQuery()->execute(); $lockMapping->setValue($document, $lockMode); }
php
public function lock($document, $lockMode) { $qb = $this->dm->createQueryBuilder($this->class->name); $identifier = $this->uow->getDocumentIdentifier($document); $lockMapping = $this->class->lockMetadata; $qb->update(); $qb->setIdentifier($identifier); $qb->attr($lockMapping->name)->set($lockMode); $qb->getQuery()->execute(); $lockMapping->setValue($document, $lockMode); }
[ "public", "function", "lock", "(", "$", "document", ",", "$", "lockMode", ")", "{", "$", "qb", "=", "$", "this", "->", "dm", "->", "createQueryBuilder", "(", "$", "this", "->", "class", "->", "name", ")", ";", "$", "identifier", "=", "$", "this", "->", "uow", "->", "getDocumentIdentifier", "(", "$", "document", ")", ";", "$", "lockMapping", "=", "$", "this", "->", "class", "->", "lockMetadata", ";", "$", "qb", "->", "update", "(", ")", ";", "$", "qb", "->", "setIdentifier", "(", "$", "identifier", ")", ";", "$", "qb", "->", "attr", "(", "$", "lockMapping", "->", "name", ")", "->", "set", "(", "$", "lockMode", ")", ";", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "$", "lockMapping", "->", "setValue", "(", "$", "document", ",", "$", "lockMode", ")", ";", "}" ]
Locks document by storing the lock mode on the mapped lock attribute. @param object $document @param int $lockMode @return void
[ "Locks", "document", "by", "storing", "the", "lock", "mode", "on", "the", "mapped", "lock", "attribute", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L587-L600
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
DocumentPersister.upsert
public function upsert($document, $parentPath = null) { $class = $this->dm->getClassMetadata(get_class($document)); $changeset = $this->uow->getDocumentChangeSet($document); if (!$class->isEmbeddedDocument) { $qb = $this->dm->createQueryBuilder($class->name); $identifier = $class->createIdentifier($document); $qb->update(); $qb->setIdentifier($identifier); } elseif ($parentPath === null) { throw new \InvalidArgumentException; } foreach ($changeset as $attributeName => $change) { if ($class->isIdentifier($attributeName)) { continue; } list($old, $new) = $change; $mapping = $class->getPropertyMetadata($attributeName); $discriminatorValue = null; if ($mapping->embedded && $mapping->isOne()) { $embeddedClassName = get_class($new); $embeddedClass = $this->dm->getClassMetadata($embeddedClassName); $discriminatorValue = $embeddedClass->getEmbeddedDiscriminatorValue($mapping, $new); //@Many will set discriminator in updatePath } if ($class->isEmbeddedDocument) { $path = $parentPath->map($attributeName, $discriminatorValue); } else { $path = $qb->attr($attributeName, $discriminatorValue); } $this->updatePath($path, $old, $new, true); } // add discriminator if the class has one if ($class->discriminatorAttribute !== null) { if ($class->isEmbeddedDocument) { $path = $parentPath->map($class->discriminatorAttribute); } else { $path = $qb->attr($class->discriminatorAttribute); } $path->set( $class->discriminatorValue !== null ? $class->discriminatorValue : $class->name ); } if ($this->class->isVersioned) { // Set the initial version. Only supported on top-level documents. $versionMapping = $this->class->getPropertyMetadata($this->class->versionAttribute); $nextVersion = null; if ($versionMapping->type === Type::INT) { $nextVersion = max(1, (int)$versionMapping->getValue($document)); } elseif ($versionMapping->isDateType()) { $nextVersion = new \DateTime(); } $nextVersion = $versionMapping->getType()->convertToDatabaseValue($nextVersion); $versionMapping->setValue($document, $nextVersion); $qb->attr($versionMapping->name)->set($nextVersion); } //DynamoDB will upsert even if we only pass the id conditional with no UpdateExpression if (!$class->isEmbeddedDocument) { $qb->getQuery()->execute(); } }
php
public function upsert($document, $parentPath = null) { $class = $this->dm->getClassMetadata(get_class($document)); $changeset = $this->uow->getDocumentChangeSet($document); if (!$class->isEmbeddedDocument) { $qb = $this->dm->createQueryBuilder($class->name); $identifier = $class->createIdentifier($document); $qb->update(); $qb->setIdentifier($identifier); } elseif ($parentPath === null) { throw new \InvalidArgumentException; } foreach ($changeset as $attributeName => $change) { if ($class->isIdentifier($attributeName)) { continue; } list($old, $new) = $change; $mapping = $class->getPropertyMetadata($attributeName); $discriminatorValue = null; if ($mapping->embedded && $mapping->isOne()) { $embeddedClassName = get_class($new); $embeddedClass = $this->dm->getClassMetadata($embeddedClassName); $discriminatorValue = $embeddedClass->getEmbeddedDiscriminatorValue($mapping, $new); //@Many will set discriminator in updatePath } if ($class->isEmbeddedDocument) { $path = $parentPath->map($attributeName, $discriminatorValue); } else { $path = $qb->attr($attributeName, $discriminatorValue); } $this->updatePath($path, $old, $new, true); } // add discriminator if the class has one if ($class->discriminatorAttribute !== null) { if ($class->isEmbeddedDocument) { $path = $parentPath->map($class->discriminatorAttribute); } else { $path = $qb->attr($class->discriminatorAttribute); } $path->set( $class->discriminatorValue !== null ? $class->discriminatorValue : $class->name ); } if ($this->class->isVersioned) { // Set the initial version. Only supported on top-level documents. $versionMapping = $this->class->getPropertyMetadata($this->class->versionAttribute); $nextVersion = null; if ($versionMapping->type === Type::INT) { $nextVersion = max(1, (int)$versionMapping->getValue($document)); } elseif ($versionMapping->isDateType()) { $nextVersion = new \DateTime(); } $nextVersion = $versionMapping->getType()->convertToDatabaseValue($nextVersion); $versionMapping->setValue($document, $nextVersion); $qb->attr($versionMapping->name)->set($nextVersion); } //DynamoDB will upsert even if we only pass the id conditional with no UpdateExpression if (!$class->isEmbeddedDocument) { $qb->getQuery()->execute(); } }
[ "public", "function", "upsert", "(", "$", "document", ",", "$", "parentPath", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "changeset", "=", "$", "this", "->", "uow", "->", "getDocumentChangeSet", "(", "$", "document", ")", ";", "if", "(", "!", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "qb", "=", "$", "this", "->", "dm", "->", "createQueryBuilder", "(", "$", "class", "->", "name", ")", ";", "$", "identifier", "=", "$", "class", "->", "createIdentifier", "(", "$", "document", ")", ";", "$", "qb", "->", "update", "(", ")", ";", "$", "qb", "->", "setIdentifier", "(", "$", "identifier", ")", ";", "}", "elseif", "(", "$", "parentPath", "===", "null", ")", "{", "throw", "new", "\\", "InvalidArgumentException", ";", "}", "foreach", "(", "$", "changeset", "as", "$", "attributeName", "=>", "$", "change", ")", "{", "if", "(", "$", "class", "->", "isIdentifier", "(", "$", "attributeName", ")", ")", "{", "continue", ";", "}", "list", "(", "$", "old", ",", "$", "new", ")", "=", "$", "change", ";", "$", "mapping", "=", "$", "class", "->", "getPropertyMetadata", "(", "$", "attributeName", ")", ";", "$", "discriminatorValue", "=", "null", ";", "if", "(", "$", "mapping", "->", "embedded", "&&", "$", "mapping", "->", "isOne", "(", ")", ")", "{", "$", "embeddedClassName", "=", "get_class", "(", "$", "new", ")", ";", "$", "embeddedClass", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "embeddedClassName", ")", ";", "$", "discriminatorValue", "=", "$", "embeddedClass", "->", "getEmbeddedDiscriminatorValue", "(", "$", "mapping", ",", "$", "new", ")", ";", "//@Many will set discriminator in updatePath", "}", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "path", "=", "$", "parentPath", "->", "map", "(", "$", "attributeName", ",", "$", "discriminatorValue", ")", ";", "}", "else", "{", "$", "path", "=", "$", "qb", "->", "attr", "(", "$", "attributeName", ",", "$", "discriminatorValue", ")", ";", "}", "$", "this", "->", "updatePath", "(", "$", "path", ",", "$", "old", ",", "$", "new", ",", "true", ")", ";", "}", "// add discriminator if the class has one", "if", "(", "$", "class", "->", "discriminatorAttribute", "!==", "null", ")", "{", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "path", "=", "$", "parentPath", "->", "map", "(", "$", "class", "->", "discriminatorAttribute", ")", ";", "}", "else", "{", "$", "path", "=", "$", "qb", "->", "attr", "(", "$", "class", "->", "discriminatorAttribute", ")", ";", "}", "$", "path", "->", "set", "(", "$", "class", "->", "discriminatorValue", "!==", "null", "?", "$", "class", "->", "discriminatorValue", ":", "$", "class", "->", "name", ")", ";", "}", "if", "(", "$", "this", "->", "class", "->", "isVersioned", ")", "{", "// Set the initial version. Only supported on top-level documents.", "$", "versionMapping", "=", "$", "this", "->", "class", "->", "getPropertyMetadata", "(", "$", "this", "->", "class", "->", "versionAttribute", ")", ";", "$", "nextVersion", "=", "null", ";", "if", "(", "$", "versionMapping", "->", "type", "===", "Type", "::", "INT", ")", "{", "$", "nextVersion", "=", "max", "(", "1", ",", "(", "int", ")", "$", "versionMapping", "->", "getValue", "(", "$", "document", ")", ")", ";", "}", "elseif", "(", "$", "versionMapping", "->", "isDateType", "(", ")", ")", "{", "$", "nextVersion", "=", "new", "\\", "DateTime", "(", ")", ";", "}", "$", "nextVersion", "=", "$", "versionMapping", "->", "getType", "(", ")", "->", "convertToDatabaseValue", "(", "$", "nextVersion", ")", ";", "$", "versionMapping", "->", "setValue", "(", "$", "document", ",", "$", "nextVersion", ")", ";", "$", "qb", "->", "attr", "(", "$", "versionMapping", "->", "name", ")", "->", "set", "(", "$", "nextVersion", ")", ";", "}", "//DynamoDB will upsert even if we only pass the id conditional with no UpdateExpression", "if", "(", "!", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "qb", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "}", "}" ]
Update a document if it already exists in DynamoDB, or insert if it does not. @param object $document @param RootPath|null $parentPath For embedded documents, the QueryBuilder object representing the top-level document path. @return void
[ "Update", "a", "document", "if", "it", "already", "exists", "in", "DynamoDB", "or", "insert", "if", "it", "does", "not", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L881-L960
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php
Identifier.addToQueryCondition
public function addToQueryCondition(Expr $expr) { $expr->attr($this->getHashKey()->getPropertyMetadata()->name)->equals($this->getHashValue()); }
php
public function addToQueryCondition(Expr $expr) { $expr->attr($this->getHashKey()->getPropertyMetadata()->name)->equals($this->getHashValue()); }
[ "public", "function", "addToQueryCondition", "(", "Expr", "$", "expr", ")", "{", "$", "expr", "->", "attr", "(", "$", "this", "->", "getHashKey", "(", ")", "->", "getPropertyMetadata", "(", ")", "->", "name", ")", "->", "equals", "(", "$", "this", "->", "getHashValue", "(", ")", ")", ";", "}" ]
Add a conditon for this identifer's values to the provided query expression. @param Expr $expr @return void
[ "Add", "a", "conditon", "for", "this", "identifer", "s", "values", "to", "the", "provided", "query", "expression", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php#L75-L78
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php
Identifier.getDocument
public function getDocument(DocumentManager $dm) { // Check identity map first, if its already in there just return it. $document = $dm->getUnitOfWork()->tryGetByIdentifier($this); if ($document !== false) { return $document; } $document = $dm->getProxyFactory()->getProxy($this->class->getName(), $this->getArray()); $dm->getUnitOfWork()->registerManaged($document, $this, []); return $document; }
php
public function getDocument(DocumentManager $dm) { // Check identity map first, if its already in there just return it. $document = $dm->getUnitOfWork()->tryGetByIdentifier($this); if ($document !== false) { return $document; } $document = $dm->getProxyFactory()->getProxy($this->class->getName(), $this->getArray()); $dm->getUnitOfWork()->registerManaged($document, $this, []); return $document; }
[ "public", "function", "getDocument", "(", "DocumentManager", "$", "dm", ")", "{", "// Check identity map first, if its already in there just return it.", "$", "document", "=", "$", "dm", "->", "getUnitOfWork", "(", ")", "->", "tryGetByIdentifier", "(", "$", "this", ")", ";", "if", "(", "$", "document", "!==", "false", ")", "{", "return", "$", "document", ";", "}", "$", "document", "=", "$", "dm", "->", "getProxyFactory", "(", ")", "->", "getProxy", "(", "$", "this", "->", "class", "->", "getName", "(", ")", ",", "$", "this", "->", "getArray", "(", ")", ")", ";", "$", "dm", "->", "getUnitOfWork", "(", ")", "->", "registerManaged", "(", "$", "document", ",", "$", "this", ",", "[", "]", ")", ";", "return", "$", "document", ";", "}" ]
Gets a reference to the target document without actually loading it. If partial objects are allowed, this method will return a partial object that only has its identifier populated. Otherwise a proxy is returned that automatically loads itself on first access. @param DocumentManager $dm @return object The document reference.
[ "Gets", "a", "reference", "to", "the", "target", "document", "without", "actually", "loading", "it", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php#L113-L125
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php
Identifier.getDocumentPartial
public function getDocumentPartial(DocumentManager $dm) { // Check identity map first, if its already in there just return it. $document = $dm->getUnitOfWork()->tryGetByIdentifier($this); if ($document !== false) { return $document; } $document = $this->class->newInstance(); $this->addToDocument($document); $dm->getUnitOfWork()->registerManaged($document, $this, []); return $document; }
php
public function getDocumentPartial(DocumentManager $dm) { // Check identity map first, if its already in there just return it. $document = $dm->getUnitOfWork()->tryGetByIdentifier($this); if ($document !== false) { return $document; } $document = $this->class->newInstance(); $this->addToDocument($document); $dm->getUnitOfWork()->registerManaged($document, $this, []); return $document; }
[ "public", "function", "getDocumentPartial", "(", "DocumentManager", "$", "dm", ")", "{", "// Check identity map first, if its already in there just return it.", "$", "document", "=", "$", "dm", "->", "getUnitOfWork", "(", ")", "->", "tryGetByIdentifier", "(", "$", "this", ")", ";", "if", "(", "$", "document", "!==", "false", ")", "{", "return", "$", "document", ";", "}", "$", "document", "=", "$", "this", "->", "class", "->", "newInstance", "(", ")", ";", "$", "this", "->", "addToDocument", "(", "$", "document", ")", ";", "$", "dm", "->", "getUnitOfWork", "(", ")", "->", "registerManaged", "(", "$", "document", ",", "$", "this", ",", "[", "]", ")", ";", "return", "$", "document", ";", "}" ]
Gets a partial reference to the target document without actually loading it, if the document is not yet loaded. The returned reference may be a partial object if the document is not yet loaded/managed. If it is a partial object it will not initialize the rest of the document state on access. Thus you can only ever safely access the identifier of a document obtained through this method. The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update a document without loading it. Note, however, that in the latter case the original (persistent) document data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place. @param DocumentManager $dm @return object The (partial) document reference.
[ "Gets", "a", "partial", "reference", "to", "the", "target", "document", "without", "actually", "loading", "it", "if", "the", "document", "is", "not", "yet", "loaded", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Schema/Identifier/Identifier.php#L146-L159
train
Beotie/Beotie-PSR7-stream
src/Stream/FileInfoComponent/MetadataComponent.php
MetadataComponent.isMetadataMethod
protected function isMetadataMethod(string &$subject, int $key, string $pattern) { unset($key); if (!preg_match($pattern, $subject)) { $subject = false; } return; }
php
protected function isMetadataMethod(string &$subject, int $key, string $pattern) { unset($key); if (!preg_match($pattern, $subject)) { $subject = false; } return; }
[ "protected", "function", "isMetadataMethod", "(", "string", "&", "$", "subject", ",", "int", "$", "key", ",", "string", "$", "pattern", ")", "{", "unset", "(", "$", "key", ")", ";", "if", "(", "!", "preg_match", "(", "$", "pattern", ",", "$", "subject", ")", ")", "{", "$", "subject", "=", "false", ";", "}", "return", ";", "}" ]
Is metadata method Update the method as subject is is not matching the given patter to false @param string $subject The subject @param int $key The subject key @param string $pattern The matching pattern @return void
[ "Is", "metadata", "method" ]
8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca
https://github.com/Beotie/Beotie-PSR7-stream/blob/8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca/src/Stream/FileInfoComponent/MetadataComponent.php#L104-L112
train
shgysk8zer0/core_api
traits/magic/domdocument.php
DOMDocument._nodeBuilder
final protected function _nodeBuilder($key, $value = null, \DOMNode &$parent = null) { if (is_null($parent)) { $parent = $this; } if (is_string($key)) { if (substr($key, 0, 1) === '@' and (is_string($value) or is_numeric($value))) { $parent->setAttribute(substr($key, 1), $value); } else { $node = $parent->appendChild($this->createElement($key)); if (is_string($value)) { $node->appendChild($this->createTextNode($value)); } elseif ($value instanceof \DOMNode) { $node->appendChild($content); } elseif (is_array($value) or (is_object($value) and $value = get_object_vars($value))) { foreach ($value as $k => $v) { $this->{__FUNCTION__}($k, $v, $node); unset($k, $v); } } } } elseif (is_string($value)) { $parent->appendChild($this->createTextNode($value)); } elseif ($value instanceof \DOMNode) { $parent->appendChild($value); } elseif (is_array($value) or is_object($value) and $value = get_object_vars($value)) { foreach ($value as $k => $v) { $this->{__FUNCTION__}($k, $v, $node); unset($k, $v); } } }
php
final protected function _nodeBuilder($key, $value = null, \DOMNode &$parent = null) { if (is_null($parent)) { $parent = $this; } if (is_string($key)) { if (substr($key, 0, 1) === '@' and (is_string($value) or is_numeric($value))) { $parent->setAttribute(substr($key, 1), $value); } else { $node = $parent->appendChild($this->createElement($key)); if (is_string($value)) { $node->appendChild($this->createTextNode($value)); } elseif ($value instanceof \DOMNode) { $node->appendChild($content); } elseif (is_array($value) or (is_object($value) and $value = get_object_vars($value))) { foreach ($value as $k => $v) { $this->{__FUNCTION__}($k, $v, $node); unset($k, $v); } } } } elseif (is_string($value)) { $parent->appendChild($this->createTextNode($value)); } elseif ($value instanceof \DOMNode) { $parent->appendChild($value); } elseif (is_array($value) or is_object($value) and $value = get_object_vars($value)) { foreach ($value as $k => $v) { $this->{__FUNCTION__}($k, $v, $node); unset($k, $v); } } }
[ "final", "protected", "function", "_nodeBuilder", "(", "$", "key", ",", "$", "value", "=", "null", ",", "\\", "DOMNode", "&", "$", "parent", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "parent", ")", ")", "{", "$", "parent", "=", "$", "this", ";", "}", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "if", "(", "substr", "(", "$", "key", ",", "0", ",", "1", ")", "===", "'@'", "and", "(", "is_string", "(", "$", "value", ")", "or", "is_numeric", "(", "$", "value", ")", ")", ")", "{", "$", "parent", "->", "setAttribute", "(", "substr", "(", "$", "key", ",", "1", ")", ",", "$", "value", ")", ";", "}", "else", "{", "$", "node", "=", "$", "parent", "->", "appendChild", "(", "$", "this", "->", "createElement", "(", "$", "key", ")", ")", ";", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "node", "->", "appendChild", "(", "$", "this", "->", "createTextNode", "(", "$", "value", ")", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "\\", "DOMNode", ")", "{", "$", "node", "->", "appendChild", "(", "$", "content", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", "or", "(", "is_object", "(", "$", "value", ")", "and", "$", "value", "=", "get_object_vars", "(", "$", "value", ")", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "{", "__FUNCTION__", "}", "(", "$", "k", ",", "$", "v", ",", "$", "node", ")", ";", "unset", "(", "$", "k", ",", "$", "v", ")", ";", "}", "}", "}", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "parent", "->", "appendChild", "(", "$", "this", "->", "createTextNode", "(", "$", "value", ")", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "\\", "DOMNode", ")", "{", "$", "parent", "->", "appendChild", "(", "$", "value", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", "or", "is_object", "(", "$", "value", ")", "and", "$", "value", "=", "get_object_vars", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "{", "__FUNCTION__", "}", "(", "$", "k", ",", "$", "v", ",", "$", "node", ")", ";", "unset", "(", "$", "k", ",", "$", "v", ")", ";", "}", "}", "}" ]
Dynamically and seemingly magically build nodes and append to parent @param mixed $key Int or string to become tagname of new node @param mixed $value String, array, sdtClass object, DOMNode @param \DOMNode $parent Parent element to append to (defaults to $this) @return void
[ "Dynamically", "and", "seemingly", "magically", "build", "nodes", "and", "append", "to", "parent" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/magic/domdocument.php#L149-L180
train
cubicmushroom/valueobjects
src/Structure/Collection.php
Collection.fromNative
public static function fromNative() { $array = \func_get_arg(0); $items = array(); foreach ($array as $item) { if ($item instanceof \Traversable || \is_array($item)) { $items[] = static::fromNative($item); } else { $items[] = new StringLiteral(\strval($item)); } } $fixedArray = \SplFixedArray::fromArray($items); return new static($fixedArray); }
php
public static function fromNative() { $array = \func_get_arg(0); $items = array(); foreach ($array as $item) { if ($item instanceof \Traversable || \is_array($item)) { $items[] = static::fromNative($item); } else { $items[] = new StringLiteral(\strval($item)); } } $fixedArray = \SplFixedArray::fromArray($items); return new static($fixedArray); }
[ "public", "static", "function", "fromNative", "(", ")", "{", "$", "array", "=", "\\", "func_get_arg", "(", "0", ")", ";", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "item", ")", "{", "if", "(", "$", "item", "instanceof", "\\", "Traversable", "||", "\\", "is_array", "(", "$", "item", ")", ")", "{", "$", "items", "[", "]", "=", "static", "::", "fromNative", "(", "$", "item", ")", ";", "}", "else", "{", "$", "items", "[", "]", "=", "new", "StringLiteral", "(", "\\", "strval", "(", "$", "item", ")", ")", ";", "}", "}", "$", "fixedArray", "=", "\\", "SplFixedArray", "::", "fromArray", "(", "$", "items", ")", ";", "return", "new", "static", "(", "$", "fixedArray", ")", ";", "}" ]
Returns a new Collection object @param \SplFixedArray $array @return self
[ "Returns", "a", "new", "Collection", "object" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Structure/Collection.php#L21-L37
train
cubicmushroom/valueobjects
src/Structure/Collection.php
Collection.contains
public function contains(ValueObjectInterface $object) { foreach ($this->items as $item) { if ($item->sameValueAs($object)) { return true; } } return false; }
php
public function contains(ValueObjectInterface $object) { foreach ($this->items as $item) { if ($item->sameValueAs($object)) { return true; } } return false; }
[ "public", "function", "contains", "(", "ValueObjectInterface", "$", "object", ")", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "sameValueAs", "(", "$", "object", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Tells whether the Collection contains an object @param ValueObjectInterface $object @return bool
[ "Tells", "whether", "the", "Collection", "contains", "an", "object" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Structure/Collection.php#L95-L104
train
drdplusinfo/drdplus-fight-properties
DrdPlus/FightProperties/FightProperties.php
FightProperties.getShieldHolding
private function getShieldHolding(): ItemHoldingCode { if ($this->weaponlikeHolding->holdsByMainHand()) { return ItemHoldingCode::getIt(ItemHoldingCode::OFFHAND); } if ($this->weaponlikeHolding->holdsByOffhand()) { return ItemHoldingCode::getIt(ItemHoldingCode::MAIN_HAND); } // two hands holding if ($this->shield->getValue() === ShieldCode::WITHOUT_SHIELD) { return ItemHoldingCode::getIt(ItemHoldingCode::MAIN_HAND); } throw new Exceptions\NoHandLeftForShield( "Can not hold {$this->shield} when holding {$this->weaponlike} with {$this->weaponlikeHolding}" ); }
php
private function getShieldHolding(): ItemHoldingCode { if ($this->weaponlikeHolding->holdsByMainHand()) { return ItemHoldingCode::getIt(ItemHoldingCode::OFFHAND); } if ($this->weaponlikeHolding->holdsByOffhand()) { return ItemHoldingCode::getIt(ItemHoldingCode::MAIN_HAND); } // two hands holding if ($this->shield->getValue() === ShieldCode::WITHOUT_SHIELD) { return ItemHoldingCode::getIt(ItemHoldingCode::MAIN_HAND); } throw new Exceptions\NoHandLeftForShield( "Can not hold {$this->shield} when holding {$this->weaponlike} with {$this->weaponlikeHolding}" ); }
[ "private", "function", "getShieldHolding", "(", ")", ":", "ItemHoldingCode", "{", "if", "(", "$", "this", "->", "weaponlikeHolding", "->", "holdsByMainHand", "(", ")", ")", "{", "return", "ItemHoldingCode", "::", "getIt", "(", "ItemHoldingCode", "::", "OFFHAND", ")", ";", "}", "if", "(", "$", "this", "->", "weaponlikeHolding", "->", "holdsByOffhand", "(", ")", ")", "{", "return", "ItemHoldingCode", "::", "getIt", "(", "ItemHoldingCode", "::", "MAIN_HAND", ")", ";", "}", "// two hands holding", "if", "(", "$", "this", "->", "shield", "->", "getValue", "(", ")", "===", "ShieldCode", "::", "WITHOUT_SHIELD", ")", "{", "return", "ItemHoldingCode", "::", "getIt", "(", "ItemHoldingCode", "::", "MAIN_HAND", ")", ";", "}", "throw", "new", "Exceptions", "\\", "NoHandLeftForShield", "(", "\"Can not hold {$this->shield} when holding {$this->weaponlike} with {$this->weaponlikeHolding}\"", ")", ";", "}" ]
Gives holding opposite to given weapon holding. @return ItemHoldingCode @throws \DrdPlus\FightProperties\Exceptions\NoHandLeftForShield
[ "Gives", "holding", "opposite", "to", "given", "weapon", "holding", "." ]
66cfce5fa8ba940ee5b9069c5ce6d5a645d4e1a1
https://github.com/drdplusinfo/drdplus-fight-properties/blob/66cfce5fa8ba940ee5b9069c5ce6d5a645d4e1a1/DrdPlus/FightProperties/FightProperties.php#L346-L361
train
drdplusinfo/drdplus-fight-properties
DrdPlus/FightProperties/FightProperties.php
FightProperties.getFightNumberModifier
private function getFightNumberModifier(): int { $fightNumberModifier = 0; // strength effect $fightNumberModifier += $this->getFightNumberMalusByStrength(); // skills effect $fightNumberModifier += $this->getFightNumberMalusBySkills(); // combat actions effect $fightNumberModifier += $this->combatActions->getFightNumberModifier(); return $fightNumberModifier; }
php
private function getFightNumberModifier(): int { $fightNumberModifier = 0; // strength effect $fightNumberModifier += $this->getFightNumberMalusByStrength(); // skills effect $fightNumberModifier += $this->getFightNumberMalusBySkills(); // combat actions effect $fightNumberModifier += $this->combatActions->getFightNumberModifier(); return $fightNumberModifier; }
[ "private", "function", "getFightNumberModifier", "(", ")", ":", "int", "{", "$", "fightNumberModifier", "=", "0", ";", "// strength effect", "$", "fightNumberModifier", "+=", "$", "this", "->", "getFightNumberMalusByStrength", "(", ")", ";", "// skills effect", "$", "fightNumberModifier", "+=", "$", "this", "->", "getFightNumberMalusBySkills", "(", ")", ";", "// combat actions effect", "$", "fightNumberModifier", "+=", "$", "this", "->", "combatActions", "->", "getFightNumberModifier", "(", ")", ";", "return", "$", "fightNumberModifier", ";", "}" ]
Fight number update according to a missing strength, missing skill and by a combat action @return int
[ "Fight", "number", "update", "according", "to", "a", "missing", "strength", "missing", "skill", "and", "by", "a", "combat", "action" ]
66cfce5fa8ba940ee5b9069c5ce6d5a645d4e1a1
https://github.com/drdplusinfo/drdplus-fight-properties/blob/66cfce5fa8ba940ee5b9069c5ce6d5a645d4e1a1/DrdPlus/FightProperties/FightProperties.php#L400-L414
train
niridoy/LaraveIinstaller
src/Helpers/FinalInstallManager.php
FinalInstallManager.generateKey
private static function generateKey($outputLog) { try{ Artisan::call('key:generate', ["--force"=> true], $outputLog); } catch(Exception $e){ return $this->response($e->getMessage()); } return $outputLog; }
php
private static function generateKey($outputLog) { try{ Artisan::call('key:generate', ["--force"=> true], $outputLog); } catch(Exception $e){ return $this->response($e->getMessage()); } return $outputLog; }
[ "private", "static", "function", "generateKey", "(", "$", "outputLog", ")", "{", "try", "{", "Artisan", "::", "call", "(", "'key:generate'", ",", "[", "\"--force\"", "=>", "true", "]", ",", "$", "outputLog", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "$", "this", "->", "response", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "outputLog", ";", "}" ]
Generate New Application Key. @param collection $outputLog @return collection
[ "Generate", "New", "Application", "Key", "." ]
8339cf45bf393be57fb4e6c63179a6865028f076
https://github.com/niridoy/LaraveIinstaller/blob/8339cf45bf393be57fb4e6c63179a6865028f076/src/Helpers/FinalInstallManager.php#L32-L42
train
Wedeto/DB
src/Query/FieldName.php
FieldName.toSQL
public function toSQL(Parameters $params, bool $inner_clause) { $field = $this->getField(); $table = $this->getTable(); if (empty($table)) $table = $params->getDefaultTable(); $drv = $params->getDriver(); if (!empty($table)) { list($table, $alias) = $params->resolveTable($table->getPrefix()); if ($alias) $table_ref = $drv->identQuote($alias); else $table_ref = $drv->getName($table); return $table_ref . '.' . $drv->identQuote($field); } return $drv->identQuote($field); }
php
public function toSQL(Parameters $params, bool $inner_clause) { $field = $this->getField(); $table = $this->getTable(); if (empty($table)) $table = $params->getDefaultTable(); $drv = $params->getDriver(); if (!empty($table)) { list($table, $alias) = $params->resolveTable($table->getPrefix()); if ($alias) $table_ref = $drv->identQuote($alias); else $table_ref = $drv->getName($table); return $table_ref . '.' . $drv->identQuote($field); } return $drv->identQuote($field); }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "bool", "$", "inner_clause", ")", "{", "$", "field", "=", "$", "this", "->", "getField", "(", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "if", "(", "empty", "(", "$", "table", ")", ")", "$", "table", "=", "$", "params", "->", "getDefaultTable", "(", ")", ";", "$", "drv", "=", "$", "params", "->", "getDriver", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "table", ")", ")", "{", "list", "(", "$", "table", ",", "$", "alias", ")", "=", "$", "params", "->", "resolveTable", "(", "$", "table", "->", "getPrefix", "(", ")", ")", ";", "if", "(", "$", "alias", ")", "$", "table_ref", "=", "$", "drv", "->", "identQuote", "(", "$", "alias", ")", ";", "else", "$", "table_ref", "=", "$", "drv", "->", "getName", "(", "$", "table", ")", ";", "return", "$", "table_ref", ".", "'.'", ".", "$", "drv", "->", "identQuote", "(", "$", "field", ")", ";", "}", "return", "$", "drv", "->", "identQuote", "(", "$", "field", ")", ";", "}" ]
Write a field name as SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @param bool $inner_clause Unused @return string The generated SQL
[ "Write", "a", "field", "name", "as", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/FieldName.php#L58-L78
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.setupOrganization
public function setupOrganization(User $user) { $guestCreateOrganization = false; $invitationHash = $this->session->get('newInvitation', false); if ($guestCreateOrganization || $invitationHash == false) { $organization = $this->createOrganization($user); } if ($invitationHash) { $organization = $this->processInvitationByHash($user, $invitationHash); } return $organization; }
php
public function setupOrganization(User $user) { $guestCreateOrganization = false; $invitationHash = $this->session->get('newInvitation', false); if ($guestCreateOrganization || $invitationHash == false) { $organization = $this->createOrganization($user); } if ($invitationHash) { $organization = $this->processInvitationByHash($user, $invitationHash); } return $organization; }
[ "public", "function", "setupOrganization", "(", "User", "$", "user", ")", "{", "$", "guestCreateOrganization", "=", "false", ";", "$", "invitationHash", "=", "$", "this", "->", "session", "->", "get", "(", "'newInvitation'", ",", "false", ")", ";", "if", "(", "$", "guestCreateOrganization", "||", "$", "invitationHash", "==", "false", ")", "{", "$", "organization", "=", "$", "this", "->", "createOrganization", "(", "$", "user", ")", ";", "}", "if", "(", "$", "invitationHash", ")", "{", "$", "organization", "=", "$", "this", "->", "processInvitationByHash", "(", "$", "user", ",", "$", "invitationHash", ")", ";", "}", "return", "$", "organization", ";", "}" ]
Setup organization from signup. It chekcs if there is an invitationHash in session @todo Add Bundle option for $guestCreateOrganization @param User $user @return Organization
[ "Setup", "organization", "from", "signup", ".", "It", "chekcs", "if", "there", "is", "an", "invitationHash", "in", "session" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L66-L80
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.createOrganization
public function createOrganization(User $user) { $organization = new $this->organizationClass; $organization->setOwner($user); $organization->addUser($user); $role = new Role; $role->setRoles(array('ROLE_ORGANIZATION_OWNER')); $role->setUser($user); $role->setOrganization($organization); $contact = $user->getContact(); if (!$contact) { $contact = new Contact; $user->setContact($contact); } $organizationContact = clone $user->getContact(); $organization->setContact($organizationContact); $user->setActiveOrganization($organization); $user->setActiveRole($role); $this->dm->persist($user); $this->dm->persist($role); $this->dm->persist($contact); $this->dm->persist($organizationContact); $this->dm->persist($organization); $this->dm->flush(); $this->eventDispatcher->dispatch( 'wc_user.organization.create', new GenericEvent('wc_user.organization.create', array( 'notifyUser' => $user, 'notifyOrganizationTrigger' => $organization, 'notifyOrganizations' => [$organization], 'data' => [ 'organization' => $organization ] )) ); return $organization; }
php
public function createOrganization(User $user) { $organization = new $this->organizationClass; $organization->setOwner($user); $organization->addUser($user); $role = new Role; $role->setRoles(array('ROLE_ORGANIZATION_OWNER')); $role->setUser($user); $role->setOrganization($organization); $contact = $user->getContact(); if (!$contact) { $contact = new Contact; $user->setContact($contact); } $organizationContact = clone $user->getContact(); $organization->setContact($organizationContact); $user->setActiveOrganization($organization); $user->setActiveRole($role); $this->dm->persist($user); $this->dm->persist($role); $this->dm->persist($contact); $this->dm->persist($organizationContact); $this->dm->persist($organization); $this->dm->flush(); $this->eventDispatcher->dispatch( 'wc_user.organization.create', new GenericEvent('wc_user.organization.create', array( 'notifyUser' => $user, 'notifyOrganizationTrigger' => $organization, 'notifyOrganizations' => [$organization], 'data' => [ 'organization' => $organization ] )) ); return $organization; }
[ "public", "function", "createOrganization", "(", "User", "$", "user", ")", "{", "$", "organization", "=", "new", "$", "this", "->", "organizationClass", ";", "$", "organization", "->", "setOwner", "(", "$", "user", ")", ";", "$", "organization", "->", "addUser", "(", "$", "user", ")", ";", "$", "role", "=", "new", "Role", ";", "$", "role", "->", "setRoles", "(", "array", "(", "'ROLE_ORGANIZATION_OWNER'", ")", ")", ";", "$", "role", "->", "setUser", "(", "$", "user", ")", ";", "$", "role", "->", "setOrganization", "(", "$", "organization", ")", ";", "$", "contact", "=", "$", "user", "->", "getContact", "(", ")", ";", "if", "(", "!", "$", "contact", ")", "{", "$", "contact", "=", "new", "Contact", ";", "$", "user", "->", "setContact", "(", "$", "contact", ")", ";", "}", "$", "organizationContact", "=", "clone", "$", "user", "->", "getContact", "(", ")", ";", "$", "organization", "->", "setContact", "(", "$", "organizationContact", ")", ";", "$", "user", "->", "setActiveOrganization", "(", "$", "organization", ")", ";", "$", "user", "->", "setActiveRole", "(", "$", "role", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "user", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "role", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "contact", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "organizationContact", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "organization", ")", ";", "$", "this", "->", "dm", "->", "flush", "(", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "'wc_user.organization.create'", ",", "new", "GenericEvent", "(", "'wc_user.organization.create'", ",", "array", "(", "'notifyUser'", "=>", "$", "user", ",", "'notifyOrganizationTrigger'", "=>", "$", "organization", ",", "'notifyOrganizations'", "=>", "[", "$", "organization", "]", ",", "'data'", "=>", "[", "'organization'", "=>", "$", "organization", "]", ")", ")", ")", ";", "return", "$", "organization", ";", "}" ]
It creates and completes a new Organization @param OrganizationInterface $organization New empty organization @param User $user User that owns the organizartion @return Organization The new organization
[ "It", "creates", "and", "completes", "a", "new", "Organization" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L90-L133
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.addMember
public function addMember(OrganizationInterface $organization, User $user, array $roles) { if ($organization->getOwner() === null) { $organization->setOwner($user); } $user->addOrganization($organization); $organization->addUser($user); $role = new Role(); $role->setOrganization($organization); $role->setUser($user); $role->setRoles($roles); $this->dm->persist($user); $this->dm->persist($organization); $this->dm->persist($role); $this->dm->flush(); }
php
public function addMember(OrganizationInterface $organization, User $user, array $roles) { if ($organization->getOwner() === null) { $organization->setOwner($user); } $user->addOrganization($organization); $organization->addUser($user); $role = new Role(); $role->setOrganization($organization); $role->setUser($user); $role->setRoles($roles); $this->dm->persist($user); $this->dm->persist($organization); $this->dm->persist($role); $this->dm->flush(); }
[ "public", "function", "addMember", "(", "OrganizationInterface", "$", "organization", ",", "User", "$", "user", ",", "array", "$", "roles", ")", "{", "if", "(", "$", "organization", "->", "getOwner", "(", ")", "===", "null", ")", "{", "$", "organization", "->", "setOwner", "(", "$", "user", ")", ";", "}", "$", "user", "->", "addOrganization", "(", "$", "organization", ")", ";", "$", "organization", "->", "addUser", "(", "$", "user", ")", ";", "$", "role", "=", "new", "Role", "(", ")", ";", "$", "role", "->", "setOrganization", "(", "$", "organization", ")", ";", "$", "role", "->", "setUser", "(", "$", "user", ")", ";", "$", "role", "->", "setRoles", "(", "$", "roles", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "user", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "organization", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "role", ")", ";", "$", "this", "->", "dm", "->", "flush", "(", ")", ";", "}" ]
Add member to an organization with specifics roles @param OrganizationInterface $organization @param User $user @param array $roles
[ "Add", "member", "to", "an", "organization", "with", "specifics", "roles" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L142-L160
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.processInvitationByHash
public function processInvitationByHash(User $user, $hash) { $invitation = $this->dm->getRepository('WobbleCodeUserBundle:Invitation')->findOneBy( [ 'hash' => $hash, 'status' => 'pending' ] ); if (!$invitation) { return false; } $organization = $invitation->getOrganization(); $this->addMemberByInvitation($organization, $user, $invitation); return $organization; }
php
public function processInvitationByHash(User $user, $hash) { $invitation = $this->dm->getRepository('WobbleCodeUserBundle:Invitation')->findOneBy( [ 'hash' => $hash, 'status' => 'pending' ] ); if (!$invitation) { return false; } $organization = $invitation->getOrganization(); $this->addMemberByInvitation($organization, $user, $invitation); return $organization; }
[ "public", "function", "processInvitationByHash", "(", "User", "$", "user", ",", "$", "hash", ")", "{", "$", "invitation", "=", "$", "this", "->", "dm", "->", "getRepository", "(", "'WobbleCodeUserBundle:Invitation'", ")", "->", "findOneBy", "(", "[", "'hash'", "=>", "$", "hash", ",", "'status'", "=>", "'pending'", "]", ")", ";", "if", "(", "!", "$", "invitation", ")", "{", "return", "false", ";", "}", "$", "organization", "=", "$", "invitation", "->", "getOrganization", "(", ")", ";", "$", "this", "->", "addMemberByInvitation", "(", "$", "organization", ",", "$", "user", ",", "$", "invitation", ")", ";", "return", "$", "organization", ";", "}" ]
Finds an Invitation by Hash and add member if exists @param User $user @param string $hash Secret Invitation Hash
[ "Finds", "an", "Invitation", "by", "Hash", "and", "add", "member", "if", "exists" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L168-L185
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.addMemberByInvitation
public function addMemberByInvitation(OrganizationInterface $organization, User $user, Invitation $invitation) { $this->addMember($organization, $user, $invitation->getRoles()); $invitation->setStatus('accepted'); $invitation->setTo($user); $this->dm->persist($invitation); $this->dm->flush(); }
php
public function addMemberByInvitation(OrganizationInterface $organization, User $user, Invitation $invitation) { $this->addMember($organization, $user, $invitation->getRoles()); $invitation->setStatus('accepted'); $invitation->setTo($user); $this->dm->persist($invitation); $this->dm->flush(); }
[ "public", "function", "addMemberByInvitation", "(", "OrganizationInterface", "$", "organization", ",", "User", "$", "user", ",", "Invitation", "$", "invitation", ")", "{", "$", "this", "->", "addMember", "(", "$", "organization", ",", "$", "user", ",", "$", "invitation", "->", "getRoles", "(", ")", ")", ";", "$", "invitation", "->", "setStatus", "(", "'accepted'", ")", ";", "$", "invitation", "->", "setTo", "(", "$", "user", ")", ";", "$", "this", "->", "dm", "->", "persist", "(", "$", "invitation", ")", ";", "$", "this", "->", "dm", "->", "flush", "(", ")", ";", "}" ]
Add member to an Organization using settings from invitation @param OrganizationInterface $organization @param User $user @param Invitation $invitation
[ "Add", "member", "to", "an", "Organization", "using", "settings", "from", "invitation" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L194-L202
train
wobblecode/WobbleCodeUserBundle
Manager/OrganizationManager.php
OrganizationManager.getAdminOwner
public function getAdminOwner() { $repo = $this->dm->getRepository($this->organizationClass); return $repo->findOneBy([ 'adminOwner' => true ]); }
php
public function getAdminOwner() { $repo = $this->dm->getRepository($this->organizationClass); return $repo->findOneBy([ 'adminOwner' => true ]); }
[ "public", "function", "getAdminOwner", "(", ")", "{", "$", "repo", "=", "$", "this", "->", "dm", "->", "getRepository", "(", "$", "this", "->", "organizationClass", ")", ";", "return", "$", "repo", "->", "findOneBy", "(", "[", "'adminOwner'", "=>", "true", "]", ")", ";", "}" ]
Gets the system admin Organization @return OrganizationInterface
[ "Gets", "the", "system", "admin", "Organization" ]
7b8206f8b4a50fbc61f7bfe4f83eb466cad96440
https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/Manager/OrganizationManager.php#L209-L216
train
agentmedia/phine-core
src/Core/Logic/Rendering/ContentRenderer.php
ContentRenderer.Render
function Render() { if (!self::Guard()->Allow(Action::Read(), $this->content)) { return ''; } ContentTranslator::Singleton()->SetContent($this->content); $module = ClassFinder::CreateFrontendModule($this->content->GetType()); $module->SetTreeItem($this->tree, $this->item); return $module->Render(); }
php
function Render() { if (!self::Guard()->Allow(Action::Read(), $this->content)) { return ''; } ContentTranslator::Singleton()->SetContent($this->content); $module = ClassFinder::CreateFrontendModule($this->content->GetType()); $module->SetTreeItem($this->tree, $this->item); return $module->Render(); }
[ "function", "Render", "(", ")", "{", "if", "(", "!", "self", "::", "Guard", "(", ")", "->", "Allow", "(", "Action", "::", "Read", "(", ")", ",", "$", "this", "->", "content", ")", ")", "{", "return", "''", ";", "}", "ContentTranslator", "::", "Singleton", "(", ")", "->", "SetContent", "(", "$", "this", "->", "content", ")", ";", "$", "module", "=", "ClassFinder", "::", "CreateFrontendModule", "(", "$", "this", "->", "content", "->", "GetType", "(", ")", ")", ";", "$", "module", "->", "SetTreeItem", "(", "$", "this", "->", "tree", ",", "$", "this", "->", "item", ")", ";", "return", "$", "module", "->", "Render", "(", ")", ";", "}" ]
Renders the content @return string Returns the rendered content
[ "Renders", "the", "content" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Rendering/ContentRenderer.php#L67-L77
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/Media.php
Media.getC2Ms
public function getC2Ms(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collC2MsPartial && !$this->isNew(); if (null === $this->collC2Ms || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collC2Ms) { // return empty collection $this->initC2Ms(); } else { $collC2Ms = ChildC2MQuery::create(null, $criteria) ->filterByMedia($this) ->find($con); if (null !== $criteria) { if (false !== $this->collC2MsPartial && count($collC2Ms)) { $this->initC2Ms(false); foreach ($collC2Ms as $obj) { if (false == $this->collC2Ms->contains($obj)) { $this->collC2Ms->append($obj); } } $this->collC2MsPartial = true; } return $collC2Ms; } if ($partial && $this->collC2Ms) { foreach ($this->collC2Ms as $obj) { if ($obj->isNew()) { $collC2Ms[] = $obj; } } } $this->collC2Ms = $collC2Ms; $this->collC2MsPartial = false; } } return $this->collC2Ms; }
php
public function getC2Ms(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collC2MsPartial && !$this->isNew(); if (null === $this->collC2Ms || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collC2Ms) { // return empty collection $this->initC2Ms(); } else { $collC2Ms = ChildC2MQuery::create(null, $criteria) ->filterByMedia($this) ->find($con); if (null !== $criteria) { if (false !== $this->collC2MsPartial && count($collC2Ms)) { $this->initC2Ms(false); foreach ($collC2Ms as $obj) { if (false == $this->collC2Ms->contains($obj)) { $this->collC2Ms->append($obj); } } $this->collC2MsPartial = true; } return $collC2Ms; } if ($partial && $this->collC2Ms) { foreach ($this->collC2Ms as $obj) { if ($obj->isNew()) { $collC2Ms[] = $obj; } } } $this->collC2Ms = $collC2Ms; $this->collC2MsPartial = false; } } return $this->collC2Ms; }
[ "public", "function", "getC2Ms", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collC2MsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collC2Ms", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collC2Ms", ")", "{", "// return empty collection", "$", "this", "->", "initC2Ms", "(", ")", ";", "}", "else", "{", "$", "collC2Ms", "=", "ChildC2MQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", "->", "filterByMedia", "(", "$", "this", ")", "->", "find", "(", "$", "con", ")", ";", "if", "(", "null", "!==", "$", "criteria", ")", "{", "if", "(", "false", "!==", "$", "this", "->", "collC2MsPartial", "&&", "count", "(", "$", "collC2Ms", ")", ")", "{", "$", "this", "->", "initC2Ms", "(", "false", ")", ";", "foreach", "(", "$", "collC2Ms", "as", "$", "obj", ")", "{", "if", "(", "false", "==", "$", "this", "->", "collC2Ms", "->", "contains", "(", "$", "obj", ")", ")", "{", "$", "this", "->", "collC2Ms", "->", "append", "(", "$", "obj", ")", ";", "}", "}", "$", "this", "->", "collC2MsPartial", "=", "true", ";", "}", "return", "$", "collC2Ms", ";", "}", "if", "(", "$", "partial", "&&", "$", "this", "->", "collC2Ms", ")", "{", "foreach", "(", "$", "this", "->", "collC2Ms", "as", "$", "obj", ")", "{", "if", "(", "$", "obj", "->", "isNew", "(", ")", ")", "{", "$", "collC2Ms", "[", "]", "=", "$", "obj", ";", "}", "}", "}", "$", "this", "->", "collC2Ms", "=", "$", "collC2Ms", ";", "$", "this", "->", "collC2MsPartial", "=", "false", ";", "}", "}", "return", "$", "this", "->", "collC2Ms", ";", "}" ]
Gets an array of ChildC2M 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 ChildMedia 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 ConnectionInterface $con optional connection object @return ObjectCollection|ChildC2M[] List of ChildC2M objects @throws PropelException
[ "Gets", "an", "array", "of", "ChildC2M", "objects", "which", "contain", "a", "foreign", "key", "that", "references", "this", "object", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Media.php#L3169-L3211
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/Media.php
Media.countM2Ps
public function countM2Ps(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collM2PsPartial && !$this->isNew(); if (null === $this->collM2Ps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collM2Ps) { return 0; } if ($partial && !$criteria) { return count($this->getM2Ps()); } $query = ChildM2PQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByMedia($this) ->count($con); } return count($this->collM2Ps); }
php
public function countM2Ps(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collM2PsPartial && !$this->isNew(); if (null === $this->collM2Ps || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collM2Ps) { return 0; } if ($partial && !$criteria) { return count($this->getM2Ps()); } $query = ChildM2PQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByMedia($this) ->count($con); } return count($this->collM2Ps); }
[ "public", "function", "countM2Ps", "(", "Criteria", "$", "criteria", "=", "null", ",", "$", "distinct", "=", "false", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collM2PsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collM2Ps", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collM2Ps", ")", "{", "return", "0", ";", "}", "if", "(", "$", "partial", "&&", "!", "$", "criteria", ")", "{", "return", "count", "(", "$", "this", "->", "getM2Ps", "(", ")", ")", ";", "}", "$", "query", "=", "ChildM2PQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "if", "(", "$", "distinct", ")", "{", "$", "query", "->", "distinct", "(", ")", ";", "}", "return", "$", "query", "->", "filterByMedia", "(", "$", "this", ")", "->", "count", "(", "$", "con", ")", ";", "}", "return", "count", "(", "$", "this", "->", "collM2Ps", ")", ";", "}" ]
Returns the number of related M2P objects. @param Criteria $criteria @param boolean $distinct @param ConnectionInterface $con @return int Count of related M2P objects. @throws PropelException
[ "Returns", "the", "number", "of", "related", "M2P", "objects", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Media.php#L3511-L3534
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/Media.php
Media.getM2PsJoinPage
public function getM2PsJoinPage(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildM2PQuery::create(null, $criteria); $query->joinWith('Page', $joinBehavior); return $this->getM2Ps($query, $con); }
php
public function getM2PsJoinPage(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildM2PQuery::create(null, $criteria); $query->joinWith('Page', $joinBehavior); return $this->getM2Ps($query, $con); }
[ "public", "function", "getM2PsJoinPage", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ",", "$", "joinBehavior", "=", "Criteria", "::", "LEFT_JOIN", ")", "{", "$", "query", "=", "ChildM2PQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "$", "query", "->", "joinWith", "(", "'Page'", ",", "$", "joinBehavior", ")", ";", "return", "$", "this", "->", "getM2Ps", "(", "$", "query", ",", "$", "con", ")", ";", "}" ]
If this collection has already been initialized with an identical criteria, it returns the collection. Otherwise if this Media is new, it will return an empty collection; or if this Media has previously been saved, it will retrieve related M2Ps from storage. This method is protected by default in order to keep the public api reasonable. You can provide public methods for those you actually need in Media. @param Criteria $criteria optional Criteria object to narrow the query @param ConnectionInterface $con optional connection object @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) @return ObjectCollection|ChildM2P[] List of ChildM2P objects
[ "If", "this", "collection", "has", "already", "been", "initialized", "with", "an", "identical", "criteria", "it", "returns", "the", "collection", ".", "Otherwise", "if", "this", "Media", "is", "new", "it", "will", "return", "an", "empty", "collection", ";", "or", "if", "this", "Media", "has", "previously", "been", "saved", "it", "will", "retrieve", "related", "M2Ps", "from", "storage", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/Media.php#L3607-L3613
train
fxpio/fxp-doctrine-extensions
Validator/Constraints/UniqueEntityValidator.php
UniqueEntityValidator.getCriteria
protected function getCriteria($entity, Constraint $constraint, ObjectManager $em) { /** @var UniqueEntity $constraint */ /** @var \Doctrine\ORM\Mapping\ClassMetadata $class */ $class = $em->getClassMetadata(ClassUtils::getClass($entity)); $fields = (array) $constraint->fields; $criteria = []; foreach ($fields as $fieldName) { $criteria = $this->findFieldCriteria($criteria, $constraint, $em, $class, $entity, $fieldName); if (null === $criteria) { break; } } return $criteria; }
php
protected function getCriteria($entity, Constraint $constraint, ObjectManager $em) { /** @var UniqueEntity $constraint */ /** @var \Doctrine\ORM\Mapping\ClassMetadata $class */ $class = $em->getClassMetadata(ClassUtils::getClass($entity)); $fields = (array) $constraint->fields; $criteria = []; foreach ($fields as $fieldName) { $criteria = $this->findFieldCriteria($criteria, $constraint, $em, $class, $entity, $fieldName); if (null === $criteria) { break; } } return $criteria; }
[ "protected", "function", "getCriteria", "(", "$", "entity", ",", "Constraint", "$", "constraint", ",", "ObjectManager", "$", "em", ")", "{", "/** @var UniqueEntity $constraint */", "/** @var \\Doctrine\\ORM\\Mapping\\ClassMetadata $class */", "$", "class", "=", "$", "em", "->", "getClassMetadata", "(", "ClassUtils", "::", "getClass", "(", "$", "entity", ")", ")", ";", "$", "fields", "=", "(", "array", ")", "$", "constraint", "->", "fields", ";", "$", "criteria", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "fieldName", ")", "{", "$", "criteria", "=", "$", "this", "->", "findFieldCriteria", "(", "$", "criteria", ",", "$", "constraint", ",", "$", "em", ",", "$", "class", ",", "$", "entity", ",", "$", "fieldName", ")", ";", "if", "(", "null", "===", "$", "criteria", ")", "{", "break", ";", "}", "}", "return", "$", "criteria", ";", "}" ]
Gets criteria. @param object $entity @param Constraint $constraint @param ObjectManager $em @throws ConstraintDefinitionException @return null|array Null if there is no constraint
[ "Gets", "criteria", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/UniqueEntityValidator.php#L91-L108
train
fxpio/fxp-doctrine-extensions
Validator/Constraints/UniqueEntityValidator.php
UniqueEntityValidator.getResult
private function getResult($entity, Constraint $constraint, array $criteria, ObjectManager $em) { /** @var UniqueEntity $constraint */ $filters = SqlFilterUtil::findFilters($em, (array) $constraint->filters, $constraint->allFilters); SqlFilterUtil::disableFilters($em, $filters); $repository = $em->getRepository(ClassUtils::getClass($entity)); $result = $repository->{$constraint->repositoryMethod}($criteria); SqlFilterUtil::enableFilters($em, $filters); if (\is_array($result)) { reset($result); } return $result; }
php
private function getResult($entity, Constraint $constraint, array $criteria, ObjectManager $em) { /** @var UniqueEntity $constraint */ $filters = SqlFilterUtil::findFilters($em, (array) $constraint->filters, $constraint->allFilters); SqlFilterUtil::disableFilters($em, $filters); $repository = $em->getRepository(ClassUtils::getClass($entity)); $result = $repository->{$constraint->repositoryMethod}($criteria); SqlFilterUtil::enableFilters($em, $filters); if (\is_array($result)) { reset($result); } return $result; }
[ "private", "function", "getResult", "(", "$", "entity", ",", "Constraint", "$", "constraint", ",", "array", "$", "criteria", ",", "ObjectManager", "$", "em", ")", "{", "/** @var UniqueEntity $constraint */", "$", "filters", "=", "SqlFilterUtil", "::", "findFilters", "(", "$", "em", ",", "(", "array", ")", "$", "constraint", "->", "filters", ",", "$", "constraint", "->", "allFilters", ")", ";", "SqlFilterUtil", "::", "disableFilters", "(", "$", "em", ",", "$", "filters", ")", ";", "$", "repository", "=", "$", "em", "->", "getRepository", "(", "ClassUtils", "::", "getClass", "(", "$", "entity", ")", ")", ";", "$", "result", "=", "$", "repository", "->", "{", "$", "constraint", "->", "repositoryMethod", "}", "(", "$", "criteria", ")", ";", "SqlFilterUtil", "::", "enableFilters", "(", "$", "em", ",", "$", "filters", ")", ";", "if", "(", "\\", "is_array", "(", "$", "result", ")", ")", "{", "reset", "(", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get entity result. @param object $entity @param Constraint $constraint @param array $criteria @param ObjectManager $em @return array
[ "Get", "entity", "result", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/UniqueEntityValidator.php#L120-L135
train
fxpio/fxp-doctrine-extensions
Validator/Constraints/UniqueEntityValidator.php
UniqueEntityValidator.isValidResult
private function isValidResult($result, $entity) { return 0 === \count($result) || (1 === \count($result) && $entity === ($result instanceof \Iterator ? $result->current() : current($result))); }
php
private function isValidResult($result, $entity) { return 0 === \count($result) || (1 === \count($result) && $entity === ($result instanceof \Iterator ? $result->current() : current($result))); }
[ "private", "function", "isValidResult", "(", "$", "result", ",", "$", "entity", ")", "{", "return", "0", "===", "\\", "count", "(", "$", "result", ")", "||", "(", "1", "===", "\\", "count", "(", "$", "result", ")", "&&", "$", "entity", "===", "(", "$", "result", "instanceof", "\\", "Iterator", "?", "$", "result", "->", "current", "(", ")", ":", "current", "(", "$", "result", ")", ")", ")", ";", "}" ]
Check if the result is valid. If no entity matched the query criteria or a single entity matched, which is the same as the entity being validated, the criteria is unique. @param array|\Iterator $result @param object $entity @return bool
[ "Check", "if", "the", "result", "is", "valid", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/UniqueEntityValidator.php#L149-L154
train
fxpio/fxp-doctrine-extensions
Validator/Constraints/UniqueEntityValidator.php
UniqueEntityValidator.findFieldCriteriaStep2
private function findFieldCriteriaStep2(array &$criteria, ObjectManager $em, ClassMetadata $class, $fieldName): void { if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) { /* Ensure the Proxy is initialized before using reflection to * read its identifiers. This is necessary because the wrapped * getter methods in the Proxy are being bypassed. */ $em->initializeObject($criteria[$fieldName]); $relatedClass = $em->getClassMetadata($class->getAssociationTargetClass($fieldName)); $relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]); if (\count($relatedId) > 1) { throw new ConstraintDefinitionException( 'Associated entities are not allowed to have more than one identifier field to be '. 'part of a unique constraint in: '.$class->getName().'#'.$fieldName ); } $value = array_pop($relatedId); $criteria[$fieldName] = Util::getFormattedIdentifier($relatedClass, $criteria, $fieldName, $value); } }
php
private function findFieldCriteriaStep2(array &$criteria, ObjectManager $em, ClassMetadata $class, $fieldName): void { if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) { /* Ensure the Proxy is initialized before using reflection to * read its identifiers. This is necessary because the wrapped * getter methods in the Proxy are being bypassed. */ $em->initializeObject($criteria[$fieldName]); $relatedClass = $em->getClassMetadata($class->getAssociationTargetClass($fieldName)); $relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]); if (\count($relatedId) > 1) { throw new ConstraintDefinitionException( 'Associated entities are not allowed to have more than one identifier field to be '. 'part of a unique constraint in: '.$class->getName().'#'.$fieldName ); } $value = array_pop($relatedId); $criteria[$fieldName] = Util::getFormattedIdentifier($relatedClass, $criteria, $fieldName, $value); } }
[ "private", "function", "findFieldCriteriaStep2", "(", "array", "&", "$", "criteria", ",", "ObjectManager", "$", "em", ",", "ClassMetadata", "$", "class", ",", "$", "fieldName", ")", ":", "void", "{", "if", "(", "null", "!==", "$", "criteria", "[", "$", "fieldName", "]", "&&", "$", "class", "->", "hasAssociation", "(", "$", "fieldName", ")", ")", "{", "/* Ensure the Proxy is initialized before using reflection to\n * read its identifiers. This is necessary because the wrapped\n * getter methods in the Proxy are being bypassed.\n */", "$", "em", "->", "initializeObject", "(", "$", "criteria", "[", "$", "fieldName", "]", ")", ";", "$", "relatedClass", "=", "$", "em", "->", "getClassMetadata", "(", "$", "class", "->", "getAssociationTargetClass", "(", "$", "fieldName", ")", ")", ";", "$", "relatedId", "=", "$", "relatedClass", "->", "getIdentifierValues", "(", "$", "criteria", "[", "$", "fieldName", "]", ")", ";", "if", "(", "\\", "count", "(", "$", "relatedId", ")", ">", "1", ")", "{", "throw", "new", "ConstraintDefinitionException", "(", "'Associated entities are not allowed to have more than one identifier field to be '", ".", "'part of a unique constraint in: '", ".", "$", "class", "->", "getName", "(", ")", ".", "'#'", ".", "$", "fieldName", ")", ";", "}", "$", "value", "=", "array_pop", "(", "$", "relatedId", ")", ";", "$", "criteria", "[", "$", "fieldName", "]", "=", "Util", "::", "getFormattedIdentifier", "(", "$", "relatedClass", ",", "$", "criteria", ",", "$", "fieldName", ",", "$", "value", ")", ";", "}", "}" ]
Finds the criteria for the entity field. @param array $criteria @param ObjectManager $em @param ClassMetadata $class @param string $fieldName @throws ConstraintDefinitionException
[ "Finds", "the", "criteria", "for", "the", "entity", "field", "." ]
82942f51d47cdd79a20a5725ee1b3ecfc69e9d77
https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/UniqueEntityValidator.php#L208-L230
train
climphp/Clim
Clim/Cli/MiddlewareStack.php
MiddlewareStack.handleResult
protected function handleResult(ContextInterface $context, $result) { $validated = $this->validateResult($result); if (is_null($validated)) { $validated = $result; } if ($validated instanceof ContextInterface) { $context = $validated; } elseif (!is_null($validated)) { $context->setResult($validated); } return $context; }
php
protected function handleResult(ContextInterface $context, $result) { $validated = $this->validateResult($result); if (is_null($validated)) { $validated = $result; } if ($validated instanceof ContextInterface) { $context = $validated; } elseif (!is_null($validated)) { $context->setResult($validated); } return $context; }
[ "protected", "function", "handleResult", "(", "ContextInterface", "$", "context", ",", "$", "result", ")", "{", "$", "validated", "=", "$", "this", "->", "validateResult", "(", "$", "result", ")", ";", "if", "(", "is_null", "(", "$", "validated", ")", ")", "{", "$", "validated", "=", "$", "result", ";", "}", "if", "(", "$", "validated", "instanceof", "ContextInterface", ")", "{", "$", "context", "=", "$", "validated", ";", "}", "elseif", "(", "!", "is_null", "(", "$", "validated", ")", ")", "{", "$", "context", "->", "setResult", "(", "$", "validated", ")", ";", "}", "return", "$", "context", ";", "}" ]
Validate middleware result. Imprementer shall invoke exceptions in this method if result is not valid. @param ContextInterface $context A context object @param mixed $result @return ContextInterface|null
[ "Validate", "middleware", "result", ".", "Imprementer", "shall", "invoke", "exceptions", "in", "this", "method", "if", "result", "is", "not", "valid", "." ]
d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4
https://github.com/climphp/Clim/blob/d2d09a82e1b7a0b8d454e585e6db421ff02ec8e4/Clim/Cli/MiddlewareStack.php#L111-L125
train
Wedeto/HTTP
src/Response/FileResponse.php
FileResponse.output
public function output(string $mime) { // Nothing to output, the webserver will handle it if ($this->xsendfile) return; $bytes = readfile($this->filename); if (!empty($this->length) && $bytes != $this->length) { self::getLogger()->warning( "FileResponse promised to send {0} bytes but {1} were actually transfered of file {2}", [$this->length, $bytes, $this->output_filename] ); } }
php
public function output(string $mime) { // Nothing to output, the webserver will handle it if ($this->xsendfile) return; $bytes = readfile($this->filename); if (!empty($this->length) && $bytes != $this->length) { self::getLogger()->warning( "FileResponse promised to send {0} bytes but {1} were actually transfered of file {2}", [$this->length, $bytes, $this->output_filename] ); } }
[ "public", "function", "output", "(", "string", "$", "mime", ")", "{", "// Nothing to output, the webserver will handle it", "if", "(", "$", "this", "->", "xsendfile", ")", "return", ";", "$", "bytes", "=", "readfile", "(", "$", "this", "->", "filename", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "length", ")", "&&", "$", "bytes", "!=", "$", "this", "->", "length", ")", "{", "self", "::", "getLogger", "(", ")", "->", "warning", "(", "\"FileResponse promised to send {0} bytes but {1} were actually transfered of file {2}\"", ",", "[", "$", "this", "->", "length", ",", "$", "bytes", ",", "$", "this", "->", "output_filename", "]", ")", ";", "}", "}" ]
Serve the file to the user
[ "Serve", "the", "file", "to", "the", "user" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/FileResponse.php#L142-L156
train
Vectrex/vxPHP
src/Routing/Route.php
Route.getPath
public function getPath(array $pathParameters = null) { $path = $this->path; //insert path parameters if(!empty($this->placeholders)) { foreach ($this->placeholders as $placeholder) { // use path parameter if it was passed on $regExp = '~\{' . $placeholder['name'] . '(=.*?)?\}~'; if($pathParameters && array_key_exists($placeholder['name'], $pathParameters)) { $path = preg_replace($regExp, $pathParameters[$placeholder['name']], $path); } // try to use previously set path parameter else if($this->pathParameters && array_key_exists($placeholder['name'], $this->pathParameters)) { $path = preg_replace($regExp, $this->pathParameters[$placeholder['name']], $path); } // no path parameter value passed on, but default defined else if(isset($placeholder['default'])){ $path = preg_replace($regExp, $placeholder['default'], $path); } else { throw new \RuntimeException(sprintf("Path parameter '%s' not set.", $placeholder['name'])); } } } // remove trailing slashes which might stem from one or more empty path parameters return rtrim($path, '/'); }
php
public function getPath(array $pathParameters = null) { $path = $this->path; //insert path parameters if(!empty($this->placeholders)) { foreach ($this->placeholders as $placeholder) { // use path parameter if it was passed on $regExp = '~\{' . $placeholder['name'] . '(=.*?)?\}~'; if($pathParameters && array_key_exists($placeholder['name'], $pathParameters)) { $path = preg_replace($regExp, $pathParameters[$placeholder['name']], $path); } // try to use previously set path parameter else if($this->pathParameters && array_key_exists($placeholder['name'], $this->pathParameters)) { $path = preg_replace($regExp, $this->pathParameters[$placeholder['name']], $path); } // no path parameter value passed on, but default defined else if(isset($placeholder['default'])){ $path = preg_replace($regExp, $placeholder['default'], $path); } else { throw new \RuntimeException(sprintf("Path parameter '%s' not set.", $placeholder['name'])); } } } // remove trailing slashes which might stem from one or more empty path parameters return rtrim($path, '/'); }
[ "public", "function", "getPath", "(", "array", "$", "pathParameters", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "path", ";", "//insert path parameters", "if", "(", "!", "empty", "(", "$", "this", "->", "placeholders", ")", ")", "{", "foreach", "(", "$", "this", "->", "placeholders", "as", "$", "placeholder", ")", "{", "// use path parameter if it was passed on", "$", "regExp", "=", "'~\\{'", ".", "$", "placeholder", "[", "'name'", "]", ".", "'(=.*?)?\\}~'", ";", "if", "(", "$", "pathParameters", "&&", "array_key_exists", "(", "$", "placeholder", "[", "'name'", "]", ",", "$", "pathParameters", ")", ")", "{", "$", "path", "=", "preg_replace", "(", "$", "regExp", ",", "$", "pathParameters", "[", "$", "placeholder", "[", "'name'", "]", "]", ",", "$", "path", ")", ";", "}", "// try to use previously set path parameter", "else", "if", "(", "$", "this", "->", "pathParameters", "&&", "array_key_exists", "(", "$", "placeholder", "[", "'name'", "]", ",", "$", "this", "->", "pathParameters", ")", ")", "{", "$", "path", "=", "preg_replace", "(", "$", "regExp", ",", "$", "this", "->", "pathParameters", "[", "$", "placeholder", "[", "'name'", "]", "]", ",", "$", "path", ")", ";", "}", "// no path parameter value passed on, but default defined", "else", "if", "(", "isset", "(", "$", "placeholder", "[", "'default'", "]", ")", ")", "{", "$", "path", "=", "preg_replace", "(", "$", "regExp", ",", "$", "placeholder", "[", "'default'", "]", ",", "$", "path", ")", ";", "}", "else", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "\"Path parameter '%s' not set.\"", ",", "$", "placeholder", "[", "'name'", "]", ")", ")", ";", "}", "}", "}", "// remove trailing slashes which might stem from one or more empty path parameters", "return", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "}" ]
get path of route When path parameters are passed on to method a path using these parameter values is generated, but path parameters are not stored and do not overwrite previously set path parameters. When no (or only some) path parameters are passed on previously set path parameters are considered when generating the path. expects path parameters when required by route @param array $pathParameters @throws \RuntimeException @return string
[ "get", "path", "of", "route" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/Route.php#L301-L344
train
Vectrex/vxPHP
src/Routing/Route.php
Route.setRequestMethods
public function setRequestMethods(array $requestMethods) { $requestMethods = array_map('strtoupper', $requestMethods); $allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; foreach($requestMethods as $requestMethod) { if(!in_array($requestMethod, $allowedMethods)) { throw new \InvalidArgumentException(sprintf("Invalid request method '%s'.", $requestMethod)); } } $this->requestMethods = $requestMethods; return $this; }
php
public function setRequestMethods(array $requestMethods) { $requestMethods = array_map('strtoupper', $requestMethods); $allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; foreach($requestMethods as $requestMethod) { if(!in_array($requestMethod, $allowedMethods)) { throw new \InvalidArgumentException(sprintf("Invalid request method '%s'.", $requestMethod)); } } $this->requestMethods = $requestMethods; return $this; }
[ "public", "function", "setRequestMethods", "(", "array", "$", "requestMethods", ")", "{", "$", "requestMethods", "=", "array_map", "(", "'strtoupper'", ",", "$", "requestMethods", ")", ";", "$", "allowedMethods", "=", "[", "'GET'", ",", "'POST'", ",", "'PUT'", ",", "'DELETE'", ",", "'PATCH'", "]", ";", "foreach", "(", "$", "requestMethods", "as", "$", "requestMethod", ")", "{", "if", "(", "!", "in_array", "(", "$", "requestMethod", ",", "$", "allowedMethods", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "\"Invalid request method '%s'.\"", ",", "$", "requestMethod", ")", ")", ";", "}", "}", "$", "this", "->", "requestMethods", "=", "$", "requestMethods", ";", "return", "$", "this", ";", "}" ]
set all allowed request methods for a route @param array $requestMethods @return \vxPHP\Routing\Route
[ "set", "all", "allowed", "request", "methods", "for", "a", "route" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/Route.php#L469-L484
train
Vectrex/vxPHP
src/Routing/Route.php
Route.allowsRequestMethod
public function allowsRequestMethod($requestMethod) { return empty($this->requestMethods) || in_array(strtoupper($requestMethod), $this->requestMethods); }
php
public function allowsRequestMethod($requestMethod) { return empty($this->requestMethods) || in_array(strtoupper($requestMethod), $this->requestMethods); }
[ "public", "function", "allowsRequestMethod", "(", "$", "requestMethod", ")", "{", "return", "empty", "(", "$", "this", "->", "requestMethods", ")", "||", "in_array", "(", "strtoupper", "(", "$", "requestMethod", ")", ",", "$", "this", "->", "requestMethods", ")", ";", "}" ]
check whether a request method is allowed with the route @param string $requestMethod @return boolean
[ "check", "whether", "a", "request", "method", "is", "allowed", "with", "the", "route" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/Route.php#L492-L496
train
Vectrex/vxPHP
src/Routing/Route.php
Route.getPathParameter
public function getPathParameter($name, $default = null) { // lazy initialization of parameters if(empty($this->pathParameters) && !is_null($this->placeholders)) { // collect all placeholder names $names = array_keys($this->placeholders); // extract values if(preg_match('~' . $this->match . '~', ltrim(Request::createFromGlobals()->getPathInfo(), '/'), $values)) { array_shift($values); // if not all parameters are set, try to fill up with defaults $offset = count($values); if($offset < count($names)) { while($offset < count($names)) { if(isset($this->placeholders[$names[$offset]]['default'])) { $values[] = $this->placeholders[$names[$offset]]['default']; } ++$offset; } } // only set parameters when count of placeholders matches count of values, that can be evaluated if(count($values) === count($names)) { $this->pathParameters = array_combine($names, $values); } } } $name = strtolower($name); if(isset($this->pathParameters[$name])) { // both bool false and null are returned as null if($this->pathParameters[$name] === false || is_null($this->pathParameters[$name])) { return null; } return $this->pathParameters[$name]; } return $default; }
php
public function getPathParameter($name, $default = null) { // lazy initialization of parameters if(empty($this->pathParameters) && !is_null($this->placeholders)) { // collect all placeholder names $names = array_keys($this->placeholders); // extract values if(preg_match('~' . $this->match . '~', ltrim(Request::createFromGlobals()->getPathInfo(), '/'), $values)) { array_shift($values); // if not all parameters are set, try to fill up with defaults $offset = count($values); if($offset < count($names)) { while($offset < count($names)) { if(isset($this->placeholders[$names[$offset]]['default'])) { $values[] = $this->placeholders[$names[$offset]]['default']; } ++$offset; } } // only set parameters when count of placeholders matches count of values, that can be evaluated if(count($values) === count($names)) { $this->pathParameters = array_combine($names, $values); } } } $name = strtolower($name); if(isset($this->pathParameters[$name])) { // both bool false and null are returned as null if($this->pathParameters[$name] === false || is_null($this->pathParameters[$name])) { return null; } return $this->pathParameters[$name]; } return $default; }
[ "public", "function", "getPathParameter", "(", "$", "name", ",", "$", "default", "=", "null", ")", "{", "// lazy initialization of parameters", "if", "(", "empty", "(", "$", "this", "->", "pathParameters", ")", "&&", "!", "is_null", "(", "$", "this", "->", "placeholders", ")", ")", "{", "// collect all placeholder names", "$", "names", "=", "array_keys", "(", "$", "this", "->", "placeholders", ")", ";", "// extract values", "if", "(", "preg_match", "(", "'~'", ".", "$", "this", "->", "match", ".", "'~'", ",", "ltrim", "(", "Request", "::", "createFromGlobals", "(", ")", "->", "getPathInfo", "(", ")", ",", "'/'", ")", ",", "$", "values", ")", ")", "{", "array_shift", "(", "$", "values", ")", ";", "// if not all parameters are set, try to fill up with defaults", "$", "offset", "=", "count", "(", "$", "values", ")", ";", "if", "(", "$", "offset", "<", "count", "(", "$", "names", ")", ")", "{", "while", "(", "$", "offset", "<", "count", "(", "$", "names", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "placeholders", "[", "$", "names", "[", "$", "offset", "]", "]", "[", "'default'", "]", ")", ")", "{", "$", "values", "[", "]", "=", "$", "this", "->", "placeholders", "[", "$", "names", "[", "$", "offset", "]", "]", "[", "'default'", "]", ";", "}", "++", "$", "offset", ";", "}", "}", "// only set parameters when count of placeholders matches count of values, that can be evaluated", "if", "(", "count", "(", "$", "values", ")", "===", "count", "(", "$", "names", ")", ")", "{", "$", "this", "->", "pathParameters", "=", "array_combine", "(", "$", "names", ",", "$", "values", ")", ";", "}", "}", "}", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "pathParameters", "[", "$", "name", "]", ")", ")", "{", "// both bool false and null are returned as null", "if", "(", "$", "this", "->", "pathParameters", "[", "$", "name", "]", "===", "false", "||", "is_null", "(", "$", "this", "->", "pathParameters", "[", "$", "name", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "pathParameters", "[", "$", "name", "]", ";", "}", "return", "$", "default", ";", "}" ]
get path parameter @param string $name @param string $default @return string
[ "get", "path", "parameter" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/Route.php#L522-L576
train
Vectrex/vxPHP
src/Routing/Route.php
Route.redirect
public function redirect($queryParams = [], $statusCode = 302) { $request = Request::createFromGlobals(); $application = Application::getInstance(); $urlSegments = [ $request->getSchemeAndHttpHost() ]; if($application->getRouter()->getServerSideRewrite()) { if(($scriptName = basename($request->getScriptName(), '.php')) !== 'index') { $urlSegments[] = $scriptName; } } else { $urlSegments[] = trim($request->getScriptName(), '/'); } if(count($queryParams)) { $query = '?' . http_build_query($queryParams); } else { $query = ''; } return new RedirectResponse(implode('/', $urlSegments) . '/' . $this->redirect . $query, $statusCode); }
php
public function redirect($queryParams = [], $statusCode = 302) { $request = Request::createFromGlobals(); $application = Application::getInstance(); $urlSegments = [ $request->getSchemeAndHttpHost() ]; if($application->getRouter()->getServerSideRewrite()) { if(($scriptName = basename($request->getScriptName(), '.php')) !== 'index') { $urlSegments[] = $scriptName; } } else { $urlSegments[] = trim($request->getScriptName(), '/'); } if(count($queryParams)) { $query = '?' . http_build_query($queryParams); } else { $query = ''; } return new RedirectResponse(implode('/', $urlSegments) . '/' . $this->redirect . $query, $statusCode); }
[ "public", "function", "redirect", "(", "$", "queryParams", "=", "[", "]", ",", "$", "statusCode", "=", "302", ")", "{", "$", "request", "=", "Request", "::", "createFromGlobals", "(", ")", ";", "$", "application", "=", "Application", "::", "getInstance", "(", ")", ";", "$", "urlSegments", "=", "[", "$", "request", "->", "getSchemeAndHttpHost", "(", ")", "]", ";", "if", "(", "$", "application", "->", "getRouter", "(", ")", "->", "getServerSideRewrite", "(", ")", ")", "{", "if", "(", "(", "$", "scriptName", "=", "basename", "(", "$", "request", "->", "getScriptName", "(", ")", ",", "'.php'", ")", ")", "!==", "'index'", ")", "{", "$", "urlSegments", "[", "]", "=", "$", "scriptName", ";", "}", "}", "else", "{", "$", "urlSegments", "[", "]", "=", "trim", "(", "$", "request", "->", "getScriptName", "(", ")", ",", "'/'", ")", ";", "}", "if", "(", "count", "(", "$", "queryParams", ")", ")", "{", "$", "query", "=", "'?'", ".", "http_build_query", "(", "$", "queryParams", ")", ";", "}", "else", "{", "$", "query", "=", "''", ";", "}", "return", "new", "RedirectResponse", "(", "implode", "(", "'/'", ",", "$", "urlSegments", ")", ".", "'/'", ".", "$", "this", "->", "redirect", ".", "$", "query", ",", "$", "statusCode", ")", ";", "}" ]
redirect using configured redirect information if route has no redirect set, redirect will lead to "start page" @param array $queryParams @param int $statusCode @return RedirectResponse @throws \vxPHP\Application\Exception\ApplicationException
[ "redirect", "using", "configured", "redirect", "information", "if", "route", "has", "no", "redirect", "set", "redirect", "will", "lead", "to", "start", "page" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/Route.php#L634-L662
train
as3io/As3ModlrBundle
DependencyInjection/Utility.php
Utility.locateResource
public static function locateResource($path, ContainerBuilder $container) { if (0 === stripos($path, '@')) { // Treat as a bundle path, e.g. @SomeBundle/path/to/something. // Correct backslashed paths. $path = str_replace('\\', '/', $path); $parts = explode('/', $path); $bundle = array_shift($parts); $bundleName = str_replace('@', '', $bundle); $bundleClass = null; foreach ($container->getParameter('kernel.bundles') as $name => $class) { if ($name === $bundleName) { $bundleClass = $class; break; } } if (null === $bundleClass) { throw new \RuntimeException(sprintf('Unable to find a bundle named "%s" for resource path "%s"', $bundleName, $path)); } $refl = new \ReflectionClass($bundleClass); $bundleDir = dirname($refl->getFileName()); return sprintf('%s/%s', $bundleDir, implode('/', $parts)); } return $path; }
php
public static function locateResource($path, ContainerBuilder $container) { if (0 === stripos($path, '@')) { // Treat as a bundle path, e.g. @SomeBundle/path/to/something. // Correct backslashed paths. $path = str_replace('\\', '/', $path); $parts = explode('/', $path); $bundle = array_shift($parts); $bundleName = str_replace('@', '', $bundle); $bundleClass = null; foreach ($container->getParameter('kernel.bundles') as $name => $class) { if ($name === $bundleName) { $bundleClass = $class; break; } } if (null === $bundleClass) { throw new \RuntimeException(sprintf('Unable to find a bundle named "%s" for resource path "%s"', $bundleName, $path)); } $refl = new \ReflectionClass($bundleClass); $bundleDir = dirname($refl->getFileName()); return sprintf('%s/%s', $bundleDir, implode('/', $parts)); } return $path; }
[ "public", "static", "function", "locateResource", "(", "$", "path", ",", "ContainerBuilder", "$", "container", ")", "{", "if", "(", "0", "===", "stripos", "(", "$", "path", ",", "'@'", ")", ")", "{", "// Treat as a bundle path, e.g. @SomeBundle/path/to/something.", "// Correct backslashed paths.", "$", "path", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "$", "bundle", "=", "array_shift", "(", "$", "parts", ")", ";", "$", "bundleName", "=", "str_replace", "(", "'@'", ",", "''", ",", "$", "bundle", ")", ";", "$", "bundleClass", "=", "null", ";", "foreach", "(", "$", "container", "->", "getParameter", "(", "'kernel.bundles'", ")", "as", "$", "name", "=>", "$", "class", ")", "{", "if", "(", "$", "name", "===", "$", "bundleName", ")", "{", "$", "bundleClass", "=", "$", "class", ";", "break", ";", "}", "}", "if", "(", "null", "===", "$", "bundleClass", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Unable to find a bundle named \"%s\" for resource path \"%s\"'", ",", "$", "bundleName", ",", "$", "path", ")", ")", ";", "}", "$", "refl", "=", "new", "\\", "ReflectionClass", "(", "$", "bundleClass", ")", ";", "$", "bundleDir", "=", "dirname", "(", "$", "refl", "->", "getFileName", "(", ")", ")", ";", "return", "sprintf", "(", "'%s/%s'", ",", "$", "bundleDir", ",", "implode", "(", "'/'", ",", "$", "parts", ")", ")", ";", "}", "return", "$", "path", ";", "}" ]
Locates a file resource path for a given config path. Is needed in order to retrieve a bundle's directory, if used. @static @param string $path @param ContainerBuilder $container @return string @throws \RuntimeException
[ "Locates", "a", "file", "resource", "path", "for", "a", "given", "config", "path", ".", "Is", "needed", "in", "order", "to", "retrieve", "a", "bundle", "s", "directory", "if", "used", "." ]
7ce2abb7390c7eaf4081c5b7e00b96e7001774a4
https://github.com/as3io/As3ModlrBundle/blob/7ce2abb7390c7eaf4081c5b7e00b96e7001774a4/DependencyInjection/Utility.php#L116-L145
train
horntell/php-sdk
lib/guzzle/GuzzleHttp/Exception/RequestException.php
RequestException.emittedError
public function emittedError($value = null) { if ($value === null) { return $this->emittedErrorEvent; } elseif ($value === true) { $this->emittedErrorEvent = true; } else { throw new \InvalidArgumentException('You cannot set the emitted ' . 'error value to false.'); } }
php
public function emittedError($value = null) { if ($value === null) { return $this->emittedErrorEvent; } elseif ($value === true) { $this->emittedErrorEvent = true; } else { throw new \InvalidArgumentException('You cannot set the emitted ' . 'error value to false.'); } }
[ "public", "function", "emittedError", "(", "$", "value", "=", "null", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "$", "this", "->", "emittedErrorEvent", ";", "}", "elseif", "(", "$", "value", "===", "true", ")", "{", "$", "this", "->", "emittedErrorEvent", "=", "true", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'You cannot set the emitted '", ".", "'error value to false.'", ")", ";", "}", "}" ]
Check or set if the exception was emitted in an error event. This value is used in the RequestEvents::emitBefore() method to check to see if an exception has already been emitted in an error event. @param bool|null Set to true to set the exception as having emitted an error. Leave null to retrieve the current setting. @return null|bool @throws \InvalidArgumentException if you attempt to set the value to false
[ "Check", "or", "set", "if", "the", "exception", "was", "emitted", "in", "an", "error", "event", "." ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Exception/RequestException.php#L116-L126
train
erenmustafaozdal/laravel-modules-base
src/Requests/BaseRequest.php
BaseRequest.addFileRule
protected function addFileRule($attribute, $size, $mimes, $count = 1, $isRequired = false) { if ($this->has($attribute) && is_string($this->$attribute)) { $this->rules[$attribute] = "elfinder_max:{$size}|elfinder:{$mimes}"; } else if ($this->file($attribute) && is_array($this->$attribute)){ $this->rules[$attribute] = "array|max:{$count}"; foreach($this->file($attribute) as $key => $file) { if(array_search($key, ['x','y','width','height']) !== false) { continue; } $this->rules[$attribute . '.' . $key] = "max:{$size}|image|mimes:{$mimes}"; if ($isRequired) { $this->rules[$attribute . '.' . $key] = "required|{$this->rules[$attribute . '.' . $key]}"; } } } else if ($this->has($attribute) && is_array($this->$attribute)) { $this->rules[$attribute] = "array|max:{$count}"; foreach($this->get($attribute) as $key => $file) { if(array_search($key, ['x','y','width','height']) !== false) { continue; } $this->rules[$attribute . '.' . $key] = "elfinder_max:{$size}|elfinder:{$mimes}"; if ($isRequired) { $this->rules[$attribute . '.' . $key] = "required|{$this->rules[$attribute . '.' . $key]}"; } } } else if ($this->file($attribute)) { $this->rules[$attribute] = "max:{$size}|image|mimes:{$mimes}"; } if ($isRequired) { $this->rules[$attribute] = "required|{$this->rules[$attribute]}"; } }
php
protected function addFileRule($attribute, $size, $mimes, $count = 1, $isRequired = false) { if ($this->has($attribute) && is_string($this->$attribute)) { $this->rules[$attribute] = "elfinder_max:{$size}|elfinder:{$mimes}"; } else if ($this->file($attribute) && is_array($this->$attribute)){ $this->rules[$attribute] = "array|max:{$count}"; foreach($this->file($attribute) as $key => $file) { if(array_search($key, ['x','y','width','height']) !== false) { continue; } $this->rules[$attribute . '.' . $key] = "max:{$size}|image|mimes:{$mimes}"; if ($isRequired) { $this->rules[$attribute . '.' . $key] = "required|{$this->rules[$attribute . '.' . $key]}"; } } } else if ($this->has($attribute) && is_array($this->$attribute)) { $this->rules[$attribute] = "array|max:{$count}"; foreach($this->get($attribute) as $key => $file) { if(array_search($key, ['x','y','width','height']) !== false) { continue; } $this->rules[$attribute . '.' . $key] = "elfinder_max:{$size}|elfinder:{$mimes}"; if ($isRequired) { $this->rules[$attribute . '.' . $key] = "required|{$this->rules[$attribute . '.' . $key]}"; } } } else if ($this->file($attribute)) { $this->rules[$attribute] = "max:{$size}|image|mimes:{$mimes}"; } if ($isRequired) { $this->rules[$attribute] = "required|{$this->rules[$attribute]}"; } }
[ "protected", "function", "addFileRule", "(", "$", "attribute", ",", "$", "size", ",", "$", "mimes", ",", "$", "count", "=", "1", ",", "$", "isRequired", "=", "false", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "attribute", ")", "&&", "is_string", "(", "$", "this", "->", "$", "attribute", ")", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", "]", "=", "\"elfinder_max:{$size}|elfinder:{$mimes}\"", ";", "}", "else", "if", "(", "$", "this", "->", "file", "(", "$", "attribute", ")", "&&", "is_array", "(", "$", "this", "->", "$", "attribute", ")", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", "]", "=", "\"array|max:{$count}\"", ";", "foreach", "(", "$", "this", "->", "file", "(", "$", "attribute", ")", "as", "$", "key", "=>", "$", "file", ")", "{", "if", "(", "array_search", "(", "$", "key", ",", "[", "'x'", ",", "'y'", ",", "'width'", ",", "'height'", "]", ")", "!==", "false", ")", "{", "continue", ";", "}", "$", "this", "->", "rules", "[", "$", "attribute", ".", "'.'", ".", "$", "key", "]", "=", "\"max:{$size}|image|mimes:{$mimes}\"", ";", "if", "(", "$", "isRequired", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", ".", "'.'", ".", "$", "key", "]", "=", "\"required|{$this->rules[$attribute . '.' . $key]}\"", ";", "}", "}", "}", "else", "if", "(", "$", "this", "->", "has", "(", "$", "attribute", ")", "&&", "is_array", "(", "$", "this", "->", "$", "attribute", ")", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", "]", "=", "\"array|max:{$count}\"", ";", "foreach", "(", "$", "this", "->", "get", "(", "$", "attribute", ")", "as", "$", "key", "=>", "$", "file", ")", "{", "if", "(", "array_search", "(", "$", "key", ",", "[", "'x'", ",", "'y'", ",", "'width'", ",", "'height'", "]", ")", "!==", "false", ")", "{", "continue", ";", "}", "$", "this", "->", "rules", "[", "$", "attribute", ".", "'.'", ".", "$", "key", "]", "=", "\"elfinder_max:{$size}|elfinder:{$mimes}\"", ";", "if", "(", "$", "isRequired", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", ".", "'.'", ".", "$", "key", "]", "=", "\"required|{$this->rules[$attribute . '.' . $key]}\"", ";", "}", "}", "}", "else", "if", "(", "$", "this", "->", "file", "(", "$", "attribute", ")", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", "]", "=", "\"max:{$size}|image|mimes:{$mimes}\"", ";", "}", "if", "(", "$", "isRequired", ")", "{", "$", "this", "->", "rules", "[", "$", "attribute", "]", "=", "\"required|{$this->rules[$attribute]}\"", ";", "}", "}" ]
add file rule to rules @param string $attribute @param string $size @param string $mimes @param integer $count @param boolean $isRequired @return void
[ "add", "file", "rule", "to", "rules" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Requests/BaseRequest.php#L58-L93
train
MBHFramework/mbh-rest
Mbh/App.php
App.getSetting
public function getSetting($key, $defaultValue = null) { return $this->hasSetting($key) ? $this->settings[$key] : $defaultValue; }
php
public function getSetting($key, $defaultValue = null) { return $this->hasSetting($key) ? $this->settings[$key] : $defaultValue; }
[ "public", "function", "getSetting", "(", "$", "key", ",", "$", "defaultValue", "=", "null", ")", "{", "return", "$", "this", "->", "hasSetting", "(", "$", "key", ")", "?", "$", "this", "->", "settings", "[", "$", "key", "]", ":", "$", "defaultValue", ";", "}" ]
Get app setting with given key @param string $key @param mixed $defaultValue @return mixed
[ "Get", "app", "setting", "with", "given", "key" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L169-L172
train
MBHFramework/mbh-rest
Mbh/App.php
App.get
public function get($pattern, $callback = null, $inject = null) { return $this->map([ 'GET', 'HEAD' ], $pattern, $callback, $inject); }
php
public function get($pattern, $callback = null, $inject = null) { return $this->map([ 'GET', 'HEAD' ], $pattern, $callback, $inject); }
[ "public", "function", "get", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'GET'", ",", "'HEAD'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `GET` @param string $route the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "GET" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L206-L209
train
MBHFramework/mbh-rest
Mbh/App.php
App.post
public function post($pattern, $callback = null, $inject = null) { return $this->map([ 'POST' ], $pattern, $callback, $inject); }
php
public function post($pattern, $callback = null, $inject = null) { return $this->map([ 'POST' ], $pattern, $callback, $inject); }
[ "public", "function", "post", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'POST'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `POST` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "POST" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L219-L222
train
MBHFramework/mbh-rest
Mbh/App.php
App.put
public function put($pattern, $callback = null, $inject = null) { return $this->map([ 'PUT' ], $pattern, $callback, $inject); }
php
public function put($pattern, $callback = null, $inject = null) { return $this->map([ 'PUT' ], $pattern, $callback, $inject); }
[ "public", "function", "put", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'PUT'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `PUT` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "PUT" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L232-L235
train
MBHFramework/mbh-rest
Mbh/App.php
App.patch
public function patch($pattern, $callback = null, $inject = null) { return $this->map([ 'PATCH' ], $pattern, $callback, $inject); }
php
public function patch($pattern, $callback = null, $inject = null) { return $this->map([ 'PATCH' ], $pattern, $callback, $inject); }
[ "public", "function", "patch", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'PATCH'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `PATCH` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "PATCH" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L245-L248
train
MBHFramework/mbh-rest
Mbh/App.php
App.delete
public function delete($pattern, $callback = null, $inject = null) { return $this->map([ 'DELETE' ], $pattern, $callback, $inject); }
php
public function delete($pattern, $callback = null, $inject = null) { return $this->map([ 'DELETE' ], $pattern, $callback, $inject); }
[ "public", "function", "delete", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'DELETE'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `DELETE` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "DELETE" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L258-L261
train
MBHFramework/mbh-rest
Mbh/App.php
App.head
public function head($pattern, $callback = null, $inject = null) { return $this->map([ 'HEAD' ], $pattern, $callback, $inject); }
php
public function head($pattern, $callback = null, $inject = null) { return $this->map([ 'HEAD' ], $pattern, $callback, $inject); }
[ "public", "function", "head", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'HEAD'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `HEAD` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "HEAD" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L271-L274
train
MBHFramework/mbh-rest
Mbh/App.php
App.trace
public function trace($pattern, $callback = null, $inject = null) { return $this->map([ 'TRACE' ], $pattern, $callback, $inject); }
php
public function trace($pattern, $callback = null, $inject = null) { return $this->map([ 'TRACE' ], $pattern, $callback, $inject); }
[ "public", "function", "trace", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'TRACE'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `TRACE` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "TRACE" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L284-L287
train
MBHFramework/mbh-rest
Mbh/App.php
App.options
public function options($pattern, $callback = null, $inject = null) { return $this->map([ 'OPTIONS' ], $pattern, $callback, $inject); }
php
public function options($pattern, $callback = null, $inject = null) { return $this->map([ 'OPTIONS' ], $pattern, $callback, $inject); }
[ "public", "function", "options", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'OPTIONS'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `OPTIONS` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "OPTIONS" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L297-L300
train
MBHFramework/mbh-rest
Mbh/App.php
App.connect
public function connect($pattern, $callback = null, $inject = null) { return $this->map([ 'CONNECT' ], $pattern, $callback, $inject); }
php
public function connect($pattern, $callback = null, $inject = null) { return $this->map([ 'CONNECT' ], $pattern, $callback, $inject); }
[ "public", "function", "connect", "(", "$", "pattern", ",", "$", "callback", "=", "null", ",", "$", "inject", "=", "null", ")", "{", "return", "$", "this", "->", "map", "(", "[", "'CONNECT'", "]", ",", "$", "pattern", ",", "$", "callback", ",", "$", "inject", ")", ";", "}" ]
Adds a new route for the HTTP request method `CONNECT` @param string $pattern the route to match, e.g. `/users/jane` @param callable|null $callback (optional) the callback to execute, e.g. an anonymous function @param array|null $inject (optional) any arguments that should be prepended to those matched in the route @return bool whether the route matched the current request
[ "Adds", "a", "new", "route", "for", "the", "HTTP", "request", "method", "CONNECT" ]
e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83
https://github.com/MBHFramework/mbh-rest/blob/e23b4e66dc2b8da35e06312dcfdba41c4cfc2c83/Mbh/App.php#L310-L313
train
Vectrex/vxPHP
src/Controller/Controller.php
Controller.createControllerFromRoute
public static function createControllerFromRoute(Route $route, array $parameters = null) { $controllerClass = Application::getInstance()->getApplicationNamespace() . $route->getControllerClassName(); /** * @var Controller */ $instance = new $controllerClass($route, $parameters); if($method = $instance->route->getMethodName()) { $instance->setExecutedMethod($method); } else { $instance->setExecutedMethod('execute'); } return $instance; }
php
public static function createControllerFromRoute(Route $route, array $parameters = null) { $controllerClass = Application::getInstance()->getApplicationNamespace() . $route->getControllerClassName(); /** * @var Controller */ $instance = new $controllerClass($route, $parameters); if($method = $instance->route->getMethodName()) { $instance->setExecutedMethod($method); } else { $instance->setExecutedMethod('execute'); } return $instance; }
[ "public", "static", "function", "createControllerFromRoute", "(", "Route", "$", "route", ",", "array", "$", "parameters", "=", "null", ")", "{", "$", "controllerClass", "=", "Application", "::", "getInstance", "(", ")", "->", "getApplicationNamespace", "(", ")", ".", "$", "route", "->", "getControllerClassName", "(", ")", ";", "/**\n\t\t * @var Controller\n\t\t */", "$", "instance", "=", "new", "$", "controllerClass", "(", "$", "route", ",", "$", "parameters", ")", ";", "if", "(", "$", "method", "=", "$", "instance", "->", "route", "->", "getMethodName", "(", ")", ")", "{", "$", "instance", "->", "setExecutedMethod", "(", "$", "method", ")", ";", "}", "else", "{", "$", "instance", "->", "setExecutedMethod", "(", "'execute'", ")", ";", "}", "return", "$", "instance", ";", "}" ]
determines controller class name from a routes controllerString property and returns a controller instance an additional parameters array will be passed on to the constructor @param Route $route @param array $parameters @return \vxPHP\Controller\Controller @throws \vxPHP\Application\Exception\ApplicationException
[ "determines", "controller", "class", "name", "from", "a", "routes", "controllerString", "property", "and", "returns", "a", "controller", "instance", "an", "additional", "parameters", "array", "will", "be", "passed", "on", "to", "the", "constructor" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Controller/Controller.php#L190-L208
train
Vectrex/vxPHP
src/Controller/Controller.php
Controller.addEchoToJsonResponse
protected function addEchoToJsonResponse(JsonResponse $r) { // handle JSON encoded request data if($this->isXhr && $this->xhrBag && $this->xhrBag->get('echo') == 1) { // echo is the original xmlHttpRequest sans echo property $echo = json_decode($this->xhrBag->get('xmlHttpRequest')); unset($echo->echo); } // handle plain POST or GET data else { if($this->request->getMethod() === 'POST' && $this->request->request->get('echo')) { $echo = $this->request->request->all(); unset($echo['echo']); } else if($this->request->query->get('echo')) { $echo = $this->request->query->all(); unset($echo['echo']); } } if(isset($echo)) { $r->setPayload([ 'echo' => $echo, 'response' => json_decode($r->getContent()) ]); } return $r; }
php
protected function addEchoToJsonResponse(JsonResponse $r) { // handle JSON encoded request data if($this->isXhr && $this->xhrBag && $this->xhrBag->get('echo') == 1) { // echo is the original xmlHttpRequest sans echo property $echo = json_decode($this->xhrBag->get('xmlHttpRequest')); unset($echo->echo); } // handle plain POST or GET data else { if($this->request->getMethod() === 'POST' && $this->request->request->get('echo')) { $echo = $this->request->request->all(); unset($echo['echo']); } else if($this->request->query->get('echo')) { $echo = $this->request->query->all(); unset($echo['echo']); } } if(isset($echo)) { $r->setPayload([ 'echo' => $echo, 'response' => json_decode($r->getContent()) ]); } return $r; }
[ "protected", "function", "addEchoToJsonResponse", "(", "JsonResponse", "$", "r", ")", "{", "// handle JSON encoded request data", "if", "(", "$", "this", "->", "isXhr", "&&", "$", "this", "->", "xhrBag", "&&", "$", "this", "->", "xhrBag", "->", "get", "(", "'echo'", ")", "==", "1", ")", "{", "// echo is the original xmlHttpRequest sans echo property", "$", "echo", "=", "json_decode", "(", "$", "this", "->", "xhrBag", "->", "get", "(", "'xmlHttpRequest'", ")", ")", ";", "unset", "(", "$", "echo", "->", "echo", ")", ";", "}", "// handle plain POST or GET data", "else", "{", "if", "(", "$", "this", "->", "request", "->", "getMethod", "(", ")", "===", "'POST'", "&&", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'echo'", ")", ")", "{", "$", "echo", "=", "$", "this", "->", "request", "->", "request", "->", "all", "(", ")", ";", "unset", "(", "$", "echo", "[", "'echo'", "]", ")", ";", "}", "else", "if", "(", "$", "this", "->", "request", "->", "query", "->", "get", "(", "'echo'", ")", ")", "{", "$", "echo", "=", "$", "this", "->", "request", "->", "query", "->", "all", "(", ")", ";", "unset", "(", "$", "echo", "[", "'echo'", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "echo", ")", ")", "{", "$", "r", "->", "setPayload", "(", "[", "'echo'", "=>", "$", "echo", ",", "'response'", "=>", "json_decode", "(", "$", "r", "->", "getContent", "(", ")", ")", "]", ")", ";", "}", "return", "$", "r", ";", "}" ]
add an echo property to a JsonResponse, if request indicates that echo was requested useful with vxJS.xhr based widgets @param JsonResponse $r @return JsonResponse @throws \Exception
[ "add", "an", "echo", "property", "to", "a", "JsonResponse", "if", "request", "indicates", "that", "echo", "was", "requested", "useful", "with", "vxJS", ".", "xhr", "based", "widgets" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Controller/Controller.php#L264-L302
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Framework/Domain/Action/Dal/DalActionTrait.php
DalActionTrait.assertEntityIsValid
protected function assertEntityIsValid($entity, $scope = null) { if (!$this->validator) { throw new \BadMethodCallException(sprintf( 'Method %s() cannot be used while validator is not configured.', __METHOD__ )); } $scopes = $scope ? (array) $scope : null; $violationList = $this->validator->validate( $entity, null, $scopes ); if (!count($violationList)) { return; } throw new ValidationException($entity, $violationList, $scopes); }
php
protected function assertEntityIsValid($entity, $scope = null) { if (!$this->validator) { throw new \BadMethodCallException(sprintf( 'Method %s() cannot be used while validator is not configured.', __METHOD__ )); } $scopes = $scope ? (array) $scope : null; $violationList = $this->validator->validate( $entity, null, $scopes ); if (!count($violationList)) { return; } throw new ValidationException($entity, $violationList, $scopes); }
[ "protected", "function", "assertEntityIsValid", "(", "$", "entity", ",", "$", "scope", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "validator", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "sprintf", "(", "'Method %s() cannot be used while validator is not configured.'", ",", "__METHOD__", ")", ")", ";", "}", "$", "scopes", "=", "$", "scope", "?", "(", "array", ")", "$", "scope", ":", "null", ";", "$", "violationList", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "entity", ",", "null", ",", "$", "scopes", ")", ";", "if", "(", "!", "count", "(", "$", "violationList", ")", ")", "{", "return", ";", "}", "throw", "new", "ValidationException", "(", "$", "entity", ",", "$", "violationList", ",", "$", "scopes", ")", ";", "}" ]
assert given entity is valid on given scope. @param object $entity @param string|array $scope @throws ValidationException If given object is invalid on given scope
[ "assert", "given", "entity", "is", "valid", "on", "given", "scope", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Domain/Action/Dal/DalActionTrait.php#L55-L77
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Framework/Domain/Action/Dal/DalActionTrait.php
DalActionTrait.fireEvent
protected function fireEvent($eventName, Event $event) { if (!$this->eventDispatcher) { throw new \BadMethodCallException(sprintf( 'Method %s() cannot be used while event dispatcher is not configured.', __METHOD__ )); } $this->eventDispatcher->dispatch($eventName, $event); }
php
protected function fireEvent($eventName, Event $event) { if (!$this->eventDispatcher) { throw new \BadMethodCallException(sprintf( 'Method %s() cannot be used while event dispatcher is not configured.', __METHOD__ )); } $this->eventDispatcher->dispatch($eventName, $event); }
[ "protected", "function", "fireEvent", "(", "$", "eventName", ",", "Event", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "eventDispatcher", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "sprintf", "(", "'Method %s() cannot be used while event dispatcher is not configured.'", ",", "__METHOD__", ")", ")", ";", "}", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "$", "eventName", ",", "$", "event", ")", ";", "}" ]
fire given event. @param string $eventName @param Event $event @throws \BadMethodCallException If any event dispatcher set
[ "fire", "given", "event", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Domain/Action/Dal/DalActionTrait.php#L87-L97
train
pipaslot/forms
src/Forms/Rendering/Bootstrap3StackRenderer.php
Bootstrap3StackRenderer.prepareForm
protected function prepareForm(Form $form) { $form->getElementPrototype()->class[] = 'form-horizontal'; $translator = $form->getTranslator(); foreach ($form->controls as $control) { /** @var BaseControl $control */ if ($control instanceof HiddenField) { continue; } elseif ($control instanceof Button) { $control->controlPrototype->class[] = "btn-block btn-lg"; } else { if ($control->getLabel()) { $control->setAttribute('placeholder', $control->caption); if (empty($control->controlPrototype->attrs['title'])) { $control->setAttribute('title', $translator ? $translator->translate($control->caption) : $control->caption); } $control->getLabelPrototype()->attrs["style"] = "display:none"; } } } BootstrapHelper::ApplyBootstrapToControls($form); }
php
protected function prepareForm(Form $form) { $form->getElementPrototype()->class[] = 'form-horizontal'; $translator = $form->getTranslator(); foreach ($form->controls as $control) { /** @var BaseControl $control */ if ($control instanceof HiddenField) { continue; } elseif ($control instanceof Button) { $control->controlPrototype->class[] = "btn-block btn-lg"; } else { if ($control->getLabel()) { $control->setAttribute('placeholder', $control->caption); if (empty($control->controlPrototype->attrs['title'])) { $control->setAttribute('title', $translator ? $translator->translate($control->caption) : $control->caption); } $control->getLabelPrototype()->attrs["style"] = "display:none"; } } } BootstrapHelper::ApplyBootstrapToControls($form); }
[ "protected", "function", "prepareForm", "(", "Form", "$", "form", ")", "{", "$", "form", "->", "getElementPrototype", "(", ")", "->", "class", "[", "]", "=", "'form-horizontal'", ";", "$", "translator", "=", "$", "form", "->", "getTranslator", "(", ")", ";", "foreach", "(", "$", "form", "->", "controls", "as", "$", "control", ")", "{", "/** @var BaseControl $control */", "if", "(", "$", "control", "instanceof", "HiddenField", ")", "{", "continue", ";", "}", "elseif", "(", "$", "control", "instanceof", "Button", ")", "{", "$", "control", "->", "controlPrototype", "->", "class", "[", "]", "=", "\"btn-block btn-lg\"", ";", "}", "else", "{", "if", "(", "$", "control", "->", "getLabel", "(", ")", ")", "{", "$", "control", "->", "setAttribute", "(", "'placeholder'", ",", "$", "control", "->", "caption", ")", ";", "if", "(", "empty", "(", "$", "control", "->", "controlPrototype", "->", "attrs", "[", "'title'", "]", ")", ")", "{", "$", "control", "->", "setAttribute", "(", "'title'", ",", "$", "translator", "?", "$", "translator", "->", "translate", "(", "$", "control", "->", "caption", ")", ":", "$", "control", "->", "caption", ")", ";", "}", "$", "control", "->", "getLabelPrototype", "(", ")", "->", "attrs", "[", "\"style\"", "]", "=", "\"display:none\"", ";", "}", "}", "}", "BootstrapHelper", "::", "ApplyBootstrapToControls", "(", "$", "form", ")", ";", "}" ]
Make form and controls compatible with Twitter Bootstrap @param Form $form
[ "Make", "form", "and", "controls", "compatible", "with", "Twitter", "Bootstrap" ]
9e1d48db512f843270fd4079ed3ff1b1729c951b
https://github.com/pipaslot/forms/blob/9e1d48db512f843270fd4079ed3ff1b1729c951b/src/Forms/Rendering/Bootstrap3StackRenderer.php#L37-L58
train
clacy-builders/graphics-php
src/Points.php
Points.rectangle
public static function rectangle(Point $corner, $width, $height, $ccw = false) { $points = new Points($corner); $points->addPoint($corner); $points->addPoint($corner)->translateX($width); $points->addPoint($corner)->translate($width, $height); $points->addPoint($corner)->translateY($height); $points->reverseIfCcw($ccw); return $points; }
php
public static function rectangle(Point $corner, $width, $height, $ccw = false) { $points = new Points($corner); $points->addPoint($corner); $points->addPoint($corner)->translateX($width); $points->addPoint($corner)->translate($width, $height); $points->addPoint($corner)->translateY($height); $points->reverseIfCcw($ccw); return $points; }
[ "public", "static", "function", "rectangle", "(", "Point", "$", "corner", ",", "$", "width", ",", "$", "height", ",", "$", "ccw", "=", "false", ")", "{", "$", "points", "=", "new", "Points", "(", "$", "corner", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateX", "(", "$", "width", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translate", "(", "$", "width", ",", "$", "height", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateY", "(", "$", "height", ")", ";", "$", "points", "->", "reverseIfCcw", "(", "$", "ccw", ")", ";", "return", "$", "points", ";", "}" ]
Calculates the points for a rectangle. @param Point $corner The top left corner. @param float $width @param float $height @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "points", "for", "a", "rectangle", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L52-L61
train
clacy-builders/graphics-php
src/Points.php
Points.polygon
public static function polygon(Point $center, $n, $radius, $ccw = false) { return self::star($center, $n, $radius, [], $ccw); }
php
public static function polygon(Point $center, $n, $radius, $ccw = false) { return self::star($center, $n, $radius, [], $ccw); }
[ "public", "static", "function", "polygon", "(", "Point", "$", "center", ",", "$", "n", ",", "$", "radius", ",", "$", "ccw", "=", "false", ")", "{", "return", "self", "::", "star", "(", "$", "center", ",", "$", "n", ",", "$", "radius", ",", "[", "]", ",", "$", "ccw", ")", ";", "}" ]
Calculates the points for a regular polygon. @param Point $center @param int $n Number of corners. @param float $radius @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "points", "for", "a", "regular", "polygon", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L71-L74
train
clacy-builders/graphics-php
src/Points.php
Points.star
public static function star(Point $center, $n, $radius, $starRadii = [], $ccw = false) { $points = new Points($center); if (!is_array($starRadii)) { $starRadii = [$starRadii]; } $radii = array_merge([$radius], $starRadii); $count = count($radii); $delta = deg2rad(360) / $n / $count; $angle = Angle::create(0); for ($i = 0; $i < $n; $i++) { foreach ($radii as $k => $radius) { $points->addPoint($center)->translateY(-$radius)->rotate($center, $angle); $angle->add($delta); } } $points->reverseIfCcw($ccw); return $points; }
php
public static function star(Point $center, $n, $radius, $starRadii = [], $ccw = false) { $points = new Points($center); if (!is_array($starRadii)) { $starRadii = [$starRadii]; } $radii = array_merge([$radius], $starRadii); $count = count($radii); $delta = deg2rad(360) / $n / $count; $angle = Angle::create(0); for ($i = 0; $i < $n; $i++) { foreach ($radii as $k => $radius) { $points->addPoint($center)->translateY(-$radius)->rotate($center, $angle); $angle->add($delta); } } $points->reverseIfCcw($ccw); return $points; }
[ "public", "static", "function", "star", "(", "Point", "$", "center", ",", "$", "n", ",", "$", "radius", ",", "$", "starRadii", "=", "[", "]", ",", "$", "ccw", "=", "false", ")", "{", "$", "points", "=", "new", "Points", "(", "$", "center", ")", ";", "if", "(", "!", "is_array", "(", "$", "starRadii", ")", ")", "{", "$", "starRadii", "=", "[", "$", "starRadii", "]", ";", "}", "$", "radii", "=", "array_merge", "(", "[", "$", "radius", "]", ",", "$", "starRadii", ")", ";", "$", "count", "=", "count", "(", "$", "radii", ")", ";", "$", "delta", "=", "deg2rad", "(", "360", ")", "/", "$", "n", "/", "$", "count", ";", "$", "angle", "=", "Angle", "::", "create", "(", "0", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "n", ";", "$", "i", "++", ")", "{", "foreach", "(", "$", "radii", "as", "$", "k", "=>", "$", "radius", ")", "{", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateY", "(", "-", "$", "radius", ")", "->", "rotate", "(", "$", "center", ",", "$", "angle", ")", ";", "$", "angle", "->", "add", "(", "$", "delta", ")", ";", "}", "}", "$", "points", "->", "reverseIfCcw", "(", "$", "ccw", ")", ";", "return", "$", "points", ";", "}" ]
Calculates the Points for a regular star polygon. @param Point $center @param int $n Number of corners of the underlying polygon. @param float $radius @param float|float[] $starRadii @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "Points", "for", "a", "regular", "star", "polygon", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L85-L103
train
clacy-builders/graphics-php
src/Points.php
Points.sector
public static function sector(Point $center, Angle $start, Angle $stop, $radius, $ccw = false) { $points = new Points($center); $points->addPoint($center); $points->addPoint($center)->translateX($radius)->rotate($center, $start); $points->addPoint($center)->translateX($radius)->rotate($center, $stop); $points->reverseIfCcw($ccw); return $points; }
php
public static function sector(Point $center, Angle $start, Angle $stop, $radius, $ccw = false) { $points = new Points($center); $points->addPoint($center); $points->addPoint($center)->translateX($radius)->rotate($center, $start); $points->addPoint($center)->translateX($radius)->rotate($center, $stop); $points->reverseIfCcw($ccw); return $points; }
[ "public", "static", "function", "sector", "(", "Point", "$", "center", ",", "Angle", "$", "start", ",", "Angle", "$", "stop", ",", "$", "radius", ",", "$", "ccw", "=", "false", ")", "{", "$", "points", "=", "new", "Points", "(", "$", "center", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "radius", ")", "->", "rotate", "(", "$", "center", ",", "$", "start", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "radius", ")", "->", "rotate", "(", "$", "center", ",", "$", "stop", ")", ";", "$", "points", "->", "reverseIfCcw", "(", "$", "ccw", ")", ";", "return", "$", "points", ";", "}" ]
Calculates the points for a sector of a circle. @param Point $center @param Angle $start @param Angle $stop Must be greater than <code>$start</code>. @param float $radius @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "points", "for", "a", "sector", "of", "a", "circle", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L129-L137
train
clacy-builders/graphics-php
src/Points.php
Points.ringSector
public static function ringSector(Point $center, Angle $start, Angle $stop, $radius, $innerRadius, $ccw = false) { $points = new Points($center, false); if ($ccw) { $swap = $start; $start = $stop; $stop = $swap; } $points->addPoint($center)->translateX($radius)->rotate($center, $start); $points->addPoint($center)->translateX($radius)->rotate($center, $stop); $points->addPoint($center)->translateX($innerRadius)->rotate($center, $stop); $points->addPoint($center)->translateX($innerRadius)->rotate($center, $start); return $points; }
php
public static function ringSector(Point $center, Angle $start, Angle $stop, $radius, $innerRadius, $ccw = false) { $points = new Points($center, false); if ($ccw) { $swap = $start; $start = $stop; $stop = $swap; } $points->addPoint($center)->translateX($radius)->rotate($center, $start); $points->addPoint($center)->translateX($radius)->rotate($center, $stop); $points->addPoint($center)->translateX($innerRadius)->rotate($center, $stop); $points->addPoint($center)->translateX($innerRadius)->rotate($center, $start); return $points; }
[ "public", "static", "function", "ringSector", "(", "Point", "$", "center", ",", "Angle", "$", "start", ",", "Angle", "$", "stop", ",", "$", "radius", ",", "$", "innerRadius", ",", "$", "ccw", "=", "false", ")", "{", "$", "points", "=", "new", "Points", "(", "$", "center", ",", "false", ")", ";", "if", "(", "$", "ccw", ")", "{", "$", "swap", "=", "$", "start", ";", "$", "start", "=", "$", "stop", ";", "$", "stop", "=", "$", "swap", ";", "}", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "radius", ")", "->", "rotate", "(", "$", "center", ",", "$", "start", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "radius", ")", "->", "rotate", "(", "$", "center", ",", "$", "stop", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "innerRadius", ")", "->", "rotate", "(", "$", "center", ",", "$", "stop", ")", ";", "$", "points", "->", "addPoint", "(", "$", "center", ")", "->", "translateX", "(", "$", "innerRadius", ")", "->", "rotate", "(", "$", "center", ",", "$", "start", ")", ";", "return", "$", "points", ";", "}" ]
Calculates the points for a sector of a ring. @param Point $center @param Angle $start @param Angle $stop Must be greater than <code>$start</code>. @param float $radius @param float $innerRadius @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "points", "for", "a", "sector", "of", "a", "ring", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L149-L159
train
clacy-builders/graphics-php
src/Points.php
Points.roundedRectangle
public static function roundedRectangle(Point $corner, $width, $height, $radius, $ccw = false) { $points = new Points($corner, false); $points->addPoint($corner)->translateX($width - $radius); $points->addPoint($corner)->translate($width, $radius); $points->addPoint($corner)->translate($width, $height - $radius); $points->addPoint($corner)->translate($width - $radius, $height); $points->addPoint($corner)->translate($radius, $height); $points->addPoint($corner)->translateY($height - $radius); $points->addPoint($corner)->translateY($radius); $points->addPoint($corner)->translateX($radius); $points->reverseIfCcw($ccw); return $points; }
php
public static function roundedRectangle(Point $corner, $width, $height, $radius, $ccw = false) { $points = new Points($corner, false); $points->addPoint($corner)->translateX($width - $radius); $points->addPoint($corner)->translate($width, $radius); $points->addPoint($corner)->translate($width, $height - $radius); $points->addPoint($corner)->translate($width - $radius, $height); $points->addPoint($corner)->translate($radius, $height); $points->addPoint($corner)->translateY($height - $radius); $points->addPoint($corner)->translateY($radius); $points->addPoint($corner)->translateX($radius); $points->reverseIfCcw($ccw); return $points; }
[ "public", "static", "function", "roundedRectangle", "(", "Point", "$", "corner", ",", "$", "width", ",", "$", "height", ",", "$", "radius", ",", "$", "ccw", "=", "false", ")", "{", "$", "points", "=", "new", "Points", "(", "$", "corner", ",", "false", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateX", "(", "$", "width", "-", "$", "radius", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translate", "(", "$", "width", ",", "$", "radius", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translate", "(", "$", "width", ",", "$", "height", "-", "$", "radius", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translate", "(", "$", "width", "-", "$", "radius", ",", "$", "height", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translate", "(", "$", "radius", ",", "$", "height", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateY", "(", "$", "height", "-", "$", "radius", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateY", "(", "$", "radius", ")", ";", "$", "points", "->", "addPoint", "(", "$", "corner", ")", "->", "translateX", "(", "$", "radius", ")", ";", "$", "points", "->", "reverseIfCcw", "(", "$", "ccw", ")", ";", "return", "$", "points", ";", "}" ]
Calculates the points for a rounded rectangle. @param Point $corner The top left corner. @param float $width @param float $height @param float $radius @param boolean $ccw Whether to list the points counterclockwise or not.
[ "Calculates", "the", "points", "for", "a", "rounded", "rectangle", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L170-L183
train
clacy-builders/graphics-php
src/Points.php
Points.scale
public function scale(Point $center, $factor) { foreach ($this->points as $point) { $point->scale($center, $factor); } $this->start->scale($center, $factor); return $this; }
php
public function scale(Point $center, $factor) { foreach ($this->points as $point) { $point->scale($center, $factor); } $this->start->scale($center, $factor); return $this; }
[ "public", "function", "scale", "(", "Point", "$", "center", ",", "$", "factor", ")", "{", "foreach", "(", "$", "this", "->", "points", "as", "$", "point", ")", "{", "$", "point", "->", "scale", "(", "$", "center", ",", "$", "factor", ")", ";", "}", "$", "this", "->", "start", "->", "scale", "(", "$", "center", ",", "$", "factor", ")", ";", "return", "$", "this", ";", "}" ]
Scales points. @param Point $center @param float $factor
[ "Scales", "points", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L206-L213
train
clacy-builders/graphics-php
src/Points.php
Points.scaleX
public function scaleX(Point $center, $factor) { foreach ($this->points as $point) { $point->scaleX($center, $factor); } $this->start->scaleX($center, $factor); $this->reverseIfCcw($factor < 0); return $this; }
php
public function scaleX(Point $center, $factor) { foreach ($this->points as $point) { $point->scaleX($center, $factor); } $this->start->scaleX($center, $factor); $this->reverseIfCcw($factor < 0); return $this; }
[ "public", "function", "scaleX", "(", "Point", "$", "center", ",", "$", "factor", ")", "{", "foreach", "(", "$", "this", "->", "points", "as", "$", "point", ")", "{", "$", "point", "->", "scaleX", "(", "$", "center", ",", "$", "factor", ")", ";", "}", "$", "this", "->", "start", "->", "scaleX", "(", "$", "center", ",", "$", "factor", ")", ";", "$", "this", "->", "reverseIfCcw", "(", "$", "factor", "<", "0", ")", ";", "return", "$", "this", ";", "}" ]
Scales points along the X-axis. @param Point $center @param float $factor
[ "Scales", "points", "along", "the", "X", "-", "axis", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L221-L229
train
clacy-builders/graphics-php
src/Points.php
Points.translate
public function translate($deltaX, $deltaY) { foreach ($this->points as $point) { $point->translate($deltaX, $deltaY); } $this->start->translate($deltaX, $deltaY); return $this; }
php
public function translate($deltaX, $deltaY) { foreach ($this->points as $point) { $point->translate($deltaX, $deltaY); } $this->start->translate($deltaX, $deltaY); return $this; }
[ "public", "function", "translate", "(", "$", "deltaX", ",", "$", "deltaY", ")", "{", "foreach", "(", "$", "this", "->", "points", "as", "$", "point", ")", "{", "$", "point", "->", "translate", "(", "$", "deltaX", ",", "$", "deltaY", ")", ";", "}", "$", "this", "->", "start", "->", "translate", "(", "$", "deltaX", ",", "$", "deltaY", ")", ";", "return", "$", "this", ";", "}" ]
Translates points. @param float $deltaX @param float $deltaY
[ "Translates", "points", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L283-L290
train
clacy-builders/graphics-php
src/Points.php
Points.translateX
public function translateX($deltaX) { foreach ($this->points as $point) { $point->translateX($deltaX); } $this->start->translateX($deltaX); return $this; }
php
public function translateX($deltaX) { foreach ($this->points as $point) { $point->translateX($deltaX); } $this->start->translateX($deltaX); return $this; }
[ "public", "function", "translateX", "(", "$", "deltaX", ")", "{", "foreach", "(", "$", "this", "->", "points", "as", "$", "point", ")", "{", "$", "point", "->", "translateX", "(", "$", "deltaX", ")", ";", "}", "$", "this", "->", "start", "->", "translateX", "(", "$", "deltaX", ")", ";", "return", "$", "this", ";", "}" ]
Translates points along the X-axis. @param float $deltaX @param float $deltaY
[ "Translates", "points", "along", "the", "X", "-", "axis", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L298-L305
train
clacy-builders/graphics-php
src/Points.php
Points.translateY
public function translateY($deltaY) { foreach ($this->points as $point) { $point->translateY($deltaY); } $this->start->translateY($deltaY); return $this; }
php
public function translateY($deltaY) { foreach ($this->points as $point) { $point->translateY($deltaY); } $this->start->translateY($deltaY); return $this; }
[ "public", "function", "translateY", "(", "$", "deltaY", ")", "{", "foreach", "(", "$", "this", "->", "points", "as", "$", "point", ")", "{", "$", "point", "->", "translateY", "(", "$", "deltaY", ")", ";", "}", "$", "this", "->", "start", "->", "translateY", "(", "$", "deltaY", ")", ";", "return", "$", "this", ";", "}" ]
Translates points along the Y-axis. @param float $deltaX @param float $deltaY
[ "Translates", "points", "along", "the", "Y", "-", "axis", "." ]
c56556c9265ea4537efdc14ae89a8f36454812d9
https://github.com/clacy-builders/graphics-php/blob/c56556c9265ea4537efdc14ae89a8f36454812d9/src/Points.php#L313-L320
train
Wedeto/Log
src/Logger.php
Logger.getLogger
public static function getLogger($module = "") { if (is_object($module)) $module = get_class($module); elseif (empty($module) || strtoupper($module) === "ROOT") $module = ""; $module = trim(str_replace('\\', '.', $module), ". \\"); if (!isset(self::$module_loggers[$module])) self::$module_loggers[$module] = new Logger($module); return self::$module_loggers[$module]; }
php
public static function getLogger($module = "") { if (is_object($module)) $module = get_class($module); elseif (empty($module) || strtoupper($module) === "ROOT") $module = ""; $module = trim(str_replace('\\', '.', $module), ". \\"); if (!isset(self::$module_loggers[$module])) self::$module_loggers[$module] = new Logger($module); return self::$module_loggers[$module]; }
[ "public", "static", "function", "getLogger", "(", "$", "module", "=", "\"\"", ")", "{", "if", "(", "is_object", "(", "$", "module", ")", ")", "$", "module", "=", "get_class", "(", "$", "module", ")", ";", "elseif", "(", "empty", "(", "$", "module", ")", "||", "strtoupper", "(", "$", "module", ")", "===", "\"ROOT\"", ")", "$", "module", "=", "\"\"", ";", "$", "module", "=", "trim", "(", "str_replace", "(", "'\\\\'", ",", "'.'", ",", "$", "module", ")", ",", "\". \\\\\"", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "module_loggers", "[", "$", "module", "]", ")", ")", "self", "::", "$", "module_loggers", "[", "$", "module", "]", "=", "new", "Logger", "(", "$", "module", ")", ";", "return", "self", "::", "$", "module_loggers", "[", "$", "module", "]", ";", "}" ]
Get a logger for a specific module. @param mixed $module A string indicating the module, or a class name or object that will be used to find the appropriate name. @return Logger The instance for the specified module
[ "Get", "a", "logger", "for", "a", "specific", "module", "." ]
88252c5052089fdcc5dae466d1ad5889bb2b735f
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Logger.php#L100-L112
train
Wedeto/Log
src/Logger.php
Logger.resetGlobalState
public static function resetGlobalState() { foreach (self::$module_loggers as $logger) $logger->removeLogWriters(); self::$module_loggers = []; self::$accept_mode = self::MODE_ACCEPT_MOST_SPECIFIC; }
php
public static function resetGlobalState() { foreach (self::$module_loggers as $logger) $logger->removeLogWriters(); self::$module_loggers = []; self::$accept_mode = self::MODE_ACCEPT_MOST_SPECIFIC; }
[ "public", "static", "function", "resetGlobalState", "(", ")", "{", "foreach", "(", "self", "::", "$", "module_loggers", "as", "$", "logger", ")", "$", "logger", "->", "removeLogWriters", "(", ")", ";", "self", "::", "$", "module_loggers", "=", "[", "]", ";", "self", "::", "$", "accept_mode", "=", "self", "::", "MODE_ACCEPT_MOST_SPECIFIC", ";", "}" ]
This method will reset all global state in the Logger object. It will remove all writers from all loggers and then remove all loggers. Note that this will not remove existing logger instances from other objects - this is why the writers are removed.
[ "This", "method", "will", "reset", "all", "global", "state", "in", "the", "Logger", "object", ".", "It", "will", "remove", "all", "writers", "from", "all", "loggers", "and", "then", "remove", "all", "loggers", ".", "Note", "that", "this", "will", "not", "remove", "existing", "logger", "instances", "from", "other", "objects", "-", "this", "is", "why", "the", "writers", "are", "removed", "." ]
88252c5052089fdcc5dae466d1ad5889bb2b735f
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Logger.php#L120-L126
train
Wedeto/Log
src/Logger.php
Logger.setLevel
public function setLevel(string $level) { if (!defined(LogLevel::class . '::' . strtoupper($level))) throw new \DomainException("Invalid log level: $level"); $this->level = $level; $this->level_num = self::$LEVEL_NUMERIC[$level]; return $this; }
php
public function setLevel(string $level) { if (!defined(LogLevel::class . '::' . strtoupper($level))) throw new \DomainException("Invalid log level: $level"); $this->level = $level; $this->level_num = self::$LEVEL_NUMERIC[$level]; return $this; }
[ "public", "function", "setLevel", "(", "string", "$", "level", ")", "{", "if", "(", "!", "defined", "(", "LogLevel", "::", "class", ".", "'::'", ".", "strtoupper", "(", "$", "level", ")", ")", ")", "throw", "new", "\\", "DomainException", "(", "\"Invalid log level: $level\"", ")", ";", "$", "this", "->", "level", "=", "$", "level", ";", "$", "this", "->", "level_num", "=", "self", "::", "$", "LEVEL_NUMERIC", "[", "$", "level", "]", ";", "return", "$", "this", ";", "}" ]
Set the log level for this module. Any log messages with a severity lower than this threshold will not bubble up. @param string $level The minimum log level of messages to handle
[ "Set", "the", "log", "level", "for", "this", "module", ".", "Any", "log", "messages", "with", "a", "severity", "lower", "than", "this", "threshold", "will", "not", "bubble", "up", "." ]
88252c5052089fdcc5dae466d1ad5889bb2b735f
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Logger.php#L203-L211
train
Wedeto/Log
src/Logger.php
Logger.fillPlaceholders
public static function fillPlaceholders(string $message, array $context) { $message = (string)$message; foreach ($context as $key => $value) { $placeholder = '{' . $key . '}'; $strval = null; $pos = 0; while (($pos = strpos($message, $placeholder, $pos)) !== false) { $strval = $strval ?: WF::str($value); $message = substr($message, 0, $pos) . $strval . substr($message, $pos + strlen($placeholder)); $pos = $pos + strlen($strval); } } return $message; }
php
public static function fillPlaceholders(string $message, array $context) { $message = (string)$message; foreach ($context as $key => $value) { $placeholder = '{' . $key . '}'; $strval = null; $pos = 0; while (($pos = strpos($message, $placeholder, $pos)) !== false) { $strval = $strval ?: WF::str($value); $message = substr($message, 0, $pos) . $strval . substr($message, $pos + strlen($placeholder)); $pos = $pos + strlen($strval); } } return $message; }
[ "public", "static", "function", "fillPlaceholders", "(", "string", "$", "message", ",", "array", "$", "context", ")", "{", "$", "message", "=", "(", "string", ")", "$", "message", ";", "foreach", "(", "$", "context", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "placeholder", "=", "'{'", ".", "$", "key", ".", "'}'", ";", "$", "strval", "=", "null", ";", "$", "pos", "=", "0", ";", "while", "(", "(", "$", "pos", "=", "strpos", "(", "$", "message", ",", "$", "placeholder", ",", "$", "pos", ")", ")", "!==", "false", ")", "{", "$", "strval", "=", "$", "strval", "?", ":", "WF", "::", "str", "(", "$", "value", ")", ";", "$", "message", "=", "substr", "(", "$", "message", ",", "0", ",", "$", "pos", ")", ".", "$", "strval", ".", "substr", "(", "$", "message", ",", "$", "pos", "+", "strlen", "(", "$", "placeholder", ")", ")", ";", "$", "pos", "=", "$", "pos", "+", "strlen", "(", "$", "strval", ")", ";", "}", "}", "return", "$", "message", ";", "}" ]
Fill the place holders in the message with values from the context array @param string $message The message to format. Any {var} placeholders will be replaced with a value from the context array. @param array $context Contains the values to replace the placeholders with. @return string The message with placeholders replaced
[ "Fill", "the", "place", "holders", "in", "the", "message", "with", "values", "from", "the", "context", "array" ]
88252c5052089fdcc5dae466d1ad5889bb2b735f
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Logger.php#L347-L366
train
Wedeto/Log
src/Logger.php
Logger.getLevelNumeric
public static function getLevelNumeric(string $level) { return isset(self::$LEVEL_NUMERIC[$level]) ? self::$LEVEL_NUMERIC[$level] : 0; }
php
public static function getLevelNumeric(string $level) { return isset(self::$LEVEL_NUMERIC[$level]) ? self::$LEVEL_NUMERIC[$level] : 0; }
[ "public", "static", "function", "getLevelNumeric", "(", "string", "$", "level", ")", "{", "return", "isset", "(", "self", "::", "$", "LEVEL_NUMERIC", "[", "$", "level", "]", ")", "?", "self", "::", "$", "LEVEL_NUMERIC", "[", "$", "level", "]", ":", "0", ";", "}" ]
Get the severity number for a specific LogLevel. @param string $level The LogLevel to convert to a number @return int The severity - 0 is less important, 7 is most important.
[ "Get", "the", "severity", "number", "for", "a", "specific", "LogLevel", "." ]
88252c5052089fdcc5dae466d1ad5889bb2b735f
https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Logger.php#L373-L376
train
squareproton/Bond
src/Bond/Pg/ConnectionFactory.php
ConnectionFactory.get
public function get( $connection, $cache = true ) { if( !is_string( $connection ) ) { throw new BadTypeException( $connection, 'string' ); } // use the multiton if( !isset( $this->instances[$connection] ) or !$cache ) { if( !isset( $this->connectionSettings[$connection]) ) { throw new UnknownNamedConnectionException( $connection ); } $resource = new Resource( $this->connectionSettings[$connection], $this ); if( $cache ) { $this->instances[$connection] = $resource; } // get the resource from the multiton } else { $resource = $this->instances[$connection]; } return new Pg( $resource, $connection ); }
php
public function get( $connection, $cache = true ) { if( !is_string( $connection ) ) { throw new BadTypeException( $connection, 'string' ); } // use the multiton if( !isset( $this->instances[$connection] ) or !$cache ) { if( !isset( $this->connectionSettings[$connection]) ) { throw new UnknownNamedConnectionException( $connection ); } $resource = new Resource( $this->connectionSettings[$connection], $this ); if( $cache ) { $this->instances[$connection] = $resource; } // get the resource from the multiton } else { $resource = $this->instances[$connection]; } return new Pg( $resource, $connection ); }
[ "public", "function", "get", "(", "$", "connection", ",", "$", "cache", "=", "true", ")", "{", "if", "(", "!", "is_string", "(", "$", "connection", ")", ")", "{", "throw", "new", "BadTypeException", "(", "$", "connection", ",", "'string'", ")", ";", "}", "// use the multiton", "if", "(", "!", "isset", "(", "$", "this", "->", "instances", "[", "$", "connection", "]", ")", "or", "!", "$", "cache", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "connectionSettings", "[", "$", "connection", "]", ")", ")", "{", "throw", "new", "UnknownNamedConnectionException", "(", "$", "connection", ")", ";", "}", "$", "resource", "=", "new", "Resource", "(", "$", "this", "->", "connectionSettings", "[", "$", "connection", "]", ",", "$", "this", ")", ";", "if", "(", "$", "cache", ")", "{", "$", "this", "->", "instances", "[", "$", "connection", "]", "=", "$", "resource", ";", "}", "// get the resource from the multiton", "}", "else", "{", "$", "resource", "=", "$", "this", "->", "instances", "[", "$", "connection", "]", ";", "}", "return", "new", "Pg", "(", "$", "resource", ",", "$", "connection", ")", ";", "}" ]
Get the singleton pg connection @param string $connection @param boolean $cache @return \Bond\Pg
[ "Get", "the", "singleton", "pg", "connection" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/ConnectionFactory.php#L56-L82
train
squareproton/Bond
src/Bond/Pg/ConnectionFactory.php
ConnectionFactory.remove
public function remove( Resource $resource ) { $cnt = 0; if( false !== $key = array_search( $resource, $this->instances, true ) ) { unset( $this->instances[$key] ); $cnt++; } return $cnt; }
php
public function remove( Resource $resource ) { $cnt = 0; if( false !== $key = array_search( $resource, $this->instances, true ) ) { unset( $this->instances[$key] ); $cnt++; } return $cnt; }
[ "public", "function", "remove", "(", "Resource", "$", "resource", ")", "{", "$", "cnt", "=", "0", ";", "if", "(", "false", "!==", "$", "key", "=", "array_search", "(", "$", "resource", ",", "$", "this", "->", "instances", ",", "true", ")", ")", "{", "unset", "(", "$", "this", "->", "instances", "[", "$", "key", "]", ")", ";", "$", "cnt", "++", ";", "}", "return", "$", "cnt", ";", "}" ]
Remove a resource from the multiton cache @param Bond\Pg\Resource @return int
[ "Remove", "a", "resource", "from", "the", "multiton", "cache" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/ConnectionFactory.php#L89-L97
train
mrbase/Smesg
src/Smesg/Provider/InMobileProvider.php
InMobileProvider.sendOne
protected function sendOne($dry_run) { $message = $this->messages[0]; $adapter = $this->getAdapter(); $adapter->setEndpoint(self::SINGLE_ENDPOINT); $adapter->setParameters(array( 'user' => $this->config['user'], 'password' => $this->config['password'], 'serviceid' => $this->config['serviceid'], 'sender' => ($message->options['from'] ?: $this->config['from']), 'message' => $message->message, 'msisdn' => $message->to, 'price' => $this->config['price'], 'overcharge' => $this->config['overcharge'], )); if ($dry_run) { return $adapter->dryRun(); } return $adapter->post(); }
php
protected function sendOne($dry_run) { $message = $this->messages[0]; $adapter = $this->getAdapter(); $adapter->setEndpoint(self::SINGLE_ENDPOINT); $adapter->setParameters(array( 'user' => $this->config['user'], 'password' => $this->config['password'], 'serviceid' => $this->config['serviceid'], 'sender' => ($message->options['from'] ?: $this->config['from']), 'message' => $message->message, 'msisdn' => $message->to, 'price' => $this->config['price'], 'overcharge' => $this->config['overcharge'], )); if ($dry_run) { return $adapter->dryRun(); } return $adapter->post(); }
[ "protected", "function", "sendOne", "(", "$", "dry_run", ")", "{", "$", "message", "=", "$", "this", "->", "messages", "[", "0", "]", ";", "$", "adapter", "=", "$", "this", "->", "getAdapter", "(", ")", ";", "$", "adapter", "->", "setEndpoint", "(", "self", "::", "SINGLE_ENDPOINT", ")", ";", "$", "adapter", "->", "setParameters", "(", "array", "(", "'user'", "=>", "$", "this", "->", "config", "[", "'user'", "]", ",", "'password'", "=>", "$", "this", "->", "config", "[", "'password'", "]", ",", "'serviceid'", "=>", "$", "this", "->", "config", "[", "'serviceid'", "]", ",", "'sender'", "=>", "(", "$", "message", "->", "options", "[", "'from'", "]", "?", ":", "$", "this", "->", "config", "[", "'from'", "]", ")", ",", "'message'", "=>", "$", "message", "->", "message", ",", "'msisdn'", "=>", "$", "message", "->", "to", ",", "'price'", "=>", "$", "this", "->", "config", "[", "'price'", "]", ",", "'overcharge'", "=>", "$", "this", "->", "config", "[", "'overcharge'", "]", ",", ")", ")", ";", "if", "(", "$", "dry_run", ")", "{", "return", "$", "adapter", "->", "dryRun", "(", ")", ";", "}", "return", "$", "adapter", "->", "post", "(", ")", ";", "}" ]
We use smspush for sending single messages. @return string $response;
[ "We", "use", "smspush", "for", "sending", "single", "messages", "." ]
e9692ed5915f5a9cd4dca0df875935a2c528e128
https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/InMobileProvider.php#L188-L210
train
duncan3dc/php-ini
src/Ini.php
Ini.restore
public function restore(string $key): self { if (array_key_exists($key, $this->original)) { ini_set($key, $this->original[$key]); } return $this; }
php
public function restore(string $key): self { if (array_key_exists($key, $this->original)) { ini_set($key, $this->original[$key]); } return $this; }
[ "public", "function", "restore", "(", "string", "$", "key", ")", ":", "self", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "original", ")", ")", "{", "ini_set", "(", "$", "key", ",", "$", "this", "->", "original", "[", "$", "key", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Restore a previous ini setting. @return $this
[ "Restore", "a", "previous", "ini", "setting", "." ]
e07435d7ddbbc466e535783e5c4d2b92e3715c7a
https://github.com/duncan3dc/php-ini/blob/e07435d7ddbbc466e535783e5c4d2b92e3715c7a/src/Ini.php#L53-L60
train
duncan3dc/php-ini
src/Ini.php
Ini.cleanup
public function cleanup(): self { foreach ($this->original as $key => $value) { ini_set($key, $value); } $this->original = []; return $this; }
php
public function cleanup(): self { foreach ($this->original as $key => $value) { ini_set($key, $value); } $this->original = []; return $this; }
[ "public", "function", "cleanup", "(", ")", ":", "self", "{", "foreach", "(", "$", "this", "->", "original", "as", "$", "key", "=>", "$", "value", ")", "{", "ini_set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "this", "->", "original", "=", "[", "]", ";", "return", "$", "this", ";", "}" ]
Restore the previous ini settings. @return $this
[ "Restore", "the", "previous", "ini", "settings", "." ]
e07435d7ddbbc466e535783e5c4d2b92e3715c7a
https://github.com/duncan3dc/php-ini/blob/e07435d7ddbbc466e535783e5c4d2b92e3715c7a/src/Ini.php#L68-L77
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/DataTypes/TypeFactory.php
TypeFactory.getType
public function getType($name) { if (false === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" was not found.', $name)); } if (isset($this->loaded[$name])) { return $this->loaded[$name]; } $fqcn = $this->types[$name]; $type = new $fqcn; if (!$type instanceof TypeInterface) { throw new InvalidArgumentException(sprintf('The class "%s" must implement the "%s\\Types\TypeInterface"', $fqcn, __NAMESPACE__)); } return $this->loaded[$name] = new $fqcn; }
php
public function getType($name) { if (false === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" was not found.', $name)); } if (isset($this->loaded[$name])) { return $this->loaded[$name]; } $fqcn = $this->types[$name]; $type = new $fqcn; if (!$type instanceof TypeInterface) { throw new InvalidArgumentException(sprintf('The class "%s" must implement the "%s\\Types\TypeInterface"', $fqcn, __NAMESPACE__)); } return $this->loaded[$name] = new $fqcn; }
[ "public", "function", "getType", "(", "$", "name", ")", "{", "if", "(", "false", "===", "$", "this", "->", "hasType", "(", "$", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The type \"%s\" was not found.'", ",", "$", "name", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "loaded", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "loaded", "[", "$", "name", "]", ";", "}", "$", "fqcn", "=", "$", "this", "->", "types", "[", "$", "name", "]", ";", "$", "type", "=", "new", "$", "fqcn", ";", "if", "(", "!", "$", "type", "instanceof", "TypeInterface", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The class \"%s\" must implement the \"%s\\\\Types\\TypeInterface\"'", ",", "$", "fqcn", ",", "__NAMESPACE__", ")", ")", ";", "}", "return", "$", "this", "->", "loaded", "[", "$", "name", "]", "=", "new", "$", "fqcn", ";", "}" ]
Gets a type object. @param string $name @return DataTypes\Types\Type @throws InvalidArgumentException If the type wasn't found.
[ "Gets", "a", "type", "object", "." ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/DataTypes/TypeFactory.php#L84-L100
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/DataTypes/TypeFactory.php
TypeFactory.addType
public function addType($name, $fqcn) { if (true === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" already exists.', $name)); } return $this->setType($name, $fqcn); }
php
public function addType($name, $fqcn) { if (true === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" already exists.', $name)); } return $this->setType($name, $fqcn); }
[ "public", "function", "addType", "(", "$", "name", ",", "$", "fqcn", ")", "{", "if", "(", "true", "===", "$", "this", "->", "hasType", "(", "$", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The type \"%s\" already exists.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "setType", "(", "$", "name", ",", "$", "fqcn", ")", ";", "}" ]
Adds a type object. @param string $name @param string $fqcn @return self @throws InvalidArgumentException If the type already exists.
[ "Adds", "a", "type", "object", "." ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/DataTypes/TypeFactory.php#L110-L116
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/DataTypes/TypeFactory.php
TypeFactory.overrideType
public function overrideType($name, $fqcn) { if (false === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" was not found.', $name)); } return $this->setType($name, $fqcn); }
php
public function overrideType($name, $fqcn) { if (false === $this->hasType($name)) { throw new InvalidArgumentException(sprintf('The type "%s" was not found.', $name)); } return $this->setType($name, $fqcn); }
[ "public", "function", "overrideType", "(", "$", "name", ",", "$", "fqcn", ")", "{", "if", "(", "false", "===", "$", "this", "->", "hasType", "(", "$", "name", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'The type \"%s\" was not found.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "setType", "(", "$", "name", ",", "$", "fqcn", ")", ";", "}" ]
Overrides a type object with new class. @param string $name @param string $fqcn @return self @throws InvalidArgumentException If the type was not found.
[ "Overrides", "a", "type", "object", "with", "new", "class", "." ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/DataTypes/TypeFactory.php#L126-L132
train
bkstg/schedule-bundle
Timeline/EventSubscriber/EventLinkSubscriber.php
EventLinkSubscriber.setInvitedLink
public function setInvitedLink(TimelineLinkEvent $event): void { $action = $event->getAction(); if ('invited' != $action->getVerb()) { return; } $event = $action->getComponent('indirectComplement')->getData(); $event->setLink($this->url_generator->generate('bkstg_event_read', [ 'id' => $event->getId(), 'production_slug' => $event->getGroups()[0]->getSlug(), ])); }
php
public function setInvitedLink(TimelineLinkEvent $event): void { $action = $event->getAction(); if ('invited' != $action->getVerb()) { return; } $event = $action->getComponent('indirectComplement')->getData(); $event->setLink($this->url_generator->generate('bkstg_event_read', [ 'id' => $event->getId(), 'production_slug' => $event->getGroups()[0]->getSlug(), ])); }
[ "public", "function", "setInvitedLink", "(", "TimelineLinkEvent", "$", "event", ")", ":", "void", "{", "$", "action", "=", "$", "event", "->", "getAction", "(", ")", ";", "if", "(", "'invited'", "!=", "$", "action", "->", "getVerb", "(", ")", ")", "{", "return", ";", "}", "$", "event", "=", "$", "action", "->", "getComponent", "(", "'indirectComplement'", ")", "->", "getData", "(", ")", ";", "$", "event", "->", "setLink", "(", "$", "this", "->", "url_generator", "->", "generate", "(", "'bkstg_event_read'", ",", "[", "'id'", "=>", "$", "event", "->", "getId", "(", ")", ",", "'production_slug'", "=>", "$", "event", "->", "getGroups", "(", ")", "[", "0", "]", "->", "getSlug", "(", ")", ",", "]", ")", ")", ";", "}" ]
Set the link for invited actions. @param TimelineLinkEvent $event The timeline action event. @return void
[ "Set", "the", "link", "for", "invited", "actions", "." ]
e64ac897aa7b28bc48319470d65de13cd4788afe
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Timeline/EventSubscriber/EventLinkSubscriber.php#L54-L67
train
bkstg/schedule-bundle
Timeline/EventSubscriber/EventLinkSubscriber.php
EventLinkSubscriber.setScheduledLink
public function setScheduledLink(TimelineLinkEvent $event): void { $action = $event->getAction(); if ('scheduled' != $action->getVerb()) { return; } $production = $action->getComponent('indirectComplement')->getData(); $schedule = $action->getComponent('directComplement')->getData(); $event->setLink($this->url_generator->generate('bkstg_schedule_read', [ 'id' => $schedule->getId(), 'production_slug' => $production->getSlug(), ])); }
php
public function setScheduledLink(TimelineLinkEvent $event): void { $action = $event->getAction(); if ('scheduled' != $action->getVerb()) { return; } $production = $action->getComponent('indirectComplement')->getData(); $schedule = $action->getComponent('directComplement')->getData(); $event->setLink($this->url_generator->generate('bkstg_schedule_read', [ 'id' => $schedule->getId(), 'production_slug' => $production->getSlug(), ])); }
[ "public", "function", "setScheduledLink", "(", "TimelineLinkEvent", "$", "event", ")", ":", "void", "{", "$", "action", "=", "$", "event", "->", "getAction", "(", ")", ";", "if", "(", "'scheduled'", "!=", "$", "action", "->", "getVerb", "(", ")", ")", "{", "return", ";", "}", "$", "production", "=", "$", "action", "->", "getComponent", "(", "'indirectComplement'", ")", "->", "getData", "(", ")", ";", "$", "schedule", "=", "$", "action", "->", "getComponent", "(", "'directComplement'", ")", "->", "getData", "(", ")", ";", "$", "event", "->", "setLink", "(", "$", "this", "->", "url_generator", "->", "generate", "(", "'bkstg_schedule_read'", ",", "[", "'id'", "=>", "$", "schedule", "->", "getId", "(", ")", ",", "'production_slug'", "=>", "$", "production", "->", "getSlug", "(", ")", ",", "]", ")", ")", ";", "}" ]
Set the link for scheduled actions. @param TimelineLinkEvent $event The timeline action event. @return void
[ "Set", "the", "link", "for", "scheduled", "actions", "." ]
e64ac897aa7b28bc48319470d65de13cd4788afe
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Timeline/EventSubscriber/EventLinkSubscriber.php#L76-L90
train
NukaCode/Front-End-Bootstrap
src/NukaCode/Bootstrap/Filesystem/Config/Theme.php
Theme.updateEntry
public function updateEntry($package, $theme) { $this->verifyCommand($package); $lines = file($this->config); $config = $this->compactConfig($package); $lines = $this->updateConfigDetails($theme, $lines, $config); $this->file->delete($this->config); $this->file->put($this->config, implode($lines)); }
php
public function updateEntry($package, $theme) { $this->verifyCommand($package); $lines = file($this->config); $config = $this->compactConfig($package); $lines = $this->updateConfigDetails($theme, $lines, $config); $this->file->delete($this->config); $this->file->put($this->config, implode($lines)); }
[ "public", "function", "updateEntry", "(", "$", "package", ",", "$", "theme", ")", "{", "$", "this", "->", "verifyCommand", "(", "$", "package", ")", ";", "$", "lines", "=", "file", "(", "$", "this", "->", "config", ")", ";", "$", "config", "=", "$", "this", "->", "compactConfig", "(", "$", "package", ")", ";", "$", "lines", "=", "$", "this", "->", "updateConfigDetails", "(", "$", "theme", ",", "$", "lines", ",", "$", "config", ")", ";", "$", "this", "->", "file", "->", "delete", "(", "$", "this", "->", "config", ")", ";", "$", "this", "->", "file", "->", "put", "(", "$", "this", "->", "config", ",", "implode", "(", "$", "lines", ")", ")", ";", "}" ]
Update the config with the color values for easy retrieval @param $package @param $theme
[ "Update", "the", "config", "with", "the", "color", "values", "for", "easy", "retrieval" ]
46c30fba4c77afb74ec4a4d70c43c9cffd464d6e
https://github.com/NukaCode/Front-End-Bootstrap/blob/46c30fba4c77afb74ec4a4d70c43c9cffd464d6e/src/NukaCode/Bootstrap/Filesystem/Config/Theme.php#L85-L96
train
agentmedia/phine-core
src/Core/Logic/Tree/PageTreeProvider.php
PageTreeProvider.TopMost
public function TopMost() { $sql = Access::SqlBuilder(); $tbl = Page::Schema()->Table(); $where = $sql->Equals($tbl->Field('Site'), $sql->Value($this->site->GetID())) ->And_($sql->IsNull($tbl->Field('Parent'))) ->And_($sql->IsNull($tbl->Field('Previous'))); return Page::Schema()->First($where); }
php
public function TopMost() { $sql = Access::SqlBuilder(); $tbl = Page::Schema()->Table(); $where = $sql->Equals($tbl->Field('Site'), $sql->Value($this->site->GetID())) ->And_($sql->IsNull($tbl->Field('Parent'))) ->And_($sql->IsNull($tbl->Field('Previous'))); return Page::Schema()->First($where); }
[ "public", "function", "TopMost", "(", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tbl", "=", "Page", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "where", "=", "$", "sql", "->", "Equals", "(", "$", "tbl", "->", "Field", "(", "'Site'", ")", ",", "$", "sql", "->", "Value", "(", "$", "this", "->", "site", "->", "GetID", "(", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "IsNull", "(", "$", "tbl", "->", "Field", "(", "'Parent'", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "IsNull", "(", "$", "tbl", "->", "Field", "(", "'Previous'", ")", ")", ")", ";", "return", "Page", "::", "Schema", "(", ")", "->", "First", "(", "$", "where", ")", ";", "}" ]
Gets the first and root page of the site @return Page
[ "Gets", "the", "first", "and", "root", "page", "of", "the", "site" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Tree/PageTreeProvider.php#L31-L40
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.connect
public function connect($credentials = []) { if ($diff = array_diff(array_keys($this->settings), array_keys($credentials))) { throw new \Exception("Missing credentials, the following fields are missing ".implode('/', $diff)); } $this->settings = array_merge($this->settings, $credentials); if (isset($this->settings['port']) === false) { $this->settings['port'] = 143; } $this->conn = @imap_open('{'.$this->settings['server'].':'.$this->settings['port'].'/notls}', $this->settings['username'], $this->settings['password']); if ($this->conn == false) { throw new \Exception("Could not connect or authorize to ".$this->settings['server'].':'.$this->settings['port']); } return ($this->conn != null); }
php
public function connect($credentials = []) { if ($diff = array_diff(array_keys($this->settings), array_keys($credentials))) { throw new \Exception("Missing credentials, the following fields are missing ".implode('/', $diff)); } $this->settings = array_merge($this->settings, $credentials); if (isset($this->settings['port']) === false) { $this->settings['port'] = 143; } $this->conn = @imap_open('{'.$this->settings['server'].':'.$this->settings['port'].'/notls}', $this->settings['username'], $this->settings['password']); if ($this->conn == false) { throw new \Exception("Could not connect or authorize to ".$this->settings['server'].':'.$this->settings['port']); } return ($this->conn != null); }
[ "public", "function", "connect", "(", "$", "credentials", "=", "[", "]", ")", "{", "if", "(", "$", "diff", "=", "array_diff", "(", "array_keys", "(", "$", "this", "->", "settings", ")", ",", "array_keys", "(", "$", "credentials", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Missing credentials, the following fields are missing \"", ".", "implode", "(", "'/'", ",", "$", "diff", ")", ")", ";", "}", "$", "this", "->", "settings", "=", "array_merge", "(", "$", "this", "->", "settings", ",", "$", "credentials", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "settings", "[", "'port'", "]", ")", "===", "false", ")", "{", "$", "this", "->", "settings", "[", "'port'", "]", "=", "143", ";", "}", "$", "this", "->", "conn", "=", "@", "imap_open", "(", "'{'", ".", "$", "this", "->", "settings", "[", "'server'", "]", ".", "':'", ".", "$", "this", "->", "settings", "[", "'port'", "]", ".", "'/notls}'", ",", "$", "this", "->", "settings", "[", "'username'", "]", ",", "$", "this", "->", "settings", "[", "'password'", "]", ")", ";", "if", "(", "$", "this", "->", "conn", "==", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Could not connect or authorize to \"", ".", "$", "this", "->", "settings", "[", "'server'", "]", ".", "':'", ".", "$", "this", "->", "settings", "[", "'port'", "]", ")", ";", "}", "return", "(", "$", "this", "->", "conn", "!=", "null", ")", ";", "}" ]
Open a connection to a mail server. @param array $credentials @return bool @throws \Exception
[ "Open", "a", "connection", "to", "a", "mail", "server", "." ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L47-L67
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.getMailbox
public function getMailbox() { $mailbox = str_replace("{".$this->settings['server']."}", '', $this->mailbox); $mailbox = (substr($mailbox, 0, 6) == 'INBOX.') ? substr($mailbox, -6) : $mailbox; return $mailbox; }
php
public function getMailbox() { $mailbox = str_replace("{".$this->settings['server']."}", '', $this->mailbox); $mailbox = (substr($mailbox, 0, 6) == 'INBOX.') ? substr($mailbox, -6) : $mailbox; return $mailbox; }
[ "public", "function", "getMailbox", "(", ")", "{", "$", "mailbox", "=", "str_replace", "(", "\"{\"", ".", "$", "this", "->", "settings", "[", "'server'", "]", ".", "\"}\"", ",", "''", ",", "$", "this", "->", "mailbox", ")", ";", "$", "mailbox", "=", "(", "substr", "(", "$", "mailbox", ",", "0", ",", "6", ")", "==", "'INBOX.'", ")", "?", "substr", "(", "$", "mailbox", ",", "-", "6", ")", ":", "$", "mailbox", ";", "return", "$", "mailbox", ";", "}" ]
Return the name of the current mailbox. @return string
[ "Return", "the", "name", "of", "the", "current", "mailbox", "." ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L111-L117
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.subscribeMailbox
public function subscribeMailbox($name = '') { if (empty($name)) { return false; } $name = imap_utf7_encode($name); return imap_subscribe ( $this->conn, "{".$this->settings['server']."}INBOX.".$name ); }
php
public function subscribeMailbox($name = '') { if (empty($name)) { return false; } $name = imap_utf7_encode($name); return imap_subscribe ( $this->conn, "{".$this->settings['server']."}INBOX.".$name ); }
[ "public", "function", "subscribeMailbox", "(", "$", "name", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "false", ";", "}", "$", "name", "=", "imap_utf7_encode", "(", "$", "name", ")", ";", "return", "imap_subscribe", "(", "$", "this", "->", "conn", ",", "\"{\"", ".", "$", "this", "->", "settings", "[", "'server'", "]", ".", "\"}INBOX.\"", ".", "$", "name", ")", ";", "}" ]
Subscribe to a mailbox. @param string $name @return bool
[ "Subscribe", "to", "a", "mailbox", "." ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L213-L220
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.getMessageInformation
public function getMessageInformation($id = '') { $message = []; if (is_array($this->messages) == true) { foreach($this ->messages as $msg) { if ($msg['index'] == $id) { return $msg; } } } return $message; }
php
public function getMessageInformation($id = '') { $message = []; if (is_array($this->messages) == true) { foreach($this ->messages as $msg) { if ($msg['index'] == $id) { return $msg; } } } return $message; }
[ "public", "function", "getMessageInformation", "(", "$", "id", "=", "''", ")", "{", "$", "message", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "this", "->", "messages", ")", "==", "true", ")", "{", "foreach", "(", "$", "this", "->", "messages", "as", "$", "msg", ")", "{", "if", "(", "$", "msg", "[", "'index'", "]", "==", "$", "id", ")", "{", "return", "$", "msg", ";", "}", "}", "}", "return", "$", "message", ";", "}" ]
Return message information without reading it from the server @param string $id @return mixed
[ "Return", "message", "information", "without", "reading", "it", "from", "the", "server" ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L408-L419
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.getMessage
public function getMessage($id = '') { $message = []; if (is_array($this->messages) == true) { foreach($this ->messages as $msg) { if ($msg['index'] == $id) { $message = $msg; break; } } } if (is_array($message) === true) { // Get the message body but do not mark as read $message['body'] = quoted_printable_decode(imap_fetchbody($this->conn, $message['index'], FT_PEEK)); } return $message; }
php
public function getMessage($id = '') { $message = []; if (is_array($this->messages) == true) { foreach($this ->messages as $msg) { if ($msg['index'] == $id) { $message = $msg; break; } } } if (is_array($message) === true) { // Get the message body but do not mark as read $message['body'] = quoted_printable_decode(imap_fetchbody($this->conn, $message['index'], FT_PEEK)); } return $message; }
[ "public", "function", "getMessage", "(", "$", "id", "=", "''", ")", "{", "$", "message", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "this", "->", "messages", ")", "==", "true", ")", "{", "foreach", "(", "$", "this", "->", "messages", "as", "$", "msg", ")", "{", "if", "(", "$", "msg", "[", "'index'", "]", "==", "$", "id", ")", "{", "$", "message", "=", "$", "msg", ";", "break", ";", "}", "}", "}", "if", "(", "is_array", "(", "$", "message", ")", "===", "true", ")", "{", "// Get the message body but do not mark as read", "$", "message", "[", "'body'", "]", "=", "quoted_printable_decode", "(", "imap_fetchbody", "(", "$", "this", "->", "conn", ",", "$", "message", "[", "'index'", "]", ",", "FT_PEEK", ")", ")", ";", "}", "return", "$", "message", ";", "}" ]
Return a message based on its index in the mailbox. @param string $id @return mixed
[ "Return", "a", "message", "based", "on", "its", "index", "in", "the", "mailbox", "." ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L428-L446
train
johnnymast/mailreader
src/MailReader/MailReader.php
MailReader.readMailbox
public function readMailbox() { $msg_cnt = imap_num_msg($this->conn); $messages = []; for ($i = 1; $i <= $msg_cnt; $i++) { $header = imap_headerinfo($this->conn, $i); $messages[] = [ 'index' => trim($header->Msgno), 'header' => $header, 'structure' => imap_fetchstructure($this->conn, $i) ]; } $this->messages = $messages; return $this->messages; }
php
public function readMailbox() { $msg_cnt = imap_num_msg($this->conn); $messages = []; for ($i = 1; $i <= $msg_cnt; $i++) { $header = imap_headerinfo($this->conn, $i); $messages[] = [ 'index' => trim($header->Msgno), 'header' => $header, 'structure' => imap_fetchstructure($this->conn, $i) ]; } $this->messages = $messages; return $this->messages; }
[ "public", "function", "readMailbox", "(", ")", "{", "$", "msg_cnt", "=", "imap_num_msg", "(", "$", "this", "->", "conn", ")", ";", "$", "messages", "=", "[", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "msg_cnt", ";", "$", "i", "++", ")", "{", "$", "header", "=", "imap_headerinfo", "(", "$", "this", "->", "conn", ",", "$", "i", ")", ";", "$", "messages", "[", "]", "=", "[", "'index'", "=>", "trim", "(", "$", "header", "->", "Msgno", ")", ",", "'header'", "=>", "$", "header", ",", "'structure'", "=>", "imap_fetchstructure", "(", "$", "this", "->", "conn", ",", "$", "i", ")", "]", ";", "}", "$", "this", "->", "messages", "=", "$", "messages", ";", "return", "$", "this", "->", "messages", ";", "}" ]
Retrieve a list of message in the mailbox. @return array
[ "Retrieve", "a", "list", "of", "message", "in", "the", "mailbox", "." ]
9c81843aece984eb6e2a9ba41f3be49733348d10
https://github.com/johnnymast/mailreader/blob/9c81843aece984eb6e2a9ba41f3be49733348d10/src/MailReader/MailReader.php#L454-L469
train
Wedeto/DB
src/Migrate/Module.php
Module.loadVersion
private function loadVersion() { try { $this->dao = $this->db->getDAO(DBVersion::class); $this->db_version = $this->dao->get( QB::where(["module" => $this->module]), QB::order(['migration_date' => 'DESC']) ) ?: new NullVersion; } catch (TableNotExistsException $e) { if ($this->module !== "wedeto.db") { throw new NoMigrationTableException(); } $this->db_version = new NullVersion; } }
php
private function loadVersion() { try { $this->dao = $this->db->getDAO(DBVersion::class); $this->db_version = $this->dao->get( QB::where(["module" => $this->module]), QB::order(['migration_date' => 'DESC']) ) ?: new NullVersion; } catch (TableNotExistsException $e) { if ($this->module !== "wedeto.db") { throw new NoMigrationTableException(); } $this->db_version = new NullVersion; } }
[ "private", "function", "loadVersion", "(", ")", "{", "try", "{", "$", "this", "->", "dao", "=", "$", "this", "->", "db", "->", "getDAO", "(", "DBVersion", "::", "class", ")", ";", "$", "this", "->", "db_version", "=", "$", "this", "->", "dao", "->", "get", "(", "QB", "::", "where", "(", "[", "\"module\"", "=>", "$", "this", "->", "module", "]", ")", ",", "QB", "::", "order", "(", "[", "'migration_date'", "=>", "'DESC'", "]", ")", ")", "?", ":", "new", "NullVersion", ";", "}", "catch", "(", "TableNotExistsException", "$", "e", ")", "{", "if", "(", "$", "this", "->", "module", "!==", "\"wedeto.db\"", ")", "{", "throw", "new", "NoMigrationTableException", "(", ")", ";", "}", "$", "this", "->", "db_version", "=", "new", "NullVersion", ";", "}", "}" ]
Load the current version from the database
[ "Load", "the", "current", "version", "from", "the", "database" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Migrate/Module.php#L88-L108
train
Wedeto/DB
src/Migrate/Module.php
Module.migrateTo
public function migrateTo(int $target_version) { if ($this->max_version === null) $this->scanMigrations(); $current_version = $this->getCurrentVersion(); $trajectory = $this->plan($current_version, $target_version); $db = $this->db; foreach ($trajectory as $migration) { $migration['module'] = $this->module; $filename = $migration['file']; $ext = strtolower(substr($filename, -4)); $db->beginTransaction(); try { static::$logger->info("Migrating module {module} from {from} to {to} using file {file}", $migration); if ($ext === ".php") { executePHP($db, $filename); } elseif ($ext === ".sql") { $db->executeSQL($filename); } // If no exceptions were thrown, we're going to assume that the // upgrade succeeded, so update the version number in the // database and commit the changes. // Clear the database schema cache $db->clearCache(); $this->dao = $this->db->getDAO(DBVersion::class); $version = new DBVersion; $version->module = $this->module; $version->from_version = (int)$migration['from']; $version->to_version = (int)$migration['to']; $version->migration_date = new \DateTime(); $version->filename = $filename; $version->md5sum = md5(file_get_contents($filename)); $this->dao->save($version); static::$logger->info("Succesfully migrated module {module} from {from} to {to} using file {file}", $migration); $db->commit(); } catch (\Exception $e) { // Upgrade failed, roll back to previous state static::$logger->error("Migration of module {module} from {from} to {to} using file {file}", $migration); static::$logger->error("Exception: {0}", [$e]); $db->rollback(); throw $e; } } }
php
public function migrateTo(int $target_version) { if ($this->max_version === null) $this->scanMigrations(); $current_version = $this->getCurrentVersion(); $trajectory = $this->plan($current_version, $target_version); $db = $this->db; foreach ($trajectory as $migration) { $migration['module'] = $this->module; $filename = $migration['file']; $ext = strtolower(substr($filename, -4)); $db->beginTransaction(); try { static::$logger->info("Migrating module {module} from {from} to {to} using file {file}", $migration); if ($ext === ".php") { executePHP($db, $filename); } elseif ($ext === ".sql") { $db->executeSQL($filename); } // If no exceptions were thrown, we're going to assume that the // upgrade succeeded, so update the version number in the // database and commit the changes. // Clear the database schema cache $db->clearCache(); $this->dao = $this->db->getDAO(DBVersion::class); $version = new DBVersion; $version->module = $this->module; $version->from_version = (int)$migration['from']; $version->to_version = (int)$migration['to']; $version->migration_date = new \DateTime(); $version->filename = $filename; $version->md5sum = md5(file_get_contents($filename)); $this->dao->save($version); static::$logger->info("Succesfully migrated module {module} from {from} to {to} using file {file}", $migration); $db->commit(); } catch (\Exception $e) { // Upgrade failed, roll back to previous state static::$logger->error("Migration of module {module} from {from} to {to} using file {file}", $migration); static::$logger->error("Exception: {0}", [$e]); $db->rollback(); throw $e; } } }
[ "public", "function", "migrateTo", "(", "int", "$", "target_version", ")", "{", "if", "(", "$", "this", "->", "max_version", "===", "null", ")", "$", "this", "->", "scanMigrations", "(", ")", ";", "$", "current_version", "=", "$", "this", "->", "getCurrentVersion", "(", ")", ";", "$", "trajectory", "=", "$", "this", "->", "plan", "(", "$", "current_version", ",", "$", "target_version", ")", ";", "$", "db", "=", "$", "this", "->", "db", ";", "foreach", "(", "$", "trajectory", "as", "$", "migration", ")", "{", "$", "migration", "[", "'module'", "]", "=", "$", "this", "->", "module", ";", "$", "filename", "=", "$", "migration", "[", "'file'", "]", ";", "$", "ext", "=", "strtolower", "(", "substr", "(", "$", "filename", ",", "-", "4", ")", ")", ";", "$", "db", "->", "beginTransaction", "(", ")", ";", "try", "{", "static", "::", "$", "logger", "->", "info", "(", "\"Migrating module {module} from {from} to {to} using file {file}\"", ",", "$", "migration", ")", ";", "if", "(", "$", "ext", "===", "\".php\"", ")", "{", "executePHP", "(", "$", "db", ",", "$", "filename", ")", ";", "}", "elseif", "(", "$", "ext", "===", "\".sql\"", ")", "{", "$", "db", "->", "executeSQL", "(", "$", "filename", ")", ";", "}", "// If no exceptions were thrown, we're going to assume that the", "// upgrade succeeded, so update the version number in the", "// database and commit the changes.", "// Clear the database schema cache", "$", "db", "->", "clearCache", "(", ")", ";", "$", "this", "->", "dao", "=", "$", "this", "->", "db", "->", "getDAO", "(", "DBVersion", "::", "class", ")", ";", "$", "version", "=", "new", "DBVersion", ";", "$", "version", "->", "module", "=", "$", "this", "->", "module", ";", "$", "version", "->", "from_version", "=", "(", "int", ")", "$", "migration", "[", "'from'", "]", ";", "$", "version", "->", "to_version", "=", "(", "int", ")", "$", "migration", "[", "'to'", "]", ";", "$", "version", "->", "migration_date", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "version", "->", "filename", "=", "$", "filename", ";", "$", "version", "->", "md5sum", "=", "md5", "(", "file_get_contents", "(", "$", "filename", ")", ")", ";", "$", "this", "->", "dao", "->", "save", "(", "$", "version", ")", ";", "static", "::", "$", "logger", "->", "info", "(", "\"Succesfully migrated module {module} from {from} to {to} using file {file}\"", ",", "$", "migration", ")", ";", "$", "db", "->", "commit", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// Upgrade failed, roll back to previous state", "static", "::", "$", "logger", "->", "error", "(", "\"Migration of module {module} from {from} to {to} using file {file}\"", ",", "$", "migration", ")", ";", "static", "::", "$", "logger", "->", "error", "(", "\"Exception: {0}\"", ",", "[", "$", "e", "]", ")", ";", "$", "db", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "}", "}", "}" ]
Perform a migration from the current version to the target version @param int $version The target version @throws MigrationException Whenever no migration path can be found to the target version @throws DBException When something goes wrong during the migration
[ "Perform", "a", "migration", "from", "the", "current", "version", "to", "the", "target", "version" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Migrate/Module.php#L242-L301
train
Wedeto/DB
src/Migrate/Module.php
Module.plan
protected function plan(int $from, int $to) { $migrations = []; if ($from === $to) return $migrations; $is_downgrade = $to < $from; $reachable = $this->migrations[$from] ?? []; // For downgrades, we want the lowest reachable target that is above or equal to the final target // For upgrades, we want the highest reachable target that is below or equal to the final target // To always use the first encountered, the array needs to be reversed for upgrades, as it's sorted by key if (!$is_downgrade) $reachable = array_reverse($reachable, true); // Traverse the reachable migrations foreach ($reachable as $direct_to => $path) { if ( ($direct_to === $to) || // Bingo ($is_downgrade && $direct_to > $to) || // Proper downgrade (!$is_downgrade && $direct_to < $to) // Proper upgrade ) { // In the right direction, so add to the path $migrations[] = ['from' => $from, 'to' => $direct_to, 'file' => $path]; break; } } if (count($migrations) === 0) throw new MigrationException("No migration path from version $from to $to for module {$this->module}"); $last = end($migrations); if ($last['to'] !== $to) { $rest = $this->plan($last['to'], $to); foreach ($rest as $migration) $migrations[] = $migration; } return $migrations; }
php
protected function plan(int $from, int $to) { $migrations = []; if ($from === $to) return $migrations; $is_downgrade = $to < $from; $reachable = $this->migrations[$from] ?? []; // For downgrades, we want the lowest reachable target that is above or equal to the final target // For upgrades, we want the highest reachable target that is below or equal to the final target // To always use the first encountered, the array needs to be reversed for upgrades, as it's sorted by key if (!$is_downgrade) $reachable = array_reverse($reachable, true); // Traverse the reachable migrations foreach ($reachable as $direct_to => $path) { if ( ($direct_to === $to) || // Bingo ($is_downgrade && $direct_to > $to) || // Proper downgrade (!$is_downgrade && $direct_to < $to) // Proper upgrade ) { // In the right direction, so add to the path $migrations[] = ['from' => $from, 'to' => $direct_to, 'file' => $path]; break; } } if (count($migrations) === 0) throw new MigrationException("No migration path from version $from to $to for module {$this->module}"); $last = end($migrations); if ($last['to'] !== $to) { $rest = $this->plan($last['to'], $to); foreach ($rest as $migration) $migrations[] = $migration; } return $migrations; }
[ "protected", "function", "plan", "(", "int", "$", "from", ",", "int", "$", "to", ")", "{", "$", "migrations", "=", "[", "]", ";", "if", "(", "$", "from", "===", "$", "to", ")", "return", "$", "migrations", ";", "$", "is_downgrade", "=", "$", "to", "<", "$", "from", ";", "$", "reachable", "=", "$", "this", "->", "migrations", "[", "$", "from", "]", "??", "[", "]", ";", "// For downgrades, we want the lowest reachable target that is above or equal to the final target", "// For upgrades, we want the highest reachable target that is below or equal to the final target", "// To always use the first encountered, the array needs to be reversed for upgrades, as it's sorted by key", "if", "(", "!", "$", "is_downgrade", ")", "$", "reachable", "=", "array_reverse", "(", "$", "reachable", ",", "true", ")", ";", "// Traverse the reachable migrations", "foreach", "(", "$", "reachable", "as", "$", "direct_to", "=>", "$", "path", ")", "{", "if", "(", "(", "$", "direct_to", "===", "$", "to", ")", "||", "// Bingo", "(", "$", "is_downgrade", "&&", "$", "direct_to", ">", "$", "to", ")", "||", "// Proper downgrade", "(", "!", "$", "is_downgrade", "&&", "$", "direct_to", "<", "$", "to", ")", "// Proper upgrade", ")", "{", "// In the right direction, so add to the path", "$", "migrations", "[", "]", "=", "[", "'from'", "=>", "$", "from", ",", "'to'", "=>", "$", "direct_to", ",", "'file'", "=>", "$", "path", "]", ";", "break", ";", "}", "}", "if", "(", "count", "(", "$", "migrations", ")", "===", "0", ")", "throw", "new", "MigrationException", "(", "\"No migration path from version $from to $to for module {$this->module}\"", ")", ";", "$", "last", "=", "end", "(", "$", "migrations", ")", ";", "if", "(", "$", "last", "[", "'to'", "]", "!==", "$", "to", ")", "{", "$", "rest", "=", "$", "this", "->", "plan", "(", "$", "last", "[", "'to'", "]", ",", "$", "to", ")", ";", "foreach", "(", "$", "rest", "as", "$", "migration", ")", "$", "migrations", "[", "]", "=", "$", "migration", ";", "}", "return", "$", "migrations", ";", "}" ]
Plan a path through available migrations to reach a specified version from another version. This is always done in one direction, opportunistically. This means that when downgrading, no intermediate upgrades are performed, even if they may result in shorter path. Whenever a more than one step is available, the larger one is selected. Potentially, this could result in sinks with no way out. Design your upgrade trajectories with this in mind. @param $from The source version to start planning from @param $to The target version to plan towards @return array The list of migrations to execute. When $from and $to are equal, an empty array is returned. @throws MigrationException When no migration path can be found
[ "Plan", "a", "path", "through", "available", "migrations", "to", "reach", "a", "specified", "version", "from", "another", "version", ".", "This", "is", "always", "done", "in", "one", "direction", "opportunistically", ".", "This", "means", "that", "when", "downgrading", "no", "intermediate", "upgrades", "are", "performed", "even", "if", "they", "may", "result", "in", "shorter", "path", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Migrate/Module.php#L320-L363
train
agentmedia/phine-core
src/Core/Logic/Module/FrontendForm.php
FrontendForm.AddUniqueSubmit
protected function AddUniqueSubmit($label) { $name = $label . '-' . $this->Content()->GetID(); $fullLabel = $this->Label($label); $this->AddSubmit($name, Trans($fullLabel)); }
php
protected function AddUniqueSubmit($label) { $name = $label . '-' . $this->Content()->GetID(); $fullLabel = $this->Label($label); $this->AddSubmit($name, Trans($fullLabel)); }
[ "protected", "function", "AddUniqueSubmit", "(", "$", "label", ")", "{", "$", "name", "=", "$", "label", ".", "'-'", ".", "$", "this", "->", "Content", "(", ")", "->", "GetID", "(", ")", ";", "$", "fullLabel", "=", "$", "this", "->", "Label", "(", "$", "label", ")", ";", "$", "this", "->", "AddSubmit", "(", "$", "name", ",", "Trans", "(", "$", "fullLabel", ")", ")", ";", "}" ]
Adds a submit button with a unique name @param string $label The wording label used for the submit button
[ "Adds", "a", "submit", "button", "with", "a", "unique", "name" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/FrontendForm.php#L12-L17
train
mullanaphy/variable
src/PHY/Variable/Obj.php
Obj.toArray
public function toArray() { $class = $this->get(); $class = (array)$class; foreach ($class as $key => $value) { if (is_object($value)) { $class[$key] = (new static($value))->toArray(); } } return $class; }
php
public function toArray() { $class = $this->get(); $class = (array)$class; foreach ($class as $key => $value) { if (is_object($value)) { $class[$key] = (new static($value))->toArray(); } } return $class; }
[ "public", "function", "toArray", "(", ")", "{", "$", "class", "=", "$", "this", "->", "get", "(", ")", ";", "$", "class", "=", "(", "array", ")", "$", "class", ";", "foreach", "(", "$", "class", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", ")", "{", "$", "class", "[", "$", "key", "]", "=", "(", "new", "static", "(", "$", "value", ")", ")", "->", "toArray", "(", ")", ";", "}", "}", "return", "$", "class", ";", "}" ]
Recursively convert our object into an array. @return array
[ "Recursively", "convert", "our", "object", "into", "an", "array", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Obj.php#L88-L98
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.validateTypes
protected function validateTypes(Dictionary $types, $path = "") { $spath = empty($path) ? "" : $path . "."; foreach ($types as $key => $value) { $kpath = $spath . $key; if ($value instanceof Dictionary) { $this->validateTypes($value, $kpath); } elseif (is_string($value)) { $types[$key] = new Validator($value); } elseif (!($value instanceof Validator)) { throw new \InvalidArgumentException( "Unknown type: " . Functions::str($value) . " for " . $kpath ); } } }
php
protected function validateTypes(Dictionary $types, $path = "") { $spath = empty($path) ? "" : $path . "."; foreach ($types as $key => $value) { $kpath = $spath . $key; if ($value instanceof Dictionary) { $this->validateTypes($value, $kpath); } elseif (is_string($value)) { $types[$key] = new Validator($value); } elseif (!($value instanceof Validator)) { throw new \InvalidArgumentException( "Unknown type: " . Functions::str($value) . " for " . $kpath ); } } }
[ "protected", "function", "validateTypes", "(", "Dictionary", "$", "types", ",", "$", "path", "=", "\"\"", ")", "{", "$", "spath", "=", "empty", "(", "$", "path", ")", "?", "\"\"", ":", "$", "path", ".", "\".\"", ";", "foreach", "(", "$", "types", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "kpath", "=", "$", "spath", ".", "$", "key", ";", "if", "(", "$", "value", "instanceof", "Dictionary", ")", "{", "$", "this", "->", "validateTypes", "(", "$", "value", ",", "$", "kpath", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "types", "[", "$", "key", "]", "=", "new", "Validator", "(", "$", "value", ")", ";", "}", "elseif", "(", "!", "(", "$", "value", "instanceof", "Validator", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Unknown type: \"", ".", "Functions", "::", "str", "(", "$", "value", ")", ".", "\" for \"", ".", "$", "kpath", ")", ";", "}", "}", "}" ]
Validate that all provided types are actually type validators @param Dictionary $types The supplied type validators @param string $path The key path, used for reporting errors
[ "Validate", "that", "all", "provided", "types", "are", "actually", "type", "validators" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L69-L90
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.setType
public function setType($key, $type) { $args = func_get_args(); $type = array_pop($args); if (!($type instanceof Validator)) $type = new Validator($type); if ($this->types->has($args)) { $old_type = $this->types->get($args); if ($old_type != $type) throw new \LogicException("Duplicate key: " . WF::str($args)); } else { $args[] = $type; $this->types->set($args, null); } return $this; }
php
public function setType($key, $type) { $args = func_get_args(); $type = array_pop($args); if (!($type instanceof Validator)) $type = new Validator($type); if ($this->types->has($args)) { $old_type = $this->types->get($args); if ($old_type != $type) throw new \LogicException("Duplicate key: " . WF::str($args)); } else { $args[] = $type; $this->types->set($args, null); } return $this; }
[ "public", "function", "setType", "(", "$", "key", ",", "$", "type", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "type", "=", "array_pop", "(", "$", "args", ")", ";", "if", "(", "!", "(", "$", "type", "instanceof", "Validator", ")", ")", "$", "type", "=", "new", "Validator", "(", "$", "type", ")", ";", "if", "(", "$", "this", "->", "types", "->", "has", "(", "$", "args", ")", ")", "{", "$", "old_type", "=", "$", "this", "->", "types", "->", "get", "(", "$", "args", ")", ";", "if", "(", "$", "old_type", "!=", "$", "type", ")", "throw", "new", "\\", "LogicException", "(", "\"Duplicate key: \"", ".", "WF", "::", "str", "(", "$", "args", ")", ")", ";", "}", "else", "{", "$", "args", "[", "]", "=", "$", "type", ";", "$", "this", "->", "types", "->", "set", "(", "$", "args", ",", "null", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a type for a parameter @param string $key The key to set a type for. Can be repeated to go deeper @param Validator $type The type for the parameter @return TypedDictionary Provides fluent interface
[ "Add", "a", "type", "for", "a", "parameter" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L98-L118
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.set
public function set($key, $value) { if (is_array($key) && $value === null) $args = $key; else $args = func_get_args(); $path = $args; $value = array_pop($path); $type = $this->types->dget($path); $kpath = implode('.', $path); // Key is undefined, but it may be in a untyped sub-array if ($type === null) { $cpy = $path; while (count($cpy)) { $last = array_pop($cpy); $subtype = $this->types->dget($cpy); if ($subtype instanceof Validator && $subtype->getType() === Type::ARRAY) return parent::set($args, null); } } if ($type === null) throw new \InvalidArgumentException("Undefined key: " . $kpath); if ($type instanceof Dictionary) { // Subfiltering required - extract values if (!Functions::is_array_like($value)) throw new \InvalidArgumentException("Value must be array at: " . $kpath); foreach ($value as $subkey => $subval) { $nargs = $path; $nargs[] = $subkey; $nargs[] = $subval; $this->set($nargs, null); } return; } if (!$type->validate($value)) { $error = $type->getErrorMessage($value); $msg = WF::fillPlaceholders($error['msg'], $error['context'] ?? []); throw new \InvalidArgumentException($msg); } return parent::set($args, null); }
php
public function set($key, $value) { if (is_array($key) && $value === null) $args = $key; else $args = func_get_args(); $path = $args; $value = array_pop($path); $type = $this->types->dget($path); $kpath = implode('.', $path); // Key is undefined, but it may be in a untyped sub-array if ($type === null) { $cpy = $path; while (count($cpy)) { $last = array_pop($cpy); $subtype = $this->types->dget($cpy); if ($subtype instanceof Validator && $subtype->getType() === Type::ARRAY) return parent::set($args, null); } } if ($type === null) throw new \InvalidArgumentException("Undefined key: " . $kpath); if ($type instanceof Dictionary) { // Subfiltering required - extract values if (!Functions::is_array_like($value)) throw new \InvalidArgumentException("Value must be array at: " . $kpath); foreach ($value as $subkey => $subval) { $nargs = $path; $nargs[] = $subkey; $nargs[] = $subval; $this->set($nargs, null); } return; } if (!$type->validate($value)) { $error = $type->getErrorMessage($value); $msg = WF::fillPlaceholders($error['msg'], $error['context'] ?? []); throw new \InvalidArgumentException($msg); } return parent::set($args, null); }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", "&&", "$", "value", "===", "null", ")", "$", "args", "=", "$", "key", ";", "else", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "path", "=", "$", "args", ";", "$", "value", "=", "array_pop", "(", "$", "path", ")", ";", "$", "type", "=", "$", "this", "->", "types", "->", "dget", "(", "$", "path", ")", ";", "$", "kpath", "=", "implode", "(", "'.'", ",", "$", "path", ")", ";", "// Key is undefined, but it may be in a untyped sub-array", "if", "(", "$", "type", "===", "null", ")", "{", "$", "cpy", "=", "$", "path", ";", "while", "(", "count", "(", "$", "cpy", ")", ")", "{", "$", "last", "=", "array_pop", "(", "$", "cpy", ")", ";", "$", "subtype", "=", "$", "this", "->", "types", "->", "dget", "(", "$", "cpy", ")", ";", "if", "(", "$", "subtype", "instanceof", "Validator", "&&", "$", "subtype", "->", "getType", "(", ")", "===", "Type", "::", "ARRAY", ")", "return", "parent", "::", "set", "(", "$", "args", ",", "null", ")", ";", "}", "}", "if", "(", "$", "type", "===", "null", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Undefined key: \"", ".", "$", "kpath", ")", ";", "if", "(", "$", "type", "instanceof", "Dictionary", ")", "{", "// Subfiltering required - extract values", "if", "(", "!", "Functions", "::", "is_array_like", "(", "$", "value", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Value must be array at: \"", ".", "$", "kpath", ")", ";", "foreach", "(", "$", "value", "as", "$", "subkey", "=>", "$", "subval", ")", "{", "$", "nargs", "=", "$", "path", ";", "$", "nargs", "[", "]", "=", "$", "subkey", ";", "$", "nargs", "[", "]", "=", "$", "subval", ";", "$", "this", "->", "set", "(", "$", "nargs", ",", "null", ")", ";", "}", "return", ";", "}", "if", "(", "!", "$", "type", "->", "validate", "(", "$", "value", ")", ")", "{", "$", "error", "=", "$", "type", "->", "getErrorMessage", "(", "$", "value", ")", ";", "$", "msg", "=", "WF", "::", "fillPlaceholders", "(", "$", "error", "[", "'msg'", "]", ",", "$", "error", "[", "'context'", "]", "??", "[", "]", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "return", "parent", "::", "set", "(", "$", "args", ",", "null", ")", ";", "}" ]
Set a value, after type checking @param string $key The key to set. Can be repeated to go deeper @param mixed $value Whatever to set. Will be type checked @return TypedDictionary Provides fluent interface
[ "Set", "a", "value", "after", "type", "checking" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L126-L178
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.&
public function &dget($key, $default = null) { $args = WF::flatten_array(func_get_args()); if (func_num_args() > 1) { $default = array_pop($args); if (!($default instanceof DefVal)) $default = new DefVal($default); $args[] = $default; } // Get the value, without referencing, so that we actually return a copy $result = parent::dget($args, null); if ($result instanceof Dictionary) { // Sub-arrays are returned as dictionary - which allow // modification without type checking. Re-wrap into // a TypedDictionary including the correct types $path = $args; $types = $this->types->dget($path); if (WF::is_array_like($types)) { $dict = new TypedDictionary($types); $dict->values = &$result->values; $result = $dict; } } // Return the copy to keep it unmodifiable return $result; }
php
public function &dget($key, $default = null) { $args = WF::flatten_array(func_get_args()); if (func_num_args() > 1) { $default = array_pop($args); if (!($default instanceof DefVal)) $default = new DefVal($default); $args[] = $default; } // Get the value, without referencing, so that we actually return a copy $result = parent::dget($args, null); if ($result instanceof Dictionary) { // Sub-arrays are returned as dictionary - which allow // modification without type checking. Re-wrap into // a TypedDictionary including the correct types $path = $args; $types = $this->types->dget($path); if (WF::is_array_like($types)) { $dict = new TypedDictionary($types); $dict->values = &$result->values; $result = $dict; } } // Return the copy to keep it unmodifiable return $result; }
[ "public", "function", "&", "dget", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "$", "args", "=", "WF", "::", "flatten_array", "(", "func_get_args", "(", ")", ")", ";", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "{", "$", "default", "=", "array_pop", "(", "$", "args", ")", ";", "if", "(", "!", "(", "$", "default", "instanceof", "DefVal", ")", ")", "$", "default", "=", "new", "DefVal", "(", "$", "default", ")", ";", "$", "args", "[", "]", "=", "$", "default", ";", "}", "// Get the value, without referencing, so that we actually return a copy", "$", "result", "=", "parent", "::", "dget", "(", "$", "args", ",", "null", ")", ";", "if", "(", "$", "result", "instanceof", "Dictionary", ")", "{", "// Sub-arrays are returned as dictionary - which allow", "// modification without type checking. Re-wrap into", "// a TypedDictionary including the correct types", "$", "path", "=", "$", "args", ";", "$", "types", "=", "$", "this", "->", "types", "->", "dget", "(", "$", "path", ")", ";", "if", "(", "WF", "::", "is_array_like", "(", "$", "types", ")", ")", "{", "$", "dict", "=", "new", "TypedDictionary", "(", "$", "types", ")", ";", "$", "dict", "->", "values", "=", "&", "$", "result", "->", "values", ";", "$", "result", "=", "$", "dict", ";", "}", "}", "// Return the copy to keep it unmodifiable", "return", "$", "result", ";", "}" ]
We override dget as dget returns a reference, allowing the TypedDictionary to be modified from the outside. This avoids the checks, so this needs to be disallowed. @param string $key The key to set. Can be repeated to go deeper @param mixed $default A default value to return in absence
[ "We", "override", "dget", "as", "dget", "returns", "a", "reference", "allowing", "the", "TypedDictionary", "to", "be", "modified", "from", "the", "outside", ".", "This", "avoids", "the", "checks", "so", "this", "needs", "to", "be", "disallowed", "." ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L188-L220
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.addAll
public function addAll($values) { foreach ($values as $key => $value) $this->set($key, $value); return $this; }
php
public function addAll($values) { foreach ($values as $key => $value) $this->set($key, $value); return $this; }
[ "public", "function", "addAll", "(", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "$", "this", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Add all provided values, checking their types @param array $values Array with values. @return TypedDictionary Provides fluent interface
[ "Add", "all", "provided", "values", "checking", "their", "types" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L227-L232
train
Wedeto/Util
src/TypedDictionary.php
TypedDictionary.wrap
public static function wrap(array &$values) { $types = new Dictionary; self::determineTypes($values, $types); return new TypedDictionary($types, $values); }
php
public static function wrap(array &$values) { $types = new Dictionary; self::determineTypes($values, $types); return new TypedDictionary($types, $values); }
[ "public", "static", "function", "wrap", "(", "array", "&", "$", "values", ")", "{", "$", "types", "=", "new", "Dictionary", ";", "self", "::", "determineTypes", "(", "$", "values", ",", "$", "types", ")", ";", "return", "new", "TypedDictionary", "(", "$", "types", ",", "$", "values", ")", ";", "}" ]
Customize wrapping of the TypedDictionary - the wrapped array can still be modified externally so we need to make sure the appropriate types are propagated @throws RuntimeException Always
[ "Customize", "wrapping", "of", "the", "TypedDictionary", "-", "the", "wrapped", "array", "can", "still", "be", "modified", "externally", "so", "we", "need", "to", "make", "sure", "the", "appropriate", "types", "are", "propagated" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/TypedDictionary.php#L296-L302
train
mwyatt/core
src/FileSystem.php
FileSystem.globRecursive
private function globRecursive($pattern) { $paths = glob($pattern); foreach ($paths as $path) { if (strpos($path, '.') === false) { $paths = array_merge($paths, $this->globRecursive($path . '/*')); } } return $paths; }
php
private function globRecursive($pattern) { $paths = glob($pattern); foreach ($paths as $path) { if (strpos($path, '.') === false) { $paths = array_merge($paths, $this->globRecursive($path . '/*')); } } return $paths; }
[ "private", "function", "globRecursive", "(", "$", "pattern", ")", "{", "$", "paths", "=", "glob", "(", "$", "pattern", ")", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "'.'", ")", "===", "false", ")", "{", "$", "paths", "=", "array_merge", "(", "$", "paths", ",", "$", "this", "->", "globRecursive", "(", "$", "path", ".", "'/*'", ")", ")", ";", "}", "}", "return", "$", "paths", ";", "}" ]
watch out can be slow! 4.75s for 20k paths @param string $pattern '/*' @return array paths
[ "watch", "out", "can", "be", "slow!", "4", ".", "75s", "for", "20k", "paths" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/FileSystem.php#L99-L108
train
phossa/phossa-cache
src/Phossa/Cache/Driver/CompositeDriver.php
CompositeDriver.get
public function get(/*# string */ $key)/*# : string */ { // try front-end cache first if ($this->frontHas($key)) { return $this->front->get($key); } // get from backend cache return $this->back->get($key); }
php
public function get(/*# string */ $key)/*# : string */ { // try front-end cache first if ($this->frontHas($key)) { return $this->front->get($key); } // get from backend cache return $this->back->get($key); }
[ "public", "function", "get", "(", "/*# string */", "$", "key", ")", "/*# : string */", "{", "// try front-end cache first", "if", "(", "$", "this", "->", "frontHas", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "front", "->", "get", "(", "$", "key", ")", ";", "}", "// get from backend cache", "return", "$", "this", "->", "back", "->", "get", "(", "$", "key", ")", ";", "}" ]
Either end get ok is ok {@inheritDoc}
[ "Either", "end", "get", "ok", "is", "ok" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/CompositeDriver.php#L127-L136
train