idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
2,800 | private function & convert ( $ nodeName , $ arr = [ ] ) { $ xml = $ this -> xml ; $ node = $ xml -> createElement ( $ nodeName ) ; if ( is_array ( $ arr ) ) { if ( isset ( $ arr [ '@attributes' ] ) ) { $ this -> extractAttributes ( $ node , $ arr , $ nodeName ) ; unset ( $ arr [ '@attributes' ] ) ; } if ( isset ( $ arr [ '@value' ] ) ) { $ node -> appendChild ( $ xml -> createTextNode ( $ this -> boolToString ( $ arr [ '@value' ] ) ) ) ; unset ( $ arr [ '@value' ] ) ; return $ node ; } elseif ( isset ( $ arr [ '@cdata' ] ) ) { $ node -> appendChild ( $ xml -> createCDATASection ( $ this -> boolToString ( $ arr [ '@cdata' ] ) ) ) ; unset ( $ arr [ '@cdata' ] ) ; return $ node ; } foreach ( $ arr as $ key => $ value ) { if ( ! $ this -> isValidTagName ( $ key ) ) { throw new \ Exception ( __CLASS__ . ' Illegal character in tag name. tag: ' . $ key . ' in node: ' . $ nodeName ) ; } if ( is_array ( $ value ) && is_numeric ( key ( $ value ) ) ) { foreach ( $ value as $ k => $ v ) { $ node -> appendChild ( $ this -> convert ( $ key , $ v ) ) ; } } else { $ node -> appendChild ( $ this -> convert ( $ key , $ value ) ) ; } unset ( $ arr [ $ key ] ) ; } } else { $ node -> appendChild ( $ xml -> createTextNode ( $ this -> boolToString ( $ arr ) ) ) ; } return $ node ; } | This method converts an array into XML recursively . |
2,801 | public static function process ( $ ficlist , $ sourcepath , $ distpath , $ preprocvars , $ preprocmanifest = false ) { $ manifest = new Reader ( $ ficlist , $ sourcepath , $ distpath ) ; $ manifest -> setVerbose ( self :: $ verbose ) ; $ manifest -> setStripComment ( self :: $ stripComment ) ; $ manifest -> setTargetCharset ( self :: $ targetPropertiesFilesCharset ) ; $ manifest -> setSourceCharset ( self :: $ sourcePropertiesFilesDefaultCharset ) ; $ manifest -> setIndentation ( self :: $ indentation ) ; $ manifest -> process ( $ preprocvars , $ preprocmanifest ) ; } | read the given manifest file and copy files . |
2,802 | public static function removeFiles ( $ ficlist , $ distpath ) { $ distdir = Fs \ DirUtils :: normalizeDir ( $ distpath ) ; $ fs = self :: getFileSystem ( $ distdir ) ; $ script = file ( $ ficlist ) ; $ currentdestdir = '' ; foreach ( $ script as $ nbline => $ line ) { ++ $ nbline ; if ( preg_match ( ';^(cd|rmd)?\s+([a-zA-Z0-9\/.\-_]+)\s*$;m' , $ line , $ m ) ) { if ( $ m [ 1 ] == 'rmd' ) { $ fs -> removeDir ( Fs \ DirUtils :: normalizeDir ( $ m [ 2 ] ) ) ; } elseif ( $ m [ 1 ] == 'cd' ) { $ currentdestdir = Fs \ DirUtils :: normalizeDir ( $ m [ 2 ] ) ; } else { if ( $ m [ 2 ] == '' ) { throw new \ Exception ( "$ficlist : file required on line $nbline \n" ) ; } $ destfile = $ currentdestdir . $ m [ 2 ] ; if ( ! file_exists ( $ distdir . $ destfile ) ) { if ( self :: $ verbose ) { echo "cannot remove $destfile. It doesn't exist anymore.\n" ; } continue ; } if ( self :: $ verbose ) { echo 'remove ' . $ destfile . "\n" ; } if ( ! $ fs -> removeFile ( $ destfile ) ) { throw new \ Exception ( " $ficlist: cannot remove file " . $ m [ 2 ] . ", line $nbline \n" ) ; } } } elseif ( preg_match ( "!^\s*(\#.*)?$!" , $ line ) ) { } else { throw new \ Exception ( "$ficlist : syntax error on line $nbline \n" ) ; } } } | delete files indicated in the given manifest file from the indicated target directory . |
2,803 | protected function bootBindings ( ) { $ this -> app [ CommandBus :: class ] = function ( $ app ) { return $ app [ 'tactician.commandbus' ] ; } ; $ this -> app [ CommandHandlerMiddleware :: class ] = function ( $ app ) { return $ app [ 'tactician.handler' ] ; } ; $ this -> app [ CommandNameExtractor :: class ] = function ( $ app ) { return $ app [ 'tactician.extractor' ] ; } ; $ this -> app [ MethodNameInflector :: class ] = function ( $ app ) { return $ app [ 'tactician.inflector' ] ; } ; $ this -> app [ HandlerLocator :: class ] = function ( $ app ) { return $ app [ 'tactician.locator' ] ; } ; $ this -> app [ DispatcherContract :: class ] = function ( $ app ) { return $ app [ 'tactician.dispatcher' ] ; } ; } | Bind some interfaces and implementations . |
2,804 | protected function registerLocator ( ) { $ this -> app -> singleton ( 'tactician.locator' , function ( $ app ) { $ commandNamespace = $ this -> config ( 'command_namespace' ) ; $ handlerNamespace = $ this -> config ( 'handler_namespace' ) ; $ locator = $ this -> config ( 'locator' ) ; return ( new $ locator ( $ this -> app , $ commandNamespace , $ handlerNamespace ) ) ; } ) ; } | Register bindings for the Handler Locator . |
2,805 | protected function registerMiddleware ( ) { $ this -> app -> bind ( 'tactician.middleware' , function ( ) { $ middleware = $ this -> config ( 'middleware' ) ; $ resolved = array_map ( function ( $ name ) { if ( is_string ( $ name ) ) { return $ this -> app -> make ( $ name ) ; } return $ name ; } , $ middleware ) ; $ resolved [ ] = $ this -> app [ 'tactician.handler' ] ; return $ resolved ; } ) ; } | Register bindings for all the middleware . |
2,806 | public static function checkRequestVars ( ) { if ( version_compare ( PHP_VERSION , '6.0.0' , '<' ) ) { if ( ini_get ( 'register_globals' ) ) { Debug :: _warn ( '<a target="_blank" href="http://www.php.net/manual/en/security.globals.php">register_globals</a> is on, strongly recommended to turn off' ) ; foreach ( array_keys ( $ _REQUEST ) as $ k ) { if ( isset ( $ GLOBALS [ $ k ] ) && $ GLOBALS [ $ k ] === $ _REQUEST [ $ k ] ) { unset ( $ GLOBALS [ $ k ] ) ; } } } if ( get_magic_quotes_gpc ( ) || ini_get ( 'magic_quotes_sybase' ) && strtolower ( ini_get ( 'magic_quotes_sybase' ) ) != 'off' ) { Debug :: _warn ( '<a target="_blank" href="http://www.php.net/manual/en/security.magicquotes.php">magic_quotes</a> is on, strongly recommended to turn off' ) ; $ _GET = ArrayUtil :: mapDeep ( 'stripslashes' , $ _GET ) ; $ _POST = ArrayUtil :: mapDeep ( 'stripslashes' , $ _POST ) ; $ _COOKIE = ArrayUtil :: mapDeep ( 'stripslashes' , $ _COOKIE ) ; } } if ( self :: $ cfgStatic [ 'keepQueryDot' ] ) { $ _GET = Str :: parse ( $ _SERVER [ 'QUERY_STRING' ] ) ; } if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'POST' && strpos ( $ _SERVER [ 'CONTENT_TYPE' ] , 'application/json' ) === 0 ) { Debug :: getInstance ( ) -> info ( 'JSON POST data' ) ; $ postdata = file_get_contents ( 'php://input' ) ; $ _POST = json_decode ( $ postdata , true ) ; $ _REQUEST = array_merge ( $ _REQUEST , $ _POST ) ; } } | Prep request parameters |
2,807 | public static function checkSettings ( ) { if ( version_compare ( PHP_VERSION , '6.0.0' , '<' ) && ini_get ( 'safe_mode' ) ) { Debug :: _warn ( '<a target="_blank" href="http://www.php.net/manual/en/features.safe-mode.php">safe_mode</a> is on' . ( ini_get ( 'safe_mode_gid' ) ? ' / safe_mode_gid = ' . ini_get ( 'safe_mode_gid' ) : '' ) ) ; } if ( ini_get ( 'default_charset' ) == '' ) { Debug :: _info ( 'default_charset not set… setting to UTF-8' ) ; ini_set ( 'default_charset' , 'UTF-8' ) ; } if ( ! extension_loaded ( 'mbstring' ) ) { Debug :: _warn ( 'mbstring extension not loaded' ) ; } elseif ( ini_get ( 'mb_string.internal_encoding' ) == '' ) { Debug :: _info ( 'mb_string.internal_encoding not set…' ) ; $ defaultCharset = ini_get ( 'default_charset' ) ; Debug :: _info ( ' setting to default_charset: ' . $ defaultCharset ) ; mb_internal_encoding ( $ defaultCharset ) ; mb_regex_encoding ( $ defaultCharset ) ; } } | Check PHP settings |
2,808 | public static function getCallerInfo ( $ retInfo = true , $ offset = 0 ) { $ offset ++ ; $ info = \ bdk \ Debug \ Utilities :: getCallerInfo ( $ offset ) ; if ( $ retInfo ) { return $ info ; } return ( $ info [ 'class' ] ? $ info [ 'class' ] . '::' : '' ) . $ info [ 'function' ] ; } | Returns the calling function |
2,809 | public static function getMemoryLimit ( ) { $ iniVal = ini_get ( 'memory_limit' ) ; $ val = $ iniVal !== '' ? $ iniVal : ( version_compare ( PHP_VERSION , '5.2.0' , '>' ) ? '128M' : ( version_compare ( PHP_VERSION , '5.2.0' , '=' ) ? '16M' : '8M' ) ) ; return $ val ; } | Determine PHP s MemoryLimit |
2,810 | public function process ( ) { if ( $ this -> cache !== null ) { return $ this -> cache ; } else { return ( $ this -> cache = UriTemplate :: expand ( $ this -> template , $ this -> data ) ) ; } } | Processes the template |
2,811 | public static function create_database ( $ database , $ charset = null , $ if_not_exists = true , $ db = null ) { $ sql = 'CREATE DATABASE' ; $ sql .= $ if_not_exists ? ' IF NOT EXISTS ' : ' ' ; $ charset = static :: process_charset ( $ charset , true ) ; return \ DB :: query ( $ sql . \ DB :: quote_identifier ( $ database , $ db ? $ db : static :: $ connection ) . $ charset , \ DB :: UPDATE ) -> execute ( $ db ? $ db : static :: $ connection ) ; } | Creates a database . Will throw a Database_Exception if it cannot . |
2,812 | public static function drop_database ( $ database , $ db = null ) { return \ DB :: query ( 'DROP DATABASE ' . \ DB :: quote_identifier ( $ database , $ db ? $ db : static :: $ connection ) , \ DB :: DELETE ) -> execute ( $ db ? $ db : static :: $ connection ) ; } | Drops a database . Will throw a Database_Exception if it cannot . |
2,813 | public static function rename_table ( $ table , $ new_table_name , $ db = null ) { return \ DB :: query ( 'RENAME TABLE ' . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , $ db ? $ db : static :: $ connection ) , $ db ? $ db : static :: $ connection ) . ' TO ' . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ new_table_name , $ db ? $ db : static :: $ connection ) ) , \ DB :: UPDATE ) -> execute ( $ db ? $ db : static :: $ connection ) ; } | Renames a table . Will throw a Database_Exception if it cannot . |
2,814 | public static function drop_index ( $ table , $ index_name , $ db = null ) { if ( strtoupper ( $ index_name ) == 'PRIMARY' ) { $ sql = 'ALTER TABLE ' . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , $ db ? $ db : static :: $ connection ) , $ db ? $ db : static :: $ connection ) ; $ sql .= ' DROP PRIMARY KEY' ; } else { $ sql = 'DROP INDEX ' . \ DB :: quote_identifier ( $ index_name , $ db ? $ db : static :: $ connection ) ; $ sql .= ' ON ' . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , $ db ? $ db : static :: $ connection ) , $ db ? $ db : static :: $ connection ) ; } return \ DB :: query ( $ sql , \ DB :: UPDATE ) -> execute ( $ db ? $ db : static :: $ connection ) ; } | Drop an index from a table . |
2,815 | protected static function process_charset ( $ charset = null , $ is_default = false , $ db = null , $ collation = null ) { $ charset or $ charset = \ Config :: get ( 'db.' . ( $ db ? $ db : \ Config :: get ( 'db.active' ) ) . '.charset' , null ) ; if ( empty ( $ charset ) ) { return '' ; } $ collation or $ collation = \ Config :: get ( 'db.' . ( $ db ? $ db : \ Config :: get ( 'db.active' ) ) . '.collation' , null ) ; if ( empty ( $ collation ) and ( $ pos = stripos ( $ charset , '_' ) ) !== false ) { $ collation = $ charset ; $ charset = substr ( $ charset , 0 , $ pos ) ; } $ charset = 'CHARACTER SET ' . $ charset ; if ( $ is_default ) { $ charset = 'DEFAULT ' . $ charset ; } if ( ! empty ( $ collation ) ) { if ( $ is_default ) { $ charset .= ' DEFAULT' ; } $ charset .= ' COLLATE ' . $ collation ; } return $ charset ; } | Formats the default charset . |
2,816 | public static function add_foreign_key ( $ table , $ foreign_key ) { if ( ! is_array ( $ foreign_key ) ) { throw new InvalidArgumentException ( 'Foreign key for add_foreign_key() must be specified as an array' ) ; } $ sql = 'ALTER TABLE ' ; $ sql .= \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , static :: $ connection ) ) . ' ' ; $ sql .= 'ADD ' ; $ sql .= ltrim ( static :: process_foreign_keys ( array ( $ foreign_key ) ) , ',' ) ; return \ DB :: query ( $ sql , \ DB :: UPDATE ) -> execute ( ) ; } | Adds a single foreign key to a table |
2,817 | public static function drop_foreign_key ( $ table , $ fk_name ) { $ sql = 'ALTER TABLE ' ; $ sql .= \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , static :: $ connection ) ) . ' ' ; $ sql .= 'DROP FOREIGN KEY ' . \ DB :: quote_identifier ( $ fk_name ) ; return \ DB :: query ( $ sql , \ DB :: UPDATE ) -> execute ( ) ; } | Drops a foreign key from a table |
2,818 | public static function process_foreign_keys ( $ foreign_keys , $ db = null ) { if ( ! is_array ( $ foreign_keys ) ) { throw new \ Database_Exception ( 'Foreign keys on create_table() must be specified as an array' ) ; } $ fk_list = array ( ) ; foreach ( $ foreign_keys as $ definition ) { if ( empty ( $ definition [ 'key' ] ) ) { throw new \ Database_Exception ( 'Foreign keys on create_table() must specify a foreign key name' ) ; } if ( empty ( $ definition [ 'reference' ] ) ) { throw new \ Database_Exception ( 'Foreign keys on create_table() must specify a foreign key reference' ) ; } if ( empty ( $ definition [ 'reference' ] [ 'table' ] ) or empty ( $ definition [ 'reference' ] [ 'column' ] ) ) { throw new \ Database_Exception ( 'Foreign keys on create_table() must specify a reference table and column name' ) ; } $ sql = '' ; ! empty ( $ definition [ 'constraint' ] ) and $ sql .= " CONSTRAINT " . \ DB :: quote_identifier ( $ definition [ 'constraint' ] ) ; $ sql .= " FOREIGN KEY (" . \ DB :: quote_identifier ( $ definition [ 'key' ] ) . ')' ; $ sql .= " REFERENCES " . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ definition [ 'reference' ] [ 'table' ] , static :: $ connection ) ) . ' (' ; if ( is_array ( $ definition [ 'reference' ] [ 'column' ] ) ) { $ sql .= implode ( ', ' , \ DB :: quote_identifier ( $ definition [ 'reference' ] [ 'column' ] ) ) ; } else { $ sql .= \ DB :: quote_identifier ( $ definition [ 'reference' ] [ 'column' ] ) ; } $ sql .= ')' ; ! empty ( $ definition [ 'on_update' ] ) and $ sql .= " ON UPDATE " . $ definition [ 'on_update' ] ; ! empty ( $ definition [ 'on_delete' ] ) and $ sql .= " ON DELETE " . $ definition [ 'on_delete' ] ; $ fk_list [ ] = "\n\t" . ltrim ( $ sql ) ; } return ', ' . implode ( ',' , $ fk_list ) ; } | Returns string of foreign keys |
2,819 | public static function truncate_table ( $ table , $ db = null ) { return \ DB :: query ( 'TRUNCATE TABLE ' . \ DB :: quote_identifier ( \ DB :: table_prefix ( $ table , $ db ? $ db : static :: $ connection ) , $ db ? $ db : static :: $ connection ) , \ DB :: DELETE ) -> execute ( $ db ? $ db : static :: $ connection ) ; } | Truncates a table . |
2,820 | public static function table_exists ( $ table , $ db = null ) { try { \ DB :: select ( ) -> from ( $ table ) -> limit ( 1 ) -> execute ( $ db ? $ db : static :: $ connection ) ; return true ; } catch ( \ Database_Exception $ e ) { $ connection = \ Database_Connection :: instance ( $ db ? $ db : static :: $ connection ) -> has_connection ( ) ; if ( ! $ connection ) { throw $ e ; } return false ; } } | Checks if a given table exists . |
2,821 | public function getRequest ( $ master = true ) { if ( ! $ master ) { return ServerRequestFactory :: make ( ) ; } if ( ! $ this -> request ) { $ this -> request = ServerRequestFactory :: make ( ) ; } return $ this -> request ; } | Gets the request . |
2,822 | public function icons ( array $ icons = null ) { foreach ( $ this -> fixIconsArray ( ( $ icons ? : $ this -> icons ) ) as $ icon ) { $ this -> add ( $ icon ) ; } return $ this ; } | add icons based on cofig array |
2,823 | protected function fixIconsArray ( array $ icons ) { $ array = [ ] ; foreach ( $ icons as $ rel => $ data ) { foreach ( ( array ) $ data [ 'sizes' ] as $ size ) { $ array [ ] = array_merge_recursive ( [ 'rel' => $ rel , 'sizes' => "{$size}x{$size}" , 'href' => sprintf ( $ data [ 'pattern' ] , $ size ) , ] , ( isset ( $ data [ 'attr' ] ) ? $ data [ 'attr' ] : [ ] ) ) ; } } return $ array ; } | fix icons data into usable array |
2,824 | public function getGroup ( ) { if ( - 1 === $ this -> index || ! $ this -> valid ( ) ) { return null ; } return $ this -> processors [ $ this -> index ] [ 1 ] [ 'group' ] ?? null ; } | Gets the name of a group the iterator points to . |
2,825 | public function getProcessorId ( ) { if ( - 1 === $ this -> index || ! $ this -> valid ( ) ) { return null ; } return $ this -> processors [ $ this -> index ] [ 0 ] ; } | Gets the id of a processor the iterator points to . |
2,826 | public function getProcessorAttributes ( ) { if ( - 1 === $ this -> index || ! $ this -> valid ( ) ) { return null ; } return $ this -> processors [ $ this -> index ] [ 1 ] ; } | Gets all attributes of a processor the iterator points to . |
2,827 | protected function nextApplicable ( ) { $ this -> index ++ ; while ( $ this -> index <= $ this -> maxIndex ) { $ applicable = $ this -> applicableChecker -> isApplicable ( $ this -> context , $ this -> processors [ $ this -> index ] [ 1 ] ) ; if ( ApplicableCheckerInterface :: NOT_APPLICABLE !== $ applicable ) { break ; } $ this -> index ++ ; } } | Moves forward to next applicable processor |
2,828 | public function match ( string $ word ) { $ this -> processAbbreviations ( ) ; $ word = strtolower ( $ word ) ; if ( $ this -> abbreviations && isset ( $ this -> abbreviations [ $ word ] ) ) { return $ this -> abbreviations [ $ word ] ; } return false ; } | Return a single matching word if it exists . |
2,829 | public function suggest ( string $ word ) { $ this -> processAbbreviations ( ) ; $ word = strtolower ( $ word ) ; $ suggestions = [ ] ; if ( $ this -> abbreviations ) { $ len = mb_strlen ( $ word ) ; foreach ( $ this -> words as $ w ) { if ( substr ( $ w , 0 , $ len ) === $ word ) { $ suggestions [ ] = $ w ; } } } return $ suggestions ; } | Obtain a list of possible word matches . |
2,830 | private static function useMcryptBacking ( ) { if ( ! extension_loaded ( self :: BACKING_MCRYPT ) ) { throw new \ RuntimeException ( 'Can not use mcrypt backing, extension mcrypt not available' ) ; } $ engine = mcrypt_module_open ( MCRYPT_DES , '' , 'ecb' , '' ) ; $ engineiv = mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $ engine ) , MCRYPT_RAND ) ; $ key = substr ( md5 ( uniqid ( ) ) , 0 , mcrypt_enc_get_key_size ( $ engine ) ) ; mcrypt_generic_init ( $ engine , $ key , $ engineiv ) ; self :: $ encrypt = function ( $ value ) use ( $ engine ) { return mcrypt_generic ( $ engine , $ value ) ; } ; self :: $ decrypt = function ( $ value ) use ( $ engine ) { return rtrim ( mdecrypt_generic ( $ engine , $ value ) , "\0" ) ; } ; } | switches backing to mcrypt |
2,831 | private static function useOpenSslBacking ( ) { if ( ! extension_loaded ( self :: BACKING_OPENSSL ) ) { throw new \ RuntimeException ( 'Can not use openssl backing, extension openssl not available' ) ; } $ key = md5 ( uniqid ( ) ) ; $ iv = substr ( md5 ( uniqid ( ) ) , 0 , openssl_cipher_iv_length ( 'des' ) ) ; self :: $ encrypt = function ( $ value ) use ( $ key , $ iv ) { return openssl_encrypt ( $ value , 'DES' , $ key , 0 , $ iv ) ; } ; self :: $ decrypt = function ( $ value ) use ( $ key , $ iv ) { return openssl_decrypt ( $ value , 'DES' , $ key , 0 , $ iv ) ; } ; } | switches backing to openssl |
2,832 | private static function usePlaintextBacking ( ) { self :: $ encrypt = function ( $ value ) { return base64_encode ( $ value ) ; } ; self :: $ decrypt = function ( $ value ) { return base64_decode ( $ value ) ; } ; } | switches backing to base64 encoding |
2,833 | public static function create ( $ string ) : self { if ( $ string instanceof self ) { return $ string ; } if ( empty ( $ string ) ) { throw new \ InvalidArgumentException ( 'Given string was null or empty, if you explicitly want to' . ' create a Secret with value null use' . ' Secret::forNull()' ) ; } $ self = new static ( ) ; try { $ encrypt = self :: $ encrypt ; self :: $ store [ $ self -> id ] = [ 'payload' => $ encrypt ( $ string ) , 'length' => \ iconv_strlen ( $ string ) ] ; } catch ( \ Throwable $ t ) { $ t = null ; unset ( self :: $ store [ $ self -> id ] ) ; } $ string = str_repeat ( '*' , strlen ( $ string ) ) ; $ string = null ; return $ self ; } | creates an instance for given characters |
2,834 | public function unveil ( ) { if ( ! $ this -> isContained ( ) ) { throw new \ LogicException ( 'An error occurred during string encryption.' ) ; } if ( $ this -> isNull ( ) ) { return null ; } $ decrypt = self :: $ decrypt ; return $ decrypt ( self :: $ store [ $ this -> id ] [ 'payload' ] ) ; } | retrieve secured characters |
2,835 | public function substring ( int $ start , int $ length = null ) : self { if ( $ this -> isNull ( ) ) { return $ this ; } $ substring = null === $ length ? substr ( $ this -> unveil ( ) , $ start ) : substr ( $ this -> unveil ( ) , $ start , $ length ) ; if ( false === $ substring ) { throw new \ InvalidArgumentException ( 'Given start offset is out of range' ) ; } return self :: create ( $ substring ) ; } | returns a substring of the secured string as a new Secret instance |
2,836 | public function setThrowable ( \ Throwable $ throwable ) : Event { if ( $ this -> getName ( ) !== definitions \ Events :: DEBUG_THROWABLE_AFTER ) { $ this -> throwable = $ throwable ; } return $ this ; } | Sets the Throwable to be handled . |
2,837 | public static function process ( $ file = NULL ) { $ exists = isset ( self :: $ data [ self :: $ level ] ) ; if ( $ exists ) { $ variables = self :: $ data [ self :: $ level ] ; foreach ( $ variables as $ key => $ value ) { global $ $ key ; $ $ key = $ value ; } } if ( $ file ) { require $ file ; } } | Define global variables from view level data Also require view file if need |
2,838 | protected function replaceDynamicExpression ( $ matches ) { $ program = new DynamicSQLProgram ( $ matches [ 2 ] ) ; $ value = $ program -> executeWith ( $ this -> buildEnvironment ( $ this -> config ) , $ this -> args ) ; if ( ! empty ( $ matches [ 1 ] ) ) return $ this -> castParameter ( $ value , $ matches [ 1 ] ) ; return $ this -> toString ( $ value ) ; } | Replaces a dynamic sql expression |
2,839 | public static function getCarrierShortName ( $ className ) { if ( 0 === strpos ( $ className , '\\' ) ) { $ className = substr ( $ className , 1 ) ; } if ( 0 === strpos ( $ className , 'Omniship\\' ) ) { return trim ( str_replace ( '\\' , '_' , substr ( $ className , 8 , - 7 ) ) , '_' ) ; } return '\\' . $ className ; } | Resolve a carrier class to a short name . |
2,840 | public static function getCarrierClassName ( $ shortName ) { if ( 0 === strpos ( $ shortName , '\\' ) ) { return $ shortName ; } $ shortName = str_replace ( '_' , '\\' , $ shortName ) ; if ( false === strpos ( $ shortName , '\\' ) ) { $ shortName .= '\\' ; } return '\\Omniship\\' . $ shortName . 'Carrier' ; } | Resolve a short carrier name to a full namespaced carrier class . |
2,841 | public function authenticate ( ClientInterface $ client ) { $ account = Account :: find ( ) -> byClient ( $ client ) -> one ( ) ; if ( ! $ this -> module -> enableRegistration && ( $ account === null || $ account -> user === null ) ) { Yii :: $ app -> session -> setFlash ( 'danger' , Yii :: t ( 'users' , 'Registration on this website is disabled' ) ) ; $ this -> action -> successUrl = Url :: to ( [ '/users/security/login' ] ) ; return ; } if ( $ account === null ) { $ accountObj = Yii :: createObject ( Account :: className ( ) ) ; $ account = $ accountObj :: create ( $ client ) ; } $ event = $ this -> getAuthEvent ( $ account , $ client ) ; $ this -> trigger ( self :: EVENT_BEFORE_AUTHENTICATE , $ event ) ; if ( $ account -> user instanceof User ) { if ( $ account -> user -> isBlocked ) { Yii :: $ app -> session -> setFlash ( 'danger' , Yii :: t ( 'users' , 'Your account has been blocked.' ) ) ; $ this -> action -> successUrl = Url :: to ( [ '/users/security/login' ] ) ; } else { Yii :: $ app -> user -> login ( $ account -> user , $ this -> module -> rememberFor ) ; $ this -> action -> successUrl = Yii :: $ app -> getUser ( ) -> getReturnUrl ( ) ; } } else { $ this -> action -> successUrl = $ account -> getConnectUrl ( ) ; } $ this -> trigger ( self :: EVENT_AFTER_AUTHENTICATE , $ event ) ; } | Tries to authenticate user via social network . If user has already used this network s account he will be logged in . Otherwise it will try to create new user account . |
2,842 | private function build_query ( ) { if ( ! empty ( $ this -> _query ) ) { return $ this -> _query ; } $ query = array ( ) ; foreach ( $ this -> _query_terms as $ k => $ v ) { $ query [ ] = "$k:$v" ; } return implode ( ' AND ' , $ query ) ; } | Builds a SOLR query . |
2,843 | public function get_results ( ) { $ query = $ this -> build_query ( ) ; $ query = $ this -> _solrclient -> createSelect ( $ query ) ; if ( isset ( $ this -> _query_modifiers [ 'limit' ] ) ) { $ query -> setRows ( $ this -> _query_modifiers [ 'limit' ] ) ; } if ( isset ( $ this -> _query_modifiers [ 'offset' ] ) ) { $ query -> setStart ( $ this -> _query_modifiers [ 'offset' ] ) ; } if ( isset ( $ this -> _query_modifiers [ 'fields' ] ) ) { $ query -> setFields ( $ this -> _query_modifiers [ 'fields' ] ) ; } if ( isset ( $ this -> _query_modifiers [ 'sort' ] ) ) { foreach ( $ this -> _query_modifiers [ 'sort' ] as $ k => $ dir ) { $ dir = $ dir == 'ASC' ? $ query :: SORT_ASC : $ query :: SORT_DESC ; $ query -> addSort ( $ k , $ dir ) ; } } $ results = array ( ) ; $ resultsset = $ this -> _solrclient -> select ( $ query ) ; foreach ( $ resultset as $ document ) { $ class = $ document -> collection = 'cartoons' ? 'CartoonsResult' : 'CollectionsResult' ; $ results [ ] = new $ class ( $ document ) ; } return $ results ; } | Return the results . |
2,844 | private function searchCompletion ( $ partial , $ filter , & $ ofs , & $ matches , & $ numMatches ) { $ ret = $ partial ; $ i = strlen ( $ ret ) ; $ numMatches = 0 ; $ matches = array ( ) ; $ ofs = 0 ; $ autocomplete = $ filter -> getResultFor ( $ ret ) ; foreach ( $ autocomplete as $ value ) { if ( 0 === strpos ( $ value , $ ret ) && $ i !== strlen ( $ value ) ) { $ matches [ $ numMatches ++ ] = $ value ; } } } | Find all valid completion |
2,845 | private function substituteFilter ( $ matches ) { if ( isset ( $ matches [ 1 ] ) && isset ( $ this -> filters [ $ matches [ 1 ] ] ) ) { return $ this -> filters [ $ matches [ 1 ] ] ; } return "([/][\w-\._@%]*)" ; } | Filters for regexp |
2,846 | protected function initializeBundles ( ) { parent :: initializeBundles ( ) ; foreach ( $ this -> registerBundles ( ) as $ bundle ) { if ( \ method_exists ( $ bundle , "extendBundle" ) ) { $ name = $ bundle -> getName ( ) ; $ extenBundle = $ bundle -> extendBundle ( ) ; $ this -> bundleMap [ $ name ] [ ] = $ this -> bundles [ $ extenBundle ] ; } } } | Initializes the data structures related to the bundle management . |
2,847 | private function determineUrl ( ) { $ sUrl = '' ; $ sRequestUri = $ this -> _oConfig -> get ( 'request_uri' ) ; $ sUrl = trim ( $ sRequestUri , '/' ) ; $ sUrl = preg_replace ( '/\?.*/' , '' , $ sUrl ) ; $ sUrl = preg_replace ( '#index$#i' , '' , $ sUrl ) ; if ( empty ( $ sUrl ) ) { return 'index' ; } return $ sUrl ; } | Set up routing |
2,848 | public function validate ( $ subject ) : bool { if ( \ is_array ( $ this -> schema [ 'required' ] ) ) { foreach ( $ this -> schema [ 'required' ] as $ propertyName ) { if ( ! \ array_key_exists ( $ propertyName , $ subject ) ) { return false ; } } } return true ; } | Validates subject against required |
2,849 | private function createDeleteForm ( Category $ category ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'ecommerce_category_delete' , array ( 'id' => $ category -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; } | Creates a form to delete a Category entity . |
2,850 | private function setLink ( $ type , $ title , $ href ) { $ this -> links [ $ type ] = [ 'rel' => $ type , 'title' => $ title , 'href' => $ href ] ; } | Internal method to add links |
2,851 | public function dispatch ( ServerRequestInterface $ request ) : array { $ uri = $ request -> getUri ( ) -> getPath ( ) ; if ( ! $ uri || $ uri [ 0 ] !== '/' ) { $ uri = '/' . $ uri ; } return $ this -> createDispatcher ( ) -> dispatch ( $ request -> getMethod ( ) , $ uri ) ; } | Dispatch router for HTTP request |
2,852 | public function removeRouteByName ( string $ name ) : bool { if ( $ route = $ this -> getRouteByName ( $ name ) ) { unset ( $ this -> routes [ $ route -> getIdentifier ( ) ] ) ; return true ; } return false ; } | Remove named route |
2,853 | public function getRouteByIdentifier ( int $ identifier ) { return isset ( $ this -> routes [ $ identifier ] ) ? $ this -> routes [ $ identifier ] : null ; } | Get Route By Identifier |
2,854 | public function addSubdirectories ( array $ directories ) { foreach ( $ directories as $ dir ) { $ this -> subdirs [ $ dir ] = $ dir ; } return $ this ; } | Add additional subdirectories within the module directory that should be searched for Module . php |
2,855 | public function setOptions ( $ options ) { if ( ! is_array ( $ options ) && ! ( $ options instanceof \ Traversable ) ) { return $ this ; } foreach ( $ options as $ name => $ option ) { switch ( strtolower ( strtr ( $ name , '-' , '' ) ) ) { case 'pathmanager' : $ this -> setPathManager ( $ option ) ; break ; case 'subdirectories' : if ( is_array ( $ option ) ) { $ this -> addSubdirectories ( $ option ) ; } break ; } } return $ this ; } | Following options are allowed |
2,856 | public static function init ( ) { self :: $ app = Kecik :: getInstance ( ) ; ; self :: $ modelUser = '\\Model\\' . self :: $ app -> config -> get ( 'auth.model' ) ; self :: $ postUsername = self :: $ app -> config -> get ( 'auth.post_username' ) ; self :: $ postPassword = self :: $ app -> config -> get ( 'auth.post_password' ) ; self :: $ fieldUsername = self :: $ app -> config -> get ( 'auth.field_username' ) ; self :: $ fieldPassword = self :: $ app -> config -> get ( 'auth.field_password' ) ; self :: $ fieldLevel = self :: $ app -> config -> get ( 'auth.field_level' ) ; self :: $ loginRoute = ( self :: $ app -> config -> get ( 'auth.login_route' ) != '' ) ? self :: $ app -> config -> get ( 'auth.login_route' ) : self :: $ loginRoute ; self :: $ logoutRoute = ( self :: $ app -> config -> get ( 'auth.logout_route' ) != '' ) ? self :: $ app -> config -> get ( 'auth.logout_route' ) : self :: $ logoutRoute ; self :: $ loginTemplate = ( self :: $ app -> config -> get ( 'auth.login_template' ) != '' ) ? self :: $ app -> config -> get ( 'auth.login_template' ) : self :: $ loginTemplate ; self :: $ encryptFunction = ( self :: $ app -> config -> get ( 'auth.encrypt_function' ) != '' ) ? self :: $ app -> config -> get ( 'auth.encrypt_function' ) : self :: $ encryptFunction ; if ( ! empty ( self :: username ( ) ) ) { $ model = self :: $ modelUser ; $ users = $ model :: find ( [ 'where' => [ [ self :: $ fieldUsername , '=' , self :: username ( ) ] ] ] ) ; if ( count ( $ users ) > 0 ) { self :: $ info = $ users [ 0 ] ; } } AuthInit ( self :: $ app ) ; } | Initialize for Auth Class |
2,857 | public static function isLogin ( ) { if ( isset ( $ _SESSION [ md5 ( 'login' . self :: $ app -> url -> baseUrl ( ) ) ] ) && base64_decode ( $ _SESSION [ md5 ( 'login' . self :: $ app -> url -> baseUrl ( ) ) ] ) == 'TRUE' ) { return TRUE ; } else { return FALSE ; } } | Check of login status |
2,858 | public static function level ( ) { if ( isset ( $ _SESSION [ md5 ( 'level' . self :: $ app -> url -> baseUrl ( ) ) ] ) ) { return base64_decode ( $ _SESSION [ md5 ( 'level' . self :: $ app -> url -> baseUrl ( ) ) ] ) ; } else { return '' ; } } | Get current level from user logged |
2,859 | public function addTo ( Component $ parent ) { $ parent -> add ( $ this ) ; $ this -> parent = $ parent ; return $ this ; } | Adds component to given parent component |
2,860 | public function getChildren ( $ recursive = true , $ includeInactiveFields = false ) { $ children = array ( ) ; foreach ( $ this -> children as $ component ) if ( $ component -> isActive ( ) || $ includeInactiveFields ) { array_push ( $ children , $ component ) ; if ( $ recursive ) $ children = array_merge ( $ children , $ component -> getChildren ( true , $ includeInactiveFields ) ) ; } return $ children ; } | Returns a flat list of the component s enabled children |
2,861 | public function hasChild ( $ child , $ recursive = true ) { foreach ( $ this -> children as $ component ) if ( $ component == $ child || ( $ recursive && $ component -> hasChild ( $ child , true ) ) ) return true ; return false ; } | Check if given component is child |
2,862 | public function getAttributesString ( ) { $ attributePairs = array ( ) ; foreach ( $ this -> getAttributes ( ) as $ attr => $ value ) $ attributePairs [ ] = sprintf ( '%s="%s"' , $ attr , str_replace ( '"' , '"' , $ value ) ) ; return implode ( ' ' , $ attributePairs ) ; } | Gets all HTML attributes |
2,863 | public function getProperty ( PHPStanClassReflection $ reflection , string $ property ) : PHPStanPropertyReflection { $ native = $ reflection -> getNativeReflection ( ) ; if ( $ native -> hasMethod ( "getter_" . $ property ) ) return $ this -> getUnderscoreGetter ( $ reflection , $ property ) ; return null ; } | Retrieve the given property if it does indeed exist |
2,864 | public function returnFullDataIo ( ) { $ aDiskIo = $ this -> getSNMP ( ) -> realWalk1d ( self :: OID_DISK_IO ) ; $ aReturn = Array ( ) ; $ aReturn [ 'index' ] = $ aDiskIo [ self :: OID_DISK_IO_INDEX ] ; $ aReturn [ 'device' ] = $ aDiskIo [ self :: OID_DISK_IO_DEVICE ] ; $ aReturn [ 'disk_io_read' ] = $ aDiskIo [ self :: OID_DISK_IO_READ ] ; $ aReturn [ 'disk_io_write' ] = $ aDiskIo [ self :: OID_DISK_IO_WRITE ] ; $ aReturn [ 'disk_io_read_access' ] = $ aDiskIo [ self :: OID_DISK_IO_READ_ACCESS ] ; $ aReturn [ 'disk_io_write_access' ] = $ aDiskIo [ self :: OID_DISK_IO_WRITE_ACCESS ] ; $ aReturn [ 'disk_io_load1Min' ] = $ aDiskIo [ self :: OID_DISK_IO_LOAD1MIN ] ; $ aReturn [ 'disk_io_load5Min' ] = $ aDiskIo [ self :: OID_DISK_IO_LOAD5MIN ] ; $ aReturn [ 'disk_io_load15Min' ] = $ aDiskIo [ self :: OID_DISK_IO_LOAD15MIN ] ; $ aReturn [ 'counter_max_value' ] = 4294967295 ; return $ aReturn ; } | Returns Full Data Io |
2,865 | private function freePercentCalculation ( array $ usedPercent = array ( ) ) { $ aReturn = array ( ) ; foreach ( $ usedPercent as $ keyUsedPercent => $ valueUsedPercent ) { $ aReturn [ $ keyUsedPercent ] = ( $ valueUsedPercent > 0 ) ? ( 100 - $ valueUsedPercent ) : 100 ; } return $ aReturn ; } | Calculation Free Percent Disk Path |
2,866 | public function setData ( array $ data ) { foreach ( $ data as $ d ) { if ( ! $ this -> isValid ( $ d ) ) { throw new \ Exception ( 'Data Provided invalid structure.' ) ; } } if ( $ this -> getNoConflictMode ( ) ) { $ scriptItem = array ( 'mode' => 'script' , 'content' => ( $ this -> getNoConflictHandler ( ) ) ? 'var ' . $ this -> getNoConflictHandler ( ) . ' = ' . 'jQuery.noConflict();' : 'jQuery.noConflict();' , 'attributes' => array ( 'type' => 'text/javascript' , ) , ) ; array_unshift ( $ data , $ scriptItem ) ; } $ baseLibrary = $ this -> getBaseLibrary ( ) ; if ( $ baseLibrary ) { $ scriptItem = array ( 'mode' => 'file' , 'content' => null , 'attributes' => array ( 'src' => $ baseLibrary , 'type' => 'text/javascript' , ) , ) ; array_unshift ( $ data , $ scriptItem ) ; } return parent :: setData ( $ data ) ; } | Set data to decorate |
2,867 | public function toString ( ) { $ items = $ this -> data ; $ attachedBaseLib = false ; $ return = array ( 'file' => '' , 'script' => '' ) ; foreach ( $ items as $ item ) { if ( $ item [ 'mode' ] == 'file' && isset ( $ item [ 'attributes' ] [ 'src' ] ) ) { if ( $ item [ 'attributes' ] [ 'src' ] == $ this -> getBaseLibrary ( ) && ! $ attachedBaseLib ) { $ attachedBaseLib = true ; } elseif ( $ item [ 'attributes' ] [ 'src' ] == $ this -> getBaseLibrary ( ) ) { continue ; } } $ return [ $ item [ 'mode' ] ] .= PHP_EOL . $ this -> startElement ( ) . $ this -> writeAttributes ( $ item [ 'attributes' ] ) . $ this -> endElement ( ) . ( ( $ item [ 'mode' ] == 'script' ) ? $ this -> overrideScript ( $ item [ 'content' ] ) : '' ) . $ this -> startElement ( true ) . $ this -> endElement ( ) ; } $ return = $ return [ 'file' ] . PHP_EOL . $ return [ 'script' ] . PHP_EOL ; return $ return ; } | Render the placeholder as script codes |
2,868 | protected function overrideScript ( $ script ) { $ noConflict = $ this -> getNoConflictMode ( ) ; if ( ! $ noConflict ) { return $ script ; } $ jQ = ( $ this -> getNoConflictHandler ( ) ) ? $ this -> getNoConflictHandler ( ) : 'jQuery' ; preg_match_all ( '/\([\s\n]*function[\s\n]*\([\s\n]*\$[\s\n]*\)[\s\n]*{([\w|\D]*)}[\s\n]*\)[\s\n]*\([\s\n]*jQuery[\s\n]*\)/' , $ script , $ matches ) ; $ immScripts = array ( ) ; if ( isset ( $ matches [ 1 ] ) ) { foreach ( $ matches [ 1 ] as $ i => $ mtch ) { $ repVar = '$__var_' . $ i ; $ immScripts [ $ repVar ] = $ mtch ; $ script = str_replace ( $ mtch , $ repVar , $ script ) ; } } $ script = preg_replace_callback ( '/\$\s*[\.|\(]\s*(\"|\'|\w[\w\d]*)/' , function ( $ matches ) use ( $ jQ ) { return str_replace ( '$' , $ jQ , $ matches [ 0 ] ) ; } , $ script ) ; foreach ( $ immScripts as $ repVar => $ scr ) { $ script = str_replace ( $ repVar , $ scr , $ script ) ; } return $ script ; } | Correct scripts to noConflict mode |
2,869 | public function isValid ( $ value ) { if ( ! is_array ( $ value ) || ! isset ( $ value [ 'mode' ] ) || ( ! isset ( $ value [ 'content' ] ) && ! isset ( $ value [ 'attributes' ] ) ) ) { return false ; } return true ; } | Is the script provided valid? |
2,870 | public function add ( ResourceSerializerSupportableInterface $ supportable , ResourceSerializerInterface $ serializer ) : void { $ this -> map [ ] = [ $ supportable , $ serializer ] ; } | Add the resource normalizer to registry |
2,871 | public function has ( ) { if ( empty ( $ this -> _message ) ) throw new RuntimeException ( "A message has not been set" ) ; return ( bool ) preg_match ( $ this -> _regex , $ this -> _message ) ; } | Check if the message actually contains what we re trying to strip . |
2,872 | public function strip ( ) { if ( empty ( $ this -> _message ) ) throw new RuntimeException ( "A message has not been set" ) ; $ messageBody = $ this -> _message ; if ( preg_match_all ( $ this -> _regex , $ messageBody , $ matches ) ) { foreach ( $ matches [ 0 ] as $ k => $ header ) { $ startPos = strpos ( $ messageBody , $ header ) ; $ lookAhead = $ k + 1 ; $ afterPos = array_key_exists ( $ lookAhead , $ matches [ 0 ] ) ? strpos ( $ messageBody , $ matches [ 0 ] [ $ lookAhead ] ) : strlen ( $ messageBody ) ; $ messageBody = substr ( $ messageBody , 0 , $ startPos ) . " " . substr ( $ messageBody , $ afterPos ) ; } } return trim ( $ messageBody ) ; } | Remove unwanted section |
2,873 | private function cast ( $ value , $ type ) { switch ( $ type ) { case 'bool' : return ( bool ) $ value ; case 'float' : return ( float ) $ value ; case 'int' : return ( int ) $ value ; default : return $ value ; } } | Cast the value . |
2,874 | private function findOption ( $ key , $ short , $ argv ) { foreach ( $ argv as $ i => $ arg ) { if ( preg_match ( '/^-(-)?([\w-]+)(?:=(.*))?$/s' , $ arg , $ match ) ) { if ( ( ! empty ( $ match [ 1 ] ) && $ match [ 2 ] === $ key ) || ( empty ( $ match [ 1 ] ) && $ match [ 2 ] === $ short ) ) { $ value = isset ( $ match [ 3 ] ) ? $ match [ 3 ] : null ; return [ $ i , $ value ] ; } } } return false ; } | Find the option . |
2,875 | private function printParameters ( $ name , $ def , $ length ) { $ name .= str_repeat ( ' ' , 2 + $ length - strlen ( $ name ) ) ; $ this -> stdio -> write ( $ name , false , [ Stdio :: STYLE_GREEN ] ) ; $ this -> stdio -> write ( trim ( $ def [ 'description' ] ? : '' ) ) ; if ( array_key_exists ( 'default' , $ def ) ) { $ default = $ def [ 'default' ] ; if ( $ default === null ) { $ default = 'null' ; } else if ( $ def [ 'type' ] == 'string' ) { $ default = '"' . $ default . '"' ; } $ this -> stdio -> write ( ' [default: ' . $ default . ']' , true ) ; } else { $ this -> stdio -> write ( '' , true ) ; } } | Print arguments and options . |
2,876 | public static function to360Range ( $ value ) { if ( $ value > 360 ) { return $ value * 1.0 - floor ( $ value / 360 ) * 360 ; } elseif ( $ value < 0 ) { return $ value * 1.0 + ( floor ( - $ value / 360 ) + 1 ) * 360 ; } return $ value ; } | Returns angle converted to 0 - 360 range . |
2,877 | public function getNodeType ( ) { static $ nodeType ; return $ nodeType ?? $ nodeType = $ this -> nodeType ?? ( static function ( $ className ) { return strtolower ( preg_replace ( '/(?<=\\w)([A-Z])/' , '_$1' , preg_replace ( '/^(?:\\w+\\\\)*(\\w+)Node$/' , '$1' , $ className ) ) ) ; } ) ( get_class ( $ this ) ) ; } | Getting the type of this node . |
2,878 | protected function loadConfig ( string $ name , IConfigProvider $ configProvider ) { $ config = $ configProvider -> getConfig ( $ this -> nodeType . '_nodes' , $ name ) ? : $ configProvider -> getConfig ( $ this -> nodeType . '_nodes' , '*' ) ; if ( isset ( $ config [ 'multiple' ] ) ) { foreach ( $ config [ 'multiple' ] as $ value ) { if ( $ this -> line -> pregGet ( $ value [ 'pattern' ] ) ) { $ config = $ value ; break ; } } } if ( isset ( $ config [ 'in' ] ) ) { $ config = ( function ( array $ config ) use ( $ name ) { foreach ( $ config [ 'in' ] as $ key => $ value ) { if ( $ this -> document -> scope && $ this -> document -> scope -> scope === $ key ) { $ value [ 'in_scope' ] = $ key ; return $ value ; } } if ( ! isset ( $ config [ 'out' ] ) ) { $ this -> document -> throw ( "The $this->nodeType node $name only use in scope " . implode ( ',' , array_keys ( $ config [ 'in' ] ) ) ) ; } return $ config [ 'out' ] ; } ) ( $ config ) ; } elseif ( isset ( $ config [ 'only_in' ] ) && ( ! $ this -> document -> scope || ! in_array ( $ this -> document -> scope -> scope , $ config [ 'only_in' ] ) ) ) { $ this -> document -> throw ( "The $this->nodeType node $name only use in scope " . implode ( ',' , $ config [ 'only_in' ] ) ) ; } elseif ( isset ( $ config [ 'not_in' ] ) && ( ! $ this -> document -> scope || ! in_array ( $ this -> document -> scope -> scope , $ config [ 'not_in' ] ) ) ) { $ this -> document -> throw ( "The $this->nodeType node $name not use in scope " . implode ( ',' , $ config [ 'not_in' ] ) ) ; } if ( ! is_array ( $ config ) ) { $ this -> document -> throw ( "The $this->nodeType node $name is not supported." ) ; } $ this -> config = $ config ; return $ this ; } | Loading node configuration . |
2,879 | public function assemble ( $ params = [ ] ) { $ params = array_merge ( $ this -> defaults , $ params ) ; $ parts = $ this -> parts ; $ return = [ ] ; foreach ( $ parts as $ part ) { if ( 0 === strpos ( $ part , '~' ) && 1 !== strpos ( $ part , ':' ) ) { continue ; } if ( 0 === strpos ( $ part , ':' ) ) { if ( ! isset ( $ params [ ltrim ( $ part , ':' ) ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Missing value for the placeholder "%s".' , $ part ) ) ; } $ name = ltrim ( $ part , ':' ) ; if ( isset ( $ this -> constraints [ $ name ] ) && ! preg_match ( '#\A' . $ this -> constraints [ $ name ] . '\Z#' , $ params [ $ name ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The value "%s" of parameter "%s" must be constrain ' . 'with regex "%s".' , $ params [ $ name ] , $ name , $ this -> constraints [ $ name ] ) ) ; } $ return [ ] = Uri :: encode ( $ params [ $ name ] ) ; continue ; } if ( 1 === strpos ( $ part , ':' ) ) { $ name = ltrim ( $ part , '~:' ) ; if ( ! isset ( $ params [ $ name ] ) ) { continue ; } if ( isset ( $ this -> constraints [ $ name ] ) && ! preg_match ( '#\A' . $ this -> constraints [ $ name ] . '\Z#' , $ params [ $ name ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The value "%s" of parameter "%s" must be constrain ' . 'with regex "%s".' , $ params [ $ name ] , $ name , $ this -> constraints [ $ name ] ) ) ; } $ return [ ] = Uri :: encode ( $ params [ $ name ] ) ; continue ; } $ return [ ] = Uri :: encode ( ltrim ( $ part , '~' ) ) ; } return '/' . implode ( '/' , $ return ) ; } | Assemble the route . |
2,880 | protected function compile ( ) { $ this -> parts = $ parts = preg_split ( '#\/#' , $ this -> path , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ regex = '' ; foreach ( $ parts as & $ part ) { $ control = substr ( $ part , 0 , 2 ) ; if ( false !== strpos ( $ control , ':' ) ) { if ( ! preg_match ( '#\A(~)?(:){1}[a-zA-Z0-9]+\Z#' , $ part ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid placeholder name "%s" provided; must contain ' . 'only english alphanumeric characters.' , $ part ) ) ; } } elseif ( preg_match ( '/[\#\?]+/' , $ part ) ) { throw new InvalidArgumentException ( sprintf ( 'The segment "%s" of path "%s" contains illegal characters.' , $ part , $ this -> path ) ) ; } if ( '~:' === substr ( $ part , 0 , 2 ) ) { $ part = ltrim ( $ part , '~:' ) ; $ regex .= '\/?(?P<' . $ part . '>' ; if ( isset ( $ this -> constraints [ $ part ] ) ) { $ regex .= $ this -> constraints [ $ part ] . ')' ; } else { $ regex .= '[^\/]*)' ; } } elseif ( ':' === substr ( $ part , 0 , 1 ) ) { $ part = ltrim ( $ part , ':' ) ; $ regex .= '\/(?P<' . $ part . '>' ; if ( isset ( $ this -> constraints [ $ part ] ) ) { $ regex .= $ this -> constraints [ $ part ] . ')' ; } else { $ regex .= '[^\/]+)' ; } } elseif ( '~' === substr ( $ part , 0 , 1 ) ) { $ part = ltrim ( $ part , '~' ) ; $ regex .= '\/?(' . preg_quote ( Uri :: encode ( $ part ) ) . ')?' ; } else { $ part = $ part ; $ regex .= '\/' . preg_quote ( Uri :: encode ( $ part ) ) ; } } $ this -> compiled = '#\A' . $ regex . '\Z#' ; } | Compiles route . |
2,881 | public function serialize ( ) { return serialize ( [ $ this -> path , $ this -> schemes , $ this -> methods , $ this -> defaults , $ this -> constraints , $ this -> parts , $ this -> compiled , ] ) ; } | Serializes the route . |
2,882 | public function unserialize ( $ serialized ) { list ( $ this -> path , $ this -> schemes , $ this -> methods , $ this -> defaults , $ this -> constraints , $ this -> parts , $ this -> compiled ) = unserialize ( $ serialized ) ; } | Constructs route . |
2,883 | public function variablize ( $ word ) : string { $ word = $ this -> camelize ( $ word ) ; return \ strtolower ( $ word [ 0 ] ) . \ substr ( $ word , 1 ) ; } | Same as camelize but first char is in lowercase . Converts a word like send_email to sendEmail . It will remove non alphanumeric character from the word so who s online will be converted to whoSOnline |
2,884 | public function pluck ( $ columnName ) { if ( is_array ( $ columnName ) ) { $ columnNames = $ columnName ; } else { $ columnNames = func_get_args ( ) ; } $ select = clone $ this -> select ; $ select -> columns ( $ columnNames ) ; $ records = $ this -> loadRecords ( $ select ) ; if ( count ( $ columnNames ) == 1 ) { return array_map ( function ( $ x ) { return current ( $ x ) ; } , $ records ) ; } else { return $ records ; } } | Pass many string values or an array of strings . |
2,885 | public function count ( ) { $ select = clone $ this -> select ; $ select -> reset ( Select :: COLUMNS ) ; $ select -> columns ( [ 'c' => $ this -> raw ( 'COUNT(*)' ) ] ) ; $ rows = $ this -> loadRecords ( $ select ) ; if ( isset ( $ rows [ 0 ] [ 'c' ] ) ) { return ( int ) $ rows [ 0 ] [ 'c' ] ; } return false ; } | Issues a count query and returns the result . |
2,886 | public static function fail ( $ format , $ args = null , $ _ = null ) { throw new EnsureException ( vsprintf ( $ format , array_slice ( func_get_args ( ) , 1 ) ) ) ; } | Simply fails with the given message in sprintf format . May be used when the code has reached a point where it shouldn t be for example the default case of a switch . |
2,887 | private function _processTypeCondition ( $ pField , $ pType , $ pValue ) { $ escapedField = '`' . $ pField . '`' ; switch ( $ pType ) { case self :: IN : case self :: NOTIN : if ( is_array ( $ pValue ) ) { $ markers = '?' . str_repeat ( ', ?' , count ( $ pValue ) - 1 ) ; return sprintf ( $ pType , $ escapedField , $ markers ) ; } break ; case self :: INSET : return sprintf ( $ pType , '?' , $ escapedField ) ; break ; default : if ( $ pValue !== NULL ) { return sprintf ( $ pType , $ escapedField , '?' ) ; } else { return sprintf ( $ pType , $ escapedField ) ; } } } | Prepare the conditions for PDO . |
2,888 | private function _processTypeValue ( $ pType , $ pValue , & $ pPrepared ) { if ( is_array ( $ pValue ) ) { foreach ( $ pValue as $ subValue ) { $ pPrepared [ ] = ( string ) $ subValue ; } } else if ( $ pValue !== NULL ) { $ pPrepared [ ] = $ pValue ; } } | Prepare the values for PDO . |
2,889 | public function getPreparedConditions ( $ pDbContainer ) { $ prepared = array ( ) ; if ( ! empty ( $ this -> _conditions ) ) { foreach ( $ this -> _conditions as $ field => $ condition ) { $ subPrepared = array ( ) ; if ( is_array ( $ condition ) ) { foreach ( $ condition as $ type => $ value ) { if ( is_int ( $ type ) and is_array ( $ value ) ) { foreach ( $ value as $ subField => $ subCondition ) { if ( is_array ( $ subCondition ) ) { foreach ( $ subCondition as $ type => $ value ) { $ prefixedField = ( stripos ( $ subField , ItemInterface :: PREFIX_SEPARATOR . ItemInterface :: IDFIELD ) !== false ) ? $ subField : $ pDbContainer . ItemInterface :: PREFIX_SEPARATOR . $ subField ; $ subPrepared [ ] = $ this -> _processTypeCondition ( $ prefixedField , $ type , $ value ) ; } } else { $ prefixedField = ( stripos ( $ subField , ItemInterface :: PREFIX_SEPARATOR . ItemInterface :: IDFIELD ) !== false ) ? $ subField : $ pDbContainer . ItemInterface :: PREFIX_SEPARATOR . $ subField ; $ subPrepared [ ] = '`' . $ prefixedField . '` = ?' ; } } } else { $ prefixedField = ( stripos ( $ field , ItemInterface :: PREFIX_SEPARATOR . ItemInterface :: IDFIELD ) !== false ) ? $ field : $ pDbContainer . ItemInterface :: PREFIX_SEPARATOR . $ field ; $ subPrepared [ ] = $ this -> _processTypeCondition ( $ prefixedField , $ type , $ value ) ; } } } else { $ prefixedField = ( stripos ( $ field , ItemInterface :: PREFIX_SEPARATOR . ItemInterface :: IDFIELD ) !== false ) ? $ field : $ pDbContainer . ItemInterface :: PREFIX_SEPARATOR . $ field ; $ prepared [ ] = '(`' . $ prefixedField . '` = ?)' ; } if ( ! empty ( $ subPrepared ) ) { $ prepared [ ] = '(' . implode ( ' ' . $ this -> getSubType ( ) . ' ' , $ subPrepared ) . ')' ; } } } return implode ( ' ' . $ this -> getType ( ) . ' ' , $ prepared ) ; } | Return a PDO prepared string representation of the conditions . |
2,890 | public function getPreparedValues ( ) { $ prepared = array ( ) ; if ( ! empty ( $ this -> _conditions ) ) { foreach ( $ this -> _conditions as $ condition ) { if ( is_array ( $ condition ) ) { foreach ( $ condition as $ type => $ value ) { if ( is_int ( $ type ) and is_array ( $ value ) ) { foreach ( $ value as $ subCondition ) { if ( is_array ( $ subCondition ) ) { foreach ( $ subCondition as $ type => $ value ) { $ this -> _processTypeValue ( $ type , $ value , $ prepared ) ; } } else { $ prepared [ ] = $ subCondition ; } } } else { $ this -> _processTypeValue ( $ type , $ value , $ prepared ) ; } } } else { $ prepared [ ] = $ condition ; } } } return $ prepared ; } | Return a PDO array with the prepared values . |
2,891 | public function user ( $ username , Bag $ bag = null ) { $ data = $ this -> createData ( array ( 'api_token' => $ this -> apiToken , 'username' => strtoupper ( $ username ) , ) , $ bag ) ; $ response = $ this -> send ( 'yo/' , InternalRequestInterface :: METHOD_POST , $ data ) ; $ content = json_decode ( $ response -> getBody ( ) -> getContents ( ) ) ; return ( boolean ) $ content -> success ; } | Yo an user with or without a Bag object . |
2,892 | public function create ( $ username , $ password , $ callbackUrl = '' , $ email = '' , $ description = '' , $ needsLocation = false ) { $ data = array ( 'new_account_username' => strtoupper ( $ username ) , 'new_account_passcode' => $ password , 'callback_url' => $ callbackUrl , 'email' => $ email , 'description' => $ description , 'needs_location' => $ needsLocation ? 'true' : 'false' , 'api_token' => $ this -> apiToken , ) ; $ this -> send ( 'accounts/' , InternalRequestInterface :: METHOD_POST , $ data ) ; } | Create new Yo account . |
2,893 | public function total ( ) { $ response = $ this -> send ( sprintf ( 'subscribers_count/?api_token=%s' , $ this -> apiToken ) ) ; $ content = json_decode ( $ response -> getBody ( ) ) ; return ( integer ) $ content -> count ; } | Get total of subscribers . |
2,894 | public function exists ( $ username ) { $ response = $ this -> send ( sprintf ( 'check_username/?api_token=%s&username=%s' , $ this -> apiToken , strtoupper ( $ username ) ) ) ; $ content = json_decode ( $ response -> getBody ( ) ) ; return ( boolean ) $ content -> exists ; } | Check if a given username exists or not . |
2,895 | public function getAuthenticateFromChallenge ( ChallengeMessage $ msg ) { $ token = [ 'id' => $ this -> authid , 'exp' => time ( ) + 60 , ] ; $ token = JWT :: encode ( $ token , Security :: salt ( ) ) ; return new AuthenticateMessage ( $ token ) ; } | Get Authenticate message from challenge message |
2,896 | protected function configure ( ) { $ this -> setDescription ( $ this -> shortDesc ) ; foreach ( $ this -> paramsArray as $ nameParam => $ arrayOptions ) { if ( $ arrayOptions [ 'optional' ] ) { $ this -> addOption ( $ nameParam , null , InputOption :: VALUE_OPTIONAL , $ arrayOptions [ 'comment' ] , null ) ; } else { $ this -> addOption ( $ nameParam , null , InputOption :: VALUE_REQUIRED , $ arrayOptions [ 'comment' ] , null ) ; } } } | Extends configure from Symfony Command Class |
2,897 | public function getOption ( $ flag ) { return isset ( $ this -> options [ $ flag ] ) ? $ this -> options [ $ flag ] : null ; } | Return a single value that matches |
2,898 | public function denormalizeValue ( array $ data ) { $ processed = array ( ) ; foreach ( $ data as $ docId => $ content ) { $ cloned = $ content ; $ keys = array_keys ( $ cloned ) ; $ ofType = array_pop ( $ keys ) ; $ asArray = ( 'array' === $ ofType ) ? true : false ; $ value = $ content [ $ ofType ] ; Assertion :: isJsonString ( $ value , 'Invalid json string in registry' ) ; $ processed [ $ docId ] = json_decode ( $ value , $ asArray ) ; } return $ processed ; } | Converts a normalized array to the original value |
2,899 | protected function resolve ( ) { $ this -> content = '' ; $ this -> isBinary = null ; if ( ! self :: $ tmpCookies ) { self :: $ tmpCookies = str_replace ( '//' , '/' , sys_get_temp_dir ( ) . '/embed-cookies.txt' ) ; } $ connection = curl_init ( ) ; curl_setopt_array ( $ connection , [ CURLOPT_RETURNTRANSFER => false , CURLOPT_FOLLOWLOCATION => true , CURLOPT_URL => $ this -> url , CURLOPT_COOKIEJAR => self :: $ tmpCookies , CURLOPT_COOKIEFILE => self :: $ tmpCookies , CURLOPT_HEADERFUNCTION => [ $ this , 'headerCallback' ] , CURLOPT_WRITEFUNCTION => [ $ this , 'writeCallback' ] , ] + $ this -> config ) ; $ result = curl_exec ( $ connection ) ; $ this -> result = curl_getinfo ( $ connection ) ? : [ ] ; if ( ! $ result ) { $ this -> result [ 'error' ] = curl_error ( $ connection ) ; $ this -> result [ 'error_number' ] = curl_errno ( $ connection ) ; } curl_close ( $ connection ) ; if ( ( $ content_type = $ this -> getResult ( 'content_type' ) ) ) { if ( strpos ( $ content_type , ';' ) !== false ) { list ( $ mimeType , $ charset ) = explode ( ';' , $ content_type ) ; $ this -> result [ 'mime_type' ] = $ mimeType ; $ charset = substr ( strtoupper ( strstr ( $ charset , '=' ) ) , 1 ) ; if ( ! empty ( $ charset ) && ! empty ( $ this -> content ) && ( $ charset !== 'UTF-8' ) ) { $ this -> content = mb_convert_encoding ( $ this -> content , 'UTF-8' , $ charset ) ; } } elseif ( strpos ( $ content_type , '/' ) !== false ) { $ this -> result [ 'mime_type' ] = $ content_type ; } } } | Resolves the current url and get the content and other data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.