idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
43,900 | private function extractAuthEndpoint ( ) { $ auth = empty ( $ this -> config [ 'auth_endpoint' ] ) ? self :: DEFAULT_AUTH_ENDPOINT : $ this -> config [ 'auth_endpoint' ] ; switch ( $ auth ) { case Endpoint :: UK : $ endpoint = Rackspace :: UK_IDENTITY_ENDPOINT ; break ; case Endpoint :: US : $ endpoint = Rackspace :: US_IDENTITY_ENDPOINT ; break ; default : $ endpoint = $ auth ; break ; } return Url :: factory ( $ endpoint ) ; } | Searchs the configuration values provided and attempts to build a suitable URL for authentication . |
43,901 | protected function getDefaultTypeHandler ( $ value ) { $ type = gettype ( $ value ) ; switch ( $ type ) { case 'null' : return null ; case 'array' : if ( count ( $ value ) == 0 ) return null ; elseif ( count ( $ value ) == 1 ) return $ this -> getDefaultTypeHandler ( current ( $ value ) ) ; $ typeHandler = null ; foreach ( $ value as $ val ) { $ typeHandler = $ this -> getDefaultTypeHandler ( $ val ) ; if ( ! is_null ( $ typeHandler ) ) break ; } return $ typeHandler ; case 'object' : $ classname = get_class ( $ value ) ; $ typeHandler = $ this -> typeManager -> getTypeHandler ( $ classname ) ; if ( $ typeHandler !== false ) return $ typeHandler ; throw new \ RuntimeException ( "No default type handler found for class '$classname'" ) ; case 'resource' : throw new \ RuntimeException ( "Argument of type 'resource' is not supported" ) ; default : return $ this -> typeManager -> getTypeHandler ( $ type ) ; } } | Obtains the default type handler for a given value |
43,902 | protected function castArray ( $ value , TypeHandler $ typeHandler , $ join_string = ',' ) { $ list = [ ] ; foreach ( $ value as $ val ) { $ val = $ typeHandler -> castParameter ( $ val ) ; if ( is_null ( $ val ) ) $ new_elem = 'NULL' ; else { $ new_elem = $ typeHandler -> setParameter ( $ val ) ; if ( is_null ( $ new_elem ) ) $ new_elem = 'NULL' ; elseif ( ! is_string ( $ new_elem ) ) $ new_elem = strval ( $ new_elem ) ; } $ list [ ] = $ new_elem ; } return implode ( $ join_string , $ list ) ; } | Casts all elements in an array with the given type handler |
43,903 | protected function castParameter ( $ value , $ type = null ) { if ( is_null ( $ value ) ) return 'NULL' ; elseif ( is_null ( $ type ) ) { $ typeHandler = $ this -> getDefaultTypeHandler ( $ value ) ; if ( is_null ( $ typeHandler ) ) return 'NULL' ; if ( is_array ( $ value ) ) return $ this -> castArray ( $ value , $ typeHandler , '_' ) ; } else { $ typeHandler = $ this -> typeManager -> getTypeHandler ( $ type ) ; if ( $ typeHandler === false ) throw new \ RuntimeException ( "No type handler found for type '$type'" ) ; if ( is_array ( $ value ) ) return $ this -> castArray ( $ value , $ typeHandler , '_' ) ; $ value = $ typeHandler -> castParameter ( $ value ) ; if ( is_null ( $ value ) ) return 'NULL' ; } $ value = $ typeHandler -> setParameter ( $ value ) ; if ( is_null ( $ value ) ) return 'NULL' ; if ( ! is_string ( $ value ) ) $ value = strval ( $ value ) ; return $ value ; } | Casts a value to a given type |
43,904 | protected function replaceConfigExpression ( $ matches ) { $ property = $ matches [ 1 ] ; if ( ! array_key_exists ( $ property , $ this -> config ) ) return '' ; if ( ( $ str = $ this -> toString ( $ this -> config [ $ property ] ) ) === false ) return '' ; return $ str ; } | Returns a string that replaces a configuration expression within a string |
43,905 | protected function replacePropertyExpression ( $ matches ) { $ total_matches = count ( $ matches ) ; $ type = $ subindex = null ; switch ( $ total_matches ) { case 4 : $ type = substr ( $ matches [ 3 ] , 1 ) ; case 3 : $ subindex = empty ( $ matches [ 2 ] ) ? null : substr ( $ matches [ 2 ] , 1 , - 1 ) ; case 2 : $ key = $ matches [ 1 ] ; if ( is_null ( $ type ) && $ this -> wrappedArg instanceof ObjectArgumentWrapper ) { if ( $ this -> wrappedArg -> getClassProfile ( ) -> isEntity ( ) ) { $ property = $ this -> wrappedArg -> getClassProfile ( ) -> getProperty ( $ key ) ; $ type = $ property -> getType ( ) ; } } return $ this -> getIndex ( $ key , $ subindex , $ type ) ; break ; case 9 : $ type = substr ( $ matches [ 8 ] , 1 ) ; case 8 : $ key = $ matches [ 4 ] ; if ( is_null ( $ type ) && $ this -> wrappedArg instanceof ObjectArgumentWrapper ) { if ( $ this -> wrappedArg -> getClassProfile ( ) -> isEntity ( ) ) { $ property = $ this -> wrappedArg -> getClassProfile ( ) -> getProperty ( $ key ) ; $ type = $ property -> getType ( ) ; } } return $ this -> getRange ( $ key , $ matches [ 6 ] , $ matches [ 7 ] , $ type ) ; break ; } } | Returns a string that replaces a property expression |
43,906 | protected function replaceArgumentExpression ( $ matches ) { $ total_matches = count ( $ matches ) ; $ type = $ subindex = null ; if ( $ total_matches == 2 ) { if ( $ this -> counter >= count ( $ this -> args ) ) throw new \ OutOfBoundsException ( "No arguments left for expression '{$matches[0]}'" ) ; return $ this -> castParameter ( $ this -> args [ $ this -> counter ++ ] , $ matches [ 1 ] ) ; } switch ( $ total_matches ) { case 5 : $ type = substr ( $ matches [ 4 ] , 1 ) ; case 4 : $ subindex = empty ( $ matches [ 3 ] ) ? null : substr ( $ matches [ 3 ] , 1 , - 1 ) ; case 3 : $ index = intval ( $ matches [ 2 ] ) ; if ( ! array_key_exists ( $ index , $ this -> args ) ) throw new \ InvalidArgumentException ( "No value found on index $index" ) ; if ( $ index == 0 && ! is_null ( $ subindex ) ) return $ this -> getIndex ( $ subindex , null , $ type ) ; return $ this -> getSubIndex ( $ this -> args [ $ index ] , $ subindex , $ type ) ; case 10 : $ type = substr ( $ matches [ 9 ] , 1 ) ; case 9 : $ index = intval ( $ matches [ 5 ] ) ; if ( ! array_key_exists ( $ index , $ this -> args ) ) throw new \ InvalidArgumentException ( "No value found on index $index" ) ; return $ this -> getSubRange ( $ this -> args [ $ index ] , $ matches [ 7 ] , $ matches [ 8 ] , $ type ) ; } } | Returns a string that replaces an argument expression |
43,907 | public static function isEmail ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return filter_var ( ( string ) $ value , FILTER_VALIDATE_EMAIL ) !== false ; } | Checks if value is an email address |
43,908 | public static function isIpAddress ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return filter_var ( ( string ) $ value , FILTER_VALIDATE_IP ) !== false ; } | Checks if value is an IP address |
43,909 | public static function isIpV4Address ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return filter_var ( ( string ) $ value , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) !== false ; } | Checks if value is an IPv4 address |
43,910 | public static function isIpV6Address ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return filter_var ( ( string ) $ value , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) !== false ; } | Checks if value is an IPv6 address |
43,911 | public static function isUri ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ pattern = sprintf ( '/\A%s%s%s%s%s\z/' , '(?:([^:\/?#]+)(:))?' , '(?:(\/\/)([^\/?#]*))?' , '([^?#]*)' , '(?:(\?)([^#]*))?' , '(?:(#)(.*))?' ) ; preg_match ( $ pattern , ( string ) $ value , $ matches ) ; $ uri = self :: uriComponentsFromMatches ( $ matches ) ; return self :: isValidUri ( $ uri ) ; } | Checks if value is a URI |
43,912 | public static function isUrn ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } if ( substr ( ( string ) $ value , 0 , 8 ) === "urn:urn:" ) { return false ; } $ pattern = sprintf ( '/\Aurn:%s:%s\z/i' , '[a-z0-9](?:[a-z0-9\-]{1,31})?' , '(?:[a-z0-9()+,\-.:=@;$_!*\']|%(?:0[a-f1-9]|[a-f1-9][a-f0-9]))+' ) ; return ! ! preg_match ( $ pattern , ( string ) $ value ) ; } | Checks if value is a URN |
43,913 | public static function isUuid ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ pattern = sprintf ( '/\A%s-%s-%s-%s%s-%s\z/i' , '[a-f0-9]{8}' , '[a-f0-9]{4}' , '[a-f0-9]{4}' , '[a-f0-9]{2}' , '[a-f0-9]{2}' , '[a-f0-9]{12}' ) ; $ value = str_replace ( [ 'urn:' , 'uuid:' , '{' , '}' ] , '' , ( string ) $ value ) ; return ! ! preg_match ( $ pattern , $ value ) ; } | Checks if value is a UUID |
43,914 | public static function isTimezone ( $ value ) : bool { if ( $ value instanceof DateTimeZone ) { return true ; } if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return self :: isValidTimezone ( ( string ) $ value ) ; } | Checks if value is a timezone |
43,915 | public static function isJson ( $ value ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } if ( ( ( string ) $ value ) === 'null' ) { return true ; } return ( json_decode ( ( string ) $ value ) !== null && json_last_error ( ) === JSON_ERROR_NONE ) ; } | Checks if value is a JSON string |
43,916 | public static function isMatch ( $ value , string $ pattern ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return ! ! preg_match ( $ pattern , ( string ) $ value ) ; } | Checks if value matches a regular expression |
43,917 | public static function contains ( $ value , string $ search , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return mb_strpos ( ( string ) $ value , $ search , 0 , $ encoding ) !== false ; } | Checks if value contains a search string |
43,918 | public static function startsWith ( $ value , string $ search , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ searchlen = ( int ) mb_strlen ( $ search , $ encoding ) ; $ start = mb_substr ( ( string ) $ value , 0 , $ searchlen , $ encoding ) ; return $ search === $ start ; } | Checks if value starts with a search string |
43,919 | public static function endsWith ( $ value , string $ search , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ searchlen = ( int ) mb_strlen ( $ search , $ encoding ) ; $ length = ( int ) mb_strlen ( ( string ) $ value , $ encoding ) ; $ end = mb_substr ( ( string ) $ value , $ length - $ searchlen , $ searchlen , $ encoding ) ; return $ search === $ end ; } | Checks if value ends with a search string |
43,920 | public static function exactLength ( $ value , int $ length , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ strlen = ( int ) mb_strlen ( ( string ) $ value , $ encoding ) ; return $ strlen === $ length ; } | Checks if value has an exact string length |
43,921 | public static function minLength ( $ value , int $ minLength , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ strlen = ( int ) mb_strlen ( ( string ) $ value , $ encoding ) ; return $ strlen >= $ minLength ; } | Checks if value has a string length greater or equal to a minimum |
43,922 | public static function rangeLength ( $ value , int $ minLength , int $ maxLength , string $ encoding = 'UTF-8' ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } $ strlen = ( int ) mb_strlen ( ( string ) $ value , $ encoding ) ; if ( $ strlen < $ minLength ) { return false ; } if ( $ strlen > $ maxLength ) { return false ; } return true ; } | Checks if value has a string length within a range |
43,923 | public static function rangeNumber ( $ value , $ minNumber , $ maxNumber ) : bool { if ( ! is_numeric ( $ value ) ) { return false ; } if ( $ value < $ minNumber ) { return false ; } if ( $ value > $ maxNumber ) { return false ; } return true ; } | Checks if value is within a numeric range |
43,924 | public static function intValue ( $ value ) : bool { if ( ! is_numeric ( $ value ) ) { return false ; } return strval ( intval ( $ value ) ) == $ value ; } | Checks if value can be cast to an integer without changing value |
43,925 | public static function exactCount ( $ value , int $ count ) : bool { if ( ! static :: isCountable ( $ value ) ) { return false ; } return count ( $ value ) == $ count ; } | Checks if value has an exact count |
43,926 | public static function minCount ( $ value , int $ minCount ) : bool { if ( ! static :: isCountable ( $ value ) ) { return false ; } return count ( $ value ) >= $ minCount ; } | Checks if value has a count greater or equal to a minimum |
43,927 | public static function maxCount ( $ value , int $ maxCount ) : bool { if ( ! static :: isCountable ( $ value ) ) { return false ; } return count ( $ value ) <= $ maxCount ; } | Checks if value has a count less or equal to a maximum |
43,928 | public static function rangeCount ( $ value , int $ minCount , int $ maxCount ) : bool { if ( ! static :: isCountable ( $ value ) ) { return false ; } $ count = count ( $ value ) ; if ( $ count < $ minCount ) { return false ; } if ( $ count > $ maxCount ) { return false ; } return true ; } | Checks if value has a count within a range |
43,929 | public static function isOneOf ( $ value , iterable $ choices ) : bool { foreach ( $ choices as $ choice ) { if ( $ value === $ choice ) { return true ; } } return false ; } | Checks if value is one of a set of choices |
43,930 | public static function keyIsset ( $ value , $ key ) : bool { if ( ! static :: isArrayAccessible ( $ value ) ) { return false ; } return isset ( $ value [ $ key ] ) ; } | Checks if value is array accessible with a non - null key |
43,931 | public static function keyNotEmpty ( $ value , $ key ) : bool { if ( ! static :: isArrayAccessible ( $ value ) ) { return false ; } return isset ( $ value [ $ key ] ) && ! empty ( $ value [ $ key ] ) ; } | Checks if value is array accessible with a non - empty key |
43,932 | public static function areEqual ( $ value1 , $ value2 ) : bool { if ( static :: isEquatable ( $ value1 ) && static :: areSameType ( $ value1 , $ value2 ) ) { return $ value1 -> equals ( $ value2 ) ; } return $ value1 == $ value2 ; } | Checks if two values are equal |
43,933 | public static function areNotEqual ( $ value1 , $ value2 ) : bool { if ( static :: isEquatable ( $ value1 ) && static :: areSameType ( $ value1 , $ value2 ) ) { return ! $ value1 -> equals ( $ value2 ) ; } return $ value1 != $ value2 ; } | Checks if two values are not equal |
43,934 | public static function areSameType ( $ value1 , $ value2 ) : bool { if ( ! is_object ( $ value1 ) || ! is_object ( $ value2 ) ) { return gettype ( $ value1 ) === gettype ( $ value2 ) ; } return get_class ( $ value1 ) === get_class ( $ value2 ) ; } | Checks if two values are the same type |
43,935 | public static function isType ( $ value , ? string $ type ) : bool { if ( $ type === null ) { return true ; } $ result = self :: isSimpleType ( $ value , $ type ) ; if ( $ result !== null ) { return $ result ; } return ( $ value instanceof $ type ) ; } | Checks if value is a given type |
43,936 | public static function isListOf ( $ value , ? string $ type ) : bool { if ( ! static :: isTraversable ( $ value ) ) { return false ; } if ( $ type === null ) { return true ; } $ result = true ; foreach ( $ value as $ val ) { if ( ! static :: isType ( $ val , $ type ) ) { $ result = false ; break ; } } return $ result ; } | Checks if value is a list of a given type |
43,937 | public static function isStringCastable ( $ value ) : bool { $ result = false ; $ type = strtolower ( gettype ( $ value ) ) ; switch ( $ type ) { case 'string' : case 'null' : case 'boolean' : case 'integer' : case 'double' : $ result = true ; break ; case 'object' : if ( method_exists ( $ value , '__toString' ) ) { $ result = true ; } break ; default : break ; } return $ result ; } | Checks if value can be cast to a string |
43,938 | public static function isJsonEncodable ( $ value ) : bool { if ( $ value === null || is_scalar ( $ value ) || is_array ( $ value ) ) { return true ; } if ( is_object ( $ value ) && ( $ value instanceof JsonSerializable ) ) { return true ; } return false ; } | Checks if value can be JSON encoded |
43,939 | public static function isSerializable ( $ value ) : bool { if ( $ value === null || is_scalar ( $ value ) || is_array ( $ value ) ) { return true ; } if ( is_object ( $ value ) && ( $ value instanceof Serializable ) ) { return true ; } return false ; } | Checks if value can be serialized |
43,940 | public static function isTraversable ( $ value ) : bool { if ( is_array ( $ value ) ) { return true ; } if ( is_object ( $ value ) && ( $ value instanceof Traversable ) ) { return true ; } return false ; } | Checks if value is traversable |
43,941 | public static function isCountable ( $ value ) : bool { if ( is_array ( $ value ) ) { return true ; } if ( is_object ( $ value ) && ( $ value instanceof Countable ) ) { return true ; } return false ; } | Checks if value is countable |
43,942 | public static function isArrayAccessible ( $ value ) : bool { if ( is_array ( $ value ) ) { return true ; } if ( is_object ( $ value ) && ( $ value instanceof ArrayAccess ) ) { return true ; } return false ; } | Checks if value is array accessible |
43,943 | public static function implementsInterface ( $ value , string $ interface ) : bool { if ( ! is_object ( $ value ) ) { if ( ! ( static :: classExists ( $ value ) || static :: interfaceExists ( $ value ) ) ) { return false ; } $ value = ( string ) $ value ; } $ reflection = new ReflectionClass ( $ value ) ; return $ reflection -> implementsInterface ( $ interface ) ; } | Checks if value implements a given interface |
43,944 | public static function methodExists ( $ value , $ object ) : bool { if ( ! static :: isStringCastable ( $ value ) ) { return false ; } return method_exists ( $ object , ( string ) $ value ) ; } | Checks if value is a method name for an object or class |
43,945 | private static function isValidTimezone ( string $ timezone ) : bool { if ( self :: $ timezones === null ) { self :: $ timezones = [ ] ; foreach ( timezone_identifiers_list ( ) as $ zone ) { self :: $ timezones [ $ zone ] = true ; } } return isset ( self :: $ timezones [ $ timezone ] ) ; } | Checks if a timezone string is valid |
43,946 | private static function isValidUri ( array $ uri ) : bool { if ( ! self :: isValidUriScheme ( $ uri [ 'scheme' ] ) ) { return false ; } if ( ! self :: isValidUriPath ( $ uri [ 'path' ] ) ) { return false ; } if ( ! self :: isValidUriQuery ( $ uri [ 'query' ] ) ) { return false ; } if ( ! self :: isValidUriFragment ( $ uri [ 'fragment' ] ) ) { return false ; } if ( ! self :: isValidUriAuthority ( $ uri [ 'authority' ] ) ) { return false ; } return true ; } | Checks if URI components are valid |
43,947 | private static function isValidUriScheme ( ? string $ scheme ) : bool { if ( $ scheme === null || $ scheme === '' ) { return false ; } $ pattern = '/\A[a-z][a-z0-9+.\-]*\z/i' ; return ! ! preg_match ( $ pattern , $ scheme ) ; } | Checks if a URI scheme is valid |
43,948 | private static function isValidUriAuthority ( ? string $ authority ) : bool { if ( $ authority === null || $ authority === '' ) { return true ; } $ pattern = '/\A(?:([^@]*)@)?(\[[^\]]*\]|[^:]*)(?::(?:\d*))?\z/' ; preg_match ( $ pattern , $ authority , $ matches ) ; if ( ! self :: isValidAuthUser ( ( isset ( $ matches [ 1 ] ) && $ matches [ 1 ] ) ? $ matches [ 1 ] : null ) ) { return false ; } if ( ! self :: isValidAuthHost ( ( isset ( $ matches [ 2 ] ) && $ matches [ 2 ] ) ? $ matches [ 2 ] : '' ) ) { return false ; } return true ; } | Checks if a URI authority is valid |
43,949 | private static function isValidUriPath ( string $ path ) : bool { if ( $ path === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:(?:[%s%s:@]|(?:%s))*\/?)*\z/i' , 'a-z0-9\-._~' , '!$&\'()*+,;=' , '%[a-f0-9]{2}' ) ; return ! ! preg_match ( $ pattern , $ path ) ; } | Checks if a URI path is valid |
43,950 | private static function isValidUriQuery ( ? string $ query ) : bool { if ( $ query === null || $ query === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s\/?:@]|(?:%s))*\z/i' , 'a-z0-9\-._~' , '!$&\'()*+,;=' , '%[a-f0-9]{2}' ) ; return ! ! preg_match ( $ pattern , $ query ) ; } | Checks if a URI query is valid |
43,951 | private static function isValidUriFragment ( ? string $ fragment ) : bool { if ( $ fragment === null || $ fragment === '' ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s\/?:@]|(?:%s))*\z/i' , 'a-z0-9\-._~' , '!$&\'()*+,;=' , '%[a-f0-9]{2}' ) ; return ! ! preg_match ( $ pattern , $ fragment ) ; } | Checks if a URI fragment is valid |
43,952 | private static function isValidAuthUser ( ? string $ userinfo ) : bool { if ( $ userinfo === null ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s:]|(?:%s))*\z/i' , 'a-z0-9\-._~' , '!$&\'()*+,;=' , '%[a-f0-9]{2}' ) ; return ! ! preg_match ( $ pattern , $ userinfo ) ; } | Checks if authority userinfo is valid |
43,953 | private static function isValidAuthHost ( string $ host ) : bool { if ( $ host === '' ) { return true ; } if ( strpos ( $ host , '[' ) !== false ) { return self :: isValidIpLiteral ( $ host ) ; } $ dec = '(?:(?:2[0-4]|1[0-9]|[1-9])?[0-9]|25[0-5])' ; $ ipV4 = sprintf ( '/\A(?:%s\.){3}%s\z/' , $ dec , $ dec ) ; if ( preg_match ( $ ipV4 , $ host ) ) { return true ; } $ pattern = sprintf ( '/\A(?:[%s%s]|(?:%s))*\z/i' , 'a-z0-9\-._~' , '!$&\'()*+,;=' , '%[a-f0-9]{2}' ) ; return ! ! preg_match ( $ pattern , $ host ) ; } | Checks if authority host is valid |
43,954 | private static function isSimpleType ( $ value , string $ type ) : ? bool { switch ( $ type ) { case 'array' : return static :: isArray ( $ value ) ; break ; case 'object' : return static :: isObject ( $ value ) ; break ; case 'bool' : return static :: isBool ( $ value ) ; break ; case 'int' : return static :: isInt ( $ value ) ; break ; case 'float' : return static :: isFloat ( $ value ) ; break ; case 'string' : return static :: isString ( $ value ) ; break ; case 'callable' : return static :: isCallable ( $ value ) ; break ; default : break ; } return null ; } | Checks if a value matches a simple type |
43,955 | private function startPluginTraits ( ) { foreach ( $ this -> getPluginTraits ( ) as $ trait ) { if ( method_exists ( get_called_class ( ) , $ method = 'start' . class_basename ( $ trait ) . 'Plugin' ) ) { call_user_func ( [ $ this , $ method ] , $ this -> app ) ; } } } | startPluginTraits method . |
43,956 | public function requiresPlugins ( ) { $ has = class_uses_recursive ( get_called_class ( ) ) ; $ check = array_combine ( func_get_args ( ) , func_get_args ( ) ) ; $ missing = array_values ( array_diff ( $ check , $ has ) ) ; if ( isset ( $ missing [ 0 ] ) ) { $ plugin = collect ( debug_backtrace ( ) ) -> where ( 'function' , 'requiresPlugins' ) -> first ( ) ; throw ProviderPluginDependencyException :: plugin ( $ plugin [ 'file' ] , implode ( ', ' , $ missing ) ) ; } } | requiresPlugins method . |
43,957 | private function resolveDirectories ( ) { if ( $ this -> scanDirs !== true ) { return ; } if ( $ this -> rootDir === null ) { $ class = new ReflectionClass ( get_called_class ( ) ) ; $ filePath = $ class -> getFileName ( ) ; $ this -> dir = $ rootDir = path_get_directory ( $ filePath ) ; $ found = false ; for ( $ i = 0 ; $ i < $ this -> scanDirsMaxLevel ; ++ $ i ) { if ( file_exists ( $ composerPath = path_join ( $ rootDir , 'composer.json' ) ) ) { $ found = true ; break ; } else { $ rootDir = path_get_directory ( $ rootDir ) ; } } if ( $ found === false ) { throw new \ OutOfBoundsException ( "Could not determinse composer.json file location in [{$this->dir}] or in {$this->scanDirsMaxLevel} parents of [$this->rootDir}]" ) ; } $ this -> rootDir = $ rootDir ; } $ this -> dir = $ this -> dir ? : path_join ( $ this -> rootDir , 'src' ) ; } | resolveDirectories method . |
43,958 | private function getPluginPriority ( $ name , $ index = 0 ) { $ priority = 10 ; if ( property_exists ( $ this , "{$name}PluginPriority" ) ) { $ value = $ this -> { $ name . 'PluginPriority' } ; $ priority = is_array ( $ value ) ? $ value [ $ index ] : $ value ; } return $ priority ; } | getPluginPriority method . |
43,959 | public function onRegister ( $ name , Closure $ callback ) { $ priority = $ this -> getPluginPriority ( $ name ) ; $ this -> registerCallbacks [ ] = compact ( 'name' , 'priority' , 'callback' ) ; } | onRegister method . |
43,960 | public function onBoot ( $ name , Closure $ callback ) { $ priority = $ this -> getPluginPriority ( $ name , 1 ) ; $ this -> bootCallbacks [ ] = compact ( 'name' , 'priority' , 'callback' ) ; } | onBoot method . |
43,961 | private function fireCallbacks ( $ name , Closure $ modifier = null , Closure $ caller = null ) { $ list = collect ( $ this -> { $ name . 'Callbacks' } ) ; if ( $ modifier ) { $ list = call_user_func_array ( $ modifier , [ $ list ] ) ; } $ caller = $ caller ? : function ( Closure $ callback ) { $ callback -> bindTo ( $ this ) ; $ callback ( $ this -> app ) ; } ; $ list -> pluck ( 'callback' ) -> each ( $ caller ) ; } | fireCallbacks method . |
43,962 | public function formatStylesJs ( ) { $ options = [ ] ; $ options [ ] = $ this -> formatStyle ( 'Arial,Arial,Helvetica,sans-serif' , 'Arial' ) ; $ options [ ] = $ this -> formatStyle ( 'Arial Black,Arial Black,Gadget,sans-serif' , 'Arial Black' ) ; $ options [ ] = $ this -> formatStyle ( 'Comic Sans MS,Comic Sans MS,cursive' , 'Comic Sans MS' ) ; $ options [ ] = $ this -> formatStyle ( 'Courier New,Courier New,Courier,monospace' , 'Courier New' ) ; $ options [ ] = $ this -> formatStyle ( 'Georgia,Georgia,serif' , 'Georgia' ) ; $ options [ ] = $ this -> formatStyle ( 'Impact,Charcoal,sans-serif' , 'Impact' ) ; $ options [ ] = $ this -> formatStyle ( 'Lucida Console,Monaco,monospace' , 'Lucida Console' ) ; $ options [ ] = $ this -> formatStyle ( 'Lucida Sans Unicode,Lucida Grande,sans-serif' , 'Lucida Sans' ) ; $ options [ ] = $ this -> formatStyle ( 'Palatino Linotype,Book Antiqua,Palatino,serif' , 'Palatino Linotype' ) ; $ options [ ] = $ this -> formatStyle ( 'Tahoma,Geneva,sans-serif' , 'Tahoma' ) ; $ options [ ] = $ this -> formatStyle ( 'Times New Roman,Times,serif' , 'Times New Roman' ) ; $ options [ ] = $ this -> formatStyle ( 'Trebuchet MS,Helvetica,sans-serif' , 'Trebuchet' ) ; $ options [ ] = $ this -> formatStyle ( 'Verdana,Geneva,sans-serif' , 'Verdana' ) ; return 'aoTypes: [' . implode ( ', ' , $ options ) . ']' ; } | Formats font styles to use them in layout editor |
43,963 | public function process ( Request $ request , FormInterface $ form ) { if ( $ request -> isMethod ( 'POST' ) ) { $ form -> submit ( $ request ) ; if ( $ form -> isValid ( ) ) { return true ; } } return false ; } | Process text node form . |
43,964 | public function onSuccess ( $ locale , NodeInterface $ node ) { $ this -> eventDispatcher -> dispatch ( TadckaTreeEvents :: NODE_EDIT_SUCCESS , new TreeNodeEvent ( $ locale , $ node ) ) ; $ this -> textNodeManager -> save ( ) ; return $ this -> translator -> trans ( 'success.text_node_save' , array ( ) , 'SilvestraTextNodeBundle' ) ; } | On edit text node success . |
43,965 | public function all ( ) { $ res = [ ] ; $ len = count ( $ this -> fragments ) ; for ( $ index = 0 ; $ index < $ len ; $ index ++ ) { $ res [ ] = $ this -> get ( $ index ) ; } return $ res ; } | Get all fragments . |
43,966 | public function with ( $ index , $ value ) { $ res = clone $ this ; $ res -> fragments = $ this -> insertInList ( $ res -> fragments , $ index , $ value ) ; return $ this ; } | Set time fragment adding null fragments if needed . |
43,967 | public function withFragments ( array $ fragments ) { $ res = clone $ this ; $ res -> fragments = $ res -> fillArrayInput ( $ fragments ) ; return $ res ; } | Set all fragments adding null fragments if needed . |
43,968 | public function withSize ( $ index , $ value ) { $ res = clone $ this ; $ res -> sizes = $ this -> insertInList ( $ res -> sizes , $ index , $ value ) ; return $ res ; } | Set time fragment size adding null values if needed . |
43,969 | public function withSizes ( array $ sizes ) { $ res = clone $ this ; $ res -> sizes = $ res -> fillArrayInput ( $ sizes ) ; return $ res ; } | Set all sizes adding null values if needed . |
43,970 | public function insertInList ( array $ values , $ index , $ value ) { for ( $ i = count ( $ values ) ; $ i < $ index ; $ i ++ ) { $ values [ $ i ] = null ; } $ values [ $ index ] = $ value ; return $ values ; } | Insrt a value in a list inserting null values if needed to keep a conscutive indexing . |
43,971 | public function withTransversal ( $ index , $ value ) { $ res = clone $ this ; $ res -> transversals = $ this -> insertInList ( $ res -> transversals , $ index , $ value ) ; return $ res ; } | Set transversal unit adding null values if needed . |
43,972 | public function withTransversals ( array $ transversals ) { $ res = clone $ this ; $ res -> transversals = $ res -> fillArrayInput ( $ transversals ) ; return $ res ; } | Set all transversal units adding null values if needed . |
43,973 | public function expired ( \ DateTime $ date = null ) { if ( ! $ this -> expire ) { return false ; } $ date = $ date ? : new \ DateTime ( 'now' , new \ DateTimezone ( 'UTC' ) ) ; return ( $ date > $ this -> expire ) ; } | Checks whether the token has expired or is still valid . |
43,974 | protected function extractAbbreviation ( DateRepresentationInterface $ input ) { $ offset = $ input -> getOffset ( ) ; if ( null === $ abbr = $ offset -> getAbbreviation ( ) ) { return $ input ; } $ abbr = strtolower ( $ abbr ) ; $ list = DateTimeZone :: listAbbreviations ( ) ; if ( ! isset ( $ list [ $ abbr ] ) || empty ( $ list [ $ abbr ] ) ) { return $ input ; } $ list = $ list [ $ abbr ] ; $ criterias = [ 'offset' => $ offset -> getValue ( ) , 'timezone_id' => $ input -> getTimezone ( ) -> getName ( ) , 'dst' => $ offset -> isDst ( ) , ] ; foreach ( $ criterias as $ key => $ value ) { if ( null === $ value ) { continue ; } $ previous = $ list ; $ list = array_filter ( $ list , function ( $ infos ) use ( $ key , $ value ) { return $ value === $ infos [ $ key ] ; } ) ; if ( empty ( $ list ) ) { $ list = $ previous ; } } $ infos = reset ( $ list ) ; if ( null === $ offset -> getValue ( ) ) { $ offset = $ offset -> withValue ( $ infos [ 'offset' ] ) ; } return $ input -> withOffset ( $ offset -> withDst ( $ infos [ 'dst' ] ) ) -> withTimezone ( new DateTimeZone ( $ infos [ 'timezone_id' ] ) ) ; } | Extract informations from timezone abbreviation . |
43,975 | public function setBirthdate ( $ date ) { if ( $ date instanceof DateTime ) { $ date = $ date -> format ( 'Y-m-d' ) ; } $ this -> data -> birthDate = $ date ; return $ this ; } | Set customer birth date |
43,976 | public function setTaxDocument ( TaxDocument $ taxDocument ) { $ taxDocument -> setContext ( Moip :: PAYMENT ) ; $ this -> data -> taxDocument = $ taxDocument -> getData ( ) ; return $ this ; } | Set customer tax document |
43,977 | public function setCreditCard ( CreditCard $ creditCard ) { $ creditCard -> setContext ( Moip :: PAYMENT ) ; $ fundingInstrument = new stdClass ; $ fundingInstrument -> method = 'CREDIT_CARD' ; $ fundingInstrument -> creditCard = $ creditCard -> getData ( ) ; $ this -> data -> fundingInstrument = $ fundingInstrument ; unset ( $ this -> data -> fundingInstruments ) ; return $ this ; } | Set customer credit card |
43,978 | public function createNewCreditCard ( CreditCard $ creditCard , $ id = null ) { if ( ! $ id ) { $ id = $ this -> data -> id ; } $ creditCard -> setContext ( Moip :: PAYMENT ) ; $ this -> data = new stdClass ; $ this -> data -> method = 'CREDIT_CARD' ; $ this -> data -> creditCard = $ creditCard -> getData ( ) ; $ response = $ this -> client -> post ( '{id}/fundinginstruments' , [ $ id ] , $ this -> data ) ; $ this -> populate ( $ response ) ; return $ this ; } | Create a new credit card for customer |
43,979 | public function getEntityClass ( $ table , Row $ row = null ) { $ namespace = $ this -> defaultEntityNamespace . '\\' ; return $ namespace . ucfirst ( Utils :: underscoreToCamel ( $ table ) ) ; } | some_entity - > App \ Entity \ SomeEntity |
43,980 | public function getEntityField ( $ table , $ column ) { $ class = $ this -> getEntityClass ( $ table ) ; $ entity = new $ class ; $ reflection = $ entity -> getReflection ( $ this ) ; foreach ( $ reflection -> getEntityProperties ( ) as $ property ) { if ( $ property -> getColumn ( ) == $ column ) { return Utils :: underscoreToCamel ( $ property -> getName ( ) ) ; } } throw new InvalidArgumentException ( sprintf ( "Could not find property for table '%s' and column '%s'" , $ table , $ column ) ) ; } | some_field - > someField |
43,981 | private function hydrateIfJsonToArray ( $ data ) { if ( is_array ( $ data ) ) { return $ data ; } elseif ( is_string ( $ data ) ) { $ attempt = json_decode ( $ data , true ) ; return empty ( $ attempt ) ? $ data : $ attempt ; } return [ ] ; } | Hydrate if the passed parameter is json to array |
43,982 | public function setData ( $ data ) { $ resultData = $ this -> hydrateIfJsonToArray ( $ data ) ; if ( ! empty ( $ resultData ) ) { $ this -> data = $ resultData ; } else { $ this -> data = [ ] ; } } | Set data to data array |
43,983 | public function setExtra ( $ extra ) { $ resultData = $ this -> hydrateIfJsonToArray ( $ extra ) ; if ( ! empty ( $ resultData ) ) { $ this -> extra = $ resultData ; } else { $ this -> extra = [ ] ; } } | Set data to extra array |
43,984 | public function saveTimeEntry ( TimeEntry $ entry ) { $ startTime = strtotime ( $ entry -> getEntryDate ( ) ) ; $ endTime = $ startTime + $ entry -> getDurationTime ( ) ; $ this -> uri = 'https://www.toggl.com/api/v8/time_entries/' . $ entry -> getId ( ) ; $ data = [ 'time_entry' => [ 'description' => $ entry -> getDescription ( ) , 'start' => substr ( strftime ( '%Y-%m-%dT%H:%M:%S%z' , $ startTime ) , 0 , 22 ) . ':00' , 'stop' => substr ( strftime ( '%Y-%m-%dT%H:%M:%S%z' , $ endTime ) , 0 , 22 ) . ':00' , 'billable' => $ entry -> isBillable ( ) , 'wid' => $ this -> workspace_id , 'duration' => $ entry -> getDurationTime ( ) , 'tags' => $ entry -> getTags ( ) , 'id' => $ entry -> getId ( ) , 'created_with' => $ this -> user_agent ] ] ; $ this -> output -> debug ( print_r ( $ data , true ) ) ; $ data = json_encode ( $ data ) ; $ response = $ this -> processRequest ( $ data , self :: PUT ) ; $ this -> _handleError ( $ data , $ response ) ; return $ entry ; } | Persists a time entry to the Toggl API |
43,985 | protected function processTogglResponse ( $ response ) { if ( $ response -> total_count <= 50 ) { return $ response -> data ; } $ reqdata = [ ] ; $ reqdata = json_encode ( $ reqdata ) ; $ pages = ceil ( $ response -> total_count / 50 ) ; $ curr_page = 1 ; $ data = $ response -> data ; $ orig_uri = $ this -> uri ; while ( $ curr_page < $ pages ) { $ curr_page ++ ; $ this -> uri .= '&page=' . $ curr_page ; $ response = $ this -> processRequest ( $ reqdata , self :: GET ) ; $ this -> _handleError ( $ reqdata , $ response ) ; foreach ( $ response -> data as $ entry ) { $ data [ ] = $ entry ; } $ this -> uri = $ orig_uri ; } return $ data ; } | Process the response from Toggl to create a TimeEntry object |
43,986 | private function initialize ( object $ object , string $ original , string $ inverted ) : void { $ this -> initMethod ( $ object , $ original , true ) ; $ this -> initMethod ( $ object , $ inverted , false ) ; } | Inicializa la instancia calculando los valores para method y expected |
43,987 | public function mapExternalAssociation ( ExternalAssociation $ externalAssociation ) { if ( ! ( method_exists ( $ externalAssociation -> getReferenceManager ( ) , 'getReference' ) ) ) { $ msg = '$referenceManager needs to implements a `getReference` method' ; throw new \ InvalidArgumentException ( $ msg ) ; } $ this -> eventListener -> addExternalAssoctiation ( $ externalAssociation ) ; $ externalAssociation -> getObjectManager ( ) -> getEventManager ( ) -> addEventListener ( [ 'postLoad' ] , $ this -> eventListener ) ; } | Map an external association between two differents Object Manager |
43,988 | public function create ( PDO $ pdo ) { switch ( $ pdo -> getDatabaseType ( ) ) { case 'mysql' : $ connection = new MySqlConnection ( $ pdo ) ; break ; case 'pgsql' : $ connection = new PostgreSqlConnection ( $ pdo ) ; break ; case 'sqlite' : $ connection = new SQLiteConnection ( $ pdo ) ; break ; default : throw new InvalidDriverException ( 'Not implemented driver: ' . $ pdo -> getDatabaseType ( ) ) ; } return $ connection ; } | Create a new Connection based on the config |
43,989 | public function updateElement ( Element $ element , array $ data ) { if ( isset ( $ data [ "id" ] ) ) { $ element -> setId ( $ data [ "id" ] ) ; } if ( isset ( $ data [ "class" ] ) ) { $ element -> addClass ( $ data [ "class" ] ) ; } return $ element ; } | Set element properties using a json string |
43,990 | public function onPreSetData ( FormEvent $ event ) { if ( ! $ event -> getData ( ) || ! $ event -> getForm ( ) -> getConfig ( ) -> getOption ( 'removable' ) ) { return ; } $ event -> getForm ( ) -> add ( 'remove' , 'checkbox' , array ( 'label' => $ this -> options [ 'remove_label' ] ) ) ; } | Adds a remove - field if need |
43,991 | public function onPreSubmit ( FormEvent $ event ) { $ data = $ event -> getData ( ) ; if ( $ data [ 'file' ] instanceof UploadedFile ) { $ event -> getForm ( ) -> remove ( 'remove' ) ; } if ( empty ( $ data [ 'file' ] ) && ( ! isset ( $ data [ 'remove' ] ) || ! $ data [ 'remove' ] ) ) { $ event -> setData ( $ event -> getForm ( ) -> getViewData ( ) ) ; } } | Forbids to erase a value |
43,992 | private function addClientSection ( ArrayNodeDefinition $ node ) { $ node -> children ( ) -> arrayNode ( 'client' ) -> children ( ) -> scalarNode ( 'application_name' ) -> isRequired ( ) -> cannotBeEmpty ( ) -> end ( ) -> scalarNode ( 'client_id' ) -> end ( ) -> scalarNode ( 'client_secret' ) -> end ( ) -> scalarNode ( 'redirect_uri' ) -> end ( ) -> scalarNode ( 'developer_key' ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; } | Adds the client section . |
43,993 | public function singleAssociationAction ( ) { $ this -> checkStaticTemplateIsIncluded ( ) ; $ this -> checkSettings ( ) ; $ this -> slotExtendedAssignMultiple ( [ self :: VIEW_VARIABLE_ASSOCIATION_ID => $ this -> settings [ self :: SETTINGS_ASSOCIATION_ID ] ] , __CLASS__ , __FUNCTION__ ) ; return $ this -> view -> render ( ) ; } | single association action . |
43,994 | public function getLogger ( ) { if ( null === $ this -> logger && \ Zend_Registry :: isRegistered ( self :: getNamespace ( ) ) ) { $ this -> setLogger ( \ Zend_Registry :: get ( self :: getNamespace ( ) ) ) ; } return $ this -> logger ; } | Get instance of logger |
43,995 | public function resolveManager ( $ dic , $ placement = 'prepend' ) { $ manager = $ dic -> resolve ( 'Fuel\\Alias\\Manager' ) ; $ manager -> register ( $ placement ) ; return $ manager ; } | Resolves an Alias Manager |
43,996 | public function controllerName ( ) { $ request = $ this -> stack -> getCurrentRequest ( ) ; if ( $ request instanceof Request ) { $ string = $ request -> get ( '_controller' ) ; $ parts = explode ( '::' , $ string ) ; $ controller = $ parts [ 0 ] ; $ pattern = "#Controller\\\([a-zA-Z\\\]*)Controller#" ; $ matches = array ( ) ; preg_match ( $ pattern , $ controller , $ matches ) ; if ( isset ( $ matches [ 1 ] ) ) { return strtolower ( str_replace ( '\\' , '_' , $ matches [ 1 ] ) ) ; } return '' ; } return '' ; } | Get current controller name |
43,997 | public function actionName ( ) { $ request = $ this -> stack -> getCurrentRequest ( ) ; if ( $ request instanceof Request ) { $ pattern = "#::([a-zA-Z]*)Action#" ; $ matches = array ( ) ; preg_match ( $ pattern , $ request -> get ( '_controller' ) , $ matches ) ; if ( isset ( $ matches [ 1 ] ) ) { return strtolower ( $ matches [ 1 ] ) ; } return '' ; } return '' ; } | Get current action name |
43,998 | public function run ( $ target ) { $ return = $ this -> exec ( $ this -> getCommand ( $ target ) ) ; return $ this -> output [ $ target ] = $ this -> cleanOutput ( $ target , $ return [ 'output' ] ) ; } | Run the command with the given target |
43,999 | public static function v5 ( string $ namespace , string $ name ) { if ( ! Validate :: isValidUUID ( $ namespace ) ) { return false ; } $ nhex = str_replace ( array ( '-' , '{' , '}' ) , '' , $ namespace ) ; $ nstr = '' ; for ( $ i = 0 ; $ i < strlen ( $ nhex ) ; $ i += 2 ) { $ nstr .= \ chr ( hexdec ( $ nhex [ $ i ] . $ nhex [ $ i + 1 ] ) ) ; } $ hash = sha1 ( $ nstr . $ name ) ; return sprintf ( '%08s-%04s-%04x-%04x-%12s' , substr ( $ hash , 0 , 8 ) , substr ( $ hash , 8 , 4 ) , ( hexdec ( substr ( $ hash , 12 , 4 ) ) & 0x0fff ) | 0x5000 , ( hexdec ( substr ( $ hash , 16 , 4 ) ) & 0x3fff ) | 0x8000 , substr ( $ hash , 20 , 12 ) ) ; } | Generate identifier of 5th version |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.