idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
11,800
public function run ( $ id = null ) { if ( $ id === null ) { $ model = new Measure ; $ model -> loadDefaultValues ( ) ; } else { $ model = $ this -> controller -> findModel ( $ id ) ; } $ isLoaded = $ model -> load ( \ Yii :: $ app -> request -> post ( ) ) ; $ hasAccess = ( $ model -> isNewRecord && \ Yii :: $ app -> user -> can ( 'measure-create-measure' ) ) || ( ! $ model -> isNewRecord && \ Yii :: $ app -> user -> can ( 'measure-edit-measure' ) ) ; if ( $ isLoaded && ! $ hasAccess ) { throw new ForbiddenHttpException ; } if ( $ isLoaded && $ model -> save ( ) ) { return $ this -> controller -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } else { return $ this -> controller -> render ( 'update' , [ 'hasAccess' => $ hasAccess , 'model' => $ model , ] ) ; } }
Updates an existing Measure model . If update is successful the browser will be redirected to the view page .
11,801
public function avatar ( $ size = 100 ) { if ( Utilities :: validGravatar ( $ this -> email ) ) { return Utilities :: gavatar ( $ this -> email ) ; } $ color = Packages :: installed ( 'customization' ) ? \ Laralum \ Customization \ Models \ Customization :: first ( ) -> navbar_color : '#1e87f0' ; return MaterialFunctions :: materialAvatar ( $ this -> name , $ size , $ color ) ; }
Returns the user avatar .
11,802
public function getLastToken ( $ type , $ key = 'type' ) { return $ this -> token ( ) -> orderBy ( 'tokens.created_at' , 'desc' ) -> where ( $ key , $ type ) -> first ( ) ; }
Get the last Token by the type .
11,803
public function checkToken ( $ token ) { return ( bool ) $ this -> token ( ) -> where ( 'token' , $ token ) -> where ( 'expiration_date' , '>' , Carbon :: now ( ) ) -> count ( ) ; }
Check the token .
11,804
public function createToken ( $ type , $ expire = 60 , $ length = 48 , $ customProperties = null ) { return $ this -> token ( ) -> create ( [ 'token' => $ this -> generateTokenString ( $ length ) , 'expiration_date' => Carbon :: now ( ) -> addMinutes ( $ expire ) , 'type' => $ type , 'custom_properties' => $ customProperties , ] ) ; }
Create new token and return the instance .
11,805
public static function route ( ) { if ( defined ( 'DACHI_CLI' ) ) return false ; $ uri = Request :: getFullUri ( ) ; $ route = self :: findRoute ( $ uri ) ; self :: performRoute ( $ route ) ; return Template :: render ( ) ; }
Performs routing based upon the loaded routing information and the incoming request
11,806
public static function findRoute ( $ uri ) { if ( self :: $ routes === array ( ) ) self :: load ( ) ; $ count = count ( $ uri ) ; $ position = & self :: $ routes ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( $ i == $ count - 1 ) { if ( isset ( $ position [ $ uri [ $ i ] ] ) && isset ( $ position [ $ uri [ $ i ] ] [ "route" ] ) ) { return $ position [ $ uri [ $ i ] ] [ "route" ] ; } else if ( isset ( $ position [ "*" ] ) && isset ( $ position [ "*" ] [ "route" ] ) ) { return $ position [ "*" ] [ "route" ] ; } else { throw new ValidRouteNotFoundException ; } } else { if ( isset ( $ position [ $ uri [ $ i ] ] ) ) { $ position = & $ position [ $ uri [ $ i ] ] [ "children" ] ; } elseif ( isset ( $ position [ "*" ] ) ) { $ position = & $ position [ "*" ] [ "children" ] ; } else { throw new ValidRouteNotFoundException ; } } } throw new ValidRouteNotFoundException ; }
Find and process a valid route from the uri
11,807
public static function performRoute ( $ route ) { $ api_mode = isset ( $ route [ "api-mode" ] ) ; Request :: setRequestVariables ( $ route [ "variables" ] , $ api_mode ) ; $ controller = new $ route [ "class" ] ; $ response = $ controller -> $ route [ "method" ] ( ) ; if ( ! Request :: isAjax ( ) && ! Request :: isAPI ( ) && isset ( $ route [ "render-path" ] ) ) { Request :: setRenderPath ( $ route [ "render-path" ] ) ; try { $ route = self :: findRoute ( explode ( '/' , $ route [ "render-path" ] ) ) ; } catch ( ValidRouteNotFoundException $ e ) { throw new ValidRenderRouteNotFoundException ( $ e ) ; } $ response = self :: performRoute ( $ route ) ; } return $ response ; }
Perform routing based upon the discovered route
11,808
public function readProperties ( $ root = null , $ web = null , $ vendor = null ) { if ( ! $ this -> propertiesRead ) { if ( is_null ( $ root ) ) { if ( is_callable ( [ $ this , 'taskDetermineProjectRoot' ] ) ) { $ this -> taskDetermineProjectRoot ( ) -> run ( ) ; } $ root = $ this -> getConfig ( ) -> get ( 'digipolis.root.project' , getcwd ( ) ) ; } if ( is_null ( $ web ) ) { if ( is_callable ( [ $ this , 'taskDetermineWebRoot' ] ) ) { $ this -> taskDetermineWebRoot ( ) -> run ( ) ; } $ web = $ this -> getConfig ( ) -> get ( 'digipolis.root.web' , $ root ) ; } if ( is_null ( $ vendor ) ) { $ vendor = $ root . '/vendor' ; } $ this -> taskReadProperties ( [ $ web , $ vendor ] ) -> run ( ) ; $ this -> propertiesRead = true ; } }
Read the properties from the YAML files . Determine project and web root if needed .
11,809
public function generateWizard ( $ dataContainer ) { if ( ! isset ( $ GLOBALS [ 'TL_DCA' ] [ $ dataContainer -> table ] [ 'fields' ] [ $ dataContainer -> field ] [ 'eval' ] [ 'coordinates' ] ) ) { return '' ; } return sprintf ( '<a href="#" onclick="$(\'ctrl_%s_toggle\').click();return false;"><img src="%s"></a>' , $ GLOBALS [ 'TL_DCA' ] [ $ dataContainer -> table ] [ 'fields' ] [ $ dataContainer -> field ] [ 'eval' ] [ 'coordinates' ] , 'bundles/leafletgeocodewidget/img/map.png' ) ; }
Generate the wizard for the radius widget .
11,810
public static function pull ( $ arr , $ name , $ type = null ) { $ ret = [ ] ; if ( $ type == self :: GETTER ) { $ method = 'get' . $ name ; foreach ( $ arr as $ elem ) { $ ret [ ] = $ elem -> $ method ( ) ; } } elseif ( $ type == self :: OBJ ) { foreach ( $ arr as $ elem ) { $ ret [ ] = $ elem -> $ name ; } } else { foreach ( $ arr as $ elem ) { $ ret [ ] = $ elem [ $ name ] ; } } return $ ret ; }
Collects value from array
11,811
public static function assoc ( $ arr , $ name , $ type = null ) { $ ret = [ ] ; if ( empty ( $ arr ) ) { return $ ret ; } if ( $ type == self :: GETTER ) { $ method = 'get' . $ name ; foreach ( $ arr as $ elem ) { $ ret [ $ elem -> $ method ( ) ] = $ elem ; } } elseif ( $ type == self :: OBJ ) { foreach ( $ arr as $ elem ) { $ ret [ $ elem -> $ name ] = $ elem ; } } else { foreach ( $ arr as $ elem ) { $ ret [ $ elem [ $ name ] ] = $ elem ; } } return $ ret ; }
Creates associated array
11,812
public static function select ( $ arr , $ includedKeys ) { $ ret = [ ] ; foreach ( $ includedKeys as $ key ) { if ( array_key_exists ( $ key , $ arr ) ) { $ ret [ $ key ] = $ arr [ $ key ] ; } } return $ ret ; }
Create array with given keys
11,813
public function MicroImage ( ) { $ pixel = $ this -> config ( ) -> pixelate ; $ blur = $ this -> config ( ) -> blur ; $ quality = $ this -> config ( ) -> quality ; $ scale = $ this -> config ( ) -> scale ; $ variant = $ this -> owner -> variantName ( __FUNCTION__ , $ pixel , $ blur , $ quality , $ scale ) ; return $ this -> owner -> manipulateImage ( $ variant , function ( Image_Backend $ backend ) use ( $ pixel , $ blur , $ quality , $ scale ) { $ clone = clone $ backend ; $ resource = clone $ backend -> getImageResource ( ) ; $ resource -> pixelate ( $ pixel ) -> blur ( $ blur ) -> encode ( 'jpg' , $ quality ) ; if ( $ scale != 100 ) { $ width = $ backend -> getWidth ( ) * ( $ scale / 100 ) ; $ height = $ backend -> getHeight ( ) * ( $ scale / 100 ) ; $ resource -> resize ( $ width , $ height ) ; } $ clone -> setImageResource ( $ resource ) ; return $ clone ; } ) ; }
Generates a reduced quality version of the current image
11,814
public function addVisitor ( $ callable , $ condition , $ when = self :: BEFORE ) { $ this -> visitors [ ] = array ( $ when , $ condition , $ callable ) ; return $ this ; }
Add a visitor to the traverser . The node being visited is passed to the second callback to determine whether the first callback should be called with the node . The arguments passed to both callbacks are the current node and the path to the node . The result of the first callback is used to replace the node in the tree .
11,815
private function doTraverse ( $ node , $ path = array ( ) ) { foreach ( $ node as $ name => $ value ) { $ path [ ] = $ name ; $ value = $ this -> doVisit ( $ path , $ value , self :: BEFORE ) ; if ( is_array ( $ value ) ) { $ value = $ this -> doTraverse ( $ value , $ path ) ; } $ value = $ this -> doVisit ( $ path , $ value , self :: AFTER ) ; $ node [ $ name ] = $ value ; array_pop ( $ path ) ; } return $ node ; }
Recursive traversal implementation
11,816
private function doVisit ( $ path , $ value , $ when ) { foreach ( $ this -> visitors as $ visitor ) { if ( $ visitor [ 0 ] === $ when && call_user_func ( $ visitor [ 1 ] , $ path , $ value ) ) { try { $ value = call_user_func ( $ visitor [ 2 ] , $ path , $ value ) ; } catch ( \ Exception $ e ) { if ( $ path ) { $ path = join ( '.' , $ path ) ; } $ path = json_encode ( $ path ) ; $ value = json_encode ( $ value ) ; throw new \ RuntimeException ( "While visiting value '{$value}' at path {$path}" , 0 , $ e ) ; } } } return $ value ; }
Visits the node with all visitors at the specified time .
11,817
protected function get_data ( ) { $ post_type = $ this -> input -> get ( 'post_type' ) ; if ( ! post_type_exists ( $ post_type ) ) { $ this -> error ( sprintf ( $ this -> __ ( 'Post type %s does not exist.' ) , $ post_type ) , 404 ) ; } if ( ! current_user_can ( 'edit_posts' ) ) { $ this -> error ( $ this -> __ ( 'Sorry, but you have no permission.' ) , 403 ) ; } $ paged = max ( intval ( $ this -> input -> get ( 'paged' ) ) , 1 ) - 1 ; $ args = [ 'post_type' => $ post_type , 'suppress_filters' => false , 'orderby' => 'title' , 'order' => 'ASC' , 'offset' => $ paged * get_option ( 'posts_per_page' ) , 's' => $ this -> input -> get ( 's' ) , ] ; if ( $ this -> is_public_search ) { $ args = array_merge ( $ args , [ 'post_status' => [ 'publish' ] ] ) ; } else { $ args = array_merge ( $ args , [ 'post_status' => [ 'publish' , 'draft' , 'future' ] , ] ) ; if ( ! current_user_can ( 'edit_others_posts' ) ) { $ args [ 'author' ] = get_current_user_id ( ) ; } } $ data = [ ] ; foreach ( get_posts ( $ args ) as $ post ) { $ data [ ] = [ 'id' => $ post -> ID , 'name' => get_the_title ( $ post ) , ] ; } return $ data ; }
Returns data as array .
11,818
public function reverseTransform ( $ modelData , PropertyPathInterface $ propertyPath , $ value ) { $ unmodified = intval ( $ value [ 'unmodified' ] ) ; if ( $ unmodified === 1 ) { return ; } $ item = null ; if ( isset ( $ value [ 0 ] ) ) { $ id = $ value [ 0 ] ; $ item = $ this -> getRepository ( ) -> find ( $ id ) ; } $ this -> propertyAccessor -> setValue ( $ modelData , $ propertyPath , $ item ) ; }
Transforms identifier to entity
11,819
public static function filter ( $ value , bool $ allowNull = false , DateTimeZoneStandard $ timezone = null ) { if ( self :: valueIsNullAndValid ( $ allowNull , $ value ) ) { return null ; } if ( $ value instanceof DateTimeStandard ) { return $ value ; } if ( is_int ( $ value ) || ctype_digit ( $ value ) ) { $ value = "@{$value}" ; } if ( ! is_string ( $ value ) || trim ( $ value ) == '' ) { throw new FilterException ( '$value is not a non-empty string' ) ; } return new DateTimeStandard ( $ value , $ timezone ) ; }
Filters the given value into a \ DateTime object .
11,820
public static function format ( DateTimeInterface $ dateTime , string $ format = 'c' ) : string { if ( empty ( trim ( $ format ) ) ) { throw new \ InvalidArgumentException ( '$format is not a non-empty string' ) ; } return $ dateTime -> format ( $ format ) ; }
Filters the give \ DateTime object to a formatted string .
11,821
public function disconnect ( ) { if ( $ this -> state !== self :: STATE_NOT_CONNECTED && $ this -> connection -> isConnected ( ) === true ) { $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} LOGOUT" ) ; $ this -> getResponse ( $ tag ) ; $ this -> state = self :: STATE_LOGOUT ; $ this -> selectedMailbox = null ; $ this -> connection -> close ( ) ; $ this -> connection = null ; $ this -> state = self :: STATE_NOT_CONNECTED ; } }
Disconnects the transport from the IMAP server .
11,822
public function listMailboxes ( $ reference = '' , $ mailbox = '*' ) { if ( $ this -> state != self :: STATE_AUTHENTICATED && $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call listMailboxes() when not successfully logged in." ) ; } $ result = array ( ) ; $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} LIST \"{$reference}\" \"{$mailbox}\"" ) ; $ response = trim ( $ this -> connection -> getLine ( ) ) ; while ( strpos ( $ response , '* LIST (' ) !== false ) { if ( strpos ( $ response , "\\Noselect" ) === false ) { $ response = substr ( $ response , strpos ( $ response , "\" " ) + 2 ) ; $ response = trim ( $ response ) ; $ response = trim ( $ response , "\"" ) ; $ result [ ] = $ response ; } $ response = $ this -> connection -> getLine ( ) ; } $ response = $ this -> getResponse ( $ tag , $ response ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "Could not list mailboxes with the parameters '\"{$reference}\"' and '\"{$mailbox}\"': {$response}." ) ; } return $ result ; }
Returns an array with the names of the available mailboxes for the user currently authenticated on the IMAP server .
11,823
public function getHierarchyDelimiter ( ) { if ( $ this -> state != self :: STATE_AUTHENTICATED && $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call getDelimiter() when not successfully logged in." ) ; } $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} LIST \"\" \"\"" ) ; $ response = trim ( $ this -> getResponse ( '* LIST' ) ) ; $ parts = explode ( '"' , $ response ) ; if ( count ( $ parts ) >= 2 ) { $ result = $ parts [ 1 ] ; } else { throw new ezcMailTransportException ( "Could not retrieve the hierarchy delimiter: {$response}." ) ; } $ response = $ this -> getResponse ( $ tag , $ response ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "Could not retrieve the hierarchy delimiter: {$response}." ) ; } return $ result ; }
Returns the hierarchy delimiter of the IMAP server useful for handling nested IMAP folders .
11,824
public function listMessages ( $ contentType = null ) { if ( $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call listMessages() on the IMAP transport when a mailbox is not selected." ) ; } $ messageList = array ( ) ; $ messages = array ( ) ; $ tag = $ this -> getNextTag ( ) ; $ command = "{$tag} SEARCH UNDELETED" ; if ( ! is_null ( $ contentType ) ) { $ command .= " HEADER \"Content-Type\" \"{$contentType}\"" ; } $ this -> connection -> sendData ( $ command ) ; $ response = trim ( $ this -> getResponse ( '* SEARCH' ) ) ; if ( strpos ( $ response , '* SEARCH' ) !== false ) { $ ids = trim ( substr ( $ response , 9 ) ) ; if ( $ ids !== "" ) { $ messageList = explode ( ' ' , $ ids ) ; } } $ response = trim ( $ this -> getResponse ( $ tag , $ response ) ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "The IMAP server could not list messages: {$response}." ) ; } if ( ! empty ( $ messageList ) ) { $ tag = $ this -> getNextTag ( ) ; $ query = trim ( implode ( ',' , $ messageList ) ) ; $ this -> connection -> sendData ( "{$tag} FETCH {$query} RFC822.SIZE" ) ; $ response = $ this -> getResponse ( 'FETCH (' ) ; $ currentMessage = trim ( reset ( $ messageList ) ) ; while ( strpos ( $ response , 'FETCH (' ) !== false ) { $ line = $ response ; $ line = explode ( ' ' , $ line ) ; $ line = trim ( $ line [ count ( $ line ) - 1 ] ) ; $ line = substr ( $ line , 0 , strlen ( $ line ) - 1 ) ; $ messages [ $ currentMessage ] = intval ( $ line ) ; $ currentMessage = next ( $ messageList ) ; $ response = $ this -> connection -> getLine ( ) ; } $ response = trim ( $ this -> getResponse ( $ tag , $ response ) ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "The IMAP server could not list messages: {$response}." ) ; } } return $ messages ; }
Returns a list of the not deleted messages in the current mailbox .
11,825
public function status ( & $ numMessages , & $ sizeMessages , & $ recent = 0 , & $ unseen = 0 ) { if ( $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call status() on the IMAP transport when a mailbox is not selected." ) ; } $ messages = $ this -> listMessages ( ) ; $ numMessages = count ( $ messages ) ; $ sizeMessages = array_sum ( $ messages ) ; $ messages = array_keys ( $ messages ) ; $ recentMessages = array_intersect ( $ this -> searchByFlag ( "RECENT" ) , $ messages ) ; $ unseenMessages = array_intersect ( $ this -> searchByFlag ( "UNSEEN" ) , $ messages ) ; $ recent = count ( $ recentMessages ) ; $ unseen = count ( $ unseenMessages ) ; return true ; }
Returns information about the messages in the current mailbox .
11,826
public function listUniqueIdentifiers ( $ msgNum = null ) { if ( $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected." ) ; } $ result = array ( ) ; if ( $ msgNum !== null ) { $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} UID SEARCH {$msgNum}" ) ; $ response = $ this -> getResponse ( '* SEARCH' ) ; if ( strpos ( $ response , '* SEARCH' ) !== false ) { $ result [ ( int ) $ msgNum ] = trim ( substr ( $ response , 9 ) ) ; } $ response = trim ( $ this -> getResponse ( $ tag , $ response ) ) ; } else { $ uids = array ( ) ; $ messages = array_keys ( $ this -> listMessages ( ) ) ; $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} UID SEARCH UNDELETED" ) ; $ response = $ this -> getResponse ( '* SEARCH' ) ; if ( strpos ( $ response , '* SEARCH' ) !== false ) { $ response = trim ( substr ( $ response , 9 ) ) ; if ( $ response !== "" ) { $ uids = explode ( ' ' , $ response ) ; } for ( $ i = 0 ; $ i < count ( $ messages ) ; $ i ++ ) { $ result [ trim ( $ messages [ $ i ] ) ] = $ uids [ $ i ] ; } } $ response = trim ( $ this -> getResponse ( $ tag ) ) ; } if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "The IMAP server could not fetch the unique identifiers: {$response}." ) ; } return $ result ; }
Returns the unique identifiers for the messages from the current mailbox .
11,827
public function countByFlag ( $ flag ) { $ flag = $ this -> normalizeFlag ( $ flag ) ; $ messages = $ this -> searchByFlag ( $ flag ) ; return count ( $ messages ) ; }
Wrapper function to fetch count of messages by a certain flag .
11,828
protected function searchByFlag ( $ flag ) { $ uid = ( $ this -> options -> uidReferencing ) ? self :: UID : self :: NO_UID ; if ( $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Can't call searchByFlag() on the IMAP transport when a mailbox is not selected." ) ; } $ matchingMessages = array ( ) ; $ flag = $ this -> normalizeFlag ( $ flag ) ; if ( in_array ( $ flag , self :: $ extendedFlags ) ) { $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} {$uid}SEARCH ({$flag})" ) ; $ response = $ this -> getResponse ( '* SEARCH' ) ; if ( strpos ( $ response , '* SEARCH' ) !== false ) { $ ids = substr ( trim ( $ response ) , 9 ) ; if ( trim ( $ ids ) !== "" ) { $ matchingMessages = explode ( ' ' , $ ids ) ; } } $ response = trim ( $ this -> getResponse ( $ tag , $ response ) ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "The IMAP server could not search the messages by flags: {$response}." ) ; } } else { throw new ezcMailTransportException ( "Flag '{$flag}' is not allowed for searching." ) ; } return $ matchingMessages ; }
Returns an array of message numbers from the selected mailbox which have a certain flag set .
11,829
public function capability ( ) { if ( $ this -> state != self :: STATE_NOT_AUTHENTICATED && $ this -> state != self :: STATE_AUTHENTICATED && $ this -> state != self :: STATE_SELECTED && $ this -> state != self :: STATE_SELECTED_READONLY ) { throw new ezcMailTransportException ( "Trying to request capability when not connected to server." ) ; } $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} CAPABILITY" ) ; $ response = $ this -> connection -> getLine ( ) ; while ( $ this -> responseType ( $ response ) != self :: RESPONSE_UNTAGGED && strpos ( $ response , '* CAPABILITY ' ) === false ) { $ response = $ this -> connection -> getLine ( ) ; } $ result = trim ( $ response ) ; $ response = trim ( $ this -> getResponse ( $ tag ) ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "The IMAP server responded negative to the CAPABILITY command: {$response}." ) ; } return explode ( ' ' , str_replace ( '* CAPABILITY ' , '' , $ result ) ) ; }
Returns an array with the capabilities of the IMAP server .
11,830
public function expunge ( ) { if ( $ this -> state != self :: STATE_SELECTED ) { throw new ezcMailTransportException ( "Can not issue EXPUNGE command if a mailbox is not selected." ) ; } $ tag = $ this -> getNextTag ( ) ; $ this -> connection -> sendData ( "{$tag} EXPUNGE" ) ; $ response = trim ( $ this -> getResponse ( $ tag ) ) ; if ( $ this -> responseType ( $ response ) != self :: RESPONSE_OK ) { throw new ezcMailTransportException ( "EXPUNGE failed: {$response}." ) ; } }
Sends an EXPUNGE command to the server .
11,831
protected function getNextTag ( ) { $ tagLetter = substr ( $ this -> currentTag , 0 , 1 ) ; $ tagNumber = intval ( substr ( $ this -> currentTag , 1 ) ) ; $ tagNumber ++ ; if ( $ tagLetter == 'Z' && $ tagNumber == 10000 ) { $ tagLetter = 'A' ; $ tagNumber = 1 ; } if ( $ tagNumber == 10000 ) { $ tagLetter ++ ; $ tagNumber = 0 ; } $ this -> currentTag = $ tagLetter . sprintf ( "%04s" , $ tagNumber ) ; return $ this -> currentTag ; }
Generates the next IMAP tag to prepend to client commands .
11,832
protected function getMessageSectionSize ( $ response ) { $ size = 0 ; preg_match ( '/\{(.*)\}/' , $ response , $ matches ) ; if ( count ( $ matches ) > 0 ) { $ size = ( int ) $ matches [ 1 ] ; } return $ size ; }
Returns the size of a FETCH section in bytes .
11,833
protected function registerEvent ( $ name , Closure $ callback ) { if ( ! isset ( static :: $ dispatcher ) ) { $ this -> initEventDispatcher ( ) ; } static :: $ dispatcher -> listen ( $ name , $ callback ) ; }
Register an event for the dispatcher to listen for .
11,834
protected function fireEvent ( $ name , $ payload = null ) { if ( ! isset ( static :: $ dispatcher ) ) { $ this -> initEventDispatcher ( ) ; } static :: $ dispatcher -> fire ( $ name , $ payload ) ; }
Fire off an event .
11,835
public function clean ( Composer $ composer ) { $ rootPkg = $ composer -> getPackage ( ) ; $ extra = $ rootPkg -> getExtra ( ) ; if ( ! isset ( $ extra [ 'wordpress-install-dir' ] ) ) { return ; } $ filesystem = new Filesystem ( ) ; $ filesystem -> remove ( $ extra [ 'wordpress-install-dir' ] . '/wp-content' ) ; }
Clean up the WordPress installation directory .
11,836
public function copy ( $ target ) { if ( ! parent :: copy ( $ target ) ) return false ; return file_put_contents ( $ target , $ this -> content ) !== false ; }
Copies the text file s content to the local filesystem .
11,837
public function setPermissionNames ( $ any , $ none , $ user , $ anon ) { if ( $ any ) { $ this -> any = $ any ; } if ( $ none ) { $ this -> none = $ none ; } if ( $ user ) { $ this -> user = $ user ; } if ( $ anon ) { $ this -> anon = $ anon ; } }
Set the names of the permissions to use for any none user and anonymous rules . Set any of these to null to continue using the current name .
11,838
public function check ( Request $ request ) { foreach ( $ this -> exemptions as $ exemption ) { try { if ( true === $ this -> checkRule ( $ request , $ exemption ) ) { return true ; } } catch ( BlockadeException $ e ) { } } foreach ( $ this -> rules as $ rule ) { $ this -> checkRule ( $ request , $ rule ) ; } return false ; }
Check if a Request has permission to access a resource .
11,839
protected function _commentCB ( $ m ) { $ hasSurroundingWs = ( trim ( $ m [ 0 ] ) !== $ m [ 1 ] ) ; $ m = $ m [ 1 ] ; if ( $ m === 'keep' ) { return '/**/' ; } if ( $ m === '" "' ) { return '/*" "*/' ; } if ( preg_match ( '@";\\}\\s*\\}/\\*\\s+@' , $ m ) ) { return '/*";}}/* */' ; } if ( $ this -> _inHack ) { if ( preg_match ( '@ ^/ # comment started like /*/ \\s* (\\S[\\s\\S]+?) # has at least some non-ws content \\s* /\\* # ends like /*/ or /**/ @x' , $ m , $ n ) ) { $ this -> _inHack = false ; return "/*/{$n[1]}/**/" ; } } if ( substr ( $ m , - 1 ) === '\\' ) { $ this -> _inHack = true ; return '/*\\*/' ; } if ( $ m !== '' && $ m [ 0 ] === '/' ) { $ this -> _inHack = true ; return '/*/*/' ; } if ( $ this -> _inHack ) { $ this -> _inHack = false ; return '/**/' ; } return $ hasSurroundingWs ? ' ' : '' ; }
Process a comment and return a replacement
11,840
public function onKernelRequest ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( $ request -> isMethod ( 'post' ) ) { $ formId = $ request -> request -> getInt ( 'form[form_id]' , 0 , true ) ; if ( $ formId > 0 ) { $ form = $ this -> container -> get ( 'netvlies.form' ) -> get ( $ formId ) ; $ sf2Form = $ form -> getSf2Form ( ) ; $ sf2Form -> bind ( $ request ) ; if ( $ sf2Form -> isValid ( ) ) { $ form -> setSuccess ( true ) ; $ event = new FormEvent ( $ form ) ; $ dispatcher = $ this -> container -> get ( 'event_dispatcher' ) ; $ dispatcher -> dispatch ( 'form.success' , $ event ) ; } } } }
Checks if a form post request was mad . If so it validates the form input and upon success dispatches the form success event which can be used for further custom handling of the received data .
11,841
public static function is_spam ( array $ values = [ ] ) { $ query_string = self :: make_request ( $ values ) ; if ( ! class_exists ( 'Akismet' ) || ! \ Akismet :: get_api_key ( ) ) { return new \ WP_Error ( 500 , 'Akismet is not active.' ) ; } add_filter ( 'akismet_ua' , [ static :: class , 'get_ua' ] , 9 ) ; $ response = \ Akismet :: http_post ( $ query_string , 'comment-check' ) ; remove_filter ( 'akismet_ua' , [ static :: class , 'get_ua' ] , 9 ) ; switch ( $ response [ 1 ] ) { case 'true' : return true ; break ; case 'false' : return false ; break ; default : if ( isset ( $ response [ 0 ] [ 'x-akismet-debug-help' ] ) && ! empty ( $ response [ 0 ] [ 'x-akismet-debug-help' ] ) ) { $ message = $ response [ 0 ] [ 'x-akismet-debug-help' ] ; } else { $ message = 'Akismet return the invalid result. Something is wrong.' ; } return new \ WP_Error ( 500 , $ message ) ; break ; } }
Check if data is spam
11,842
public static function make_request ( array $ args = [ ] ) { $ args = wp_parse_args ( [ 'blog' => get_option ( 'home' ) , 'blog_lang' => get_locale ( ) , 'blog_charset' => get_option ( 'blog_charset' ) , 'user_ip' => isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ? $ _SERVER [ 'REMOTE_ADDR' ] : '' , 'user_agent' => isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '' , 'referrer' => isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ? $ _SERVER [ 'HTTP_REFERER' ] : '' , ] , $ args ) ; foreach ( $ _SERVER as $ key => $ value ) { switch ( $ key ) { case 'REMOTE_ADDR' : case 'HTTP_USER_AGENT' : case 'HTTP_REFERER' : case 'HTTP_COOKIE' : case 'HTTP_COOKIE2' : case 'PHP_AUTH_PW' : break ; default : $ args [ $ key ] = $ value ; break ; } } return http_build_query ( $ args ) ; }
Make request arguments
11,843
public function get ( $ url , $ data = [ ] , $ method = 'post' ) { $ ch = curl_init ( $ this -> gitlab_host . '/api/v3' . $ url ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 0 ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'PRIVATE-TOKEN:' . $ this -> private_key ) ) ; if ( $ this -> debug ) { curl_setopt ( $ ch , CURLOPT_VERBOSE , true ) ; if ( ! \ sb \ Gateway :: $ command_line ) { $ curl_log = fopen ( "php://temp" , 'rw' ) ; curl_setopt ( $ ch , CURLOPT_STDERR , $ curl_log ) ; } } curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; if ( $ data ) { curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , http_build_query ( $ data ) ) ; if ( $ method != 'post' ) { curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ method ) ; } } $ error = curl_error ( $ ch ) ; $ error_no = curl_errno ( $ ch ) ; if ( $ error_no ) { throw ( new \ Exception ( $ error . ': ' . $ error_no ) ) ; } $ data = json_decode ( curl_exec ( $ ch ) ) ; if ( $ this -> debug && ! \ sb \ Gateway :: $ command_line ) { rewind ( $ curl_log ) ; $ output = fread ( $ curl_log , 2048 ) ; echo "<pre>" . print_r ( $ output , 1 ) . "</pre>" ; fclose ( $ curl_log ) ; } return $ data ; }
GRabs data from a URL and json_decodes it
11,844
private function getExampleFileContents ( $ filename ) { $ normalizedPath = null ; foreach ( $ this -> exampleDirectories as $ directory ) { $ exampleFileFromConfig = $ this -> constructExamplePath ( $ directory , $ filename ) ; if ( is_readable ( $ exampleFileFromConfig ) ) { $ normalizedPath = $ exampleFileFromConfig ; break ; } } if ( ! $ normalizedPath ) { if ( is_readable ( $ this -> getExamplePathFromSource ( $ filename ) ) ) { $ normalizedPath = $ this -> getExamplePathFromSource ( $ filename ) ; } elseif ( is_readable ( $ this -> getExamplePathFromExampleDirectory ( $ filename ) ) ) { $ normalizedPath = $ this -> getExamplePathFromExampleDirectory ( $ filename ) ; } elseif ( is_readable ( $ filename ) ) { $ normalizedPath = $ filename ; } } return $ normalizedPath && is_readable ( $ normalizedPath ) ? file ( $ normalizedPath ) : null ; }
Attempts to find the requested example file and returns its contents or null if no file was found .
11,845
public function addGraphMetadata ( GraphNode $ node , GraphMetadataInterface $ data ) { $ this -> nodes [ ] = [ 'node' => $ node , 'object' => $ data , ] ; return $ this ; }
Add OpenGraph metadata
11,846
public function match ( $ method , $ path , callable $ callback ) { $ route = new Route ( mb_strtoupper ( $ method ) , $ path , $ callback ) ; $ this -> _routes [ ] = $ route ; return $ route ; }
Maps a request to a callable .
11,847
public function check ( $ file , $ verify = null ) { if ( $ this -> prepareFile ( $ file ) ) { $ leads = $ this -> leads ( ) ; if ( ! is_null ( $ verify ) ) { if ( isset ( $ leads [ $ verify ] ) ) { return $ this -> checkLead ( $ leads [ $ verify ] ) ; } return false ; } else { foreach ( $ leads as $ lead ) { $ results = $ this -> checkLead ( $ lead ) ; if ( $ results === true ) { return true ; } else if ( $ results === false ) { break ; } } } } return false ; }
Check the the file against our leads .
11,848
protected function closeCase ( $ ext , $ mime , array $ meta = array ( ) ) { $ this -> caseClosed = true ; $ this -> extension = $ ext ; $ this -> mime = $ mime ; $ this -> metadata = $ meta ; return true ; }
Closes the case by setting protected properties .
11,849
protected function leads ( ) { $ leads = preg_grep ( '/^lead(?<ext>[A-Z0-9]+)$/' , get_class_methods ( $ this ) ) ; $ leads = array_combine ( $ leads , $ leads ) ; $ ext = "lead" . strtoupper ( pathinfo ( $ this -> file , PATHINFO_EXTENSION ) ) ; if ( isset ( $ leads [ $ ext ] ) ) { $ newLeads = [ $ ext => $ leads [ $ ext ] ] ; unset ( $ leads [ $ ext ] ) ; $ newLeads += $ leads ; $ leads = $ newLeads ; unset ( $ newleads ) ; } return $ leads ; }
Returns an array of file extensions this detective has leads on .
11,850
public function actionCreate ( ) { $ model = new Country ; try { if ( $ model -> load ( $ _POST ) && $ model -> save ( ) ) { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } elseif ( ! \ Yii :: $ app -> request -> isPost ) { $ model -> load ( $ _GET ) ; } } catch ( \ Exception $ e ) { $ msg = ( isset ( $ e -> errorInfo [ 2 ] ) ) ? $ e -> errorInfo [ 2 ] : $ e -> getMessage ( ) ; $ model -> addError ( '_exception' , $ msg ) ; } return $ this -> render ( 'create' , [ 'model' => $ model ] ) ; }
Creates a new Country model . If creation is successful the browser will be redirected to the view page .
11,851
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; if ( $ model -> load ( $ _POST ) && $ model -> save ( ) ) { return $ this -> redirect ( Url :: previous ( ) ) ; } else { return $ this -> render ( 'update' , [ 'model' => $ model , ] ) ; } }
Updates an existing Country model . If update is successful the browser will be redirected to the view page .
11,852
public function actionDelete ( $ id ) { try { $ this -> findModel ( $ id ) -> delete ( ) ; } catch ( \ Exception $ e ) { $ msg = ( isset ( $ e -> errorInfo [ 2 ] ) ) ? $ e -> errorInfo [ 2 ] : $ e -> getMessage ( ) ; \ Yii :: $ app -> getSession ( ) -> addFlash ( 'error' , $ msg ) ; return $ this -> redirect ( Url :: previous ( ) ) ; } $ isPivot = strstr ( '$id' , ',' ) ; if ( $ isPivot == true ) { return $ this -> redirect ( Url :: previous ( ) ) ; } elseif ( isset ( \ Yii :: $ app -> session [ '__crudReturnUrl' ] ) && \ Yii :: $ app -> session [ '__crudReturnUrl' ] != '/' ) { Url :: remember ( null ) ; $ url = \ Yii :: $ app -> session [ '__crudReturnUrl' ] ; \ Yii :: $ app -> session [ '__crudReturnUrl' ] = null ; return $ this -> redirect ( $ url ) ; } else { return $ this -> redirect ( [ 'index' ] ) ; } }
Deletes an existing Country model . If deletion is successful the browser will be redirected to the index page .
11,853
public static function create ( array $ params = [ ] ) { $ assembler = new static ( ) ; if ( ! empty ( $ params ) ) { array_walk ( $ params , function ( $ v , $ k ) use ( $ assembler ) { $ assembler -> $ k ( function ( ) use ( $ v ) { return $ v ; } ) ; } ) ; $ assembler -> assemble ( ) ; } return $ assembler ; }
Static Assembler constructor Returns a new Assembler
11,854
public static function get ( array $ params = [ ] ) { if ( empty ( self :: $ singleton ) ) { self :: $ singleton = static :: create ( $ params ) ; } return self :: $ singleton ; }
Return Singleton instance of Assembler
11,855
public function assemble ( ) { foreach ( $ this -> placeHolders as $ name => $ placeholder ) { if ( ! isset ( $ this -> values [ $ name ] ) ) { $ this -> values [ $ name ] = $ this -> addVars ( $ placeholder ) ; } } return $ this ; }
Run the Assembly not returning any value . Assembly will not overwrite anything already assembled
11,856
public function merge ( Assembler $ other ) { $ refl = new \ ReflectionObject ( $ other ) ; $ reflValues = $ refl -> getProperty ( 'values' ) ; $ reflValues -> setAccessible ( true ) ; $ oValues = $ reflValues -> getValue ( $ other ) ; if ( count ( $ oValues ) == 0 ) { return $ this ; } $ this -> values = array_merge ( $ this -> values , $ oValues ) ; return $ this ; }
Merge this assembly with another . Obeys the rules of array_merge
11,857
protected function addVars ( \ Closure $ func ) { $ args = ( new \ ReflectionFunction ( $ func ) ) -> getParameters ( ) ; if ( count ( $ args ) === 0 ) { return $ func ( ) ; } $ fArgs = array_map ( function ( $ key ) { return $ this -> values [ $ key ] ; } , array_map ( function ( $ arg ) { return $ arg -> getName ( ) ; } , $ args ) ) ; return call_user_func_array ( $ func , $ fArgs ) ; }
Execute the function assigned to the value binding in values created earlier in the assembly
11,858
protected function leadSVG ( ) { $ sanitizer = new Sanitizer ( ) ; $ dirtySVG = file_get_contents ( $ this -> file ) ; $ cleanSVG = $ sanitizer -> sanitize ( $ dirtySVG ) ; if ( is_string ( $ cleanSVG ) ) { return $ this -> closeCase ( "svg" , "image/svg+xml" ) ; } return false ; }
Checks if thise file is a valid SVG .
11,859
public static function resolve ( $ key ) { if ( $ key == 'B' ) return 0 ; $ dict = static :: $ metric ; if ( preg_match ( static :: IEC_PATTERN , $ key ) ) $ dict = static :: $ binary ; if ( array_key_exists ( $ key , $ dict ) ) return $ dict [ $ key ] ; throw new UnitNotFoundException ( sprintf ( 'Unit "%s" not found' , $ key ) ) ; }
Lookup the exponent based on prefix
11,860
public static function unitsAreDifferent ( $ first , $ second ) { return ( preg_match ( UnitResolver :: SI_PATTERN , $ first ) && preg_match ( UnitResolver :: IEC_PATTERN , $ second ) ) || ( preg_match ( UnitResolver :: IEC_PATTERN , $ first ) && preg_match ( UnitResolver :: SI_PATTERN , $ second ) ) ; }
Check if two units are in the same family
11,861
static function getAttributes ( $ obj , $ visibilityFlags = null , $ getterPrefix = 'get' , $ useCamelCase = true , $ convertInternalObjects = false ) { if ( ! isset ( $ obj ) ) { return array ( ) ; } $ flags = null === $ visibilityFlags ? self :: allFlags ( ) : $ visibilityFlags ; $ attributes = array ( ) ; $ reflectionObject = new \ ReflectionObject ( $ obj ) ; $ currentClass = new \ ReflectionClass ( $ obj ) ; while ( $ currentClass !== false && ! $ currentClass -> isInterface ( ) ) { $ properties = $ currentClass -> getProperties ( $ flags ) ; foreach ( $ properties as $ property ) { $ attributeName = $ property -> getName ( ) ; $ methodName = $ getterPrefix . ( $ useCamelCase ? self :: mb_ucfirst ( $ attributeName ) : $ attributeName ) ; if ( $ property -> isPrivate ( ) || $ property -> isProtected ( ) ) { if ( $ reflectionObject -> hasMethod ( $ methodName ) ) { $ method = $ reflectionObject -> getMethod ( $ methodName ) ; if ( $ method -> isPublic ( ) ) { $ attributes [ $ attributeName ] = $ method -> invoke ( $ obj ) ; } } else { $ attributes [ $ attributeName ] = $ obj -> { $ methodName } ( ) ; } } else { try { $ attributes [ $ attributeName ] = $ obj -> { $ attributeName } ; } catch ( \ Exception $ e ) { } } } if ( count ( $ properties ) < 1 ) { $ properties = get_object_vars ( $ obj ) ; foreach ( $ properties as $ k => $ v ) { $ attributes [ $ k ] = $ v ; } } $ currentClass = $ currentClass -> getParentClass ( ) ; } if ( $ convertInternalObjects ) { foreach ( $ attributes as $ key => $ value ) { if ( is_object ( $ value ) ) { $ attributes [ $ key ] = self :: getAttributes ( $ value , $ flags , $ getterPrefix , $ useCamelCase ) ; } } } return $ attributes ; }
Retrieve names and values from the attributes of a object as a map .
11,862
static function getPrivateAttributes ( $ obj , $ getterPrefix = 'get' , $ useCamelCase = true ) { return self :: getAttributes ( $ obj , self :: IS_PRIVATE , $ getterPrefix , $ useCamelCase ) ; }
Retrieve names and values from the private attributes of a object as a map . This method has been kept for backward compatibility .
11,863
static function setAttributes ( array $ map , & $ obj , $ visibilityFlags = null , $ setterPrefix = 'set' , $ useCamelCase = true ) { $ flags = null === $ visibilityFlags ? self :: allFlags ( ) : $ visibilityFlags ; $ reflectionObject = new \ ReflectionObject ( $ obj ) ; $ currentClass = new \ ReflectionClass ( $ obj ) ; while ( $ currentClass !== false && ! $ currentClass -> isInterface ( ) ) { $ properties = $ currentClass -> getProperties ( $ flags ) ; foreach ( $ properties as $ property ) { $ attributeName = $ property -> getName ( ) ; $ methodName = $ setterPrefix . ( $ useCamelCase ? self :: mb_ucfirst ( $ attributeName ) : $ attributeName ) ; if ( $ property -> isPrivate ( ) || $ property -> isProtected ( ) ) { if ( $ reflectionObject -> hasMethod ( $ methodName ) ) { $ method = $ reflectionObject -> getMethod ( $ methodName ) ; if ( $ method -> isPublic ( ) && array_key_exists ( $ attributeName , $ map ) ) { $ method -> invoke ( $ obj , $ map [ $ attributeName ] ) ; } } } else { try { if ( array_key_exists ( $ attributeName , $ map ) ) { $ obj -> { $ attributeName } = $ map [ $ attributeName ] ; } } catch ( \ Exception $ e ) { } } } if ( count ( $ properties ) < 1 ) { $ properties = get_object_vars ( $ obj ) ; foreach ( $ properties as $ attributeName => $ v ) { if ( array_key_exists ( $ attributeName , $ map ) ) { try { $ obj -> { $ attributeName } = $ map [ $ attributeName ] ; } catch ( \ Exception $ e ) { } } } } $ currentClass = $ currentClass -> getParentClass ( ) ; } }
Set the attribute values of a object .
11,864
static function setPrivateAttributes ( array $ map , & $ obj , $ setterPrefix = 'set' , $ useCamelCase = true ) { self :: setAttributes ( $ map , $ obj , \ RTTI :: IS_PRIVATE , $ setterPrefix , $ useCamelCase ) ; }
Set the attribute values of a object . This method has been kept for backward compatibility .
11,865
public function getResourceIdentifier ( ) { if ( $ this -> resolvedPath !== null ) { return $ this -> resolvedPath ; } elseif ( $ this -> includePath === null ) { return $ this -> file ; } else { foreach ( $ this -> includePath as $ path ) { $ path = rtrim ( $ path , DIRECTORY_SEPARATOR ) ; if ( file_exists ( $ path . DIRECTORY_SEPARATOR . $ this -> file ) === true ) { $ this -> resolvedPath = $ path . DIRECTORY_SEPARATOR . $ this -> file ; return $ this -> resolvedPath ; } } throw new Dwoo_Exception ( 'Template "' . $ this -> file . '" could not be found in any of your include path(s)' ) ; } }
returns this template s source filename
11,866
private function read ( ) { $ files = $ this -> getFilesystem ( ) -> allFiles ( app_path ( ) . '/database/seeds' ) ; $ filtered = [ ] ; foreach ( $ files as $ file ) { if ( strpos ( file_get_contents ( $ file -> getPathName ( ) ) , 'extends Seeder' ) != false ) { if ( $ file -> getFileName ( ) != 'DatabaseSeeder.php' ) { $ filtered [ ] = $ file -> getFileName ( ) ; } } } $ this -> setFiles ( $ filtered ) ; }
Get an array of all the files that is actually compatible with the files we re looking for .
11,867
private function write ( ) { $ content = '' ; foreach ( $ this -> getFiles ( ) as $ file ) { $ content .= '$this->call(\'' . str_replace ( '.php' , '' , $ file ) . '\');' ; } $ databaseSeeder = str_replace ( '{calls}' , $ content , $ this -> getPattern ( ) ) ; $ this -> getFilesystem ( ) -> put ( app_path ( ) . '/database/seeds/DatabaseSeeder.php' , $ databaseSeeder ) ; }
Write the new DatabaseSeeder . php
11,868
public function restore ( ) { $ this -> getFilesystem ( ) -> put ( app_path ( ) . '/database/seeds/DatabaseSeeder.php' , $ this -> getCopied ( ) ) ; $ this -> getFilesystem ( ) -> delete ( app_path ( ) . '/database/seeds/DatabaseSeeder.old' ) ; }
Restore the DatabaseSeeder . php file to it s previous version .
11,869
public function getList ( $ list ) { $ filteredList = [ ] ; foreach ( explode ( ',' , $ list ) as $ item ) { if ( $ item != '' ) { $ filteredList [ ] = $ item ; } } return $ filteredList ; }
Recieves the string list entered by the developer explode it and only return the ones filtered .
11,870
public function only ( $ list ) { $ this -> copy ( ) ; $ this -> readForOnly ( $ list ) ; $ this -> write ( ) ; $ this -> setSeeded ( count ( $ this -> getFiles ( ) ) ) ; return true ; }
Copy the current DatabaseSeeder . php file loop through each file and verify it s idententy with ther files array write the new DatabaseSeeder . php file and return true if it s alright .
11,871
public function get ( $ content , array $ variables = [ ] ) { $ replacements = [ ] ; $ instruction = 'foreach' ; foreach ( $ variables as $ key => $ values ) { $ inner = $ this -> getInnerInstruction ( $ content , $ instruction ) ; foreach ( $ inner as $ config ) { if ( ! str_contains ( $ config [ 'cleared' ] , $ key ) ) { continue ; } $ replacements [ $ key ] = $ inner ; } } if ( ! empty ( $ replacements ) ) { foreach ( $ replacements as $ key => $ value ) { foreach ( $ value as $ element ) { $ inner = $ this -> renderByTwig ( $ element [ 'cleared' ] , $ variables ) ; $ content = str_replace ( [ "[[{$instruction}]]" , "[[/{$instruction}]]" , $ element [ 'to_replace' ] ] , [ '' , '' , $ inner ] , $ content ) ; } } } $ content = str_replace ( [ '<p>' , '</p>' , '<br />' ] , '' , $ content ) ; $ filled = $ this -> fill ( $ content ) ; preg_match_all ( '/\[\[(.*?)\]\]/' , $ content , $ matches ) ; if ( ! isset ( $ matches [ 0 ] ) or ! isset ( $ matches [ 1 ] ) ) { return $ filled ; } foreach ( $ matches [ 0 ] as $ index => $ variable ) { $ filled = str_replace ( $ variable , '{{ ' . $ matches [ 1 ] [ $ index ] . ' }}' , $ filled ) ; } return $ this -> renderByTwig ( $ filled , array_merge ( $ variables , $ this -> variables ) ) ; }
Gets variables filled notification content
11,872
public function fill ( $ content ) { if ( $ this -> hasInstructions ( $ content ) ) { $ instructions = $ this -> getInstructions ( ) ; foreach ( $ instructions as $ instruction ) { $ content = $ this -> parseInstructions ( $ content , $ instruction ) ; } } return $ this -> fillContent ( $ content ) ; }
fill notification notification content with variables
11,873
protected function hasInstructions ( $ content ) { $ instructionKeys = $ this -> getInstructions ( ) ; foreach ( $ instructionKeys as $ instructionKey ) { if ( str_contains ( $ content , [ '[[' . $ instructionKey . ']]' , '[[/' . $ instructionKey . ']]' ] ) ) { return true ; } } return false ; }
whether notification has instructions
11,874
protected function parseInstructions ( $ content , $ instruction ) { $ twig = new Twig_Environment ( new Twig_Loader_String ( ) ) ; $ sources = $ this -> getStringsBetween ( $ content , "[[{$instruction}]]" , "[[/{$instruction}]]" ) ; foreach ( $ sources as $ source ) { $ toReplace = $ source ; $ source = $ this -> clearCondition ( $ source ) ; if ( $ source === '' ) { return $ content ; } $ variables = $ this -> extractVariables ( $ source ) ; $ renderParams = [ ] ; foreach ( array_keys ( $ variables ) as $ index => $ key ) { $ localVariable = 'var_' . $ index ; $ source = str_replace ( $ key , $ localVariable , $ source ) ; $ renderParams [ $ localVariable ] = $ variables [ $ key ] ; } $ content = str_replace ( [ "[[{$instruction}]]" , "[[/{$instruction}]]" , $ toReplace ] , [ '' , '' , $ twig -> render ( $ source , $ renderParams ) ] , $ content ) ; } return $ content ; }
parsing instructions in notification content
11,875
protected function clearCondition ( $ source ) { $ line = $ this -> getStringBetween ( $ source , '{%' , '%}' ) ; if ( strlen ( $ line ) > 0 ) { return str_replace ( [ '&#39;' , '&nbsp;' ] , [ "'" , ' ' ] , $ source ) ; } return $ source ; }
clear conditions in notification
11,876
public function getStringsBetween ( $ string , $ start , $ end ) { $ lastPos = 0 ; $ positions = array ( ) ; while ( ( $ lastPos = strpos ( $ string , $ start , $ lastPos ) ) !== false ) { $ positions [ ] = $ lastPos ; $ lastPos += strlen ( $ start ) ; } $ lastPos = 0 ; $ positionsEnd = array ( ) ; while ( ( $ lastPos = strpos ( $ string , $ end , $ lastPos ) ) !== false ) { $ positionsEnd [ ] = $ lastPos ; $ lastPos += strlen ( $ end ) ; } $ return = [ ] ; foreach ( $ positions as $ index => $ position ) { $ return [ ] = str_replace ( [ $ start , $ end ] , '' , substr ( $ string , $ position , $ positionsEnd [ $ index ] - $ position ) ) ; } return $ return ; }
gets list of occurences between two strings
11,877
protected function extractVariables ( $ content ) { preg_match_all ( '/\[\[(.*?)\]\]/' , $ content , $ matches ) ; if ( ! isset ( $ matches [ 0 ] , $ matches [ 1 ] ) ) { return [ ] ; } $ return = [ ] ; $ notifications = \ Antares \ Foundation \ Notification :: getInstance ( ) -> all ( ) ; foreach ( $ matches [ 1 ] as $ index => $ match ) { if ( ! str_contains ( $ match , '::' ) ) { continue ; } list ( $ component , $ var ) = explode ( '::' , trim ( $ match ) ) ; $ name = $ this -> findExtensionName ( $ component ) ; if ( ! $ name ) { continue ; } $ variables = $ notifications [ $ name ] [ 'variables' ] ; $ return [ $ matches [ 0 ] [ $ index ] ] = $ this -> resolveValue ( $ var , $ variables ) ; } return $ return ; }
extract variables from notification
11,878
protected function fillContent ( $ content ) { preg_match_all ( '/\[\[(.*?)\]\]/' , $ content , $ matches ) ; if ( ! isset ( $ matches [ 0 ] ) or ! isset ( $ matches [ 1 ] ) ) { return $ content ; } $ notifications = \ Antares \ Foundation \ Notification :: getInstance ( ) -> all ( ) ; foreach ( ( array ) $ matches [ 1 ] as $ index => $ match ) { if ( ! str_contains ( $ match , '::' ) ) { continue ; } list ( $ component , $ var ) = explode ( '::' , trim ( $ match ) ) ; $ name = $ this -> findExtensionName ( $ component ) ; $ variables = isset ( $ notifications [ $ name ] [ 'variables' ] ) ? $ notifications [ $ name ] [ 'variables' ] : [ ] ; event ( 'notifications:notification.variables' , [ & $ variables ] ) ; $ value = $ this -> resolveValue ( $ var , $ variables ) ; if ( is_array ( $ value ) ) { $ value = $ this -> getDefaultNotificationForList ( $ value ) -> render ( ) ; } $ content = str_replace ( $ matches [ 0 ] [ $ index ] , $ value , $ content ) ; } return $ content ; }
fills content with notification variables values
11,879
protected function resolveValue ( $ name , $ variables ) { if ( ! empty ( $ variables ) ) { foreach ( $ variables as $ container => $ vars ) { foreach ( $ vars as $ subname => $ var ) { $ value = $ var [ 'value' ] ; if ( is_callable ( $ value ) && $ var [ 'name' ] === $ name ) { return $ value ( $ this -> variables ) ; } if ( isset ( $ var [ 'name' ] ) and $ name == $ value and isset ( $ value ) ) { return $ value ; } elseif ( ! isset ( $ var [ 'name' ] ) and $ subname == $ name and isset ( $ value ) ) { return $ value ; } } } } if ( ! isset ( $ variables [ $ name ] ) ) { return false ; } if ( isset ( $ variable [ 'dataProvider' ] ) ) { $ value = $ this -> resolveDataProviderValue ( $ variable [ 'dataProvider' ] ) ; if ( ! $ value ) { return false ; } return $ value ; } return array_get ( $ variable , 'value' , '' ) ; }
resolve notification variable value
11,880
protected function resolveDataProviderValue ( $ dataProvider ) { preg_match ( "/(.*)@(.*)/" , $ dataProvider , $ matches ) ; if ( ! isset ( $ matches [ 1 ] ) and ! isset ( $ matches [ 2 ] ) ) { return false ; } if ( ! class_exists ( $ matches [ 1 ] ) ) { return false ; } try { $ instance = app ( $ matches [ 1 ] ) ; $ return = call_user_func_array ( [ $ instance , $ matches [ 2 ] ] , [ ] ) ; if ( $ return instanceof Builder ) { return $ return -> get ( ) -> toArray ( ) ; } if ( $ return instanceof Collection ) { return $ return -> toArray ( ) ; } return $ return ; } catch ( Exception $ ex ) { return false ; } }
resolve notification variable value from data provider
11,881
protected function findExtensionName ( $ name ) { if ( $ name == 'foundation' ) { return $ name ; } $ extensions = app ( 'antares.memory' ) -> make ( 'component' ) -> get ( 'extensions.active' ) ; foreach ( $ extensions as $ keyname => $ extension ) { if ( $ name == $ extension [ 'name' ] ) { return $ keyname ; } } return false ; }
get extension key name by name from manifest
11,882
protected function searchCookiesInHeaders ( ) { $ headers = $ this -> holder -> getHeaders ( ) -> get ( 'set-cookie' ) ; foreach ( $ headers as $ header ) { $ cookie = $ this -> createCookieFromHeader ( $ header ) ; if ( $ cookie !== null ) { $ this -> storeCookie ( $ cookie ) ; } } }
Parse headers for cookies .
11,883
public function save ( $ log_dir = '' ) { if ( empty ( $ log_dir ) ) { $ log_dir = \ ROOT . '/private/logs/syslog/' ; } if ( ! is_dir ( $ log_dir ) ) { mkdir ( $ log_dir , 0777 , true ) ; } return file_put_contents ( $ log_dir . date ( 'Y_m_d' ) . '.log' , $ this -> message . "\n" , \ FILE_APPEND ) ; }
Saves data to local logs dir when syslog server is not available
11,884
protected function checkLength ( $ str , $ max_length = '' , $ type = 'packet' ) { $ max_length = $ max_length ? $ max_length : $ this -> max_length ; if ( $ max_length == - 1 ) { return $ str ; } $ strlen = strlen ( $ str ) ; if ( $ strlen > $ max_length ) { throw new \ Exception ( "Syslog " . $ type . " is > " . $ max_length . " (" . $ strlen . ") in length and will be truncated. Original str is: " . $ str , E_USER_WARNING ) ; return substr ( $ str , 0 , $ max_length ) ; } return $ str ; }
Checks to make sure the length of something is expected or warn and truncate
11,885
public static function parse ( $ input , $ exceptionOnInvalidType = false , $ objectSupport = false ) { $ file = '' ; if ( strpos ( $ input , "\n" ) === false && is_file ( $ input ) ) { if ( false === is_readable ( $ input ) ) { throw new ParseException ( sprintf ( 'Unable to parse "%s" as the file is not readable.' , $ input ) ) ; } $ file = $ input ; $ input = file_get_contents ( $ file ) ; } $ yaml = new Parser ( ) ; try { return $ yaml -> parse ( $ input , $ exceptionOnInvalidType , $ objectSupport ) ; } catch ( ParseException $ e ) { if ( $ file ) { $ e -> setParsedFile ( $ file ) ; } throw $ e ; } }
Parses YAML into a PHP array .
11,886
protected function getSpacerType ( ) { $ type = "" ; if ( ! $ this -> currObj instanceof Channel || ! $ this -> currObj -> isSpacer ( ) ) { return "none" ; } switch ( $ this -> currObj -> spacerGetType ( ) ) { case ( string ) TeamSpeak3 :: SPACER_SOLIDLINE : $ type .= "solidline" ; break ; case ( string ) TeamSpeak3 :: SPACER_DASHLINE : $ type .= "dashline" ; break ; case ( string ) TeamSpeak3 :: SPACER_DASHDOTLINE : $ type .= "dashdotline" ; break ; case ( string ) TeamSpeak3 :: SPACER_DASHDOTDOTLINE : $ type .= "dashdotdotline" ; break ; case ( string ) TeamSpeak3 :: SPACER_DOTLINE : $ type .= "dotline" ; break ; default : $ type .= "custom" ; } if ( $ type == "custom" ) { switch ( $ this -> currObj -> spacerGetAlign ( ) ) { case TeamSpeak3 :: SPACER_ALIGN_REPEAT : $ type .= "repeat" ; break ; case TeamSpeak3 :: SPACER_ALIGN_CENTER : $ type .= "center" ; break ; case TeamSpeak3 :: SPACER_ALIGN_RIGHT : $ type .= "right" ; break ; default : $ type .= "left" ; } } return $ type ; }
Returns an individual type for a spacer .
11,887
protected function getName ( ) { if ( $ this -> currObj instanceof Channel && $ this -> currObj -> isSpacer ( ) ) { return $ this -> currObj [ "channel_name" ] -> section ( "]" , 1 , 99 ) -> toString ( ) ; } elseif ( $ this -> currObj instanceof Client ) { $ before = array ( ) ; $ behind = array ( ) ; foreach ( $ this -> currObj -> memberOf ( ) as $ group ) { if ( $ group -> getProperty ( "namemode" ) == TeamSpeak3 :: GROUP_NAMEMODE_BEFORE ) { $ before [ ] = "[" . $ group [ "name" ] . "]" ; } elseif ( $ group -> getProperty ( "namemode" ) == TeamSpeak3 :: GROUP_NAMEMODE_BEHIND ) { $ behind [ ] = "[" . $ group [ "name" ] . "]" ; } } return trim ( implode ( "" , $ before ) . " " . $ this -> currObj . " " . implode ( "" , $ behind ) ) ; } return $ this -> currObj -> toString ( ) ; }
Returns a string for the current corpus element which contains the display name for the current TeamSpeak_Node_Abstract object .
11,888
public function store ( $ key , $ data , $ lifetime = 0 ) { $ key = $ this -> namespace . $ key ; $ store = apc_store ( $ key , $ data , $ lifetime ) ; if ( $ store && $ key != $ this -> namespace . $ this -> catalog_key ) { $ this -> catalogKeyAdd ( $ key , $ lifetime ) ; } return $ store ; }
Store the cache data in APC
11,889
private function catalogKeyAdd ( $ key , $ lifetime ) { $ catalog = $ this -> fetch ( $ this -> catalog_key ) ; $ catalog = is_array ( $ catalog ) ? $ catalog : Array ( ) ; $ catalog [ $ key ] = ( $ lifetime == 0 ) ? $ lifetime : $ lifetime + time ( ) ; return $ this -> store ( $ this -> catalog_key , $ catalog ) ; }
Keeps track of the data stored in the cache to make deleting groups of data possible
11,890
public function getOptions ( ) { $ options = array ( ) ; foreach ( $ this -> commandOptions as $ key => $ value ) { $ options [ $ key ] = $ this -> $ value ; } return $ options ; }
Returns a two dimensional array of options to pass to the command The key is the
11,891
public function getArguments ( ) { $ arguments = array ( ) ; foreach ( $ this -> commandArguments as $ argument ) { $ arguments [ ] = $ this -> $ argument ; } return $ arguments ; }
Returns a one dimensional array of arguments to pass to the command
11,892
public function commonApplicationAttributes ( ) { return [ 'modules' => [ 'users' => [ 'emailConfirmationNeeded' => ( bool ) $ this -> emailConfirmationNeeded , 'allowLoginInactiveAccounts' => ( bool ) $ this -> allowLoginInactiveAccounts , 'enableSocialNetworks' => ( bool ) $ this -> enableSocialNetworks , 'logLastLoginTime' => ( bool ) $ this -> logLastLoginTime , 'logLastLoginData' => ( bool ) $ this -> logLastLoginData , 'passwordResetTokenExpire' => ( int ) $ this -> passwordResetTokenExpire , 'loginDuration' => ( int ) $ this -> loginDuration , 'generatedPasswordLength' => ( int ) $ this -> generatedPasswordLength , ] ] , ] ; }
Returns array of module configuration that should be stored in application config . Array should be ready to merge in app config . Used both for web and console .
11,893
public function socialLogin ( $ serviceName ) { if ( config ( 'services.' . $ serviceName ) ) { $ this -> setDynamicRedirectUrl ( $ serviceName ) ; return $ this -> socialite -> driver ( $ serviceName ) -> redirect ( ) ; } return redirect ( '/' ) ; }
Function responsible for login the user by the given social service .
11,894
public function socialCallback ( Request $ request , $ serviceName ) { try { $ this -> setDynamicRedirectUrl ( $ serviceName ) ; $ user = $ this -> socialite -> driver ( $ serviceName ) -> user ( ) ; $ this -> authService -> login ( $ serviceName , $ user ) ; return redirect ( session ( 'url.intended' , '/' ) ) ; } catch ( \ Exception $ e ) { Log :: error ( 'Social login failed: ' . $ e -> getMessage ( ) . ' - ' . print_r ( $ request -> all ( ) , true ) ) ; if ( session ( ) -> has ( 'url.intended' ) ) { $ reditectUrl = session ( 'url.intended' ) ; session ( ) -> forget ( 'url.intended' ) ; session ( ) -> flash ( 'messages' , [ [ 'code' => 'error' , 'text' => $ e -> getMessage ( ) ] ] ) ; return redirect ( $ reditectUrl ) ; } else { return app ( ) -> abort ( 500 , $ e -> getMessage ( ) ) ; } } }
Function responsible for handle a callback request from the given social service .
11,895
protected function registerPlugin ( ) { $ id = $ this -> options [ 'id' ] ; $ view = $ this -> getView ( ) ; yii2instafeedAsset :: register ( $ view ) ; $ js = array ( ) ; $ options = Json :: encode ( $ this -> clientOptions ) ; $ js [ ] = "var feed$id = new Instafeed($options);" ; $ js [ ] = "feed$id.run();" ; $ view -> registerJs ( implode ( "\n" , $ js ) , View :: POS_READY ) ; }
Registers a specific dhtmlx widget and the related events
11,896
public function salvarArquivo ( $ arquivo ) { $ this -> verificaChaveNula ( ) ; $ xml = file_get_contents ( __DIR__ . '/../Templates/certificado.xml' ) ; $ xml = str_replace ( '{{chave_pub}}' , $ this -> chavePub , $ xml ) ; $ xml = str_replace ( '{{chave_pri}}' , $ this -> chavePri , $ xml ) ; file_put_contents ( $ arquivo , $ xml ) ; return true ; }
Salva um arquivo com as propriedades do certificado .
11,897
public function getValidade ( ) { $ this -> verificaChaveNula ( ) ; $ data = openssl_x509_read ( $ this -> chavePub ) ; $ certData = openssl_x509_parse ( $ data ) ; return Carbon :: createFromFormat ( 'ymdHis' , str_replace ( 'Z' , '' , $ certData [ 'validTo' ] ) ) ; }
Retorna a data e hora da validade do certificado .
11,898
public function getFollows ( $ user , $ params = [ ] ) { $ defaults = [ 'limit' => 25 , 'offset' => 0 , 'direction' => 'desc' , 'sortby' => 'created_at' , ] ; return $ this -> wrapper -> request ( 'GET' , "users/$user/follows/channels" , [ 'query' => $ this -> resolveOptions ( $ params , $ defaults ) ] ) ; }
Returns a list of follows objects .
11,899
public function channel ( $ bind = [ ] ) : Observable { $ this -> bunny = $ this -> bunny ?? new BaseAsynchClient ( $ this -> loop , $ this -> configuration ) ; if ( ! \ is_array ( $ bind ) ) { $ bind = \ func_get_args ( ) ; } return Observable :: fromPromise ( $ this -> bunny -> connect ( ) -> then ( function ( BaseAsynchClient $ client ) { return $ client -> channel ( ) ; } ) -> then ( function ( Channel $ channel ) use ( $ bind ) { foreach ( $ bind as $ obj ) { $ obj -> setChannel ( $ channel ) ; } return $ channel ; } ) ) ; }
Open a new channel and attribute it to given queues or exchanges .