idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
45,900
public function finalize ( ) : Values { foreach ( $ this -> definitions as $ name => $ parameter ) { if ( isset ( $ this -> items [ $ name ] ) ) { continue ; } $ this -> items [ $ name ] = ( $ value = $ parameter -> getValue ( ) ) ? $ value -> getDefault ( ) : false ; } return $ this ; }
Finalizes the Collection populating it with Parameters that have not been explicitly set but have defined default values .
45,901
protected function assertIsDefined ( string $ name ) : input \ Parameter { if ( ! $ parameter = $ this -> definitions -> get ( $ name ) ) { throw new \ OutOfBoundsException ( "The parameter [$name] is not defined." ) ; } return $ parameter ; }
Asserts a Parameter with the given name is defined for this collection and returns it .
45,902
protected function _normalizeKey ( $ key ) { try { return $ this -> _normalizeString ( $ key ) ; } catch ( InvalidArgumentException $ e ) { throw $ this -> _createOutOfRangeException ( $ this -> __ ( 'Invalid key' ) , null , $ e , $ key ) ; } }
Normalizes a key .
45,903
public function _getLifetime ( \ Doctrine_Record $ record ) { $ return = $ this -> _lifetime ; if ( ! $ this -> _overrideLifetime ) { $ return = ( int ) $ record -> { $ this -> _lifetimeColumn } ; } return $ return ; }
Retrieve session lifetime
45,904
public static function get ( ) { return [ self :: $ equals , self :: $ lessThan , self :: $ lessThanEqualTo , self :: $ greaterThan , self :: $ greaterThanEqualTo , self :: $ doesNotEqual , self :: $ doesNotEqualAlt , self :: $ is , self :: $ isA , self :: $ isNot , self :: $ like , ] ; }
Returns all available operators .
45,905
public static function that ( $ condition , $ message = null ) { if ( $ condition === true ) { return ; } if ( isset ( $ message ) ) { throw new InvalidArgumentException ( $ message ) ; } $ bt = debug_backtrace ( ) ; $ call = $ bt [ 0 ] ; $ lines = file ( $ call [ 'file' ] ) ; preg_match ( '/' . $ call [ 'function' ] . '\((.+)\)/' , $ lines [ $ call [ 'line' ] - 1 ] , $ matches ) ; throw new InvalidArgumentException ( 'Assumption failed: ' . $ matches [ 1 ] ) ; }
Precondition function that can be used to add additional constraints to function parameters .
45,906
public function run ( ) { $ this -> connect ( ) ; $ this -> connection -> writeText ( '{ "action" : "listen" }' ) ; while ( ! $ this -> moribund ) { $ read = array ( $ this -> connection -> getSocket ( ) -> getRawSocket ( ) ) ; $ result = @ stream_select ( $ read , $ write = null , $ except = null , null ) ; if ( $ result === false || $ result < 1 ) { continue ; } $ moribund = false ; $ bytes = $ this -> connection -> getSocket ( ) -> peek ( 1 ) ; if ( mb_strlen ( $ bytes , '8bit' ) === 0 ) { $ this -> log ( 'server closed connection.' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; $ moribund = true ; } try { if ( $ this -> connection -> read ( Net_Notifier_Client :: READ_BUFFER_LENGTH ) ) { if ( $ this -> connection -> getState ( ) < Net_Notifier_WebSocket_Connection :: STATE_CLOSING ) { $ messages = $ this -> connection -> getTextMessages ( ) ; foreach ( $ messages as $ message ) { if ( mb_strlen ( $ message , '8bit' ) > 0 ) { $ this -> log ( sprintf ( 'received message: "%s"' . PHP_EOL , $ message ) , Net_Notifier_Logger :: VERBOSITY_MESSAGES ) ; $ this -> handleMessage ( $ message ) ; } } } } else { $ this -> log ( 'got a message chunk from server' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; } } catch ( Net_Notifier_WebSocket_HandshakeFailureException $ e ) { $ this -> log ( sprintf ( 'failed server handshake: %s' . PHP_EOL , $ e -> getMessage ( ) ) , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; } if ( $ moribund ) { $ this -> connection -> close ( ) ; break ; } } if ( $ this -> connection -> getState ( ) < Net_Notifier_WebSocket_Connection :: STATE_CLOSING ) { $ this -> disconnect ( ) ; } }
Runs this listen client
45,907
public static function parse ( $ value ) { if ( is_array ( $ value ) ) { return static :: fromArray ( ( array ) $ value ) ; } elseif ( is_string ( $ value ) ) { return static :: fromString ( ( string ) $ value ) ; } else { return null ; } }
Parses a value and returns its Locale representation .
45,908
public static function fromArray ( array $ value ) { $ language = null ; $ culture = null ; if ( ! empty ( $ value [ 'language' ] ) ) { $ language = $ value [ 'language' ] ; } elseif ( $ value [ 0 ] ) { $ language = $ value [ 0 ] ; } if ( ! empty ( $ value [ 'culture' ] ) ) { $ culture = $ value [ 'culture' ] ; } elseif ( $ value [ 1 ] ) { $ culture = $ value [ 1 ] ; } return new static ( $ language , $ culture ) ; }
Parses the given array and returns its Locale representation .
45,909
public static function fromString ( string $ value ) { $ locale = preg_split ( '/-|_/' , $ value , 2 ) ; $ language = null ; $ culture = null ; if ( isset ( $ locale [ 0 ] ) ) { $ language = $ locale [ 0 ] ; } if ( isset ( $ locale [ 1 ] ) ) { $ culture = $ locale [ 1 ] ; } return new static ( $ language , $ culture ) ; }
Parses the given string and returns its Locale representation .
45,910
public function toString ( ) { if ( $ this -> _language && $ this -> _culture ) { return ( string ) $ this -> _language . '_' . ( string ) $ this -> _culture ; } else { return ( string ) $ this -> _language ; } }
Convert the current Locale to its string representation .
45,911
public function image ( ) { if ( $ this -> relationLoaded ( 'mediables' ) ) { return $ this -> mediables -> where ( 'type' , 'image' ) -> first ( ) ; } return $ this -> mediables ( ) -> where ( 'media.type' , 'image' ) -> whereNull ( 'mediables.type' ) -> first ( ) ; }
Image object .
45,912
public function setImageAttribute ( $ value ) { $ value = $ this -> resolveMediableValue ( $ value ) ; if ( ! $ this -> exists && $ value ) { return $ this -> attributes [ 'image' ] = $ value ; } elseif ( ! $ this -> exists ) { return ; } $ this -> mediables ( ) -> sync ( $ value ) ; $ this -> touch ( ) ; }
Image setter .
45,913
public function getImageAttribute ( ) { if ( $ this -> exists ) { return $ this -> image ( ) ; } return isset ( $ this -> attributes [ 'image' ] ) ? $ this -> attributes [ 'image' ] : null ; }
Image getter .
45,914
public function getImageUrlAttribute ( ) { if ( $ this -> exists ) { $ image = $ this -> image ( ) ; if ( $ image ) { return $ image -> url ; } return config ( 'media.image.default' ) ; } return config ( 'media.image.default' ) ; }
Default image url attribute .
45,915
public function auth ( Request $ request , $ action ) { $ provider = strtolower ( $ request -> attributes -> get ( 'provider' ) ) ; if ( ! $ this -> providerExists ( $ provider ) ) { return $ this -> createNotFoundResponse ( ) ; } $ service = $ this -> getServiceByProvider ( $ provider ) ; $ redirectUri = $ service -> getAuthorizationUri ( [ 'state' => $ action ] ) ; $ response = new Response ( ) ; $ response -> setStatusCode ( 301 ) ; $ response -> headers -> set ( 'Location' , ( string ) $ redirectUri ) ; return $ response ; }
Authenticate via a separate OAuth provider
45,916
public function callback ( Request $ request ) { $ provider = strtolower ( $ request -> attributes -> get ( 'provider' ) ) ; if ( ! $ this -> providerExists ( $ provider ) ) { return $ this -> createNotFoundResponse ( ) ; } if ( ! method_exists ( $ this , $ provider ) ) { throw new LogicException ( sprintf ( 'Callback for provider \'%s\' not implemented' , $ provider ) ) ; } $ code = $ request -> query -> get ( 'code' ) ; $ providerService = $ this -> getServiceByProvider ( $ provider ) ; $ providerToken = $ providerService -> requestAccessToken ( $ code ) ; $ socialLoginRequest = $ this -> $ provider ( $ providerService , $ providerToken ) ; $ state = ( int ) $ request -> query -> get ( 'state' ) ; try { if ( $ state === self :: ACTION_LOGIN_WITH_ACCOUNT ) { $ token = $ this -> service -> handleLoginRequest ( $ socialLoginRequest ) ; } elseif ( $ state === self :: ACTION_LINK_ACCOUNT ) { $ token = $ this -> service -> handleLinkRequest ( $ socialLoginRequest , $ this -> session -> get ( 'user' ) ) ; } else { return new Response ( 'State parameter not set' , 422 ) ; } $ redirect = $ this -> config [ 'redirect-url' ] ; $ redirect .= '?' . http_build_query ( $ token ) ; } catch ( NoLinkedAccountException $ e ) { $ redirect = $ this -> config [ 'redirect-url' ] ; $ redirect .= '?login_failure=1&error=no_linked_account' ; } catch ( LinkedAccountExistsException $ e ) { $ redirect = $ this -> config [ 'redirect-url' ] ; $ redirect .= '?login_failure=1&error=account_already_linked' ; } catch ( OutOfBoundsException $ e ) { $ redirect = $ this -> config [ 'redirect-url' ] ; $ redirect .= '?login_failure=1' ; if ( $ e -> getCode ( ) === SocialLoginService :: EXCEPTION_ACCOUNT_NOT_FOUND ) { $ redirect .= '&error=account_not_found' ; } } $ response = new Response ( ) ; $ response -> setStatusCode ( 301 ) ; $ response -> headers -> set ( 'Location' , $ redirect ) ; return $ response ; }
Callback for OAuth authentication requests
45,917
protected function providerExists ( $ provider ) { return ( array_key_exists ( $ provider , $ this -> serviceMap ) || array_key_exists ( $ provider , $ this -> config ) ) ; }
Determine whether the provider exists in the service map as well as the social login config
45,918
protected function github ( Oauth2Service \ GitHub $ github , TokenInterface $ token ) { $ emails = json_decode ( $ github -> request ( 'user/emails' ) , true ) ; $ user = json_decode ( $ github -> request ( 'user' ) , true ) ; $ loginRequest = new LoginRequest ( 'github' , $ user [ 'id' ] , $ token -> getAccessToken ( ) , $ token -> getEndOfLife ( ) > 0 ? $ token -> getEndOfLife ( ) : 0 , $ token -> getRefreshToken ( ) , $ emails ) ; return $ loginRequest ; }
Request access token from GitHub and return a LoginRequest object for logging into our app
45,919
protected function google ( Oauth2Service \ Google $ google , TokenInterface $ token ) { $ user = json_decode ( $ google -> request ( 'https://www.googleapis.com/oauth2/v1/userinfo' ) , true ) ; $ loginRequest = new LoginRequest ( 'google' , $ user [ 'id' ] , $ token -> getAccessToken ( ) , $ token -> getEndOfLife ( ) > 0 ? $ token -> getEndOfLife ( ) : 0 , $ token -> getRefreshToken ( ) , [ $ user [ 'email' ] ] ) ; return $ loginRequest ; }
Request access token from Google and return a LoginRequest object for logging into our app
45,920
protected function facebook ( Oauth2Service \ Facebook $ facebook , TokenInterface $ token ) { $ user = json_decode ( $ facebook -> request ( '/me' ) , true ) ; $ loginRequest = new LoginRequest ( 'facebook' , $ user [ 'id' ] , $ token -> getAccessToken ( ) , $ token -> getEndOfLife ( ) > 0 ? $ token -> getEndOfLife ( ) : 0 , $ token -> getRefreshToken ( ) , [ $ user [ 'email' ] ] ) ; return $ loginRequest ; }
Request access token from Facebook and return a LoginRequest object for logging into our app
45,921
public function getServiceByProvider ( $ provider ) { $ redirect = $ this -> url ( $ this -> config [ $ provider ] [ 'callback_route' ] , array ( 'provider' => $ provider , ) ) ; $ serviceName = $ this -> serviceMap [ $ provider ] ; $ storage = new SessionStorage ( false ) ; $ credentials = new ConsumerCredentials ( $ this -> config [ $ provider ] [ 'key' ] , $ this -> config [ $ provider ] [ 'secret' ] , $ redirect ) ; $ service = $ this -> serviceFactory -> createService ( $ serviceName , $ credentials , $ storage , $ this -> config [ $ provider ] [ 'scope' ] ) ; return $ service ; }
Get a provider service given a provider name
45,922
protected function dumpToSimpleYaml ( $ array ) { $ parts = [ ] ; foreach ( $ array as $ key => $ value ) { $ parts [ ] = "$key: $value" ; } $ yaml = implode ( "\n" , $ parts ) ; return $ yaml ; }
Transform an associative array to yaml . Not using symfony s yaml dumper for full control over the format .
45,923
public static function parseYaml ( $ yaml ) { if ( self :: $ yamlParser == null ) { self :: $ yamlParser = new YamlParser ; } return self :: $ yamlParser -> parse ( $ yaml ) ; }
Parse yaml to an array
45,924
public function deleteAction ( $ parameter ) { try { if ( ! $ this -> request -> isPost ( ) ) { return $ this -> jsonResult ( 400 , 'Please access via POST method.' , 'error_access_post' ) ; } if ( ! $ this -> getFile ( ) ) { return $ this -> jsonResult ( 400 , 'No file was uploaded.' , 'error_no_file' ) ; } $ this -> initFromSession ( ) ; $ this -> file = NULL ; $ this -> filename = NULL ; $ this -> filesize = NULL ; $ this -> saveToSession ( ) ; if ( ! $ this -> deleteFile ( ) ) { return $ this -> jsonResult ( 400 , 'Could not delete file.' , 'error_delete_failed' ) ; } return $ this -> jsonResult ( ) ; } catch ( Exception $ e ) { return $ this -> jsonResult ( 500 , $ e -> getMessage ( ) ) ; } }
Deletes a previously uploaded file . Must be accessed with the POST method .
45,925
public function downloadAction ( $ parameter ) { if ( ! $ this -> getFile ( ) ) { return 404 ; } if ( count ( $ parameter ) > 1 ) { return 404 ; } if ( $ parameter && $ parameter [ 0 ] != $ this -> filename ) { return 404 ; } return Misc :: servefile ( $ this -> file , $ parameter ? FALSE : $ this -> filename ) ; }
Sends a previously uploaded file if it exists .
45,926
public function uploadAction ( $ parameter ) { try { if ( ! $ files = $ this -> request -> files ( ) ) { return $ this -> jsonResult ( 400 , 'Failed to upload file.' , 'error_upload_failed' ) ; } foreach ( $ files as $ file ) { if ( $ error = $ file -> getError ( ) ) { return $ this -> jsonResult ( 400 , "Failed to upload file '%s'." , "error_upload_failed_detail" , [ $ file -> getError ( ) ] ) ; } } $ this -> initFromSession ( ) ; $ this -> deleteFile ( ) ; $ dir = $ this -> getUploadDir ( ) ; if ( ! Misc :: recursiveMkdir ( $ dir , 0700 ) ) { return $ this -> jsonResult ( 500 , "Failed to create upload directory at '%s'." , "error_createdir_failed" , [ $ dir ] ) ; } foreach ( $ files as $ file ) { $ target = "$dir/" . $ file -> getName ( ) ; if ( ! $ file -> moveTo ( $ target ) ) { return $ this -> jsonResult ( 500 , 'Failed to move file.' , 'error_move_failed' ) ; } } $ this -> file = $ target ; $ this -> filename = $ file -> getName ( ) ; $ this -> filesize = $ file -> getSize ( ) ; $ this -> saveToSession ( ) ; $ this -> cleanFiles ( ) ; return $ this -> jsonResult ( ) ; } catch ( Exception $ e ) { return $ this -> jsonResult ( 500 , $ e -> getMessage ( ) ) ; } }
Stores a received file . The request must be encoded as formdata .
45,927
public function find ( $ token , $ _params = array ( ) ) { return $ this -> transform ( $ this -> master -> get ( 'availability/' . $ token , $ _params ) ) ; }
Retrieve a list of availability for an event date range
45,928
public function month ( $ token , $ _params = array ( ) ) { return $ this -> transform ( $ this -> master -> get ( 'availability/' . $ token . '/month' , $ _params ) , true ) ; }
Retrieve a list of availability for an event month
45,929
public function date ( $ token , $ _params = array ( ) ) { return $ this -> transform ( $ this -> master -> get ( 'availability/' . $ token . '/date' , $ _params ) , true ) ; }
Retrieve a list of availability for a single event date
45,930
protected function fullQueryString ( ) { $ queryParts = [ ] ; if ( $ this -> queryString ) { if ( ! $ this -> querySwitchFulltext ) { $ queryParts [ ] = $ this -> queryString ; } else { $ queryParts [ ] = $ this -> createSearchString ( 'fulltext' , $ this -> queryString ) ; } } if ( $ this -> queryStringTitle ) { if ( ! $ this -> querySwitchJournalOnly ) { $ queryParts [ ] = $ this -> createSearchString ( 'title' , $ this -> queryStringTitle ) ; } else { $ queryParts [ ] = $ this -> createSearchString ( 'journal' , $ this -> queryStringTitle ) ; } } if ( $ this -> queryStringPerson ) { $ myQueryStringPerson = preg_replace ( '/^[\s"]*/' , '' , $ this -> queryStringPerson ) ; $ myQueryStringPerson = preg_replace ( '/[\s"]*$/' , '' , $ myQueryStringPerson ) ; $ queryParts [ ] = $ this -> createSearchString ( 'person' , '"' . $ myQueryStringPerson . '"' ) ; } if ( $ this -> queryStringKeyword ) { $ queryParts [ ] = $ this -> createSearchString ( 'subject' , $ this -> queryStringKeyword ) ; } if ( $ this -> queryStringDate ) { $ queryParts [ ] = $ this -> createSearchString ( 'date' , $ this -> queryStringDate ) ; } $ query = implode ( ' and ' , $ queryParts ) ; $ query = str_replace ( '*' , '?' , $ query ) ; return $ query ; }
Returns the full query string to send to pazpar2 .
45,931
public function getPazpar2BaseURL ( ) { $ URL = 'http://' . GeneralUtility :: getIndpEnv ( 'HTTP_HOST' ) . $ this -> getPazpar2Path ( ) ; if ( $ this -> pazpar2BaseURL ) { $ URL = $ this -> pazpar2BaseURL ; } return $ URL ; }
Return URL of pazpar2 service . If it is not set return default URL on localhost .
45,932
protected function queryIsDone ( ) { $ result = false ; $ statReplyString = $ this -> fetchURL ( $ this -> pazpar2StatURL ( ) ) ; $ statReply = GeneralUtility :: xml2array ( $ statReplyString ) ; if ( $ statReply ) { $ progress = ( int ) $ statReply [ 'progress' ] ; $ result = ( $ progress === 1 ) ; if ( $ result === true ) { $ this -> setDidRun ( true ) ; $ this -> setTotalResultCount ( $ statReply [ 'hits' ] ) ; } } else { GeneralUtility :: devLog ( 'could not parse pazpar2 stat reply' , 'pazpar2' , 3 ) ; } return $ result ; }
Checks whether the query is done . Requires a session to be established .
45,933
protected function fetchResults ( ) { $ maxResults = 1000 ; if ( count ( $ this -> conf [ 'exportFormats' ] ) > 0 ) { $ maxResults = $ maxResults / ( count ( $ this -> conf [ 'exportFormats' ] ) + 1 ) ; } $ recordsToFetch = 350 ; $ firstRecord = 0 ; while ( $ firstRecord < $ maxResults ) { $ recordsToFetchNow = min ( [ $ recordsToFetch , $ maxResults - $ firstRecord ] ) ; $ showReplyString = $ this -> fetchURL ( $ this -> pazpar2ShowURL ( $ firstRecord , $ recordsToFetchNow ) ) ; $ firstRecord += $ recordsToFetchNow ; $ showReplyTree = GeneralUtility :: xml2tree ( $ showReplyString ) ; $ showReply = $ showReplyTree [ 'show' ] [ 0 ] [ 'ch' ] ; if ( $ showReply ) { $ status = $ showReply [ 'status' ] [ 0 ] [ 'values' ] [ 0 ] ; if ( $ status == 'OK' ) { $ this -> queryIsRunning = false ; $ hits = $ showReply [ 'hit' ] ; if ( $ hits ) { foreach ( $ hits as $ hit ) { $ myHit = $ hit [ 'ch' ] ; $ key = $ myHit [ 'recid' ] [ 0 ] [ 'values' ] [ 0 ] ; if ( ! array_key_exists ( 'md-medium' , $ myHit ) ) { $ myHit [ 'md-medium' ] = [ 0 => [ 'values' => [ 0 => 'other' ] ] ] ; } if ( ! ( array_key_exists ( 'md-title' , $ myHit ) || array_key_exists ( 'md-multivolume-title' , $ myHit ) ) && array_key_exists ( 'md-series-title' , $ myHit ) ) { $ myHit [ 'md-multivolume-title' ] = [ $ myHit [ 'md-series-title' ] [ 0 ] ] ; } usort ( $ myHit [ 'location' ] , [ $ this , 'yearSort' ] ) ; $ this -> results [ $ key ] = $ myHit ; } } } else { GeneralUtility :: devLog ( 'pazpar2 show reply status is not "OK" but "' . $ status . '"' , 'pazpar2' , 3 ) ; } } else { GeneralUtility :: devLog ( 'could not parse pazpar2 show reply' , 'pazpar2' , 3 ) ; } } }
Fetches results from pazpar2 . Requires an established session .
45,934
protected function pazpar2ShowURL ( $ start = 0 , $ num = 500 ) { $ URL = $ this -> getPazpar2BaseURL ( ) . '?command=show' ; $ URL .= '&query=' . urlencode ( $ this -> fullQueryString ( ) ) ; $ URL .= '&start=' . $ start . '&num=' . $ num ; $ URL .= '&sort=' . urlencode ( $ this -> sortOrderString ( ) ) ; $ URL .= '&block=1' ; return $ URL ; }
Returns URL for downloading pazpar2 results . The parameters can be used to give the the start record as well as the number of records required .
45,935
protected function sortOrderString ( ) { $ sortOrderComponents = [ ] ; foreach ( $ this -> getSortOrder ( ) as $ sortCriterion ) { $ sortOrderComponents [ ] = $ sortCriterion [ 'fieldName' ] . ':' . ( ( $ sortCriterion [ 'direction' ] === 'descending' ) ? '0' : '1' ) ; } $ sortOrderString = implode ( ',' , $ sortOrderComponents ) ; return $ sortOrderString ; }
Returns a string encoding the sort order formatted for use by pazpar2 .
45,936
protected function yearSort ( $ a , $ b ) { $ aDates = $ this -> extractNewestDates ( $ a ) ; $ bDates = $ this -> extractNewestDates ( $ b ) ; if ( count ( $ aDates ) > 0 && count ( $ bDates ) > 0 ) { return $ bDates [ 0 ] - $ aDates [ 0 ] ; } elseif ( count ( $ aDates ) > 0 && count ( $ bDates ) === 0 ) { return - 1 ; } elseif ( count ( $ aDates ) === 0 && count ( $ bDates ) > 0 ) { return 1 ; } else { return 0 ; } }
Auxiliary sort function for sorting records and locations based on their date field with the newest item being first and undefined dates last .
45,937
public function getObjects ( $ query , $ object ) { $ this -> statement = $ this -> db -> query ( $ query ) ; if ( $ this -> statement ) { $ this -> statement -> setFetchMode ( \ PDO :: FETCH_CLASS , $ object ) ; $ objects = $ this -> statement -> fetchAll ( ) ; if ( $ objects ) { return $ objects ; } } return false ; }
Get objects by sql query
45,938
public function getObject ( $ query , $ object ) { $ this -> statement = $ this -> db -> query ( $ query ) ; if ( $ this -> statement ) { $ this -> statement -> setFetchMode ( \ PDO :: FETCH_CLASS , $ object ) ; return $ this -> statement -> fetch ( ) ; } return false ; }
Get object by sql query
45,939
public function getArrays ( $ query ) { $ this -> statement = $ this -> db -> query ( $ query ) ; if ( $ this -> statement ) { $ result = $ this -> statement -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; if ( $ result ) { return $ result ; } } return false ; }
Get arrays by sql query
45,940
public function registerShard ( $ shard_name , $ parameters ) { if ( empty ( $ shard_name ) ) { throw new \ Exception ( "The shard name is not specified!" ) ; } if ( ! empty ( $ this -> shard_table [ $ shard_name ] ) ) { throw new \ Exception ( "The shard '$shard_name' has been already registered!" ) ; } $ this -> shard_table [ $ shard_name ] [ "parameters" ] = $ parameters ; return true ; }
Registers a new shard .
45,941
public function dbshard ( $ shard_name ) { if ( empty ( $ shard_name ) || empty ( $ this -> shard_table [ $ shard_name ] ) ) { throw new \ Exception ( "The shard '$shard_name' was not found!" ) ; return null ; } if ( empty ( $ this -> shard_table [ $ shard_name ] [ "dbworker" ] ) ) { $ this -> shard_table [ $ shard_name ] [ "dbworker" ] = dbworker ( $ this -> shard_table [ $ shard_name ] [ "parameters" ] , true ) ; } return $ this -> shard_table [ $ shard_name ] [ "dbworker" ] ; }
The method dbshard provides the DBWorker object for working with the shard .
45,942
public function findByFileId ( $ fileId ) { foreach ( $ this -> volumes as $ volume ) { try { $ file = $ volume -> findFile ( $ fileId ) ; if ( $ file ) { return $ volume ; } } catch ( \ Exception $ e ) { } } return null ; }
Return volume by file ID .
45,943
public function findByFolderId ( $ folderId ) { foreach ( $ this -> volumes as $ volume ) { if ( $ volume -> findFolder ( $ folderId ) ) { return $ volume ; } } return null ; }
Return volume by folder ID .
45,944
public function get ( ) { $ result = $ this -> _environment ? $ this -> _environment -> getenv ( $ this -> _name ) : getenv ( $ this -> _name ) ; return $ result !== false ? $ result : null ; }
Returns the command as found in the environment variable .
45,945
protected function getMessageFile ( $ category , $ language ) { if ( ! isset ( $ this -> _files [ $ category ] [ $ language ] ) ) { if ( ( $ pos = strpos ( $ category , '.' ) ) !== false && strpos ( $ category , 'ciims' ) === false ) { $ extensionClass = substr ( $ category , 0 , $ pos ) ; $ extensionCategory = substr ( $ category , $ pos + 1 ) ; if ( isset ( $ this -> extensionPaths [ $ extensionClass ] ) ) $ this -> _files [ $ category ] [ $ language ] = Yii :: getPathOfAlias ( $ this -> extensionPaths [ $ extensionClass ] ) . DS . $ language . DS . $ extensionCategory . '.php' ; else { if ( strpos ( $ extensionClass , 'themes' ) !== false ) { $ baseClass = explode ( '.' , $ extensionCategory ) ; $ theme = $ baseClass [ 0 ] ; unset ( $ baseClass [ 0 ] ) ; $ baseClass = implode ( '.' , $ baseClass ) ; $ this -> _files [ $ category ] [ $ language ] = Yii :: getPathOfAlias ( "base.themes.$theme.messages" ) . DS . $ language . DS . $ baseClass . '.php' ; } else { if ( isset ( Yii :: app ( ) -> controller -> module -> id ) ) $ extensionClass .= 'Module' ; $ class = new ReflectionClass ( $ extensionClass ) ; $ this -> _files [ $ category ] [ $ language ] = dirname ( $ class -> getFileName ( ) ) . DS . 'messages' . DS . $ language . DS . $ extensionCategory . '.php' ; } } } else { if ( strpos ( $ category , 'ciims.' ) !== false ) { $ this -> basePath = Yii :: getPathOfAlias ( 'application.messages.' ) ; $ this -> _files [ $ category ] [ $ language ] = $ this -> basePath . DS . $ language . DS . str_replace ( '.' , '/' , str_replace ( 'ciims.' , '' , $ category ) ) . '.php' ; } else $ this -> _files [ $ category ] [ $ language ] = $ this -> basePath . DS . $ language . DS . $ category . '.php' ; } } return $ this -> _files [ $ category ] [ $ language ] ; }
Direct overload of getMessageFile
45,946
public function parse ( \ Pinocchio \ Pinocchio $ pinocchio , \ Pinocchio \ Highlighter \ HighlighterInterface $ highlighter = null ) { if ( null === $ highlighter ) { $ highlighter = new Pygments ( ) ; } $ code = '' ; $ docBlocks = array ( '' ) ; $ previousToken = null ; $ commentRegexSet = $ this -> getCommentRegexSet ( ) ; foreach ( $ this -> tokenize ( $ pinocchio -> getSource ( ) ) as $ token ) { if ( is_array ( $ token ) ) { if ( $ this -> isComment ( token_name ( $ token [ 0 ] ) ) ) { $ last = '' ; $ token [ 1 ] = str_replace ( "\t" , self :: TAB_AS_SPACES , $ token [ 1 ] ) ; if ( token_name ( $ previousToken [ 0 ] ) === self :: TOKEN_NAME_COMMENT && token_name ( $ token [ 0 ] ) === self :: TOKEN_NAME_COMMENT ) { $ last = array_pop ( $ docBlocks ) ; } else { $ code .= self :: CODEBLOCK_DELIMITER ; } $ docBlocks [ ] = $ last . preg_replace ( $ commentRegexSet , '$1' , $ token [ 1 ] ) ; } else { $ code .= $ token [ 1 ] ; } } else { $ code .= $ token ; } $ previousToken = $ token ; } $ codeBlocks = explode ( self :: HIGHLIGHTED_CODEBLOCK_DELIMITER , $ highlighter -> highlight ( 'php' , $ code ) ) ; foreach ( $ codeBlocks as $ codeBlock ) { $ pinocchio -> addCodeBlock ( sprintf ( self :: HIGHLIGHT_BLOCK_HTML_PATTERN , str_replace ( "\t" , ' ' , $ codeBlock ) ) ) ; } $ pinocchio -> setDocBlocks ( $ this -> parseDocblocks ( $ docBlocks ) ) ; return $ pinocchio ; }
Parse a Pinocchio instance .
45,947
public function getCommentRegexSet ( ) { return array ( self :: REGEX_COMMENT_SINGLE_LINE , self :: REGEX_COMMENT_MULTILINE_START , self :: REGEX_COMMENT_MULTILINE_CONT , self :: REGEX_COMMENT_MULTILINE_END , self :: REGEX_COMMENT_MULTILINE_ONE_LINER , ) ; }
Get the set of regular expressions that represent the different comment blocks that might be found in the PHP code .
45,948
protected function parseDocblocks ( $ rawDocBlocks ) { $ parsedDocBlocks = array ( ) ; $ docBlockParser = new MarkdownParser ( ) ; foreach ( $ rawDocBlocks as $ docBlock ) { $ docBlock = preg_replace ( self :: REGEX_DOCBLOCK_TYPE , '$1$2 `$4` ' , $ docBlock ) ; $ docBlock = preg_replace ( self :: REGEX_DOCBLOCK_VAR , '$1`$2`' , $ docBlock ) ; $ docBlock = preg_replace ( self :: REGEX_DOCBLOCK_ARG , "\n<em class=\"docparam\">$1</em>" , $ docBlock ) ; $ parsedDocBlocks [ ] = $ docBlockParser -> transformMarkdown ( $ docBlock ) ; } return $ parsedDocBlocks ; }
Parse the given documentation blocks with a Markdown parser and return the resulting formatted blocks as HTML snippets .
45,949
public function update ( $ new_instance , $ old_instance ) { $ post_types = get_post_types ( ) ; $ selected = isset ( $ _REQUEST [ $ this -> get_field_id ( 'post_type' ) ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST [ $ this -> get_field_id ( 'post_type' ) ] ) ) : false ; if ( in_array ( $ selected , $ post_types , true ) ) { $ new_instance [ 'post_type' ] = $ selected ; } $ number = isset ( $ _REQUEST [ $ this -> get_field_id ( 'number' ) ] ) ? absint ( $ _REQUEST [ $ this -> get_field_id ( 'number' ) ] ) : false ; $ new_instance [ 'number' ] = $ number ; return $ new_instance ; }
Save the post type
45,950
public static function GetAndStoreUsersInSession ( $ caller ) { $ users = array ( ) ; if ( ! $ caller -> app ( ) -> user ( ) -> getAttribute ( \ Puzzlout \ Framework \ Enums \ SessionKeys :: AllUsers ) ) { $ manager = $ caller -> managers ( ) -> getDalInstance ( $ caller -> module ( ) ) ; $ users = $ manager -> selectAllUsers ( ) ; $ caller -> app ( ) -> user -> setAttribute ( \ Puzzlout \ Framework \ Enums \ SessionKeys :: AllUsers , $ users ) ; } else { $ users = $ caller -> app ( ) -> user -> getAttribute ( \ Puzzlout \ Framework \ Enums \ SessionKeys :: AllUsers ) ; } return $ users ; }
Checks if the users are not stored in Session . Stores the users Set the data into the session for later use .
45,951
public static function AddNewUserToSession ( $ caller , $ user ) { $ users = self :: GetAndStoreUsersInSession ( $ caller ) ; $ users [ ] = $ user ; $ caller -> app ( ) -> user -> setAttribute ( \ Puzzlout \ Framework \ Enums \ SessionKeys :: AllUsers , $ users ) ; }
Add new user in session
45,952
public static function CategorizeUsersList ( $ users ) { $ list = array ( ) ; if ( is_array ( $ users ) && count ( $ users ) > 0 ) { foreach ( $ users as $ user ) { $ userType = $ user -> user_type ( ) ; $ list [ $ userType ] [ ] = $ user ; } } return $ list ; }
Categorize user list by type
45,953
private static function getProxyString ( ) : ? string { $ proxyString = null ; if ( \ getenv ( 'HTTP_CLIENT_IP' ) ) { $ proxyString = \ getenv ( 'HTTP_CLIENT_IP' ) ; } elseif ( \ getenv ( 'HTTP_X_FORWARDED_FOR' ) ) { $ proxyString = \ getenv ( 'HTTP_X_FORWARDED_FOR' ) ; } elseif ( \ getenv ( 'HTTP_X_FORWARDED' ) ) { $ proxyString = \ getenv ( 'HTTP_X_FORWARDED' ) ; } elseif ( \ getenv ( 'HTTP_X_COMING_FROM' ) ) { $ proxyString = \ getenv ( 'HTTP_X_COMING_FROM' ) ; } elseif ( \ getenv ( 'HTTP_FORWARDED_FOR' ) ) { $ proxyString = \ getenv ( 'HTTP_FORWARDED_FOR' ) ; } elseif ( \ getenv ( 'HTTP_FORWARDED' ) ) { $ proxyString = \ getenv ( 'HTTP_FORWARDED' ) ; } elseif ( \ getenv ( 'HTTP_COMING_FROM' ) ) { $ proxyString = \ getenv ( 'HTTP_COMING_FROM' ) ; } return $ proxyString ; }
Check and returns proxy string
45,954
private static function getFirstIP ( $ proxyString = '' ) : ? string { \ preg_match ( '/^(([0-9]{1,3}\.){3}[0-9]{1,3})/' , $ proxyString , $ matches ) ; return ( \ is_array ( $ matches ) && isset ( $ matches [ 1 ] ) ) ? $ matches [ 1 ] : null ; }
Checks for first IP in proxy string and returns it
45,955
private static function getFullIpHost ( $ clientIpHost = null , $ proxyIpHost = null ) : ? string { $ fullIpHost = [ ] ; if ( $ clientIpHost !== null ) { $ fullIpHost [ ] = \ sprintf ( 'client: %s' , $ clientIpHost ) ; } if ( $ proxyIpHost !== null ) { $ fullIpHost [ ] = \ sprintf ( 'proxy: %s' , $ proxyIpHost ) ; } return ( \ count ( $ fullIpHost ) > 0 ) ? \ implode ( ', ' , $ fullIpHost ) : null ; }
Returns full ip host string
45,956
public static function check ( ) : array { $ remoteAddr = \ getenv ( 'REMOTE_ADDR' ) ? : null ; $ httpVia = \ getenv ( 'HTTP_VIA' ) ? : null ; $ proxyString = static :: getProxyString ( ) ; $ ipData = static :: $ ipData ; if ( $ remoteAddr !== null ) { if ( $ proxyString !== null ) { $ clientIP = static :: getFirstIP ( $ proxyString ) ; $ proxyIP = $ remoteAddr ; $ proxyHost = static :: getHost ( $ proxyIP ) ; if ( $ clientIP !== null ) { $ clientHost = static :: getHost ( $ clientIP ) ; $ ipData [ 'CLIENT_IP' ] = $ clientIP ; $ ipData [ 'CLIENT_HOST' ] = $ clientHost ; $ ipData [ 'CLIENT_IP_HOST' ] = \ sprintf ( '%s (%s)' , $ clientIP , $ clientHost ) ; } $ ipData [ 'PROXY_IP' ] = $ proxyIP ; $ ipData [ 'PROXY_HOST' ] = $ proxyHost ; $ ipData [ 'PROXY_IP_HOST' ] = \ sprintf ( '%s (%s)' , $ proxyIP , $ proxyHost ) ; $ ipData [ 'PROXY_STRING' ] = $ proxyString ; } elseif ( $ httpVia !== null ) { $ proxyHost = static :: getHost ( $ remoteAddr ) ; $ ipData [ 'PROXY_IP' ] = $ remoteAddr ; $ ipData [ 'PROXY_HOST' ] = $ proxyHost ; $ ipData [ 'PROXY_IP_HOST' ] = \ sprintf ( '%s (%s)' , $ remoteAddr , $ proxyHost ) ; $ ipData [ 'HTTP_VIA' ] = $ httpVia ; } else { $ clientHost = static :: getHost ( $ remoteAddr ) ; $ ipData [ 'CLIENT_IP' ] = $ remoteAddr ; $ ipData [ 'CLIENT_HOST' ] = $ clientHost ; $ ipData [ 'CLIENT_IP_HOST' ] = \ sprintf ( '%s (%s)' , $ remoteAddr , $ clientHost ) ; } $ ipData [ 'FULL_IP_HOST' ] = static :: getFullIpHost ( $ ipData [ 'CLIENT_IP_HOST' ] , $ ipData [ 'PROXY_IP_HOST' ] ) ; } return $ ipData ; }
Checks for visitor IP address proxy address and returns them
45,957
public function getAttributesString ( array $ attributes = array ( ) ) { $ attributesString = '' ; foreach ( $ attributes as $ name => $ values ) { $ value = is_array ( $ values ) ? implode ( ' ' , $ values ) : $ values ; $ attributesString .= ' ' . $ name . '="' . $ value . '"' ; } return $ attributesString ; }
Returns an string for the given attributes ready to be places in an html element
45,958
public function update ( array $ options = array ( ) ) { $ options += self :: $ updateDefaults ; if ( empty ( $ options [ 'table' ] ) ) { throw new Exception ( 'Empty table option' ) ; } if ( empty ( $ options [ 'what' ] ) ) { throw new Exception ( 'No field' ) ; } $ OPTIONS = '' ; $ OPTIONS .= ( ! empty ( $ options [ 'lowpriority' ] ) ) ? ' LOW_PRIORITY' : '' ; $ OPTIONS .= ( ! empty ( $ options [ 'ignore' ] ) ) ? ' IGNORE' : '' ; $ WHAT = $ this -> formatFieldList ( $ options [ 'what' ] ) ; $ WC = ( ! empty ( $ options [ 'where' ] ) ) ? 'WHERE ' . $ options [ 'where' ] : '' ; $ ORDERBY = ( ! empty ( $ options [ 'orderby' ] ) ) ? 'ORDER BY ' . $ options [ 'orderby' ] : '' ; $ LIMIT = ( $ options [ 'number' ] > 0 ) ? 'LIMIT ' . ( ( $ options [ 'offset' ] > 0 ) ? $ options [ 'offset' ] . ', ' : '' ) . $ options [ 'number' ] : '' ; $ TABLE = static :: escapeIdentifier ( $ options [ 'table' ] ) ; $ QUERY = "UPDATE {$OPTIONS} {$TABLE} SET {$WHAT} {$WC} {$ORDERBY} {$LIMIT}" ; if ( $ options [ 'output' ] == static :: SQLQUERY ) { return $ QUERY ; } return $ this -> query ( $ QUERY , PDOEXEC ) ; }
Update something in database
45,959
public function insert ( array $ options = array ( ) ) { $ options += self :: $ insertDefaults ; if ( empty ( $ options [ 'table' ] ) ) { throw new Exception ( 'Empty table option' ) ; } if ( empty ( $ options [ 'what' ] ) ) { throw new Exception ( 'No field' ) ; } $ OPTIONS = '' ; $ OPTIONS .= ( ! empty ( $ options [ 'lowpriority' ] ) ) ? ' LOW_PRIORITY' : ( ! empty ( $ options [ 'delayed' ] ) ) ? ' DELAYED' : '' ; $ OPTIONS .= ( ! empty ( $ options [ 'ignore' ] ) ) ? ' IGNORE' : '' ; $ OPTIONS .= ( ! empty ( $ options [ 'into' ] ) ) ? ' INTO' : '' ; $ COLS = $ WHAT = '' ; if ( is_array ( $ options [ 'what' ] ) ) { if ( ! empty ( $ options [ 'what' ] [ 0 ] ) ) { $ COLS = '(`' . implode ( '`, `' , array_keys ( $ options [ 'what' ] [ 0 ] ) ) . '`)' ; foreach ( $ options [ 'what' ] as $ row ) { $ WHAT .= ( ! empty ( $ WHAT ) ? ', ' : '' ) . '(' . implode ( ', ' , $ row ) . ')' ; } $ WHAT = 'VALUES ' . $ WHAT ; } else { $ WHAT = 'SET ' . $ this -> formatFieldList ( $ options [ 'what' ] ) ; } } else { $ WHAT = $ options [ 'what' ] ; } $ TABLE = static :: escapeIdentifier ( $ options [ 'table' ] ) ; $ QUERY = "INSERT {$OPTIONS} {$TABLE} {$COLS} {$WHAT}" ; if ( $ options [ 'output' ] == static :: SQLQUERY ) { return $ QUERY ; } return $ this -> query ( $ QUERY , PDOEXEC ) ; }
Insert something in database
45,960
public function delete ( array $ options = array ( ) ) { $ options += self :: $ deleteDefaults ; if ( empty ( $ options [ 'table' ] ) ) { throw new Exception ( 'Empty table option' ) ; } $ OPTIONS = '' ; $ OPTIONS .= ( ! empty ( $ options [ 'lowpriority' ] ) ) ? ' LOW_PRIORITY' : '' ; $ OPTIONS .= ( ! empty ( $ options [ 'quick' ] ) ) ? ' QUICK' : '' ; $ OPTIONS .= ( ! empty ( $ options [ 'ignore' ] ) ) ? ' IGNORE' : '' ; $ WC = ( ! empty ( $ options [ 'where' ] ) ) ? 'WHERE ' . $ options [ 'where' ] : '' ; $ ORDERBY = ( ! empty ( $ options [ 'orderby' ] ) ) ? 'ORDER BY ' . $ options [ 'orderby' ] : '' ; $ LIMIT = ( $ options [ 'number' ] > 0 ) ? 'LIMIT ' . ( ( $ options [ 'offset' ] > 0 ) ? $ options [ 'offset' ] . ', ' : '' ) . $ options [ 'number' ] : '' ; $ TABLE = static :: escapeIdentifier ( $ options [ 'table' ] ) ; $ QUERY = "DELETE {$OPTIONS} FROM {$TABLE} {$WC} {$ORDERBY} {$LIMIT}" ; if ( $ options [ 'output' ] == static :: SQLQUERY ) { return $ QUERY ; } return $ this -> query ( $ QUERY , PDOEXEC ) ; }
Delete something in database
45,961
protected function getDimensionsFromTput ( ) : ? array { if ( empty ( $ output = $ this -> execute ( 'tput cols && tput lines' ) ) ) { return null ; } $ output = explode ( "\n" , $ output ) ; return [ 'width' => ( int ) $ output [ 0 ] , 'height' => ( int ) $ output [ 1 ] ] ; }
Executes a combined tput call and parses the results in order to determine the dimensions of the terminal .
45,962
function recover_session ( $ token = '' ) { $ key = Env :: getConfig ( "jwt" ) -> get ( 'key' ) ; $ expiration = Env :: getConfig ( "jwt" ) -> get ( 'token_expiration' ) ; $ cookie_key = Env :: getConfig ( "jwt" ) -> get ( 'cookie_key' ) ; if ( empty ( $ key ) || empty ( $ expiration ) || empty ( $ cookie_key ) ) { throw new Exception ( "critical security failure. Please configure module" , 00 ) ; } $ result = false ; if ( empty ( $ token ) ) { $ token = ( isset ( $ _COOKIE [ $ cookie_key ] ) ) ? $ _COOKIE [ $ cookie_key ] : Env :: getRequest ( ) -> getToken ( ) ; } try { $ decoded = array ( ) ; if ( ! empty ( $ token ) ) { $ decoded = JWT :: decode ( $ token , $ key , array ( 'HS256' ) ) ; if ( $ decoded ) { $ result = true ; $ this -> setToken ( $ token ) ; if ( Env :: getConfig ( "jwt" ) -> get ( 'auto_renew' ) ) { $ this -> create_session ( ( array ) $ decoded -> data ) ; } } } } catch ( \ Firebase \ JWT \ ExpiredException $ e ) { $ this -> setError ( "Expired token, please log in again" , 101 ) ; return false ; } catch ( \ Exception $ e ) { $ this -> setError ( "Invalid token " . var_export ( $ e , true ) , 102 ) ; return false ; } finally { if ( $ result ) { $ this -> setDefaultDatas ( ( array ) $ decoded -> data ) ; return true ; } } return false ; }
Recover a jwt user session from a cookie
45,963
function create_session ( $ data ) { $ key = Env :: getConfig ( "jwt" ) -> get ( 'key' ) ; $ expiration = Env :: getConfig ( "jwt" ) -> get ( 'token_expiration' ) ; $ cookie_key = Env :: getConfig ( "jwt" ) -> get ( 'cookie_key' ) ; $ token = array ( "iss" => $ _SERVER [ 'HTTP_HOST' ] , "iat" => time ( ) , "nbf" => time ( ) , "exp" => time ( ) + ( $ expiration ) , "data" => $ data ) ; $ jwt = JWT :: encode ( $ token , $ key ) ; $ this -> setToken ( $ jwt ) ; $ _SESSION [ $ cookie_key ] = $ jwt ; setcookie ( $ cookie_key , $ jwt , time ( ) + $ expiration , '/' ) ; Env :: getRequest ( ) -> setToken ( $ jwt ) ; $ this -> setDefaultDatas ( $ data ) ; }
Create a jwt user session
45,964
function destroy ( ) { $ cookie_key = Env :: getConfig ( "jwt" ) -> get ( 'cookie_key' ) ; setcookie ( $ cookie_key , '' , time ( ) - 10000 , '/' ) ; unset ( $ _SESSION [ $ cookie_key ] ) ; session_destroy ( ) ; }
Destroy a jwt user session
45,965
public static function getHtmlMail ( $ mailView , $ params , $ to , $ from , $ subject ) { if ( file_exists ( $ mailView ) ) { ob_start ( ) ; require_once $ mailView ; $ body = ob_get_contents ( ) ; ob_end_clean ( ) ; } else { throw new MailViewException ( $ mailView ) ; } $ mail = new MailMessage ( $ to , $ from , $ body , $ subject ) ; $ headers = "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n" . "From: =?UTF-8?B?" . base64_encode ( $ params [ "from_name" ] ) . "?= <" . $ from . ">\r\n" . "X-Mailer: PHP/" . phpversion ( ) ; $ mail -> setHeaders ( $ headers ) ; return $ mail ; }
Get Html Mail with a view .
45,966
public static function getPlainMail ( $ to , $ from , $ body , $ subject ) { $ mail = new MailMessage ( $ to , $ from , $ body , $ subject ) ; return $ mail ; }
Gat a standard plain mail .
45,967
public static function reconstituteFrom ( CommittedEvents $ history ) { $ instance = static :: fromIdentity ( $ history -> getIdentity ( ) ) ; $ instance -> whenAll ( $ history ) ; return $ instance ; }
Reconstructs given concrete aggregate and applies the history
45,968
protected function _containerHas ( $ container , $ key ) { $ key = $ this -> _normalizeKey ( $ key ) ; if ( $ container instanceof BaseContainerInterface ) { return $ container -> has ( $ key ) ; } if ( $ container instanceof ArrayAccess ) { try { return $ container -> offsetExists ( $ key ) ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not check for key "%1$s"' , [ $ key ] ) , null , $ e , null ) ; } } if ( is_array ( $ container ) ) { return array_key_exists ( $ key , $ container ) ; } if ( $ container instanceof stdClass ) { return property_exists ( $ container , $ key ) ; } throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Not a valid container' ) , null , null , $ container ) ; }
Checks for a key on a container .
45,969
public function parse ( ) { $ value = $ this -> getRawValue ( ) ; $ matches = [ ] ; if ( is_array ( $ value ) ) { return $ value ; } if ( preg_match ( self :: NESTED_CONFIGURATION_REGEX , $ value , $ matches ) === 1 ) { return $ this -> parseNestedValue ( $ value , $ matches ) ; } else { return $ this -> parser -> parseIntelligent ( $ value ) ; } }
Parse the configuration value and return the parsed result
45,970
function value ( $ value , $ u = 0 ) { if ( null === $ this -> x ) { $ this -> x = ( 1 / $ this -> measurementVector ) * $ value ; $ this -> cov = ( 1 / $ this -> measurementVector ) * $ this -> measurementNoise * ( 1 / $ this -> measurementVector ) ; } else { $ predX = ( $ this -> stateVector * $ this -> x ) + ( $ this -> controlVector * $ u ) ; $ predCov = ( ( $ this -> stateVector * $ this -> cov ) * $ this -> stateVector ) + $ this -> processNoise ; $ K = $ predCov * $ this -> measurementVector * ( 1 / ( ( $ this -> measurementVector * $ predCov * $ this -> measurementVector ) + $ this -> measurementNoise ) ) ; $ this -> x = $ predX + $ K * ( $ value - ( $ this -> measurementVector * $ predX ) ) ; $ this -> cov = $ predCov - ( $ K * $ this -> measurementVector * $ predCov ) ; } return $ this -> x ; }
Filter a new value
45,971
public function findBy ( array $ wheres , array $ options = [ ] ) { $ query = $ this -> getSqlObject ( ) -> select ( ) ; $ this -> setColumns ( $ query , $ options ) ; $ wheres = $ this -> addJoins ( $ query , $ wheres , $ options ) ; $ this -> addWheres ( $ query , $ wheres , $ options ) ; if ( Arr :: get ( $ options , 'order' ) ) { $ this -> setOrder ( $ query , $ options [ 'order' ] ) ; } return $ this -> executeAndGetResultsAsEntity ( $ query ) ; }
Find a single entity by specific field values
45,972
public function findAllBy ( array $ wheres , array $ options = [ ] ) { $ query = $ this -> getSqlObject ( ) -> select ( ) ; $ this -> setColumns ( $ query , $ options ) ; $ wheres = $ this -> addJoins ( $ query , $ wheres , $ options ) ; $ this -> addWheres ( $ query , $ wheres , $ options ) ; $ page = Arr :: get ( $ options , 'page' ) ; if ( $ page && ! Arr :: get ( $ options , 'order' ) ) { throw new LogicException ( 'Must provide an ORDER BY if using pagination' ) ; } if ( Arr :: get ( $ options , 'order' ) ) { $ this -> setOrder ( $ query , $ options [ 'order' ] ) ; } if ( $ page ) { $ paginationData = $ this -> getPaginationData ( $ query , $ options ) ; $ query -> limit ( $ paginationData -> getResultsPerPage ( ) ) ; $ query -> offset ( ( $ page - 1 ) * $ paginationData -> getResultsPerPage ( ) ) ; } $ entityIterator = $ this -> executeAndGetResultsAsEntityIterator ( $ query ) ; if ( $ page ) { $ entityIterator -> setPaginationData ( $ paginationData ) ; } return $ entityIterator ; }
Find all entities matching specific field values
45,973
protected function setOrder ( Select $ query , array $ order ) { if ( ! is_array ( Arr :: get ( $ order , 0 ) ) ) { $ order = [ $ order ] ; } foreach ( $ order as $ key => $ orderValue ) { if ( is_array ( $ orderValue ) ) { $ query -> order ( Arr :: get ( $ orderValue , 0 ) . ' ' . Arr :: get ( $ orderValue , 1 ) ) ; } } return $ query ; }
Set the order on the given query
45,974
protected function getPaginationData ( Select $ query , array $ options ) { $ page = ( int ) Arr :: get ( $ options , 'page' ) ; if ( $ page < 1 ) { $ page = 1 ; } $ resultsPerPage = Arr :: get ( $ options , 'resultsPerPage' , $ this -> resultsPerPage ) ; $ resultCount = $ this -> getQueryResultCount ( $ query ) ; $ pageCount = ceil ( $ resultCount / $ resultsPerPage ) ; return new PaginationData ( [ 'page' => $ page , 'page_count' => $ pageCount , 'result_count' => $ resultCount , 'results_per_page' => $ resultsPerPage ] ) ; }
Get data object with pagination data like page and page_count
45,975
protected function getQueryResultCount ( Select $ query ) { $ queryString = $ this -> getSqlObject ( ) -> getSqlStringForSqlObject ( $ query , $ this -> dbAdapter -> getPlatform ( ) ) ; $ format = 'Select count(*) as `count` from (%s) as `query_count`' ; $ countQueryString = sprintf ( $ format , $ queryString ) ; $ countQuery = $ this -> dbAdapter -> query ( $ countQueryString ) ; $ result = $ countQuery -> execute ( ) -> current ( ) ; return ( int ) Arr :: get ( $ result , 'count' ) ; }
Get the count of results from a given query
45,976
protected function addWheres ( PreparableSqlInterface $ query , array $ wheres , array $ options = [ ] ) { foreach ( $ wheres as $ key => $ where ) { if ( is_array ( $ where ) && count ( $ where ) === 3 ) { $ leftOpRightSyntax = true ; $ operator = $ where [ 1 ] ; switch ( $ operator ) { case '=' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_EQ , $ where [ 2 ] ) ; break ; case '!=' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_NE , $ where [ 2 ] ) ; break ; case '>' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_GT , $ where [ 2 ] ) ; break ; case '<' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_LT , $ where [ 2 ] ) ; break ; case '>=' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_GTE , $ where [ 2 ] ) ; break ; case '<=' : $ predicate = new Operator ( $ where [ 0 ] , Operator :: OP_LTE , $ where [ 2 ] ) ; break ; case 'LIKE' : $ predicate = new Like ( $ where [ 0 ] , $ where [ 2 ] ) ; break ; case 'NOT LIKE' : $ predicate = new NotLike ( $ where [ 0 ] , $ where [ 2 ] ) ; break ; case 'IN' : $ predicate = new In ( $ where [ 0 ] , $ where [ 2 ] ) ; break ; case 'NOT IN' : $ predicate = new NotIn ( $ where [ 0 ] , $ where [ 2 ] ) ; break ; case 'IS' : $ predicate = new IsNull ( $ where [ 0 ] ) ; break ; case 'IS NOT' : $ predicate = new IsNotNull ( $ where [ 0 ] ) ; break ; default : $ leftOpRightSyntax = false ; break ; } if ( $ leftOpRightSyntax === false ) { $ predicate = [ $ key => $ where ] ; } } else { $ predicate = [ $ key => $ where ] ; } $ query -> where ( $ predicate ) ; } return $ query ; }
Add where clauses to query
45,977
protected function _setValidator ( $ validator ) { if ( ! is_null ( $ validator ) && ! ( $ validator instanceof ValidatorInterface ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid validator' ) , null , null , $ validator ) ; } $ this -> validator = $ validator ; }
Assigns a validator to this instance .
45,978
protected function getMatchedParameters ( array $ matches ) : array { $ parameters = [ ] ; foreach ( $ matches as $ key => $ match ) { if ( is_string ( $ key ) ) { $ parameters [ $ key ] = $ match [ 0 ] ; } } return array_replace_recursive ( $ this -> getParameters ( ) , $ parameters ) ; }
Get the parameters when the route is matched .
45,979
protected function getPattern ( ) : string { $ path = preg_replace_callback ( '~:([a-z][a-z0-9\_]+)~i' , function ( $ match ) { return sprintf ( '(?<%s>%s)' , $ match [ 1 ] , '[^\/]*' ) ; } , $ this -> getPath ( ) ) ; return sprintf ( '~\G(%s)(/|\z)~' , $ path ) ; }
Get pattern to match request path .
45,980
public function prepareEmailDataForInsert ( $ request ) { $ data = [ ] ; $ data [ 'email_type_id' ] = 1 ; $ data [ 'title' ] = $ request -> input ( 'email' ) ; $ data [ 'description' ] = "" ; $ data [ 'comments' ] = "Created by front-end subscription to an email list" ; $ data [ 'created_at' ] = Carbon :: now ( ) ; $ data [ 'created_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; $ data [ 'updated_at' ] = Carbon :: now ( ) ; $ data [ 'updated_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; return $ data ; }
Prepare the data for creating a new record in the emails db table
45,981
public function prepareList_emailDataForInsert ( $ input ) { $ data = [ ] ; $ data [ 'title' ] = $ input [ 'listID' ] . " " . $ input [ 'emailID' ] ; $ data [ 'list_id' ] = $ input [ 'listID' ] ; $ data [ 'email_id' ] = $ input [ 'emailID' ] ; $ data [ 'comments' ] = "" ; $ data [ 'enabled' ] = 1 ; $ data [ 'created_at' ] = Carbon :: now ( ) ; $ data [ 'created_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; $ data [ 'updated_at' ] = Carbon :: now ( ) ; $ data [ 'updated_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; return $ data ; }
Prepare the data for creating a new record in the list_email db table
45,982
public function preparePeoplesDataForInsert ( $ input ) { $ data = [ ] ; $ data [ 'user_id' ] = null ; $ data [ 'title' ] = $ input [ 'first_name' ] . " " . $ input [ 'surname' ] ; $ data [ 'salutation' ] = "" ; $ data [ 'first_name' ] = $ input [ 'first_name' ] ; $ data [ 'middle_name' ] = "" ; $ data [ 'surname' ] = $ input [ 'surname' ] ; $ data [ 'position' ] = "" ; $ data [ 'description' ] = "" ; $ data [ 'comments' ] = "Created by front-end subscription to an email list" ; $ data [ 'birthday' ] = null ; $ data [ 'anniversary' ] = null ; $ data [ 'created_at' ] = Carbon :: now ( ) ; $ data [ 'created_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; $ data [ 'updated_at' ] = Carbon :: now ( ) ; $ data [ 'updated_by' ] = $ this -> userRepository -> getFirstAmongEqualsUserID ( ) ; $ data [ 'profile' ] = null ; $ data [ 'featured_image' ] = null ; return $ data ; }
Prepare the data for creating a new record in the peoplesl db table
45,983
protected function getValidReturnUri ( $ returnUri , $ default = null ) { $ match = array ( ) ; $ returnUri = ltrim ( str_replace ( '\\' , '/' , $ returnUri ) , "\n\r\t\v\e\f" ) ; if ( ! preg_match ( '#^/([^/].*)?$#' , $ returnUri , $ match ) ) { return $ default ; } return $ returnUri ; }
Gte valid return - uri
45,984
public function exportAction ( ) { $ params = $ this -> params ( ) ; $ paragraphId = $ params -> fromRoute ( 'paragraphId' ) ; $ serviceLocator = $ this -> getServiceLocator ( ) ; $ paragraphModel = $ serviceLocator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) ; $ paragraph = $ paragraphModel -> find ( $ paragraphId ) ; if ( empty ( $ paragraph ) ) { $ this -> getResponse ( ) -> setResultCode ( 404 ) ; return ; } $ zipFile = $ serviceLocator -> get ( 'Grid\Customize\Model\Exporter' ) -> export ( $ paragraph -> id ) ; $ name = strtolower ( $ paragraph -> name ) ; if ( empty ( $ name ) ) { $ name = 'paragraph-' . $ paragraph -> id ; } $ response = Readfile :: fromFile ( $ zipFile , 'application/zip' , $ name . '.zip' , true ) ; $ this -> getEvent ( ) -> setResponse ( $ response ) ; return $ response ; }
Export paragraph action
45,985
protected function authenticateExternalMember ( $ data , ValidationResult & $ result = null , Member $ member = null ) { $ result = $ result ? : ValidationResult :: create ( ) ; $ ssLoginUserName = Environment :: getEnv ( 'SS_DEFAULT_ADMIN_USERNAME' ) ; $ email = ! empty ( $ data [ 'Email' ] ) ? $ data [ 'Email' ] : null ; if ( $ email != $ ssLoginUserName ) { return ; } $ member = Member :: get ( ) -> find ( Member :: config ( ) -> get ( 'unique_identifier_field' ) , $ ssLoginUserName ) ; if ( ! $ member ) { return ; } $ member -> checkLoginPassword ( $ data [ 'Password' ] , $ result ) ; return $ member ; }
Attempt to find and authenticate external member if possible from the given data
45,986
private function saveReport ( JobConfigurationInterface $ configuration ) { $ report = $ this -> reportManager -> create ( $ configuration ) ; $ report -> setEndedAt ( ) -> setOutput ( 'Job was dead and restored.' ) -> setSuccessful ( true ) ; $ this -> reportManager -> add ( $ report , true ) ; }
Create restored job report .
45,987
private function isDead ( JobConfigurationInterface $ configuration ) { $ report = $ this -> reportManager -> getLastStartedByConfiguration ( $ configuration ) ; return $ report && $ report -> getPid ( ) && ( false === $ report -> isSuccessful ( ) ) && ! posix_getsid ( $ report -> getPid ( ) ) ; }
Checks or job is dead .
45,988
public function WriteContent ( ) { $ output = $ this -> WriteGetListMethod ( ) ; $ output .= PhpCodeSnippets :: CRLF ; fwrite ( $ this -> writer , $ output ) ; }
Write the content of the class method by method .
45,989
public function WriteNewArrayAndItsContents ( $ array , $ arrayOpened = false , $ tabAmount = 0 ) { $ output = "" ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ output .= $ this -> WriteAssociativeArrayValueAsNewArray ( $ key , $ tabAmount ) ; $ output .= $ this -> WriteNewArrayAndItsContents ( $ value , true , $ tabAmount ) ; } else { $ output .= $ this -> WriteAssociativeArrayValueWithKeyAndValue ( $ key , $ value , $ tabAmount ) ; } } if ( $ arrayOpened ) { $ output .= $ this -> CloseArray ( $ tabAmount - 1 ) ; } return $ output ; }
Recursively writes an array from an array of values .
45,990
public function ackAction ( ) { $ json = array ( ) ; $ postId = $ this -> params ( ) -> fromQuery ( 'postid' , null ) ; $ response = $ this -> mattermost -> saveReaction ( $ postId , 'ok' ) ; $ json [ 'result' ] = $ response ; return new JsonModel ( $ json ) ; }
Post a ok reaction to send an acknowledge
45,991
public function isAckAction ( ) { $ json = array ( ) ; $ postId = $ this -> params ( ) -> fromQuery ( 'postid' , null ) ; $ myReactions = $ this -> mattermost -> getMyReactions ( $ postId ) ; $ ok = array_filter ( $ myReactions , function ( $ v ) { return strcmp ( $ v [ 'emoji_name' ] , 'ok' ) == 0 ; } ) ; $ json [ 'ack' ] = count ( $ ok ) == 1 ; return new JsonModel ( $ json ) ; }
Test if the post has a ok reaction signifying the post has already been aknowledged
45,992
public function migrate ( array $ filters ) { $ this -> filters = $ filters ; foreach ( $ this -> academicPeriods ( ) as $ period ) { $ this -> period = $ period -> id ; $ this -> setDestinationConnectionByPeriod ( $ this -> period ) ; $ this -> switchToDestinationConnection ( ) ; $ this -> output -> info ( 'Migrating period: ' . $ period -> name . '(' . $ period -> id . ')' ) ; $ this -> migrateTeachers ( ) ; $ this -> migrateLocations ( ) ; $ this -> migrateCurriculum ( ) ; $ this -> migrateClassrooms ( ) ; $ this -> migrateEnrollments ( ) ; $ this -> seedDays ( ) ; $ this -> seedShifts ( ) ; $ this -> migrateTimeslots ( ) ; $ this -> migrateLessons ( ) ; } }
Migrate old database to new database .
45,993
protected function migrateTeachers ( ) { $ this -> output -> info ( '### Migrating teachers ###' ) ; foreach ( $ this -> teachers ( ) as $ teacher ) { $ this -> showMigratingInfo ( $ teacher , 1 ) ; $ this -> output -> info ( ' email: ' . $ teacher -> email ) ; $ this -> migrateTeacher ( $ teacher ) ; } $ this -> output -> info ( '### END Migrating teachers. Migrated ' . count ( $ this -> teachers ( ) ) . ' teachers ###' ) ; }
Migrate teachers .
45,994
protected function migrateTeacher ( Teacher $ teacher ) { $ user = User :: firstOrNew ( [ 'email' => $ teacher -> email , ] ) ; $ user -> name = $ teacher -> name ; $ user -> password = bcrypt ( 'secret' ) ; $ user -> remember_token = str_random ( 10 ) ; $ user -> save ( ) ; }
Migrate teacher .
45,995
protected function migrateEnrollment ( $ enrollment ) { $ user = $ this -> migratePerson ( $ enrollment -> person ) ; try { $ enrollment = ScoolEnrollment :: firstOrNew ( [ 'user_id' => $ user -> id , 'study_id' => $ this -> translateStudyId ( $ enrollment -> study_id ) , 'course_id' => $ this -> translateCourseId ( $ enrollment -> course_id ) , 'classroom_id' => $ this -> translateClassroomId ( $ enrollment -> group_id ) ] ) ; $ enrollment -> state = 'Validated' ; $ enrollment -> save ( ) ; return $ enrollment ; } catch ( \ Exception $ e ) { $ this -> output -> error ( 'Error migrating enrollment. ' . class_basename ( $ e ) . ' ' . $ e -> getMessage ( ) ) ; return null ; } }
Migrate ebre - escool enrollment to scool enrollment .
45,996
protected function migrateLesson ( $ oldLesson ) { if ( $ this -> lessonNotExists ( $ oldLesson ) ) { DB :: beginTransaction ( ) ; try { $ lesson = new ScoolLesson ; $ lesson -> location_id = $ this -> translateLocationId ( $ oldLesson -> location_id ) ; $ lesson -> day_id = $ this -> translateDayId ( $ oldLesson -> day ) ; $ lesson -> timeslot_id = $ this -> translateTimeslotId ( $ oldLesson -> time_slot_id ) ; $ lesson -> state = 'Validated' ; $ lesson -> save ( ) ; $ lesson -> addTeacher ( $ this -> translateTeacher ( $ oldLesson -> teacher_id ) ) ; $ module = Module :: findOrFail ( $ this -> translateModuleId ( $ oldLesson -> study_module_id ) ) ; foreach ( $ module -> submodules as $ submodule ) { $ lesson -> addSubmodule ( $ submodule ) ; } $ classroom = Classroom :: findOrFail ( $ this -> translateClassroomId ( $ oldLesson -> classroom_group_id ) ) ; $ lesson -> addClassroom ( $ classroom ) ; $ lesson_migration = new LessonMigration ( ) ; $ lesson_migration -> newlesson_id = $ lesson -> id ; $ lesson_migration -> lesson ( ) -> associate ( $ oldLesson ) ; $ lesson_migration -> save ( ) ; DB :: commit ( ) ; } catch ( \ Exception $ e ) { DB :: rollBack ( ) ; $ this -> output -> error ( 'Error migrating lesson. ' . class_basename ( $ e ) . ' ' . $ e -> getMessage ( ) ) ; return null ; } } }
Migrate lesson .
45,997
protected function migrateEnrollmentDetail ( $ enrollmentDetail , $ enrollment_id ) { try { $ enrollment = ScoolEnrollmentSubmodule :: firstOrNew ( [ 'enrollment_id' => $ enrollment_id , 'module_id' => $ this -> translateModuleId ( $ enrollmentDetail -> moduleid ) , 'submodule_id' => $ this -> translateSubmoduleId ( $ enrollmentDetail -> submoduleid ) , ] ) ; $ enrollment -> state = 'Validated' ; $ enrollment -> save ( ) ; } catch ( \ Exception $ e ) { $ this -> output -> error ( 'Error migrating enrollment detail. ' . class_basename ( $ e ) . ' ' . $ e -> getMessage ( ) ) ; } }
Migrate ebre - escool enrollment detail to scool enrollment .
45,998
protected function translateLocationId ( $ oldLocationId ) { $ location = ScoolLocation :: where ( 'name' , Location :: findOrFail ( $ oldLocationId ) -> name ) -> first ( ) ; if ( $ location != null ) { return $ location -> id ; } throw new LocationNotFoundByNameException ( ) ; }
Translate location id .
45,999
protected function translateTimeslotId ( $ oldTimeslotId ) { $ timeslot = ScoolTimeslot :: where ( 'order' , Timeslot :: findOrFail ( $ oldTimeslotId ) -> order ) -> first ( ) ; if ( $ timeslot != null ) { return $ timeslot -> id ; } throw new TimeslotNotFoundByNameException ( ) ; }
Translate timeslot id .