idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
47,100 | public function parseSection ( $ name , array $ section ) { $ name = explode ( ':' , $ name , 2 ) ; $ class = $ this -> findSection ( $ name [ 0 ] ) ; if ( isset ( $ name [ 1 ] ) ) { return new $ class ( $ name [ 1 ] , $ section ) ; } return new $ class ( $ section ) ; } | Parses an individual section |
47,101 | public static function save ( $ file , $ config ) { if ( ! is_array ( $ config ) ) { if ( ! isset ( static :: $ items [ $ config ] ) ) { return false ; } $ config = static :: $ items [ $ config ] ; } $ info = pathinfo ( $ file ) ; $ type = 'php' ; if ( isset ( $ info [ 'extension' ] ) ) { $ type = $ info [ 'extension' ] ; if ( $ file [ 0 ] !== '/' and $ file [ 1 ] !== ':' ) { $ file = substr ( $ file , 0 , - ( strlen ( $ type ) + 1 ) ) ; } } $ class = '\\Config_' . ucfirst ( $ type ) ; if ( ! class_exists ( $ class ) ) { throw new \ FuelException ( sprintf ( 'Invalid config type "%s".' , $ type ) ) ; } $ driver = new $ class ( $ file ) ; return $ driver -> save ( $ config ) ; } | Save a config array to disc . |
47,102 | public static function renderError ( ) { try { $ _errorTemplate = \ Kisma :: get ( 'app.error_template' , '_error.twig' ) ; Render :: twigView ( $ _errorTemplate , array ( 'base_path' => \ Kisma :: get ( 'app.base_path' ) , 'app_root' => \ Kisma :: get ( 'app.root' ) , 'page_title' => 'Error' , 'error' => static :: $ _error , 'page_header' => 'Something has gone awry...' , 'page_header_small' => 'Not cool. :(' , 'navbar' => array ( 'brand' => 'Kisma v' . \ Kisma :: KismaVersion , 'items' => array ( array ( 'title' => 'Kisma on GitHub!' , 'href' => 'http://github.com/kisma/kisma/' , 'target' => '_blank' , 'active' => 'active' , ) , ) , ) , ) ) ; return true ; } catch ( \ Exception $ _ex ) { Log :: error ( 'Exception during rendering of error: ' . print_r ( static :: $ _error , true ) ) ; } return false ; } | Renders an error |
47,103 | protected static function _cleanTrace ( array & $ trace , $ skipLines = null , $ basePath = null ) { $ _trace = array ( ) ; $ _basePath = $ basePath ? : \ Kisma :: get ( 'app.base_path' ) ; if ( ! empty ( $ skipLines ) && count ( $ trace ) > $ skipLines ) { $ trace = array_slice ( $ trace , $ skipLines ) ; } foreach ( $ trace as $ _index => $ _code ) { $ _traceItem = array ( ) ; Scalar :: sins ( $ trace [ $ _index ] , 'file' , 'Unspecified' ) ; Scalar :: sins ( $ trace [ $ _index ] , 'line' , 0 ) ; Scalar :: sins ( $ trace [ $ _index ] , 'function' , 'Unspecified' ) ; $ _traceItem [ 'file_name' ] = trim ( str_replace ( array ( $ _basePath , "\t" , "\r" , "\n" , PHP_EOL , 'phar://' , ) , array ( null , ' ' , null , null , null , null , ) , $ trace [ $ _index ] [ 'file' ] ) ) ; $ _args = null ; if ( isset ( $ _code [ 'args' ] ) && ! empty ( $ _code [ 'args' ] ) ) { foreach ( $ _code [ 'args' ] as $ _arg ) { if ( is_object ( $ _arg ) ) { $ _args .= get_class ( $ _arg ) . ', ' ; } else if ( is_array ( $ _arg ) ) { $ _args .= '[array], ' ; } else if ( is_bool ( $ _arg ) ) { if ( $ _arg ) { $ _args .= 'true, ' ; } else { $ _args .= 'false, ' ; } } else if ( is_numeric ( $ _arg ) ) { $ _args .= $ _arg . ', ' ; } else if ( is_scalar ( $ _arg ) ) { $ _args .= '"' . $ _arg . '", ' ; } else { $ _args .= '"' . gettype ( $ _arg ) . '", ' ; } } } $ _traceItem [ 'line' ] = $ trace [ $ _index ] [ 'line' ] ; if ( isset ( $ _code [ 'type' ] ) ) { $ _traceItem [ 'function' ] = ( isset ( $ _code [ 'class' ] ) ? $ _code [ 'class' ] : null ) . $ _code [ 'type' ] . $ _code [ 'function' ] ; } else { $ _traceItem [ 'function' ] = $ _code [ 'function' ] ; } $ _traceItem [ 'function' ] .= '(' . ( $ _args ? ' ' . trim ( $ _args , ', ' ) . ' ' : null ) . ')' ; $ _traceItem [ 'index' ] = $ _index ; $ _trace [ ] = $ _traceItem ; } return $ _trace ; } | Cleans up a trace array |
47,104 | protected function checkPreparation ( ) { if ( null === $ this -> prepared ) { throw new RuntimeException ( Message :: get ( Message :: DB_STMT_NOTPREPARED ) , Message :: DB_STMT_NOTPREPARED ) ; } $ this -> closeResult ( ) ; } | Throw exception if not prepared |
47,105 | private function loadItemOrThrowException ( QueryBuildingEventInterface $ event , string $ eventName , EventDispatcherInterface $ dispatcher ) { $ queryResult = $ this -> executeItemQuery ( $ event , $ eventName , $ dispatcher ) ; if ( empty ( $ queryResult ) && $ this -> noItemException ) { $ this -> logger -> notice ( 'Item not found from loader' , [ 'loader class' => static :: class , 'from event' => $ eventName , 'dispatched event' => $ this -> itemEventName ] ) ; throw new \ RuntimeException ( 'Item not found from loader' , 404 ) ; } return $ queryResult ; } | Load item or throw exception |
47,106 | public function createUri ( $ page ) { $ queryString = $ this -> query ; $ queryString [ ] = "page={$page}" ; $ queryString = implode ( '&' , $ queryString ) ; return Request :: pathInfo ( ) . "?{$queryString}" ; } | Creates the URI for the specified page . |
47,107 | protected function createPageLinks ( ) { $ pageLinks = array ( ) ; if ( $ this -> totalPages > 10 ) { $ startRange = $ this -> page - floor ( $ this -> range / 2 ) ; $ endRange = $ this -> page + floor ( $ this -> range / 2 ) ; if ( $ startRange <= 0 ) { $ startRange = 1 ; $ endRange += abs ( $ startRange ) + 1 ; } if ( $ endRange > $ this -> totalPages ) { $ startRange -= $ endRange - $ this -> totalPages ; $ endRange = $ this -> totalPages ; } $ range = range ( $ startRange , $ endRange ) ; $ this -> pageLinks [ ] = array ( 'page' => 1 , 'uri' => $ this -> createUri ( 1 ) ) ; foreach ( $ range as $ page ) { if ( $ page == 1 or $ page == $ this -> totalPages ) { continue ; } $ this -> pageLinks [ ] = array ( 'page' => $ page , 'uri' => $ this -> createUri ( $ page ) ) ; } $ this -> pageLinks [ ] = array ( 'page' => $ this -> totalPages , 'uri' => $ this -> createUri ( $ this -> totalPages ) ) ; } else { for ( $ i = 1 ; $ i <= $ this -> totalPages ; $ i ++ ) { $ this -> pageLinks [ ] = array ( 'page' => $ i , 'uri' => $ this -> createUri ( $ i ) ) ; } } } | Creates the page links . |
47,108 | public static function fromObject ( $ object , $ rootName = null , $ nodeName = null , $ addHeader = true ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( 'The value of "$object" is not an object.' ) ; } return static :: fromArray ( get_object_vars ( $ object ) , $ rootName , $ nodeName , $ addHeader ) ; } | Converts an object to an XML string |
47,109 | public static function fromArray ( $ data , $ rootName = null , $ nodeName = null , $ addHeader = true ) { $ _xml = true === $ addHeader ? '<?xml version="1.0" encoding="UTF-8" ?>' : null ; if ( null !== $ rootName ) { $ _xml .= Markup :: openTag ( $ rootName ) ; } $ _string = null ; if ( $ data instanceof \ Traversable ) { foreach ( $ data as $ _key => $ _value ) { if ( is_numeric ( $ _key ) ) { $ _key = $ nodeName ? : 'node' ; } $ _string .= Markup :: tag ( $ _key , array ( ) , static :: fromArray ( $ _value , $ nodeName ) ) ; } } else { $ _string = htmlspecialchars ( $ data , ENT_QUOTES ) ; } $ _xml .= $ _string ; if ( null !== $ rootName ) { $ _xml .= Markup :: closeTag ( $ rootName ) ; } return $ _xml ; } | Converts an array to an XML string |
47,110 | public static function & createWithName ( $ name = null , AuraSession $ session = null ) : Session { $ session = ! is_null ( $ session ) ? new static : new static ( $ session ) ; if ( is_null ( $ name ) ) { return $ session ; } $ session -> setSegmentName ( $ name ) ; return $ session ; } | Create Instance Session |
47,111 | public function startOrResume ( ) : bool { if ( ! $ this -> session -> isStarted ( ) ) { return $ this -> session -> start ( ) ; } return $ this -> session -> resume ( ) ; } | Start Or Resume Session |
47,112 | public function validateToken ( $ value ) : bool { if ( ! is_string ( $ value ) ) { return false ; } return $ this -> getCSRFToken ( ) -> isValid ( $ value ) ; } | validate token set |
47,113 | public function exist ( $ keyName ) : bool { return $ this -> get ( $ keyName , true ) !== true && $ this -> get ( $ keyName , false ) !== false ; } | Check whether Session is exists or not on segment |
47,114 | public function required ( $ keys , array $ params = [ ] , array $ parents = [ ] ) { if ( ! $ params ) { $ params = $ this -> all ( ) ; } if ( is_array ( $ keys ) ) { foreach ( $ keys as $ key => $ value ) { if ( is_int ( $ key ) ) { $ key = $ value ; } if ( ! isset ( $ params [ $ key ] ) ) { if ( $ parents ) { $ str = '' ; foreach ( $ parents as $ parent ) { $ str .= '[ ' . $ parent . ' => ' ; } $ str .= $ key . str_repeat ( ' ]' , count ( $ parents ) ) ; } else { $ str = $ Key ; } throw new ParameterMissingException ( sprintf ( "Missing parameter %s" , $ str ) ) ; } if ( is_array ( $ value ) ) { $ params = $ params [ $ key ] ; $ parents [ ] = $ key ; $ this -> required ( $ value , $ params , $ parents ) ; } } } else { if ( ! isset ( $ params [ $ keys ] ) ) { throw new ParameterMissingException ( sprintf ( "Missing parameter %s" , $ keys ) ) ; } } } | Checks for required parameters . If one of them is null ParameterMissingException is thrown . |
47,115 | public function set ( string $ name , RequestCookieInterface $ requestCookie ) : void { $ this -> requestCookies [ $ name ] = $ requestCookie ; } | Sets a request cookie by name . |
47,116 | public function make ( $ name , $ options ) { if ( ! $ name || ! is_string ( $ name ) ) { return null ; } if ( isset ( $ this -> objTemplates [ $ name ] ) ) { return clone $ this -> objTemplates [ $ name ] ; } if ( ! $ this -> namespaceTransformer ) { $ this -> namespaceTransformer = $ this -> objTemplates [ self :: NAMESPACE_TRANSFORMER ] = new PrependNamespace ( ) ; } $ className = $ this -> namespaceTransformer -> transform ( $ name , [ 'namespace' => __NAMESPACE__ ] ) ; if ( ! class_exists ( $ className , true ) ) { return null ; } $ this -> objTemplates [ $ name ] = new $ className ( ) ; return clone $ this -> objTemplates [ $ name ] ; } | the name is expected to prepend the subnamespace string or time or something similar - > otherwise a config based mapping would be required |
47,117 | protected function setDefaultAttributes ( ) { if ( ! empty ( $ this -> attributes ) ) { foreach ( $ this -> attributes as $ attr => $ val ) { $ this -> realSetAttribute ( $ attr , $ val ) ; } } } | Set default attributes |
47,118 | protected function doAdd ( $ object ) { $ this -> notifyAccess ( ) ; $ this -> objectsArray [ $ this -> total ] = $ object ; $ this -> total ++ ; } | leave the type checking of the arg to the concrete subclasses - to avoid being forced to create an DomainEntityAbstract if i don t want to |
47,119 | public function countVideos ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collVideosPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collVideos || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collVideos ) { return 0 ; } if ( $ partial && ! $ criteria ) { return count ( $ this -> getVideos ( ) ) ; } $ query = ChildVideoQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByReference ( $ this ) -> count ( $ con ) ; } return count ( $ this -> collVideos ) ; } | Returns the number of related Video objects . |
47,120 | public function getSkillReferences ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collSkillReferencesPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collSkillReferences || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collSkillReferences ) { $ this -> initSkillReferences ( ) ; } else { $ collSkillReferences = ChildSkillReferenceQuery :: create ( null , $ criteria ) -> filterByReference ( $ this ) -> find ( $ con ) ; if ( null !== $ criteria ) { if ( false !== $ this -> collSkillReferencesPartial && count ( $ collSkillReferences ) ) { $ this -> initSkillReferences ( false ) ; foreach ( $ collSkillReferences as $ obj ) { if ( false == $ this -> collSkillReferences -> contains ( $ obj ) ) { $ this -> collSkillReferences -> append ( $ obj ) ; } } $ this -> collSkillReferencesPartial = true ; } return $ collSkillReferences ; } if ( $ partial && $ this -> collSkillReferences ) { foreach ( $ this -> collSkillReferences as $ obj ) { if ( $ obj -> isNew ( ) ) { $ collSkillReferences [ ] = $ obj ; } } } $ this -> collSkillReferences = $ collSkillReferences ; $ this -> collSkillReferencesPartial = false ; } } return $ this -> collSkillReferences ; } | Gets an array of ChildSkillReference objects which contain a foreign key that references this object . |
47,121 | public function getSkillReferencesJoinSkill ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildSkillReferenceQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'Skill' , $ joinBehavior ) ; return $ this -> getSkillReferences ( $ query , $ con ) ; } | If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this Reference is new it will return an empty collection ; or if this Reference has previously been saved it will retrieve related SkillReferences from storage . |
47,122 | public function getSkills ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collSkillsPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collSkills || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) ) { if ( null === $ this -> collSkills ) { $ this -> initSkills ( ) ; } } else { $ query = ChildSkillQuery :: create ( null , $ criteria ) -> filterByReference ( $ this ) ; $ collSkills = $ query -> find ( $ con ) ; if ( null !== $ criteria ) { return $ collSkills ; } if ( $ partial && $ this -> collSkills ) { foreach ( $ this -> collSkills as $ obj ) { if ( ! $ collSkills -> contains ( $ obj ) ) { $ collSkills [ ] = $ obj ; } } } $ this -> collSkills = $ collSkills ; $ this -> collSkillsPartial = false ; } } return $ this -> collSkills ; } | Gets a collection of ChildSkill objects related by a many - to - many relationship to the current object by way of the kk_trixionary_skill_reference cross - reference table . |
47,123 | public function removeSkill ( ChildSkill $ skill ) { if ( $ this -> getSkills ( ) -> contains ( $ skill ) ) { $ skillReference = new ChildSkillReference ( ) ; $ skillReference -> setSkill ( $ skill ) ; if ( $ skill -> isReferencesLoaded ( ) ) { $ skill -> getReferences ( ) -> removeObject ( $ this ) ; } $ skillReference -> setReference ( $ this ) ; $ this -> removeSkillReference ( clone $ skillReference ) ; $ skillReference -> clear ( ) ; $ this -> collSkills -> remove ( $ this -> collSkills -> search ( $ skill ) ) ; if ( null === $ this -> skillsScheduledForDeletion ) { $ this -> skillsScheduledForDeletion = clone $ this -> collSkills ; $ this -> skillsScheduledForDeletion -> clear ( ) ; } $ this -> skillsScheduledForDeletion -> push ( $ skill ) ; } return $ this ; } | Remove skill of this object through the kk_trixionary_skill_reference cross reference table . |
47,124 | public function search ( $ key ) { $ binarySearch = new BinarySearch ( $ this ) ; $ result = $ binarySearch -> search ( $ key ) ; if ( \ is_null ( $ result ) || $ result -> getKey ( ) != $ key ) { return null ; } return $ result ; } | Searches for the container with that key |
47,125 | public function searchRange ( Range $ range ) { $ iterator = $ this -> getIterator ( ) ; $ start = null ; $ binarySearch = new BinarySearch ( $ this ) ; $ startHint = $ binarySearch -> search ( $ range -> getMin ( ) ) ; if ( $ startHint == null ) { return new RangeIterator ( $ iterator , Range :: getEmptyRange ( ) ) ; } $ iterator -> setOffset ( $ startHint -> getOffset ( ) , Parser :: HINT_RESULT_BOUNDARY ) ; if ( ! $ range -> contains ( $ startHint -> getKey ( ) ) && $ startHint -> getKey ( ) <= $ range -> getMin ( ) ) { foreach ( $ iterator as $ result ) { if ( $ range -> contains ( $ result -> getKey ( ) ) ) { $ start = $ result ; break ; } } } else { if ( $ range -> contains ( $ startHint -> getKey ( ) ) ) { $ start = $ startHint ; } $ iterator -> setDirection ( KeyReader :: DIRECTION_BACKWARD ) ; foreach ( $ iterator as $ result ) { if ( ! $ range -> contains ( $ result -> getKey ( ) && $ result -> getKey ( ) >= $ range -> getMax ( ) ) ) { continue ; } if ( $ range -> contains ( $ result -> getKey ( ) ) ) { $ start = $ result ; } else { break ; } } } if ( is_null ( $ start ) ) { return new RangeIterator ( $ iterator , Range :: getEmptyRange ( ) ) ; } $ iterator = $ this -> getIterator ( ) ; $ iterator -> setOffset ( $ start -> getOffset ( ) , Parser :: HINT_RESULT_BOUNDARY ) ; return new RangeIterator ( $ iterator , $ range ) ; } | Searches a range |
47,126 | public function get ( $ property , $ default = null ) { if ( ! $ this -> has ( $ property ) ) { return $ default ; } return null !== $ this -> data [ $ property ] ? $ this -> data [ $ property ] : $ default ; } | Get property of the object |
47,127 | public function copyfrom ( $ var , $ func = NULL ) { if ( is_string ( $ var ) ) { $ var = Base :: instance ( ) -> get ( $ var ) ; } if ( $ func ) { $ var = call_user_func ( $ func , $ var ) ; } foreach ( $ var as $ key => $ val ) { if ( array_key_exists ( $ key , $ this -> fields ) || array_key_exists ( $ key , $ this -> extras ) ) { $ this -> set ( $ key , $ val ) ; } } } | Override parent method to accept custom property assigment |
47,128 | public function parse ( $ param_str ) { $ file = new File ( trim ( $ param_str ) , $ this -> getScope ( ) -> getFile ( ) -> getAbsoluteFile ( ) -> getParent ( ) ) ; if ( ! $ file -> exists ( ) ) { throw new ResourceNotFoundException ( $ param_str , $ this -> getScope ( ) , $ this -> getOccursPos ( ) , "The Requirement File Not Exists" ) ; } if ( is_null ( $ require_resource = $ this -> getParentProject ( ) -> getResourceByFile ( $ file ) ) ) { throw new \ Chigi \ Chiji \ Exception \ ProjectMemberNotFoundException ( "ERROR: UNREGISTERED Resource File: " + $ file -> getAbsolutePath ( ) ) ; } if ( $ this -> getScope ( ) instanceof RequiresMapInterface ) { $ this -> getScope ( ) -> getRequires ( ) -> addResource ( $ require_resource ) ; } } | Parse the path param in the require annotation to an Resource File Object . |
47,129 | public function compare ( $ old , $ new , $ mode = 'normal' ) { if ( $ mode === 'mixed' ) { $ ins_begin = '<ins>+ ' ; $ ins_end = '</ins>' . PHP_EOL ; $ del_begin = '<del>- ' ; $ del_end = '</del>' . PHP_EOL ; } elseif ( $ mode === 'html' ) { $ ins_begin = '<ins>' ; $ ins_end = '</ins>' . PHP_EOL ; $ del_begin = '<del>' ; $ del_end = '</del>' . PHP_EOL ; } else { $ ins_begin = '+ ' ; $ ins_end = PHP_EOL ; $ del_begin = '- ' ; $ del_end = PHP_EOL ; } $ diff = $ this -> diff ( explode ( PHP_EOL , $ old ) , explode ( PHP_EOL , $ new ) ) ; $ result = '' ; if ( $ mode == 'raw' ) return $ diff ; foreach ( $ diff as $ line ) { if ( is_array ( $ line ) ) { $ result .= ! empty ( $ line [ 'del' ] ) ? $ del_begin . implode ( PHP_EOL , $ line [ 'del' ] ) . $ del_end : '' ; $ result .= ! empty ( $ line [ 'ins' ] ) ? $ ins_begin . implode ( PHP_EOL , $ line [ 'ins' ] ) . $ ins_end : '' ; } else { $ result .= $ line . PHP_EOL ; } } return $ result ; } | Compare two strings and return the difference |
47,130 | private function diff ( $ old , $ new ) { $ maxlen = 0 ; foreach ( $ old as $ old_line => $ old_value ) { $ new_lines = array_keys ( $ new , $ old_value ) ; foreach ( $ new_lines as $ new_line ) { $ matrix [ $ old_line ] [ $ new_line ] = isset ( $ matrix [ $ old_line - 1 ] [ $ new_line - 1 ] ) ? $ matrix [ $ old_line - 1 ] [ $ new_line - 1 ] + 1 : 1 ; if ( $ matrix [ $ old_line ] [ $ new_line ] > $ maxlen ) { $ maxlen = $ matrix [ $ old_line ] [ $ new_line ] ; $ old_max = $ old_line + 1 - $ maxlen ; $ new_max = $ new_line + 1 - $ maxlen ; } } } if ( $ maxlen == 0 ) { return array ( array ( 'del' => $ old , 'ins' => $ new ) ) ; } return array_merge ( self :: diff ( array_slice ( $ old , 0 , $ old_max ) , array_slice ( $ new , 0 , $ new_max ) ) , array_slice ( $ new , $ new_max , $ maxlen ) , self :: diff ( array_slice ( $ old , $ old_max + $ maxlen ) , array_slice ( $ new , $ new_max + $ maxlen ) ) ) ; } | Diff function . Contributed by Dan Horrigan who again took it from Paul Butler . |
47,131 | public function getRoughDistance ( $ clientLng , $ clientLat , $ poiLng , $ poiLat ) { $ result = abs ( $ clientLng - $ poiLng ) + abs ( $ clientLat - $ poiLat ) ; $ this -> BackyardError -> log ( 5 , "client({$clientLng}, {$clientLat}) poi({$poiLng}, {$poiLat}) roughDistance = {$result}" ) ; return $ result ; } | 1 ~ 100km |
47,132 | public function register ( ) { $ this -> registerSubProviders ( collect ( $ this -> subProviders ) ) ; $ this -> registerBindings ( collect ( $ this -> bindings ) ) ; $ this -> registerMigrations ( collect ( $ this -> migrations ) ) ; $ this -> registerSeeders ( collect ( $ this -> seeders ) ) ; $ this -> registerFactories ( collect ( $ this -> factories ) ) ; } | Register the current Domain . |
47,133 | protected function registerSubProviders ( Collection $ subProviders ) { $ subProviders -> each ( function ( $ provider ) { $ this -> app -> register ( $ provider ) ; } ) ; } | Register domain sub providers . |
47,134 | protected function registerBindings ( Collection $ bindings ) { $ bindings -> each ( function ( $ concretion , $ abstraction ) { $ this -> app -> bind ( $ abstraction , $ concretion ) ; } ) ; } | Register the defined domain bindings . |
47,135 | public function getKinesisClient ( $ type ) { if ( ! empty ( $ this -> clients [ $ type ] ) ) { return $ this -> clients [ $ type ] ; } $ config = [ 'version' => $ this -> config [ 'api_version' ] , 'region' => $ this -> config [ 'region' ] , ] ; $ config [ 'credentials' ] = [ 'key' => $ this -> config [ $ type ] [ 'key' ] , 'secret' => $ this -> config [ $ type ] [ 'secret' ] , ] ; $ sdk = new Sdk ( ) ; $ this -> clients [ $ type ] = $ sdk -> createKinesis ( $ config ) ; return $ this -> clients [ $ type ] ; } | Gets the Kinesis client . |
47,136 | public function preDispatch ( MvcEvent $ e ) { if ( $ this -> zfcUserAuthentication ( ) -> hasIdentity ( ) ) { $ userName = $ this -> zfcUserAuthentication ( ) -> getIdentity ( ) -> getUsername ( ) ; } else { $ userName = 'anonymous' ; } $ this -> layout ( ) -> setVariable ( 'dataTypes' , $ this -> getDataTypesHandler ( ) -> getDataTypes ( ) ) ; $ this -> layout ( ) -> setVariable ( 'userName' , $ userName ) ; $ this -> layout ( ) -> setVariable ( 'action' , $ this -> params ( 'action' ) ) ; $ this -> layout ( ) -> setVariable ( 'authService' , $ this -> getFileAuthService ( ) ) ; $ this -> layout ( ) -> setVariable ( 'jqueryUiTheme' , $ this -> getJqueryUiTheme ( ) ) ; $ controller = $ this -> params ( 'controller' ) ; $ controller = explode ( '\\' , $ controller ) ; $ controller = array_pop ( $ controller ) ; $ controller = strtolower ( $ controller ) ; $ this -> layout ( ) -> setVariable ( 'controller' , $ controller ) ; } | Avant l action |
47,137 | public function isDirty ( ) { if ( count ( $ this ) != $ this -> _original ) { return true ; } if ( count ( $ this -> _deleted ) ) { return true ; } foreach ( $ this as $ model ) { if ( is_object ( $ model ) && ( $ model -> isDirty ( ) || $ model -> isNew ( ) ) ) { return true ; } } return false ; } | Check if the collection is dirty i . e . its contents have changed since the last save . |
47,138 | public function markClean ( ) { foreach ( $ this as $ model ) { if ( is_object ( $ model ) ) { $ model -> markClean ( ) ; } } $ this -> _original = count ( $ this ) ; } | Mark the collection as clean i . e . in pristine state . |
47,139 | public function jsonSerialize ( ) { $ out = [ ] ; foreach ( $ this as $ model ) { if ( ! is_object ( $ model ) ) { continue ; } if ( $ model instanceof JsonSerializable ) { $ out [ ] = $ model -> jsonSerialize ( ) ; } else { $ out [ ] = ( object ) ( array ) $ model ; } } return $ out ; } | Export the Collection as a regular PHP array for Json serialization . |
47,140 | public function get ( $ key , $ default = null ) { if ( ! is_string ( $ key ) || empty ( $ key ) ) { return $ default ; } $ item_pieces = explode ( '.' , $ key ) ; return igorw \ get_in ( $ this -> data , $ item_pieces , $ default ) ; } | Gets item from array if it exists else return default value |
47,141 | protected static function execute ( $ seeder ) { $ data = self :: fill ( $ seeder ) ; $ table = new DBTable ( $ seeder -> table ) ; return $ table -> insert ( $ data ) ; } | Execute thh seeder . |
47,142 | public static function fill ( $ seeder ) { $ data = [ ] ; if ( $ seeder -> count <= 0 ) { foreach ( $ seeder -> data ( ) as $ value ) { array_push ( $ data , $ value ) ; } } else { for ( $ i = 0 ; $ i < $ seeder -> count ; $ i ++ ) { array_push ( $ data , $ seeder -> data ( ) ) ; } } return $ data ; } | Fill data . |
47,143 | public function request ( Request $ request ) { $ user = User :: whereEmail ( $ request -> email ) -> firstOrFail ( ) ; $ user -> sendResetPasswordNotification ( $ this -> broker ( ) -> createToken ( $ user ) , $ request ) ; return response ( ) -> json ( 'Password request successful' , 200 ) ; } | Send an email to the registered email address with a reset password link |
47,144 | public function createNew ( string $ attribute , string $ name , float $ value ) : array { return $ this -> sendPost ( sprintf ( '/profiles/%s/scores' , $ this -> userName ) , [ ] , [ 'attribute' => $ attribute , 'name' => $ name , 'value' => $ value ] ) ; } | Creates a new score for the given source . |
47,145 | public function upsertOne ( string $ attribute , string $ name , float $ value ) : array { return $ this -> sendPut ( sprintf ( '/profiles/%s/scores' , $ this -> userName ) , [ ] , [ 'attribute' => $ attribute , 'name' => $ name , 'value' => $ value ] ) ; } | Tries to update a score and if it doesnt exists creates a new score . |
47,146 | public function updateOne ( string $ attribute , string $ name , float $ value ) : array { return $ this -> sendPatch ( sprintf ( '/profiles/%s/scores/%s' , $ this -> userName , $ name ) , [ ] , [ 'attribute' => $ attribute , 'value' => $ value ] ) ; } | Updates a score in the given profile . |
47,147 | public function all ( ) { foreach ( $ this -> tasks as $ task => $ option ) { $ task = $ this -> taskClassname ( $ task ) ; $ this -> $ task -> all ( ) ; } } | Execute all tasks |
47,148 | public function make ( $ name = "default" , $ width = 100 , $ height = 100 , $ bgcolor = 0xFFFFFF ) { $ bstall = new Bstall ; $ this -> width = $ width ; $ this -> height = $ height ; $ this -> bgcolor = $ bgcolor ; $ this -> load ( $ name ) ; return View :: make ( 'bstall::canvas' , [ 'name' => $ name , 'width' => $ this -> width , 'height' => $ this -> height , 'canvas' => json_encode ( $ this -> canvas , true ) ] ) ; } | Print stall s canvas |
47,149 | public function load ( $ name ) { $ stall = $ this -> redis -> get ( "bstall_{$name}" ) ; if ( is_null ( $ stall ) ) { $ this -> clean ( ) ; $ this -> save ( $ name ) ; } else { $ canvas = unserialize ( $ stall ) ; $ this -> canvas = $ canvas ; } } | Load or initialize a stall |
47,150 | public function clean ( ) { $ this -> canvas = [ ] ; for ( $ y = 0 ; $ y < $ this -> height ; $ y ++ ) { array_push ( $ this -> canvas , [ ] ) ; for ( $ x = 0 ; $ x < $ this -> width ; $ x ++ ) { $ this -> canvas [ $ y ] [ $ x ] = $ this -> bgcolor ; } } } | Cleans the stall replacing each pixel with the set background color |
47,151 | public function write ( $ x , $ y , $ color ) { if ( isset ( $ this -> canvas [ $ y ] [ $ x ] ) ) { $ this -> canvas [ $ y ] [ $ x ] = $ color ; } } | Scribble onto the stall |
47,152 | public static function parent ( ) { if ( ! self :: $ activeTraitMethod ) { throw new \ BadMethodCallException ( "next:parent() call is only allowed in trait calls" ) ; } $ arguments = func_get_args ( ) ; return call_user_func ( self :: $ activeTraitMethod , $ arguments ) ; } | Allows call to parent trait method if it got overwritten |
47,153 | public function importArticleStatistics ( ) { $ pendingImports = $ this -> em -> getRepository ( 'ImportBundle:PendingStatisticImport' ) -> findAll ( ) ; $ this -> consoleOutput -> writeln ( "Importing article statistics..." ) ; foreach ( $ pendingImports as $ import ) { $ this -> importArticleStatistic ( $ import -> getOldId ( ) , $ import -> getArticle ( ) -> getId ( ) ) ; $ this -> em -> remove ( $ import ) ; $ this -> em -> flush ( $ import ) ; } } | Imports article statistics whose import are pending . |
47,154 | public function importArticleStatistic ( $ oldId , $ newId ) { $ article = $ this -> em -> getRepository ( 'VipaJournalBundle:Article' ) -> find ( $ newId ) ; if ( ! $ article ) { $ this -> consoleOutput -> writeln ( "Couldn't find #" . $ newId . " on the new database." ) ; return ; } $ this -> consoleOutput -> writeln ( "Reading view statistics for #" . $ oldId . "..." ) ; $ viewStatsSql = "SELECT DATE(view_time) AS date, COUNT(*) as view FROM " . "article_view_stats WHERE article_id = :id GROUP BY DATE(view_time)" ; $ viewStatsStatement = $ this -> dbalConnection -> prepare ( $ viewStatsSql ) ; $ viewStatsStatement -> bindValue ( 'id' , $ oldId ) ; $ viewStatsStatement -> execute ( ) ; $ this -> consoleOutput -> writeln ( "Reading download statistics for #" . $ oldId . "..." ) ; $ downloadStatsSql = "SELECT DATE(download_time) AS date, COUNT(*) as download FROM " . "article_download_stats WHERE article_id = :id GROUP BY DATE(download_time)" ; $ downloadStatsStatement = $ this -> dbalConnection -> prepare ( $ downloadStatsSql ) ; $ downloadStatsStatement -> bindValue ( 'id' , $ oldId ) ; $ downloadStatsStatement -> execute ( ) ; $ pkpViewStats = $ viewStatsStatement -> fetchAll ( ) ; $ pkpDownloadStats = $ downloadStatsStatement -> fetchAll ( ) ; foreach ( $ pkpViewStats as $ stat ) { $ articleFileStatistic = new ArticleStatistic ( ) ; $ articleFileStatistic -> setArticle ( $ article ) ; $ articleFileStatistic -> setDate ( DateTime :: createFromFormat ( 'Y-m-d' , $ stat [ 'date' ] ) ) ; $ articleFileStatistic -> setView ( $ stat [ 'view' ] ) ; $ this -> em -> persist ( $ articleFileStatistic ) ; } if ( ! $ article -> getArticleFiles ( ) -> isEmpty ( ) ) { foreach ( $ pkpDownloadStats as $ stat ) { $ articleFileStatistic = new ArticleFileStatistic ( ) ; $ articleFileStatistic -> setArticleFile ( $ article -> getArticleFiles ( ) -> first ( ) ) ; $ articleFileStatistic -> setDate ( DateTime :: createFromFormat ( 'Y-m-d' , $ stat [ 'date' ] ) ) ; $ articleFileStatistic -> setDownload ( $ stat [ 'download' ] ) ; $ this -> em -> persist ( $ articleFileStatistic ) ; } } $ this -> em -> flush ( ) ; } | Imports the given article s statistics |
47,155 | public function getFeed ( $ location , $ className = 'Zend_Gdata_Feed' ) { if ( is_string ( $ location ) ) { $ uri = $ location ; } elseif ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( ) ; } else { require_once 'Zend/Gdata/App/InvalidArgumentException.php' ; throw new Zend_Gdata_App_InvalidArgumentException ( 'You must specify the location as either a string URI ' . 'or a child of Zend_Gdata_Query' ) ; } return parent :: getFeed ( $ uri , $ className ) ; } | Retrieve feed as string or object |
47,156 | public function performHttpRequest ( $ method , $ url , $ headers = array ( ) , $ body = null , $ contentType = null , $ remainingRedirects = null ) { if ( $ this -> _httpClient instanceof Zend_Gdata_HttpClient ) { $ filterResult = $ this -> _httpClient -> filterHttpRequest ( $ method , $ url , $ headers , $ body , $ contentType ) ; $ method = $ filterResult [ 'method' ] ; $ url = $ filterResult [ 'url' ] ; $ body = $ filterResult [ 'body' ] ; $ headers = $ filterResult [ 'headers' ] ; $ contentType = $ filterResult [ 'contentType' ] ; return $ this -> _httpClient -> filterHttpResponse ( parent :: performHttpRequest ( $ method , $ url , $ headers , $ body , $ contentType , $ remainingRedirects ) ) ; } else { return parent :: performHttpRequest ( $ method , $ url , $ headers , $ body , $ contentType , $ remainingRedirects ) ; } } | Performs a HTTP request using the specified method . |
47,157 | public function isAuthenticated ( ) { $ client = parent :: getHttpClient ( ) ; if ( $ client -> getClientLoginToken ( ) || $ client -> getAuthSubToken ( ) ) { return true ; } return false ; } | Determines whether service object is authenticated . |
47,158 | public function renderTree ( $ pages , $ closedPages , $ langId , $ level = null ) { if ( empty ( $ pages ) ) { $ newPageLink = $ this -> Html -> link ( __d ( 'wasabi_cms' , 'Please add your first Page' ) , [ 'plugin' => 'Wasabi/Cms' , 'controller' => 'Pages' , 'action' => 'add' ] , [ 'title' => __d ( 'wasabi_cms' , 'Add your first Page' ) ] ) ; return '<li class="center">' . __d ( 'wasabi_cms' , 'There are no pages yet. {0}.' , $ newPageLink ) . '</li>' ; } $ output = '' ; $ depth = ( $ level !== null ) ? $ level : 1 ; foreach ( $ pages as $ page ) { $ closed = false ; $ classes = [ 'page' ] ; if ( in_array ( $ page -> id , $ closedPages ) ) { $ closed = true ; $ classes [ ] = 'closed' ; } $ pageRow = $ this -> _View -> element ( 'Wasabi/Cms.../Pages/__page-row' , [ 'page' => $ page , 'closed' => $ closed , 'langId' => $ langId ] ) ; if ( ! empty ( $ page -> children ) ) { $ pageRow .= '<ul' . ( $ closed ? ' style="display: none;"' : '' ) . '>' . $ this -> renderTree ( $ page -> children , $ closedPages , $ langId , $ depth + 1 ) . '</ul>' ; } else { $ classes [ ] = 'no-children' ; } $ output .= '<li class="' . join ( ' ' , $ classes ) . '" data-cms-page-id="' . $ page -> id . '">' . $ pageRow . '</li>' ; } return $ output ; } | Renders a complete tree of pages without the toplevel ul element . |
47,159 | protected function _toBoolean ( $ value ) { $ value = strtolower ( ( string ) $ value ) ; $ result = ( $ value != 'false' ) && ( $ value != 'off' ) && ! empty ( $ value ) ; return $ result ; } | Get boolean value |
47,160 | public static function quoteXpathValue ( $ string ) { if ( strpos ( $ string , "'" ) === false ) { return "'$string'" ; } if ( strpos ( $ string , '"' ) === false ) { return '"' . $ string . '"' ; } $ parts = explode ( "'" , $ string ) ; $ quoted = implode ( '\', "\'", \'' , $ parts ) ; return "concat('$quoted')" ; } | Quote the given value for an xpath expression |
47,161 | public function getPath ( ) { $ stack = array ( $ this -> getName ( ) ) ; $ current = $ this ; while ( $ parent = $ current -> getParent ( ) ) { array_unshift ( $ stack , $ parent -> getName ( ) ) ; $ current = $ parent ; } return implode ( '/' , $ stack ) ; } | returns the path name |
47,162 | public function toValue ( $ type = null , $ valueAttribute = null ) { $ value = ( $ valueAttribute ) ? ( string ) $ this [ $ valueAttribute ] : ( string ) $ this ; $ type = ( $ type ) ? : ( string ) $ this [ 'type' ] ; switch ( $ type ) { case 'int' : $ value = ( int ) $ value ; break ; case 'float' : $ value = ( float ) $ value ; break ; case 'bool' : $ value = $ this -> _toBoolean ( $ value ) ; break ; case 'double' : $ value = ( double ) $ value ; break ; case 'null' : $ value = null ; break ; case 'array' : $ value = $ this -> toArray ( true ) ; break ; } return $ value ; } | To php value |
47,163 | public function toArray ( $ force = true ) { if ( ! $ force && ! $ this -> hasChildren ( ) ) { return $ this -> toValue ( ) ; } $ data = array ( ) ; foreach ( $ this -> children ( ) as $ name => $ child ) { $ data [ $ name ] = $ child -> toArray ( false ) ; } return $ data ; } | convert to array |
47,164 | public function toPhpValue ( $ type = null , $ serviceLocator = null ) { if ( ! $ type ) { $ type = $ this -> getName ( ) ; } switch ( $ type ) { case 'array' : $ value = array ( ) ; if ( ! isset ( $ this -> item ) ) { return $ value ; } foreach ( $ this -> item as $ item ) { if ( ! ( $ type = ( string ) $ item [ 'type' ] ) ) { $ type = 'string' ; } if ( ( $ type == 'instance' ) && ! $ item -> { $ type } ) { $ current = null ; } else { $ current = ( $ item -> { $ type } ) ? $ item -> { $ type } -> toPhpValue ( $ type , $ serviceLocator ) : $ item -> toPhpValue ( $ type , $ serviceLocator ) ; } if ( ! isset ( $ item [ 'key' ] ) && ! isset ( $ item [ 'index' ] ) ) { $ value [ ] = $ current ; continue ; } $ key = ( isset ( $ item [ 'key' ] ) ) ? ( string ) $ item [ 'key' ] : intval ( ( string ) $ item [ 'index' ] ) ; $ value [ $ key ] = $ current ; } break ; case 'null' : $ value = null ; break ; case 'instance' : $ class = ( string ) $ this [ 'class' ] ; $ value = null ; if ( ( $ serviceLocator instanceof ServiceLocatorInterface ) && ( $ serviceLocator -> has ( $ class ) ) ) { $ value = $ serviceLocator -> get ( $ class ) ; break ; } if ( $ serviceLocator instanceof DependencyInjectionInterface ) { $ options = array ( ) ; if ( isset ( $ this -> options ) ) { $ options = $ this -> options -> toPhpValue ( 'array' , $ serviceLocator ) ; } $ value = $ serviceLocator -> newInstance ( $ class , $ options ) ; break ; } break ; default : $ value = $ this -> toValue ( $ type ) ; break ; } return $ value ; } | Convert to php value |
47,165 | protected function _getMergeRule ( $ element , & $ affected = null , $ rule = null ) { if ( $ rule instanceof MergeRuleInterface ) { $ result = $ rule ( $ this , $ element , $ affected ) ; if ( $ result !== false ) { return $ result ; } } $ name = $ element -> getName ( ) ; if ( isset ( $ this -> { $ name } ) ) { $ affected = $ this -> { $ name } ; return self :: MERGE_REPLACE ; } return self :: MERGE_APPEND ; } | find merge rule |
47,166 | public function mergeAttributes ( SimpleXmlElement $ node , $ replace = true ) { foreach ( $ node -> attributes ( ) as $ name => $ value ) { if ( isset ( $ this [ $ name ] ) ) { if ( $ replace ) { $ this [ $ name ] = ( string ) $ value ; } continue ; } $ this -> addAttribute ( $ name , ( string ) $ value ) ; } return $ this ; } | Merge attributes from the given node to this one |
47,167 | public function merge ( SimpleXmlElement $ element , $ replace = true , $ rule = null ) { foreach ( $ element -> children ( ) as $ name => $ child ) { $ affected = null ; $ currentpath = $ child -> getPath ( ) ; $ action = $ this -> _getMergeRule ( $ child , $ affected , $ rule ) ; if ( $ action == self :: MERGE_APPEND ) { $ affected = $ this -> addChild ( $ name , ( string ) $ child ) ; } if ( ! $ affected instanceof SimpleXmlElement ) { continue ; } $ affected -> mergeAttributes ( $ child , $ replace ) ; if ( $ child -> hasChildren ( ) ) { $ affected -> merge ( $ child , $ replace , $ rule ) ; continue ; } else if ( $ replace ) { $ affected [ 0 ] = ( string ) $ child ; } } return $ this ; } | merge another xml element into this one |
47,168 | private function route_exists ( ) : bool { if ( property_exists ( $ this , 'routes' ) ) { return array_key_exists ( $ this -> __method_name , $ this -> routes ) ; } return false ; } | Check if the route has been defined |
47,169 | private function route_request ( ) { $ named_arguments = $ this -> get_named_arguments ( ) ; list ( $ to_class , $ to_method , $ on_error ) = $ this -> get_route_parts ( ) ; return $ this -> do_route ( $ to_class , $ to_method , $ named_arguments , $ on_error ) ; } | Build and do the route |
47,170 | private function get_named_arguments ( ) : array { $ named_arguments = [ ] ; if ( array_key_exists ( 'expects' , $ this -> routes [ $ this -> __method_name ] ) ) { $ expects = $ this -> routes [ $ this -> __method_name ] [ 'expects' ] ; foreach ( $ expects as $ index => $ parameter_name ) { if ( array_key_exists ( $ index , $ this -> __arguments ) ) { $ named_arguments [ $ parameter_name ] = $ this -> __arguments [ $ index ] ; } } } return $ named_arguments ; } | Map the arguments passed into the method to the expected arguments defined by the route |
47,171 | private function get_route_parts ( ) : array { $ to = $ this -> routes [ $ this -> __method_name ] [ 'to' ] ; if ( \ is_array ( $ to ) ) { $ to_parts = $ to ; } else { $ to_parts = explode ( '@' , $ to ) ; } $ to_class = $ to_parts [ 0 ] ; $ to_method = $ to_parts [ 1 ] ; $ on_error = null ; if ( array_key_exists ( 'on_error' , $ this -> routes [ $ this -> __method_name ] ) ) { $ on_error = $ this -> routes [ $ this -> __method_name ] [ 'on_error' ] ; } return [ $ to_class , $ to_method , $ on_error ] ; } | Get the individual parts of the route including the class and method to route to |
47,172 | private function do_route ( $ class_name , $ method_name , $ named_arguments , $ on_error ) { if ( \ is_object ( $ class_name ) ) { return $ this -> call ( array ( $ class_name , $ method_name , ) , $ named_arguments ) ; } $ injector_factory = new Dependency_Injection_Factory ( $ class_name , $ method_name , $ named_arguments ) ; list ( $ obj , $ dependencies , $ validators ) = $ injector_factory -> build ( ) ; foreach ( $ validators as $ validator ) { $ message = $ validator -> validate ( $ on_error ) ; if ( $ message ) { return $ message ; } } return $ this -> call ( array ( $ obj , $ method_name , ) , $ dependencies ) ; } | Resolve dependencies for dependency injection and call the given route |
47,173 | public static function template ( $ template , $ parameter = array ( ) , $ status = 200 , $ headers = array ( ) ) { View :: setTemplate ( $ template , $ parameter ) ; return new Response ( '' , $ status , $ headers ) ; } | Generate response from template . |
47,174 | public static function json ( $ data , $ status = 200 , $ headers = array ( ) ) { $ jsonHeader = array ( 'Content-Type' => 'application/json' ) ; $ content = json_encode ( $ data ) ; return new Response ( $ content , $ status , $ jsonHeader ) ; } | Return JSON response . |
47,175 | public static function redirect ( $ url , $ status = 302 , $ headers = array ( ) ) { $ redirect = new RedirectResponse ( $ url , $ status , $ headers ) ; $ redirect -> sendHeaders ( ) ; die ( ) ; } | Redirect Response . |
47,176 | public static function download ( $ file , $ status = 200 , $ headers = array ( ) ) { require_once ABSPATH . 'wp-admin/includes/file.php' ; WP_Filesystem ( ) ; global $ wp_filesystem ; $ fileData = $ wp_filesystem -> get_contents ( $ file ) ; $ downloadHeader [ 'Content-Description' ] = 'File Transfer' ; $ downloadHeader [ 'Content-Type' ] = 'application/octet-stream' ; $ downloadHeader [ 'Content-Disposition' ] = 'attachment; filename=' . basename ( $ file ) ; $ downloadHeader [ 'Content-Transfer-Encoding' ] = 'binary' ; $ downloadHeader [ 'Expires' ] = '0' ; $ downloadHeader [ 'Cache-Control' ] = 'must-revalidate' ; $ downloadHeader [ 'Pragma' ] = 'public' ; $ downloadHeader [ 'Content-Length' ] = filesize ( $ file ) ; $ response = new Response ( $ fileData , 200 , $ downloadHeader ) ; $ response -> send ( ) ; } | Generate download file . |
47,177 | public function setLocaleForUnauthenticatedUser ( GetResponseEvent $ event ) { if ( HttpKernelInterface :: MASTER_REQUEST !== $ event -> getRequestType ( ) ) { return ; } $ request = $ event -> getRequest ( ) ; if ( 'unset' == $ request -> getLocale ( ) ) { if ( $ locale = $ request -> getSession ( ) -> get ( '_locale' ) ) { $ request -> setLocale ( $ locale ) ; } else { $ request -> setLocale ( $ request -> getPreferredLanguage ( ) ) ; } } } | kernel . request event . If a guest user doesn t have an opened session locale is equal to undefined as configured by default in parameters . ini . If so set as a locale the user s preferred language . |
47,178 | public function setLocaleForAuthenticatedUser ( InteractiveLoginEvent $ event ) { $ user = $ event -> getAuthenticationToken ( ) -> getUser ( ) ; if ( $ lang = $ user -> getLocale ( ) ) { $ this -> session -> set ( '_locale' , $ lang ) ; } else { $ request = $ event -> getRequest ( ) ; if ( 'unset' == $ request -> getLocale ( ) ) { $ this -> session -> set ( '_locale' , 'en' ) ; } } } | security . interactive_login event . If a user chose a language in preferences it would be set if not a locale that was set by setLocaleForUnauthenticatedUser remains . |
47,179 | protected static function makeInstance ( $ class , array $ options = null ) : Implementation { $ options || $ options = [ 'provider' => self :: app ( ) ] ; return IOC :: make ( $ class , [ $ options , true ] ) ; } | Make the instance this facade refers to |
47,180 | public static function getInstance ( $ class = null , array $ options = [ ] ) { if ( is_null ( self :: $ instance ) ) { if ( is_null ( $ class ) ) { self :: $ instance = self :: makeInstance ( Implementation :: class , $ options ) -> getApp ( $ options ) ; self :: $ instance -> load ( ) ; } else { ! is_object ( $ class ) || self :: $ instance = $ class ; } } return self :: $ instance ; } | Get the instance this facade refers to |
47,181 | public function setHttpMethod ( $ method ) { $ allowedMethods = array ( 'POST' , 'PUT' , 'GET' , 'DELETE' , 'PATCH' ) ; if ( ! in_array ( strtoupper ( $ method ) , $ allowedMethods ) ) { throw new \ InvalidArgumentException ( 'Provided method not allowed' ) ; } $ this -> httpMethod = strtoupper ( $ method ) ; return $ this ; } | Method to set the HTTP verb for the request |
47,182 | public function getNonce ( ) { if ( $ this -> nonce !== '' ) { return $ this -> nonce ; } $ this -> nonce = md5 ( uniqid ( rand ( ) , true ) ) ; return $ this -> nonce ; } | Method to retrieve the nonce |
47,183 | public function setTimestamp ( $ timestamp = 0 ) { $ this -> timestamp = $ timestamp ; if ( $ timestamp === 0 ) { $ this -> timestamp = $ this -> generateTimestamp ( ) ; } return $ this ; } | Method to set the timestamp parameter for the signature |
47,184 | public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ annotationManager = new AnnotationManager ( ) ; $ parser = new DoctrineAnnotationParser ( ) ; foreach ( $ this -> defaultAnnotations as $ annotationName ) { $ class = 'TjoAnnotationRouter\\Annotation\\' . $ annotationName ; $ parser -> registerAnnotation ( $ class ) ; } $ annotationManager -> attach ( $ parser ) ; return $ annotationManager ; } | Returns a configured instance of Zend \ Code \ Annotation \ AnnotationManager |
47,185 | public function setTask ( $ task ) { $ taskCode = filter_var ( $ task , FILTER_SANITIZE_NUMBER_FLOAT , FILTER_FLAG_ALLOW_FRACTION ) ; if ( strpos ( $ taskCode , '-' ) !== false ) { $ taskCode = str_replace ( '-' , '' , $ taskCode ) ; } $ taskCode = $ this -> project . $ taskCode ; $ this -> task = $ taskCode ; } | Sets the internal task ID for this task . Task is determineed by concatenating project and task code |
47,186 | public function processTags ( $ tags = null ) { if ( empty ( $ tags ) ) { $ tags = $ this -> tags ; } foreach ( $ tags as $ tag ) { $ this -> tags [ ] = $ tag ; if ( preg_match ( '/[A-Z]+\-[\d]+/' , $ tag ) ) { $ this -> setTicket ( $ tag ) ; continue ; } if ( $ tag == 'Jira' ) { $ this -> setLogged ( true ) ; } } $ this -> tags = array_unique ( $ this -> tags ) ; } | Processes an array of tags to find the ticket number as well as other internally used tags |
47,187 | private function startRestoreService ( StorageboxData $ data , $ backupKey , Database $ database , OutputInterface $ output ) { $ stackName = $ data -> getBackup ( ) -> getStackName ( ) ; $ restoreService = new Service ( ) ; $ restoreService -> setImage ( 'ipunktbs/xtrabackup:1.1.1' ) ; $ restoreService -> setName ( 'restore-' . $ backupKey ) ; $ restoreService -> setCommand ( 'restore ' . $ backupKey ) ; $ restoreService -> setRestart ( Service :: RESTART_START_ONCE ) ; $ mysqlVolume = $ this -> makeVolume ( $ data ) ; $ backupVolume = $ this -> makeBackupVolume ( $ database ) ; $ restoreService -> addVolume ( $ mysqlVolume ) ; $ restoreService -> addVolume ( $ backupVolume ) ; $ schedulerParser = container ( 'scheduler-parser' ) ; $ config = new ArrayConfiguration ( [ 'scheduler' => [ 'should-have-tags' => [ 'primary-restore' ] ] ] ) ; $ schedulerParser -> parse ( $ restoreService , $ config ) ; $ restoreInfrastructure = new Infrastructure ( ) ; $ restoreInfrastructure -> addService ( $ restoreService ) ; $ this -> infrastructureWriter -> setPath ( $ this -> getWorkDirectory ( ) ) -> setSkipClear ( false ) -> write ( $ restoreInfrastructure , new FileWriter ( ) ) ; $ output -> writeln ( "Starting " . $ restoreService -> getName ( ) . "." ) ; $ this -> rancherService -> start ( $ this -> getWorkDirectory ( ) , $ stackName ) ; $ output -> writeln ( "Waiting for " . $ restoreService -> getName ( ) . " to finish." ) ; $ this -> rancherService -> wait ( $ stackName , $ restoreService -> getName ( ) , new HealthStateMatcher ( 'started-once' ) ) ; $ output -> writeln ( $ restoreService -> getName ( ) . " finished." ) ; return $ restoreService ; } | Start the restore service |
47,188 | private function startNewService ( Service $ restoreService , StorageboxData $ data , $ backupKey , OutputInterface $ output ) { $ stackName = $ data -> getBackup ( ) -> getStackName ( ) ; $ restoreServiceName = $ restoreService -> getName ( ) ; $ dockerCompose = [ 'version' => '2' , 'services' => array_merge ( [ $ data -> getBackup ( ) -> getServiceName ( ) => $ data -> getService ( ) ] , $ data -> getSidekicks ( ) ) ] ; $ rancherCompose = $ data -> getRancherData ( ) ; $ regex = '~$~' ; $ replacement = '-' . $ backupKey ; foreach ( $ this -> modifiers as $ modifier ) { if ( $ modifier instanceof RequiresReplacementRegex ) $ modifier -> setReplacementRegex ( $ regex , $ replacement ) ; $ modifier -> modify ( $ dockerCompose , $ rancherCompose , $ data ) ; } $ compose = & $ dockerCompose ; foreach ( [ 'services' , $ data -> getNewServiceName ( ) , 'labels' , ] as $ key ) { if ( ! array_key_exists ( $ key , $ compose ) ) $ compose [ $ key ] = [ ] ; $ compose = & $ compose [ $ key ] ; } $ dockerCompose [ 'services' ] [ $ data -> getNewServiceName ( ) ] [ 'labels' ] [ 'io.rancher.scheduler.affinity:container_label_soft' ] = "io.rancher.stack_service.name=${stackName}/${restoreServiceName}" ; $ dockerFileContent = Yaml :: dump ( $ dockerCompose , 100 , 2 ) ; $ this -> buildService -> createDockerCompose ( $ dockerFileContent ) ; $ rancherFileContent = Yaml :: dump ( $ rancherCompose , 100 , 2 ) ; $ this -> buildService -> createRancherCompose ( $ rancherFileContent ) ; $ stackName = $ data -> getBackup ( ) -> getStackName ( ) ; $ newServiceName = $ data -> getNewServiceName ( ) ; $ output -> writeln ( "Starting $newServiceName." ) ; $ this -> rancherService -> start ( $ this -> getWorkDirectory ( ) , $ stackName ) ; $ output -> writeln ( "Waiting for $newServiceName to start." ) ; $ this -> rancherService -> wait ( $ stackName , $ newServiceName , new SingleStateMatcher ( 'active' ) ) ; $ output -> writeln ( "$newServiceName Started." ) ; } | Start the new service |
47,189 | public function prepareI18nModels ( ) { $ mI18n = $ this -> getJoined ( ) -> all ( ) ; $ modelsI18n = [ ] ; foreach ( $ mI18n as $ modelI18n ) { $ modelI18n -> correctSelectedText ( ) ; $ modelsI18n [ $ modelI18n -> lang_code ] = $ modelI18n ; } foreach ( $ this -> languages as $ langCode => $ lang ) { if ( empty ( $ modelsI18n [ $ langCode ] ) ) { $ newI18n = $ this -> module -> model ( static :: I18N_JOIN_MODEL ) ; $ modelsI18n [ $ langCode ] = $ newI18n -> loadDefaultValues ( ) ; $ modelsI18n [ $ langCode ] -> lang_code = $ langCode ; } } return $ modelsI18n ; } | Prepare i18n - models array create new if need . No error if new language add or not found joined record - will create new i18n - model with default values . |
47,190 | public function errors ( $ field = null , $ errors = null , $ overwrite = false ) { if ( isset ( $ this -> _properties [ 'scope' ] ) ) { $ this -> _errors = [ ] ; } return parent :: errors ( $ field , $ errors , $ overwrite ) ; } | Skip error checking for the actual save operation since the entity is checked for errors manually within the KeyValueBehavior . |
47,191 | public function addRepository ( RepositoryInterface $ repository ) { if ( $ repository instanceof IssueRepository ) { $ type = 'issue' ; } else { throw new \ Exception ( 'Unknown repository type.' ) ; } $ this -> repositories [ $ type ] = $ repository ; } | Register the repository in the manager |
47,192 | public function addArgument ( $ shortName = '' , $ fullName = '' , $ description = '' , $ hasValue = false , $ isMandatory = false ) { $ argument = new \ stdClass ( ) ; $ argument -> shortName = $ shortName ; $ argument -> fullName = $ fullName ; $ argument -> description = $ description ; $ argument -> hasValue = ( bool ) $ hasValue ; $ argument -> isMandatory = ( bool ) $ isMandatory ; $ this -> arguments [ ] = $ argument ; } | Add argument in list for script help |
47,193 | protected function _q45 ( EarthIT_Schema_ResourceClass $ rc , array $ items ) { $ restObjects = array ( ) ; $ keyByIds = $ this -> shouldKeyRestItemsById ( $ rc ) ; foreach ( $ items as $ item ) { $ restItem = $ this -> internalObjectToRest ( $ rc , $ item ) ; if ( $ keyByIds ) { $ restObjects [ EarthIT_Storage_Util :: itemId ( $ item , $ rc ) ] = $ restItem ; } else { $ restObjects [ ] = $ restItem ; } } return $ this -> jsonTyped ( $ restObjects , $ keyByIds ? EarthIT_JSON :: JT_OBJECT : EarthIT_JSON :: JT_LIST ) ; } | Convert the given rows from DB to REST format according to the specified resource class . |
47,194 | protected function addAssets ( ) { $ this -> assets = ViewService :: getAssetManager ( ) ; $ this -> assets -> addCss ( __DIR__ . '/../../assets/common/dist/common.css' ) -> addJs ( __DIR__ . '/../../assets/common/dist/common.js' ) -> entry ( 'teamelf/common/main' ) ; } | add common assets |
47,195 | public function buildDataRequestQuery ( DataRequest $ dataRequest , QueryBuilder $ queryBuilder , $ entity , $ tableCode ) { $ queryBuilder -> select ( $ tableCode ) -> from ( $ entity , $ tableCode ) ; $ hasWhere = false ; $ i = 1 ; foreach ( $ dataRequest -> getFilters ( ) as $ filter ) { $ whereQuery = $ tableCode . '.' . $ filter -> getFieldName ( ) . ' ' . $ filter -> getMode ( ) . ' :p' . $ i ; if ( $ hasWhere ) { $ queryBuilder -> andWhere ( $ whereQuery ) ; } else { $ queryBuilder -> where ( $ whereQuery ) ; $ hasWhere = true ; } $ queryBuilder -> setParameter ( 'p' . $ i , $ this -> prepareValue ( $ filter -> getNeededValue ( ) , $ filter -> getMode ( ) ) ) ; $ i ++ ; } if ( $ dataRequest -> hasSorting ( ) ) { $ mode = 'ASC' ; if ( in_array ( $ dataRequest -> getSortByDirection ( ) , array ( 'ASC' , 'DESC' ) ) ) { $ mode = $ dataRequest -> getSortByDirection ( ) ; } $ queryBuilder -> orderBy ( $ tableCode . '.' . $ dataRequest -> getSortBy ( ) , $ mode ) ; } if ( $ dataRequest -> hasRange ( ) ) { $ queryBuilder -> setFirstResult ( $ dataRequest -> getOffset ( ) ) ; $ queryBuilder -> setMaxResults ( $ dataRequest -> getNumberOfEntries ( ) ) ; } } | Builds the query for the given data request object |
47,196 | public static function run ( $ cwd = null , array $ index = [ 'html' , 'php' ] , $ front = '/index.php' ) { if ( $ cwd === null ) { $ cwd = getcwd ( ) ; } $ file = self :: getFilePath ( $ cwd , $ index ) ; if ( $ file === false ) { return false ; } if ( ! empty ( $ front ) && ( $ file === $ cwd . $ front ) ) { return false ; } if ( $ cwd === getcwd ( ) ) { return true ; } $ ext = strtolower ( pathinfo ( $ file , PATHINFO_EXTENSION ) ) ; if ( $ ext === 'php' ) { return $ file ; } if ( isset ( self :: $ mimes [ $ ext ] ) ) { $ mime = self :: $ mimes [ $ ext ] ; } else { $ info = new finfo ( FILEINFO_MIME ) ; $ mime = $ info -> file ( $ file ) ; } header ( 'Content-Type: ' . $ mime ) ; readfile ( $ file ) ; exit ; } | Runs the server |
47,197 | public static function getRequestPath ( ) { if ( empty ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return false ; } $ path = parse_url ( $ _SERVER [ 'REQUEST_URI' ] , PHP_URL_PATH ) ; return empty ( $ path ) ? $ path : urldecode ( $ path ) ; } | Returns the path of the request uri |
47,198 | public static function getFilePath ( $ cwd , array $ index ) { $ path = self :: getRequestPath ( ) ; if ( $ path === false ) { return false ; } $ file = $ cwd . $ path ; if ( is_file ( $ file ) ) { return $ file ; } if ( empty ( $ index ) ) { return false ; } foreach ( $ index as $ ext ) { $ f = rtrim ( $ file , '/' ) . '/index.' . $ ext ; if ( is_file ( $ f ) ) { return $ f ; } } return false ; } | Check whether the requested path exists |
47,199 | public function handle ( \ AltoRouter $ router , \ PowerOn \ Network \ Request $ request ) { $ match = $ router -> match ( $ request -> path ) ; if ( $ match ) { $ target = explode ( '#' , $ match [ 'target' ] ) ; $ this -> controller = $ target [ 0 ] ; $ this -> action = key_exists ( 1 , $ target ) ? $ target [ 1 ] : 'index' ; } else { $ url = $ request -> urlToArray ( ) ; $ controller = array_shift ( $ url ) ; $ action = array_shift ( $ url ) ; $ this -> controller = $ controller ? $ controller : 'index' ; $ this -> action = $ action ? $ action : 'index' ; } $ handler = $ this -> loadController ( ) ; if ( ! $ handler || ! method_exists ( $ handler , $ this -> action ) ) { throw new NotFoundException ( 'El sitio al que intenta ingresar no existe.' ) ; } return $ handler ; } | Obtiene el controlador a utilizar |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.