repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
PenoaksDev/Milky-Framework
src/Milky/Annotations/DocParser.php
DocParser.classExists
private function classExists( $fqcn ) { if ( isset( $this->classExists[$fqcn] ) ) return $this->classExists[$fqcn]; // first check if the class already exists, maybe loaded through another AnnotationReader if ( class_exists( $fqcn ) ) return $this->classExists[$fqcn] = true; return false; }
php
private function classExists( $fqcn ) { if ( isset( $this->classExists[$fqcn] ) ) return $this->classExists[$fqcn]; // first check if the class already exists, maybe loaded through another AnnotationReader if ( class_exists( $fqcn ) ) return $this->classExists[$fqcn] = true; return false; }
[ "private", "function", "classExists", "(", "$", "fqcn", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "classExists", "[", "$", "fqcn", "]", ")", ")", "return", "$", "this", "->", "classExists", "[", "$", "fqcn", "]", ";", "// first check if the class already exists, maybe loaded through another AnnotationReader", "if", "(", "class_exists", "(", "$", "fqcn", ")", ")", "return", "$", "this", "->", "classExists", "[", "$", "fqcn", "]", "=", "true", ";", "return", "false", ";", "}" ]
Attempts to check if a class exists or not. @param string $fqcn @return boolean
[ "Attempts", "to", "check", "if", "a", "class", "exists", "or", "not", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Annotations/DocParser.php#L321-L331
PenoaksDev/Milky-Framework
src/Milky/Annotations/DocParser.php
DocParser.Annotation
private function Annotation() { $this->match( DocLexer::T_AT ); // check if we have an annotation $name = $this->Identifier(); // only process names which are not fully qualified, yet // fully qualified names must start with a \ $originalName = $name; if ( '\\' !== $name[0] ) { $alias = ( false === $pos = strpos( $name, '\\' ) ) ? $name : substr( $name, 0, $pos ); $found = true; if ( $import = $this->namespaced( $alias ) ) $name = $import; elseif ( $import = $this->imported( $alias ) ) // isset( $this->imports[$loweredAlias = strtolower( $alias )] ) ) $name = $import; // $name = ( false !== $pos ) ? $this->imports[$loweredAlias] . substr( $name, $pos ) : $this->imports[$loweredAlias]; elseif ( !isset( $this->ignoredAnnotationNames[$name] ) && isset( $this->imports['__NAMESPACE__'] ) && $this->classExists( $this->imports['__NAMESPACE__'] . '\\' . $name ) ) $name = $this->imports['__NAMESPACE__'] . '\\' . $name; elseif ( !isset( $this->ignoredAnnotationNames[$name] ) && $this->classExists( $name ) ) { // } else $found = false; if ( !$found ) { if ( $this->ignoreNotImportedAnnotations || isset( $this->ignoredAnnotationNames[$name] ) ) return false; throw AnnotationException::semanticalError( sprintf( 'The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context ) ); } } if ( !$this->classExists( $name ) ) throw AnnotationException::semanticalError( sprintf( 'The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context ) ); // at this point, $name contains the fully qualified class name of the // annotation, and it is also guaranteed that this class exists, and // that it is loaded // collects the metadata annotation only if there is not yet if ( !isset( self::$annotationMetadata[$name] ) ) $this->collectAnnotationMetadata( $name ); // verify that the class is really meant to be an annotation and not just any ordinary class if ( self::$annotationMetadata[$name]['is_annotation'] === false ) { if ( isset( $this->ignoredAnnotationNames[$originalName] ) ) return false; throw AnnotationException::semanticalError( sprintf( 'The class "%s" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "%s". If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.', $name, $name, $originalName, $this->context ) ); } //if target is nested annotation $target = $this->isNestedAnnotation ? Target::TARGET_ANNOTATION : $this->target; // Next will be nested $this->isNestedAnnotation = true; //if annotation does not support current target if ( 0 === ( self::$annotationMetadata[$name]['targets'] & $target ) && $target ) throw AnnotationException::semanticalError( sprintf( 'Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.', $originalName, $this->context, self::$annotationMetadata[$name]['targets_literal'] ) ); $values = $this->MethodCall(); if ( isset( self::$annotationMetadata[$name]['enum'] ) ) // checks all declared attributes foreach ( self::$annotationMetadata[$name]['enum'] as $property => $enum ) // checks if the attribute is a valid enumerator if ( isset( $values[$property] ) && !in_array( $values[$property], $enum['value'] ) ) throw AnnotationException::enumeratorError( $property, $name, $this->context, $enum['literal'], $values[$property] ); // checks all declared attributes foreach ( self::$annotationMetadata[$name]['attribute_types'] as $property => $type ) { if ( $property === self::$annotationMetadata[$name]['default_property'] && !isset( $values[$property] ) && isset( $values['value'] ) ) $property = 'value'; // handle a not given attribute or null value if ( !isset( $values[$property] ) ) { if ( $type['required'] ) throw AnnotationException::requiredError( $property, $originalName, $this->context, 'a(n) ' . $type['value'] ); continue; } if ( $type['type'] === 'array' ) { // handle the case of a single value if ( !is_array( $values[$property] ) ) $values[$property] = [$values[$property]]; // checks if the attribute has array type declaration, such as "array<string>" if ( isset( $type['array_type'] ) ) foreach ( $values[$property] as $item ) if ( gettype( $item ) !== $type['array_type'] && !$item instanceof $type['array_type'] ) throw AnnotationException::attributeTypeError( $property, $originalName, $this->context, 'either a(n) ' . $type['array_type'] . ', or an array of ' . $type['array_type'] . 's', $item ); } elseif ( gettype( $values[$property] ) !== $type['type'] && !$values[$property] instanceof $type['type'] ) throw AnnotationException::attributeTypeError( $property, $originalName, $this->context, 'a(n) ' . $type['value'], $values[$property] ); } // check if the annotation expects values via the constructor, // or directly injected into public properties if ( self::$annotationMetadata[$name]['has_constructor'] === true ) return new $name( $values ); $instance = new $name(); foreach ( $values as $property => $value ) { if ( !isset( self::$annotationMetadata[$name]['properties'][$property] ) ) { if ( 'value' !== $property ) throw AnnotationException::creationError( sprintf( 'The annotation @%s declared on %s does not have a property named "%s". Available properties: %s', $originalName, $this->context, $property, implode( ', ', self::$annotationMetadata[$name]['properties'] ) ) ); // handle the case if the property has no annotations if ( !$property = self::$annotationMetadata[$name]['default_property'] ) throw AnnotationException::creationError( sprintf( 'The annotation @%s declared on %s does not accept any values, but got %s.', $originalName, $this->context, json_encode( $values ) ) ); } $instance->{$property} = $value; } return $instance; }
php
private function Annotation() { $this->match( DocLexer::T_AT ); // check if we have an annotation $name = $this->Identifier(); // only process names which are not fully qualified, yet // fully qualified names must start with a \ $originalName = $name; if ( '\\' !== $name[0] ) { $alias = ( false === $pos = strpos( $name, '\\' ) ) ? $name : substr( $name, 0, $pos ); $found = true; if ( $import = $this->namespaced( $alias ) ) $name = $import; elseif ( $import = $this->imported( $alias ) ) // isset( $this->imports[$loweredAlias = strtolower( $alias )] ) ) $name = $import; // $name = ( false !== $pos ) ? $this->imports[$loweredAlias] . substr( $name, $pos ) : $this->imports[$loweredAlias]; elseif ( !isset( $this->ignoredAnnotationNames[$name] ) && isset( $this->imports['__NAMESPACE__'] ) && $this->classExists( $this->imports['__NAMESPACE__'] . '\\' . $name ) ) $name = $this->imports['__NAMESPACE__'] . '\\' . $name; elseif ( !isset( $this->ignoredAnnotationNames[$name] ) && $this->classExists( $name ) ) { // } else $found = false; if ( !$found ) { if ( $this->ignoreNotImportedAnnotations || isset( $this->ignoredAnnotationNames[$name] ) ) return false; throw AnnotationException::semanticalError( sprintf( 'The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context ) ); } } if ( !$this->classExists( $name ) ) throw AnnotationException::semanticalError( sprintf( 'The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context ) ); // at this point, $name contains the fully qualified class name of the // annotation, and it is also guaranteed that this class exists, and // that it is loaded // collects the metadata annotation only if there is not yet if ( !isset( self::$annotationMetadata[$name] ) ) $this->collectAnnotationMetadata( $name ); // verify that the class is really meant to be an annotation and not just any ordinary class if ( self::$annotationMetadata[$name]['is_annotation'] === false ) { if ( isset( $this->ignoredAnnotationNames[$originalName] ) ) return false; throw AnnotationException::semanticalError( sprintf( 'The class "%s" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "%s". If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.', $name, $name, $originalName, $this->context ) ); } //if target is nested annotation $target = $this->isNestedAnnotation ? Target::TARGET_ANNOTATION : $this->target; // Next will be nested $this->isNestedAnnotation = true; //if annotation does not support current target if ( 0 === ( self::$annotationMetadata[$name]['targets'] & $target ) && $target ) throw AnnotationException::semanticalError( sprintf( 'Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.', $originalName, $this->context, self::$annotationMetadata[$name]['targets_literal'] ) ); $values = $this->MethodCall(); if ( isset( self::$annotationMetadata[$name]['enum'] ) ) // checks all declared attributes foreach ( self::$annotationMetadata[$name]['enum'] as $property => $enum ) // checks if the attribute is a valid enumerator if ( isset( $values[$property] ) && !in_array( $values[$property], $enum['value'] ) ) throw AnnotationException::enumeratorError( $property, $name, $this->context, $enum['literal'], $values[$property] ); // checks all declared attributes foreach ( self::$annotationMetadata[$name]['attribute_types'] as $property => $type ) { if ( $property === self::$annotationMetadata[$name]['default_property'] && !isset( $values[$property] ) && isset( $values['value'] ) ) $property = 'value'; // handle a not given attribute or null value if ( !isset( $values[$property] ) ) { if ( $type['required'] ) throw AnnotationException::requiredError( $property, $originalName, $this->context, 'a(n) ' . $type['value'] ); continue; } if ( $type['type'] === 'array' ) { // handle the case of a single value if ( !is_array( $values[$property] ) ) $values[$property] = [$values[$property]]; // checks if the attribute has array type declaration, such as "array<string>" if ( isset( $type['array_type'] ) ) foreach ( $values[$property] as $item ) if ( gettype( $item ) !== $type['array_type'] && !$item instanceof $type['array_type'] ) throw AnnotationException::attributeTypeError( $property, $originalName, $this->context, 'either a(n) ' . $type['array_type'] . ', or an array of ' . $type['array_type'] . 's', $item ); } elseif ( gettype( $values[$property] ) !== $type['type'] && !$values[$property] instanceof $type['type'] ) throw AnnotationException::attributeTypeError( $property, $originalName, $this->context, 'a(n) ' . $type['value'], $values[$property] ); } // check if the annotation expects values via the constructor, // or directly injected into public properties if ( self::$annotationMetadata[$name]['has_constructor'] === true ) return new $name( $values ); $instance = new $name(); foreach ( $values as $property => $value ) { if ( !isset( self::$annotationMetadata[$name]['properties'][$property] ) ) { if ( 'value' !== $property ) throw AnnotationException::creationError( sprintf( 'The annotation @%s declared on %s does not have a property named "%s". Available properties: %s', $originalName, $this->context, $property, implode( ', ', self::$annotationMetadata[$name]['properties'] ) ) ); // handle the case if the property has no annotations if ( !$property = self::$annotationMetadata[$name]['default_property'] ) throw AnnotationException::creationError( sprintf( 'The annotation @%s declared on %s does not accept any values, but got %s.', $originalName, $this->context, json_encode( $values ) ) ); } $instance->{$property} = $value; } return $instance; }
[ "private", "function", "Annotation", "(", ")", "{", "$", "this", "->", "match", "(", "DocLexer", "::", "T_AT", ")", ";", "// check if we have an annotation", "$", "name", "=", "$", "this", "->", "Identifier", "(", ")", ";", "// only process names which are not fully qualified, yet", "// fully qualified names must start with a \\", "$", "originalName", "=", "$", "name", ";", "if", "(", "'\\\\'", "!==", "$", "name", "[", "0", "]", ")", "{", "$", "alias", "=", "(", "false", "===", "$", "pos", "=", "strpos", "(", "$", "name", ",", "'\\\\'", ")", ")", "?", "$", "name", ":", "substr", "(", "$", "name", ",", "0", ",", "$", "pos", ")", ";", "$", "found", "=", "true", ";", "if", "(", "$", "import", "=", "$", "this", "->", "namespaced", "(", "$", "alias", ")", ")", "$", "name", "=", "$", "import", ";", "elseif", "(", "$", "import", "=", "$", "this", "->", "imported", "(", "$", "alias", ")", ")", "// isset( $this->imports[$loweredAlias = strtolower( $alias )] ) )", "$", "name", "=", "$", "import", ";", "// $name = ( false !== $pos ) ? $this->imports[$loweredAlias] . substr( $name, $pos ) : $this->imports[$loweredAlias];", "elseif", "(", "!", "isset", "(", "$", "this", "->", "ignoredAnnotationNames", "[", "$", "name", "]", ")", "&&", "isset", "(", "$", "this", "->", "imports", "[", "'__NAMESPACE__'", "]", ")", "&&", "$", "this", "->", "classExists", "(", "$", "this", "->", "imports", "[", "'__NAMESPACE__'", "]", ".", "'\\\\'", ".", "$", "name", ")", ")", "$", "name", "=", "$", "this", "->", "imports", "[", "'__NAMESPACE__'", "]", ".", "'\\\\'", ".", "$", "name", ";", "elseif", "(", "!", "isset", "(", "$", "this", "->", "ignoredAnnotationNames", "[", "$", "name", "]", ")", "&&", "$", "this", "->", "classExists", "(", "$", "name", ")", ")", "{", "//", "}", "else", "$", "found", "=", "false", ";", "if", "(", "!", "$", "found", ")", "{", "if", "(", "$", "this", "->", "ignoreNotImportedAnnotations", "||", "isset", "(", "$", "this", "->", "ignoredAnnotationNames", "[", "$", "name", "]", ")", ")", "return", "false", ";", "throw", "AnnotationException", "::", "semanticalError", "(", "sprintf", "(", "'The annotation \"@%s\" in %s was never imported. Did you maybe forget to add a \"use\" statement for this annotation?'", ",", "$", "name", ",", "$", "this", "->", "context", ")", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "classExists", "(", "$", "name", ")", ")", "throw", "AnnotationException", "::", "semanticalError", "(", "sprintf", "(", "'The annotation \"@%s\" in %s does not exist, or could not be auto-loaded.'", ",", "$", "name", ",", "$", "this", "->", "context", ")", ")", ";", "// at this point, $name contains the fully qualified class name of the", "// annotation, and it is also guaranteed that this class exists, and", "// that it is loaded", "// collects the metadata annotation only if there is not yet", "if", "(", "!", "isset", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", ")", ")", "$", "this", "->", "collectAnnotationMetadata", "(", "$", "name", ")", ";", "// verify that the class is really meant to be an annotation and not just any ordinary class", "if", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'is_annotation'", "]", "===", "false", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "ignoredAnnotationNames", "[", "$", "originalName", "]", ")", ")", "return", "false", ";", "throw", "AnnotationException", "::", "semanticalError", "(", "sprintf", "(", "'The class \"%s\" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of \"%s\". If it is indeed no annotation, then you need to add @IgnoreAnnotation(\"%s\") to the _class_ doc comment of %s.'", ",", "$", "name", ",", "$", "name", ",", "$", "originalName", ",", "$", "this", "->", "context", ")", ")", ";", "}", "//if target is nested annotation", "$", "target", "=", "$", "this", "->", "isNestedAnnotation", "?", "Target", "::", "TARGET_ANNOTATION", ":", "$", "this", "->", "target", ";", "// Next will be nested", "$", "this", "->", "isNestedAnnotation", "=", "true", ";", "//if annotation does not support current target", "if", "(", "0", "===", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'targets'", "]", "&", "$", "target", ")", "&&", "$", "target", ")", "throw", "AnnotationException", "::", "semanticalError", "(", "sprintf", "(", "'Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.'", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'targets_literal'", "]", ")", ")", ";", "$", "values", "=", "$", "this", "->", "MethodCall", "(", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'enum'", "]", ")", ")", "// checks all declared attributes", "foreach", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'enum'", "]", "as", "$", "property", "=>", "$", "enum", ")", "// checks if the attribute is a valid enumerator", "if", "(", "isset", "(", "$", "values", "[", "$", "property", "]", ")", "&&", "!", "in_array", "(", "$", "values", "[", "$", "property", "]", ",", "$", "enum", "[", "'value'", "]", ")", ")", "throw", "AnnotationException", "::", "enumeratorError", "(", "$", "property", ",", "$", "name", ",", "$", "this", "->", "context", ",", "$", "enum", "[", "'literal'", "]", ",", "$", "values", "[", "$", "property", "]", ")", ";", "// checks all declared attributes", "foreach", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'attribute_types'", "]", "as", "$", "property", "=>", "$", "type", ")", "{", "if", "(", "$", "property", "===", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'default_property'", "]", "&&", "!", "isset", "(", "$", "values", "[", "$", "property", "]", ")", "&&", "isset", "(", "$", "values", "[", "'value'", "]", ")", ")", "$", "property", "=", "'value'", ";", "// handle a not given attribute or null value", "if", "(", "!", "isset", "(", "$", "values", "[", "$", "property", "]", ")", ")", "{", "if", "(", "$", "type", "[", "'required'", "]", ")", "throw", "AnnotationException", "::", "requiredError", "(", "$", "property", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "'a(n) '", ".", "$", "type", "[", "'value'", "]", ")", ";", "continue", ";", "}", "if", "(", "$", "type", "[", "'type'", "]", "===", "'array'", ")", "{", "// handle the case of a single value", "if", "(", "!", "is_array", "(", "$", "values", "[", "$", "property", "]", ")", ")", "$", "values", "[", "$", "property", "]", "=", "[", "$", "values", "[", "$", "property", "]", "]", ";", "// checks if the attribute has array type declaration, such as \"array<string>\"", "if", "(", "isset", "(", "$", "type", "[", "'array_type'", "]", ")", ")", "foreach", "(", "$", "values", "[", "$", "property", "]", "as", "$", "item", ")", "if", "(", "gettype", "(", "$", "item", ")", "!==", "$", "type", "[", "'array_type'", "]", "&&", "!", "$", "item", "instanceof", "$", "type", "[", "'array_type'", "]", ")", "throw", "AnnotationException", "::", "attributeTypeError", "(", "$", "property", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "'either a(n) '", ".", "$", "type", "[", "'array_type'", "]", ".", "', or an array of '", ".", "$", "type", "[", "'array_type'", "]", ".", "'s'", ",", "$", "item", ")", ";", "}", "elseif", "(", "gettype", "(", "$", "values", "[", "$", "property", "]", ")", "!==", "$", "type", "[", "'type'", "]", "&&", "!", "$", "values", "[", "$", "property", "]", "instanceof", "$", "type", "[", "'type'", "]", ")", "throw", "AnnotationException", "::", "attributeTypeError", "(", "$", "property", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "'a(n) '", ".", "$", "type", "[", "'value'", "]", ",", "$", "values", "[", "$", "property", "]", ")", ";", "}", "// check if the annotation expects values via the constructor,", "// or directly injected into public properties", "if", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'has_constructor'", "]", "===", "true", ")", "return", "new", "$", "name", "(", "$", "values", ")", ";", "$", "instance", "=", "new", "$", "name", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "property", "=>", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'properties'", "]", "[", "$", "property", "]", ")", ")", "{", "if", "(", "'value'", "!==", "$", "property", ")", "throw", "AnnotationException", "::", "creationError", "(", "sprintf", "(", "'The annotation @%s declared on %s does not have a property named \"%s\". Available properties: %s'", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "$", "property", ",", "implode", "(", "', '", ",", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'properties'", "]", ")", ")", ")", ";", "// handle the case if the property has no annotations", "if", "(", "!", "$", "property", "=", "self", "::", "$", "annotationMetadata", "[", "$", "name", "]", "[", "'default_property'", "]", ")", "throw", "AnnotationException", "::", "creationError", "(", "sprintf", "(", "'The annotation @%s declared on %s does not accept any values, but got %s.'", ",", "$", "originalName", ",", "$", "this", "->", "context", ",", "json_encode", "(", "$", "values", ")", ")", ")", ";", "}", "$", "instance", "->", "{", "$", "property", "}", "=", "$", "value", ";", "}", "return", "$", "instance", ";", "}" ]
Annotation ::= "@" AnnotationName MethodCall AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName NameSpacePart ::= identifier | null | false | true SimpleName ::= identifier | null | false | true @return mixed False if it is not a valid annotation. @throws AnnotationException
[ "Annotation", "::", "=", "@", "AnnotationName", "MethodCall", "AnnotationName", "::", "=", "QualifiedName", "|", "SimpleName", "QualifiedName", "::", "=", "NameSpacePart", "\\", "{", "NameSpacePart", "\\", "}", "*", "SimpleName", "NameSpacePart", "::", "=", "identifier", "|", "null", "|", "false", "|", "true", "SimpleName", "::", "=", "identifier", "|", "null", "|", "false", "|", "true" ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Annotations/DocParser.php#L522-L655
PenoaksDev/Milky-Framework
src/Milky/Annotations/DocParser.php
DocParser.MethodCall
private function MethodCall() { $values = []; if ( !$this->lexer->isNextToken( DocLexer::T_OPEN_PARENTHESIS ) ) return $values; $this->match( DocLexer::T_OPEN_PARENTHESIS ); if ( !$this->lexer->isNextToken( DocLexer::T_CLOSE_PARENTHESIS ) ) $values = $this->Values(); $this->match( DocLexer::T_CLOSE_PARENTHESIS ); return $values; }
php
private function MethodCall() { $values = []; if ( !$this->lexer->isNextToken( DocLexer::T_OPEN_PARENTHESIS ) ) return $values; $this->match( DocLexer::T_OPEN_PARENTHESIS ); if ( !$this->lexer->isNextToken( DocLexer::T_CLOSE_PARENTHESIS ) ) $values = $this->Values(); $this->match( DocLexer::T_CLOSE_PARENTHESIS ); return $values; }
[ "private", "function", "MethodCall", "(", ")", "{", "$", "values", "=", "[", "]", ";", "if", "(", "!", "$", "this", "->", "lexer", "->", "isNextToken", "(", "DocLexer", "::", "T_OPEN_PARENTHESIS", ")", ")", "return", "$", "values", ";", "$", "this", "->", "match", "(", "DocLexer", "::", "T_OPEN_PARENTHESIS", ")", ";", "if", "(", "!", "$", "this", "->", "lexer", "->", "isNextToken", "(", "DocLexer", "::", "T_CLOSE_PARENTHESIS", ")", ")", "$", "values", "=", "$", "this", "->", "Values", "(", ")", ";", "$", "this", "->", "match", "(", "DocLexer", "::", "T_CLOSE_PARENTHESIS", ")", ";", "return", "$", "values", ";", "}" ]
MethodCall ::= ["(" [Values] ")"] @return array
[ "MethodCall", "::", "=", "[", "(", "[", "Values", "]", ")", "]" ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Annotations/DocParser.php#L680-L695
PenoaksDev/Milky-Framework
src/Milky/Annotations/DocParser.php
DocParser.Values
private function Values() { $values = [$this->Value()]; while ( $this->lexer->isNextToken( DocLexer::T_COMMA ) ) { $this->match( DocLexer::T_COMMA ); if ( $this->lexer->isNextToken( DocLexer::T_CLOSE_PARENTHESIS ) ) break; $token = $this->lexer->lookahead; $value = $this->Value(); if ( !is_object( $value ) && !is_array( $value ) ) $this->syntaxError( 'Value', $token ); $values[] = $value; } foreach ( $values as $k => $value ) { if ( is_object( $value ) && $value instanceof \stdClass ) $values[$value->name] = $value->value; else if ( !isset( $values['value'] ) ) $values['value'] = $value; else { if ( !is_array( $values['value'] ) ) $values['value'] = [$values['value']]; $values['value'][] = $value; } unset( $values[$k] ); } return $values; }
php
private function Values() { $values = [$this->Value()]; while ( $this->lexer->isNextToken( DocLexer::T_COMMA ) ) { $this->match( DocLexer::T_COMMA ); if ( $this->lexer->isNextToken( DocLexer::T_CLOSE_PARENTHESIS ) ) break; $token = $this->lexer->lookahead; $value = $this->Value(); if ( !is_object( $value ) && !is_array( $value ) ) $this->syntaxError( 'Value', $token ); $values[] = $value; } foreach ( $values as $k => $value ) { if ( is_object( $value ) && $value instanceof \stdClass ) $values[$value->name] = $value->value; else if ( !isset( $values['value'] ) ) $values['value'] = $value; else { if ( !is_array( $values['value'] ) ) $values['value'] = [$values['value']]; $values['value'][] = $value; } unset( $values[$k] ); } return $values; }
[ "private", "function", "Values", "(", ")", "{", "$", "values", "=", "[", "$", "this", "->", "Value", "(", ")", "]", ";", "while", "(", "$", "this", "->", "lexer", "->", "isNextToken", "(", "DocLexer", "::", "T_COMMA", ")", ")", "{", "$", "this", "->", "match", "(", "DocLexer", "::", "T_COMMA", ")", ";", "if", "(", "$", "this", "->", "lexer", "->", "isNextToken", "(", "DocLexer", "::", "T_CLOSE_PARENTHESIS", ")", ")", "break", ";", "$", "token", "=", "$", "this", "->", "lexer", "->", "lookahead", ";", "$", "value", "=", "$", "this", "->", "Value", "(", ")", ";", "if", "(", "!", "is_object", "(", "$", "value", ")", "&&", "!", "is_array", "(", "$", "value", ")", ")", "$", "this", "->", "syntaxError", "(", "'Value'", ",", "$", "token", ")", ";", "$", "values", "[", "]", "=", "$", "value", ";", "}", "foreach", "(", "$", "values", "as", "$", "k", "=>", "$", "value", ")", "{", "if", "(", "is_object", "(", "$", "value", ")", "&&", "$", "value", "instanceof", "\\", "stdClass", ")", "$", "values", "[", "$", "value", "->", "name", "]", "=", "$", "value", "->", "value", ";", "else", "if", "(", "!", "isset", "(", "$", "values", "[", "'value'", "]", ")", ")", "$", "values", "[", "'value'", "]", "=", "$", "value", ";", "else", "{", "if", "(", "!", "is_array", "(", "$", "values", "[", "'value'", "]", ")", ")", "$", "values", "[", "'value'", "]", "=", "[", "$", "values", "[", "'value'", "]", "]", ";", "$", "values", "[", "'value'", "]", "[", "]", "=", "$", "value", ";", "}", "unset", "(", "$", "values", "[", "$", "k", "]", ")", ";", "}", "return", "$", "values", ";", "}" ]
Values ::= Array | Value {"," Value}* [","] @return array
[ "Values", "::", "=", "Array", "|", "Value", "{", "Value", "}", "*", "[", "]" ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Annotations/DocParser.php#L702-L740
PenoaksDev/Milky-Framework
src/Milky/Annotations/DocParser.php
DocParser.ArrayEntry
private function ArrayEntry() { $peek = $this->lexer->glimpse(); if ( DocLexer::T_EQUALS === $peek['type'] || DocLexer::T_COLON === $peek['type'] ) { if ( $this->lexer->isNextToken( DocLexer::T_IDENTIFIER ) ) $key = $this->Constant(); else { $this->matchAny( [DocLexer::T_INTEGER, DocLexer::T_STRING] ); $key = $this->lexer->token['value']; } $this->matchAny( [DocLexer::T_EQUALS, DocLexer::T_COLON] ); return [$key, $this->PlainValue()]; } return [null, $this->Value()]; }
php
private function ArrayEntry() { $peek = $this->lexer->glimpse(); if ( DocLexer::T_EQUALS === $peek['type'] || DocLexer::T_COLON === $peek['type'] ) { if ( $this->lexer->isNextToken( DocLexer::T_IDENTIFIER ) ) $key = $this->Constant(); else { $this->matchAny( [DocLexer::T_INTEGER, DocLexer::T_STRING] ); $key = $this->lexer->token['value']; } $this->matchAny( [DocLexer::T_EQUALS, DocLexer::T_COLON] ); return [$key, $this->PlainValue()]; } return [null, $this->Value()]; }
[ "private", "function", "ArrayEntry", "(", ")", "{", "$", "peek", "=", "$", "this", "->", "lexer", "->", "glimpse", "(", ")", ";", "if", "(", "DocLexer", "::", "T_EQUALS", "===", "$", "peek", "[", "'type'", "]", "||", "DocLexer", "::", "T_COLON", "===", "$", "peek", "[", "'type'", "]", ")", "{", "if", "(", "$", "this", "->", "lexer", "->", "isNextToken", "(", "DocLexer", "::", "T_IDENTIFIER", ")", ")", "$", "key", "=", "$", "this", "->", "Constant", "(", ")", ";", "else", "{", "$", "this", "->", "matchAny", "(", "[", "DocLexer", "::", "T_INTEGER", ",", "DocLexer", "::", "T_STRING", "]", ")", ";", "$", "key", "=", "$", "this", "->", "lexer", "->", "token", "[", "'value'", "]", ";", "}", "$", "this", "->", "matchAny", "(", "[", "DocLexer", "::", "T_EQUALS", ",", "DocLexer", "::", "T_COLON", "]", ")", ";", "return", "[", "$", "key", ",", "$", "this", "->", "PlainValue", "(", ")", "]", ";", "}", "return", "[", "null", ",", "$", "this", "->", "Value", "(", ")", "]", ";", "}" ]
ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant @return array
[ "ArrayEntry", "::", "=", "Value", "|", "KeyValuePair", "KeyValuePair", "::", "=", "Key", "(", "=", "|", ":", ")", "PlainValue", "|", "Constant", "Key", "::", "=", "string", "|", "integer", "|", "Constant" ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Annotations/DocParser.php#L965-L985
nguyenanhung/my-debug
src/Debug.php
Debug.setGlobalLoggerLevel
public function setGlobalLoggerLevel($globalLoggerLevel = NULL) { if (!empty($globalLoggerLevel) && is_string($globalLoggerLevel)) { $this->globalLoggerLevel = strtolower($globalLoggerLevel); } return $this; }
php
public function setGlobalLoggerLevel($globalLoggerLevel = NULL) { if (!empty($globalLoggerLevel) && is_string($globalLoggerLevel)) { $this->globalLoggerLevel = strtolower($globalLoggerLevel); } return $this; }
[ "public", "function", "setGlobalLoggerLevel", "(", "$", "globalLoggerLevel", "=", "NULL", ")", "{", "if", "(", "!", "empty", "(", "$", "globalLoggerLevel", ")", "&&", "is_string", "(", "$", "globalLoggerLevel", ")", ")", "{", "$", "this", "->", "globalLoggerLevel", "=", "strtolower", "(", "$", "globalLoggerLevel", ")", ";", "}", "return", "$", "this", ";", "}" ]
Hàm cấu hình level Debug @author: 713uk13m <[email protected]> @time : 10/17/18 09:53 @param null|string $globalLoggerLevel Level Debug được cấu hình theo chuẩn RFC 5424 @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels @see https://tools.ietf.org/html/rfc5424 @return $this
[ "Hàm", "cấu", "hình", "level", "Debug" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Debug.php#L108-L115
nguyenanhung/my-debug
src/Debug.php
Debug.setLoggerFilename
public function setLoggerFilename($loggerFilename = '') { if (!empty($loggerFilename)) { $this->loggerFilename = trim($loggerFilename); } else { $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } return $this; }
php
public function setLoggerFilename($loggerFilename = '') { if (!empty($loggerFilename)) { $this->loggerFilename = trim($loggerFilename); } else { $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } return $this; }
[ "public", "function", "setLoggerFilename", "(", "$", "loggerFilename", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "loggerFilename", ")", ")", "{", "$", "this", "->", "loggerFilename", "=", "trim", "(", "$", "loggerFilename", ")", ";", "}", "else", "{", "$", "this", "->", "loggerFilename", "=", "'Log-'", ".", "date", "(", "'Y-m-d'", ")", ".", "'.log'", ";", "}", "return", "$", "this", ";", "}" ]
Hàm cấu hình file lưu trữ Log @author: 713uk13m <[email protected]> @time : 10/17/18 09:57 @param string $loggerFilename Filename cần lưu log, VD: app.log, Log-2018-10-17.log @return $this
[ "Hàm", "cấu", "hình", "file", "lưu", "trữ", "Log" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Debug.php#L204-L213
nguyenanhung/my-debug
src/Debug.php
Debug.setLoggerDateFormat
public function setLoggerDateFormat($loggerDateFormat = NULL) { if (!empty($loggerDateFormat) && is_string($loggerDateFormat)) { $this->loggerDateFormat = $loggerDateFormat; } else { $this->loggerDateFormat = "Y-m-d H:i:s u"; } return $this; }
php
public function setLoggerDateFormat($loggerDateFormat = NULL) { if (!empty($loggerDateFormat) && is_string($loggerDateFormat)) { $this->loggerDateFormat = $loggerDateFormat; } else { $this->loggerDateFormat = "Y-m-d H:i:s u"; } return $this; }
[ "public", "function", "setLoggerDateFormat", "(", "$", "loggerDateFormat", "=", "NULL", ")", "{", "if", "(", "!", "empty", "(", "$", "loggerDateFormat", ")", "&&", "is_string", "(", "$", "loggerDateFormat", ")", ")", "{", "$", "this", "->", "loggerDateFormat", "=", "$", "loggerDateFormat", ";", "}", "else", "{", "$", "this", "->", "loggerDateFormat", "=", "\"Y-m-d H:i:s u\"", ";", "}", "return", "$", "this", ";", "}" ]
Hàm quy định Date Format cho file Log @author: 713uk13m <[email protected]> @time : 10/17/18 09:59 @param null $loggerDateFormat Logger Date Format, VD: Y-m-d H:i:s u @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php @return $this
[ "Hàm", "quy", "định", "Date", "Format", "cho", "file", "Log" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Debug.php#L240-L249
nguyenanhung/my-debug
src/Debug.php
Debug.setLoggerLineFormat
public function setLoggerLineFormat($loggerLineFormat = NULL) { if (!empty($loggerLineFormat) && is_string($loggerLineFormat)) { $this->loggerLineFormat = $loggerLineFormat; } else { $this->loggerLineFormat = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; } return $this; }
php
public function setLoggerLineFormat($loggerLineFormat = NULL) { if (!empty($loggerLineFormat) && is_string($loggerLineFormat)) { $this->loggerLineFormat = $loggerLineFormat; } else { $this->loggerLineFormat = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; } return $this; }
[ "public", "function", "setLoggerLineFormat", "(", "$", "loggerLineFormat", "=", "NULL", ")", "{", "if", "(", "!", "empty", "(", "$", "loggerLineFormat", ")", "&&", "is_string", "(", "$", "loggerLineFormat", ")", ")", "{", "$", "this", "->", "loggerLineFormat", "=", "$", "loggerLineFormat", ";", "}", "else", "{", "$", "this", "->", "loggerLineFormat", "=", "\"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\\n\"", ";", "}", "return", "$", "this", ";", "}" ]
Hàm cấu hình thông tin về format dòng ghi log @author: 713uk13m <[email protected]> @time : 10/17/18 10:00 @param null $loggerLineFormat Line Format Input, example: [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php @return $this
[ "Hàm", "cấu", "hình", "thông", "tin", "về", "format", "dòng", "ghi", "log" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Debug.php#L277-L286
nguyenanhung/my-debug
src/Debug.php
Debug.log
public function log($level = '', $name = 'log', $msg = 'My Message', $context = []) { $level = strtolower(trim($level)); if ($this->DEBUG == TRUE) { if (!class_exists('\Monolog\Logger')) { if (function_exists('log_message')) { $errorMsg = 'Không tồn tại class Monolog'; log_message('error', $errorMsg); } return FALSE; } try { $loggerSubPath = trim($this->loggerSubPath); $loggerSubPath = !empty($loggerSubPath) ? Utils::slugify($loggerSubPath) : 'Default-Sub-Path'; if (empty($this->loggerFilename)) { $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } $listLevel = array('debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'); if ( // Tồn tại Global Logger Level isset($this->globalLoggerLevel) && // Là 1 string is_string($this->globalLoggerLevel) && // Và thuộc list Level được quy định in_array($this->globalLoggerLevel, $listLevel) ) { // If valid globalLoggerLevel -> use globalLoggerLevel $useLevel = strtolower($this->globalLoggerLevel); } else { $useLevel = in_array($level, $listLevel) ? trim($level) : trim('info'); } switch ($useLevel) { case 'debug': $keyLevel = \Monolog\Logger::DEBUG; break; case 'info': $keyLevel = \Monolog\Logger::INFO; break; case 'notice': $keyLevel = \Monolog\Logger::NOTICE; break; case 'warning': $keyLevel = \Monolog\Logger::WARNING; break; case 'error': $keyLevel = \Monolog\Logger::ERROR; break; case 'critical': $keyLevel = \Monolog\Logger::CRITICAL; break; case 'alert': $keyLevel = \Monolog\Logger::ALERT; break; case 'emergency': $keyLevel = \Monolog\Logger::EMERGENCY; break; default: $keyLevel = \Monolog\Logger::WARNING; } $loggerFilename = $this->loggerPath . DIRECTORY_SEPARATOR . $loggerSubPath . DIRECTORY_SEPARATOR . $this->loggerFilename; $dateFormat = !empty($this->loggerDateFormat) ? $this->loggerDateFormat : "Y-m-d H:i:s u"; $output = !empty($this->loggerLineFormat) ? $this->loggerLineFormat : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; $formatter = new \Monolog\Formatter\LineFormatter($output, $dateFormat); $stream = new \Monolog\Handler\StreamHandler($loggerFilename, $keyLevel, self::LOG_BUBBLE, self::FILE_PERMISSION); $stream->setFormatter($formatter); $logger = new \Monolog\Logger(trim($name)); $logger->pushHandler($stream); if (empty($msg)) { $msg = 'My Log Message is Empty'; } if (is_array($context)) { return $logger->$level($msg, $context); } else { return $logger->$level($msg . json_encode($context)); } } catch (\Exception $e) { if (function_exists('log_message')) { $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(); log_message('error', $message); } return FALSE; } } return NULL; }
php
public function log($level = '', $name = 'log', $msg = 'My Message', $context = []) { $level = strtolower(trim($level)); if ($this->DEBUG == TRUE) { if (!class_exists('\Monolog\Logger')) { if (function_exists('log_message')) { $errorMsg = 'Không tồn tại class Monolog'; log_message('error', $errorMsg); } return FALSE; } try { $loggerSubPath = trim($this->loggerSubPath); $loggerSubPath = !empty($loggerSubPath) ? Utils::slugify($loggerSubPath) : 'Default-Sub-Path'; if (empty($this->loggerFilename)) { $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } $listLevel = array('debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'); if ( // Tồn tại Global Logger Level isset($this->globalLoggerLevel) && // Là 1 string is_string($this->globalLoggerLevel) && // Và thuộc list Level được quy định in_array($this->globalLoggerLevel, $listLevel) ) { // If valid globalLoggerLevel -> use globalLoggerLevel $useLevel = strtolower($this->globalLoggerLevel); } else { $useLevel = in_array($level, $listLevel) ? trim($level) : trim('info'); } switch ($useLevel) { case 'debug': $keyLevel = \Monolog\Logger::DEBUG; break; case 'info': $keyLevel = \Monolog\Logger::INFO; break; case 'notice': $keyLevel = \Monolog\Logger::NOTICE; break; case 'warning': $keyLevel = \Monolog\Logger::WARNING; break; case 'error': $keyLevel = \Monolog\Logger::ERROR; break; case 'critical': $keyLevel = \Monolog\Logger::CRITICAL; break; case 'alert': $keyLevel = \Monolog\Logger::ALERT; break; case 'emergency': $keyLevel = \Monolog\Logger::EMERGENCY; break; default: $keyLevel = \Monolog\Logger::WARNING; } $loggerFilename = $this->loggerPath . DIRECTORY_SEPARATOR . $loggerSubPath . DIRECTORY_SEPARATOR . $this->loggerFilename; $dateFormat = !empty($this->loggerDateFormat) ? $this->loggerDateFormat : "Y-m-d H:i:s u"; $output = !empty($this->loggerLineFormat) ? $this->loggerLineFormat : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; $formatter = new \Monolog\Formatter\LineFormatter($output, $dateFormat); $stream = new \Monolog\Handler\StreamHandler($loggerFilename, $keyLevel, self::LOG_BUBBLE, self::FILE_PERMISSION); $stream->setFormatter($formatter); $logger = new \Monolog\Logger(trim($name)); $logger->pushHandler($stream); if (empty($msg)) { $msg = 'My Log Message is Empty'; } if (is_array($context)) { return $logger->$level($msg, $context); } else { return $logger->$level($msg . json_encode($context)); } } catch (\Exception $e) { if (function_exists('log_message')) { $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(); log_message('error', $message); } return FALSE; } } return NULL; }
[ "public", "function", "log", "(", "$", "level", "=", "''", ",", "$", "name", "=", "'log'", ",", "$", "msg", "=", "'My Message'", ",", "$", "context", "=", "[", "]", ")", "{", "$", "level", "=", "strtolower", "(", "trim", "(", "$", "level", ")", ")", ";", "if", "(", "$", "this", "->", "DEBUG", "==", "TRUE", ")", "{", "if", "(", "!", "class_exists", "(", "'\\Monolog\\Logger'", ")", ")", "{", "if", "(", "function_exists", "(", "'log_message'", ")", ")", "{", "$", "errorMsg", "=", "'Không tồn tại class Monolog';", "", "log_message", "(", "'error'", ",", "$", "errorMsg", ")", ";", "}", "return", "FALSE", ";", "}", "try", "{", "$", "loggerSubPath", "=", "trim", "(", "$", "this", "->", "loggerSubPath", ")", ";", "$", "loggerSubPath", "=", "!", "empty", "(", "$", "loggerSubPath", ")", "?", "Utils", "::", "slugify", "(", "$", "loggerSubPath", ")", ":", "'Default-Sub-Path'", ";", "if", "(", "empty", "(", "$", "this", "->", "loggerFilename", ")", ")", "{", "$", "this", "->", "loggerFilename", "=", "'Log-'", ".", "date", "(", "'Y-m-d'", ")", ".", "'.log'", ";", "}", "$", "listLevel", "=", "array", "(", "'debug'", ",", "'info'", ",", "'notice'", ",", "'warning'", ",", "'error'", ",", "'critical'", ",", "'alert'", ",", "'emergency'", ")", ";", "if", "(", "// Tồn tại Global Logger Level", "isset", "(", "$", "this", "->", "globalLoggerLevel", ")", "&&", "// Là 1 string", "is_string", "(", "$", "this", "->", "globalLoggerLevel", ")", "&&", "// Và thuộc list Level được quy định", "in_array", "(", "$", "this", "->", "globalLoggerLevel", ",", "$", "listLevel", ")", ")", "{", "// If valid globalLoggerLevel -> use globalLoggerLevel", "$", "useLevel", "=", "strtolower", "(", "$", "this", "->", "globalLoggerLevel", ")", ";", "}", "else", "{", "$", "useLevel", "=", "in_array", "(", "$", "level", ",", "$", "listLevel", ")", "?", "trim", "(", "$", "level", ")", ":", "trim", "(", "'info'", ")", ";", "}", "switch", "(", "$", "useLevel", ")", "{", "case", "'debug'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "DEBUG", ";", "break", ";", "case", "'info'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "INFO", ";", "break", ";", "case", "'notice'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "NOTICE", ";", "break", ";", "case", "'warning'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "WARNING", ";", "break", ";", "case", "'error'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "ERROR", ";", "break", ";", "case", "'critical'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "CRITICAL", ";", "break", ";", "case", "'alert'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "ALERT", ";", "break", ";", "case", "'emergency'", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "EMERGENCY", ";", "break", ";", "default", ":", "$", "keyLevel", "=", "\\", "Monolog", "\\", "Logger", "::", "WARNING", ";", "}", "$", "loggerFilename", "=", "$", "this", "->", "loggerPath", ".", "DIRECTORY_SEPARATOR", ".", "$", "loggerSubPath", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "loggerFilename", ";", "$", "dateFormat", "=", "!", "empty", "(", "$", "this", "->", "loggerDateFormat", ")", "?", "$", "this", "->", "loggerDateFormat", ":", "\"Y-m-d H:i:s u\"", ";", "$", "output", "=", "!", "empty", "(", "$", "this", "->", "loggerLineFormat", ")", "?", "$", "this", "->", "loggerLineFormat", ":", "\"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\\n\"", ";", "$", "formatter", "=", "new", "\\", "Monolog", "\\", "Formatter", "\\", "LineFormatter", "(", "$", "output", ",", "$", "dateFormat", ")", ";", "$", "stream", "=", "new", "\\", "Monolog", "\\", "Handler", "\\", "StreamHandler", "(", "$", "loggerFilename", ",", "$", "keyLevel", ",", "self", "::", "LOG_BUBBLE", ",", "self", "::", "FILE_PERMISSION", ")", ";", "$", "stream", "->", "setFormatter", "(", "$", "formatter", ")", ";", "$", "logger", "=", "new", "\\", "Monolog", "\\", "Logger", "(", "trim", "(", "$", "name", ")", ")", ";", "$", "logger", "->", "pushHandler", "(", "$", "stream", ")", ";", "if", "(", "empty", "(", "$", "msg", ")", ")", "{", "$", "msg", "=", "'My Log Message is Empty'", ";", "}", "if", "(", "is_array", "(", "$", "context", ")", ")", "{", "return", "$", "logger", "->", "$", "level", "(", "$", "msg", ",", "$", "context", ")", ";", "}", "else", "{", "return", "$", "logger", "->", "$", "level", "(", "$", "msg", ".", "json_encode", "(", "$", "context", ")", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "function_exists", "(", "'log_message'", ")", ")", "{", "$", "message", "=", "'Error File: '", ".", "$", "e", "->", "getFile", "(", ")", ".", "' - Line: '", ".", "$", "e", "->", "getLine", "(", ")", ".", "' - Code: '", ".", "$", "e", "->", "getCode", "(", ")", ".", "' - Message: '", ".", "$", "e", "->", "getMessage", "(", ")", ";", "log_message", "(", "'error'", ",", "$", "message", ")", ";", "}", "return", "FALSE", ";", "}", "}", "return", "NULL", ";", "}" ]
Hàm ghi log cho hệ thống @author : 713uk13m <[email protected]> @time : 10/6/18 23:35 @param string $level Level Debug: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY @param string $name Log Name: log, etc... @param string $msg Log Message write to Log @param array $context Log Context aka Log Message Array format @example log('info', 'test', 'Log Test', []) @return mixed TRUE nếu ghi log thành công, FALSE nếu ghi log thất bại, Message Error nếu có lỗi Exception xảy ra, ngoài ra các trường hợp khác sẽ trả về mã Null
[ "Hàm", "ghi", "log", "cho", "hệ", "thống" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Debug.php#L304-L392
ddvphp/ddv-exception
src/DdvException/Handler.php
Handler.errorHandler
public static function errorHandler($errorCode, $message, $errfile, $errline, $errcontext){ $isError = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errorCode) === $errorCode); $r = array(); $r['errorCode'] =$errorCode; $r['statusCode'] =500; $r['errorId'] ='UNKNOWN_ERROR'; $r['message'] = $message; $r['isIgnoreError'] = (($errorCode & error_reporting()) !== $errorCode); $r['responseData'] = array(); $e = new \Exception($message, $errorCode); //调试模式 if (self::isDevelopment()) { $r['debug'] = array(); $r['debug']['type'] = 'Error'; $r['debug']['line'] = $errline; $r['debug']['file'] = $errfile; $r['debug']['trace'] = ''; $r['debug']['isError'] = $isError; $r['debug']['isIgnoreError'] = $r['isIgnoreError']; $r['debug']['trace'] = $e->getTraceAsString(); $r['debug']['trace'] = explode("\n", $r['debug']['trace']); if (count($r['debug']['trace'])>0) { $r['debug']['trace'] = array_splice($r['debug']['trace'],2); } } self::emitHandler($r, $e); }
php
public static function errorHandler($errorCode, $message, $errfile, $errline, $errcontext){ $isError = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errorCode) === $errorCode); $r = array(); $r['errorCode'] =$errorCode; $r['statusCode'] =500; $r['errorId'] ='UNKNOWN_ERROR'; $r['message'] = $message; $r['isIgnoreError'] = (($errorCode & error_reporting()) !== $errorCode); $r['responseData'] = array(); $e = new \Exception($message, $errorCode); //调试模式 if (self::isDevelopment()) { $r['debug'] = array(); $r['debug']['type'] = 'Error'; $r['debug']['line'] = $errline; $r['debug']['file'] = $errfile; $r['debug']['trace'] = ''; $r['debug']['isError'] = $isError; $r['debug']['isIgnoreError'] = $r['isIgnoreError']; $r['debug']['trace'] = $e->getTraceAsString(); $r['debug']['trace'] = explode("\n", $r['debug']['trace']); if (count($r['debug']['trace'])>0) { $r['debug']['trace'] = array_splice($r['debug']['trace'],2); } } self::emitHandler($r, $e); }
[ "public", "static", "function", "errorHandler", "(", "$", "errorCode", ",", "$", "message", ",", "$", "errfile", ",", "$", "errline", ",", "$", "errcontext", ")", "{", "$", "isError", "=", "(", "(", "(", "E_ERROR", "|", "E_PARSE", "|", "E_COMPILE_ERROR", "|", "E_CORE_ERROR", "|", "E_USER_ERROR", ")", "&", "$", "errorCode", ")", "===", "$", "errorCode", ")", ";", "$", "r", "=", "array", "(", ")", ";", "$", "r", "[", "'errorCode'", "]", "=", "$", "errorCode", ";", "$", "r", "[", "'statusCode'", "]", "=", "500", ";", "$", "r", "[", "'errorId'", "]", "=", "'UNKNOWN_ERROR'", ";", "$", "r", "[", "'message'", "]", "=", "$", "message", ";", "$", "r", "[", "'isIgnoreError'", "]", "=", "(", "(", "$", "errorCode", "&", "error_reporting", "(", ")", ")", "!==", "$", "errorCode", ")", ";", "$", "r", "[", "'responseData'", "]", "=", "array", "(", ")", ";", "$", "e", "=", "new", "\\", "Exception", "(", "$", "message", ",", "$", "errorCode", ")", ";", "//调试模式", "if", "(", "self", "::", "isDevelopment", "(", ")", ")", "{", "$", "r", "[", "'debug'", "]", "=", "array", "(", ")", ";", "$", "r", "[", "'debug'", "]", "[", "'type'", "]", "=", "'Error'", ";", "$", "r", "[", "'debug'", "]", "[", "'line'", "]", "=", "$", "errline", ";", "$", "r", "[", "'debug'", "]", "[", "'file'", "]", "=", "$", "errfile", ";", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", "=", "''", ";", "$", "r", "[", "'debug'", "]", "[", "'isError'", "]", "=", "$", "isError", ";", "$", "r", "[", "'debug'", "]", "[", "'isIgnoreError'", "]", "=", "$", "r", "[", "'isIgnoreError'", "]", ";", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", "=", "$", "e", "->", "getTraceAsString", "(", ")", ";", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", "=", "explode", "(", "\"\\n\"", ",", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", ")", ";", "if", "(", "count", "(", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", ")", ">", "0", ")", "{", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", "=", "array_splice", "(", "$", "r", "[", "'debug'", "]", "[", "'trace'", "]", ",", "2", ")", ";", "}", "}", "self", "::", "emitHandler", "(", "$", "r", ",", "$", "e", ")", ";", "}" ]
用户定义的错误处理函数
[ "用户定义的错误处理函数" ]
train
https://github.com/ddvphp/ddv-exception/blob/4f1830dca40ea8ef99e721f043ade30c680ec2c5/src/DdvException/Handler.php#L122-L148
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.wherePivotIn
public function wherePivotIn($column, $values, $boolean = 'and', $not = false) { $this->pivotWheres[] = func_get_args(); return $this->whereIn($this->table.'.'.$column, $values, $boolean, $not); }
php
public function wherePivotIn($column, $values, $boolean = 'and', $not = false) { $this->pivotWheres[] = func_get_args(); return $this->whereIn($this->table.'.'.$column, $values, $boolean, $not); }
[ "public", "function", "wherePivotIn", "(", "$", "column", ",", "$", "values", ",", "$", "boolean", "=", "'and'", ",", "$", "not", "=", "false", ")", "{", "$", "this", "->", "pivotWheres", "[", "]", "=", "func_get_args", "(", ")", ";", "return", "$", "this", "->", "whereIn", "(", "$", "this", "->", "table", ".", "'.'", ".", "$", "column", ",", "$", "values", ",", "$", "boolean", ",", "$", "not", ")", ";", "}" ]
Set a "where in" clause for a pivot table column. @param string $column @param mixed $values @param string $boolean @param bool $not @return BelongsToMany
[ "Set", "a", "where", "in", "clause", "for", "a", "pivot", "table", "column", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L131-L136
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.chunk
public function chunk($count, callable $callback) { $this->query->addSelect($this->getSelectColumns()); return $this->query->chunk($count, function ($results) use ($callback) { $this->hydratePivotRelation($results->all()); return $callback($results); }); }
php
public function chunk($count, callable $callback) { $this->query->addSelect($this->getSelectColumns()); return $this->query->chunk($count, function ($results) use ($callback) { $this->hydratePivotRelation($results->all()); return $callback($results); }); }
[ "public", "function", "chunk", "(", "$", "count", ",", "callable", "$", "callback", ")", "{", "$", "this", "->", "query", "->", "addSelect", "(", "$", "this", "->", "getSelectColumns", "(", ")", ")", ";", "return", "$", "this", "->", "query", "->", "chunk", "(", "$", "count", ",", "function", "(", "$", "results", ")", "use", "(", "$", "callback", ")", "{", "$", "this", "->", "hydratePivotRelation", "(", "$", "results", "->", "all", "(", ")", ")", ";", "return", "$", "callback", "(", "$", "results", ")", ";", "}", ")", ";", "}" ]
Chunk the results of the query. @param int $count @param callable $callback @return bool
[ "Chunk", "the", "results", "of", "the", "query", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L270-L279
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.getRelationQuery
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*']) { if ($parent->getQuery()->from == $query->getQuery()->from) { return $this->getRelationQueryForSelfJoin($query, $parent, $columns); } $this->setJoin($query); return parent::getRelationQuery($query, $parent, $columns); }
php
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*']) { if ($parent->getQuery()->from == $query->getQuery()->from) { return $this->getRelationQueryForSelfJoin($query, $parent, $columns); } $this->setJoin($query); return parent::getRelationQuery($query, $parent, $columns); }
[ "public", "function", "getRelationQuery", "(", "Builder", "$", "query", ",", "Builder", "$", "parent", ",", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "$", "parent", "->", "getQuery", "(", ")", "->", "from", "==", "$", "query", "->", "getQuery", "(", ")", "->", "from", ")", "{", "return", "$", "this", "->", "getRelationQueryForSelfJoin", "(", "$", "query", ",", "$", "parent", ",", "$", "columns", ")", ";", "}", "$", "this", "->", "setJoin", "(", "$", "query", ")", ";", "return", "parent", "::", "getRelationQuery", "(", "$", "query", ",", "$", "parent", ",", "$", "columns", ")", ";", "}" ]
Add the constraints for a relationship query. @param Builder $query @param Builder $parent @param array|mixed $columns @return Builder
[ "Add", "the", "constraints", "for", "a", "relationship", "query", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L345-L354
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.getRelationQueryForSelfJoin
public function getRelationQueryForSelfJoin(Builder $query, Builder $parent, $columns = ['*']) { $query->select($columns); $query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash()); $this->related->setTable($hash); $this->setJoin($query); return parent::getRelationQuery($query, $parent, $columns); }
php
public function getRelationQueryForSelfJoin(Builder $query, Builder $parent, $columns = ['*']) { $query->select($columns); $query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash()); $this->related->setTable($hash); $this->setJoin($query); return parent::getRelationQuery($query, $parent, $columns); }
[ "public", "function", "getRelationQueryForSelfJoin", "(", "Builder", "$", "query", ",", "Builder", "$", "parent", ",", "$", "columns", "=", "[", "'*'", "]", ")", "{", "$", "query", "->", "select", "(", "$", "columns", ")", ";", "$", "query", "->", "from", "(", "$", "this", "->", "related", "->", "getTable", "(", ")", ".", "' as '", ".", "$", "hash", "=", "$", "this", "->", "getRelationCountHash", "(", ")", ")", ";", "$", "this", "->", "related", "->", "setTable", "(", "$", "hash", ")", ";", "$", "this", "->", "setJoin", "(", "$", "query", ")", ";", "return", "parent", "::", "getRelationQuery", "(", "$", "query", ",", "$", "parent", ",", "$", "columns", ")", ";", "}" ]
Add the constraints for a relationship query on the same table. @param Builder $query @param Builder $parent @param array|mixed $columns @return Builder
[ "Add", "the", "constraints", "for", "a", "relationship", "query", "on", "the", "same", "table", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L364-L375
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.getSelectColumns
protected function getSelectColumns(array $columns = ['*']) { if ($columns == ['*']) { $columns = [$this->related->getTable().'.*']; } return array_merge($columns, $this->getAliasedPivotColumns()); }
php
protected function getSelectColumns(array $columns = ['*']) { if ($columns == ['*']) { $columns = [$this->related->getTable().'.*']; } return array_merge($columns, $this->getAliasedPivotColumns()); }
[ "protected", "function", "getSelectColumns", "(", "array", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "$", "columns", "==", "[", "'*'", "]", ")", "{", "$", "columns", "=", "[", "$", "this", "->", "related", "->", "getTable", "(", ")", ".", "'.*'", "]", ";", "}", "return", "array_merge", "(", "$", "columns", ",", "$", "this", "->", "getAliasedPivotColumns", "(", ")", ")", ";", "}" ]
Set the select clause for the relation query. @param array $columns @return BelongsToMany
[ "Set", "the", "select", "clause", "for", "the", "relation", "query", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L393-L400
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.findOrNew
public function findOrNew($id, $columns = ['*']) { if (is_null($instance = $this->find($id, $columns))) { $instance = $this->getRelated()->newInstance(); } return $instance; }
php
public function findOrNew($id, $columns = ['*']) { if (is_null($instance = $this->find($id, $columns))) { $instance = $this->getRelated()->newInstance(); } return $instance; }
[ "public", "function", "findOrNew", "(", "$", "id", ",", "$", "columns", "=", "[", "'*'", "]", ")", "{", "if", "(", "is_null", "(", "$", "instance", "=", "$", "this", "->", "find", "(", "$", "id", ",", "$", "columns", ")", ")", ")", "{", "$", "instance", "=", "$", "this", "->", "getRelated", "(", ")", "->", "newInstance", "(", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Find a related model by its primary key or return new instance of the related model. @param mixed $id @param array $columns @return Model
[ "Find", "a", "related", "model", "by", "its", "primary", "key", "or", "return", "new", "instance", "of", "the", "related", "model", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L684-L691
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.attachNew
protected function attachNew(array $records, array $current, $touch = true) { $changes = ['attached' => [], 'updated' => []]; foreach ($records as $id => $attributes) { // If the ID is not in the list of existing pivot IDs, we will insert a new pivot // record, otherwise, we will just update this existing record on this joining // table, so that the developers will easily update these records pain free. if (! in_array($id, $current)) { $this->attach($id, $attributes, $touch); $changes['attached'][] = is_numeric($id) ? (int) $id : (string) $id; } // Now we'll try to update an existing pivot record with the attributes that were // given to the method. If the model is actually updated we will add it to the // list of updated pivot records so we return them back out to the consumer. elseif (count($attributes) > 0 && $this->updateExistingPivot($id, $attributes, $touch)) { $changes['updated'][] = is_numeric($id) ? (int) $id : (string) $id; } } return $changes; }
php
protected function attachNew(array $records, array $current, $touch = true) { $changes = ['attached' => [], 'updated' => []]; foreach ($records as $id => $attributes) { // If the ID is not in the list of existing pivot IDs, we will insert a new pivot // record, otherwise, we will just update this existing record on this joining // table, so that the developers will easily update these records pain free. if (! in_array($id, $current)) { $this->attach($id, $attributes, $touch); $changes['attached'][] = is_numeric($id) ? (int) $id : (string) $id; } // Now we'll try to update an existing pivot record with the attributes that were // given to the method. If the model is actually updated we will add it to the // list of updated pivot records so we return them back out to the consumer. elseif (count($attributes) > 0 && $this->updateExistingPivot($id, $attributes, $touch)) { $changes['updated'][] = is_numeric($id) ? (int) $id : (string) $id; } } return $changes; }
[ "protected", "function", "attachNew", "(", "array", "$", "records", ",", "array", "$", "current", ",", "$", "touch", "=", "true", ")", "{", "$", "changes", "=", "[", "'attached'", "=>", "[", "]", ",", "'updated'", "=>", "[", "]", "]", ";", "foreach", "(", "$", "records", "as", "$", "id", "=>", "$", "attributes", ")", "{", "// If the ID is not in the list of existing pivot IDs, we will insert a new pivot", "// record, otherwise, we will just update this existing record on this joining", "// table, so that the developers will easily update these records pain free.", "if", "(", "!", "in_array", "(", "$", "id", ",", "$", "current", ")", ")", "{", "$", "this", "->", "attach", "(", "$", "id", ",", "$", "attributes", ",", "$", "touch", ")", ";", "$", "changes", "[", "'attached'", "]", "[", "]", "=", "is_numeric", "(", "$", "id", ")", "?", "(", "int", ")", "$", "id", ":", "(", "string", ")", "$", "id", ";", "}", "// Now we'll try to update an existing pivot record with the attributes that were", "// given to the method. If the model is actually updated we will add it to the", "// list of updated pivot records so we return them back out to the consumer.", "elseif", "(", "count", "(", "$", "attributes", ")", ">", "0", "&&", "$", "this", "->", "updateExistingPivot", "(", "$", "id", ",", "$", "attributes", ",", "$", "touch", ")", ")", "{", "$", "changes", "[", "'updated'", "]", "[", "]", "=", "is_numeric", "(", "$", "id", ")", "?", "(", "int", ")", "$", "id", ":", "(", "string", ")", "$", "id", ";", "}", "}", "return", "$", "changes", ";", "}" ]
Attach all of the IDs that aren't in the current array. @param array $records @param array $current @param bool $touch @return array
[ "Attach", "all", "of", "the", "IDs", "that", "aren", "t", "in", "the", "current", "array", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L869-L893
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.updateExistingPivot
public function updateExistingPivot($id, array $attributes, $touch = true) { if (in_array($this->updatedAt(), $this->pivotColumns)) { $attributes = $this->setTimestampsOnAttach($attributes, true); } $updated = $this->newPivotStatementForId($id)->update($attributes); if ($touch) { $this->touchIfTouching(); } return $updated; }
php
public function updateExistingPivot($id, array $attributes, $touch = true) { if (in_array($this->updatedAt(), $this->pivotColumns)) { $attributes = $this->setTimestampsOnAttach($attributes, true); } $updated = $this->newPivotStatementForId($id)->update($attributes); if ($touch) { $this->touchIfTouching(); } return $updated; }
[ "public", "function", "updateExistingPivot", "(", "$", "id", ",", "array", "$", "attributes", ",", "$", "touch", "=", "true", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "updatedAt", "(", ")", ",", "$", "this", "->", "pivotColumns", ")", ")", "{", "$", "attributes", "=", "$", "this", "->", "setTimestampsOnAttach", "(", "$", "attributes", ",", "true", ")", ";", "}", "$", "updated", "=", "$", "this", "->", "newPivotStatementForId", "(", "$", "id", ")", "->", "update", "(", "$", "attributes", ")", ";", "if", "(", "$", "touch", ")", "{", "$", "this", "->", "touchIfTouching", "(", ")", ";", "}", "return", "$", "updated", ";", "}" ]
Update an existing pivot record on the table. @param mixed $id @param array $attributes @param bool $touch @return int
[ "Update", "an", "existing", "pivot", "record", "on", "the", "table", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L903-L916
PenoaksDev/Milky-Framework
src/Milky/Database/Eloquent/Relations/BelongsToMany.php
BelongsToMany.newPivot
public function newPivot(array $attributes = [], $exists = false) { $pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists); return $pivot->setPivotKeys($this->foreignKey, $this->otherKey); }
php
public function newPivot(array $attributes = [], $exists = false) { $pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists); return $pivot->setPivotKeys($this->foreignKey, $this->otherKey); }
[ "public", "function", "newPivot", "(", "array", "$", "attributes", "=", "[", "]", ",", "$", "exists", "=", "false", ")", "{", "$", "pivot", "=", "$", "this", "->", "related", "->", "newPivot", "(", "$", "this", "->", "parent", ",", "$", "attributes", ",", "$", "this", "->", "table", ",", "$", "exists", ")", ";", "return", "$", "pivot", "->", "setPivotKeys", "(", "$", "this", "->", "foreignKey", ",", "$", "this", "->", "otherKey", ")", ";", "}" ]
Create a new pivot model instance. @param array $attributes @param bool $exists @return Pivot
[ "Create", "a", "new", "pivot", "model", "instance", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/BelongsToMany.php#L1168-L1173
Eden-PHP/Block
Field/Textarea.php
Textarea.setAttributes
public function setAttributes($name, $value = null) { Argument::i() ->test(1, 'string', 'array') ->test(2, 'scalar', 'null'); if(is_array($name)) { $this->attributes = $name; return $this; } $this->attributes[$name] = $value; return $this; }
php
public function setAttributes($name, $value = null) { Argument::i() ->test(1, 'string', 'array') ->test(2, 'scalar', 'null'); if(is_array($name)) { $this->attributes = $name; return $this; } $this->attributes[$name] = $value; return $this; }
[ "public", "function", "setAttributes", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "Argument", "::", "i", "(", ")", "->", "test", "(", "1", ",", "'string'", ",", "'array'", ")", "->", "test", "(", "2", ",", "'scalar'", ",", "'null'", ")", ";", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "this", "->", "attributes", "=", "$", "name", ";", "return", "$", "this", ";", "}", "$", "this", "->", "attributes", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Returns the template variables in key value format @param string|array @param scalar|null @return Eden\Block\Field\Textarea
[ "Returns", "the", "template", "variables", "in", "key", "value", "format" ]
train
https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Field/Textarea.php#L65-L78
ScaraMVC/Framework
src/Scara/Console/Database/Rollback.php
Rollback.configure
protected function configure() { $this->setName('db:rollback') ->setDescription('Rollback migrations') ->addArgument('migration', InputArgument::OPTIONAL, 'The migriation to rollback. Done by class name'); $this->_db = new Database(); $this->_cap = $this->_db->getCapsule(); }
php
protected function configure() { $this->setName('db:rollback') ->setDescription('Rollback migrations') ->addArgument('migration', InputArgument::OPTIONAL, 'The migriation to rollback. Done by class name'); $this->_db = new Database(); $this->_cap = $this->_db->getCapsule(); }
[ "protected", "function", "configure", "(", ")", "{", "$", "this", "->", "setName", "(", "'db:rollback'", ")", "->", "setDescription", "(", "'Rollback migrations'", ")", "->", "addArgument", "(", "'migration'", ",", "InputArgument", "::", "OPTIONAL", ",", "'The migriation to rollback. Done by class name'", ")", ";", "$", "this", "->", "_db", "=", "new", "Database", "(", ")", ";", "$", "this", "->", "_cap", "=", "$", "this", "->", "_db", "->", "getCapsule", "(", ")", ";", "}" ]
Configure Symfony Command. @return void
[ "Configure", "Symfony", "Command", "." ]
train
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Console/Database/Rollback.php#L35-L43
phuria/under-query
src/QueryCompiler/TableCompiler.php
TableCompiler.compileTableDeclaration
public function compileTableDeclaration(AbstractTable $table) { $declaration = ''; if ($table->isJoin()) { $declaration .= $this->compileJoinName($table->getJoinMetadata()) . ' '; } $declaration .= $table->getTableName(); if ($alias = $table->getAlias()) { $declaration .= ' AS ' . $alias; } if ($table->isJoin() && $joinOn = $table->getJoinMetadata()->getJoinOn()) { $declaration .= ' ON ' . $joinOn; } return $declaration; }
php
public function compileTableDeclaration(AbstractTable $table) { $declaration = ''; if ($table->isJoin()) { $declaration .= $this->compileJoinName($table->getJoinMetadata()) . ' '; } $declaration .= $table->getTableName(); if ($alias = $table->getAlias()) { $declaration .= ' AS ' . $alias; } if ($table->isJoin() && $joinOn = $table->getJoinMetadata()->getJoinOn()) { $declaration .= ' ON ' . $joinOn; } return $declaration; }
[ "public", "function", "compileTableDeclaration", "(", "AbstractTable", "$", "table", ")", "{", "$", "declaration", "=", "''", ";", "if", "(", "$", "table", "->", "isJoin", "(", ")", ")", "{", "$", "declaration", ".=", "$", "this", "->", "compileJoinName", "(", "$", "table", "->", "getJoinMetadata", "(", ")", ")", ".", "' '", ";", "}", "$", "declaration", ".=", "$", "table", "->", "getTableName", "(", ")", ";", "if", "(", "$", "alias", "=", "$", "table", "->", "getAlias", "(", ")", ")", "{", "$", "declaration", ".=", "' AS '", ".", "$", "alias", ";", "}", "if", "(", "$", "table", "->", "isJoin", "(", ")", "&&", "$", "joinOn", "=", "$", "table", "->", "getJoinMetadata", "(", ")", "->", "getJoinOn", "(", ")", ")", "{", "$", "declaration", ".=", "' ON '", ".", "$", "joinOn", ";", "}", "return", "$", "declaration", ";", "}" ]
@param AbstractTable $table @return string
[ "@param", "AbstractTable", "$table" ]
train
https://github.com/phuria/under-query/blob/f5e733808c1f109fa73fd95a1fbc5c78fb4b8793/src/QueryCompiler/TableCompiler.php#L51-L70
phuria/under-query
src/QueryCompiler/TableCompiler.php
TableCompiler.compileJoinName
private function compileJoinName(JoinMetadata $metadata) { return implode(' ', array_filter([ $metadata->isNaturalJoin() ? 'NATURAL' : '', $this->compileJoinPrefix($metadata->getJoinType()), $metadata->isOuterJoin() ? 'OUTER' : '', $this->compileJoinSuffix($metadata->getJoinType()) ])); }
php
private function compileJoinName(JoinMetadata $metadata) { return implode(' ', array_filter([ $metadata->isNaturalJoin() ? 'NATURAL' : '', $this->compileJoinPrefix($metadata->getJoinType()), $metadata->isOuterJoin() ? 'OUTER' : '', $this->compileJoinSuffix($metadata->getJoinType()) ])); }
[ "private", "function", "compileJoinName", "(", "JoinMetadata", "$", "metadata", ")", "{", "return", "implode", "(", "' '", ",", "array_filter", "(", "[", "$", "metadata", "->", "isNaturalJoin", "(", ")", "?", "'NATURAL'", ":", "''", ",", "$", "this", "->", "compileJoinPrefix", "(", "$", "metadata", "->", "getJoinType", "(", ")", ")", ",", "$", "metadata", "->", "isOuterJoin", "(", ")", "?", "'OUTER'", ":", "''", ",", "$", "this", "->", "compileJoinSuffix", "(", "$", "metadata", "->", "getJoinType", "(", ")", ")", "]", ")", ")", ";", "}" ]
@param JoinMetadata $metadata @return string
[ "@param", "JoinMetadata", "$metadata" ]
train
https://github.com/phuria/under-query/blob/f5e733808c1f109fa73fd95a1fbc5c78fb4b8793/src/QueryCompiler/TableCompiler.php#L77-L85
phuria/under-query
src/QueryCompiler/TableCompiler.php
TableCompiler.compileJoinPrefix
private function compileJoinPrefix($joinType) { if (array_key_exists($joinType, $this->joinPrefixes)) { return $this->joinPrefixes[$joinType]; } return null; }
php
private function compileJoinPrefix($joinType) { if (array_key_exists($joinType, $this->joinPrefixes)) { return $this->joinPrefixes[$joinType]; } return null; }
[ "private", "function", "compileJoinPrefix", "(", "$", "joinType", ")", "{", "if", "(", "array_key_exists", "(", "$", "joinType", ",", "$", "this", "->", "joinPrefixes", ")", ")", "{", "return", "$", "this", "->", "joinPrefixes", "[", "$", "joinType", "]", ";", "}", "return", "null", ";", "}" ]
@param int $joinType @return string
[ "@param", "int", "$joinType" ]
train
https://github.com/phuria/under-query/blob/f5e733808c1f109fa73fd95a1fbc5c78fb4b8793/src/QueryCompiler/TableCompiler.php#L92-L99
phuria/under-query
src/QueryCompiler/TableCompiler.php
TableCompiler.compileRootTables
public function compileRootTables(CompilerPayload $payload) { $builder = $payload->getBuilder(); $newSQL = ''; if ($builder instanceof AbstractBuilder && $builder->getRootTables()) { $newSQL = implode(', ', array_map([$this, 'compileTableDeclaration'], $builder->getRootTables())); } if ($builder instanceof SelectBuilder || $builder instanceof DeleteBuilder) { $newSQL = $newSQL ? 'FROM ' . $newSQL : ''; } return $payload->appendSQL($newSQL); }
php
public function compileRootTables(CompilerPayload $payload) { $builder = $payload->getBuilder(); $newSQL = ''; if ($builder instanceof AbstractBuilder && $builder->getRootTables()) { $newSQL = implode(', ', array_map([$this, 'compileTableDeclaration'], $builder->getRootTables())); } if ($builder instanceof SelectBuilder || $builder instanceof DeleteBuilder) { $newSQL = $newSQL ? 'FROM ' . $newSQL : ''; } return $payload->appendSQL($newSQL); }
[ "public", "function", "compileRootTables", "(", "CompilerPayload", "$", "payload", ")", "{", "$", "builder", "=", "$", "payload", "->", "getBuilder", "(", ")", ";", "$", "newSQL", "=", "''", ";", "if", "(", "$", "builder", "instanceof", "AbstractBuilder", "&&", "$", "builder", "->", "getRootTables", "(", ")", ")", "{", "$", "newSQL", "=", "implode", "(", "', '", ",", "array_map", "(", "[", "$", "this", ",", "'compileTableDeclaration'", "]", ",", "$", "builder", "->", "getRootTables", "(", ")", ")", ")", ";", "}", "if", "(", "$", "builder", "instanceof", "SelectBuilder", "||", "$", "builder", "instanceof", "DeleteBuilder", ")", "{", "$", "newSQL", "=", "$", "newSQL", "?", "'FROM '", ".", "$", "newSQL", ":", "''", ";", "}", "return", "$", "payload", "->", "appendSQL", "(", "$", "newSQL", ")", ";", "}" ]
@param CompilerPayload $payload @return CompilerPayload
[ "@param", "CompilerPayload", "$payload" ]
train
https://github.com/phuria/under-query/blob/f5e733808c1f109fa73fd95a1fbc5c78fb4b8793/src/QueryCompiler/TableCompiler.php#L116-L130
phuria/under-query
src/QueryCompiler/TableCompiler.php
TableCompiler.compileJoinTables
public function compileJoinTables(CompilerPayload $payload) { $builder = $payload->getBuilder(); if ($builder instanceof Clause\JoinInterface) { $newSQL = implode(' ', array_map([$this, 'compileTableDeclaration'], $builder->getJoinTables())); return $payload->appendSQL($newSQL); } return $payload; }
php
public function compileJoinTables(CompilerPayload $payload) { $builder = $payload->getBuilder(); if ($builder instanceof Clause\JoinInterface) { $newSQL = implode(' ', array_map([$this, 'compileTableDeclaration'], $builder->getJoinTables())); return $payload->appendSQL($newSQL); } return $payload; }
[ "public", "function", "compileJoinTables", "(", "CompilerPayload", "$", "payload", ")", "{", "$", "builder", "=", "$", "payload", "->", "getBuilder", "(", ")", ";", "if", "(", "$", "builder", "instanceof", "Clause", "\\", "JoinInterface", ")", "{", "$", "newSQL", "=", "implode", "(", "' '", ",", "array_map", "(", "[", "$", "this", ",", "'compileTableDeclaration'", "]", ",", "$", "builder", "->", "getJoinTables", "(", ")", ")", ")", ";", "return", "$", "payload", "->", "appendSQL", "(", "$", "newSQL", ")", ";", "}", "return", "$", "payload", ";", "}" ]
@param CompilerPayload $payload @return CompilerPayload
[ "@param", "CompilerPayload", "$payload" ]
train
https://github.com/phuria/under-query/blob/f5e733808c1f109fa73fd95a1fbc5c78fb4b8793/src/QueryCompiler/TableCompiler.php#L137-L147
koolkode/stream
src/Stream.php
Stream.fillBuffer
public static function fillBuffer(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } $buffer = ''; while(!$stream->eof() && strlen($buffer) < $bufferSize) { $buffer .= $stream->read($bufferSize - strlen($buffer)); } return $buffer; }
php
public static function fillBuffer(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } $buffer = ''; while(!$stream->eof() && strlen($buffer) < $bufferSize) { $buffer .= $stream->read($bufferSize - strlen($buffer)); } return $buffer; }
[ "public", "static", "function", "fillBuffer", "(", "StreamInterface", "$", "stream", ",", "$", "bufferSize", "=", "8192", ")", "{", "if", "(", "!", "$", "stream", "->", "isReadable", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Stream is not readable: %s'", ",", "get_class", "(", "$", "stream", ")", ")", ")", ";", "}", "$", "buffer", "=", "''", ";", "while", "(", "!", "$", "stream", "->", "eof", "(", ")", "&&", "strlen", "(", "$", "buffer", ")", "<", "$", "bufferSize", ")", "{", "$", "buffer", ".=", "$", "stream", "->", "read", "(", "$", "bufferSize", "-", "strlen", "(", "$", "buffer", ")", ")", ";", "}", "return", "$", "buffer", ";", "}" ]
Read contents from the given input stream until EOF or the specified buffer is full. @param StreamInterface $stream @param int $bufferSize @return string @throws \InvalidArgumentException When the stream is not readable.
[ "Read", "contents", "from", "the", "given", "input", "stream", "until", "EOF", "or", "the", "specified", "buffer", "is", "full", "." ]
train
https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/Stream.php#L32-L47
koolkode/stream
src/Stream.php
Stream.reader
public static function reader(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } while(!$stream->eof()) { yield $stream->read($bufferSize); } }
php
public static function reader(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } while(!$stream->eof()) { yield $stream->read($bufferSize); } }
[ "public", "static", "function", "reader", "(", "StreamInterface", "$", "stream", ",", "$", "bufferSize", "=", "8192", ")", "{", "if", "(", "!", "$", "stream", "->", "isReadable", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Stream is not readable: %s'", ",", "get_class", "(", "$", "stream", ")", ")", ")", ";", "}", "while", "(", "!", "$", "stream", "->", "eof", "(", ")", ")", "{", "yield", "$", "stream", "->", "read", "(", "$", "bufferSize", ")", ";", "}", "}" ]
Turn a stream into an iterator. @param StreamInterface $stream @param int $bufferSize @return \Iterator @throws \InvalidArgumentException When the stream is not readable.
[ "Turn", "a", "stream", "into", "an", "iterator", "." ]
train
https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/Stream.php#L58-L69
koolkode/stream
src/Stream.php
Stream.bufferedReader
public static function bufferedReader(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } $buffer = ''; while(!$stream->eof()) { $buffer .= $stream->read($bufferSize); while(strlen($buffer) >= $bufferSize) { yield (string)substr($buffer, 0, $bufferSize); $buffer = (string)substr($buffer, $bufferSize); } } if($buffer !== '') { yield $buffer; } }
php
public static function bufferedReader(StreamInterface $stream, $bufferSize = 8192) { if(!$stream->isReadable()) { throw new \InvalidArgumentException(sprintf('Stream is not readable: %s', get_class($stream))); } $buffer = ''; while(!$stream->eof()) { $buffer .= $stream->read($bufferSize); while(strlen($buffer) >= $bufferSize) { yield (string)substr($buffer, 0, $bufferSize); $buffer = (string)substr($buffer, $bufferSize); } } if($buffer !== '') { yield $buffer; } }
[ "public", "static", "function", "bufferedReader", "(", "StreamInterface", "$", "stream", ",", "$", "bufferSize", "=", "8192", ")", "{", "if", "(", "!", "$", "stream", "->", "isReadable", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Stream is not readable: %s'", ",", "get_class", "(", "$", "stream", ")", ")", ")", ";", "}", "$", "buffer", "=", "''", ";", "while", "(", "!", "$", "stream", "->", "eof", "(", ")", ")", "{", "$", "buffer", ".=", "$", "stream", "->", "read", "(", "$", "bufferSize", ")", ";", "while", "(", "strlen", "(", "$", "buffer", ")", ">=", "$", "bufferSize", ")", "{", "yield", "(", "string", ")", "substr", "(", "$", "buffer", ",", "0", ",", "$", "bufferSize", ")", ";", "$", "buffer", "=", "(", "string", ")", "substr", "(", "$", "buffer", ",", "$", "bufferSize", ")", ";", "}", "}", "if", "(", "$", "buffer", "!==", "''", ")", "{", "yield", "$", "buffer", ";", "}", "}" ]
Turn a stream into an iterator returning even-sized results. @param StreamInterface $stream @param int $bufferSize @return \Iterator @throws \InvalidArgumentException When the stream is not readable.
[ "Turn", "a", "stream", "into", "an", "iterator", "returning", "even", "-", "sized", "results", "." ]
train
https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/Stream.php#L80-L105
koolkode/stream
src/Stream.php
Stream.pipe
public static function pipe(StreamInterface $in, StreamInterface $out, $chunkSize = 8192) { if(!$in->isReadable()) { throw new \InvalidArgumentException(sprintf('Input stream is not readable: %s', get_class($in))); } if(!$out->isWritable()) { throw new \InvalidArgumentException(sprintf('Output stream is not writable: %s', get_class($out))); } $size = 0; while(!$in->eof()) { $size += $out->write($in->read($chunkSize)); } return $size; }
php
public static function pipe(StreamInterface $in, StreamInterface $out, $chunkSize = 8192) { if(!$in->isReadable()) { throw new \InvalidArgumentException(sprintf('Input stream is not readable: %s', get_class($in))); } if(!$out->isWritable()) { throw new \InvalidArgumentException(sprintf('Output stream is not writable: %s', get_class($out))); } $size = 0; while(!$in->eof()) { $size += $out->write($in->read($chunkSize)); } return $size; }
[ "public", "static", "function", "pipe", "(", "StreamInterface", "$", "in", ",", "StreamInterface", "$", "out", ",", "$", "chunkSize", "=", "8192", ")", "{", "if", "(", "!", "$", "in", "->", "isReadable", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Input stream is not readable: %s'", ",", "get_class", "(", "$", "in", ")", ")", ")", ";", "}", "if", "(", "!", "$", "out", "->", "isWritable", "(", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Output stream is not writable: %s'", ",", "get_class", "(", "$", "out", ")", ")", ")", ";", "}", "$", "size", "=", "0", ";", "while", "(", "!", "$", "in", "->", "eof", "(", ")", ")", "{", "$", "size", "+=", "$", "out", "->", "write", "(", "$", "in", "->", "read", "(", "$", "chunkSize", ")", ")", ";", "}", "return", "$", "size", ";", "}" ]
Pipe data from an input stream into an output stream. @param StreamInterface $in @param StreamInterface $out @param int $chunkSize Maximum chunk size being used during copy. @return int Number of bytes being copied. @throws \InvalidArgumentException When input stream is not readable or output stream is not writable.
[ "Pipe", "data", "from", "an", "input", "stream", "into", "an", "output", "stream", "." ]
train
https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/Stream.php#L117-L137
Danack/Jig
src/Jig/Jig.php
Jig.deleteCompiledFile
public function deleteCompiledFile($templateName) { $className = $this->jigConverter->getClassNameFromFilename($templateName); $compileFilename = $this->jigConfig->getCompiledFilenameFromClassname($className); $deleted = @unlink($compileFilename); return $deleted; }
php
public function deleteCompiledFile($templateName) { $className = $this->jigConverter->getClassNameFromFilename($templateName); $compileFilename = $this->jigConfig->getCompiledFilenameFromClassname($className); $deleted = @unlink($compileFilename); return $deleted; }
[ "public", "function", "deleteCompiledFile", "(", "$", "templateName", ")", "{", "$", "className", "=", "$", "this", "->", "jigConverter", "->", "getClassNameFromFilename", "(", "$", "templateName", ")", ";", "$", "compileFilename", "=", "$", "this", "->", "jigConfig", "->", "getCompiledFilenameFromClassname", "(", "$", "className", ")", ";", "$", "deleted", "=", "@", "unlink", "(", "$", "compileFilename", ")", ";", "return", "$", "deleted", ";", "}" ]
Delete the compiled version of a template. @param $templateName @return bool
[ "Delete", "the", "compiled", "version", "of", "a", "template", "." ]
train
https://github.com/Danack/Jig/blob/b11106bc7d634add9873bf246eda1dadb059ed7a/src/Jig/Jig.php#L78-L85
ekyna/Table
Bridge/Doctrine/ORM/Source/EntitySource.php
EntitySource.setQueryBuilderInitializer
public function setQueryBuilderInitializer(\Closure $initializer = null) { if (!is_null($initializer)) { $this->validateQueryBuilderInitializer($initializer); } $this->queryBuilderInitializer = $initializer; return $this; }
php
public function setQueryBuilderInitializer(\Closure $initializer = null) { if (!is_null($initializer)) { $this->validateQueryBuilderInitializer($initializer); } $this->queryBuilderInitializer = $initializer; return $this; }
[ "public", "function", "setQueryBuilderInitializer", "(", "\\", "Closure", "$", "initializer", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "initializer", ")", ")", "{", "$", "this", "->", "validateQueryBuilderInitializer", "(", "$", "initializer", ")", ";", "}", "$", "this", "->", "queryBuilderInitializer", "=", "$", "initializer", ";", "return", "$", "this", ";", "}" ]
Sets the query builder initializer. A closure with the query builder as first argument and the root alias as the second argument: function (QueryBuilder $qb, $alias) { } @param \Closure|null $initializer @return EntitySource
[ "Sets", "the", "query", "builder", "initializer", "." ]
train
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Doctrine/ORM/Source/EntitySource.php#L73-L82
ekyna/Table
Bridge/Doctrine/ORM/Source/EntitySource.php
EntitySource.validateQueryBuilderInitializer
private function validateQueryBuilderInitializer(\Closure $initializer) { $reflection = new \ReflectionFunction($initializer); $parameters = $reflection->getParameters(); if (2 !== count($parameters)) { throw new InvalidArgumentException("The query builder initializer must have two and only two arguments."); } $class = $parameters[0]->getClass(); if (!$class || $class->getName() !== QueryBuilder::class) { throw new InvalidArgumentException(sprintf( "The query builder initializer's first argument must be type hinted to the %s class.", QueryBuilder::class )); } if (!in_array($parameters[1]->getType(), [null, 'string'], true)) { throw new InvalidArgumentException(sprintf( "The query builder initializer's second must be type hinted to 'string'.", QueryBuilder::class )); } }
php
private function validateQueryBuilderInitializer(\Closure $initializer) { $reflection = new \ReflectionFunction($initializer); $parameters = $reflection->getParameters(); if (2 !== count($parameters)) { throw new InvalidArgumentException("The query builder initializer must have two and only two arguments."); } $class = $parameters[0]->getClass(); if (!$class || $class->getName() !== QueryBuilder::class) { throw new InvalidArgumentException(sprintf( "The query builder initializer's first argument must be type hinted to the %s class.", QueryBuilder::class )); } if (!in_array($parameters[1]->getType(), [null, 'string'], true)) { throw new InvalidArgumentException(sprintf( "The query builder initializer's second must be type hinted to 'string'.", QueryBuilder::class )); } }
[ "private", "function", "validateQueryBuilderInitializer", "(", "\\", "Closure", "$", "initializer", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionFunction", "(", "$", "initializer", ")", ";", "$", "parameters", "=", "$", "reflection", "->", "getParameters", "(", ")", ";", "if", "(", "2", "!==", "count", "(", "$", "parameters", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"The query builder initializer must have two and only two arguments.\"", ")", ";", "}", "$", "class", "=", "$", "parameters", "[", "0", "]", "->", "getClass", "(", ")", ";", "if", "(", "!", "$", "class", "||", "$", "class", "->", "getName", "(", ")", "!==", "QueryBuilder", "::", "class", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"The query builder initializer's first argument must be type hinted to the %s class.\"", ",", "QueryBuilder", "::", "class", ")", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "parameters", "[", "1", "]", "->", "getType", "(", ")", ",", "[", "null", ",", "'string'", "]", ",", "true", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "\"The query builder initializer's second must be type hinted to 'string'.\"", ",", "QueryBuilder", "::", "class", ")", ")", ";", "}", "}" ]
Validates the query builder initializer. @param \Closure $initializer @throws InvalidArgumentException
[ "Validates", "the", "query", "builder", "initializer", "." ]
train
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Doctrine/ORM/Source/EntitySource.php#L91-L114
dms-org/common.structure
src/DateTime/Persistence/TimezonedDateTimeMapper.php
TimezonedDateTimeMapper.define
protected function define(MapperDefinition $map) { $map->type(TimezonedDateTime::class); $map->property(TimezonedDateTime::DATE_TIME) ->mappedVia(function (\DateTimeImmutable $phpDateTime) { // Remove timezone information as this is lost when persisted anyway // The timezone will be stored in a separate column return \DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $phpDateTime->format('Y-m-d H:i:s'), new \DateTimeZone('UTC') ); }, function (\DateTimeImmutable $dbDateTime, array $row) { // When persisted, the date time instance will lose its timezone information // so it is loaded as if it is UTC but the actual timezone is stored in a // separate column. So we can create a new date time in the correct timezone // from the string representation of it in that timezone. // TODO: handle prefixes for $row return \DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $dbDateTime->format('Y-m-d H:i:s'), new \DateTimeZone($row[$this->timezoneColumnName]) ); }) ->to($this->dateTimeColumnName) ->asDateTime(); $map->computed( function (TimezonedDateTime $dateTime) { return $dateTime->getTimezone()->getName(); }) ->to($this->timezoneColumnName) ->asVarchar(50); }
php
protected function define(MapperDefinition $map) { $map->type(TimezonedDateTime::class); $map->property(TimezonedDateTime::DATE_TIME) ->mappedVia(function (\DateTimeImmutable $phpDateTime) { // Remove timezone information as this is lost when persisted anyway // The timezone will be stored in a separate column return \DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $phpDateTime->format('Y-m-d H:i:s'), new \DateTimeZone('UTC') ); }, function (\DateTimeImmutable $dbDateTime, array $row) { // When persisted, the date time instance will lose its timezone information // so it is loaded as if it is UTC but the actual timezone is stored in a // separate column. So we can create a new date time in the correct timezone // from the string representation of it in that timezone. // TODO: handle prefixes for $row return \DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $dbDateTime->format('Y-m-d H:i:s'), new \DateTimeZone($row[$this->timezoneColumnName]) ); }) ->to($this->dateTimeColumnName) ->asDateTime(); $map->computed( function (TimezonedDateTime $dateTime) { return $dateTime->getTimezone()->getName(); }) ->to($this->timezoneColumnName) ->asVarchar(50); }
[ "protected", "function", "define", "(", "MapperDefinition", "$", "map", ")", "{", "$", "map", "->", "type", "(", "TimezonedDateTime", "::", "class", ")", ";", "$", "map", "->", "property", "(", "TimezonedDateTime", "::", "DATE_TIME", ")", "->", "mappedVia", "(", "function", "(", "\\", "DateTimeImmutable", "$", "phpDateTime", ")", "{", "// Remove timezone information as this is lost when persisted anyway", "// The timezone will be stored in a separate column", "return", "\\", "DateTimeImmutable", "::", "createFromFormat", "(", "'Y-m-d H:i:s'", ",", "$", "phpDateTime", "->", "format", "(", "'Y-m-d H:i:s'", ")", ",", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "}", ",", "function", "(", "\\", "DateTimeImmutable", "$", "dbDateTime", ",", "array", "$", "row", ")", "{", "// When persisted, the date time instance will lose its timezone information", "// so it is loaded as if it is UTC but the actual timezone is stored in a", "// separate column. So we can create a new date time in the correct timezone", "// from the string representation of it in that timezone.", "// TODO: handle prefixes for $row", "return", "\\", "DateTimeImmutable", "::", "createFromFormat", "(", "'Y-m-d H:i:s'", ",", "$", "dbDateTime", "->", "format", "(", "'Y-m-d H:i:s'", ")", ",", "new", "\\", "DateTimeZone", "(", "$", "row", "[", "$", "this", "->", "timezoneColumnName", "]", ")", ")", ";", "}", ")", "->", "to", "(", "$", "this", "->", "dateTimeColumnName", ")", "->", "asDateTime", "(", ")", ";", "$", "map", "->", "computed", "(", "function", "(", "TimezonedDateTime", "$", "dateTime", ")", "{", "return", "$", "dateTime", "->", "getTimezone", "(", ")", "->", "getName", "(", ")", ";", "}", ")", "->", "to", "(", "$", "this", "->", "timezoneColumnName", ")", "->", "asVarchar", "(", "50", ")", ";", "}" ]
Defines the value object mapper @param MapperDefinition $map @return void
[ "Defines", "the", "value", "object", "mapper" ]
train
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/Persistence/TimezonedDateTimeMapper.php#L40-L74
lasallecms/lasallecms-l5-lasallecmsadmin-pkg
src/FormProcessing/Postupdates/DeletePostupdateFormProcessing.php
DeletePostupdateFormProcessing.quarterback
public function quarterback($id) { // SPECIAL FOR POST UPDATES: WHAT IS THE POST_ID OF THIS POST UPDATE? BETTER FIND OUT BEFORE DELETING THE POST! $post_id = $this->repository->postIdOfPostupdate($id); // DELETE record if (!$this->persist($id, $this->type)) { // Prepare the response array, and then return to the edit form with error messages // Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php // does not prepare a MessageBag object, so we'll whip up an error message in the // originating controller return $this->prepareResponseArray('persist_failed', 500, $id); } // SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE ARE NO POST UPDATE FOR THAT POST, // WHEN THE LAST POST UPDATE IS DELETED. $this->repository->postupdateNotExist($post_id); // Prepare the response array, and then return to the command return $this->prepareResponseArray('create_successful', 200, $id); }
php
public function quarterback($id) { // SPECIAL FOR POST UPDATES: WHAT IS THE POST_ID OF THIS POST UPDATE? BETTER FIND OUT BEFORE DELETING THE POST! $post_id = $this->repository->postIdOfPostupdate($id); // DELETE record if (!$this->persist($id, $this->type)) { // Prepare the response array, and then return to the edit form with error messages // Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php // does not prepare a MessageBag object, so we'll whip up an error message in the // originating controller return $this->prepareResponseArray('persist_failed', 500, $id); } // SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE ARE NO POST UPDATE FOR THAT POST, // WHEN THE LAST POST UPDATE IS DELETED. $this->repository->postupdateNotExist($post_id); // Prepare the response array, and then return to the command return $this->prepareResponseArray('create_successful', 200, $id); }
[ "public", "function", "quarterback", "(", "$", "id", ")", "{", "// SPECIAL FOR POST UPDATES: WHAT IS THE POST_ID OF THIS POST UPDATE? BETTER FIND OUT BEFORE DELETING THE POST!", "$", "post_id", "=", "$", "this", "->", "repository", "->", "postIdOfPostupdate", "(", "$", "id", ")", ";", "// DELETE record", "if", "(", "!", "$", "this", "->", "persist", "(", "$", "id", ",", "$", "this", "->", "type", ")", ")", "{", "// Prepare the response array, and then return to the edit form with error messages", "// Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php", "// does not prepare a MessageBag object, so we'll whip up an error message in the", "// originating controller", "return", "$", "this", "->", "prepareResponseArray", "(", "'persist_failed'", ",", "500", ",", "$", "id", ")", ";", "}", "// SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE ARE NO POST UPDATE FOR THAT POST,", "// WHEN THE LAST POST UPDATE IS DELETED.", "$", "this", "->", "repository", "->", "postupdateNotExist", "(", "$", "post_id", ")", ";", "// Prepare the response array, and then return to the command", "return", "$", "this", "->", "prepareResponseArray", "(", "'create_successful'", ",", "200", ",", "$", "id", ")", ";", "}" ]
The processing steps. @param The command bus object $deletePostCommand @return The custom response array
[ "The", "processing", "steps", "." ]
train
https://github.com/lasallecms/lasallecms-l5-lasallecmsadmin-pkg/blob/5a4b3375e449273a98e84a566bcf60fd2172cb2d/src/FormProcessing/Postupdates/DeletePostupdateFormProcessing.php#L115-L139
lightwerk/SurfTasks
Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php
DumpTask.execute
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) { $options = array_replace_recursive($this->options, $options); if (empty($options['sourceNode']) === false) { $node = $this->nodeFactory->getNodeByArray($options['sourceNode']); $options = array_replace_recursive($options, $options['sourceNodeOptions']); } $credentials = $this->getCredentials($node, $deployment, $options, $application); $mysqlArguments = $this->getMysqlArguments($credentials); $tableLikes = $this->getTableLikes($options, $credentials); $dumpFile = $this->getDumpFile($options, $credentials); $commands = [$this->getDataTablesCommand($mysqlArguments, $tableLikes, $dumpFile)]; if (empty($tableLikes) === false) { $commands[] = $this->getStructureCommand($mysqlArguments, $tableLikes, $dumpFile); } $this->shell->executeOrSimulate($commands, $node, $deployment, false, false); }
php
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) { $options = array_replace_recursive($this->options, $options); if (empty($options['sourceNode']) === false) { $node = $this->nodeFactory->getNodeByArray($options['sourceNode']); $options = array_replace_recursive($options, $options['sourceNodeOptions']); } $credentials = $this->getCredentials($node, $deployment, $options, $application); $mysqlArguments = $this->getMysqlArguments($credentials); $tableLikes = $this->getTableLikes($options, $credentials); $dumpFile = $this->getDumpFile($options, $credentials); $commands = [$this->getDataTablesCommand($mysqlArguments, $tableLikes, $dumpFile)]; if (empty($tableLikes) === false) { $commands[] = $this->getStructureCommand($mysqlArguments, $tableLikes, $dumpFile); } $this->shell->executeOrSimulate($commands, $node, $deployment, false, false); }
[ "public", "function", "execute", "(", "Node", "$", "node", ",", "Application", "$", "application", ",", "Deployment", "$", "deployment", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "array_replace_recursive", "(", "$", "this", "->", "options", ",", "$", "options", ")", ";", "if", "(", "empty", "(", "$", "options", "[", "'sourceNode'", "]", ")", "===", "false", ")", "{", "$", "node", "=", "$", "this", "->", "nodeFactory", "->", "getNodeByArray", "(", "$", "options", "[", "'sourceNode'", "]", ")", ";", "$", "options", "=", "array_replace_recursive", "(", "$", "options", ",", "$", "options", "[", "'sourceNodeOptions'", "]", ")", ";", "}", "$", "credentials", "=", "$", "this", "->", "getCredentials", "(", "$", "node", ",", "$", "deployment", ",", "$", "options", ",", "$", "application", ")", ";", "$", "mysqlArguments", "=", "$", "this", "->", "getMysqlArguments", "(", "$", "credentials", ")", ";", "$", "tableLikes", "=", "$", "this", "->", "getTableLikes", "(", "$", "options", ",", "$", "credentials", ")", ";", "$", "dumpFile", "=", "$", "this", "->", "getDumpFile", "(", "$", "options", ",", "$", "credentials", ")", ";", "$", "commands", "=", "[", "$", "this", "->", "getDataTablesCommand", "(", "$", "mysqlArguments", ",", "$", "tableLikes", ",", "$", "dumpFile", ")", "]", ";", "if", "(", "empty", "(", "$", "tableLikes", ")", "===", "false", ")", "{", "$", "commands", "[", "]", "=", "$", "this", "->", "getStructureCommand", "(", "$", "mysqlArguments", ",", "$", "tableLikes", ",", "$", "dumpFile", ")", ";", "}", "$", "this", "->", "shell", "->", "executeOrSimulate", "(", "$", "commands", ",", "$", "node", ",", "$", "deployment", ",", "false", ",", "false", ")", ";", "}" ]
@param Node $node @param Application $application @param Deployment $deployment @param array $options @throws TaskExecutionException @throws InvalidConfigurationException
[ "@param", "Node", "$node", "@param", "Application", "$application", "@param", "Deployment", "$deployment", "@param", "array", "$options" ]
train
https://github.com/lightwerk/SurfTasks/blob/8a6e4c85e42c762ad6515778c3fc7e19052cd9d1/Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php#L68-L87
lightwerk/SurfTasks
Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php
DumpTask.getTableLikes
protected function getTableLikes($options, $credentials) { if ($options['fullDump'] === true || empty($options['ignoreTables']) === true) { return []; } $tablesLike = []; foreach ($options['ignoreTables'] as $table => $enabled) { if (!$enabled) { continue; } $tablesLike[] = 'Tables_in_' . $credentials['database'] . ' LIKE ' . escapeshellarg($table); } return $tablesLike; }
php
protected function getTableLikes($options, $credentials) { if ($options['fullDump'] === true || empty($options['ignoreTables']) === true) { return []; } $tablesLike = []; foreach ($options['ignoreTables'] as $table => $enabled) { if (!$enabled) { continue; } $tablesLike[] = 'Tables_in_' . $credentials['database'] . ' LIKE ' . escapeshellarg($table); } return $tablesLike; }
[ "protected", "function", "getTableLikes", "(", "$", "options", ",", "$", "credentials", ")", "{", "if", "(", "$", "options", "[", "'fullDump'", "]", "===", "true", "||", "empty", "(", "$", "options", "[", "'ignoreTables'", "]", ")", "===", "true", ")", "{", "return", "[", "]", ";", "}", "$", "tablesLike", "=", "[", "]", ";", "foreach", "(", "$", "options", "[", "'ignoreTables'", "]", "as", "$", "table", "=>", "$", "enabled", ")", "{", "if", "(", "!", "$", "enabled", ")", "{", "continue", ";", "}", "$", "tablesLike", "[", "]", "=", "'Tables_in_'", ".", "$", "credentials", "[", "'database'", "]", ".", "' LIKE '", ".", "escapeshellarg", "(", "$", "table", ")", ";", "}", "return", "$", "tablesLike", ";", "}" ]
@param array $options @return array
[ "@param", "array", "$options" ]
train
https://github.com/lightwerk/SurfTasks/blob/8a6e4c85e42c762ad6515778c3fc7e19052cd9d1/Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php#L94-L108
lightwerk/SurfTasks
Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php
DumpTask.getDataTablesCommand
protected function getDataTablesCommand($mysqlArguments, $tableLikes, $targetFile) { if (empty($tableLikes) === false) { $dataTables = ' `mysql -N ' . $mysqlArguments . ' -e "SHOW TABLES WHERE NOT (' . implode(' OR ', $tableLikes) . ')" | awk \'{printf $1" "}\'`'; } else { $dataTables = ''; } return 'mysqldump --single-transaction ' . $mysqlArguments . ' ' . $dataTables . ' | gzip > ' . $targetFile; }
php
protected function getDataTablesCommand($mysqlArguments, $tableLikes, $targetFile) { if (empty($tableLikes) === false) { $dataTables = ' `mysql -N ' . $mysqlArguments . ' -e "SHOW TABLES WHERE NOT (' . implode(' OR ', $tableLikes) . ')" | awk \'{printf $1" "}\'`'; } else { $dataTables = ''; } return 'mysqldump --single-transaction ' . $mysqlArguments . ' ' . $dataTables . ' | gzip > ' . $targetFile; }
[ "protected", "function", "getDataTablesCommand", "(", "$", "mysqlArguments", ",", "$", "tableLikes", ",", "$", "targetFile", ")", "{", "if", "(", "empty", "(", "$", "tableLikes", ")", "===", "false", ")", "{", "$", "dataTables", "=", "' `mysql -N '", ".", "$", "mysqlArguments", ".", "' -e \"SHOW TABLES WHERE NOT ('", ".", "implode", "(", "' OR '", ",", "$", "tableLikes", ")", ".", "')\" | awk \\'{printf $1\" \"}\\'`'", ";", "}", "else", "{", "$", "dataTables", "=", "''", ";", "}", "return", "'mysqldump --single-transaction '", ".", "$", "mysqlArguments", ".", "' '", ".", "$", "dataTables", ".", "' | gzip > '", ".", "$", "targetFile", ";", "}" ]
@param string $mysqlArguments @param array $tableLikes @param string $targetFile @return string
[ "@param", "string", "$mysqlArguments", "@param", "array", "$tableLikes", "@param", "string", "$targetFile" ]
train
https://github.com/lightwerk/SurfTasks/blob/8a6e4c85e42c762ad6515778c3fc7e19052cd9d1/Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php#L117-L127
lightwerk/SurfTasks
Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php
DumpTask.getStructureCommand
protected function getStructureCommand($mysqlArguments, $tableLikes, $targetFile) { $dataTables = ' `mysql -N ' . $mysqlArguments . ' -e "SHOW TABLES WHERE (' . implode(' OR ', $tableLikes) . ')" | awk \'{printf $1" "}\'`'; return 'mysqldump --no-data --single-transaction ' . $mysqlArguments . ' --skip-add-drop-table ' . $dataTables . ' | sed "s/^CREATE TABLE/CREATE TABLE IF NOT EXISTS/g"' . ' | gzip >> ' . $targetFile; }
php
protected function getStructureCommand($mysqlArguments, $tableLikes, $targetFile) { $dataTables = ' `mysql -N ' . $mysqlArguments . ' -e "SHOW TABLES WHERE (' . implode(' OR ', $tableLikes) . ')" | awk \'{printf $1" "}\'`'; return 'mysqldump --no-data --single-transaction ' . $mysqlArguments . ' --skip-add-drop-table ' . $dataTables . ' | sed "s/^CREATE TABLE/CREATE TABLE IF NOT EXISTS/g"' . ' | gzip >> ' . $targetFile; }
[ "protected", "function", "getStructureCommand", "(", "$", "mysqlArguments", ",", "$", "tableLikes", ",", "$", "targetFile", ")", "{", "$", "dataTables", "=", "' `mysql -N '", ".", "$", "mysqlArguments", ".", "' -e \"SHOW TABLES WHERE ('", ".", "implode", "(", "' OR '", ",", "$", "tableLikes", ")", ".", "')\" | awk \\'{printf $1\" \"}\\'`'", ";", "return", "'mysqldump --no-data --single-transaction '", ".", "$", "mysqlArguments", ".", "' --skip-add-drop-table '", ".", "$", "dataTables", ".", "' | sed \"s/^CREATE TABLE/CREATE TABLE IF NOT EXISTS/g\"'", ".", "' | gzip >> '", ".", "$", "targetFile", ";", "}" ]
@param string $mysqlArguments @param array $tableLikes @param string $targetFile @return string
[ "@param", "string", "$mysqlArguments", "@param", "array", "$tableLikes", "@param", "string", "$targetFile" ]
train
https://github.com/lightwerk/SurfTasks/blob/8a6e4c85e42c762ad6515778c3fc7e19052cd9d1/Classes/Lightwerk/SurfTasks/Task/Database/DumpTask.php#L136-L143
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Type/BinaryType.php
BinaryType.databaseValue
protected function databaseValue($value) { if (is_string($value)) { return $value; } if (!$value instanceof BinaryValue) { if (!is_resource($value) && !$value instanceof StreamInterface) { throw ODMException::invalidValueForType('Binary', ['string', 'resource', 'StreamInterface', 'BinaryValue', 'null'], $value); } $value = \GuzzleHttp\Psr7\stream_for($value); } return (string)$value; }
php
protected function databaseValue($value) { if (is_string($value)) { return $value; } if (!$value instanceof BinaryValue) { if (!is_resource($value) && !$value instanceof StreamInterface) { throw ODMException::invalidValueForType('Binary', ['string', 'resource', 'StreamInterface', 'BinaryValue', 'null'], $value); } $value = \GuzzleHttp\Psr7\stream_for($value); } return (string)$value; }
[ "protected", "function", "databaseValue", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "if", "(", "!", "$", "value", "instanceof", "BinaryValue", ")", "{", "if", "(", "!", "is_resource", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "StreamInterface", ")", "{", "throw", "ODMException", "::", "invalidValueForType", "(", "'Binary'", ",", "[", "'string'", ",", "'resource'", ",", "'StreamInterface'", ",", "'BinaryValue'", ",", "'null'", "]", ",", "$", "value", ")", ";", "}", "$", "value", "=", "\\", "GuzzleHttp", "\\", "Psr7", "\\", "stream_for", "(", "$", "value", ")", ";", "}", "return", "(", "string", ")", "$", "value", ";", "}" ]
@param string|resource|StreamInterface|BinaryValue $value @return string @throws ODMException
[ "@param", "string|resource|StreamInterface|BinaryValue", "$value" ]
train
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/BinaryType.php#L28-L43
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.render
public function render($return = false) { $html = "<form"; if($this->id) $html .= " id='$this->id'"; if($this->class) $html .= " class='$this->class'"; if($this->action || $this->action == "") $html .= " action='$this->action'"; if($this->method) $html .= " method='$this->method'"; if($this->enctype) $html .= " enctype='$this->enctype'"; if($this->custom) $html .= " $this->custom"; $html .= ">"; // Render all the controls foreach($this->controls as $control) { if($control->isPlainControl()){ $html .= $control->renderBasic(); }else{ $html .= $this->renderControl($control, true); } } // Close the form $html .= "</form>"; // Return or echo if($return) return $html; echo $html; }
php
public function render($return = false) { $html = "<form"; if($this->id) $html .= " id='$this->id'"; if($this->class) $html .= " class='$this->class'"; if($this->action || $this->action == "") $html .= " action='$this->action'"; if($this->method) $html .= " method='$this->method'"; if($this->enctype) $html .= " enctype='$this->enctype'"; if($this->custom) $html .= " $this->custom"; $html .= ">"; // Render all the controls foreach($this->controls as $control) { if($control->isPlainControl()){ $html .= $control->renderBasic(); }else{ $html .= $this->renderControl($control, true); } } // Close the form $html .= "</form>"; // Return or echo if($return) return $html; echo $html; }
[ "public", "function", "render", "(", "$", "return", "=", "false", ")", "{", "$", "html", "=", "\"<form\"", ";", "if", "(", "$", "this", "->", "id", ")", "$", "html", ".=", "\" id='$this->id'\"", ";", "if", "(", "$", "this", "->", "class", ")", "$", "html", ".=", "\" class='$this->class'\"", ";", "if", "(", "$", "this", "->", "action", "||", "$", "this", "->", "action", "==", "\"\"", ")", "$", "html", ".=", "\" action='$this->action'\"", ";", "if", "(", "$", "this", "->", "method", ")", "$", "html", ".=", "\" method='$this->method'\"", ";", "if", "(", "$", "this", "->", "enctype", ")", "$", "html", ".=", "\" enctype='$this->enctype'\"", ";", "if", "(", "$", "this", "->", "custom", ")", "$", "html", ".=", "\" $this->custom\"", ";", "$", "html", ".=", "\">\"", ";", "// Render all the controls", "foreach", "(", "$", "this", "->", "controls", "as", "$", "control", ")", "{", "if", "(", "$", "control", "->", "isPlainControl", "(", ")", ")", "{", "$", "html", ".=", "$", "control", "->", "renderBasic", "(", ")", ";", "}", "else", "{", "$", "html", ".=", "$", "this", "->", "renderControl", "(", "$", "control", ",", "true", ")", ";", "}", "}", "// Close the form", "$", "html", ".=", "\"</form>\"", ";", "// Return or echo", "if", "(", "$", "return", ")", "return", "$", "html", ";", "echo", "$", "html", ";", "}" ]
Render form @param boolean $return Do you want to return the HTML?
[ "Render", "form" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L24-L49
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.addAll
public function addAll() { if(func_num_args() > 0) { for($i = 0; $i < func_num_args(); $i++) { if(func_get_arg($i) instanceof \bootbuilder\Controls\Control){ array_push($this->controls, func_get_arg($i)); } } } }
php
public function addAll() { if(func_num_args() > 0) { for($i = 0; $i < func_num_args(); $i++) { if(func_get_arg($i) instanceof \bootbuilder\Controls\Control){ array_push($this->controls, func_get_arg($i)); } } } }
[ "public", "function", "addAll", "(", ")", "{", "if", "(", "func_num_args", "(", ")", ">", "0", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "func_num_args", "(", ")", ";", "$", "i", "++", ")", "{", "if", "(", "func_get_arg", "(", "$", "i", ")", "instanceof", "\\", "bootbuilder", "\\", "Controls", "\\", "Control", ")", "{", "array_push", "(", "$", "this", "->", "controls", ",", "func_get_arg", "(", "$", "i", ")", ")", ";", "}", "}", "}", "}" ]
Add multiple controls to form @param \BootBuilder\Controls\Control $control,... Multiple controls
[ "Add", "multiple", "controls", "to", "form" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L72-L80
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.replaceControl
public function replaceControl($nr, $control) { if(isset($this->controls[$nr])) { $this->controls[$nr] = $control; } }
php
public function replaceControl($nr, $control) { if(isset($this->controls[$nr])) { $this->controls[$nr] = $control; } }
[ "public", "function", "replaceControl", "(", "$", "nr", ",", "$", "control", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "controls", "[", "$", "nr", "]", ")", ")", "{", "$", "this", "->", "controls", "[", "$", "nr", "]", "=", "$", "control", ";", "}", "}" ]
Replace current control in array with new one @param int $nr @param mixed $control
[ "Replace", "current", "control", "in", "array", "with", "new", "one" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L143-L147
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.parseParameters
public function parseParameters($parameters) { for($i = 0; $i < count($this->controls); $i++) { $this->controls[$i] = $this->parseParameterControl($this->controls[$i], $parameters); } }
php
public function parseParameters($parameters) { for($i = 0; $i < count($this->controls); $i++) { $this->controls[$i] = $this->parseParameterControl($this->controls[$i], $parameters); } }
[ "public", "function", "parseParameters", "(", "$", "parameters", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "controls", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "controls", "[", "$", "i", "]", "=", "$", "this", "->", "parseParameterControl", "(", "$", "this", "->", "controls", "[", "$", "i", "]", ",", "$", "parameters", ")", ";", "}", "}" ]
Parse Posted Parameters into controls @param mixed $parameters
[ "Parse", "Posted", "Parameters", "into", "controls" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L185-L189
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.parseParameterControl
private function parseParameterControl($control, $parameters) { if($control instanceof \bootbuilder\Pane\Pane) { $control->parseParameters($parameters); }elseif($control instanceof \bootbuilder\Controls\Control) { if(isset($parameters[$control->getName()])) { if($control instanceof \bootbuilder\Controls\Checkbox) { if($control instanceof \bootbuilder\Controls\Radio) { if($control->getValue() == $parameters[$control->getName()]) { $control->setChecked(true); }else{ $control->setChecked(false); } }else{ $control->setChecked(true); } }else{ $control->setValue(htmlentities($parameters[$control->getName()])); } } } return $control; }
php
private function parseParameterControl($control, $parameters) { if($control instanceof \bootbuilder\Pane\Pane) { $control->parseParameters($parameters); }elseif($control instanceof \bootbuilder\Controls\Control) { if(isset($parameters[$control->getName()])) { if($control instanceof \bootbuilder\Controls\Checkbox) { if($control instanceof \bootbuilder\Controls\Radio) { if($control->getValue() == $parameters[$control->getName()]) { $control->setChecked(true); }else{ $control->setChecked(false); } }else{ $control->setChecked(true); } }else{ $control->setValue(htmlentities($parameters[$control->getName()])); } } } return $control; }
[ "private", "function", "parseParameterControl", "(", "$", "control", ",", "$", "parameters", ")", "{", "if", "(", "$", "control", "instanceof", "\\", "bootbuilder", "\\", "Pane", "\\", "Pane", ")", "{", "$", "control", "->", "parseParameters", "(", "$", "parameters", ")", ";", "}", "elseif", "(", "$", "control", "instanceof", "\\", "bootbuilder", "\\", "Controls", "\\", "Control", ")", "{", "if", "(", "isset", "(", "$", "parameters", "[", "$", "control", "->", "getName", "(", ")", "]", ")", ")", "{", "if", "(", "$", "control", "instanceof", "\\", "bootbuilder", "\\", "Controls", "\\", "Checkbox", ")", "{", "if", "(", "$", "control", "instanceof", "\\", "bootbuilder", "\\", "Controls", "\\", "Radio", ")", "{", "if", "(", "$", "control", "->", "getValue", "(", ")", "==", "$", "parameters", "[", "$", "control", "->", "getName", "(", ")", "]", ")", "{", "$", "control", "->", "setChecked", "(", "true", ")", ";", "}", "else", "{", "$", "control", "->", "setChecked", "(", "false", ")", ";", "}", "}", "else", "{", "$", "control", "->", "setChecked", "(", "true", ")", ";", "}", "}", "else", "{", "$", "control", "->", "setValue", "(", "htmlentities", "(", "$", "parameters", "[", "$", "control", "->", "getName", "(", ")", "]", ")", ")", ";", "}", "}", "}", "return", "$", "control", ";", "}" ]
Parse control @param mixed $control @param array $parameters @return mixed
[ "Parse", "control" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L197-L219
ValkSystems/bootbuilder
src/bootbuilder/Form.php
Form.save
public function save($replace = true, $prepare = true) { $this->add(new \bootbuilder\Controls\Hidden("bootbuilder-form", $this->id)); if($replace) { \bootbuilder\Validation\Validator::clean(); } \bootbuilder\Validation\Validator::save($this, $this->id, $prepare); }
php
public function save($replace = true, $prepare = true) { $this->add(new \bootbuilder\Controls\Hidden("bootbuilder-form", $this->id)); if($replace) { \bootbuilder\Validation\Validator::clean(); } \bootbuilder\Validation\Validator::save($this, $this->id, $prepare); }
[ "public", "function", "save", "(", "$", "replace", "=", "true", ",", "$", "prepare", "=", "true", ")", "{", "$", "this", "->", "add", "(", "new", "\\", "bootbuilder", "\\", "Controls", "\\", "Hidden", "(", "\"bootbuilder-form\"", ",", "$", "this", "->", "id", ")", ")", ";", "if", "(", "$", "replace", ")", "{", "\\", "bootbuilder", "\\", "Validation", "\\", "Validator", "::", "clean", "(", ")", ";", "}", "\\", "bootbuilder", "\\", "Validation", "\\", "Validator", "::", "save", "(", "$", "this", ",", "$", "this", "->", "id", ",", "$", "prepare", ")", ";", "}" ]
Save form for validation @param boolean $replace set false if you have multiple forms on one page @param boolean $prepare prepare session, false on unittesting
[ "Save", "form", "for", "validation" ]
train
https://github.com/ValkSystems/bootbuilder/blob/7601a403f42eba47ce4cf02a3c852d5196b1d860/src/bootbuilder/Form.php#L226-L234
cocur/pli
src/Pli.php
Pli.loadConfiguration
public function loadConfiguration(ConfigurationInterface $configuration, array $configFiles = []) { $rawConfig = []; foreach ($configFiles as $configFile) { if (!file_exists($configFile)) { $configFile = $this->getConfigFilename($configFile); } if ($configFile) { $rawConfig[] = Yaml::parse(file_get_contents($configFile)); } } return (new Processor())->processConfiguration($configuration, $rawConfig); }
php
public function loadConfiguration(ConfigurationInterface $configuration, array $configFiles = []) { $rawConfig = []; foreach ($configFiles as $configFile) { if (!file_exists($configFile)) { $configFile = $this->getConfigFilename($configFile); } if ($configFile) { $rawConfig[] = Yaml::parse(file_get_contents($configFile)); } } return (new Processor())->processConfiguration($configuration, $rawConfig); }
[ "public", "function", "loadConfiguration", "(", "ConfigurationInterface", "$", "configuration", ",", "array", "$", "configFiles", "=", "[", "]", ")", "{", "$", "rawConfig", "=", "[", "]", ";", "foreach", "(", "$", "configFiles", "as", "$", "configFile", ")", "{", "if", "(", "!", "file_exists", "(", "$", "configFile", ")", ")", "{", "$", "configFile", "=", "$", "this", "->", "getConfigFilename", "(", "$", "configFile", ")", ";", "}", "if", "(", "$", "configFile", ")", "{", "$", "rawConfig", "[", "]", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "$", "configFile", ")", ")", ";", "}", "}", "return", "(", "new", "Processor", "(", ")", ")", "->", "processConfiguration", "(", "$", "configuration", ",", "$", "rawConfig", ")", ";", "}" ]
@param ConfigurationInterface $configuration @param string[] $configFiles @return array
[ "@param", "ConfigurationInterface", "$configuration", "@param", "string", "[]", "$configFiles" ]
train
https://github.com/cocur/pli/blob/9f036160065b11998b07a5fd79a3be670f9ffa7b/src/Pli.php#L54-L67
cocur/pli
src/Pli.php
Pli.buildContainer
public function buildContainer( ExtensionInterface $extension = null, array $config = [], array $parameters = [], array $compilerPasses = [] ) { $container = new ContainerBuilder(); if ($extension !== null) { $extension->setConfigDirectories($this->configDirectories); $extension->buildContainer($container, $config); } foreach ($parameters as $key => $value) { $container->setParameter($key, $value); } foreach ($compilerPasses as $compilerPass) { $container->addCompilerPass($compilerPass); } $container->compile(); return $container; }
php
public function buildContainer( ExtensionInterface $extension = null, array $config = [], array $parameters = [], array $compilerPasses = [] ) { $container = new ContainerBuilder(); if ($extension !== null) { $extension->setConfigDirectories($this->configDirectories); $extension->buildContainer($container, $config); } foreach ($parameters as $key => $value) { $container->setParameter($key, $value); } foreach ($compilerPasses as $compilerPass) { $container->addCompilerPass($compilerPass); } $container->compile(); return $container; }
[ "public", "function", "buildContainer", "(", "ExtensionInterface", "$", "extension", "=", "null", ",", "array", "$", "config", "=", "[", "]", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "compilerPasses", "=", "[", "]", ")", "{", "$", "container", "=", "new", "ContainerBuilder", "(", ")", ";", "if", "(", "$", "extension", "!==", "null", ")", "{", "$", "extension", "->", "setConfigDirectories", "(", "$", "this", "->", "configDirectories", ")", ";", "$", "extension", "->", "buildContainer", "(", "$", "container", ",", "$", "config", ")", ";", "}", "foreach", "(", "$", "parameters", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "container", "->", "setParameter", "(", "$", "key", ",", "$", "value", ")", ";", "}", "foreach", "(", "$", "compilerPasses", "as", "$", "compilerPass", ")", "{", "$", "container", "->", "addCompilerPass", "(", "$", "compilerPass", ")", ";", "}", "$", "container", "->", "compile", "(", ")", ";", "return", "$", "container", ";", "}" ]
@param ExtensionInterface|null $extension @param array $config @param array $parameters @param CompilerPassInterface[] $compilerPasses @return ContainerBuilder
[ "@param", "ExtensionInterface|null", "$extension", "@param", "array", "$config", "@param", "array", "$parameters", "@param", "CompilerPassInterface", "[]", "$compilerPasses" ]
train
https://github.com/cocur/pli/blob/9f036160065b11998b07a5fd79a3be670f9ffa7b/src/Pli.php#L77-L97
cocur/pli
src/Pli.php
Pli.addCommands
protected function addCommands(Application $application, ContainerBuilder $container) { $commands = array_keys($container->findTaggedServiceIds('command')); foreach ($commands as $id) { /** @var \Symfony\Component\Console\Command\Command|ContainerAwareInterface $command */ $command = $container->get($id); $application->add($command); if ($command instanceof ContainerAwareInterface) { $command->setContainer($container); } } return $application; }
php
protected function addCommands(Application $application, ContainerBuilder $container) { $commands = array_keys($container->findTaggedServiceIds('command')); foreach ($commands as $id) { /** @var \Symfony\Component\Console\Command\Command|ContainerAwareInterface $command */ $command = $container->get($id); $application->add($command); if ($command instanceof ContainerAwareInterface) { $command->setContainer($container); } } return $application; }
[ "protected", "function", "addCommands", "(", "Application", "$", "application", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "commands", "=", "array_keys", "(", "$", "container", "->", "findTaggedServiceIds", "(", "'command'", ")", ")", ";", "foreach", "(", "$", "commands", "as", "$", "id", ")", "{", "/** @var \\Symfony\\Component\\Console\\Command\\Command|ContainerAwareInterface $command */", "$", "command", "=", "$", "container", "->", "get", "(", "$", "id", ")", ";", "$", "application", "->", "add", "(", "$", "command", ")", ";", "if", "(", "$", "command", "instanceof", "ContainerAwareInterface", ")", "{", "$", "command", "->", "setContainer", "(", "$", "container", ")", ";", "}", "}", "return", "$", "application", ";", "}" ]
@param Application $application @param ContainerBuilder $container @return Application
[ "@param", "Application", "$application", "@param", "ContainerBuilder", "$container" ]
train
https://github.com/cocur/pli/blob/9f036160065b11998b07a5fd79a3be670f9ffa7b/src/Pli.php#L115-L128
cocur/pli
src/Pli.php
Pli.getConfigFilename
protected function getConfigFilename($configFile) { foreach ($this->configDirectories as $configDirectory) { $configPathname = sprintf('%s/%s', $configDirectory, $configFile); if (file_exists($configPathname)) { return $configPathname; } } return null; }
php
protected function getConfigFilename($configFile) { foreach ($this->configDirectories as $configDirectory) { $configPathname = sprintf('%s/%s', $configDirectory, $configFile); if (file_exists($configPathname)) { return $configPathname; } } return null; }
[ "protected", "function", "getConfigFilename", "(", "$", "configFile", ")", "{", "foreach", "(", "$", "this", "->", "configDirectories", "as", "$", "configDirectory", ")", "{", "$", "configPathname", "=", "sprintf", "(", "'%s/%s'", ",", "$", "configDirectory", ",", "$", "configFile", ")", ";", "if", "(", "file_exists", "(", "$", "configPathname", ")", ")", "{", "return", "$", "configPathname", ";", "}", "}", "return", "null", ";", "}" ]
@param string $configFile @return null|string
[ "@param", "string", "$configFile" ]
train
https://github.com/cocur/pli/blob/9f036160065b11998b07a5fd79a3be670f9ffa7b/src/Pli.php#L135-L145
Saritasa/php-eloquent-custom
src/Utils/Query.php
Query.captureQueries
public static function captureQueries(\Closure $closure) { DB::enableQueryLog(); $closure(); $logs = DB::getQueryLog(); return array_map(function ($log) { return static::inlineBindings($log['query'], $log['bindings']); }, $logs); }
php
public static function captureQueries(\Closure $closure) { DB::enableQueryLog(); $closure(); $logs = DB::getQueryLog(); return array_map(function ($log) { return static::inlineBindings($log['query'], $log['bindings']); }, $logs); }
[ "public", "static", "function", "captureQueries", "(", "\\", "Closure", "$", "closure", ")", "{", "DB", "::", "enableQueryLog", "(", ")", ";", "$", "closure", "(", ")", ";", "$", "logs", "=", "DB", "::", "getQueryLog", "(", ")", ";", "return", "array_map", "(", "function", "(", "$", "log", ")", "{", "return", "static", "::", "inlineBindings", "(", "$", "log", "[", "'query'", "]", ",", "$", "log", "[", "'bindings'", "]", ")", ";", "}", ",", "$", "logs", ")", ";", "}" ]
Capture SQL queries, called via Eloquent inside argument closure @param \Closure $closure function, that contains DB invocations @return array
[ "Capture", "SQL", "queries", "called", "via", "Eloquent", "inside", "argument", "closure" ]
train
https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Utils/Query.php#L17-L25
Saritasa/php-eloquent-custom
src/Utils/Query.php
Query.plainSql
public static function plainSql($query) { $query = static::getBaseQuery($query); return self::inlineBindings($query->toSql(), $query->getBindings()); }
php
public static function plainSql($query) { $query = static::getBaseQuery($query); return self::inlineBindings($query->toSql(), $query->getBindings()); }
[ "public", "static", "function", "plainSql", "(", "$", "query", ")", "{", "$", "query", "=", "static", "::", "getBaseQuery", "(", "$", "query", ")", ";", "return", "self", "::", "inlineBindings", "(", "$", "query", "->", "toSql", "(", ")", ",", "$", "query", "->", "getBindings", "(", ")", ")", ";", "}" ]
Present query builder as plain SQL, including inline parameter values @param QueryBuilder|EloquentBuilder $query Query buiilder @return string
[ "Present", "query", "builder", "as", "plain", "SQL", "including", "inline", "parameter", "values" ]
train
https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Utils/Query.php#L55-L59
cravler/CravlerRemoteBundle
DependencyInjection/Compiler/GlobalVariablesCompilerPass.php
GlobalVariablesCompilerPass.process
public function process(ContainerBuilder $container) { $def = $container->getDefinition('twig'); $parameters = array( CravlerRemoteExtension::CONFIG_KEY . '.app_port', ); foreach ($parameters as $key) { list($listen, $connect) = explode(':', $container->getParameter($key) . ':'); $def->addMethodCall('addGlobal', array( str_replace('.', '_', $key), $connect ?: $listen )); } }
php
public function process(ContainerBuilder $container) { $def = $container->getDefinition('twig'); $parameters = array( CravlerRemoteExtension::CONFIG_KEY . '.app_port', ); foreach ($parameters as $key) { list($listen, $connect) = explode(':', $container->getParameter($key) . ':'); $def->addMethodCall('addGlobal', array( str_replace('.', '_', $key), $connect ?: $listen )); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "def", "=", "$", "container", "->", "getDefinition", "(", "'twig'", ")", ";", "$", "parameters", "=", "array", "(", "CravlerRemoteExtension", "::", "CONFIG_KEY", ".", "'.app_port'", ",", ")", ";", "foreach", "(", "$", "parameters", "as", "$", "key", ")", "{", "list", "(", "$", "listen", ",", "$", "connect", ")", "=", "explode", "(", "':'", ",", "$", "container", "->", "getParameter", "(", "$", "key", ")", ".", "':'", ")", ";", "$", "def", "->", "addMethodCall", "(", "'addGlobal'", ",", "array", "(", "str_replace", "(", "'.'", ",", "'_'", ",", "$", "key", ")", ",", "$", "connect", "?", ":", "$", "listen", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/cravler/CravlerRemoteBundle/blob/b13e182007850063781d277ab5b0e4e69d415e2b/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php#L17-L30
Xsaven/laravel-intelect-admin
src/Addons/Modules/Generators/FromModuleGenerator.php
FromModuleGenerator.generateFiles
public function generateFiles() { foreach ($this->getFiles() as $stub => $file) { $path = $this->module->getModulePath($this->getName()) . $file; if (!$this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } $this->filesystem->put($path, $this->getStubContents($stub)); } }
php
public function generateFiles() { foreach ($this->getFiles() as $stub => $file) { $path = $this->module->getModulePath($this->getName()) . $file; if (!$this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } $this->filesystem->put($path, $this->getStubContents($stub)); } }
[ "public", "function", "generateFiles", "(", ")", "{", "foreach", "(", "$", "this", "->", "getFiles", "(", ")", "as", "$", "stub", "=>", "$", "file", ")", "{", "$", "path", "=", "$", "this", "->", "module", "->", "getModulePath", "(", "$", "this", "->", "getName", "(", ")", ")", ".", "$", "file", ";", "if", "(", "!", "$", "this", "->", "filesystem", "->", "isDirectory", "(", "$", "dir", "=", "dirname", "(", "$", "path", ")", ")", ")", "{", "$", "this", "->", "filesystem", "->", "makeDirectory", "(", "$", "dir", ",", "0775", ",", "true", ")", ";", "}", "$", "this", "->", "filesystem", "->", "put", "(", "$", "path", ",", "$", "this", "->", "getStubContents", "(", "$", "stub", ")", ")", ";", "}", "}" ]
Generate the files.
[ "Generate", "the", "files", "." ]
train
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Modules/Generators/FromModuleGenerator.php#L282-L293
Xsaven/laravel-intelect-admin
src/Addons/Modules/Generators/FromModuleGenerator.php
FromModuleGenerator.generateResources
public function generateResources() { Artisan::call('module:make-seed', [ 'name' => $this->getName(), 'module' => $this->getName(), '--master' => true, ]); Artisan::call('module:make-provider', [ 'name' => $this->getName() . 'ServiceProvider', 'module' => $this->getName(), '--master' => true, ]); Artisan::call('module:make-controller', [ 'controller' => $this->getName() . 'Controller', 'module' => $this->getName(), ]); }
php
public function generateResources() { Artisan::call('module:make-seed', [ 'name' => $this->getName(), 'module' => $this->getName(), '--master' => true, ]); Artisan::call('module:make-provider', [ 'name' => $this->getName() . 'ServiceProvider', 'module' => $this->getName(), '--master' => true, ]); Artisan::call('module:make-controller', [ 'controller' => $this->getName() . 'Controller', 'module' => $this->getName(), ]); }
[ "public", "function", "generateResources", "(", ")", "{", "Artisan", "::", "call", "(", "'module:make-seed'", ",", "[", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'module'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'--master'", "=>", "true", ",", "]", ")", ";", "Artisan", "::", "call", "(", "'module:make-provider'", ",", "[", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ".", "'ServiceProvider'", ",", "'module'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'--master'", "=>", "true", ",", "]", ")", ";", "Artisan", "::", "call", "(", "'module:make-controller'", ",", "[", "'controller'", "=>", "$", "this", "->", "getName", "(", ")", ".", "'Controller'", ",", "'module'", "=>", "$", "this", "->", "getName", "(", ")", ",", "]", ")", ";", "}" ]
Generate some resources.
[ "Generate", "some", "resources", "." ]
train
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Modules/Generators/FromModuleGenerator.php#L298-L317
Xsaven/laravel-intelect-admin
src/Addons/Modules/Generators/FromModuleGenerator.php
FromModuleGenerator.generateModuleJsonFile
private function generateModuleJsonFile() { $path = $this->module->getModulePath($this->getName()) . 'module.json'; if (!$this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } $this->filesystem->put($path, $this->getStubContents('json')); }
php
private function generateModuleJsonFile() { $path = $this->module->getModulePath($this->getName()) . 'module.json'; if (!$this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } $this->filesystem->put($path, $this->getStubContents('json')); }
[ "private", "function", "generateModuleJsonFile", "(", ")", "{", "$", "path", "=", "$", "this", "->", "module", "->", "getModulePath", "(", "$", "this", "->", "getName", "(", ")", ")", ".", "'module.json'", ";", "if", "(", "!", "$", "this", "->", "filesystem", "->", "isDirectory", "(", "$", "dir", "=", "dirname", "(", "$", "path", ")", ")", ")", "{", "$", "this", "->", "filesystem", "->", "makeDirectory", "(", "$", "dir", ",", "0775", ",", "true", ")", ";", "}", "$", "this", "->", "filesystem", "->", "put", "(", "$", "path", ",", "$", "this", "->", "getStubContents", "(", "'json'", ")", ")", ";", "}" ]
Generate the module.json file
[ "Generate", "the", "module", ".", "json", "file" ]
train
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Modules/Generators/FromModuleGenerator.php#L376-L385
Erebot/Timer
src/Timer.php
Timer.cleanup
protected function cleanup() { if ($this->resource) { proc_terminate($this->resource); } if (is_resource($this->handle)) { fclose($this->handle); } $this->handle = null; $this->resource = null; }
php
protected function cleanup() { if ($this->resource) { proc_terminate($this->resource); } if (is_resource($this->handle)) { fclose($this->handle); } $this->handle = null; $this->resource = null; }
[ "protected", "function", "cleanup", "(", ")", "{", "if", "(", "$", "this", "->", "resource", ")", "{", "proc_terminate", "(", "$", "this", "->", "resource", ")", ";", "}", "if", "(", "is_resource", "(", "$", "this", "->", "handle", ")", ")", "{", "fclose", "(", "$", "this", "->", "handle", ")", ";", "}", "$", "this", "->", "handle", "=", "null", ";", "$", "this", "->", "resource", "=", "null", ";", "}" ]
Performs cleanup duties so that no traces of this timer having ever been used remain.
[ "Performs", "cleanup", "duties", "so", "that", "no", "traces", "of", "this", "timer", "having", "ever", "been", "used", "remain", "." ]
train
https://github.com/Erebot/Timer/blob/cd04905d859221f9e216deba25693bc8906441f5/src/Timer.php#L123-L135
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.setAttribute
public function setAttribute($name, $value) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } $this->tag_attributes[strtolower($name)] = $value; return $this; }
php
public function setAttribute($name, $value) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } $this->tag_attributes[strtolower($name)] = $value; return $this; }
[ "public", "function", "setAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "strlen", "(", "$", "name", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Attribute name is empty\"", ")", ";", "}", "$", "this", "->", "tag_attributes", "[", "strtolower", "(", "$", "name", ")", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Sets the attribute of this tag to the value given, a value of NULL will list the attribute with no ="value" after @param string $name @param string|null $value @return HTMLTag @throws HTMLTagException
[ "Sets", "the", "attribute", "of", "this", "tag", "to", "the", "value", "given", "a", "value", "of", "NULL", "will", "list", "the", "attribute", "with", "no", "=", "value", "after" ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L77-L87
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.getAttribute
public function getAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } if(!isset($this->tag_attributes[strtolower($name)])) { return null; } return $this->tag_attributes[strtolower($name)]; }
php
public function getAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } if(!isset($this->tag_attributes[strtolower($name)])) { return null; } return $this->tag_attributes[strtolower($name)]; }
[ "public", "function", "getAttribute", "(", "$", "name", ")", "{", "if", "(", "strlen", "(", "$", "name", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Attribute name is empty\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "tag_attributes", "[", "strtolower", "(", "$", "name", ")", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "tag_attributes", "[", "strtolower", "(", "$", "name", ")", "]", ";", "}" ]
Returns the value of the given attribute @param string $name @return null|string @throws HTMLTagException
[ "Returns", "the", "value", "of", "the", "given", "attribute" ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L95-L108
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.removeAttribute
public function removeAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } unset($this->tag_attributes[strtolower($name)]); return $this; }
php
public function removeAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } unset($this->tag_attributes[strtolower($name)]); return $this; }
[ "public", "function", "removeAttribute", "(", "$", "name", ")", "{", "if", "(", "strlen", "(", "$", "name", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Attribute name is empty\"", ")", ";", "}", "unset", "(", "$", "this", "->", "tag_attributes", "[", "strtolower", "(", "$", "name", ")", "]", ")", ";", "return", "$", "this", ";", "}" ]
Removes the attribute from the tag, along with its value. @param string $name @return HTMLTag @throws HTMLTagException
[ "Removes", "the", "attribute", "from", "the", "tag", "along", "with", "its", "value", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L117-L127
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.hasAttribute
public function hasAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } return (isset($this->tag_attributes[strtolower($name)])) ? true : false; }
php
public function hasAttribute($name) { if(strlen($name) < 1) { throw new HTMLTagException("Attribute name is empty"); } return (isset($this->tag_attributes[strtolower($name)])) ? true : false; }
[ "public", "function", "hasAttribute", "(", "$", "name", ")", "{", "if", "(", "strlen", "(", "$", "name", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Attribute name is empty\"", ")", ";", "}", "return", "(", "isset", "(", "$", "this", "->", "tag_attributes", "[", "strtolower", "(", "$", "name", ")", "]", ")", ")", "?", "true", ":", "false", ";", "}" ]
Returns true/false depending on if the attribute name exists. @param string $name @return bool @throws HTMLTagException
[ "Returns", "true", "/", "false", "depending", "on", "if", "the", "attribute", "name", "exists", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L135-L143
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.addClass
public function addClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } if(!$this->hasClass($className)) { $classes = $this->getClasses() . " " . $this->removeMultipleSpaces(trim($className)); $this->setAttribute("class",trim($classes)); } return $this; }
php
public function addClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } if(!$this->hasClass($className)) { $classes = $this->getClasses() . " " . $this->removeMultipleSpaces(trim($className)); $this->setAttribute("class",trim($classes)); } return $this; }
[ "public", "function", "addClass", "(", "$", "className", ")", "{", "if", "(", "strlen", "(", "$", "className", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Class name is empty\"", ")", ";", "}", "if", "(", "!", "$", "this", "->", "hasClass", "(", "$", "className", ")", ")", "{", "$", "classes", "=", "$", "this", "->", "getClasses", "(", ")", ".", "\" \"", ".", "$", "this", "->", "removeMultipleSpaces", "(", "trim", "(", "$", "className", ")", ")", ";", "$", "this", "->", "setAttribute", "(", "\"class\"", ",", "trim", "(", "$", "classes", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a class name to the class attribute, this won't add duplicates. @param string $className @return HTMLTag @throws HTMLTagException
[ "Add", "a", "class", "name", "to", "the", "class", "attribute", "this", "won", "t", "add", "duplicates", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L163-L177
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.removeClass
public function removeClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } $classes = explode(" ", $this->getClasses()); $this->clearClasses(); foreach($classes as $class) { if(strtolower($class) != strtolower($className)) { $this->addClass($class); } } return $this; }
php
public function removeClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } $classes = explode(" ", $this->getClasses()); $this->clearClasses(); foreach($classes as $class) { if(strtolower($class) != strtolower($className)) { $this->addClass($class); } } return $this; }
[ "public", "function", "removeClass", "(", "$", "className", ")", "{", "if", "(", "strlen", "(", "$", "className", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Class name is empty\"", ")", ";", "}", "$", "classes", "=", "explode", "(", "\" \"", ",", "$", "this", "->", "getClasses", "(", ")", ")", ";", "$", "this", "->", "clearClasses", "(", ")", ";", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "if", "(", "strtolower", "(", "$", "class", ")", "!=", "strtolower", "(", "$", "className", ")", ")", "{", "$", "this", "->", "addClass", "(", "$", "class", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Removes the specified class name. @param string $className @return HTMLTag @throws HTMLTagException
[ "Removes", "the", "specified", "class", "name", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L196-L214
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.hasClass
public function hasClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } if($this->hasAttribute("class")) { $classes = $this->getClasses(); foreach(explode(" ",$classes) as $class) { if(strtolower($class) == strtolower($className)) { return true; // We found it. } } } return false; }
php
public function hasClass($className) { if(strlen($className) < 1) { throw new HTMLTagException("Class name is empty"); } if($this->hasAttribute("class")) { $classes = $this->getClasses(); foreach(explode(" ",$classes) as $class) { if(strtolower($class) == strtolower($className)) { return true; // We found it. } } } return false; }
[ "public", "function", "hasClass", "(", "$", "className", ")", "{", "if", "(", "strlen", "(", "$", "className", ")", "<", "1", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Class name is empty\"", ")", ";", "}", "if", "(", "$", "this", "->", "hasAttribute", "(", "\"class\"", ")", ")", "{", "$", "classes", "=", "$", "this", "->", "getClasses", "(", ")", ";", "foreach", "(", "explode", "(", "\" \"", ",", "$", "classes", ")", "as", "$", "class", ")", "{", "if", "(", "strtolower", "(", "$", "class", ")", "==", "strtolower", "(", "$", "className", ")", ")", "{", "return", "true", ";", "// We found it.", "}", "}", "}", "return", "false", ";", "}" ]
Checks to see if the given class name is inside of the class attribute @param string $className @return bool @throws HTMLTagException
[ "Checks", "to", "see", "if", "the", "given", "class", "name", "is", "inside", "of", "the", "class", "attribute" ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L222-L242
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.getClasses
public function getClasses() { $classes = $this->getAttribute("class"); return (strlen($classes) > 0) ? trim($this->removeMultipleSpaces($classes)) : ""; }
php
public function getClasses() { $classes = $this->getAttribute("class"); return (strlen($classes) > 0) ? trim($this->removeMultipleSpaces($classes)) : ""; }
[ "public", "function", "getClasses", "(", ")", "{", "$", "classes", "=", "$", "this", "->", "getAttribute", "(", "\"class\"", ")", ";", "return", "(", "strlen", "(", "$", "classes", ")", ">", "0", ")", "?", "trim", "(", "$", "this", "->", "removeMultipleSpaces", "(", "$", "classes", ")", ")", ":", "\"\"", ";", "}" ]
Returns a space separated string of classes belonging to the tag. @return string @throws HTMLTagException
[ "Returns", "a", "space", "separated", "string", "of", "classes", "belonging", "to", "the", "tag", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L249-L253
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.appendContent
public function appendContent($content) { if(!is_string($content) && !($content instanceof self)) { throw new HTMLTagException("Only HTMLTags and strings are allowed as content."); } $this->tag_content[] = $content; $this->setClosingTag(true); return $this; }
php
public function appendContent($content) { if(!is_string($content) && !($content instanceof self)) { throw new HTMLTagException("Only HTMLTags and strings are allowed as content."); } $this->tag_content[] = $content; $this->setClosingTag(true); return $this; }
[ "public", "function", "appendContent", "(", "$", "content", ")", "{", "if", "(", "!", "is_string", "(", "$", "content", ")", "&&", "!", "(", "$", "content", "instanceof", "self", ")", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Only HTMLTags and strings are allowed as content.\"", ")", ";", "}", "$", "this", "->", "tag_content", "[", "]", "=", "$", "content", ";", "$", "this", "->", "setClosingTag", "(", "true", ")", ";", "return", "$", "this", ";", "}" ]
Adds content inside of a tag and places it in the last slot, NOTE: performing this will automatically add a closing tag. @param self|string $content @return HTMLTag @throws HTMLTagException
[ "Adds", "content", "inside", "of", "a", "tag", "and", "places", "it", "in", "the", "last", "slot", "NOTE", ":", "performing", "this", "will", "automatically", "add", "a", "closing", "tag", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L262-L274
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.prependContent
public function prependContent($content) { if(!is_string($content) && !($content instanceof self)) { throw new HTMLTagException("Only HTMLTags and strings are allowed as content."); } array_unshift($this->tag_content,$content); $this->setClosingTag(true); return $this; }
php
public function prependContent($content) { if(!is_string($content) && !($content instanceof self)) { throw new HTMLTagException("Only HTMLTags and strings are allowed as content."); } array_unshift($this->tag_content,$content); $this->setClosingTag(true); return $this; }
[ "public", "function", "prependContent", "(", "$", "content", ")", "{", "if", "(", "!", "is_string", "(", "$", "content", ")", "&&", "!", "(", "$", "content", "instanceof", "self", ")", ")", "{", "throw", "new", "HTMLTagException", "(", "\"Only HTMLTags and strings are allowed as content.\"", ")", ";", "}", "array_unshift", "(", "$", "this", "->", "tag_content", ",", "$", "content", ")", ";", "$", "this", "->", "setClosingTag", "(", "true", ")", ";", "return", "$", "this", ";", "}" ]
Adds content inside of a tag and places it in the first slot, NOTE: performing this will automatically add a closing tag. @param self|string $content @return HTMLTag @throws HTMLTagException
[ "Adds", "content", "inside", "of", "a", "tag", "and", "places", "it", "in", "the", "first", "slot", "NOTE", ":", "performing", "this", "will", "automatically", "add", "a", "closing", "tag", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L283-L295
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.getFormattedAttributes
public function getFormattedAttributes() { $rtn = ""; foreach($this->listAttributes() as $name => $value) { $rtn .= sprintf(" %s=\"%s\"",htmlentities($name),htmlentities($value)); } return $rtn; }
php
public function getFormattedAttributes() { $rtn = ""; foreach($this->listAttributes() as $name => $value) { $rtn .= sprintf(" %s=\"%s\"",htmlentities($name),htmlentities($value)); } return $rtn; }
[ "public", "function", "getFormattedAttributes", "(", ")", "{", "$", "rtn", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "listAttributes", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "rtn", ".=", "sprintf", "(", "\" %s=\\\"%s\\\"\"", ",", "htmlentities", "(", "$", "name", ")", ",", "htmlentities", "(", "$", "value", ")", ")", ";", "}", "return", "$", "rtn", ";", "}" ]
Format and return attributes in a name="value" format as it should appear in an HTML tag. @return string
[ "Format", "and", "return", "attributes", "in", "a", "name", "=", "value", "format", "as", "it", "should", "appear", "in", "an", "HTML", "tag", "." ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L380-L388
Gercoli/HTMLTags
src/HTMLTag.php
HTMLTag.setTagPrefix
public function setTagPrefix($prefix) { if(!is_string($prefix) && $prefix !== null) { throw new HTMLTagException("The tag prefix must be a string or null."); } $this->tag_prefix_previous = $this->getTagPrefix(); $this->tag_prefix = $prefix; return $this; }
php
public function setTagPrefix($prefix) { if(!is_string($prefix) && $prefix !== null) { throw new HTMLTagException("The tag prefix must be a string or null."); } $this->tag_prefix_previous = $this->getTagPrefix(); $this->tag_prefix = $prefix; return $this; }
[ "public", "function", "setTagPrefix", "(", "$", "prefix", ")", "{", "if", "(", "!", "is_string", "(", "$", "prefix", ")", "&&", "$", "prefix", "!==", "null", ")", "{", "throw", "new", "HTMLTagException", "(", "\"The tag prefix must be a string or null.\"", ")", ";", "}", "$", "this", "->", "tag_prefix_previous", "=", "$", "this", "->", "getTagPrefix", "(", ")", ";", "$", "this", "->", "tag_prefix", "=", "$", "prefix", ";", "return", "$", "this", ";", "}" ]
Sets the string that should precede a tag @param string|null $prefix @return HTMLTag @throws HTMLTagException
[ "Sets", "the", "string", "that", "should", "precede", "a", "tag" ]
train
https://github.com/Gercoli/HTMLTags/blob/795c4c1bab405d1387406a4da0e2884f4314b2ce/src/HTMLTag.php#L396-L408
benjamindulau/AnoDataGrid
src/Ano/DataGrid/DataGrid.php
DataGrid.addColumn
public function addColumn(ColumnInterface $column) { $column->setGrid($this); $this->columns[$column->getName()] = $column; return $this; }
php
public function addColumn(ColumnInterface $column) { $column->setGrid($this); $this->columns[$column->getName()] = $column; return $this; }
[ "public", "function", "addColumn", "(", "ColumnInterface", "$", "column", ")", "{", "$", "column", "->", "setGrid", "(", "$", "this", ")", ";", "$", "this", "->", "columns", "[", "$", "column", "->", "getName", "(", ")", "]", "=", "$", "column", ";", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/benjamindulau/AnoDataGrid/blob/69b31803929b04e9d6e807bb2213b9b3477d0367/src/Ano/DataGrid/DataGrid.php#L30-L36
benjamindulau/AnoDataGrid
src/Ano/DataGrid/DataGrid.php
DataGrid.getColumn
public function getColumn($name) { if (!$this->hasColumn($name)) { throw new DataGridException(sprintf('The column "%s" does not exist', $name)); } return $this->columns[$name]; }
php
public function getColumn($name) { if (!$this->hasColumn($name)) { throw new DataGridException(sprintf('The column "%s" does not exist', $name)); } return $this->columns[$name]; }
[ "public", "function", "getColumn", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "hasColumn", "(", "$", "name", ")", ")", "{", "throw", "new", "DataGridException", "(", "sprintf", "(", "'The column \"%s\" does not exist'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "columns", "[", "$", "name", "]", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/benjamindulau/AnoDataGrid/blob/69b31803929b04e9d6e807bb2213b9b3477d0367/src/Ano/DataGrid/DataGrid.php#L41-L48
benjamindulau/AnoDataGrid
src/Ano/DataGrid/DataGrid.php
DataGrid.setData
public function setData($data) { if (!is_object($data) && !is_array($data)) { throw new UnexpectedTypeException($data, 'array or object'); } $this->data = $data; // $this->prepareRows(); }
php
public function setData($data) { if (!is_object($data) && !is_array($data)) { throw new UnexpectedTypeException($data, 'array or object'); } $this->data = $data; // $this->prepareRows(); }
[ "public", "function", "setData", "(", "$", "data", ")", "{", "if", "(", "!", "is_object", "(", "$", "data", ")", "&&", "!", "is_array", "(", "$", "data", ")", ")", "{", "throw", "new", "UnexpectedTypeException", "(", "$", "data", ",", "'array or object'", ")", ";", "}", "$", "this", "->", "data", "=", "$", "data", ";", "// $this->prepareRows();\r", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/benjamindulau/AnoDataGrid/blob/69b31803929b04e9d6e807bb2213b9b3477d0367/src/Ano/DataGrid/DataGrid.php#L72-L80
benjamindulau/AnoDataGrid
src/Ano/DataGrid/DataGrid.php
DataGrid.createView
public function createView() { $view = new DataGridView(); foreach($this->columns as $column) { $columnView = $column->createView($view); $view->addColumn($column->getName(), $columnView); } $view ->set('dataGrid', $view) ->set('data', $this->getData()) ; return $view; }
php
public function createView() { $view = new DataGridView(); foreach($this->columns as $column) { $columnView = $column->createView($view); $view->addColumn($column->getName(), $columnView); } $view ->set('dataGrid', $view) ->set('data', $this->getData()) ; return $view; }
[ "public", "function", "createView", "(", ")", "{", "$", "view", "=", "new", "DataGridView", "(", ")", ";", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", ")", "{", "$", "columnView", "=", "$", "column", "->", "createView", "(", "$", "view", ")", ";", "$", "view", "->", "addColumn", "(", "$", "column", "->", "getName", "(", ")", ",", "$", "columnView", ")", ";", "}", "$", "view", "->", "set", "(", "'dataGrid'", ",", "$", "view", ")", "->", "set", "(", "'data'", ",", "$", "this", "->", "getData", "(", ")", ")", ";", "return", "$", "view", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/benjamindulau/AnoDataGrid/blob/69b31803929b04e9d6e807bb2213b9b3477d0367/src/Ano/DataGrid/DataGrid.php#L93-L108
wasinger/adaptimage
src/ImageResizer.php
ImageResizer.resize
public function resize(ImageResizeDefinition $image_resize_definition, ImageFileInfo $image, $really_do_it = false, $pre_transformation = null) { if ($image->getOrientation() != 1) { if ($pre_transformation == null) { $pre_transformation = new FilterChain($this->imagine); } $pre_transformation->add(new FixOrientation($image->getOrientation())); } $outputTypeOptions = $image_resize_definition->getOutputTypeMap()->getOutputTypeOptions($image->getImagetype()); $cachepath = $this->output_path_generator->getOutputPathname( $image, $image_resize_definition, $outputTypeOptions->getExtension(false), $pre_transformation ); // if cached file already exists just return it if (file_exists($cachepath) && filemtime($cachepath) > $image->getFilemtime()) { return ImageFileInfo::createFromFile($cachepath); } if ($pre_transformation instanceof FilterChain) { $transformation = new FilterChain($this->imagine); $transformation->append($pre_transformation); $transformation->append($image_resize_definition->getResizeTransformation()); } else { $transformation = $image_resize_definition->getResizeTransformation(); } $post_transformation = $image_resize_definition->getPostTransformation(); if (!$really_do_it) { // calculate size after transformation $size = $transformation->calculateSize(new Box($image->getWidth(), $image->getHeight())); return new ImageFileInfo($cachepath, $size->getWidth(), $size->getHeight(), $outputTypeOptions->getType(), 0); } // check whether original file exists if (!$image->fileExists()) { throw new ImageFileNotFoundException($image->getPathname()); } $count = 0; while ($this->_doTransform($image, $transformation, $outputTypeOptions, $post_transformation, $cachepath) === false) { if ($count > 4) { throw new ImageResizingFailedException('Could not generate Thumbnail'); } sleep(2); $count++; } return ImageFileInfo::createFromFile($cachepath); }
php
public function resize(ImageResizeDefinition $image_resize_definition, ImageFileInfo $image, $really_do_it = false, $pre_transformation = null) { if ($image->getOrientation() != 1) { if ($pre_transformation == null) { $pre_transformation = new FilterChain($this->imagine); } $pre_transformation->add(new FixOrientation($image->getOrientation())); } $outputTypeOptions = $image_resize_definition->getOutputTypeMap()->getOutputTypeOptions($image->getImagetype()); $cachepath = $this->output_path_generator->getOutputPathname( $image, $image_resize_definition, $outputTypeOptions->getExtension(false), $pre_transformation ); // if cached file already exists just return it if (file_exists($cachepath) && filemtime($cachepath) > $image->getFilemtime()) { return ImageFileInfo::createFromFile($cachepath); } if ($pre_transformation instanceof FilterChain) { $transformation = new FilterChain($this->imagine); $transformation->append($pre_transformation); $transformation->append($image_resize_definition->getResizeTransformation()); } else { $transformation = $image_resize_definition->getResizeTransformation(); } $post_transformation = $image_resize_definition->getPostTransformation(); if (!$really_do_it) { // calculate size after transformation $size = $transformation->calculateSize(new Box($image->getWidth(), $image->getHeight())); return new ImageFileInfo($cachepath, $size->getWidth(), $size->getHeight(), $outputTypeOptions->getType(), 0); } // check whether original file exists if (!$image->fileExists()) { throw new ImageFileNotFoundException($image->getPathname()); } $count = 0; while ($this->_doTransform($image, $transformation, $outputTypeOptions, $post_transformation, $cachepath) === false) { if ($count > 4) { throw new ImageResizingFailedException('Could not generate Thumbnail'); } sleep(2); $count++; } return ImageFileInfo::createFromFile($cachepath); }
[ "public", "function", "resize", "(", "ImageResizeDefinition", "$", "image_resize_definition", ",", "ImageFileInfo", "$", "image", ",", "$", "really_do_it", "=", "false", ",", "$", "pre_transformation", "=", "null", ")", "{", "if", "(", "$", "image", "->", "getOrientation", "(", ")", "!=", "1", ")", "{", "if", "(", "$", "pre_transformation", "==", "null", ")", "{", "$", "pre_transformation", "=", "new", "FilterChain", "(", "$", "this", "->", "imagine", ")", ";", "}", "$", "pre_transformation", "->", "add", "(", "new", "FixOrientation", "(", "$", "image", "->", "getOrientation", "(", ")", ")", ")", ";", "}", "$", "outputTypeOptions", "=", "$", "image_resize_definition", "->", "getOutputTypeMap", "(", ")", "->", "getOutputTypeOptions", "(", "$", "image", "->", "getImagetype", "(", ")", ")", ";", "$", "cachepath", "=", "$", "this", "->", "output_path_generator", "->", "getOutputPathname", "(", "$", "image", ",", "$", "image_resize_definition", ",", "$", "outputTypeOptions", "->", "getExtension", "(", "false", ")", ",", "$", "pre_transformation", ")", ";", "// if cached file already exists just return it", "if", "(", "file_exists", "(", "$", "cachepath", ")", "&&", "filemtime", "(", "$", "cachepath", ")", ">", "$", "image", "->", "getFilemtime", "(", ")", ")", "{", "return", "ImageFileInfo", "::", "createFromFile", "(", "$", "cachepath", ")", ";", "}", "if", "(", "$", "pre_transformation", "instanceof", "FilterChain", ")", "{", "$", "transformation", "=", "new", "FilterChain", "(", "$", "this", "->", "imagine", ")", ";", "$", "transformation", "->", "append", "(", "$", "pre_transformation", ")", ";", "$", "transformation", "->", "append", "(", "$", "image_resize_definition", "->", "getResizeTransformation", "(", ")", ")", ";", "}", "else", "{", "$", "transformation", "=", "$", "image_resize_definition", "->", "getResizeTransformation", "(", ")", ";", "}", "$", "post_transformation", "=", "$", "image_resize_definition", "->", "getPostTransformation", "(", ")", ";", "if", "(", "!", "$", "really_do_it", ")", "{", "// calculate size after transformation", "$", "size", "=", "$", "transformation", "->", "calculateSize", "(", "new", "Box", "(", "$", "image", "->", "getWidth", "(", ")", ",", "$", "image", "->", "getHeight", "(", ")", ")", ")", ";", "return", "new", "ImageFileInfo", "(", "$", "cachepath", ",", "$", "size", "->", "getWidth", "(", ")", ",", "$", "size", "->", "getHeight", "(", ")", ",", "$", "outputTypeOptions", "->", "getType", "(", ")", ",", "0", ")", ";", "}", "// check whether original file exists", "if", "(", "!", "$", "image", "->", "fileExists", "(", ")", ")", "{", "throw", "new", "ImageFileNotFoundException", "(", "$", "image", "->", "getPathname", "(", ")", ")", ";", "}", "$", "count", "=", "0", ";", "while", "(", "$", "this", "->", "_doTransform", "(", "$", "image", ",", "$", "transformation", ",", "$", "outputTypeOptions", ",", "$", "post_transformation", ",", "$", "cachepath", ")", "===", "false", ")", "{", "if", "(", "$", "count", ">", "4", ")", "{", "throw", "new", "ImageResizingFailedException", "(", "'Could not generate Thumbnail'", ")", ";", "}", "sleep", "(", "2", ")", ";", "$", "count", "++", ";", "}", "return", "ImageFileInfo", "::", "createFromFile", "(", "$", "cachepath", ")", ";", "}" ]
Apply transformation to image. Return an ImageFileInfo object with information about the resulting file. If a cached version of this image/transformation combination already exists, the cached version will be returned. @param ImageResizeDefinition $image_resize_definition @param ImageFileInfo $image @param bool $really_do_it If false, the image will not be really processed, but instead the resulting size is calculated @param FilterChain|null $pre_transformation Custom Transformation for this image that will be applied before the resizing transformation Used for image rotation and custom thumbnail crops @return ImageFileInfo|static @throws ImageFileNotFoundException If the original image file does not exist or is not readable @throws ImageResizingFailedException If the image could not be resized
[ "Apply", "transformation", "to", "image", ".", "Return", "an", "ImageFileInfo", "object", "with", "information", "about", "the", "resulting", "file", ".", "If", "a", "cached", "version", "of", "this", "image", "/", "transformation", "combination", "already", "exists", "the", "cached", "version", "will", "be", "returned", "." ]
train
https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImageResizer.php#L53-L106
chalasr/RCHCapistranoBundle
Generator/DeployGenerator.php
DeployGenerator.write
public function write() { foreach ($this->parameters as $prop => $value) { $placeHolders[] = sprintf('<%s>', $prop); $replacements[] = $value; } $config = str_replace($placeHolders, $replacements, self::$configTemplate); $config = sprintf('%s%s%s', self::$defaultConfigTemplate, PHP_EOL, $config); if (true === $this->parameters['composer']) { $config = sprintf('%s%s%s', $config, PHP_EOL, self::$downloadComposerTaskTemplate); } if (true === $this->parameters['schemadb']) { $config = sprintf('%s%s%s', $config, PHP_EOL, self::$updateSchemaTaskTemplate); } fwrite($this->file, $this->addHeaders($config)); }
php
public function write() { foreach ($this->parameters as $prop => $value) { $placeHolders[] = sprintf('<%s>', $prop); $replacements[] = $value; } $config = str_replace($placeHolders, $replacements, self::$configTemplate); $config = sprintf('%s%s%s', self::$defaultConfigTemplate, PHP_EOL, $config); if (true === $this->parameters['composer']) { $config = sprintf('%s%s%s', $config, PHP_EOL, self::$downloadComposerTaskTemplate); } if (true === $this->parameters['schemadb']) { $config = sprintf('%s%s%s', $config, PHP_EOL, self::$updateSchemaTaskTemplate); } fwrite($this->file, $this->addHeaders($config)); }
[ "public", "function", "write", "(", ")", "{", "foreach", "(", "$", "this", "->", "parameters", "as", "$", "prop", "=>", "$", "value", ")", "{", "$", "placeHolders", "[", "]", "=", "sprintf", "(", "'<%s>'", ",", "$", "prop", ")", ";", "$", "replacements", "[", "]", "=", "$", "value", ";", "}", "$", "config", "=", "str_replace", "(", "$", "placeHolders", ",", "$", "replacements", ",", "self", "::", "$", "configTemplate", ")", ";", "$", "config", "=", "sprintf", "(", "'%s%s%s'", ",", "self", "::", "$", "defaultConfigTemplate", ",", "PHP_EOL", ",", "$", "config", ")", ";", "if", "(", "true", "===", "$", "this", "->", "parameters", "[", "'composer'", "]", ")", "{", "$", "config", "=", "sprintf", "(", "'%s%s%s'", ",", "$", "config", ",", "PHP_EOL", ",", "self", "::", "$", "downloadComposerTaskTemplate", ")", ";", "}", "if", "(", "true", "===", "$", "this", "->", "parameters", "[", "'schemadb'", "]", ")", "{", "$", "config", "=", "sprintf", "(", "'%s%s%s'", ",", "$", "config", ",", "PHP_EOL", ",", "self", "::", "$", "updateSchemaTaskTemplate", ")", ";", "}", "fwrite", "(", "$", "this", "->", "file", ",", "$", "this", "->", "addHeaders", "(", "$", "config", ")", ")", ";", "}" ]
Writes deployment file.
[ "Writes", "deployment", "file", "." ]
train
https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Generator/DeployGenerator.php#L111-L130
Innmind/Socket
src/Server/Unix.php
Unix.recoverable
public static function recoverable(Address $path): self { try { return new self($path); } catch (FailedToOpenSocket $e) { @unlink((string) $path); return new self($path); } }
php
public static function recoverable(Address $path): self { try { return new self($path); } catch (FailedToOpenSocket $e) { @unlink((string) $path); return new self($path); } }
[ "public", "static", "function", "recoverable", "(", "Address", "$", "path", ")", ":", "self", "{", "try", "{", "return", "new", "self", "(", "$", "path", ")", ";", "}", "catch", "(", "FailedToOpenSocket", "$", "e", ")", "{", "@", "unlink", "(", "(", "string", ")", "$", "path", ")", ";", "return", "new", "self", "(", "$", "path", ")", ";", "}", "}" ]
On open failure it will try to delete existing socket file the ntry to reopen the socket connection
[ "On", "open", "failure", "it", "will", "try", "to", "delete", "existing", "socket", "file", "the", "ntry", "to", "reopen", "the", "socket", "connection" ]
train
https://github.com/Innmind/Socket/blob/4d05c841d85ccbde7bfdaeafc6930970923bab84/src/Server/Unix.php#L49-L58
romm/configuration_object
Classes/Validation/Validator/ClassExistsValidator.php
ClassExistsValidator.isValid
public function isValid($value) { if (false === Core::get()->classExists($value)) { $errorMessage = $this->translateErrorMessage('validator.class_exists.not_valid', 'configuration_object', [$value]); $this->addError($errorMessage, 1457610460); } }
php
public function isValid($value) { if (false === Core::get()->classExists($value)) { $errorMessage = $this->translateErrorMessage('validator.class_exists.not_valid', 'configuration_object', [$value]); $this->addError($errorMessage, 1457610460); } }
[ "public", "function", "isValid", "(", "$", "value", ")", "{", "if", "(", "false", "===", "Core", "::", "get", "(", ")", "->", "classExists", "(", "$", "value", ")", ")", "{", "$", "errorMessage", "=", "$", "this", "->", "translateErrorMessage", "(", "'validator.class_exists.not_valid'", ",", "'configuration_object'", ",", "[", "$", "value", "]", ")", ";", "$", "this", "->", "addError", "(", "$", "errorMessage", ",", "1457610460", ")", ";", "}", "}" ]
Checks if the value is an existing class. @param mixed $value The value that should be validated.
[ "Checks", "if", "the", "value", "is", "an", "existing", "class", "." ]
train
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/Validator/ClassExistsValidator.php#L27-L33
phossa/phossa-di
src/Phossa/Di/Container.php
Container.get
public function get($id) { if ($this->has($id)) { // prepare constructor arguments and scope list($args, $scope, $sid) = $this->prepareArguments( $id, func_get_args() ); // try get from pool first if (empty($args) && isset($this->pool[$sid])) { // get service from the pool return $this->pool[$sid]; // not in pool, create the service } else { // circular detection $this->checkCircularMark($id); // create service base on definition $service = $this->serviceFromDefinition($id, $args); // remove circular detection mark $this->removeCircularMark($id); // store service in the pool if (static::SCOPE_SINGLE !== $scope) { $this->pool[$sid] = $service; } return $service; } } else { throw new NotFoundException( Message::get(Message::SERVICE_ID_NOT_FOUND, $id), Message::SERVICE_ID_NOT_FOUND ); } }
php
public function get($id) { if ($this->has($id)) { // prepare constructor arguments and scope list($args, $scope, $sid) = $this->prepareArguments( $id, func_get_args() ); // try get from pool first if (empty($args) && isset($this->pool[$sid])) { // get service from the pool return $this->pool[$sid]; // not in pool, create the service } else { // circular detection $this->checkCircularMark($id); // create service base on definition $service = $this->serviceFromDefinition($id, $args); // remove circular detection mark $this->removeCircularMark($id); // store service in the pool if (static::SCOPE_SINGLE !== $scope) { $this->pool[$sid] = $service; } return $service; } } else { throw new NotFoundException( Message::get(Message::SERVICE_ID_NOT_FOUND, $id), Message::SERVICE_ID_NOT_FOUND ); } }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "// prepare constructor arguments and scope", "list", "(", "$", "args", ",", "$", "scope", ",", "$", "sid", ")", "=", "$", "this", "->", "prepareArguments", "(", "$", "id", ",", "func_get_args", "(", ")", ")", ";", "// try get from pool first", "if", "(", "empty", "(", "$", "args", ")", "&&", "isset", "(", "$", "this", "->", "pool", "[", "$", "sid", "]", ")", ")", "{", "// get service from the pool", "return", "$", "this", "->", "pool", "[", "$", "sid", "]", ";", "// not in pool, create the service", "}", "else", "{", "// circular detection", "$", "this", "->", "checkCircularMark", "(", "$", "id", ")", ";", "// create service base on definition", "$", "service", "=", "$", "this", "->", "serviceFromDefinition", "(", "$", "id", ",", "$", "args", ")", ";", "// remove circular detection mark", "$", "this", "->", "removeCircularMark", "(", "$", "id", ")", ";", "// store service in the pool", "if", "(", "static", "::", "SCOPE_SINGLE", "!==", "$", "scope", ")", "{", "$", "this", "->", "pool", "[", "$", "sid", "]", "=", "$", "service", ";", "}", "return", "$", "service", ";", "}", "}", "else", "{", "throw", "new", "NotFoundException", "(", "Message", "::", "get", "(", "Message", "::", "SERVICE_ID_NOT_FOUND", ",", "$", "id", ")", ",", "Message", "::", "SERVICE_ID_NOT_FOUND", ")", ";", "}", "}" ]
Accept second parameter $constructorArguments (array) Accept third parameter $inThisScope (string) {@inheritDoc}
[ "Accept", "second", "parameter", "$constructorArguments", "(", "array", ")", "Accept", "third", "parameter", "$inThisScope", "(", "string", ")" ]
train
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Container.php#L93-L132
phossa/phossa-di
src/Phossa/Di/Container.php
Container.has
public function has($id) { // second argument $withAutowiring = func_num_args() > 1 ? (bool) func_get_arg(1) : $this->autowiring; // return FALSE if $id not a string return is_string($id) && ( // found in definitions ? isset($this->services[$id]) || // Or in definition providers ? $this->hasInProvider($id) || // Or with id autowired ? $this->autoWiringId($id, $withAutowiring) ) ? true : false; }
php
public function has($id) { // second argument $withAutowiring = func_num_args() > 1 ? (bool) func_get_arg(1) : $this->autowiring; // return FALSE if $id not a string return is_string($id) && ( // found in definitions ? isset($this->services[$id]) || // Or in definition providers ? $this->hasInProvider($id) || // Or with id autowired ? $this->autoWiringId($id, $withAutowiring) ) ? true : false; }
[ "public", "function", "has", "(", "$", "id", ")", "{", "// second argument", "$", "withAutowiring", "=", "func_num_args", "(", ")", ">", "1", "?", "(", "bool", ")", "func_get_arg", "(", "1", ")", ":", "$", "this", "->", "autowiring", ";", "// return FALSE if $id not a string", "return", "is_string", "(", "$", "id", ")", "&&", "(", "// found in definitions ?", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", "||", "// Or in definition providers ?", "$", "this", "->", "hasInProvider", "(", "$", "id", ")", "||", "// Or with id autowired ?", "$", "this", "->", "autoWiringId", "(", "$", "id", ",", "$", "withAutowiring", ")", ")", "?", "true", ":", "false", ";", "}" ]
Accept second parameter $withAutowiring (bool) Non-string $id will return FALSE @inheritDoc
[ "Accept", "second", "parameter", "$withAutowiring", "(", "bool", ")" ]
train
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Container.php#L141-L158
phossa/phossa-di
src/Phossa/Di/Container.php
Container.prepareArguments
protected function prepareArguments(/*# string */ $id, array $arguments) { $args = isset($arguments[1]) ? (array) $arguments[1] : []; $scope = isset($arguments[2]) ? (string) $arguments[2] : $this->getScope($id); // scope === '@serviceId@' ? if (isset($this->circular[$scope])) { $scope .= '#' . $this->circular[$scope]; } return [ $args, $scope, $scope . '::' . $id ]; }
php
protected function prepareArguments(/*# string */ $id, array $arguments) { $args = isset($arguments[1]) ? (array) $arguments[1] : []; $scope = isset($arguments[2]) ? (string) $arguments[2] : $this->getScope($id); // scope === '@serviceId@' ? if (isset($this->circular[$scope])) { $scope .= '#' . $this->circular[$scope]; } return [ $args, $scope, $scope . '::' . $id ]; }
[ "protected", "function", "prepareArguments", "(", "/*# string */", "$", "id", ",", "array", "$", "arguments", ")", "{", "$", "args", "=", "isset", "(", "$", "arguments", "[", "1", "]", ")", "?", "(", "array", ")", "$", "arguments", "[", "1", "]", ":", "[", "]", ";", "$", "scope", "=", "isset", "(", "$", "arguments", "[", "2", "]", ")", "?", "(", "string", ")", "$", "arguments", "[", "2", "]", ":", "$", "this", "->", "getScope", "(", "$", "id", ")", ";", "// scope === '@serviceId@' ?", "if", "(", "isset", "(", "$", "this", "->", "circular", "[", "$", "scope", "]", ")", ")", "{", "$", "scope", ".=", "'#'", ".", "$", "this", "->", "circular", "[", "$", "scope", "]", ";", "}", "return", "[", "$", "args", ",", "$", "scope", ",", "$", "scope", ".", "'::'", ".", "$", "id", "]", ";", "}" ]
Process arguments for get() @param string $id service id @param array $arguments of get() @return array @access protected
[ "Process", "arguments", "for", "get", "()" ]
train
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Container.php#L186-L198
phossa/phossa-di
src/Phossa/Di/Container.php
Container.serviceFromDefinition
protected function serviceFromDefinition($id, $args) { // create the service object $service = $this->createServiceObject($id, $args); // run predefined methods if any $this->runDefinedMethods($id, $service); // decorate the service if DecorateExtension loaded $this->decorateService($service); return $service; }
php
protected function serviceFromDefinition($id, $args) { // create the service object $service = $this->createServiceObject($id, $args); // run predefined methods if any $this->runDefinedMethods($id, $service); // decorate the service if DecorateExtension loaded $this->decorateService($service); return $service; }
[ "protected", "function", "serviceFromDefinition", "(", "$", "id", ",", "$", "args", ")", "{", "// create the service object", "$", "service", "=", "$", "this", "->", "createServiceObject", "(", "$", "id", ",", "$", "args", ")", ";", "// run predefined methods if any", "$", "this", "->", "runDefinedMethods", "(", "$", "id", ",", "$", "service", ")", ";", "// decorate the service if DecorateExtension loaded", "$", "this", "->", "decorateService", "(", "$", "service", ")", ";", "return", "$", "service", ";", "}" ]
Check circular, create service and decorate service @param string $id service id @param array $args constructor arguments @return object @access protected
[ "Check", "circular", "create", "service", "and", "decorate", "service" ]
train
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Container.php#L208-L220
phossa/phossa-di
src/Phossa/Di/Container.php
Container.checkCircularMark
protected function checkCircularMark(/*# string */ $id) { // reference id "@$id@" of current service object $refId = $this->getServiceReferenceId($id); // circular detected if (isset($this->circular[$refId])) { throw new LogicException( Message::get(Message::SERVICE_CIRCULAR, $id), Message::SERVICE_CIRCULAR ); // mark it } else { $this->circular[$refId] = ++$this->counter; } }
php
protected function checkCircularMark(/*# string */ $id) { // reference id "@$id@" of current service object $refId = $this->getServiceReferenceId($id); // circular detected if (isset($this->circular[$refId])) { throw new LogicException( Message::get(Message::SERVICE_CIRCULAR, $id), Message::SERVICE_CIRCULAR ); // mark it } else { $this->circular[$refId] = ++$this->counter; } }
[ "protected", "function", "checkCircularMark", "(", "/*# string */", "$", "id", ")", "{", "// reference id \"@$id@\" of current service object", "$", "refId", "=", "$", "this", "->", "getServiceReferenceId", "(", "$", "id", ")", ";", "// circular detected", "if", "(", "isset", "(", "$", "this", "->", "circular", "[", "$", "refId", "]", ")", ")", "{", "throw", "new", "LogicException", "(", "Message", "::", "get", "(", "Message", "::", "SERVICE_CIRCULAR", ",", "$", "id", ")", ",", "Message", "::", "SERVICE_CIRCULAR", ")", ";", "// mark it", "}", "else", "{", "$", "this", "->", "circular", "[", "$", "refId", "]", "=", "++", "$", "this", "->", "counter", ";", "}", "}" ]
Check circular for get() @param string $id service id @return void @throws LogicException if circular found @access protected
[ "Check", "circular", "for", "get", "()" ]
train
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Container.php#L230-L246
sndsgd/http
src/http/request/Client.php
Client.getIp
public function getIp(): string { if ($this->ip === null) { foreach (["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR"] as $key) { $proxyIpList = $this->environment[$key] ?? ""; if ($proxyIpList) { $commaPosition = strpos($proxyIpList, ","); if ($commaPosition !== false) { $this->ip = substr($proxyIpList, 0, $commaPosition); } else { $this->ip = $proxyIpList; } return $this->ip; } } $this->ip = $this->environment["REMOTE_ADDR"] ?? ""; } return $this->ip; }
php
public function getIp(): string { if ($this->ip === null) { foreach (["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR"] as $key) { $proxyIpList = $this->environment[$key] ?? ""; if ($proxyIpList) { $commaPosition = strpos($proxyIpList, ","); if ($commaPosition !== false) { $this->ip = substr($proxyIpList, 0, $commaPosition); } else { $this->ip = $proxyIpList; } return $this->ip; } } $this->ip = $this->environment["REMOTE_ADDR"] ?? ""; } return $this->ip; }
[ "public", "function", "getIp", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "ip", "===", "null", ")", "{", "foreach", "(", "[", "\"HTTP_X_FORWARDED_FOR\"", ",", "\"X_FORWARDED_FOR\"", "]", "as", "$", "key", ")", "{", "$", "proxyIpList", "=", "$", "this", "->", "environment", "[", "$", "key", "]", "??", "\"\"", ";", "if", "(", "$", "proxyIpList", ")", "{", "$", "commaPosition", "=", "strpos", "(", "$", "proxyIpList", ",", "\",\"", ")", ";", "if", "(", "$", "commaPosition", "!==", "false", ")", "{", "$", "this", "->", "ip", "=", "substr", "(", "$", "proxyIpList", ",", "0", ",", "$", "commaPosition", ")", ";", "}", "else", "{", "$", "this", "->", "ip", "=", "$", "proxyIpList", ";", "}", "return", "$", "this", "->", "ip", ";", "}", "}", "$", "this", "->", "ip", "=", "$", "this", "->", "environment", "[", "\"REMOTE_ADDR\"", "]", "??", "\"\"", ";", "}", "return", "$", "this", "->", "ip", ";", "}" ]
Retrieve the client ip address @return string
[ "Retrieve", "the", "client", "ip", "address" ]
train
https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/request/Client.php#L42-L60
CalderaWP/caldera-interop
src/IteratableCollection.php
IteratableCollection.count
public function count(): int { $key = $this->storeKey(); if (! $this->isCountable($this->$key)) { return 0; } return count($this->$key); }
php
public function count(): int { $key = $this->storeKey(); if (! $this->isCountable($this->$key)) { return 0; } return count($this->$key); }
[ "public", "function", "count", "(", ")", ":", "int", "{", "$", "key", "=", "$", "this", "->", "storeKey", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isCountable", "(", "$", "this", "->", "$", "key", ")", ")", "{", "return", "0", ";", "}", "return", "count", "(", "$", "this", "->", "$", "key", ")", ";", "}" ]
Get size of collection @return int
[ "Get", "size", "of", "collection" ]
train
https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/IteratableCollection.php#L38-L45
CalderaWP/caldera-interop
src/IteratableCollection.php
IteratableCollection.increase
public function increase(int $size) { $count = $this->count(); if ($size > $this->count()) { $add = $size - $this->count(); $key = $this->storeKey(); for ($i = 0; $i < $add; $i++) { $this->addEmpty(); } } return $this; }
php
public function increase(int $size) { $count = $this->count(); if ($size > $this->count()) { $add = $size - $this->count(); $key = $this->storeKey(); for ($i = 0; $i < $add; $i++) { $this->addEmpty(); } } return $this; }
[ "public", "function", "increase", "(", "int", "$", "size", ")", "{", "$", "count", "=", "$", "this", "->", "count", "(", ")", ";", "if", "(", "$", "size", ">", "$", "this", "->", "count", "(", ")", ")", "{", "$", "add", "=", "$", "size", "-", "$", "this", "->", "count", "(", ")", ";", "$", "key", "=", "$", "this", "->", "storeKey", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "add", ";", "$", "i", "++", ")", "{", "$", "this", "->", "addEmpty", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Increase size of collection @param int $size @return $this
[ "Increase", "size", "of", "collection" ]
train
https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/IteratableCollection.php#L76-L88
artscorestudio/user-bundle
Repository/UserRepository.php
UserRepository.findByUsernameContains
public function findByUsernameContains($searched_term) { $qb = $this->createQueryBuilder('u'); $qb instanceof QueryBuilder; $qb->add('where', $qb->expr()->like('u.username', $qb->expr()->lower(':searched_term'))) ->setParameter('searched_term', $searched_term . '%'); return $qb->getQuery()->getResult(); }
php
public function findByUsernameContains($searched_term) { $qb = $this->createQueryBuilder('u'); $qb instanceof QueryBuilder; $qb->add('where', $qb->expr()->like('u.username', $qb->expr()->lower(':searched_term'))) ->setParameter('searched_term', $searched_term . '%'); return $qb->getQuery()->getResult(); }
[ "public", "function", "findByUsernameContains", "(", "$", "searched_term", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'u'", ")", ";", "$", "qb", "instanceof", "QueryBuilder", ";", "$", "qb", "->", "add", "(", "'where'", ",", "$", "qb", "->", "expr", "(", ")", "->", "like", "(", "'u.username'", ",", "$", "qb", "->", "expr", "(", ")", "->", "lower", "(", "':searched_term'", ")", ")", ")", "->", "setParameter", "(", "'searched_term'", ",", "$", "searched_term", ".", "'%'", ")", ";", "return", "$", "qb", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "}" ]
Find user by username @param string $searched_term
[ "Find", "user", "by", "username" ]
train
https://github.com/artscorestudio/user-bundle/blob/83e660d1073e1cbfde6eed0b528b8c99e78a2e53/Repository/UserRepository.php#L28-L37
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.set
public function set($id, $service) { // Runs the internal initializer; used by the dumped container to include always-needed files if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) { $initialize = $this->privates['service_container']; unset($this->privates['service_container']); $initialize(); } $id = $this->normalizeId($id); if ('service_container' === $id) { throw new InvalidArgumentException('You cannot set service "service_container".'); } if (isset($this->privates[$id]) || !(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) { if (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id])) { // no-op } elseif (null === $service) { @trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); unset($this->privates[$id]); } else { @trigger_error(sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); } } elseif (isset($this->services[$id])) { if (null === $service) { @trigger_error(sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED); } else { @trigger_error(sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED); } } if (isset($this->aliases[$id])) { unset($this->aliases[$id]); } if (null === $service) { unset($this->services[$id]); return; } $this->services[$id] = $service; }
php
public function set($id, $service) { // Runs the internal initializer; used by the dumped container to include always-needed files if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) { $initialize = $this->privates['service_container']; unset($this->privates['service_container']); $initialize(); } $id = $this->normalizeId($id); if ('service_container' === $id) { throw new InvalidArgumentException('You cannot set service "service_container".'); } if (isset($this->privates[$id]) || !(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) { if (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id])) { // no-op } elseif (null === $service) { @trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); unset($this->privates[$id]); } else { @trigger_error(sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); } } elseif (isset($this->services[$id])) { if (null === $service) { @trigger_error(sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED); } else { @trigger_error(sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED); } } if (isset($this->aliases[$id])) { unset($this->aliases[$id]); } if (null === $service) { unset($this->services[$id]); return; } $this->services[$id] = $service; }
[ "public", "function", "set", "(", "$", "id", ",", "$", "service", ")", "{", "// Runs the internal initializer; used by the dumped container to include always-needed files", "if", "(", "isset", "(", "$", "this", "->", "privates", "[", "'service_container'", "]", ")", "&&", "$", "this", "->", "privates", "[", "'service_container'", "]", "instanceof", "\\", "Closure", ")", "{", "$", "initialize", "=", "$", "this", "->", "privates", "[", "'service_container'", "]", ";", "unset", "(", "$", "this", "->", "privates", "[", "'service_container'", "]", ")", ";", "$", "initialize", "(", ")", ";", "}", "$", "id", "=", "$", "this", "->", "normalizeId", "(", "$", "id", ")", ";", "if", "(", "'service_container'", "===", "$", "id", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'You cannot set service \"service_container\".'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", "||", "!", "(", "isset", "(", "$", "this", "->", "fileMap", "[", "$", "id", "]", ")", "||", "isset", "(", "$", "this", "->", "methodMap", "[", "$", "id", "]", ")", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", "&&", "!", "isset", "(", "$", "this", "->", "getRemovedIds", "(", ")", "[", "$", "id", "]", ")", ")", "{", "// no-op", "}", "elseif", "(", "null", "===", "$", "service", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "unset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", ";", "}", "else", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "}", "elseif", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ")", "{", "if", "(", "null", "===", "$", "service", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "else", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ";", "}", "if", "(", "null", "===", "$", "service", ")", "{", "unset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ";", "return", ";", "}", "$", "this", "->", "services", "[", "$", "id", "]", "=", "$", "service", ";", "}" ]
Sets a service. Setting a service to null resets the service: has() returns false and get() behaves in the same way as if the service was never created. @param string $id The service identifier @param object $service The service instance
[ "Sets", "a", "service", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L168-L211
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.has
public function has($id) { for ($i = 2;;) { if (isset($this->privates[$id])) { @trigger_error(sprintf('The "%s" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } if (isset($this->services[$id])) { return true; } if ('service_container' === $id) { return true; } if (isset($this->fileMap[$id]) || isset($this->methodMap[$id])) { return true; } if (--$i && $id !== $normalizedId = $this->normalizeId($id)) { $id = $normalizedId; continue; } // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service')) { @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); return true; } return false; } }
php
public function has($id) { for ($i = 2;;) { if (isset($this->privates[$id])) { @trigger_error(sprintf('The "%s" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } if (isset($this->services[$id])) { return true; } if ('service_container' === $id) { return true; } if (isset($this->fileMap[$id]) || isset($this->methodMap[$id])) { return true; } if (--$i && $id !== $normalizedId = $this->normalizeId($id)) { $id = $normalizedId; continue; } // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service')) { @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); return true; } return false; } }
[ "public", "function", "has", "(", "$", "id", ")", "{", "for", "(", "$", "i", "=", "2", ";", ";", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ")", "{", "$", "id", "=", "$", "this", "->", "aliases", "[", "$", "id", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ")", "{", "return", "true", ";", "}", "if", "(", "'service_container'", "===", "$", "id", ")", "{", "return", "true", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "fileMap", "[", "$", "id", "]", ")", "||", "isset", "(", "$", "this", "->", "methodMap", "[", "$", "id", "]", ")", ")", "{", "return", "true", ";", "}", "if", "(", "--", "$", "i", "&&", "$", "id", "!==", "$", "normalizedId", "=", "$", "this", "->", "normalizeId", "(", "$", "id", ")", ")", "{", "$", "id", "=", "$", "normalizedId", ";", "continue", ";", "}", "// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,", "// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)", "if", "(", "!", "$", "this", "->", "methodMap", "&&", "!", "$", "this", "instanceof", "ContainerBuilder", "&&", "__CLASS__", "!==", "static", "::", "class", "&&", "method_exists", "(", "$", "this", ",", "'get'", ".", "strtr", "(", "$", "id", ",", "$", "this", "->", "underscoreMap", ")", ".", "'Service'", ")", ")", "{", "@", "trigger_error", "(", "'Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'", ",", "E_USER_DEPRECATED", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}", "}" ]
Returns true if the given service is defined. @param string $id The service identifier @return bool true if the service is defined, false otherwise
[ "Returns", "true", "if", "the", "given", "service", "is", "defined", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L220-L255
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.get
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1) { // Attempt to retrieve the service by checking first aliases then // available services. Service IDs are case insensitive, however since // this method can be called thousands of times during a request, avoid // calling $this->normalizeId($id) unless necessary. for ($i = 2;;) { if (isset($this->privates[$id])) { @trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } // Re-use shared service instance if it exists. if (isset($this->services[$id])) { return $this->services[$id]; } if ('service_container' === $id) { return $this; } if (isset($this->loading[$id])) { throw new ServiceCircularReferenceException($id, array_keys($this->loading)); } $this->loading[$id] = true; try { if (isset($this->fileMap[$id])) { return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->load($this->fileMap[$id]); } elseif (isset($this->methodMap[$id])) { return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->{$this->methodMap[$id]}(); } elseif (--$i && $id !== $normalizedId = $this->normalizeId($id)) { unset($this->loading[$id]); $id = $normalizedId; continue; } elseif (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, $method = 'get'.strtr($id, $this->underscoreMap).'Service')) { // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->{$method}(); } break; } catch (\Exception $e) { unset($this->services[$id]); throw $e; } finally { unset($this->loading[$id]); } } if (/* self::EXCEPTION_ON_INVALID_REFERENCE */ 1 === $invalidBehavior) { if (!$id) { throw new ServiceNotFoundException($id); } if (isset($this->syntheticIds[$id])) { throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id)); } if (isset($this->getRemovedIds()[$id])) { throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id)); } $alternatives = array(); foreach ($this->getServiceIds() as $knownId) { $lev = levenshtein($id, $knownId); if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) { $alternatives[] = $knownId; } } throw new ServiceNotFoundException($id, null, null, $alternatives); } }
php
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1) { // Attempt to retrieve the service by checking first aliases then // available services. Service IDs are case insensitive, however since // this method can be called thousands of times during a request, avoid // calling $this->normalizeId($id) unless necessary. for ($i = 2;;) { if (isset($this->privates[$id])) { @trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } // Re-use shared service instance if it exists. if (isset($this->services[$id])) { return $this->services[$id]; } if ('service_container' === $id) { return $this; } if (isset($this->loading[$id])) { throw new ServiceCircularReferenceException($id, array_keys($this->loading)); } $this->loading[$id] = true; try { if (isset($this->fileMap[$id])) { return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->load($this->fileMap[$id]); } elseif (isset($this->methodMap[$id])) { return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->{$this->methodMap[$id]}(); } elseif (--$i && $id !== $normalizedId = $this->normalizeId($id)) { unset($this->loading[$id]); $id = $normalizedId; continue; } elseif (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this, $method = 'get'.strtr($id, $this->underscoreMap).'Service')) { // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); return /* self::IGNORE_ON_UNINITIALIZED_REFERENCE */ 4 === $invalidBehavior ? null : $this->{$method}(); } break; } catch (\Exception $e) { unset($this->services[$id]); throw $e; } finally { unset($this->loading[$id]); } } if (/* self::EXCEPTION_ON_INVALID_REFERENCE */ 1 === $invalidBehavior) { if (!$id) { throw new ServiceNotFoundException($id); } if (isset($this->syntheticIds[$id])) { throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id)); } if (isset($this->getRemovedIds()[$id])) { throw new ServiceNotFoundException($id, null, null, array(), sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id)); } $alternatives = array(); foreach ($this->getServiceIds() as $knownId) { $lev = levenshtein($id, $knownId); if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) { $alternatives[] = $knownId; } } throw new ServiceNotFoundException($id, null, null, $alternatives); } }
[ "public", "function", "get", "(", "$", "id", ",", "$", "invalidBehavior", "=", "/* self::EXCEPTION_ON_INVALID_REFERENCE */", "1", ")", "{", "// Attempt to retrieve the service by checking first aliases then", "// available services. Service IDs are case insensitive, however since", "// this method can be called thousands of times during a request, avoid", "// calling $this->normalizeId($id) unless necessary.", "for", "(", "$", "i", "=", "2", ";", ";", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'The \"%s\" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ")", "{", "$", "id", "=", "$", "this", "->", "aliases", "[", "$", "id", "]", ";", "}", "// Re-use shared service instance if it exists.", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ")", "{", "return", "$", "this", "->", "services", "[", "$", "id", "]", ";", "}", "if", "(", "'service_container'", "===", "$", "id", ")", "{", "return", "$", "this", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "loading", "[", "$", "id", "]", ")", ")", "{", "throw", "new", "ServiceCircularReferenceException", "(", "$", "id", ",", "array_keys", "(", "$", "this", "->", "loading", ")", ")", ";", "}", "$", "this", "->", "loading", "[", "$", "id", "]", "=", "true", ";", "try", "{", "if", "(", "isset", "(", "$", "this", "->", "fileMap", "[", "$", "id", "]", ")", ")", "{", "return", "/* self::IGNORE_ON_UNINITIALIZED_REFERENCE */", "4", "===", "$", "invalidBehavior", "?", "null", ":", "$", "this", "->", "load", "(", "$", "this", "->", "fileMap", "[", "$", "id", "]", ")", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "methodMap", "[", "$", "id", "]", ")", ")", "{", "return", "/* self::IGNORE_ON_UNINITIALIZED_REFERENCE */", "4", "===", "$", "invalidBehavior", "?", "null", ":", "$", "this", "->", "{", "$", "this", "->", "methodMap", "[", "$", "id", "]", "}", "(", ")", ";", "}", "elseif", "(", "--", "$", "i", "&&", "$", "id", "!==", "$", "normalizedId", "=", "$", "this", "->", "normalizeId", "(", "$", "id", ")", ")", "{", "unset", "(", "$", "this", "->", "loading", "[", "$", "id", "]", ")", ";", "$", "id", "=", "$", "normalizedId", ";", "continue", ";", "}", "elseif", "(", "!", "$", "this", "->", "methodMap", "&&", "!", "$", "this", "instanceof", "ContainerBuilder", "&&", "__CLASS__", "!==", "static", "::", "class", "&&", "method_exists", "(", "$", "this", ",", "$", "method", "=", "'get'", ".", "strtr", "(", "$", "id", ",", "$", "this", "->", "underscoreMap", ")", ".", "'Service'", ")", ")", "{", "// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,", "// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)", "@", "trigger_error", "(", "'Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'", ",", "E_USER_DEPRECATED", ")", ";", "return", "/* self::IGNORE_ON_UNINITIALIZED_REFERENCE */", "4", "===", "$", "invalidBehavior", "?", "null", ":", "$", "this", "->", "{", "$", "method", "}", "(", ")", ";", "}", "break", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "unset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ";", "throw", "$", "e", ";", "}", "finally", "{", "unset", "(", "$", "this", "->", "loading", "[", "$", "id", "]", ")", ";", "}", "}", "if", "(", "/* self::EXCEPTION_ON_INVALID_REFERENCE */", "1", "===", "$", "invalidBehavior", ")", "{", "if", "(", "!", "$", "id", ")", "{", "throw", "new", "ServiceNotFoundException", "(", "$", "id", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "syntheticIds", "[", "$", "id", "]", ")", ")", "{", "throw", "new", "ServiceNotFoundException", "(", "$", "id", ",", "null", ",", "null", ",", "array", "(", ")", ",", "sprintf", "(", "'The \"%s\" service is synthetic, it needs to be set at boot time before it can be used.'", ",", "$", "id", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "getRemovedIds", "(", ")", "[", "$", "id", "]", ")", ")", "{", "throw", "new", "ServiceNotFoundException", "(", "$", "id", ",", "null", ",", "null", ",", "array", "(", ")", ",", "sprintf", "(", "'The \"%s\" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.'", ",", "$", "id", ")", ")", ";", "}", "$", "alternatives", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getServiceIds", "(", ")", "as", "$", "knownId", ")", "{", "$", "lev", "=", "levenshtein", "(", "$", "id", ",", "$", "knownId", ")", ";", "if", "(", "$", "lev", "<=", "strlen", "(", "$", "id", ")", "/", "3", "||", "false", "!==", "strpos", "(", "$", "knownId", ",", "$", "id", ")", ")", "{", "$", "alternatives", "[", "]", "=", "$", "knownId", ";", "}", "}", "throw", "new", "ServiceNotFoundException", "(", "$", "id", ",", "null", ",", "null", ",", "$", "alternatives", ")", ";", "}", "}" ]
Gets a service. If a service is defined both through a set() method and with a get{$id}Service() method, the former has always precedence. @param string $id The service identifier @param int $invalidBehavior The behavior when the service does not exist @return object The associated service @throws ServiceCircularReferenceException When a circular reference is detected @throws ServiceNotFoundException When the service is not defined @throws \Exception if an exception has been thrown when the service has been resolved @see Reference
[ "Gets", "a", "service", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L274-L350
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.initialized
public function initialized($id) { $id = $this->normalizeId($id); if (isset($this->privates[$id])) { @trigger_error(sprintf('Checking for the initialization of the "%s" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } if ('service_container' === $id) { return false; } return isset($this->services[$id]); }
php
public function initialized($id) { $id = $this->normalizeId($id); if (isset($this->privates[$id])) { @trigger_error(sprintf('Checking for the initialization of the "%s" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } if ('service_container' === $id) { return false; } return isset($this->services[$id]); }
[ "public", "function", "initialized", "(", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "normalizeId", "(", "$", "id", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "privates", "[", "$", "id", "]", ")", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'Checking for the initialization of the \"%s\" private service is deprecated since Symfony 3.4 and won\\'t be supported anymore in Symfony 4.0.'", ",", "$", "id", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ")", "{", "$", "id", "=", "$", "this", "->", "aliases", "[", "$", "id", "]", ";", "}", "if", "(", "'service_container'", "===", "$", "id", ")", "{", "return", "false", ";", "}", "return", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", ")", ";", "}" ]
Returns true if the given service has actually been initialized. @param string $id The service identifier @return bool true if service has already been initialized, false otherwise
[ "Returns", "true", "if", "the", "given", "service", "has", "actually", "been", "initialized", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L359-L376
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.getServiceIds
public function getServiceIds() { $ids = array(); if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) { // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); foreach (get_class_methods($this) as $method) { if (preg_match('/^get(.+)Service$/', $method, $match)) { $ids[] = self::underscore($match[1]); } } } $ids[] = 'service_container'; return array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services))); }
php
public function getServiceIds() { $ids = array(); if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) { // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder, // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper) @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', E_USER_DEPRECATED); foreach (get_class_methods($this) as $method) { if (preg_match('/^get(.+)Service$/', $method, $match)) { $ids[] = self::underscore($match[1]); } } } $ids[] = 'service_container'; return array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services))); }
[ "public", "function", "getServiceIds", "(", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "if", "(", "!", "$", "this", "->", "methodMap", "&&", "!", "$", "this", "instanceof", "ContainerBuilder", "&&", "__CLASS__", "!==", "static", "::", "class", ")", "{", "// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,", "// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)", "@", "trigger_error", "(", "'Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'", ",", "E_USER_DEPRECATED", ")", ";", "foreach", "(", "get_class_methods", "(", "$", "this", ")", "as", "$", "method", ")", "{", "if", "(", "preg_match", "(", "'/^get(.+)Service$/'", ",", "$", "method", ",", "$", "match", ")", ")", "{", "$", "ids", "[", "]", "=", "self", "::", "underscore", "(", "$", "match", "[", "1", "]", ")", ";", "}", "}", "}", "$", "ids", "[", "]", "=", "'service_container'", ";", "return", "array_unique", "(", "array_merge", "(", "$", "ids", ",", "array_keys", "(", "$", "this", "->", "methodMap", ")", ",", "array_keys", "(", "$", "this", "->", "fileMap", ")", ",", "array_keys", "(", "$", "this", "->", "services", ")", ")", ")", ";", "}" ]
Gets all service ids. @return array An array of all defined service ids
[ "Gets", "all", "service", "ids", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L391-L409
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.getEnv
protected function getEnv($name) { if (isset($this->resolving[$envName = "env($name)"])) { throw new ParameterCircularReferenceException(array_keys($this->resolving)); } if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) { return $this->envCache[$name]; } if (!$this->has($id = 'container.env_var_processors_locator')) { $this->set($id, new ServiceLocator(array())); } if (!$this->getEnv) { $this->getEnv = new \ReflectionMethod($this, __FUNCTION__); $this->getEnv->setAccessible(true); $this->getEnv = $this->getEnv->getClosure($this); } $processors = $this->get($id); if (false !== $i = strpos($name, ':')) { $prefix = substr($name, 0, $i); $localName = substr($name, 1 + $i); } else { $prefix = 'string'; $localName = $name; } $processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this); $this->resolving[$envName] = true; try { return $this->envCache[$name] = $processor->getEnv($prefix, $localName, $this->getEnv); } finally { unset($this->resolving[$envName]); } }
php
protected function getEnv($name) { if (isset($this->resolving[$envName = "env($name)"])) { throw new ParameterCircularReferenceException(array_keys($this->resolving)); } if (isset($this->envCache[$name]) || array_key_exists($name, $this->envCache)) { return $this->envCache[$name]; } if (!$this->has($id = 'container.env_var_processors_locator')) { $this->set($id, new ServiceLocator(array())); } if (!$this->getEnv) { $this->getEnv = new \ReflectionMethod($this, __FUNCTION__); $this->getEnv->setAccessible(true); $this->getEnv = $this->getEnv->getClosure($this); } $processors = $this->get($id); if (false !== $i = strpos($name, ':')) { $prefix = substr($name, 0, $i); $localName = substr($name, 1 + $i); } else { $prefix = 'string'; $localName = $name; } $processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this); $this->resolving[$envName] = true; try { return $this->envCache[$name] = $processor->getEnv($prefix, $localName, $this->getEnv); } finally { unset($this->resolving[$envName]); } }
[ "protected", "function", "getEnv", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "resolving", "[", "$", "envName", "=", "\"env($name)\"", "]", ")", ")", "{", "throw", "new", "ParameterCircularReferenceException", "(", "array_keys", "(", "$", "this", "->", "resolving", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "envCache", "[", "$", "name", "]", ")", "||", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "envCache", ")", ")", "{", "return", "$", "this", "->", "envCache", "[", "$", "name", "]", ";", "}", "if", "(", "!", "$", "this", "->", "has", "(", "$", "id", "=", "'container.env_var_processors_locator'", ")", ")", "{", "$", "this", "->", "set", "(", "$", "id", ",", "new", "ServiceLocator", "(", "array", "(", ")", ")", ")", ";", "}", "if", "(", "!", "$", "this", "->", "getEnv", ")", "{", "$", "this", "->", "getEnv", "=", "new", "\\", "ReflectionMethod", "(", "$", "this", ",", "__FUNCTION__", ")", ";", "$", "this", "->", "getEnv", "->", "setAccessible", "(", "true", ")", ";", "$", "this", "->", "getEnv", "=", "$", "this", "->", "getEnv", "->", "getClosure", "(", "$", "this", ")", ";", "}", "$", "processors", "=", "$", "this", "->", "get", "(", "$", "id", ")", ";", "if", "(", "false", "!==", "$", "i", "=", "strpos", "(", "$", "name", ",", "':'", ")", ")", "{", "$", "prefix", "=", "substr", "(", "$", "name", ",", "0", ",", "$", "i", ")", ";", "$", "localName", "=", "substr", "(", "$", "name", ",", "1", "+", "$", "i", ")", ";", "}", "else", "{", "$", "prefix", "=", "'string'", ";", "$", "localName", "=", "$", "name", ";", "}", "$", "processor", "=", "$", "processors", "->", "has", "(", "$", "prefix", ")", "?", "$", "processors", "->", "get", "(", "$", "prefix", ")", ":", "new", "EnvVarProcessor", "(", "$", "this", ")", ";", "$", "this", "->", "resolving", "[", "$", "envName", "]", "=", "true", ";", "try", "{", "return", "$", "this", "->", "envCache", "[", "$", "name", "]", "=", "$", "processor", "->", "getEnv", "(", "$", "prefix", ",", "$", "localName", ",", "$", "this", "->", "getEnv", ")", ";", "}", "finally", "{", "unset", "(", "$", "this", "->", "resolving", "[", "$", "envName", "]", ")", ";", "}", "}" ]
Fetches a variable from the environment. @param string $name The name of the environment variable @return mixed The value to use for the provided environment variable name @throws EnvNotFoundException When the environment variable is not found and has no default value
[ "Fetches", "a", "variable", "from", "the", "environment", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L464-L497
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/Container.php
Container.normalizeId
public function normalizeId($id) { if (!\is_string($id)) { $id = (string) $id; } if (isset($this->normalizedIds[$normalizedId = strtolower($id)])) { $normalizedId = $this->normalizedIds[$normalizedId]; if ($id !== $normalizedId) { @trigger_error(sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.3.', $id, $normalizedId), E_USER_DEPRECATED); } } else { $normalizedId = $this->normalizedIds[$normalizedId] = $id; } return $normalizedId; }
php
public function normalizeId($id) { if (!\is_string($id)) { $id = (string) $id; } if (isset($this->normalizedIds[$normalizedId = strtolower($id)])) { $normalizedId = $this->normalizedIds[$normalizedId]; if ($id !== $normalizedId) { @trigger_error(sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.3.', $id, $normalizedId), E_USER_DEPRECATED); } } else { $normalizedId = $this->normalizedIds[$normalizedId] = $id; } return $normalizedId; }
[ "public", "function", "normalizeId", "(", "$", "id", ")", "{", "if", "(", "!", "\\", "is_string", "(", "$", "id", ")", ")", "{", "$", "id", "=", "(", "string", ")", "$", "id", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "normalizedIds", "[", "$", "normalizedId", "=", "strtolower", "(", "$", "id", ")", "]", ")", ")", "{", "$", "normalizedId", "=", "$", "this", "->", "normalizedIds", "[", "$", "normalizedId", "]", ";", "if", "(", "$", "id", "!==", "$", "normalizedId", ")", "{", "@", "trigger_error", "(", "sprintf", "(", "'Service identifiers will be made case sensitive in Symfony 4.0. Using \"%s\" instead of \"%s\" is deprecated since Symfony 3.3.'", ",", "$", "id", ",", "$", "normalizedId", ")", ",", "E_USER_DEPRECATED", ")", ";", "}", "}", "else", "{", "$", "normalizedId", "=", "$", "this", "->", "normalizedIds", "[", "$", "normalizedId", "]", "=", "$", "id", ";", "}", "return", "$", "normalizedId", ";", "}" ]
Returns the case sensitive id used at registration time. @param string $id @return string @internal
[ "Returns", "the", "case", "sensitive", "id", "used", "at", "registration", "time", "." ]
train
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Container.php#L508-L523
danielgp/common-lib
source/CommonCode.php
CommonCode.getContentFromUrlThroughCurl
public function getContentFromUrlThroughCurl($fullURL, $features = null) { if (!function_exists('curl_init')) { $aReturn = ['info' => $this->lclMsgCmn('i18n_Error_ExtensionNotLoaded'), 'response' => '']; return $this->setArrayToJson($aReturn); } if (!filter_var($fullURL, FILTER_VALIDATE_URL)) { $aReturn = ['info' => $this->lclMsgCmn('i18n_Error_GivenUrlIsNotValid'), 'response' => '']; return $this->setArrayToJson($aReturn); } $aReturn = $this->getContentFromUrlThroughCurlRawArray($fullURL, $features); return '{ ' . $this->packIntoJson($aReturn, 'info') . ', ' . $this->packIntoJson($aReturn, 'response') . ' }'; }
php
public function getContentFromUrlThroughCurl($fullURL, $features = null) { if (!function_exists('curl_init')) { $aReturn = ['info' => $this->lclMsgCmn('i18n_Error_ExtensionNotLoaded'), 'response' => '']; return $this->setArrayToJson($aReturn); } if (!filter_var($fullURL, FILTER_VALIDATE_URL)) { $aReturn = ['info' => $this->lclMsgCmn('i18n_Error_GivenUrlIsNotValid'), 'response' => '']; return $this->setArrayToJson($aReturn); } $aReturn = $this->getContentFromUrlThroughCurlRawArray($fullURL, $features); return '{ ' . $this->packIntoJson($aReturn, 'info') . ', ' . $this->packIntoJson($aReturn, 'response') . ' }'; }
[ "public", "function", "getContentFromUrlThroughCurl", "(", "$", "fullURL", ",", "$", "features", "=", "null", ")", "{", "if", "(", "!", "function_exists", "(", "'curl_init'", ")", ")", "{", "$", "aReturn", "=", "[", "'info'", "=>", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_ExtensionNotLoaded'", ")", ",", "'response'", "=>", "''", "]", ";", "return", "$", "this", "->", "setArrayToJson", "(", "$", "aReturn", ")", ";", "}", "if", "(", "!", "filter_var", "(", "$", "fullURL", ",", "FILTER_VALIDATE_URL", ")", ")", "{", "$", "aReturn", "=", "[", "'info'", "=>", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_GivenUrlIsNotValid'", ")", ",", "'response'", "=>", "''", "]", ";", "return", "$", "this", "->", "setArrayToJson", "(", "$", "aReturn", ")", ";", "}", "$", "aReturn", "=", "$", "this", "->", "getContentFromUrlThroughCurlRawArray", "(", "$", "fullURL", ",", "$", "features", ")", ";", "return", "'{ '", ".", "$", "this", "->", "packIntoJson", "(", "$", "aReturn", ",", "'info'", ")", ".", "', '", ".", "$", "this", "->", "packIntoJson", "(", "$", "aReturn", ",", "'response'", ")", ".", "' }'", ";", "}" ]
Reads the content of a remote file through CURL extension @param string $fullURL @param array $features @return string
[ "Reads", "the", "content", "of", "a", "remote", "file", "through", "CURL", "extension" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L49-L61
danielgp/common-lib
source/CommonCode.php
CommonCode.getContentFromUrlThroughCurlAsArrayIfJson
public function getContentFromUrlThroughCurlAsArrayIfJson($fullURL, $features = null) { $result = $this->setJsonToArray($this->getContentFromUrlThroughCurl($fullURL, $features)); if (is_array($result['info'])) { ksort($result['info']); } if (is_array($result['response'])) { ksort($result['response']); } return $result; }
php
public function getContentFromUrlThroughCurlAsArrayIfJson($fullURL, $features = null) { $result = $this->setJsonToArray($this->getContentFromUrlThroughCurl($fullURL, $features)); if (is_array($result['info'])) { ksort($result['info']); } if (is_array($result['response'])) { ksort($result['response']); } return $result; }
[ "public", "function", "getContentFromUrlThroughCurlAsArrayIfJson", "(", "$", "fullURL", ",", "$", "features", "=", "null", ")", "{", "$", "result", "=", "$", "this", "->", "setJsonToArray", "(", "$", "this", "->", "getContentFromUrlThroughCurl", "(", "$", "fullURL", ",", "$", "features", ")", ")", ";", "if", "(", "is_array", "(", "$", "result", "[", "'info'", "]", ")", ")", "{", "ksort", "(", "$", "result", "[", "'info'", "]", ")", ";", "}", "if", "(", "is_array", "(", "$", "result", "[", "'response'", "]", ")", ")", "{", "ksort", "(", "$", "result", "[", "'response'", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Reads the content of a remote file through CURL extension @param string $fullURL @param array $features @return array
[ "Reads", "the", "content", "of", "a", "remote", "file", "through", "CURL", "extension" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L70-L80
danielgp/common-lib
source/CommonCode.php
CommonCode.getFileDetails
public function getFileDetails($fileGiven) { if (!file_exists($fileGiven)) { return ['error' => sprintf($this->lclMsgCmn('i18n_Error_GivenFileDoesNotExist'), $fileGiven)]; } return $this->getFileDetailsRaw($fileGiven); }
php
public function getFileDetails($fileGiven) { if (!file_exists($fileGiven)) { return ['error' => sprintf($this->lclMsgCmn('i18n_Error_GivenFileDoesNotExist'), $fileGiven)]; } return $this->getFileDetailsRaw($fileGiven); }
[ "public", "function", "getFileDetails", "(", "$", "fileGiven", ")", "{", "if", "(", "!", "file_exists", "(", "$", "fileGiven", ")", ")", "{", "return", "[", "'error'", "=>", "sprintf", "(", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_GivenFileDoesNotExist'", ")", ",", "$", "fileGiven", ")", "]", ";", "}", "return", "$", "this", "->", "getFileDetailsRaw", "(", "$", "fileGiven", ")", ";", "}" ]
returns the details about Communicator (current) file @param string $fileGiven @return array
[ "returns", "the", "details", "about", "Communicator", "(", "current", ")", "file" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L129-L135
danielgp/common-lib
source/CommonCode.php
CommonCode.getListOfFiles
public function getListOfFiles($pathAnalised) { if (realpath($pathAnalised) === false) { return ['error' => sprintf($this->lclMsgCmn('i18n_Error_GivenPathIsNotValid'), $pathAnalised)]; } elseif (!is_dir($pathAnalised)) { return ['error' => $this->lclMsgCmn('i18n_Error_GivenPathIsNotFolder')]; } $finder = new \Symfony\Component\Finder\Finder(); $iterator = $finder->files()->sortByName()->in($pathAnalised); $aFiles = null; foreach ($iterator as $file) { $aFiles[$file->getRealPath()] = $this->getFileDetails($file); } return $aFiles; }
php
public function getListOfFiles($pathAnalised) { if (realpath($pathAnalised) === false) { return ['error' => sprintf($this->lclMsgCmn('i18n_Error_GivenPathIsNotValid'), $pathAnalised)]; } elseif (!is_dir($pathAnalised)) { return ['error' => $this->lclMsgCmn('i18n_Error_GivenPathIsNotFolder')]; } $finder = new \Symfony\Component\Finder\Finder(); $iterator = $finder->files()->sortByName()->in($pathAnalised); $aFiles = null; foreach ($iterator as $file) { $aFiles[$file->getRealPath()] = $this->getFileDetails($file); } return $aFiles; }
[ "public", "function", "getListOfFiles", "(", "$", "pathAnalised", ")", "{", "if", "(", "realpath", "(", "$", "pathAnalised", ")", "===", "false", ")", "{", "return", "[", "'error'", "=>", "sprintf", "(", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_GivenPathIsNotValid'", ")", ",", "$", "pathAnalised", ")", "]", ";", "}", "elseif", "(", "!", "is_dir", "(", "$", "pathAnalised", ")", ")", "{", "return", "[", "'error'", "=>", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_GivenPathIsNotFolder'", ")", "]", ";", "}", "$", "finder", "=", "new", "\\", "Symfony", "\\", "Component", "\\", "Finder", "\\", "Finder", "(", ")", ";", "$", "iterator", "=", "$", "finder", "->", "files", "(", ")", "->", "sortByName", "(", ")", "->", "in", "(", "$", "pathAnalised", ")", ";", "$", "aFiles", "=", "null", ";", "foreach", "(", "$", "iterator", "as", "$", "file", ")", "{", "$", "aFiles", "[", "$", "file", "->", "getRealPath", "(", ")", "]", "=", "$", "this", "->", "getFileDetails", "(", "$", "file", ")", ";", "}", "return", "$", "aFiles", ";", "}" ]
returns a multi-dimensional array with list of file details within a given path (by using Symfony/Finder package) @param string $pathAnalised @return array
[ "returns", "a", "multi", "-", "dimensional", "array", "with", "list", "of", "file", "details", "within", "a", "given", "path", "(", "by", "using", "Symfony", "/", "Finder", "package", ")" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L144-L158
danielgp/common-lib
source/CommonCode.php
CommonCode.getTimestamp
public function getTimestamp($returnType = 'string') { if (in_array($returnType, ['array', 'float', 'string'])) { return $this->getTimestampRaw($returnType); } return sprintf($this->lclMsgCmn('i18n_Error_UnknownReturnType'), $returnType); }
php
public function getTimestamp($returnType = 'string') { if (in_array($returnType, ['array', 'float', 'string'])) { return $this->getTimestampRaw($returnType); } return sprintf($this->lclMsgCmn('i18n_Error_UnknownReturnType'), $returnType); }
[ "public", "function", "getTimestamp", "(", "$", "returnType", "=", "'string'", ")", "{", "if", "(", "in_array", "(", "$", "returnType", ",", "[", "'array'", ",", "'float'", ",", "'string'", "]", ")", ")", "{", "return", "$", "this", "->", "getTimestampRaw", "(", "$", "returnType", ")", ";", "}", "return", "sprintf", "(", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_UnknownReturnType'", ")", ",", "$", "returnType", ")", ";", "}" ]
Returns server Timestamp into various formats @param string $returnType @return string
[ "Returns", "server", "Timestamp", "into", "various", "formats" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L166-L172
danielgp/common-lib
source/CommonCode.php
CommonCode.isJsonByDanielGP
public function isJsonByDanielGP($inputJson) { if (is_string($inputJson)) { json_decode($inputJson); return (json_last_error() == JSON_ERROR_NONE); } return $this->lclMsgCmn('i18n_Error_GivenInputIsNotJson'); }
php
public function isJsonByDanielGP($inputJson) { if (is_string($inputJson)) { json_decode($inputJson); return (json_last_error() == JSON_ERROR_NONE); } return $this->lclMsgCmn('i18n_Error_GivenInputIsNotJson'); }
[ "public", "function", "isJsonByDanielGP", "(", "$", "inputJson", ")", "{", "if", "(", "is_string", "(", "$", "inputJson", ")", ")", "{", "json_decode", "(", "$", "inputJson", ")", ";", "return", "(", "json_last_error", "(", ")", "==", "JSON_ERROR_NONE", ")", ";", "}", "return", "$", "this", "->", "lclMsgCmn", "(", "'i18n_Error_GivenInputIsNotJson'", ")", ";", "}" ]
Tests if given string has a valid Json format @param string|null|array $inputJson @return boolean|string
[ "Tests", "if", "given", "string", "has", "a", "valid", "Json", "format" ]
train
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonCode.php#L180-L187