idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
45,300 | public function registerServiceManager ( string $ name , ServiceManager $ service_manager ) : Core { $ this -> service_managers -> register ( $ name , $ service_manager ) ; return $ this ; } | Register a service manager . |
45,301 | public function on ( string $ event , $ class_or_obj , string $ method , array $ arguments = [ ] ) : Core { $ this -> registerEventHandler ( new EventHandler ( $ event , $ class_or_obj , $ method , $ arguments ) ) ; return $ this ; } | Create an event handler to be called when a specified event is fired by the framework or a library within the Framework . |
45,302 | public function fireEvent ( string $ event ) : void { $ this -> log -> debug ( 'Event {event} has been fired.' , [ 'event' => $ event ] ) ; foreach ( $ this -> event_handlers as $ handler ) { if ( $ event === $ handler -> getEvent ( ) ) { $ handler -> execute ( ) ; } } } | Register a callback to be run before the renderer is called |
45,303 | public function getRemoteIP ( ) : string { if ( null === $ this -> remote_ip ) { $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; if ( ! empty ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ ip = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; $ ip = explode ( ',' , $ ip ) ; $ ip = trim ( $ ip [ 0 ] ) ; } $ this -> remote_ip = $ ip ; } return $ this -> remote_ip ; } | Get the IP address of the user |
45,304 | public static function check ( $ name , $ user , $ request , $ options = [ ] ) { if ( ( $ config = static :: _config ( $ name ) ) === null ) { throw new ConfigException ( "Configuration `{$name}` has not been defined." ) ; } $ filter = function ( $ self , $ params ) use ( $ name ) { $ user = $ params [ 'user' ] ; $ request = $ params [ 'request' ] ; $ options = $ params [ 'options' ] ; return $ self :: adapter ( $ name ) -> check ( $ user , $ request , $ options ) ; } ; $ params = compact ( 'user' , 'request' , 'options' ) ; return static :: _filter ( __FUNCTION__ , $ params , $ filter , ( array ) $ config [ 'filters' ] ) ; } | Performs an access check . |
45,305 | protected function call ( array $ params ) { $ defaultParams = [ 'key' => $ this -> apiKey , 'format' => 'json' , 'apiVersion' => self :: VERSION , ] ; $ params = array_merge ( $ defaultParams , $ params ) ; $ url = sprintf ( '%s?%s' , self :: ENDPOINT , http_build_query ( $ params ) ) ; $ response = $ this -> adapter -> get ( $ url ) ; $ result = json_decode ( $ response -> getBody ( ) -> getContents ( ) , true ) ; if ( $ result [ 'result' ] == 'ERR' ) { throw new ApiException ( $ result [ 'message' ] , $ result [ 'code' ] ) ; } return $ result ; } | Sends a call to the API |
45,306 | protected function _parseLang ( $ src = null , $ lang ) { if ( $ src == null ) { $ file = APP_RESOURCE_LANG_PATH . $ lang . '.xml' ; $ src = 'app' ; } else { $ file = SRC_PATH . $ src . '/' . SRC_RESOURCE_LANG_PATH . $ lang . '.xml' ; } $ this -> config [ 'lang' ] [ '' . $ src . '' ] [ '' . $ lang . '' ] = [ ] ; if ( file_exists ( $ file ) ) { if ( $ xml = simplexml_load_file ( $ file ) ) { $ values = $ xml -> xpath ( '//lang' ) ; foreach ( $ values as $ value ) { $ data = null ; foreach ( $ this -> _langAttribute as $ attribute ) { $ attributeType = $ attribute [ 'name' ] ; if ( is_object ( $ value [ $ attributeType ] ) ) { $ data [ $ attributeType ] = $ value [ $ attributeType ] -> __toString ( ) ; } else { $ data [ $ attributeType ] = '' ; } $ data [ 'content' ] = $ value -> __toString ( ) ; } $ data = $ this -> _parseParent ( $ value , $ data , $ this -> _langAttribute ) ; $ this -> config [ 'lang' ] [ '' . $ src . '' ] [ '' . $ lang . '' ] [ '' . $ data [ 'name' ] . '' ] = $ data ; $ this -> config [ 'lang' ] [ '' . $ src . '' ] [ '' . $ lang . '' ] [ '' . $ data [ 'name' ] . '' ] = $ this -> config [ 'lang' ] [ '' . $ src . '' ] [ '' . $ lang . '' ] [ '' . $ data [ 'name' ] . '' ] [ 'content' ] ; } } else { throw new MissingConfigException ( 'can\'t read file "' . $ file . '"' ) ; } } else { throw new MissingConfigException ( 'can\'t open file "' . $ file . '"' ) ; } } | parse lang files and put data in an array |
45,307 | protected function _parseParent ( $ child , $ data , $ attributes ) { $ parent = $ child -> xpath ( "parent::*" ) ; if ( is_object ( $ parent [ 0 ] [ 'name' ] ) ) { foreach ( $ attributes as $ attribute ) { $ name = $ attribute [ 'name' ] ; if ( is_object ( $ parent [ 0 ] [ $ name ] ) ) { $ element = $ parent [ 0 ] [ $ name ] ; if ( $ attribute [ 'concatenate' ] == true ) { if ( $ data [ $ name ] != '' ) { $ data [ $ name ] = $ element -> __toString ( ) . $ attribute [ 'separator' ] . $ data [ $ name ] ; } else { $ data [ $ name ] = $ element -> __toString ( ) ; } } else { if ( $ data [ $ name ] == '' ) { $ data [ $ name ] = $ element -> __toString ( ) ; } } } } $ data = $ this -> _parseParent ( $ parent [ 0 ] , $ data , $ attributes ) ; } return $ data ; } | parse parent node |
45,308 | protected function performAjaxValidation ( $ model ) { $ result = ( $ model instanceof Model ) ? ActiveForm :: validate ( $ model ) : ActiveForm :: validateMultiple ( $ model ) ; $ response = Yii :: $ app -> getResponse ( ) ; if ( ! empty ( $ result ) && $ ajaxRedirect = Yii :: $ app -> getSession ( ) -> get ( 'site_ajax_redirect' ) ) { $ response = $ response -> redirect ( $ ajaxRedirect ) ; Yii :: $ app -> getSession ( ) -> remove ( 'site_ajax_redirect' ) ; } else { $ response -> format = Response :: FORMAT_JSON ; $ response -> data = $ result ; } return $ response ; } | Performs ajax validation |
45,309 | public function start ( string $ key ) { $ filteredKey = $ this -> filterKey ( $ key ) ; $ value = $ this -> get ( $ filteredKey ) ; if ( $ value === null ) { $ this -> lastKey = $ filteredKey ; ob_start ( ) ; } else { $ this -> lastKey = null ; trigger_error ( 'Cache start failed' ) ; } return $ this ; } | Start cache via buffer |
45,310 | public function stop ( float $ timeout = 0.0 ) : self { if ( $ this -> lastKey !== null ) { $ this -> set ( $ this -> lastKey , ob_get_clean ( ) , $ timeout ) ; } $ this -> lastKey = null ; return $ this ; } | Stop buffer and put it in cache |
45,311 | public function cleanAll ( ) : int { $ cpt = 0 ; $ keys = $ this -> getRedis ( ) -> keys ( $ this -> namespace . ':*' ) ; if ( $ keys ) { foreach ( $ keys as $ key ) { $ this -> getRedis ( ) -> del ( $ key ) ; $ cpt ++ ; } } return $ cpt ; } | Clean all values of the current namespace |
45,312 | public function getZendStorage ( string $ namespace = 'default' ) { static $ storages = [ ] ; if ( ! isset ( $ storages [ $ namespace ] ) ) { $ rrm = new RedisResourceManager ( ) ; $ rrm -> setResource ( 'default' , $ this -> getRedis ( ) ) ; $ rrm -> setLibOption ( 'default' , Redis :: OPT_SERIALIZER , $ this -> redis -> getOption ( Redis :: OPT_SERIALIZER ) ) ; $ options = new RedisOptions ( ) ; $ options -> setResourceManager ( $ rrm ) ; $ storages [ $ namespace ] = new RedisAdapter ( $ options ) ; } return $ storages [ $ namespace ] ; } | Build and return a zend cache storage using OSF cache configuration |
45,313 | protected function filterTtl ( & $ ttl ) : void { if ( $ ttl !== null ) { if ( $ ttl instanceof \ DateInterval ) { $ ttl = ( int ) $ ttl -> format ( '%s' ) ; } $ ttl = ( int ) $ ttl ; } } | Mixed ttl to seconds |
45,314 | public function register ( $ serviceClass ) : void { try { $ class = new ReflectionClass ( $ serviceClass ) ; } catch ( ReflectionException $ e ) { throw new RuntimeException ( 'Service class not found' , 0 , $ e ) ; } if ( ! $ class -> implementsInterface ( ServiceProvider :: class ) ) { throw new InvalidArgumentException ( "[$serviceClass] is not a service provider" ) ; } if ( $ class -> hasConstant ( 'requires' ) ) { $ requirements = array_flip ( $ class -> getConstant ( 'requires' ) ) ; foreach ( $ this -> services as $ service_name => $ service ) { if ( array_key_exists ( $ service_name , $ requirements ) ) { unset ( $ requirements [ $ service_name ] ) ; } } if ( count ( $ requirements ) !== 0 ) { $ this -> queue [ $ serviceClass ] = array_flip ( $ requirements ) ; return ; } } $ service = $ this -> ioc -> make ( $ serviceClass ) ; $ service -> register ( ) ; if ( ! $ class -> hasConstant ( 'provides' ) ) { $ this -> services [ ] = $ service ; } else { $ provides = $ class -> getConstant ( 'provides' ) ; $ this -> services [ $ provides ] = $ service ; foreach ( $ this -> queue as $ queued_name => & $ queued ) { if ( in_array ( $ provides , $ queued , true ) ) { unset ( $ this -> queue [ $ queued_name ] ) ; $ this -> register ( $ queued_name ) ; } } } } | Registers a Service Provider to be loaded when the framework boots |
45,315 | public function boot ( ) : void { if ( count ( $ this -> queue ) !== 0 ) { throw new ServiceDependenciesNotRegisteredException ( $ this -> queue ) ; } foreach ( $ this -> services as $ service ) { $ service -> boot ( ) ; } } | Boot all Service Providers |
45,316 | public function handleLogin ( array $ request = [ ] ) { $ validator = new \ Valitron \ Validator ( $ request ) ; $ validator -> rule ( 'required' , [ 'username' , 'password' ] ) ; $ validator -> rule ( function ( $ field , $ value , array $ params , array $ fields ) { return is_string ( $ value ) ; } , [ 'username' , 'password' ] ) -> message ( "Invalid username or password" ) ; $ validator -> rule ( 'lengthBetween' , 'username' , 6 , 200 ) ; $ validator -> rule ( 'lengthBetween' , 'password' , 8 , 80 ) ; if ( $ validator -> validate ( ) === false ) { if ( headers_sent ( ) === false ) { header ( 'X-PHP-Response-Code: 422' , true , 422 ) ; } return $ this -> templates -> render ( "Auth::Login" , [ "messages" => [ 'error' => 'Incorrect username and/or password' , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } $ response = $ this -> core -> api ( 'User/login/' . $ request [ 'username' ] , 'POST' ) -> run ( $ request ) ; if ( headers_sent ( ) === false ) { foreach ( $ response [ "headers" ] as $ header ) { header ( $ header [ 0 ] , $ header [ 1 ] , $ header [ 2 ] ) ; } } if ( $ response [ "headers" ] [ 0 ] [ 2 ] === 422 ) { return $ this -> templates -> render ( "Auth::Login" , [ "messages" => [ 'error' => 'Incorrect username and/or password' , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } elseif ( ( $ response [ "headers" ] [ 0 ] [ 2 ] - 200 ) * ( $ response [ "headers" ] [ 0 ] [ 2 ] - 299 ) <= 0 ) { $ this -> core -> auth ( ) -> validate ( $ response [ "response" ] ) ; $ _SERVER [ 'REQUEST_URI' ] = 'GET' ; $ this -> router -> map ( 'GET' , '/' , "User@showProfile" , 'home-page' ) ; return $ this -> redirect ( ) ; } else { return $ this -> templates -> render ( "500" , [ "error" => $ response [ 'response' ] , "result" => '' ] ) ; } } | Handle the login page submission |
45,317 | public function handleRegister ( array $ request = [ ] ) { $ validator = new \ Valitron \ Validator ( $ request ) ; $ validator -> rule ( 'required' , [ 'username' , 'password' , 'confirm_password' ] ) ; $ validator -> rule ( function ( $ field , $ value , array $ params , array $ fields ) { return is_string ( $ value ) ; } , [ 'username' , 'password' , 'confirm_password' ] ) -> message ( "{field} must be a string" ) ; $ validator -> rule ( 'equals' , 'confirm_password' , 'password' ) ; $ validator -> rule ( 'lengthBetween' , 'username' , 6 , 200 ) ; $ validator -> rule ( 'lengthBetween' , 'password' , 8 , 80 ) ; if ( $ validator -> validate ( ) === false ) { if ( headers_sent ( ) === false ) { header ( 'X-PHP-Response-Code: 422' , true , 422 ) ; } return $ this -> templates -> render ( "Auth::Register" , [ "messages" => [ 'error' => $ validator -> errors ( ) , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } $ response = $ this -> core -> api ( 'User/' , 'POST' ) -> run ( $ request ) ; if ( headers_sent ( ) === false ) { foreach ( $ response [ "headers" ] as $ header ) { header ( $ header [ 0 ] , $ header [ 1 ] , $ header [ 2 ] ) ; } } if ( $ response [ "headers" ] [ 0 ] [ 2 ] === 422 ) { return $ this -> templates -> render ( "Auth::Register" , [ "messages" => [ 'error' => $ response [ 'response' ] , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } elseif ( ( $ response [ "headers" ] [ 0 ] [ 2 ] - 200 ) * ( $ response [ "headers" ] [ 0 ] [ 2 ] - 299 ) <= 0 ) { if ( isset ( $ _GET [ 'template' ] ) === false ) { return redirect ( $ this -> router -> generate ( 'login-page' ) . "?m=1" ) ; } else { return 'Redirect: ' . $ this -> router -> generate ( 'login-page' ) . "?m=1" ; } } else { return $ this -> templates -> render ( "500" , [ "error" => $ response [ 'response' ] , "result" => '' ] ) ; } } | Handle the registration page submission |
45,318 | public function handleForgot ( array $ request = [ ] ) { $ validator = new \ Valitron \ Validator ( $ request ) ; $ validator -> rule ( 'required' , 'email' ) ; $ validator -> rule ( 'email' , 'email' ) ; if ( $ validator -> validate ( ) === false ) { if ( headers_sent ( ) === false ) { header ( 'X-PHP-Response-Code: 422' , true , 422 ) ; } return $ this -> templates -> render ( "Auth::Forgot" , [ "messages" => [ 'error' => $ validator -> errors ( ) , 'info' => '' , 'success' => '' , 'warning' => '' ] , "email" => $ request [ 'email' ] ] ) ; } $ response = $ this -> core -> api ( 'User/forgot/' . $ request [ 'email' ] , 'POST' ) -> run ( $ request ) ; if ( headers_sent ( ) === false ) { foreach ( $ response [ "headers" ] as $ header ) { header ( $ header [ 0 ] , $ header [ 1 ] , $ header [ 2 ] ) ; } } if ( $ response [ "headers" ] [ 0 ] [ 2 ] === 422 ) { return $ this -> templates -> render ( "Auth::Forgot" , [ "messages" => [ 'error' => $ response [ 'response' ] , 'info' => '' , 'success' => '' , 'warning' => '' ] , "email" => $ request [ 'email' ] ] ) ; } elseif ( ( $ response [ "headers" ] [ 0 ] [ 2 ] - 200 ) * ( $ response [ "headers" ] [ 0 ] [ 2 ] - 299 ) <= 0 ) { if ( isset ( $ _GET [ 'template' ] ) === false ) { return redirect ( $ this -> router -> generate ( 'login-page' ) . "?m=2" ) ; } else { return 'Redirect: ' . $ this -> router -> generate ( 'login-page' ) . "?m=2" ; } } else { return $ this -> templates -> render ( "500" , [ "error" => $ response [ 'response' ] , "result" => '' ] ) ; } } | Handle the forgot password page submission |
45,319 | public function showReset ( string $ reset_code = null ) { if ( $ reset_code === null ) { if ( isset ( $ _GET [ 'template' ] ) === false ) { return redirect ( $ this -> router -> generate ( 'login-page' ) . "?m=3" ) ; } else { return 'Redirect: ' . $ this -> router -> generate ( 'login-page' ) . "?m=3" ; } } $ user = Model \ User :: where ( "reset_code" , $ reset_code ) -> first ( ) ; if ( $ user === null ) { if ( isset ( $ _GET [ 'template' ] ) === false ) { return redirect ( $ this -> router -> generate ( 'login-page' ) . "?m=3" ) ; } else { return 'Redirect: ' . $ this -> router -> generate ( 'login-page' ) . "?m=3" ; } } return $ this -> templates -> render ( "Auth::Reset" , [ "messages" => [ 'error' => '' , 'info' => '' , 'success' => '' , 'warning' => '' ] ] ) ; } | Show the password reset page |
45,320 | protected function executeUpdate ( $ sql , $ bindparams = NULL ) { $ result = $ this -> db -> handle -> prepare ( $ sql ) ; $ result -> execute ( $ bindparams ) ; if ( $ result -> errorCode ( ) == '00000' ) { return true ; } $ this -> logStatementError ( $ result -> errorInfo ( ) , $ sql ) ; return false ; } | Execute an update query |
45,321 | protected function queryWithIndex ( $ sql , $ index , $ findex = NULL , $ bindparams = NULL ) { if ( $ result = $ this -> executeQuery ( $ sql , $ bindparams ) ) { $ temp = array ( ) ; if ( $ findex ) { foreach ( $ result as $ row ) { $ temp [ $ row [ $ findex ] ] [ $ row [ $ index ] ] = $ row ; } } else { foreach ( $ result as $ row ) { $ temp [ $ row [ $ index ] ] = $ row ; } } return $ temp ; } return false ; } | Query the DB and return the rows as a 1 or 2 dimensional indexed array |
45,322 | protected function buildIn ( $ ar , & $ bindparams , $ varprefix = 'v' ) { $ x = 1 ; foreach ( $ ar as $ value ) { $ sql .= ":{$varprefix}{$x}," ; $ bindparams [ ":{$varprefix}{$x}" ] = $ value ; $ x ++ ; } return 'IN (' . rtrim ( $ sql , ',' ) . ')' ; } | Returns a parametrized IN clause for use in a prepared statement |
45,323 | protected function buildInsertStatement ( $ data , $ table = null ) { if ( ! $ table ) { $ table = $ this -> primaryTable ; } $ bindparams = array ( ) ; $ sql_fields = NULL ; $ sql_values = NULL ; foreach ( $ data as $ field => $ value ) { $ sql_fields .= "{$field}," ; $ sql_values .= ":{$field}," ; $ bindparams [ ":{$field}" ] = $ value ; } $ sql_fields = rtrim ( $ sql_fields , ',' ) ; $ sql_values = rtrim ( $ sql_values , ',' ) ; $ sql = "INSERT INTO {$table} ({$sql_fields}) VALUES ({$sql_values})" ; if ( $ this -> executeUpdate ( $ sql , $ bindparams ) ) { return $ this -> getLastInsertId ( ) ; } return false ; } | Builds and executes an insert statement |
45,324 | protected function buildMultiRowInsertStatement ( $ rows , $ table = null ) { if ( ! $ table ) { $ table = $ this -> primaryTable ; } $ bindparams = array ( ) ; $ sqlRows = NULL ; $ sqlFields = implode ( ',' , array_keys ( current ( $ rows ) ) ) ; $ x = 1 ; foreach ( $ rows as $ data ) { $ sqlValues = NULL ; foreach ( $ data as $ field => $ value ) { $ sqlValues .= ":{$field}{$x}," ; $ bindparams [ ":{$field}{$x}" ] = $ value ; } $ sqlValues = rtrim ( $ sqlValues , ',' ) ; $ sqlRows .= "({$sqlValues})," ; $ x ++ ; } $ sql = "INSERT INTO {$table} ({$sqlFields}) VALUES " . rtrim ( $ sqlRows , ',' ) ; return $ this -> executeUpdate ( $ sql , $ bindparams ) ; } | Builds and executes a single insert statement that inserts multiple new records |
45,325 | protected function buildUpdateStatement ( $ id , $ data , $ table = null ) { if ( ! $ table ) { $ table = $ this -> primaryTable ; } $ sql = "UPDATE {$table} SET " ; foreach ( $ data as $ field => $ value ) { $ sql .= "{$field}=:{$field}," ; $ bindparams [ ":{$field}" ] = $ value ; } $ sql = rtrim ( $ sql , ',' ) . " WHERE id=:id" ; $ bindparams [ ":id" ] = $ id ; if ( $ this -> executeUpdate ( $ sql , $ bindparams ) ) { return true ; } return false ; } | Builds and executes an update statement |
45,326 | protected function logStatementError ( $ error , $ sql = null ) { if ( ! empty ( $ GLOBALS [ 'config' ] [ 'DB_DEBUG' ] ) ) { $ message = "Error with query - CODE: {$error[1]}" ; if ( $ sql ) { $ message .= " QUERY: {$sql}" ; } $ this -> getLogger ( ) -> error ( $ message ) ; } } | Logs SQL errors to the logger |
45,327 | public function setCookieValue ( string $ name , string $ value , ? \ DateTimeInterface $ expiry = null , ? UrlPathInterface $ path = null , ? HostInterface $ domain = null , bool $ isSecure = false , bool $ isHttpOnly = false ) : void { $ this -> cookies -> set ( $ name , new ResponseCookie ( $ value , $ expiry , $ path , $ domain , $ isSecure , $ isHttpOnly ) ) ; } | Sets a cookie value . |
45,328 | public function setExpiry ( ? \ DateTimeImmutable $ expiry = null ) : void { $ date = new \ DateTimeImmutable ( ) ; $ expiry = $ expiry ? : $ date ; $ this -> setHeader ( 'Date' , $ date -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) -> format ( 'D, d M Y H:i:s \G\M\T' ) ) ; $ this -> setHeader ( 'Expires' , $ expiry -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) -> format ( 'D, d M Y H:i:s \G\M\T' ) ) ; if ( $ expiry <= $ date ) { $ this -> setHeader ( 'Cache-Control' , 'no-cache, no-store, must-revalidate, max-age=0' ) ; return ; } $ maxAge = $ expiry -> getTimestamp ( ) - $ date -> getTimestamp ( ) ; $ this -> setHeader ( 'Cache-Control' , 'public, max-age=' . $ maxAge ) ; } | Sets the expiry time . |
45,329 | public function readUntil ( $ end ) { if ( empty ( $ end ) ) { throw new ResourceException ( "Empty string given to Reader::readUntil()" ) ; } fseek ( $ this -> resource , $ this -> readPosition ) ; $ buffer = stream_get_contents ( $ this -> resource , 1 ) ; $ mode = $ this -> blocking ( ) ; $ size = strlen ( $ end ) ; $ this -> blocking ( false ) ; while ( strlen ( $ buffer ) < $ size || substr ( $ buffer , - $ size ) != $ end ) { $ c = stream_get_contents ( $ this -> resource , 1 ) ; if ( empty ( $ c ) ) { break ; } $ buffer .= $ c ; } $ this -> blocking ( $ mode ) ; $ this -> readPosition = ftell ( $ this -> resource ) ; return ( substr ( $ buffer , - $ size ) == $ end ) ? substr ( $ buffer , 0 , strlen ( $ buffer ) - $ size ) : $ buffer ; } | Reads until the given string or the end of contents . Returns the read string without the ending string . |
45,330 | public function write ( $ content ) { fseek ( $ this -> resource , $ this -> writePosition ) ; if ( false === fwrite ( $ this -> resource , $ content ) ) throw new ResourceException ( "Unable to write content to resource" ) ; $ this -> writePosition = ftell ( $ this -> resource ) ; return $ this ; } | Writes content . |
45,331 | protected function initialiseMonitoring ( ) { for ( $ i = 0 ; $ i < count ( $ this -> entries ) ; $ i ++ ) { $ this -> monitor -> monitor ( $ this -> entries [ $ i ] [ 'entry' ] ) ; } } | Registers all entries at the monitor as not executed . |
45,332 | protected function publishEntry ( string $ entryId , array $ parameters , array $ content ) { $ entry = $ this -> entryFactory -> getEntry ( $ entryId , $ parameters ) ; $ entry -> setBody ( $ content ) ; $ response = $ this -> publish ( $ entry ) ; $ this -> setStatus ( $ entryId , $ entry , $ response ) ; } | Creates the entry gets the request executes it and sets the status of the request as successful or failed . |
45,333 | public function update ( $ options = [ ] ) { if ( is_null ( $ this -> row ) ) { return $ this -> reset ( ) ; } $ mergeOptions = array_replace_recursive ( $ this -> _value , $ options ) ; $ result = WpOption :: updateOrCreate ( [ 'option_name' => $ this -> optionsName ] , [ 'option_value' => json_encode ( $ mergeOptions ) ] ) ; $ this -> _value = ( array ) $ mergeOptions ; return $ result ; } | Update a branch of options . |
45,334 | public function delta ( ) { $ mergeOptions = $ this -> __delta ( $ this -> optionsData , $ this -> _value ) ; $ result = WpOption :: updateOrCreate ( [ 'option_name' => $ this -> optionsName ] , [ 'option_value' => json_encode ( $ mergeOptions ) ] ) ; $ this -> _value = ( array ) $ mergeOptions ; return $ result ; } | Execute a delta from the current version of the options and the previous version stored in the database . |
45,335 | public function set ( string $ name , $ item ) : void { $ this -> payloadContainerItems -> set ( $ name , $ item ) ; } | Add a specific item to the container . |
45,336 | protected function checkResponseErrors ( ResponseInterface $ response ) { $ status = intval ( $ response -> getStatusCode ( ) ) ; if ( $ status === 200 ) return ; switch ( $ status ) { case 401 : throw new AuthorizationException ( $ response ) ; default : throw new RequestException ( $ response ) ; } } | Checks the given response for error codes throwing the appropriate exceptions if needed . |
45,337 | public function getDafaultLogger ( ) { if ( null === $ this -> root ) { $ this -> root = new HierarchialLogger ( null ) ; } return $ this -> root ; } | Get the default logger . |
45,338 | protected function newLogger ( $ name , LoggerInterface $ parent ) { $ logger = $ parent ; if ( $ parent instanceof HierarchialLogger ) { $ logger = new HierarchialLogger ( $ name ) ; $ logger -> setParent ( $ parent ) ; } return $ logger ; } | Create a new LoggerInterface instance . |
45,339 | public function removeOne ( $ value ) : bool { if ( $ this -> isValidType ( $ value ) === false ) { throw new MWrongTypeException ( "\$value" , $ this -> getType ( ) , $ value ) ; } $ result = array_search ( $ value , $ this -> list ) ; if ( $ result === false ) { throw new \ OutOfBoundsException ( ) ; } unset ( $ this -> list [ $ result ] ) ; return true ; } | Removes the first occurrence of value in the list and returns true on success ; otherwise returns false . |
45,340 | public function startsWith ( $ value ) : bool { if ( $ this -> isValidType ( $ value ) === false ) { throw new MWrongTypeException ( "\$value" , $ this -> getType ( ) , $ value ) ; } if ( $ this -> count ( ) <= 0 ) { return false ; } $ lastValue = $ this -> list [ 0 ] ; return ( $ lastValue == $ value ) ; } | Returns true if this list is not empty and its first item is equal to value ; otherwise returns false . |
45,341 | public function offsetExists ( $ offset ) : bool { MDataType :: mustBe ( array ( MDataType :: INT ) ) ; return ( array_key_exists ( $ offset , $ this -> list ) === true ) ; } | Return if a key exists . |
45,342 | public function FireAs ( $ Options ) { if ( ! is_array ( $ Options ) ) $ Options = array ( 'FireClass' => $ Options ) ; if ( array_key_exists ( 'FireClass' , $ Options ) ) $ this -> FireAs = GetValue ( 'FireClass' , $ Options ) ; return $ this ; } | Fire the next event off a custom parent class |
45,343 | public function flip ( ) { $ this -> counter ++ ; unset ( $ this -> isLucky ) ; $ this -> currentSide = $ this -> isLucky ( ) ? $ this -> expectedSide : $ this -> getOppositeSide ( $ this -> expectedSide ) ; return $ this -> currentSide ; } | Flips the coin and returns its side |
45,344 | public function isLucky ( ) { if ( isset ( $ this -> isLucky ) ) { return $ this -> isLucky ; } $ this -> isLucky = $ this -> checkLuck ( ) ; return $ this -> isLucky ; } | Returns true if you are lucky |
45,345 | private function createCookie ( ) { $ rand_id = rand ( 10000000 , 99999999 ) ; $ random = rand ( 1000000000 , 2147483647 ) ; $ var = '-' ; $ time = time ( ) ; $ cookie = '' ; $ cookie .= '__utma=' . $ rand_id . '.' . $ random . '.' . $ time . '.' . $ time . '.' . $ time . '.2;+' ; $ cookie .= '__utmb=' . $ rand_id . ';+' ; $ cookie .= '__utmc=' . $ rand_id . ';+' ; $ cookie .= '__utmz=' . $ rand_id . '.' . $ time . '.2.2.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none);+' ; $ cookie .= '__utmv=' . $ rand_id . '.' . $ var . ';' ; return $ cookie ; } | Create unique cookie |
45,346 | public function createGif ( ) { $ data = array ( ) ; foreach ( $ this -> data as $ key => $ item ) { if ( $ item !== null ) { $ data [ $ key ] = $ item ; } } return $ this -> tracking = self :: GA_URL . '?' . http_build_query ( $ data ) ; } | Create the GA callback url aka the gif |
45,347 | private function remoteCall ( ) { if ( function_exists ( 'wp_remote_head' ) ) { $ response = wp_remote_head ( $ this -> tracking ) ; return $ response ; } elseif ( function_exists ( 'curl_init' ) ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ this -> tracking ) ; curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 10 ) ; curl_exec ( $ ch ) ; curl_close ( $ ch ) ; } else { $ handle = fopen ( $ this -> tracking , "r" ) ; fclose ( $ handle ) ; } return ; } | Use WP s HTTP class or CURL or fopen |
45,348 | public function sendTransaction ( $ transaction_id , $ affiliation , $ total , $ tax , $ shipping , $ city , $ region , $ country ) { $ this -> data [ 'utmvw' ] = '5.6.4dc' ; $ this -> data [ 'utms' ] = ++ self :: $ RequestsForThisSession ; $ this -> data [ 'utmt' ] = 'tran' ; $ this -> data [ 'utmtid' ] = $ transaction_id ; $ this -> data [ 'utmtst' ] = $ affiliation ; $ this -> data [ 'utmtto' ] = $ total ; $ this -> data [ 'utmttx' ] = $ tax ; $ this -> data [ 'utmtsp' ] = $ shipping ; $ this -> data [ 'utmtci' ] = $ city ; $ this -> data [ 'utmtrg' ] = $ region ; $ this -> data [ 'utmtco' ] = $ country ; $ this -> data [ 'utmcs' ] = 'UTF-8' ; $ this -> send ( ) ; $ this -> reset ( ) ; return $ this ; } | Create and send a transaction object |
45,349 | public static function truncate ( $ value , $ length = 80 , $ terminator = "\n" , $ preserve = false ) { $ length = $ preserve ? static :: preserveBreakpoint ( $ value , $ length ) : $ length ; if ( mb_strlen ( $ value ) > $ length ) { $ value = rtrim ( mb_substr ( $ value , 0 , $ length ) ) . $ terminator ; } return $ value ; } | Truncates the value string with the provided length |
45,350 | private static function preserveBreakpoint ( $ value , $ length ) { if ( strlen ( $ value ) <= $ length ) { return $ length ; } $ breakpoint = mb_strpos ( $ value , ' ' , $ length ) ; $ length = $ breakpoint ; if ( false === $ breakpoint ) { $ length = mb_strlen ( $ value ) ; } return $ length ; } | Check truncate length to avoid split a word |
45,351 | protected function validate ( ) { if ( ! empty ( $ this -> errors ) ) { return ; } $ this -> errors = [ ] ; foreach ( $ this -> rules as $ field => $ rules ) { $ value = $ this -> getValue ( $ field ) ; foreach ( $ this -> provider -> getRules ( $ rules ) as $ rule ) { if ( $ rule -> ignoreEmpty ( $ value ) && empty ( $ rule -> hasConditions ( ) ) ) { continue ; } foreach ( $ rule -> getConditions ( ) as $ condition ) { if ( ! $ condition -> isMet ( $ this , $ field , $ value ) ) { continue 2 ; } } if ( ! $ rule -> validate ( $ this , $ field , $ value ) ) { $ this -> errors [ $ field ] = $ rule -> getMessage ( $ field , $ value ) ; break ; } } } } | Validate data over given rules and context . |
45,352 | private function getDefinitionForServiceId ( $ serviceId , ServiceConfig $ serviceConfig ) { if ( $ serviceConfig -> has ( ServiceConfig :: LAZY ) && ! $ serviceConfig -> get ( ServiceConfig :: LAZY ) ) { return new Reference ( $ serviceId ) ; } else { return new Definition ( $ this -> invokeClass , array ( new Reference ( 'service_container' ) , $ serviceId ) ) ; } } | return a InvokeClass for lazyLoading or a reference of the service |
45,353 | protected function load ( $ filename , $ data = array ( ) , $ return = false ) { $ template = $ this -> createSubTemplate ( ) ; try { return $ template -> renderTemplate ( $ filename , $ data , $ return ) ; } catch ( \ Exception $ exception ) { if ( ! empty ( $ this -> log ) ) { $ this -> log -> error ( "Failed to render template " . $ filename , $ exception ) ; } return '' ; } } | Build a template |
45,354 | private function parseTemplate ( $ filename , $ data ) { if ( is_array ( $ data ) ) { $ this -> _templateData = $ data ; } else if ( is_object ( $ data ) ) { if ( method_exists ( $ data , 'getTemplateData' ) ) { $ this -> _templateData = $ data -> getTemplateData ( ) ; } else { $ this -> _templateData = ( array ) $ data ; } } else { $ this -> _templateData = array ( 'variable' => $ data ) ; } $ this -> allowRecursion = ( ! empty ( $ this -> _templateData [ '_allowRecursion' ] ) ? true : false ) ; $ filename = $ this -> locateViewFile ( $ filename ) ; if ( $ filename ) { $ this -> setCurrentTemplate ( $ filename ) ; ob_start ( ) ; include $ filename ; $ info = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ info ; } return false ; } | Parse a specific filename with data |
45,355 | public function locateViewFile ( $ filename , $ requiredNamespace = '' ) { foreach ( $ this -> templateSearchDirectories as $ namespace => $ location ) { if ( ! empty ( $ requiredNamespace ) && ( $ namespace != $ requiredNamespace ) ) { continue ; } $ fullFilename = $ location . DIRECTORY_SEPARATOR . str_replace ( '..' , '' , $ filename ) ; if ( ! $ this -> allowRecursion && ( $ fullFilename == $ this -> parentTemplate ) ) { if ( ! empty ( $ this -> log ) ) { $ this -> log -> error ( "Disallowed template recursion found in filename " . $ filename . ". To allow recursion, send _allowRecursion=true into the template data." ) ; } return '' ; } if ( is_file ( $ fullFilename ) ) { return $ fullFilename ; } } if ( ! empty ( $ this -> log ) ) { $ this -> log -> error ( "Invalid template filename specified " . $ filename ) ; } return '' ; } | Locate a desired view file |
45,356 | public function humanize ( ) { $ this -> stream -> setCompression ( Stream :: COMPRESS_OFF ) ; $ this -> stream -> setEncryption ( Stream :: CRYPT_OFF ) ; $ this -> setEncoding ( Common :: ENC_XML ) ; return $ this ; } | good for debugging bad for security size flexibility |
45,357 | public function getResponse ( $ code = ResponseCode :: NO_CONTENT , $ content = null , $ headers = [ ] ) { $ response = clone $ this -> baseResponse ; if ( $ code !== false ) { $ response -> setStatus ( $ code ) ; } if ( $ content !== false ) { $ response -> setBody ( $ content ) ; } if ( $ this -> headersMode === self :: HEADERS_MODE_ADD ) { foreach ( $ headers as $ name => $ value ) { $ response -> addHeader ( $ name , $ value ) ; } } else { foreach ( $ headers as $ name => $ value ) { $ response -> setHeader ( $ name , $ value ) ; } } return $ response ; } | Produces response with default values . |
45,358 | public function providers ( ) { return collect ( $ this -> getManifest ( ) ) -> flatMap ( function ( $ configuration ) { return ( array ) ( $ configuration [ 'providers' ] ? $ configuration [ 'providers' ] : [ ] ) ; } ) -> filter ( ) -> all ( ) ; } | Get all of the service provider class names for all packages . |
45,359 | public function aliases ( ) { return collect ( $ this -> getManifest ( ) ) -> flatMap ( function ( $ configuration ) { return ( array ) ( $ configuration [ 'aliases' ] ? $ configuration [ 'aliases' ] : [ ] ) ; } ) -> filter ( ) -> all ( ) ; } | Get all of the aliases for all packages . |
45,360 | public function build ( ) { $ packages = [ ] ; if ( $ this -> files -> exists ( $ path = $ this -> vendorPath . '/composer/installed.json' ) ) { $ packages = json_decode ( $ this -> files -> get ( $ path ) , true ) ; } $ ignoreAll = in_array ( '*' , $ ignore = $ this -> packagesToIgnore ( ) ) ; $ this -> write ( $ keys = collect ( $ packages ) -> mapWithKeys ( function ( $ package ) { return [ $ this -> format ( $ package [ 'name' ] ) => $ package [ 'extra' ] [ 'nano7' ] ? $ package [ 'extra' ] [ 'nano7' ] : [ ] ] ; } ) -> each ( function ( $ configuration ) use ( & $ ignore ) { $ ignore = array_merge ( $ ignore , $ configuration [ 'dont-discover' ] ? $ configuration [ 'dont-discover' ] : [ ] ) ; } ) -> reject ( function ( $ configuration , $ package ) use ( $ ignore , $ ignoreAll ) { return $ ignoreAll || in_array ( $ package , $ ignore ) ; } ) -> filter ( ) -> all ( ) ) ; return $ keys ; } | Build the manifest and write it to disk . |
45,361 | public static function Taitt ( $ tai1 , $ tai2 , & $ tt1 , & $ tt2 ) { $ dtat = TTMTAI / DAYSEC ; if ( $ tai1 > $ tai2 ) { $ tt1 = $ tai1 ; $ tt2 = $ tai2 + $ dtat ; } else { $ tt1 = $ tai1 + $ dtat ; $ tt2 = $ tai2 ; } return 0 ; } | - - - - - - - - - i a u T a i t t - - - - - - - - - |
45,362 | public static function convertToMaestranoObject ( $ resp , $ preset ) { $ types = array ( 'account_bill' => 'Maestrano_Account_Bill' , 'account_recurring_bill' => 'Maestrano_Account_RecurringBill' , 'account_group' => 'Maestrano_Account_Group' , 'account_user' => 'Maestrano_Account_User' , 'account_reseller' => 'Maestrano_Account_Reseller' , ) ; if ( self :: isList ( $ resp ) ) { $ mapped = array ( ) ; foreach ( $ resp as $ i ) array_push ( $ mapped , self :: convertToMaestranoObject ( $ i , $ preset ) ) ; return $ mapped ; } else if ( is_array ( $ resp ) ) { if ( isset ( $ resp [ 'object' ] ) && is_string ( $ resp [ 'object' ] ) && isset ( $ types [ $ resp [ 'object' ] ] ) ) { $ class = $ types [ $ resp [ 'object' ] ] ; } else { $ class = 'Maestrano_Api_Object' ; } return Maestrano_Api_Object :: scopedConstructFrom ( $ class , $ resp , $ preset ) ; } else { if ( preg_match ( '/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/' , $ resp ) ) { return new DateTime ( $ resp ) ; } else { return $ resp ; } } } | Converts a response from the Maestrano API to the corresponding PHP object . |
45,363 | protected function doLoad ( $ itemClass ) { $ itemMetaData = $ this -> newItemMetaDataInstance ( $ itemClass ) ; $ entityDefinitions = $ this -> annotationDriver -> loadEntityDefinitions ( $ itemClass ) ; $ itemMetaData -> mapEntities ( $ entityDefinitions ) ; $ hitDefinitions = $ this -> annotationDriver -> loadHitDefinitions ( $ itemClass ) ; $ itemMetaData -> mapHits ( $ hitDefinitions ) ; return $ itemMetaData ; } | Loads the itemMetaData of the item class |
45,364 | public static function forge ( $ setup = null , array $ config = array ( ) ) { empty ( $ setup ) and $ setup = \ Config :: get ( 'email.default_setup' , 'default' ) ; is_string ( $ setup ) and $ setup = \ Config :: get ( 'email.setups.' . $ setup , array ( ) ) ; $ setup = \ Arr :: merge ( static :: $ _defaults , $ setup ) ; $ config = \ Arr :: merge ( $ setup , $ config ) ; $ driver = '\\Email_Driver_' . ucfirst ( strtolower ( $ config [ 'driver' ] ) ) ; if ( ! class_exists ( $ driver , true ) ) { throw new \ FuelException ( 'Could not find Email driver: ' . $ config [ 'driver' ] . ' (' . $ driver . ')' ) ; } $ driver = new $ driver ( $ config ) ; return $ driver ; } | Email driver forge . |
45,365 | public function get ( $ key ) { if ( ! $ this -> has ( $ key ) ) { return null ; } return ( new SettingModel ) -> cached ( ) -> where ( 'key' , $ key ) -> first ( ) -> value ; } | Get value if key exists else it will return null |
45,366 | public function put ( $ key , $ value ) { if ( $ this :: has ( $ key ) ) { $ setting = ( new SettingModel ) -> cached ( ) -> where ( 'key' , $ key ) -> first ( ) ; $ setting -> value = $ value ; return $ setting -> save ( ) ; } return SettingModel :: create ( [ 'key' => $ key , 'value' => $ value , ] ) ; } | Store new key and value in settings if it s already exits then override . |
45,367 | public function forget ( $ key ) { $ isDeleted = SettingModel :: where ( 'key' , $ key ) -> delete ( ) ; if ( $ isDeleted ) { Cache :: forget ( 'Klaravel\Settings\Setting' ) ; } return $ isDeleted ; } | Delete setting data from databasse |
45,368 | protected function getClient ( $ clientName ) { $ clientName = $ clientName ? : 'gbprod.elastica_extra.default_client' ; $ client = $ this -> getContainer ( ) -> get ( $ clientName , ContainerInterface :: NULL_ON_INVALID_REFERENCE ) ; $ this -> validateClient ( $ client , $ clientName ) ; return $ client ; } | Get elasticsearch client from his name |
45,369 | public static function find ( string $ source ) : ? string { $ class = false ; $ namespace = false ; $ tokens = token_get_all ( $ source ) ; if ( 1 === count ( $ tokens ) && T_INLINE_HTML === $ tokens [ 0 ] [ 0 ] ) { return null ; } for ( $ i = 0 ; isset ( $ tokens [ $ i ] ) ; ++ $ i ) { $ token = $ tokens [ $ i ] ; if ( ! isset ( $ token [ 1 ] ) ) { continue ; } if ( true === $ class && T_STRING === $ token [ 0 ] ) { return $ namespace . '\\' . $ token [ 1 ] ; } if ( true === $ namespace && T_STRING === $ token [ 0 ] ) { $ namespace = $ token [ 1 ] ; while ( isset ( $ tokens [ ++ $ i ] [ 1 ] ) && in_array ( $ tokens [ $ i ] [ 0 ] , [ T_NS_SEPARATOR , T_STRING ] , true ) ) { $ namespace .= $ tokens [ $ i ] [ 1 ] ; } $ token = $ tokens [ $ i ] ; } if ( T_CLASS === $ token [ 0 ] ) { $ skipClassToken = false ; for ( $ j = $ i - 1 ; $ j > 0 ; -- $ j ) { if ( ! isset ( $ tokens [ $ j ] [ 1 ] ) || ! in_array ( $ tokens [ $ j ] [ 0 ] , [ T_WHITESPACE , T_DOC_COMMENT , T_COMMENT ] , true ) ) { break ; } if ( T_DOUBLE_COLON === $ tokens [ $ j ] [ 0 ] || T_NEW === $ tokens [ $ j ] [ 0 ] ) { $ skipClassToken = true ; break ; } } if ( ! $ skipClassToken ) { $ class = true ; } } if ( T_NAMESPACE === $ token [ 0 ] ) { $ namespace = true ; } } return null ; } | Find class and return fully qualified name in the source |
45,370 | public static function shutdown ( ) { global $ PPHP ; $ req = grab ( 'request' ) ; if ( ! $ req [ 'binary' ] ) { $ body = ob_get_contents ( ) ; ob_end_clean ( ) ; try { array_merge_assoc ( self :: $ _stash , array ( 'body' => self :: $ _safeBody , 'stdout' => $ body , 'config' => $ PPHP [ 'config' ] , 'session' => $ _SESSION , 'req' => grab ( 'request' ) ) ) ; self :: $ _template -> displayBlock ( 'body' , self :: $ _stash ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } ; } ; } | Clean up content capture and display main template |
45,371 | function gettext ( $ string ) { global $ PPHP ; $ req = grab ( 'request' ) ; $ default = $ PPHP [ 'config' ] [ 'global' ] [ 'default_lang' ] ; $ current = $ req [ 'lang' ] ; $ res = $ string ; try { if ( self :: $ _gettext !== null ) { $ res = self :: $ _gettext -> gettext ( $ string ) ; } ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } ; return $ res ; } | Simple no - plurals translation lookup in config . ini |
45,372 | public static function title ( $ prepend , $ sep = ' - ' ) { self :: $ _stash [ 'title' ] = $ prepend . ( isset ( self :: $ _stash [ 'title' ] ) ? ( $ sep . self :: $ _stash [ 'title' ] ) : '' ) ; } | Prepend new section to page title |
45,373 | public static function renderBlocks ( $ name , $ args = array ( ) ) { global $ PPHP , $ _SESSION ; array_merge_assoc ( self :: $ _stash , $ args , array ( 'config' => $ PPHP [ 'config' ] , 'session' => $ _SESSION , 'req' => grab ( 'request' ) ) ) ; try { $ template = self :: $ _twig -> loadTemplate ( $ name ) ; $ blockNames = $ template -> getBlockNames ( self :: $ _stash ) ; $ results = array ( ) ; foreach ( $ blockNames as $ blockName ) { $ results [ $ blockName ] = $ template -> renderBlock ( $ blockName , self :: $ _stash ) ; } ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; } ; return $ results ; } | Render all blocks from a template |
45,374 | protected function convertAndReturn ( $ comments ) { $ retval = false ; if ( $ comments && is_array ( $ comments ) && count ( $ comments ) ) { $ retval = array ( ) ; foreach ( $ comments as $ theComment ) { $ commentInstance = new $ this -> className ( $ theComment ) ; array_push ( $ retval , $ commentInstance ) ; } } return $ retval ; } | Converts an array of standard object instances to Comment model instances |
45,375 | public static function concat ( ) { $ args = func_get_arg ( ) ; $ string = '' ; foreach ( $ args as $ arg ) { $ string .= $ arg ; } return $ string ; } | Concat strings as many as args . |
45,376 | public static function compare ( $ str1 , $ str2 , $ ignoreCase = true ) { if ( $ ignoreCase ) { if ( strcasecmp ( $ str1 , $ str2 ) == 0 ) { return true ; } } else { if ( strcmp ( $ str1 , $ str2 ) == 0 ) { return true ; } } return false ; } | Compare between two strings . |
45,377 | public static function join ( $ strings , $ separator , $ start = 0 , $ count = - 1 ) { $ string = '' ; $ end = $ count == - 1 ? Collection :: count ( $ strings ) : $ count ; for ( $ i = $ start ; $ i < $ end ; $ i ++ ) { $ string .= $ strings [ $ i ] . $ separator ; if ( $ i == ( $ end - 1 ) ) { $ string .= $ separator ; } } return $ string ; } | Join array element to string . |
45,378 | public static function at ( $ string , $ index ) { if ( self :: length ( $ string ) >= ( $ index + 1 ) ) { return $ string [ $ index ] ; } exception ( StringOutIndexException :: class ) ; } | Get the char at an index from a given string . |
45,379 | public static function insert ( $ string , $ substring , $ index ) { exception_if ( ! self :: checkIndex ( $ string , $ index ) , StringOutIndexException :: class ) ; $ str = '' ; for ( $ i = 0 ; $ i < static :: length ( $ string ) ; $ i ++ ) { if ( $ i == $ index ) { $ str .= $ substring ; } $ str .= $ string [ $ i ] ; } return $ str ; } | Insert a substring inside another string . |
45,380 | public static function trim ( $ string , $ side = self :: TRIM_BOTH , $ chars = null ) { if ( $ side == self :: TRIM_START ) { return ltrim ( $ string , $ chars ) ; } elseif ( $ side == self :: TRIM_END ) { return rtrim ( $ string , $ chars ) ; } elseif ( $ side == self :: TRIM_BOTH ) { return trim ( $ string , $ chars ) ; } } | Trim a string . |
45,381 | public static function startsWith ( $ string , $ substrings ) { if ( is_array ( $ substrings ) ) { foreach ( ( array ) $ substrings as $ substring ) { if ( $ substring != '' && mb_strpos ( $ string , $ substring ) === 0 ) { return true ; } } } elseif ( is_string ( $ substrings ) ) { if ( $ substrings != '' && mb_strpos ( $ string , $ substrings ) === 0 ) { return true ; } } return false ; } | Check if string starts with another string of collection of strings . |
45,382 | public static function endsWith ( $ string , $ substrings ) { if ( is_array ( $ substrings ) ) { foreach ( ( array ) $ substrings as $ substring ) { if ( ( string ) $ substring === static :: subString ( $ string , - static :: length ( $ substring ) ) ) { return true ; } } } elseif ( is_string ( $ substrings ) ) { if ( ( string ) $ substring === static :: subString ( $ string , - static :: length ( $ substring ) ) ) { return true ; } } return false ; } | Check ifstring ends with another string of collection of strings . |
45,383 | public function getSiteMap ( ) { $ sitemap = $ this -> getCacheItem ( 'site-map' ) ; if ( null === $ sitemap ) { $ menuService = $ this -> getService ( MenuService :: class ) ; $ navigation = $ menuService -> getPages ( ) ; $ argv = $ this -> prepareEventArguments ( compact ( 'navigation' ) ) ; $ this -> getEventManager ( ) -> trigger ( 'uthando.site-map' , $ this , $ argv ) ; $ sitemap = $ this -> getService ( 'ViewHelperManager' ) -> get ( Navigation :: class ) -> setRole ( 'guest' ) -> sitemap ( $ navigation ) -> render ( ) ; $ this -> setCacheItem ( 'site-map' , $ sitemap ) ; } return $ sitemap ; } | Returns a formatted xml sitemap string |
45,384 | private static function includeConfigFile ( array & $ config , $ config_file , File $ base_dir , ConfigReader $ reader ) { $ file = new File ( $ config_file , $ base_dir ) ; if ( $ file -> exists ( ) ) { $ included = self :: loadConfigFileByFormat ( $ file , $ reader ) ; $ config = array_merge_recursive ( $ config , $ included ) ; return ; } $ file = new File ( $ config_file ) ; if ( $ file -> exists ( ) ) { $ included = self :: loadConfigFileByFormat ( $ file , $ reader ) ; $ config = array_merge_recursive ( $ config , $ included ) ; return ; } throw new IncludeConfigFileNotFoundException ( $ config_file ) ; } | Include other config file |
45,385 | public function replaceAbsoluteUrls ( $ currentHost = true ) { $ hosts = array ( ) ; if ( $ currentHost === true ) { $ hosts [ ] = $ _SERVER [ "HTTP_HOST" ] ; } elseif ( is_array ( $ currentHost ) ) { foreach ( $ currentHost as $ h ) { $ hosts [ ] = $ h ; } } foreach ( $ hosts as $ h ) { $ this -> filteredHtml = preg_replace ( "/=([\"'])((http[s]?:\/\/)?" . $ h . ")/usi" , '=$1' , $ this -> filteredHtml ) ; } return $ this ; } | Replace absolute urls with relative path |
45,386 | public function hasScope ( Scope $ scope ) { foreach ( $ scope -> toArray ( ) as $ scopeToken ) { if ( ! $ this -> hasScopeToken ( $ scopeToken ) ) { return false ; } } return true ; } | Check if all scope tokens from the provided scope are in this object s scope tokens . |
45,387 | public function indexAction ( Request $ request ) { $ messages = [ ] ; $ data = [ ] ; foreach ( $ this -> get ( 'phlexible_dashboard.portlets' ) as $ portlet ) { $ data [ $ portlet -> getId ( ) ] = $ portlet -> getData ( ) ; } $ message = new \ stdClass ( ) ; $ message -> type = 'start' ; $ message -> event = 'update' ; $ message -> uid = $ this -> getUser ( ) -> getId ( ) ; $ message -> msg = null ; $ message -> data = $ data ; $ message -> objectID = null ; $ message -> ts = date ( 'Y-m-d H:i:s' ) ; $ messages [ ] = ( array ) $ message ; $ request -> getSession ( ) -> set ( 'lastPoll' , date ( 'Y-m-d H:i:s' ) ) ; return new JsonResponse ( $ messages ) ; } | Poll Action . |
45,388 | public function indexAction ( $ categoryId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'EcommerceBundle:Category' ) -> find ( $ categoryId ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Category entity.' ) ; } return array ( 'category' => $ entity , ) ; } | Lists all subcategories from a Category entity . |
45,389 | public function createAction ( Request $ request , $ categoryId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ category = $ em -> getRepository ( 'EcommerceBundle:Category' ) -> find ( $ categoryId ) ; if ( ! $ category ) { throw $ this -> createNotFoundException ( 'Unable to find Category entity.' ) ; } $ entity = new Category ( ) ; $ form = $ this -> createForm ( new SubcategoryType ( ) , $ entity ) ; $ entity -> setParentCategory ( $ category ) ; $ form -> bind ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'category.created' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_category_show' , array ( 'id' => $ entity -> getId ( ) ) ) ) ; } return array ( 'entity' => $ entity , 'category' => $ category , 'form' => $ form -> createView ( ) , ) ; } | Creates a new Category entity . |
45,390 | public function createLifestream ( $ serviceName , array $ arguments = array ( ) , array $ filters = array ( ) , array $ formatters = array ( ) ) { if ( ! array_key_exists ( $ serviceName , $ this -> services ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Service "%s" not Found. Services supported: "%s"' , $ serviceName , implode ( '", "' , $ this -> getSupportedServices ( ) ) ) ) ; } $ reflect = new \ ReflectionClass ( $ this -> services [ $ serviceName ] ) ; $ service = $ reflect -> newInstanceArgs ( $ arguments ) ; $ service -> setClient ( $ this -> client ) ; $ lifestream = new Lifestream ( $ service , $ filters , $ formatters ) ; return $ lifestream ; } | Create a Lifestream with a nammed service |
45,391 | protected function finderWrapperInject ( $ finder ) { foreach ( $ this -> wrappedMethodHistory as $ row ) { call_user_func_array ( array ( $ finder , $ row [ 'method' ] ) , $ row [ 'args' ] ) ; } } | Configure a Symfony Finder |
45,392 | public function setConfig ( $ config = array ( ) ) { if ( $ config instanceof Zend_Config ) { $ config = $ config -> toArray ( ) ; } elseif ( ! is_array ( $ config ) ) { throw new Zend_Http_Client_Adapter_Exception ( 'Array or Zend_Config object expected, got ' . gettype ( $ config ) ) ; } foreach ( $ config as $ k => $ v ) { $ this -> config [ strtolower ( $ k ) ] = $ v ; } } | Set the configuration array for the adapter |
45,393 | public function setStreamContext ( $ context ) { if ( is_resource ( $ context ) && get_resource_type ( $ context ) == 'stream-context' ) { $ this -> _context = $ context ; } elseif ( is_array ( $ context ) ) { $ this -> _context = stream_context_create ( $ context ) ; } else { throw new Zend_Http_Client_Adapter_Exception ( "Expecting either a stream context resource or array, got " . gettype ( $ context ) ) ; } return $ this ; } | Set the stream context for the TCP connection to the server |
45,394 | protected function _checkSocketReadTimeout ( ) { if ( $ this -> socket ) { $ info = stream_get_meta_data ( $ this -> socket ) ; $ timedout = $ info [ 'timed_out' ] ; if ( $ timedout ) { $ this -> close ( ) ; throw new Zend_Http_Client_Adapter_Exception ( "Read timed out after {$this->config['timeout']} seconds" , Zend_Http_Client_Adapter_Exception :: READ_TIMEOUT ) ; } } } | Check if the socket has timed out - if so close connection and throw an exception |
45,395 | public function & createButton ( $ button_class = 'Bootstrap\Button\Button' ) { $ button = $ this -> factory -> create ( $ button_class ) ; $ this -> addButton ( $ button ) ; return $ button ; } | Creates a Bootstrap button element and adds it to the buttonlist |
45,396 | public function create ( $ data ) { $ authService = $ this -> options -> getAuthenticationService ( ) ; if ( $ authService -> hasIdentity ( ) ) { $ authService -> logout ( ) ; } $ result = $ authService -> login ( $ data [ $ this -> options -> getDataUsernameKey ( ) ] , $ data [ $ this -> options -> getDataPasswordKey ( ) ] , isset ( $ data [ $ this -> options -> getDataRememberMeKey ( ) ] ) ? $ data [ $ this -> options -> getDataRememberMeKey ( ) ] : false ) ; if ( ! $ result -> isValid ( ) ) { throw new Exception \ LoginFailedException ( implode ( '. ' , $ result -> getMessages ( ) ) ) ; } $ this -> response -> getHeaders ( ) -> addHeader ( Location :: fromString ( 'Location: ' . $ this -> request -> getUri ( ) -> getPath ( ) ) ) ; return $ this -> model -> setVariables ( $ this -> options -> getSerializer ( ) -> toArray ( $ result -> getIdentity ( ) ) ) ; } | Checks the provided username and password against the AuthenticationService and returns the active user |
45,397 | protected function setComposerFile ( $ file ) { if ( null != $ file && ! is_file ( $ file ) ) { throw new FileNotFoundException ( "The file {$file} was not found." ) ; } $ this -> composerFile = $ file ; } | Sets the composer file to parse |
45,398 | protected function getComposerData ( ) { if ( null == $ this -> composerData ) { $ json = file_get_contents ( $ this -> getComposerFile ( ) ) ; $ this -> composerData = json_decode ( $ json ) ; if ( null === $ this -> composerData ) { throw new ComposerParseException ( "Error parsing file {$this->getComposerFile()}" ) ; } } return $ this -> composerData ; } | Gets the data object from json file |
45,399 | protected function getAuthor ( ) { if ( ! isset ( $ this -> getComposerData ( ) -> authors ) || count ( $ this -> getComposerData ( ) -> authors ) != 1 ) { return $ this -> requestAuthor ( ) ; } return [ 'authorName' => $ this -> getComposerData ( ) -> authors [ 0 ] -> name , 'authorEmail' => $ this -> getComposerData ( ) -> authors [ 0 ] -> email ] ; } | Gets the author name and e - mail |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.