idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
9,100
public static function mergeDeep ( array $ a , array $ b ) : array { $ result = $ a ; foreach ( $ b as $ k => $ v ) { if ( \ is_int ( $ k ) ) { $ result [ ] = $ v ; continue ; } if ( ! \ array_key_exists ( $ k , $ result ) ) { $ result [ $ k ] = $ v ; continue ; } if ( \ is_array ( $ result [ $ k ] ) ) { if ( \ is_arra...
Deep merge of arrays eventualy combining nested arrays .
9,101
public function dump ( $ value , int $ output = self :: OUTPUT_ECHO ) : string { switch ( $ output ) { case self :: OUTPUT_ECHO : echo $ this -> style -> wrapContainer ( $ this -> dumpValue ( $ value , '' , 0 ) ) ; break ; case self :: OUTPUT_LOG : if ( ! empty ( $ this -> logger ) ) { $ this -> logger -> debug ( $ thi...
Dump specified value . Dumper will automatically detect CLI mode in OUTPUT_ECHO mode .
9,102
public function record ( Model $ model = null , $ name , $ user = null ) { if ( ! $ this -> isEnabled ( ) ) { return false ; } $ activity = $ this -> initActivity ( ) ; $ user = $ this -> getUserId ( $ user ) ; $ data = [ 'name' => $ name , 'user_id' => $ user ] ; if ( $ model ) { $ data [ 'subject_id' ] = $ model -> g...
Records an activity
9,103
public function delete ( Model $ model , $ user = null ) { if ( ! $ this -> isEnabled ( ) ) { return false ; } $ activity = $ this -> initActivity ( ) ; $ user = $ this -> getUserId ( $ user ) ; $ data = [ 'user_id' => $ user , 'subject_id' => $ model -> getKey ( ) , 'subject_type' => get_class ( $ model ) ] ; $ activi...
Deletes an activity
9,104
protected function getUserId ( $ user ) { if ( is_null ( $ user ) ) { $ user = auth ( ) -> user ( ) ; } if ( $ user instanceof Model ) { $ user = $ user -> getKey ( ) ; } return $ user ; }
Determines current user
9,105
public function getRecords ( $ limit = null , $ name = null ) { $ modelName = $ this -> getModelName ( ) ; $ activity = $ modelName :: with ( 'subject' ) ; if ( ! is_null ( $ limit ) ) { $ activity -> limit ( $ limit ) ; } if ( $ name ) { if ( ! is_array ( $ name ) ) { $ name = [ $ name ] ; } $ activity -> whereIn ( 'n...
Getter for records
9,106
public function getUserActivity ( $ user , $ limit = null , $ name = null ) { $ user = $ this -> getUserId ( $ user ) ; $ modelName = $ this -> getModelName ( ) ; $ activity = $ modelName :: belongsToUser ( $ user ) ; if ( ! is_null ( $ limit ) ) { $ activity -> limit ( $ limit ) ; } if ( $ name ) { if ( ! is_array ( $...
Getter for a users activity
9,107
protected function prepareArtefacts ( $ linkTypeCode , array $ columns ) { $ artefacts = array ( ) ; $ parentSku = $ this -> getValue ( ColumnKeys :: SKU ) ; list ( $ columnNameChildSkus , $ callbackChildSkus ) = array_shift ( $ columns ) ; if ( $ links = $ this -> getValue ( $ columnNameChildSkus , null , $ callbackCh...
Prepare s and return s the artefacts for the passed link type .
9,108
public function onKernelRequest ( GetResponseEvent $ event ) { $ this -> setUpRequiredFolders ( ) ; $ this -> setUpPageTree ( ) ; $ this -> checkTemplatesSlots ( ) ; $ this -> setupBootstrapVersion ( ) ; $ this -> setupConfiguration ( ) ; }
Listen to onKernelRequest to check and configure RedKiteCms
9,109
private function normalizeCmsRequestAttributes ( Request $ request , DataManager $ dataManager ) { if ( $ request -> getMethod ( ) == 'POST' ) { return ; } $ page = $ dataManager -> getPage ( ) ; if ( null !== $ page ) { $ request -> attributes -> set ( 'page' , $ page -> getPageName ( ) ) ; } $ language = $ dataManage...
Normalizes the request attributes for page language and permalink for a GET request
9,110
public function finishView ( FormView $ view , FormInterface $ form , array $ options ) { $ data = $ this -> context -> getCurrentNodeId ( ) ; if ( ! $ view -> parent && $ options [ 'compound' ] and ! empty ( $ data ) ) { $ factory = $ form -> getConfig ( ) -> getFormFactory ( ) ; $ form = $ factory -> createNamed ( $ ...
Adds a Node ID field to the root form view .
9,111
protected function dispatchCurrentPageEvent ( Request $ request ) { $ pageName = $ request -> get ( 'page' ) ; $ seo = $ this -> seoRepository -> fromPermalink ( $ pageName ) ; if ( null !== $ seo ) { $ page = $ this -> pageRepository -> fromPk ( $ seo -> getPageId ( ) ) ; $ pageName = $ page -> getPageName ( ) ; } $ e...
Overrides the base method to replace the permalink when it is used instad of the page name
9,112
public function add ( $ name , $ sid = NULL ) { $ user = new User ; if ( ! $ user -> isAdmin ( $ sid ) ) throw new \ JohnVanOrange \ Core \ Exception \ NotAllowed ( 'Must be an admin to access method' , 401 ) ; if ( strlen ( $ name ) < 1 OR $ name == NULL ) throw new \ Exception ( 'Tag name cannot be empty' ) ; $ tag =...
Add to blacklist
9,113
private function getErrorPage ( ErrorBag $ errorBag ) { $ code = $ errorBag -> getCode ( ) ; $ data = [ 'bag' => $ errorBag , 'errorBag' => $ errorBag ] ; try { return View :: fetch ( "errors/$code" , $ data ) ; } catch ( Exception $ e ) { return View :: fetch ( "errors/default" , $ data ) ; } }
Return error page content for the given ErrorBag
9,114
static function insertItems ( array $ items ) { foreach ( $ items as $ item ) { if ( ! isset ( $ item [ 'blockID' ] , $ item [ 'objectID' ] , $ item [ 'nodeID' ] , $ item [ 'priority' ] , $ item [ 'timestamp' ] ) ) { eZDebug :: writeError ( "Pool item is missing one of the following information: blockID, objectID, node...
Insert items in the pool
9,115
public function writeTemplate ( $ dir ) { $ fileDir = $ dir . '/' . $ this -> language -> getLanguageName ( ) . $ this -> baseFolder ; if ( ! is_dir ( $ fileDir ) ) { mkdir ( $ fileDir ) ; } return @ file_put_contents ( $ fileDir . '/' . $ this -> fileName . '.html.twig' , $ this -> twigTemplate ) ; }
Writes the template
9,116
protected function verboseIfFileExists ( ConsoleIo $ io , $ path ) { if ( ! file_exists ( $ path ) ) { return false ; } $ io -> verbose ( __d ( 'me_tools' , 'File or directory `{0}` already exists' , rtr ( $ path ) ) ) ; return true ; }
Internal method to check if a file already exists and output a warning at the verbose level
9,117
public function createLink ( ConsoleIo $ io , $ source , $ dest ) { if ( $ this -> verboseIfFileExists ( $ io , $ dest ) ) { return false ; } try { is_readable_or_fail ( $ source ) ; is_writable_or_fail ( dirname ( $ dest ) ) ; } catch ( Exception $ e ) { $ io -> error ( $ e -> getMessage ( ) ) ; return false ; } symli...
Creates a symbolic link
9,118
public function folderChmod ( ConsoleIo $ io , $ path , $ chmod = 0777 ) { if ( ! ( new Folder ( ) ) -> chmod ( $ path , $ chmod , true ) ) { $ io -> error ( __d ( 'me_tools' , 'Failed to set permissions on `{0}`' , rtr ( $ path ) ) ) ; return false ; } $ io -> verbose ( __d ( 'me_tools' , 'Setted permissions on `{0}`'...
Sets folder chmods .
9,119
private function _isClassInList ( $ class , $ classes ) { $ items = explode ( " " , trim ( $ classes ) ) ; if ( count ( $ items ) > 0 ) { foreach ( $ items as $ item ) { if ( strcasecmp ( $ class , trim ( $ item ) ) == 0 ) { return true ; } } } return false ; }
Is a class name in a given list?
9,120
public function loginWithEmail ( Request $ request ) { $ request -> rules = [ 'email' => 'required' ] ; $ request -> validate ( ) ; $ provider = $ this -> provider ; $ info = MagicLink :: notify ( $ request , $ provider , $ this -> musk ( ) ) ; $ this -> sendMagicLinkNotification ( $ info [ 'email' ] , $ info [ 'token'...
Login with rmail
9,121
public function loginEmailCallback ( ) { if ( Get :: has ( 'token' ) ) { $ provider = $ this -> provider ; $ varified = MagicLink :: verify ( Get :: key ( 'token' ) , $ provider , $ this -> musk ( ) ) ; if ( isset ( $ varified -> id ) ) { if ( Auth :: provider ( $ provider ) -> login ( $ varified ) -> status == 'succes...
Login email callback
9,122
public function login ( Request $ request ) { $ hidden = $ this -> hidden ; $ request -> rules = $ this -> rules ( ) ; $ provider = $ this -> provider ; $ user = $ request -> validate ( function ( $ response ) use ( $ request , $ hidden , $ provider ) { return Auth :: attempt ( $ request -> all ( ) , $ hidden , $ provi...
Try to log the user in
9,123
protected function buildRegexp ( $ pattern , array $ matches ) { $ src = [ ] ; $ trg = [ ] ; foreach ( $ matches as $ match ) { list ( $ key , $ regexp ) = $ this -> splitSegment ( $ match [ 3 ] ) ; if ( in_array ( substr ( $ regexp , - 1 ) , [ '+' , '*' , '?' ] ) ) { throw new RouteException ( 'Route must not end with...
Builds regular expression for route matching
9,124
protected function buildRequirements ( array $ matches ) { $ result = [ ] ; foreach ( $ matches as $ match ) { list ( $ key , $ regexp ) = $ this -> splitSegment ( $ match [ 3 ] ) ; $ result [ $ key ] = $ regexp . ( $ match [ 1 ] == '(' ? '*' : '+' ) ; } return $ result ; }
Builds array of regular expression for route arguments
9,125
protected function buildBuilders ( $ pattern , array $ matches ) { $ result = [ 'pattern' => $ pattern , 'segments' => [ ] ] ; foreach ( $ matches as $ match ) { list ( $ key , ) = $ this -> splitSegment ( $ match [ 3 ] ) ; $ result [ 'pattern' ] = str_replace ( $ match [ 0 ] , '{' . $ key . '}' , $ result [ 'pattern' ...
Builds array allowing route creation
9,126
public function arguments ( array $ arguments = [ ] ) { if ( empty ( $ arguments ) ) { return $ this -> arguments ; } foreach ( $ arguments as $ key => $ value ) { if ( ! isset ( $ this -> requirements [ $ key ] ) ) { $ this -> arguments [ $ key ] = $ value ; continue ; } $ this -> assertArgumentValue ( $ key , $ this ...
Sets values for each argument in pattern
9,127
public function host ( $ host = null ) { $ this -> host = empty ( $ host ) ? null : $ host ; return $ this -> host ; }
Sets host requirement
9,128
public function schema ( $ schema = null ) { $ this -> schema = empty ( $ schema ) ? null : $ schema ; return $ this -> schema ; }
Sets allowed schema
9,129
public function match ( RequestInterface $ request ) { return ( $ this -> matchSchema ( $ request -> schema ( ) ) && $ this -> matchMethods ( $ request -> method ( ) ) && $ this -> matchHost ( $ request -> host ( ) ) && $ this -> matchPath ( $ request -> path ( ) ) ) ; }
Returns true if matches request otherwise returns false
9,130
protected function matchSchema ( $ schema ) { if ( empty ( $ this -> schema ) ) { return true ; } if ( strpos ( $ schema , $ this -> schema ) !== false ) { return true ; } return false ; }
Returns true if request matches schema or if no schema restrictions set
9,131
protected function matchMethods ( $ method ) { if ( empty ( $ this -> methods ) ) { return true ; } if ( in_array ( $ method , $ this -> methods ) ) { return true ; } return false ; }
Returns true if request matches methods or if no methods restrictions set
9,132
protected function matchHost ( $ host ) { if ( empty ( $ this -> host ) ) { return true ; } $ host = preg_replace ( '/^[^:]+:\/\//i' , '' , $ host ) ; $ regex = str_replace ( '\{basename\}' , '.*' , preg_quote ( $ this -> host ) ) ; return preg_match ( '/^' . $ regex . '$/i' , $ host ) ; }
Returns true if request matches host or if no host restrictions set
9,133
protected function matchPath ( $ path ) { if ( ! preg_match_all ( $ this -> regex , $ path , $ matches , \ PREG_SET_ORDER ) ) { return false ; } foreach ( $ matches [ 0 ] as $ k => $ v ) { if ( is_numeric ( $ k ) ) { continue ; } $ this -> arguments [ $ k ] = $ v ; } return true ; }
Returns true if request matches pattern
9,134
public function check ( $ controller , array $ arguments = [ ] ) { if ( $ this -> controller !== $ controller ) { return false ; } foreach ( $ this -> requirements as $ key => $ regex ) { $ value = isset ( $ arguments [ $ key ] ) ? $ arguments [ $ key ] : null ; if ( ! preg_match ( '/^' . $ regex . '$/i' , $ value ) ) ...
Check if route should be used to make url
9,135
public function make ( $ host , array $ arguments = [ ] ) { return $ host === null ? $ this -> makeRelative ( $ arguments ) : $ this -> makeAbsolute ( $ host , $ arguments ) ; }
Creates route url
9,136
protected function makeAbsolute ( $ host , array $ arguments = [ ] ) { list ( $ schema , $ host ) = $ this -> resolveHost ( $ host ) ; $ url = $ this -> buildUrl ( $ arguments ) ; $ regex = '/^' . str_replace ( '\{basename\}' , '.*' , preg_quote ( $ this -> host ) ) . '$/' ; if ( $ this -> host && ! preg_match ( $ rege...
Creates absolute url
9,137
protected function resolveHost ( $ host ) { if ( strpos ( $ host , '://' ) !== false ) { list ( $ schema , $ host ) = explode ( '://' , $ host , 2 ) ; } if ( $ this -> schema ) { $ schema = $ this -> schema ; } if ( empty ( $ schema ) ) { $ schema = 'http' ; } return array ( $ schema , $ host ) ; }
Resolves schema and host name with dir from passed basename
9,138
protected function buildUrl ( array $ arguments ) { $ url = strtr ( $ this -> builders [ 'pattern' ] , $ this -> buildUrlRequirements ( $ arguments ) ) ; $ url = str_replace ( '//' , '/' , $ url ) ; $ query = array_filter ( $ arguments ) ; if ( ! empty ( $ query ) ) { $ url .= '?' . http_build_query ( $ query , null , ...
Builds url with passed arguments
9,139
protected function buildUrlRequirements ( array & $ arguments ) { $ url = [ ] ; foreach ( $ this -> requirements as $ key => $ regex ) { $ this -> assertArgumentRequirement ( $ key , $ regex , $ arguments ) ; if ( array_key_exists ( $ key , $ arguments ) && isset ( $ this -> builders [ 'segments' ] [ '{' . $ key . '}' ...
Builds array with url required arguments
9,140
protected function assertArgumentRequirement ( $ key , $ regex , $ arguments ) { if ( substr ( $ regex , - 1 ) === '+' && ! array_key_exists ( $ key , $ arguments ) ) { throw new RouteException ( sprintf ( 'Missing value for argument "%s" in route "%s"' , $ key , $ this -> pattern ) ) ; } }
Asserts required argument matches regex
9,141
protected function assertArgumentValue ( $ key , $ regex , $ value ) { if ( ! preg_match ( '/^' . $ regex . '$/i' , $ value ) ) { throw new RouteException ( sprintf ( 'Invalid value for argument "%s" in route "%s", got "%s" need "/^%s\$/"' , $ key , $ this -> pattern , $ value , $ regex ) ) ; } }
Asserts argument value
9,142
protected function strip ( $ urlString , $ separator = '-' ) { if ( is_numeric ( $ urlString ) ) { return $ urlString ; } $ urlString = iconv ( 'UTF-8' , 'ASCII//TRANSLIT//IGNORE' , $ urlString ) ; $ urlString = preg_replace ( '#[^\w \-\.]+#i' , null , $ urlString ) ; $ urlString = preg_replace ( '/[ -\.]+/' , $ separa...
Strips string from non ASCII chars
9,143
public static function make ( Upstart $ app ) { $ response = $ app -> getResponse ( ) ; if ( method_exists ( $ response , 'toArray' ) ) { $ response = $ response -> toArray ( ) ; } if ( is_string ( $ response ) || is_int ( $ response ) || is_float ( $ response ) || is_double ( $ response ) || is_array ( $ response ) ) ...
Make application response
9,144
public function matchCommand ( Args $ args ) { $ this -> args = $ args ; return $ this -> getTarget ( $ args -> getCommand ( ) ) ; }
Loads CLI commands and return matched target
9,145
public function getTarget ( $ command ) { if ( empty ( $ this -> routes [ $ command ] ) ) { return null ; } $ route = $ this -> routes [ $ command ] ; return $ route -> getTarget ( $ this -> args ) ; }
Return target for the specified command note that this method only searches the
9,146
public static function getInstance ( $ classname , $ input = "" , $ userDefFunction = null ) { $ fullname = "soloproyectos\\css\\parser\\filter\\" . $ classname ; return new $ fullname ( $ input , $ userDefFunction ) ; }
Gets a psuedo - filter instance by class name .
9,147
public function actionExists ( $ id ) { $ inlineActionMethodName = 'action' . Inflector :: camelize ( $ id ) ; if ( method_exists ( $ this -> controller , $ inlineActionMethodName ) ) { return true ; } if ( array_key_exists ( $ id , $ this -> controller -> actions ( ) ) ) { return true ; } return false ; }
Checks whether action with specified ID exists in owner controller .
9,148
public function setReturnAction ( $ actionId = null ) { if ( $ actionId === null ) { $ actionId = $ this -> id ; } if ( strpos ( $ actionId , '/' ) === false ) { $ actionId = $ this -> controller -> getUniqueId ( ) . '/' . $ actionId ; } $ sessionKey = '__adminReturnAction' ; Yii :: $ app -> getSession ( ) -> set ( $ s...
Sets the return action ID .
9,149
public function getReturnAction ( $ defaultActionId = 'index' ) { if ( $ this -> returnAction !== null ) { return $ this -> returnAction ; } $ sessionKey = '__adminReturnAction' ; $ actionId = Yii :: $ app -> getSession ( ) -> get ( $ sessionKey , $ defaultActionId ) ; $ actionId = trim ( $ actionId , '/' ) ; if ( $ ac...
Returns the ID of action which should be used for return redirect . If action belongs to another controller or does not exist in current controller - index is returned .
9,150
public function renderSlot ( $ slotName = null , $ extraAttributes = "" ) { $ this -> checkSlotName ( $ slotName ) ; try { $ slotContents = array ( ) ; $ pageTree = $ this -> container -> get ( 'red_kite_cms.page_tree' ) ; $ blockManagers = $ pageTree -> getBlockManagers ( $ slotName ) ; foreach ( $ blockManagers as $ ...
Overrides the base renderSlot method
9,151
public function renderBlock ( BlockManager $ blockManager , $ template = null , $ included = false , $ extraAttributes = '' , array $ extraOptions = null ) { try { $ block = $ blockManager -> toArray ( ) ; if ( empty ( $ block ) ) { return "" ; } $ templating = $ this -> container -> get ( 'templating' ) ; $ slotName =...
Renders a block
9,152
public function blockContentToHtml ( $ content , array $ extraOptions = null ) { $ result = $ content ; if ( is_array ( $ content ) ) { $ result = "" ; if ( \ array_key_exists ( 'RenderView' , $ content ) ) { if ( null !== $ extraOptions ) { $ content [ 'RenderView' ] [ 'options' ] = array_merge ( $ content [ 'RenderVi...
Converts a block s content to html
9,153
public static function guessMimeTypeFromFilename ( string $ file , string $ default = self :: MIMETYPE_DEFAULT ) : string { $ file = \ strtolower ( $ file ) ; if ( ( $ pos = \ strrpos ( $ file , '.' ) ) !== false ) { $ file = \ substr ( $ file , $ pos + 1 ) ; } if ( \ array_key_exists ( $ file , self :: $ mimeTypes ) )...
Get the guessed MIME type of a file .
9,154
public static function suggestExtensionByMediaType ( string $ mediaType ) : string { if ( false !== ( $ ext = \ array_search ( \ strtolower ( $ mediaType ) , self :: $ mimeTypes ) ) ) { return $ ext ; } if ( \ func_num_args ( ) > 1 ) { return ( string ) \ func_get_arg ( 1 ) ; } return '' ; }
Suggest a file extension that is related to the given media type .
9,155
public static function readFile ( string $ file ) : string { $ contents = @ \ file_get_contents ( $ file ) ; if ( $ contents === false ) { throw new \ RuntimeException ( \ sprintf ( 'File not found: "%s"' , $ file ) ) ; } return $ contents ; }
Read contents of the given file into a string and return it .
9,156
public static function changePermissions ( string $ file , int $ permissions ) { if ( ! \ is_file ( $ file ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'No such file found: "%s"' , $ file ) ) ; } if ( DIRECTORY_SEPARATOR == '\\' ) { return $ file ; } $ old = \ umask ( 0 ) ; try { if ( ! @ \ chmod ( $ file ,...
Change access permissions of the given file .
9,157
public static function touchFile ( string $ file , int $ permissions = 0777 ) : string { self :: createDirectory ( \ dirname ( $ file ) ) ; if ( ! @ \ touch ( $ file ) ) { throw new \ RuntimeException ( \ sprintf ( 'Unable to touch file "%s"%s' , $ file , self :: getErrorInfo ( ) ) ) ; } self :: changePermissions ( $ f...
Touches the given file and ensures the given access permissions are set .
9,158
public static function writeFile ( string $ file , string $ contents , int $ permissions = 0777 ) : string { self :: createDirectory ( \ dirname ( $ file ) ) ; $ tempFile = \ tempnam ( \ sys_get_temp_dir ( ) , self :: TEMP_FILE_PREFIX ) ; \ file_put_contents ( $ tempFile , $ contents ) ; if ( \ DIRECTORY_SEPARATOR == '...
Atomic file writer .
9,159
public static function removeFile ( string $ file ) : void { if ( \ is_file ( $ file ) ) { if ( ! @ \ unlink ( $ file ) ) { throw new \ RuntimeException ( \ sprintf ( 'Unable to delete file "%s"%s' , $ file , self :: getErrorInfo ( ) ) ) ; } } \ clearstatcache ( true , $ file ) ; }
Remove a file if it exists .
9,160
public function getFilteredRecordList ( $ gridfield ) { $ list = $ gridfield -> getList ( ) ; foreach ( $ gridfield -> getComponents ( ) as $ item ) { if ( $ item instanceof GridField_DataManipulator && ! $ item instanceof GridFieldPaginator ) { $ list = $ item -> getManipulatedData ( $ gridfield , $ list ) ; } } retur...
To get the entire list of records with the potential filters we need to remove the pagination but apply all other filters
9,161
public function create ( $ image , $ thumbnailWidth = 100 , $ thumbnailHeight = 100 ) { $ this -> setupTargetPath ( $ image ) ; $ this -> setupTargetImage ( $ image ) ; $ this -> transformation -> thumbnail ( new Image \ Box ( $ thumbnailWidth , $ thumbnailHeight ) ) -> apply ( $ this -> imagine -> open ( $ image ) ) -...
Creates the thumbnail
9,162
protected function setupTargetPath ( $ image ) { $ this -> thumbnailPath = dirname ( $ image ) . '/' . $ this -> thumbnailsFolder . '/' ; if ( ! is_dir ( $ this -> thumbnailPath ) ) { $ filesystem = new Filesystem ( ) ; $ filesystem -> mkdir ( $ this -> thumbnailPath ) ; } }
Sets up the target path and creates it if it does not exist
9,163
protected function translate ( $ name ) { preg_match_all ( '/^(?P<bundle>[^:]+):(?P<directory>[^:]*:)?(?P<file>.+)$/' , $ name , $ matches , \ PREG_SET_ORDER ) ; foreach ( [ 'bundle' , 'file' ] as $ offset ) { if ( empty ( $ matches [ 0 ] [ $ offset ] ) ) { throw new ViewException ( sprintf ( 'Invalid or missing "%s" n...
Translates view identifier to path
9,164
protected static function bootRecordsActivity ( ) { foreach ( static :: getModelEvents ( ) as $ event ) { static :: $ event ( function ( $ model ) use ( $ event ) { $ model -> recordActivity ( $ event ) ; } ) ; } if ( static :: deleteActivityOnCascade ( ) ) { static :: deleting ( function ( $ model ) { $ model -> delet...
Registers the event listeners
9,165
public function recordActivity ( $ event ) { return chronicle ( ) -> record ( $ this , $ this -> getActivityName ( $ event ) , $ this -> getUserId ( ) ) ; }
Records an activity through chronicle
9,166
protected function getUserId ( ) { if ( property_exists ( $ this , 'userKey' ) ) { $ userKey = $ this -> userKey ; return $ this -> $ userKey ; } if ( ! is_null ( $ this -> user_id ) ) { return $ this -> user_id ; } return null ; }
Returns the user that is associated with the model
9,167
protected function withProps ( $ model , array $ props ) : array { if ( ! ( \ is_array ( $ model ) || $ model instanceof \ ArrayAccess ) ) { throw new \ InvalidArgumentException ( 'Expect array or object implementing \ArrayAccess' ) ; } $ data = [ ] ; foreach ( $ props as $ key => $ definition ) { if ( \ is_int ( $ key...
Helper method for returning formatted properties from a source object or array .
9,168
protected function convertTimeZone ( DateTimeInterface $ date , $ timezone ) { $ timezone = ( $ timezone instanceof DateTimeZone ) ? $ timezone : new DateTimeZone ( $ timezone ) ; if ( $ date -> getTimezone ( ) !== $ timezone ) { if ( $ date instanceof DateTime ) { $ date = ( clone $ date ) ; $ date -> setTimezone ( $ ...
Given a date object return a new date object with the specified timezone . This method ensures that the original date object is not mutated .
9,169
protected function formatDatetime ( DateTimeInterface $ date , PropDefinition $ definition ) : string { $ timezone = $ definition -> get ( 'timezone' , $ this -> getDefaultTimezone ( ) ) ; if ( $ timezone !== null ) { $ date = $ this -> convertTimeZone ( $ date , $ timezone ) ; } return $ date -> format ( $ definition ...
Format a date object .
9,170
protected function formatDatetimeUtc ( DateTimeInterface $ date , PropDefinition $ propDefinition ) : string { return $ this -> formatDatetime ( $ date , $ propDefinition -> set ( 'timezone' , 'UTC' ) ) ; }
Shortcut method for converting a date to UTC and returning the formatted string .
9,171
public function onPostRender ( FilterPostRenderEvent $ event ) : void { foreach ( $ this -> registry -> getTemplateFilters ( ) as $ filter ) { if ( null !== ( $ mailRendered = $ event -> getMailRendered ( ) ) && $ filter -> supports ( $ mailRendered ) ) { $ filter -> filter ( $ mailRendered ) ; } } }
Action on post render event of mail templater .
9,172
public function onPreSend ( FilterPreSendEvent $ event ) : void { foreach ( $ this -> registry -> getTransportFilters ( ) as $ filter ) { if ( $ filter -> supports ( $ event -> getTransport ( ) , $ event -> getMessage ( ) , $ event -> getMailRendered ( ) ) ) { $ filter -> filter ( $ event -> getTransport ( ) , $ event ...
Action on pre send event of mailer transport .
9,173
protected function guessError ( $ err , $ uri , $ method ) { $ regex = '/HTTP\/1\.[01]? ([0-9]+) ([ a-zA-Z]+)/' ; $ matches = array ( ) ; preg_match ( $ regex , $ err , $ matches ) ; if ( count ( $ matches ) < 3 ) { throw new \ HPCloud \ Exception ( $ err ) ; } Response :: failure ( $ matches [ 1 ] , $ matches [ 0 ] , ...
Given an error this tries to guess the cause and throw an exception .
9,174
protected function smashHeaders ( $ headers ) { if ( empty ( $ headers ) ) { return ; } $ buffer = array ( ) ; foreach ( $ headers as $ name => $ value ) { $ buffer [ ] = sprintf ( "%s: %s" , $ name , $ value ) ; } $ headerStr = implode ( "\r\n" , $ buffer ) ; return $ headerStr . "\r\n" ; }
Given an array of headers build a header string .
9,175
protected function buildStreamContext ( $ method , $ headers , $ body ) { $ headers [ 'Connection' ] = 'close' ; $ config = array ( 'http' => array ( 'protocol_version' => $ this -> httpVersion , 'method' => strtoupper ( $ method ) , 'header' => $ this -> smashHeaders ( $ headers ) , 'user_agent' => Transporter :: HTTP...
Build the stream context for a request .
9,176
public static function normalize ( $ string , $ canonicalForm = self :: NORMALIZE_NFC ) { if ( static :: $ supportNormalizer ) { return \ Normalizer :: normalize ( $ string , $ canonicalForm ) ; } return $ string ; }
normalize an utf8 string to canonical form Default to NFC
9,177
public function getDesiredUrl ( ? string $ url = null ) { if ( isset ( $ _GET [ 'url' ] ) ) { $ url = $ _GET [ 'url' ] . ( count ( $ _GET ) > 0 ? '?' : '' ) ; unset ( $ _GET [ 'url' ] ) ; foreach ( $ _GET as $ key => $ value ) { $ url .= ( ends_with ( $ url , '?' ) ? '' : '&' ) . $ key . '=' . $ value ; } } if ( $ url ...
Get desired endpoint
9,178
protected function openHandle ( ) { $ fileName = $ this -> getFileName ( ) ; $ this -> _handle = fopen ( $ fileName , 'w' ) ; if ( ! $ this -> _handle ) { throw new \ Exception ( 'Cannot open file ' . $ fileName ) ; } }
Open new file handle .
9,179
public function write ( $ string ) { $ fileName = $ this -> getFileName ( ) ; $ handle = $ this -> getHandle ( ) ; if ( fwrite ( $ handle , $ string ) === false ) { throw new \ Exception ( 'Cannot write to file ' . $ fileName ) ; } }
Binary - safe file handle write .
9,180
protected function closeHandle ( ) { $ handle = $ this -> getHandle ( ) ; fclose ( $ handle ) ; $ this -> _handle = false ; $ this -> runCommand ( $ this -> getFileName ( ) ) ; }
Close file handle .
9,181
public static function readString ( & $ buffer ) { $ tmp = unpack ( 'n' , $ buffer ) ; $ length = array_pop ( $ tmp ) ; if ( $ length + 2 > strlen ( $ buffer ) ) { throw new \ RuntimeException ( "buffer:" . bin2hex ( $ buffer ) . " lenth:$length not enough for unpackString" ) ; } $ string = substr ( $ buffer , 2 , $ le...
Read string from buffer .
9,182
public static function readShortInt ( & $ buffer ) { $ tmp = unpack ( 'n' , $ buffer ) ; $ buffer = substr ( $ buffer , 2 ) ; return array_pop ( $ tmp ) ; }
Read unsigned short int from buffer .
9,183
public function authenticateNewUser ( string $ invite ) { $ result = $ this -> authenticateNewUserInternal ( [ 'invite' => $ invite , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } elseif ( $ statusCode === 400 )...
Attempt to authenticate using a new user invite code
9,184
public function createUser ( array $ config = [ ] ) { $ result = $ this -> createUserInternal ( $ config ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } $ this -> reportUnexpectedResponse ( $ result , 1490802526 ) ;...
Create a user with the given information .
9,185
public function deactivateUser ( string $ employeeId ) { $ result = $ this -> deactivateUserInternal ( [ 'employee_id' => $ employeeId , 'active' => 'no' , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode !== 200 ) { $ this -> reportUnexpectedResponse ( $ result , 1490808523 ) ; } }
Deactivate a user .
9,186
public function getUser ( string $ employeeId ) { $ result = $ this -> getUserInternal ( [ 'employee_id' => $ employeeId , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } elseif ( $ statusCode === 204 ) { return n...
Get information about the specified user .
9,187
public function mfaCreate ( $ employee_id , $ type , $ label = null ) { $ result = $ this -> mfaCreateInternal ( [ 'employee_id' => $ employee_id , 'type' => $ type , 'label' => $ label , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatu...
Create a new MFA configuration
9,188
public function mfaDelete ( $ id , $ employeeId ) { $ result = $ this -> mfaDeleteInternal ( [ 'id' => $ id , 'employee_id' => $ employeeId , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 204 ) { return null ; } $ this -> reportUnexpectedResponse ( $ result , 1506710702 ) ; }
Delete an MFA configuration
9,189
public function mfaList ( $ employee_id ) { $ result = $ this -> mfaListInternal ( [ 'employee_id' => $ employee_id , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } $ this -> reportUnexpectedResponse ( $ result ,...
Get a list of MFA configurations for given user
9,190
public function mfaUpdate ( $ id , $ employeeId , $ label ) { $ result = $ this -> mfaUpdateInternal ( [ 'id' => $ id , 'employee_id' => $ employeeId , 'label' => $ label , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ resul...
Update an MFA configuration
9,191
public function mfaVerify ( $ id , $ employeeId , $ value ) { $ result = $ this -> mfaVerifyInternal ( [ 'id' => $ id , 'employee_id' => $ employeeId , 'value' => $ value , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 204 ) { return true ; } if ( $ statusCode === 200 ) { return $ this ...
Verify an MFA value
9,192
public function createMethod ( $ employee_id , $ value , $ created = '' ) { $ params = compact ( 'employee_id' , 'value' ) ; if ( ! empty ( $ created ) ) { $ params [ 'created' ] = $ created ; } $ result = $ this -> createMethodInternal ( $ params ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode...
Create a new recovery method
9,193
public function deleteMethod ( $ uid , $ employee_id ) { $ result = $ this -> deleteMethodInternal ( compact ( 'uid' , 'employee_id' ) ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 204 || $ statusCode === 200 ) { return null ; } $ this -> reportUnexpectedResponse ( $ result , 1541006315 )...
Delete a recovery method
9,194
public function getMethod ( $ uid , $ employee_id ) { $ result = $ this -> getMethodInternal ( compact ( 'uid' , 'employee_id' ) ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } $ this -> reportUnexpectedResponse ( $...
View a single recovery method
9,195
public function listMethod ( $ employee_id ) { $ result = $ this -> listMethodInternal ( compact ( 'employee_id' ) ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } $ this -> reportUnexpectedResponse ( $ result , 1541...
Get a list of recovery methods for given user
9,196
public function verifyMethod ( $ uid , $ employee_id , $ code ) { $ result = $ this -> verifyMethodInternal ( compact ( 'uid' , 'employee_id' , 'code' ) ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ result ) ; } $ this -> repo...
Verify a recovery method
9,197
public function resendMethod ( $ uid , $ employee_id ) { $ result = $ this -> resendMethodInternal ( compact ( 'uid' , 'employee_id' ) ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 204 || $ statusCode === 200 ) { return true ; } $ this -> reportUnexpectedResponse ( $ result , 1541006732 )...
Resend a recovery method verification message
9,198
public function setPassword ( string $ employeeId , string $ password ) { $ result = $ this -> setPasswordInternal ( [ 'employee_id' => $ employeeId , 'password' => $ password , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode === 200 ) { return $ this -> getResultAsArrayWithoutStatusCode ( $ ...
Set the password for the specified user .
9,199
public function assessPassword ( string $ employeeId , string $ password ) { $ result = $ this -> assessPasswordInternal ( [ 'employee_id' => $ employeeId , 'password' => $ password , ] ) ; $ statusCode = ( int ) $ result [ 'statusCode' ] ; if ( $ statusCode >= 200 && $ statusCode <= 299 ) { return true ; } $ this -> r...
Validate a new password for a specified user but do not save it .