idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
19,000 | public function getFieldValue ( string $ field_name ) { try { $ value = null ; $ fields = $ this -> stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( array_key_exists ( $ field_name , $ fields ) ) { $ value = $ fields [ $ field_name ] ; } else { throw new \ Exception ( "Field '$field_name' is not present in the current result set.\n" ) ; } return $ value ; } catch ( \ PDOException $ e ) { die ( 'Error: ' . $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { die ( "Error: " . $ e -> getMessage ( ) ) ; } } | Returns field s value |
19,001 | public function getFieldValues ( string $ field_name ) { try { $ field = [ ] ; $ result = $ this -> stmt -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; if ( array_key_exists ( $ field_name , $ result [ 0 ] ) ) { foreach ( $ result as $ row ) { $ field [ ] = $ row [ $ field_name ] ; } } else { throw new \ Exception ( "Field '$field_name' is not present in the current result set.\n" ) ; } return $ field ; } catch ( \ PDOException $ e ) { die ( 'Error: ' . $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { die ( "Error: " . $ e -> getMessage ( ) ) ; } } | Returns field s values |
19,002 | public function generate ( ) : string { $ namespace = $ this -> reflectionClass -> getNamespaceName ( ) ; $ fileDirectory = \ rtrim ( $ this -> directory , '/' ) . '/Proxy/' . \ str_replace ( '\\' , '/' , $ namespace ) ; $ fileName = $ this -> reflectionClass -> getShortName ( ) . 'Proxy.php' ; $ filePath = $ fileDirectory . '/' . $ fileName ; if ( ! \ is_dir ( $ fileDirectory ) ) { if ( false === @ \ mkdir ( $ fileDirectory , 0777 , true ) ) { throw new \ RuntimeException ( sprintf ( 'Could not create directory "%s" for proxy file. Maybe not rights?' , $ fileDirectory ) ) ; } } else if ( ! \ is_writable ( $ fileDirectory ) ) { throw new \ RuntimeException ( sprintf ( 'Cannot write to "%s" directory for save proxy file.' , $ fileDirectory ) ) ; } if ( false === @ \ touch ( $ filePath ) ) { throw new \ RuntimeException ( sprintf ( 'Could not create file "%s" for proxy class. Maybe not rights?' , $ filePath ) ) ; } \ file_put_contents ( $ filePath , $ this -> codeGenerator -> generate ( ) ) ; return $ filePath ; } | Generate proxy file |
19,003 | private function buildTree ( array $ rows , $ parent = null ) { $ tree = [ ] ; foreach ( $ rows as & $ row ) { if ( $ row [ 'parent' ] == $ parent ) { $ hasChildren = $ this -> propertyAccessor -> getValue ( $ row , "[{$this->options['children_column']}]" ) ; $ row [ 'hasChildren' ] = ( bool ) ( $ hasChildren > 0 ) ; $ row [ 'children' ] = $ this -> buildTree ( $ rows , $ row [ 'id' ] ) ; $ tree [ ] = $ row ; } } return $ tree ; } | Creates nested tree structure from result rows |
19,004 | protected function loadDatabaseConfig ( ) { if ( ! $ this -> databaseConfigFile ) { return null ; } $ configPath = "{$this->path}/{$this->databaseConfigFile}" ; if ( file_exists ( $ configPath ) ) { $ this -> databaseConfig = require $ configPath ; } else { throw new Exception ( "Unable to load database configuration." ) ; } } | Loads the database configuration file . |
19,005 | public function compileWhile ( $ expression ) { $ expression = $ this -> normalizeExpression ( $ expression ) ; preg_match ( '/ *(.*?) *(?:, *(.*))? *$/is' , $ expression , $ matches ) ; $ iteration = isset ( $ matches [ 2 ] ) ? trim ( $ matches [ 1 ] ) : $ expression ; $ length = isset ( $ matches [ 2 ] ) ? trim ( $ matches [ 2 ] ) : '' ; $ initLoop = '$loop = new ' . Counter :: class . "(); \$__currentLoopData = \$loop->start({$length}); \$__loops->addLoop(\$__currentLoopData);" ; return "<?php {$initLoop} while({$iteration}): ?>" ; } | Compile the while statements into valid PHP . |
19,006 | public function exportToPDFAction ( Meeting $ meeting ) { $ html = $ this -> render ( "InterneSeanceBundle:Export:pdf_export.html.twig" , [ "meeting" => $ meeting ] ) -> getContent ( ) ; $ html2pdf = $ this -> get ( 'html2pdf_factory' ) -> create ( ) ; $ html2pdf -> WriteHTML ( $ html ) ; $ html2pdf -> pdf -> SetTitle ( $ meeting -> getName ( ) ) ; $ file = $ html2pdf -> Output ( "export_" . strtolower ( $ meeting -> getName ( ) ) . ".pdf" , "I" ) ; } | Generate a PDF for a given Meeting entity |
19,007 | public static function getInstance ( $ driverName = null ) : AbstractMySQL { if ( ! static :: $ initialized ) { static :: $ baseClass = Base :: getInstance ( ) ; } $ driverName = $ driverName !== null ? '\\MS\\LightFramework\\Db\\MySQL\\Drivers\\' . $ driverName : '\\MS\\LightFramework\\Db\\MySQL\\Drivers\\' . ( ( string ) static :: $ baseClass -> Database -> MySQL -> driverClass ) ; $ driver = $ driverName :: getInstance ( ) ; if ( ! ( $ driver instanceof AbstractMySQL ) ) { throw new RuntimeException ( 'MySQL driver must extend \\MS\\LightFramework\\Db\\MySQL\\AbstractMySQL' ) ; } return $ driver ; } | Returns MySQL driver according to configuration . |
19,008 | public static function setIsDebug ( bool $ bool ) : void { if ( self :: isCliApp ( ) ) { self :: $ IS_DEBUG = $ bool ; } else { MSession :: set ( MCoreApplication :: DEBUG , $ bool ) ; } } | Set the debug mode . |
19,009 | public static function getApplicationDirPath ( ) : ? MApplicationDir { if ( self :: isCliApp ( ) ) { return self :: $ APPLICATION_DIR_PATH ; } return MSession :: get ( MCoreApplication :: APPLICATION_DIR_PATH ) ; } | Return the root path of the project . |
19,010 | public function newAction ( ) { $ entity = new Author ( ) ; $ form = $ this -> createForm ( new AuthorType ( ) , $ entity ) ; return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; } | Displays a form to create a new Author entity . |
19,011 | public function getHelper ( $ name , array $ options = [ ] ) { $ helper = $ this -> get ( $ name ) ; if ( ! empty ( $ options ) && is_callable ( [ $ helper , 'setOptions' ] ) ) { $ helper -> setOptions ( $ options ) ; } return $ helper ; } | Gets the helper and sets its options . |
19,012 | public function merge ( ViewHelpersInterface $ source ) { $ this -> registry = array_merge ( $ this -> registry , $ source -> getRegistry ( ) ) ; $ this -> instances = array_merge ( $ this -> instances , $ source -> getInstances ( ) ) ; return $ this ; } | Merges with other view helpers . |
19,013 | protected function removeNumericAndEmpty ( array & $ matches ) { foreach ( $ matches as $ idx => $ val ) { if ( is_int ( $ idx ) || '' === $ val ) { unset ( $ matches [ $ idx ] ) ; } } } | remove numeric keys and empty group match |
19,014 | public function store ( $ account_id = null , $ identifier = null , $ username = null , $ number , $ country_code = null , $ mobile_carrier_id = null , $ mobile_carrier_code = null , $ verified = null , $ upstream_app_name = null , $ verification_callback = null ) { $ fields = [ ] ; if ( ! is_null ( $ account_id ) ) $ fields [ 'account_id' ] = $ account_id ; if ( ! is_null ( $ identifier ) ) $ fields [ 'identifier' ] = $ identifier ; if ( ! is_null ( $ username ) ) $ fields [ 'username' ] = $ username ; $ fields [ 'number' ] = $ number ; if ( ! is_null ( $ country_code ) ) $ fields [ 'country_code' ] = $ country_code ; if ( ! is_null ( $ mobile_carrier_id ) ) $ fields [ 'mobile_carrier_id' ] = $ mobile_carrier_id ; if ( ! is_null ( $ mobile_carrier_code ) ) $ fields [ 'mobile_carrier_code' ] = $ mobile_carrier_code ; if ( ! is_null ( $ verified ) ) $ fields [ 'verified' ] = $ verified ; if ( ! is_null ( $ upstream_app_name ) ) $ fields [ 'upstream_app_name' ] = $ upstream_app_name ; if ( ! is_null ( $ verification_callback ) ) $ fields [ 'verification_callback' ] = $ verification_callback ; return $ this -> _post ( $ fields ) ; } | Create Or Update Mobile Phone |
19,015 | public function filterPreSetSiteTransientUpdatePlugins ( $ transient ) { $ this -> updatePluginData ( ) ; $ this -> updateGithubData ( ) ; if ( version_compare ( $ this -> githubLatestRelease [ 'tag_name' ] , $ this -> pluginData [ 'Version' ] ) === 1 ) { $ update = new \ stdClass ( ) ; $ update -> slug = $ this -> pluginSlug ; $ update -> new_version = $ this -> githubLatestRelease [ 'tag_name' ] ; $ update -> url = $ this -> pluginData [ 'PluginURI' ] ; $ update -> package = $ this -> githubLatestRelease [ 'zipball_url' ] ; $ transient -> response [ $ this -> pluginBaseName ] = $ update ; } return $ transient ; } | Add in plugin information in order to get updates |
19,016 | public function filterPluginsApi ( $ false , $ action , $ response ) { if ( empty ( $ response -> slug ) ) return false ; $ this -> updatePluginData ( ) ; if ( $ response -> slug != $ this -> pluginSlug ) return false ; $ this -> updateGithubData ( ) ; $ response -> last_updated = $ this -> githubLatestRelease [ 'published_at' ] ; $ response -> slug = $ this -> pluginSlug ; $ response -> name = $ this -> pluginData [ "Name" ] ; $ response -> version = $ this -> githubLatestRelease [ 'tag_name' ] ; $ response -> author = $ this -> pluginData [ "AuthorName" ] ; $ response -> homepage = $ this -> pluginData [ "PluginURI" ] ; $ response -> download_link = $ this -> githubLatestRelease [ 'zipball_url' ] ; $ parsedown = new \ Parsedown ( ) ; $ response -> sections = [ 'description' => $ this -> pluginData [ 'Description' ] , 'changelog' => $ parsedown -> text ( $ this -> githubLatestRelease [ 'body' ] ) ] ; return $ response ; } | This updates the details for showing information in the modal |
19,017 | public function filterUpgraderPostInstall ( $ true , $ hookExtra , $ result ) { $ this -> updatePluginData ( ) ; $ wasPluginActive = is_plugin_active ( $ this -> pluginBaseName ) ; global $ wp_filesystem ; $ pluginFolder = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname ( $ this -> pluginBaseName ) ; $ wp_filesystem -> move ( $ result [ 'destination' ] , $ pluginFolder ) ; $ result [ 'destination' ] = $ pluginFolder ; if ( $ wasPluginActive ) { $ activation = activate_plugin ( $ this -> pluginBaseName ) ; if ( is_wp_error ( $ activation ) ) { throw new \ Exception ( 'Unable to reactivate plugin: ' . $ activation -> get_error_message ( ) ) ; } } return $ result ; } | Handles the post upgrade moving of files and what not |
19,018 | protected function updatePluginData ( ) { $ this -> pluginBaseName = \ plugin_basename ( $ this -> pluginFile ) ; $ this -> pluginSlug = dirname ( $ this -> pluginBaseName ) ; $ this -> pluginData = \ get_plugin_data ( $ this -> pluginFile ) ; } | Gather plugin data from the file |
19,019 | protected function updateGithubData ( ) { if ( ! empty ( $ this -> githubLatestRelease ) ) return false ; $ url = \ esc_url_raw ( "https://api.github.com/repos/{$this->githubNamespace}/{$this->githubProject}/releases" ) ; $ response = \ wp_remote_retrieve_body ( \ wp_remote_get ( $ url ) ) ; if ( is_wp_error ( $ response ) ) { error_log ( $ response -> get_error_message ( ) ) ; return false ; } $ jsonDecodedResponse = json_decode ( $ response , true ) ; if ( is_null ( $ jsonDecodedResponse ) ) { error_log ( 'Unable to parse response: ' . json_last_error_msg ( ) ) ; return false ; } if ( empty ( $ jsonDecodedResponse [ 0 ] ) ) { error_log ( 'There is no release information gathered.' ) ; return false ; } $ this -> githubLatestRelease = $ jsonDecodedResponse [ 0 ] ; return true ; } | Update the data from GitHub |
19,020 | public function createMigration ( ) { $ migration = $ this -> laravel -> path . '/database/migrations/' . date ( 'Y_m_d_His' ) . '_drawbridge_migrations_tables.php' ; $ view = $ this -> laravel -> make ( 'view' ) -> make ( 'drawbridge::migration' ) -> render ( ) ; if ( ! file_exists ( $ migration ) ) { $ fs = fopen ( $ migration , 'x' ) ; if ( $ fs ) { fwrite ( $ fs , $ view ) ; fclose ( $ fs ) ; return true ; } } return false ; } | Create migration for tables |
19,021 | function validateObjectAttributeHTTPInput ( $ http , $ base , $ contentObjectAttribute ) { $ classList = $ http -> postVariable ( $ base . self :: CLASS_LIST_VARIABLE . $ contentObjectAttribute -> attribute ( "id" ) , array ( ) ) ; $ classList = ! is_array ( $ classList ) ? array ( ) : $ classList ; if ( empty ( $ classList ) && $ contentObjectAttribute -> validateIsRequired ( ) ) { $ contentObjectAttribute -> setValidationError ( ezpI18n :: tr ( "kernel/classes/datatypes" , "Input required." ) ) ; return eZInputValidator :: STATE_INVALID ; } $ invalidClassIdentifiers = array ( ) ; foreach ( $ classList as $ classIdentifier ) { if ( ! eZContentClass :: exists ( $ classIdentifier , eZContentClass :: VERSION_STATUS_DEFINED , false , true ) ) { $ invalidClassIdentifiers [ ] = $ classIdentifier ; } } if ( ! empty ( $ invalidClassIdentifiers ) ) { if ( count ( $ invalidClassIdentifiers ) == 1 ) { $ contentObjectAttribute -> setValidationError ( ezpI18n :: tr ( "extension/ngclasslist/datatypes" , "Class with identifier '%identifier%' does not exist" , null , array ( "%identifier%" => $ invalidClassIdentifiers [ 0 ] ) ) ) ; } else { $ contentObjectAttribute -> setValidationError ( ezpI18n :: tr ( "extension/ngclasslist/datatypes" , "Classes with '%identifiers%' identifiers do not exist" , null , array ( "%identifiers%" => implode ( ", " , $ invalidClassIdentifiers ) ) ) ) ; } return eZInputValidator :: STATE_INVALID ; } return eZInputValidator :: STATE_ACCEPTED ; } | Validates the input and returns the validity status code |
19,022 | public function getProperty ( & $ object , $ propertyName ) { $ property = $ this -> getPropertyInstance ( $ object , $ propertyName ) ; $ property -> setAccessible ( true ) ; return $ property -> getValue ( $ object ) ; } | Gets a property value |
19,023 | protected function validatePattern ( $ pattern ) { if ( ! is_string ( $ pattern ) || substr_count ( $ pattern , '[' ) !== substr_count ( $ pattern , ']' ) || substr_count ( $ pattern , '{' ) !== substr_count ( $ pattern , '}' ) ) { throw new LogicException ( Message :: get ( Message :: RTE_PATTERN_MALFORM , $ pattern ) , Message :: RTE_PATTERN_MALFORM ) ; } } | Validate the pattern |
19,024 | public function applyConfigOverrides ( ) { $ config_items = [ ] ; foreach ( $ this -> settings_default as $ key => $ value ) { if ( ee ( ) -> config -> item ( $ key ) ) { $ config_items [ $ key ] = ee ( ) -> config -> item ( $ key ) ; } } if ( is_array ( $ this -> settings ) ) { $ this -> settings = array_merge ( $ this -> settings , $ config_items ) ; } } | Config Overrides . |
19,025 | public function _log ( $ message ) { ee ( ) -> load -> library ( 'logger' ) ; ee ( ) -> load -> library ( 'user_agent' ) ; ee ( ) -> logger -> developer ( $ this -> package . ' - ' . $ message ) ; } | Log to the developer log if the setting is turned on . |
19,026 | private function add_new_hooks ( ) { foreach ( $ this -> hooks as $ hook => $ method ) { if ( ! isset ( $ this -> current_hooks [ $ hook ] ) ) { $ data = [ 'class' => $ this -> package , 'method' => $ method , 'hook' => $ hook , 'settings' => serialize ( $ this -> settings ( ) ) , 'priority' => 10 , 'version' => $ this -> version , 'enabled' => 'y' , ] ; ee ( ) -> db -> insert ( 'extensions' , $ data ) ; } } } | Add New Hooks . |
19,027 | public function update_extension ( $ current = '' ) { if ( $ current == '' || $ current == $ this -> version ) { return false ; } if ( $ current < '0.1' ) { } $ this -> add_new_hooks ( ) ; ee ( ) -> db -> where ( 'class' , $ this -> package ) ; ee ( ) -> db -> update ( 'extensions' , [ 'version' => $ this -> version ] ) ; } | Update Extension . |
19,028 | public static function Apci13 ( $ date1 , $ date2 , iauASTROM & $ astrom , & $ eo ) { $ ehpv = [ ] ; $ ebpv = [ ] ; $ r = [ ] ; $ x ; $ y ; $ s ; IAU :: Epv00 ( $ date1 , $ date2 , $ ehpv , $ ebpv ) ; IAU :: Pnm06a ( $ date1 , $ date2 , $ r ) ; IAU :: Bpn2xy ( $ r , $ x , $ y ) ; $ s = IAU :: S06 ( $ date1 , $ date2 , $ x , $ y ) ; IAU :: Apci ( $ date1 , $ date2 , $ ebpv , $ ehpv [ 0 ] , $ x , $ y , $ s , $ astrom ) ; $ eo = IAU :: Eors ( $ r , $ s ) ; } | - - - - - - - - - - i a u A p c i 1 3 - - - - - - - - - - |
19,029 | public function fromRaw ( $ value ) { $ type = $ this -> getDataType ( ) ; if ( $ type === 'json' ) { $ value = json_decode ( $ value , true ) ; } elseif ( $ type === 'array' ) { $ value = ( array ) $ value ; } elseif ( $ type === 'list' ) { $ value = explode ( ',' , $ value ) ; } elseif ( $ type === 'boolean' ) { $ value = $ value ? '1' : '0' ; } elseif ( $ type === 'integer' ) { if ( strlen ( $ value ) ) { $ value = ( int ) $ value ; } else { $ value = null ; } } elseif ( $ type === 'float' ) { if ( strlen ( $ value ) ) { $ value = ( float ) $ value ; } else { $ value = null ; } } return $ value ; } | From submitted value to object . |
19,030 | public function serialize ( $ value ) { if ( $ this -> getDataType ( ) === 'json' ) { return json_encode ( $ value ) ; } elseif ( $ this -> getDataType ( ) === 'array' ) { return json_encode ( $ value ) ; } elseif ( $ this -> getDataType ( ) === 'list' ) { return implode ( ',' , $ value ) ; } return trim ( $ value ) ; } | From object to database . |
19,031 | public function unserialize ( $ value ) { $ type = $ this -> getDataType ( ) ; if ( $ type === 'json' ) { $ value = json_decode ( $ value , true ) ; } elseif ( $ type === 'array' ) { $ value = json_decode ( $ value , true ) ; } elseif ( $ type === 'list' ) { $ value = explode ( ',' , $ value ) ; } elseif ( $ type === 'boolean' ) { $ value = ( bool ) $ value ; } elseif ( $ type === 'integer' ) { if ( strlen ( $ value ) ) { $ value = ( int ) $ value ; } else { $ value = null ; } } elseif ( $ type === 'float' ) { if ( strlen ( $ value ) ) { $ value = ( float ) $ value ; } else { $ value = null ; } } return $ value ; } | From database to object . |
19,032 | public function getScoreByCategory ( ) { $ categories = array ( ) ; foreach ( $ this -> getData ( ) as $ template ) { $ category = $ template -> getQuestion ( ) -> getCategory ( ) ; if ( ! isset ( $ categories [ $ category -> getId ( ) ] ) ) { $ categories [ $ category -> getId ( ) ] = array ( 'name' => $ category -> getName ( ) , 'valid' => 0 , 'total' => 0 , 'color' => '#' . substr ( '00000' . dechex ( mt_rand ( 0 , 0xffffff ) ) , - 6 ) ) ; } if ( $ template -> isValid ( ) ) { $ categories [ $ category -> getId ( ) ] [ 'valid' ] ++ ; } $ categories [ $ category -> getId ( ) ] [ 'total' ] ++ ; } return $ categories ; } | Get score by category |
19,033 | public function getScoreByLevel ( ) { $ levels = array ( ) ; foreach ( $ this -> getData ( ) as $ template ) { $ question = $ template -> getQuestion ( ) ; if ( ! isset ( $ levels [ $ question -> getLevel ( ) ] ) ) { $ levels [ $ question -> getLevel ( ) ] = array ( 'name' => $ question -> getLevel ( ) , 'valid' => 0 , 'total' => 0 , 'color' => '#' . substr ( '00000' . dechex ( mt_rand ( 0 , 0xffffff ) ) , - 6 ) ) ; } if ( $ template -> isValid ( ) ) { $ levels [ $ question -> getLevel ( ) ] [ 'valid' ] ++ ; } $ levels [ $ question -> getLevel ( ) ] [ 'total' ] ++ ; } sort ( $ levels ) ; return $ levels ; } | Get Score by question level |
19,034 | public function getPercentagePartial ( ) { $ total = $ this -> getTotal ( ) ; return round ( ( ( $ this -> score -> getValid ( ) + $ this -> score -> getPartial ( ) ) / $ total ) * 100 ) ; } | Get percentage valid + partial |
19,035 | public function getTotal ( ) { return $ this -> score -> getValid ( ) + $ this -> score -> getPartial ( ) + $ this -> score -> getNotValid ( ) ; } | Get total answers |
19,036 | final public function doIndex ( $ start = 0 , $ len = 30 , $ search = null ) { if ( $ search !== null && is_array ( $ search ) ) { $ tmp = ' WHERE ' ; $ and = '' ; foreach ( $ search as $ k => $ v ) { $ tmp .= $ and . $ k . ' LIKE "%' . $ v . '%" ' ; $ and = ' AND ' ; } $ search = $ tmp ; } else { $ search = '' ; } $ this -> db -> query ( 'SELECT * FROM ' . $ this -> table . $ search . ' LIMIT ' . ( 0 + $ start ) . ', ' . ( 0 + $ len ) ) ; return $ this -> db -> result ( ) ; } | Lista todos || paginado |
19,037 | final public function doShow ( $ id ) { $ this -> db -> query ( 'SELECT * FROM ' . $ this -> table . ' WHERE id = :id' , [ ':id' => $ id ] ) ; $ result = $ this -> db -> result ( ) ; return $ result ? $ result : false ; } | Lista o selecionado |
19,038 | public function send ( Request $ request ) { $ response = $ this -> adapter -> send ( $ request ) ; return $ response -> getBody ( ) -> getContents ( ) ; } | Sends a request and returns it s body |
19,039 | public function createRequest ( $ method , $ url = null , array $ options = [ ] ) { $ protocol_version = '1.1' ; $ body = null ; $ headers = [ ] ; extract ( $ options ) ; $ request = new Message \ Request ; $ request -> setMethod ( $ method ) ; $ request -> setUrl ( $ url ? ( string ) $ this -> createUrl ( $ url ) : ( string ) $ this -> baseUrl ) ; $ request -> setProtocolVersion ( $ protocol_version ) ; if ( isset ( $ body ) ) { $ body = Stream :: create ( $ body ) ; $ request -> setBody ( $ body ) ; } foreach ( $ headers as $ key => $ value ) { $ request -> setHeader ( $ key , $ value ) ; } return $ request ; } | Creates a request |
19,040 | protected function createUrl ( $ url ) { if ( strpos ( $ url , '://' ) ) { return Url :: createFromUrl ( $ url ) ; } $ url = Url :: createFromUrl ( $ url ) ; $ query = $ this -> baseUrl -> getQuery ( ) ; $ path = $ this -> baseUrl -> getPath ( ) ; $ query -> modify ( $ url -> getQuery ( ) ) ; $ path -> append ( $ url -> getPath ( ) ) ; return $ this -> baseUrl -> setQuery ( $ query ) -> setPath ( $ path ) ; } | Creates a URL using the base URL |
19,041 | private function subVars ( $ query , $ vars = [ ] ) { if ( ! is_array ( $ vars ) ) { $ vars = [ $ vars ] ; } $ queryParts = explode ( "?" , $ query ) ; if ( count ( $ queryParts ) - 1 != count ( $ vars ) ) { throw new \ Exception ( "Number of variables supplied does not match number of ?s in the query!" ) ; } $ finalQuery = $ queryParts [ 0 ] ; $ queryPartNo = 0 ; foreach ( $ vars as $ var ) { $ var = $ this -> escapifyVariable ( $ var ) ; $ queryPartNo ++ ; $ finalQuery .= $ var . $ queryParts [ $ queryPartNo ] ; } return $ finalQuery ; } | fakey bound parameters |
19,042 | public function findApplicableFiltersByMessage ( Message $ message , $ handler = null ) { if ( $ handler ) { $ filters = $ this -> findByHandler ( $ handler ) ; } else { $ filters = $ this -> findAll ( ) ; } $ applicableFilters = [ ] ; $ checker = new MessageChecker ( ) ; foreach ( $ filters as $ filter ) { if ( ! $ checker -> checkByFilter ( $ filter , $ message ) ) { continue ; } $ applicableFilters [ ] = $ filter ; } return $ applicableFilters ; } | Return all filters applicable for a message . |
19,043 | public function FromBytes ( $ stream , $ offset ) { $ moved = 0 ; $ vi = 0 ; $ moved += $ parsed = ProtoBuf_Bytes2Varint ( $ stream , $ offset + $ moved , $ vi ) ; if ( $ parsed <= 0 ) return $ parsed ; $ this -> wt = ( $ vi & 0x07 ) ; $ this -> fn = ( $ vi >> 3 ) ; switch ( $ this -> wt ) { case ProtoBuf_Field :: ProtoBuf_WireType_Varint : $ this -> data = 0 ; $ moved += $ parsed = ProtoBuf_Bytes2Varint ( $ stream , $ offset + $ moved , $ this -> data ) ; break ; case ProtoBuf_Field :: ProtoBuf_WireType_64bit : $ this -> data = substr ( $ stream , $ offset + $ moved , 8 ) ; $ high4 = ProtoBuf_Bytes2Fixed ( substr ( $ this -> data , 4 ) , 4 ) ; if ( $ high4 == 0 ) { $ this -> fixed64_is_32bit = true ; $ this -> data = ProtoBuf_Bytes2Fixed ( $ this -> data , 4 ) ; } else { $ this -> fixed64_is_32bit = false ; $ this -> data = ProtoBuf_Bytes2Fixed ( $ this -> data , 8 ) ; } $ moved += 8 ; break ; case ProtoBuf_Field :: ProtoBuf_WireType_LengthDelimited : $ moved += $ parsed = ProtoBuf_Bytes2Varint ( $ stream , $ offset + $ moved , $ vi ) ; if ( $ parsed <= 0 ) return $ parsed ; $ this -> data = substr ( $ stream , $ offset + $ moved , $ vi ) ; $ moved += $ vi ; break ; case ProtoBuf_Field :: ProtoBuf_WireType_32bit : $ this -> data = substr ( $ stream , $ offset + $ moved , 4 ) ; $ this -> data = ProtoBuf_Bytes2Fixed ( $ this -> data , 4 ) ; $ moved += 4 ; break ; default : die ( "[lib_protobuf.inc] Unrecognized protobuf wire type '" . $ this -> wt . "'\n" ) ; break ; } return $ moved ; } | if fixed64 is in fact 32bit value this is just to improve compatibility with 32bit php which does not support 64 |
19,044 | public function set_feed_url ( $ url ) { $ this -> multifeed_url = array ( ) ; if ( is_array ( $ url ) ) { foreach ( $ url as $ value ) { $ this -> multifeed_url [ ] = $ this -> registry -> call ( 'Misc' , 'fix_protocol' , array ( $ value , 1 ) ) ; } } else { $ this -> feed_url = $ this -> registry -> call ( 'Misc' , 'fix_protocol' , array ( $ url , 1 ) ) ; } } | Set the URL of the feed you want to parse |
19,045 | public function set_stupidly_fast ( $ set = false ) { if ( $ set ) { $ this -> enable_order_by_date ( false ) ; $ this -> remove_div ( false ) ; $ this -> strip_comments ( false ) ; $ this -> strip_htmltags ( false ) ; $ this -> strip_attributes ( false ) ; $ this -> set_image_handler ( false ) ; } } | Set options to make SP as fast as possible |
19,046 | public function preRun ( ) : void { $ this -> insert = $ this -> getConnection ( ) -> insert ( $ this -> getTable ( ) , $ this -> getFields ( ) ) ; } | Prepares a statement and initiates a transaction in the pre - run phase . |
19,047 | public function getMessage ( ) { if ( $ this -> EmailMessage ) { return sprintf ( '%s %s' , rtrim ( $ this -> EmailMessage ) , $ this -> getCurrentPageLink ( ) ) ; } return $ this -> getCurrentPageLink ( ) ; } | Answers the message for the email . |
19,048 | public function getButtonLink ( ) { return sprintf ( 'mailto:?subject=%s&body=%s' , Convert :: raw2mailto ( $ this -> getSubject ( ) ) , Convert :: raw2mailto ( $ this -> getMessage ( ) ) ) ; } | Answers the link for the sharing button . |
19,049 | public function bind ( $ name , \ Closure $ callable , $ singleton = false ) { $ this -> _ioc [ $ name ] = array ( 'closure' => $ callable , 'singleton' => ( bool ) $ singleton , 'instance' => null ) ; return $ this ; } | Registers a new object container . |
19,050 | public function make ( $ name , array $ params = array ( ) , $ force = false ) { if ( isset ( $ this -> _ioc [ $ name ] ) ) { if ( $ this -> _ioc [ $ name ] [ 'instance' ] && ! $ force ) return $ this -> _ioc [ $ name ] [ 'instance' ] ; $ params [ ] = $ this ; $ result = call_user_func_array ( $ this -> _ioc [ $ name ] [ 'closure' ] , $ params ) ; if ( $ this -> _ioc [ $ name ] [ 'singleton' ] ) $ this -> _ioc [ $ name ] [ 'instance' ] = $ result ; return $ result ; } return null ; } | Resolves a set container and returns the result . |
19,051 | public function on ( $ event , $ callable ) { if ( ! is_callable ( $ callable ) && ! $ callable instanceof \ Closure ) throw new \ InvalidArgumentException ( ) ; if ( ! isset ( $ this -> _hooks [ $ event ] ) ) $ this -> _hooks [ $ event ] = array ( ) ; $ this -> _hooks [ $ event ] [ ] = $ callable ; return $ this ; } | Binds a new callable action to a hook event . |
19,052 | public function setDateTime ( ... $ params ) { switch ( count ( $ params ) ) { case 5 : case 6 : return parent :: setDate ( ... array_slice ( $ params , 0 , 3 ) ) -> setTime ( ... array_slice ( $ params , 3 , 3 ) ) ; case 1 : $ param = $ params [ 0 ] ; if ( is_string ( $ param ) ) { if ( preg_match ( '~(\d\d\d\d)-(\d\d)-(\d\d) ([012]\d):([0-5]\d):([0-5]\d)~' , $ param , $ values ) === 1 ) { return parent :: setDate ( ... array_slice ( $ values , 1 , 3 ) ) -> setTime ( ... array_slice ( $ values , 4 , 3 ) ) ; } throw new \ InvalidArgumentException ( "Invalid DateTime format `{$param}` passed to setDateTime(); expecting `YYYY-MM-DD HH:MM:SS`" ) ; } } throw new \ InvalidArgumentException ( 'Invalid number or type of params for setDateTime(); requires one DateTime string or 6x params for year, month, day, hour, minute, second' ) ; } | Set the date and time all together |
19,053 | public static function createInterval ( $ interval ) { return isset ( static :: $ intervals [ $ interval ] ) ? static :: $ intervals [ $ interval ] : static :: $ intervals [ $ interval ] = $ interval [ 0 ] === 'P' ? new \ DateInterval ( $ interval ) : \ DateInterval :: createFromDateString ( $ interval ) ; } | Create a DateInterval from ISO 8601 duration string OR relative parts! |
19,054 | public static function createIntervalFromSpec ( $ interval_spec ) { return isset ( static :: $ intervals [ $ interval_spec ] ) ? static :: $ intervals [ $ interval_spec ] : static :: $ intervals [ $ interval_spec ] = new \ DateInterval ( $ interval_spec ) ; } | Create a DateInterval from ISO 8601 duration string |
19,055 | public static function createIntervalFromDateString ( $ time ) { return isset ( static :: $ intervals [ $ time ] ) ? static :: $ intervals [ $ time ] : static :: $ intervals [ $ time ] = \ DateInterval :: createFromDateString ( $ time ) ; } | Create a DateInterval from a string of relative parts |
19,056 | public static function create ( ... $ params ) { switch ( count ( $ params ) ) { case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : } return new static ( new \ DateTime ( $ time , $ timezone === null ? self :: $ utc : ( is_string ( $ timezone ) ? new \ DateTimeZone ( $ timezone ) : $ timezone ) ) ) ; } | Create a new Twister \ DateTime instance from a specific date and time . |
19,057 | public static function __parse ( $ date , & $ result = null ) { $ result = date_parse ( $ date ) ; if ( $ result [ 'warning_count' ] === 0 && $ result [ 'error_count' ] === 0 ) { $ year = $ result [ 'year' ] ; $ month = $ result [ 'month' ] ; $ day = $ result [ 'day' ] ; $ hour = $ result [ 'hour' ] ; $ minute = $ result [ 'minute' ] ; $ second = $ result [ 'second' ] ; $ fraction = $ result [ 'fraction' ] ; $ format = null ; $ value = null ; if ( is_numeric ( $ year ) && is_numeric ( $ month ) && is_numeric ( $ day ) ) { $ value = str_pad ( $ year , 4 , '0' , STR_PAD_LEFT ) . str_pad ( $ month , 3 , '-0' , STR_PAD_LEFT ) . str_pad ( $ day , 3 , '-0' , STR_PAD_LEFT ) ; $ format = 'Y-m-d' ; } if ( is_numeric ( $ hour ) && is_numeric ( $ minute ) && is_numeric ( $ second ) ) { $ value .= str_pad ( $ hour , 2 , '0' , STR_PAD_LEFT ) . str_pad ( $ minute , 3 , ':0' , STR_PAD_LEFT ) . str_pad ( $ second , 3 , ':0' , STR_PAD_LEFT ) ; $ format .= 'H:i:s' ; } $ is_localtime = $ result [ 'is_localtime' ] ; if ( $ is_localtime ) { } } return null ; } | Wrapper around date_parse |
19,058 | public function md5 ( $ format = null , $ raw_output = false ) { return hash ( 'md5' , parent :: format ( $ format === null ? static :: $ format : $ format ) , $ raw_output ) ; } | Gets an MD5 hash code of the internal date . Return result can be raw binary or hex by default |
19,059 | public function sha256 ( $ format = null , $ raw_output = false ) { return hash ( 'sha256' , parent :: format ( $ format === null ? static :: $ format : $ format ) , $ raw_output ) ; } | Gets a SHA - 256 hash code of the internal string . Return result can be raw binary or hex by default |
19,060 | public function sha384 ( $ format = null , $ raw_output = false ) { return hash ( 'sha384' , parent :: format ( $ format === null ? static :: $ format : $ format ) , $ raw_output ) ; } | Gets a SHA - 384 hash code of the internal string . Return result can be raw binary or hex by default |
19,061 | public function sha512 ( $ format = null , $ raw_output = false ) { return hash ( 'sha512' , parent :: format ( $ format === null ? static :: $ format : $ format ) , $ raw_output ) ; } | Gets a SHA - 512 hash code of the internal string . Return result can be raw binary or hex by default |
19,062 | public static function map ( $ actions = array ( ) , $ options = array ( ) ) { if ( empty ( $ actions ) ) { return null ; } $ out = array ( ) ; $ count = 0 ; $ len = count ( $ actions ) ; foreach ( $ actions as $ label => $ mixed ) { $ count ++ ; $ action = new Item ( $ label , $ mixed ) ; if ( $ count == 1 ) { $ action -> isFirst = true ; } if ( $ count == $ len ) { $ action -> isLast = true ; } $ out [ ] = $ action ; } return $ out ; } | Get actions mapped Preserve structure |
19,063 | public function getReplicator ( ) { if ( ! isset ( $ this -> replicator ) ) { $ this -> replicator = $ this -> createReplicator ( ) ; } return $ this -> replicator ; } | Returns the replicator used . |
19,064 | public function materializeCollection ( $ collection ) { $ materializedCollection = new Collection ( ) ; foreach ( $ collection as $ resource ) { $ materializedCollection -> add ( $ this -> materialize ( $ resource ) ) ; } return $ materializedCollection ; } | Materializes a collection of resources . |
19,065 | public function materialize ( $ resource , $ overwrite = false ) { if ( $ resource instanceof MaterializedResource ) { return $ resource ; } if ( $ overwrite || ! $ this -> exists ( $ resource ) ) { try { $ this -> getReplicator ( ) -> replicate ( $ resource ) ; } catch ( ReplicatorException $ e ) { throw new MaterializeException ( sprintf ( 'Cannot materialize resource: %s' , $ e -> getMessage ( ) ) , 0 , $ e ) ; } $ materialized = true ; } $ materializedResource = new MaterializedResource ( $ resource , $ this -> getDirectory ( ) ) ; if ( ! empty ( $ materialized ) ) { $ this -> dispatcher -> dispatch ( ResourceEvents :: MATERIALIZE , new ResourceMaterializeEvent ( $ materializedResource ) ) ; } return $ materializedResource ; } | Materializes a resource . |
19,066 | public function store ( $ resource ) { if ( ! $ resource instanceof LocalResource ) { throw new \ InvalidArgumentException ( 'Resource is not local.' ) ; } $ file = $ this -> directory . '/' . $ resource -> getPath ( ) ; @ mkdir ( dirname ( $ file ) , 0777 , true ) ; file_put_contents ( $ file , $ resource -> getContent ( ) ) ; return new MaterializedResource ( $ resource , $ this -> directory ) ; } | Stores a local resource . Existing files are overwritten . |
19,067 | public function getCallableData ( ) { $ result = parent :: getCallableData ( ) ; $ data = $ this -> model -> toArray ( ) ; $ data [ 'class' ] = $ this -> model -> className ( ) ; $ result [ 'object' ] = $ data ; return $ result ; } | Admin edit widget data |
19,068 | public function getRpAttributes ( ) { $ result = [ ] ; $ rpm = $ this -> model -> relatedPropertiesModel ; if ( $ attributes = $ this -> visibleRpAttributes ) { foreach ( $ attributes as $ attribute ) { if ( ! $ this -> visible_only_has_values ) { $ result [ ] = $ attribute ; continue ; } $ value = $ rpm -> getSmartAttribute ( $ attribute ) ; if ( $ value ) { $ result [ $ attribute ] = $ value ; continue ; } } } return $ result ; } | Smart visible code = > value |
19,069 | public function getVisibleRpAttributes ( ) { if ( $ this -> visible_properties ) { return ( array ) $ this -> visible_properties ; } else { $ this -> model -> relatedPropertiesModel -> initAllProperties ( ) ; $ attributes = $ this -> model -> relatedPropertiesModel -> toArray ( ) ; if ( $ attributes ) { return array_keys ( $ attributes ) ; } else { return [ ] ; } } } | Only visible codes |
19,070 | public static function fromXml ( \ DOMNodeList $ xml ) { $ items = array ( ) ; foreach ( $ xml as $ xmlTag ) { $ items [ ] = Loan :: fromXml ( $ xmlTag ) ; } return new static ( $ items ) ; } | Builds a LoanCollection object from XML . |
19,071 | public static function title ( $ value , $ encoding = null ) { $ options = [ ] ; $ encoding = $ encoding ? : static :: $ encoding ; if ( $ encoding ) { $ options [ 'encoding' ] = $ encoding ; } return StaticFilter :: execute ( static :: camelCaseToUnderscore ( $ value ) , Filter \ UpperCaseWords :: class , $ options ) ; } | Convert the given string to title case . |
19,072 | public static function slug ( $ string , $ separator = '-' , array $ options = [ ] ) { if ( ! static :: $ slugify instanceof Slugify ) { static :: $ slugify = Slugify :: create ( $ options ) ; } return mb_strtolower ( static :: $ slugify -> slugify ( $ string , $ separator ) ) ; } | Creates url friendly string . |
19,073 | public static function alternator ( array $ strings ) { return function ( ) use ( $ strings ) { static $ i = 0 ; $ index = $ i ++ % count ( $ strings ) ; return $ strings [ $ index ] ; } ; } | Returns a closure that will alternate between the defined strings . |
19,074 | public static function getRandomBytes ( $ byteLength ) { $ results = null ; if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ results = openssl_random_pseudo_bytes ( $ byteLength ) ; } elseif ( is_readable ( '/dev/urandom' ) ) { $ fileHandler = fopen ( '/dev/urandom' , 'rb' ) ; if ( $ fileHandler !== false ) { $ results = fread ( $ fileHandler , $ byteLength ) ; fclose ( $ fileHandler ) ; } } elseif ( function_exists ( 'mcrypt_create_iv' ) && version_compare ( PHP_VERSION , '5.3.0' , '>=' ) ) { $ results = mcrypt_create_iv ( $ byteLength , MCRYPT_DEV_RANDOM ) ; } elseif ( function_exists ( 'random_bytes' ) ) { $ results = random_bytes ( $ byteLength ) ; } elseif ( class_exists ( 'COM' ) ) { try { $ capiUtil = new \ COM ( 'CAPICOM.Utilities.1' ) ; $ results = $ capiUtil -> GetRandom ( $ byteLength , 0 ) ; } catch ( \ Exception $ ex ) { } } if ( empty ( $ results ) ) { throw new Exception \ RuntimeException ( 'Unable to find a secure method for generating random bytes.' ) ; } return $ results ; } | Returns X random raw binary bytes . |
19,075 | public static function hasFlag ( string $ flag ) : bool { $ flag = ltrim ( $ flag , '-' ) ; if ( isset ( static :: $ flags [ $ flag ] ) ) { return static :: $ flags [ $ flag ] ; } $ result = strpos ( static :: $ info [ INFO_ALL ] ?? static :: getInfo ( INFO_GENERAL ) , '--' . $ flag ) ; return static :: $ flags [ $ flag ] = false !== $ result ; } | Checks whether PHP has been compiled with the given flag . |
19,076 | public function finish ( string $ document , LayoutInterface $ layout ) : string { return str_replace ( [ '<' . ManipulatorInterface :: WORKING_TAG . '>' , '</' . ManipulatorInterface :: WORKING_TAG . '>' ] , '' , $ document ) ; } | Finish the plain text layout document |
19,077 | public static function factory ( $ config = array ( ) ) { $ default = array ( 'Accept' => 'application/json' , 'environment' => 'prod' , 'service-description-name' => Client :: NAME_SERVICE_API , 'store' => new FileStore ( ) , 'ssl' => false ) ; $ required = array ( 'base_url' , 'client_id' , 'secret' , ) ; $ config = Collection :: fromConfig ( $ config , $ default , $ required ) ; if ( $ config [ 'environment' ] == 'dev' && $ config [ 'ssl' ] == false ) { $ config [ 'ssl.certificate_authority' ] = 'system' ; $ config [ 'curl.options' ] = array ( CURLOPT_SSL_VERIFYHOST => false , CURLOPT_SSL_VERIFYPEER => false ) ; } $ client = new self ( $ config -> get ( 'base_url' ) , $ config ) ; $ client -> authenticateAsGuest = isset ( $ config [ 'as_guest' ] ) ? $ config [ 'as_guest' ] : false ; $ client -> chateaOAuth2Client = $ config -> get ( 'OAuth2Client' ) ; $ client -> store = $ config -> get ( 'store' ) ; $ client -> addSubscriber ( new AcceptHeaderPluging ( $ config -> toArray ( ) ) ) ; return $ client ; } | Build new class ChateaOAuth2Client this provides commands to run at ApiChateaServer This client can get self credentials and save in store . This version do not encrypted credentials . |
19,078 | private function prepareAccessToken ( ) { if ( ! $ this -> store -> getPersistentData ( 'token_expires_at' ) ) { return $ this -> getAccessTokenWithClientCredentials ( ) ; } else if ( $ this -> store -> getPersistentData ( 'token_expires_at' ) < time ( ) ) { try { return $ this -> getAccessTokenWithRefreshToken ( ) ; } catch ( AuthenticationException $ e ) { return $ this -> getAccessTokenWithClientCredentials ( ) ; } } else { return $ this -> store -> getPersistentData ( 'access_token' ) ; } } | This retrieve the access token in store or in server |
19,079 | public static function init ( ) { foreach ( glob ( implode ( DIRECTORY_SEPARATOR , array ( __DIR__ , 'Format' , '*.php' ) ) ) as $ filename ) { $ filename = explode ( DIRECTORY_SEPARATOR , $ filename ) ; $ filename = explode ( '.' , array_pop ( $ filename ) ) ; array_pop ( $ filename ) ; $ filename = implode ( '.' , $ filename ) ; if ( $ filename == 'FormatInterface' ) continue ; $ className = explode ( "\\" , __CLASS__ ) ; array_pop ( $ className ) ; array_push ( $ className , 'Format' ) ; array_push ( $ className , $ filename ) ; $ className = implode ( '\\' , $ className ) ; self :: registerFormat ( $ className ) ; } foreach ( glob ( implode ( DIRECTORY_SEPARATOR , array ( __DIR__ , 'Storage' , '*.php' ) ) ) as $ filename ) { $ filename = explode ( DIRECTORY_SEPARATOR , $ filename ) ; $ filename = explode ( '.' , array_pop ( $ filename ) ) ; array_pop ( $ filename ) ; $ filename = implode ( '.' , $ filename ) ; if ( $ filename == 'StorageInterface' ) continue ; $ className = explode ( "\\" , __CLASS__ ) ; array_pop ( $ className ) ; array_push ( $ className , 'Storage' ) ; array_push ( $ className , $ filename ) ; $ className = implode ( '\\' , $ className ) ; self :: registerStorage ( $ className ) ; } } | Initialize all direct - access variables This gets called as soon as this file is loaded |
19,080 | public function set_attribute ( $ key , $ value ) { $ attributes = $ this -> get_config ( 'form_attributes' , array ( ) ) ; $ attributes [ $ key ] = $ value ; $ this -> set_config ( 'form_attributes' , $ attributes ) ; return $ this ; } | Set form attribute |
19,081 | public function get_attribute ( $ key , $ default = null ) { $ attributes = $ this -> get_config ( 'form_attributes' , array ( ) ) ; return array_key_exists ( $ key , $ attributes ) ? $ attributes [ $ key ] : $ default ; } | Get form attribute |
19,082 | public function open ( $ attributes = array ( ) , array $ hidden = array ( ) ) { $ attributes = ! is_array ( $ attributes ) ? array ( 'action' => $ attributes ) : $ attributes ; if ( ! array_key_exists ( 'action' , $ attributes ) or empty ( $ attributes [ 'action' ] ) ) { $ attributes [ 'action' ] = \ Uri :: main ( ) ; } elseif ( ! strpos ( $ attributes [ 'action' ] , '://' ) ) { $ attributes [ 'action' ] = \ Uri :: create ( $ attributes [ 'action' ] ) ; } if ( empty ( $ attributes [ 'accept-charset' ] ) ) { $ attributes [ 'accept-charset' ] = strtolower ( \ Fuel :: $ encoding ) ; } ! empty ( $ attributes [ 'method' ] ) || $ attributes [ 'method' ] = $ this -> get_config ( 'form_method' , 'post' ) ; $ form = '<form' ; foreach ( $ attributes as $ prop => $ value ) { $ form .= ' ' . $ prop . '="' . $ value . '"' ; } $ form .= '>' ; foreach ( $ hidden as $ field => $ value ) { $ form .= PHP_EOL . $ this -> hidden ( $ field , $ value ) ; } return $ form ; } | Create a form open tag |
19,083 | public function fieldset_open ( $ attributes = array ( ) , $ legend = null ) { $ fieldset_open = '<fieldset ' . array_to_attr ( $ attributes ) . ' >' ; ! is_null ( $ legend ) and $ attributes [ 'legend' ] = $ legend ; if ( ! empty ( $ attributes [ 'legend' ] ) ) { $ fieldset_open .= "\n<legend>" . $ attributes [ 'legend' ] . "</legend>" ; } return $ fieldset_open ; } | Create a fieldset open tag |
19,084 | public function file ( $ field , array $ attributes = array ( ) ) { if ( is_array ( $ field ) ) { $ attributes = $ field ; } else { $ attributes [ 'name' ] = ( string ) $ field ; } $ attributes [ 'type' ] = 'file' ; return $ this -> input ( $ attributes ) ; } | Create a file upload input field |
19,085 | public function reset ( $ field = 'reset' , $ value = 'Reset' , array $ attributes = array ( ) ) { if ( is_array ( $ field ) ) { $ attributes = $ field ; } else { $ attributes [ 'name' ] = ( string ) $ field ; $ attributes [ 'value' ] = ( string ) $ value ; } $ attributes [ 'type' ] = 'reset' ; return $ this -> input ( $ attributes ) ; } | Create a reset button |
19,086 | public function submit ( $ field = 'submit' , $ value = 'Submit' , array $ attributes = array ( ) ) { if ( is_array ( $ field ) ) { $ attributes = $ field ; } else { $ attributes [ 'name' ] = ( string ) $ field ; $ attributes [ 'value' ] = ( string ) $ value ; } $ attributes [ 'type' ] = 'submit' ; return $ this -> input ( $ attributes ) ; } | Create a submit button |
19,087 | public function build_field ( $ field ) { ! $ field instanceof Fieldset_Field && $ field = $ this -> field ( $ field ) ; return $ field -> build ( ) ; } | Build & template individual field |
19,088 | public function add_csrf ( ) { $ this -> add ( \ Config :: get ( 'security.csrf_token_key' , 'fuel_csrf_token' ) , 'CSRF Token' ) -> set_type ( 'hidden' ) -> set_value ( \ Security :: fetch_token ( ) ) -> add_rule ( array ( 'Security' , 'check_token' ) ) ; return $ this ; } | Add a CSRF token and a validation rule to check it |
19,089 | protected function setFilesParameters ( ContainerBuilder $ container , array $ config , YamlFileLoader $ loader ) { $ container -> setParameter ( 'open_orchestra_media_admin.files.thumbnail_format' , $ config [ 'thumbnail' ] ) ; $ container -> setParameter ( 'open_orchestra_media_admin.files.alternatives.default.thumbnail' , $ config [ 'files' ] [ 'alternatives' ] [ 'default' ] [ 'thumbnail' ] ) ; $ container -> setParameter ( 'open_orchestra_media_admin.files.alternatives.audio.thumbnail' , $ config [ 'files' ] [ 'alternatives' ] [ 'audio' ] [ 'thumbnail' ] ) ; if ( count ( $ config [ 'files' ] [ 'alternatives' ] [ 'image' ] [ 'formats' ] ) > 0 ) { $ container -> setParameter ( 'open_orchestra_media_admin.files.alternatives.image.formats' , $ config [ 'files' ] [ 'alternatives' ] [ 'image' ] [ 'formats' ] ) ; } else { $ loader -> load ( 'alternatives_formats.yml' ) ; } } | Add the files generation parameters to the container Takes the Open Orchestra alternatives image formats or the application one instead if defined |
19,090 | public static function escapeValues ( array $ data , \ mysqli $ mysqli ) { foreach ( $ data as $ index => $ value ) { if ( $ value !== null ) { $ data [ $ index ] = mysqli_escape_string ( $ mysqli , $ value ) ; } } return $ data ; } | Escape an array of data for the database . |
19,091 | public static function generateBatchReplaceQuery ( array $ rows , $ tableName , \ mysqli $ mysqli ) { $ query = "REPLACE " . self :: generateBatchQueryCore ( $ rows , $ tableName , $ mysqli ) ; return $ query ; } | Generates a single REPLACE query that can replace any number of rows . Replacements will perform an insert except if a row with the same primary key or unique index already exists in which case an UPDATE will take place . |
19,092 | public static function generateBatchInsertQuery ( array $ rows , $ tableName , \ mysqli $ mysqli ) { $ query = "INSERT " . self :: generateBatchQueryCore ( $ rows , $ tableName , $ mysqli ) ; return $ query ; } | Generates a single INSERT query that for any number of rows . This is one of the most efficient ways to insert a lot of data . |
19,093 | private static function generateBatchQueryCore ( array $ rows , $ tableName , \ mysqli $ mysqli ) { $ firstRow = true ; $ dataStringRows = array ( ) ; if ( count ( $ rows ) == 0 ) { throw new \ Exception ( "Cannot create batch query with no data." ) ; } foreach ( $ rows as $ row ) { if ( $ firstRow ) { $ columns = array_keys ( $ row ) ; sort ( $ columns ) ; $ firstRow = false ; } ksort ( $ row ) ; $ escapedRow = self :: escapeValues ( $ row , $ mysqli ) ; $ quotedValues = array ( ) ; foreach ( $ escapedRow as $ columnName => $ value ) { if ( $ value !== null ) { $ quotedValues [ ] = "'" . $ value . "'" ; } else { $ quotedValues [ ] = 'NULL' ; } } $ dataStringRows [ ] = "(" . implode ( "," , $ quotedValues ) . ")" ; } $ columns = ArrayLib :: wrapElements ( $ columns , '`' ) ; $ query = "INTO `" . $ tableName . "` (" . implode ( ',' , $ columns ) . ") " . "VALUES " . implode ( "," , $ dataStringRows ) ; return $ query ; } | Helper function to generateBatchReplaceQuery and generateBatchInsertQuery which are 99% exactly the same except for the word REPLACE or INSERT . |
19,094 | public static function convertResultToArrayList ( \ mysqli_result $ result ) { $ list = array ( ) ; while ( ( $ row = $ result -> fetch_assoc ( ) ) != null ) { $ list [ ] = $ row ; } return $ list ; } | Convert a mysqli_result object into a list of rows . This is not memory efficient but can save the developer from writing a loop . |
19,095 | public static function getTableColumnNames ( \ mysqli $ mysqliConn , string $ tableName ) : array { $ sql = "SHOW COLUMNS FROM `{$tableName}`" ; $ result = $ mysqliConn -> query ( $ sql ) ; $ columns = array ( ) ; while ( ( $ row = $ result -> fetch_array ( ) ) != null ) { $ columns [ ] = $ row [ 0 ] ; } return $ columns ; } | Fetches the names of the columns for a particular table . |
19,096 | public static function getTableHash ( \ mysqli $ mysqliConn , string $ tableName , array $ columns = array ( ) ) : string { $ tableHash = "" ; if ( count ( $ columns ) == 0 ) { $ columns = MysqliLib :: getTableColumnNames ( $ mysqliConn , $ tableName ) ; sort ( $ columns ) ; } $ wrappedColumnList = array ( ) ; foreach ( $ columns as $ column ) { $ wrappedColumnList [ ] = "COALESCE(`" . $ column . "`, 'NULL')" ; } $ mysqliConn -> query ( "SET group_concat_max_len = 18446744073709547520" ) ; $ primaryKeyArray = MysqliLib :: fetchPrimaryKey ( $ mysqliConn , $ tableName ) ; $ primaryKeyString = MysqliLib :: convertPrimaryKeyArrayToString ( $ primaryKeyArray ) ; $ orderByString = $ primaryKeyString ; $ query = "SELECT MD5(GROUP_CONCAT(MD5(CONCAT_WS('#'," . implode ( ',' , $ wrappedColumnList ) . ")))) " . "AS `hash` " . "FROM `{$tableName}` ORDER BY {$orderByString}" ; $ result = $ mysqliConn -> query ( $ query ) ; if ( $ result !== FALSE ) { $ row = $ result -> fetch_assoc ( ) ; if ( $ row [ 'hash' ] === NULL ) { $ tablehash = "" ; } else { $ tableHash = $ row [ 'hash' ] ; } } else { throw new \ Exception ( "Failed to fetch table hash" ) ; } return $ tableHash ; } | Generates a hash for the entire table so we can quickly compare tables to see if they are the same . The hash will be an empty string if the table has no data . |
19,097 | public static function fetchPrimaryKey ( \ mysqli $ mysqliConn , string $ tableName ) : array { $ primaryKeyArray = array ( ) ; $ query = "show index FROM `" . $ tableName . "`" ; $ result = $ mysqliConn -> query ( $ query ) ; if ( $ result === FALSE ) { throw new \ Exception ( "Failed to fetch primary key" , 500 ) ; } while ( ( $ row = $ result -> fetch_assoc ( ) ) != null ) { if ( $ row [ "Key_name" ] === "PRIMARY" ) { $ primaryKeyArray [ ] = $ row [ "Column_name" ] ; } } if ( count ( $ primaryKeyArray ) == 0 ) { throw new \ Exception ( $ tableName . " does not have a primary key." ) ; } return $ primaryKeyArray ; } | Dynamically discovers the primary key for this table and sets this objects member variable accordingly . This returns an array |
19,098 | private static function createConnection ( ) { $ driver = Configuration :: get ( 'database_driver' ) ; $ dsn = "" ; $ options = Configuration :: get ( 'database-options' ) ; $ options = ! is_array ( $ options ) ? array ( ) : $ options ; $ user = null ; $ password = null ; if ( $ driver === 'pdo_sqlite' ) { $ path = Configuration :: get ( 'database_path' ) ; if ( ! $ path || ! file_exists ( $ path ) ) { throw new \ Exception ( "SQLite Database File doesn't exists or not configured! '" . $ path . "'" ) ; } $ dsn = "sqlite:" . $ path ; } else if ( $ driver === 'pdo_mysql' ) { $ host = Configuration :: get ( 'database_host' ) ; $ database = Configuration :: get ( 'database_db' ) ; $ user = Configuration :: get ( 'database_user' ) ; $ password = Configuration :: get ( 'database_password' ) ; $ port = Configuration :: get ( 'database_port' ) ; $ port = ! is_int ( $ port ) ? 3306 : $ port ; $ encoding = Configuration :: get ( 'database_encoding' ) ; $ encoding = $ encoding == null ? 'utf8' : $ encoding ; if ( is_null ( $ host ) || is_null ( $ database ) || is_null ( $ user ) || is_null ( $ password ) ) { throw new \ Exception ( "Please configure the ORM first. We can't get a connection now!" ) ; } $ dsn = "mysql:host=" . $ host . ";port=" . $ port . ";dbname=" . $ database . ";charset=" . $ encoding ; } else { throw new \ Exception ( "Please configure the ORM first. We can't get a connection now! No driver given!" ) ; } self :: $ connection = new \ PDO ( $ dsn , $ user , $ password , $ options ) ; } | Create PDO connection with current Configuration |
19,099 | public function get ( ) { $ processors = [ ] ; $ result = $ this -> connection -> newQuery ( ) -> from ( Classes :: WIN32_PROCESSOR ) -> get ( ) ; foreach ( $ result as $ processor ) { $ processors [ ] = new Processor ( $ processor ) ; } return $ processors ; } | Returns all processors on the computer . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.