idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,600
protected function populateAnnotationCacheFilename ( ) { if ( isset ( $ this -> annotationCacheFilename ) ) { return $ this -> annotationCacheFilename ; } $ directory = $ this -> cacheDir . '/DtcGridBundle' ; $ metadata = $ this -> getClassMetadata ( ) ; $ reflectionClass = $ metadata -> getReflectionClass ( ) ; $ name = $ reflectionClass -> getName ( ) ; $ namespace = $ reflectionClass -> getNamespaceName ( ) ; $ namespace = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ namespace ) ; $ namespaceDir = $ directory . DIRECTORY_SEPARATOR . $ namespace ; $ umask = decoct ( umask ( ) ) ; $ umask = str_pad ( $ umask , 4 , '0' , STR_PAD_LEFT ) ; $ permissions = '0777' ; $ permissions [ 1 ] = intval ( $ permissions [ 1 ] ) - intval ( $ umask [ 1 ] ) ; $ permissions [ 2 ] = intval ( $ permissions [ 2 ] ) - intval ( $ umask [ 2 ] ) ; $ permissions [ 3 ] = intval ( $ permissions [ 3 ] ) - intval ( $ umask [ 3 ] ) ; if ( ! is_dir ( $ namespaceDir ) && ! mkdir ( $ namespaceDir , octdec ( $ permissions ) , true ) ) { throw new \ Exception ( "Can't create: " . $ namespaceDir ) ; } $ name = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ name ) ; $ this -> annotationCacheFilename = $ directory . DIRECTORY_SEPARATOR . $ name . '.php' ; return $ this -> annotationCacheFilename ; }
Populates the filename for the annotationCache .
48,601
protected function getAnnotationColumns ( ) { if ( ! isset ( $ this -> reader ) ) { return null ; } if ( ! isset ( $ this -> cacheDir ) ) { return null ; } if ( ! isset ( $ this -> annotationCacheFilename ) ) { $ this -> populateAnnotationCacheFilename ( ) ; } if ( ! $ this -> debug && null !== $ this -> annotationColumns ) { return $ this -> annotationColumns ? : null ; } if ( is_file ( $ this -> annotationCacheFilename ) ) { $ result = $ this -> tryIncludeAnnotationCache ( ) ; if ( $ result ) { return $ this -> annotationColumns ; } } $ this -> populateAndCacheAnnotationColumns ( ) ; return $ this -> annotationColumns ? : null ; }
Attempt to discover columns using the GridColumn annotation .
48,602
protected function includeAnnotationCache ( ) { $ annotationInfo = include $ this -> annotationCacheFilename ; $ this -> annotationColumns = $ annotationInfo [ 'columns' ] ; $ this -> annotationSort = $ annotationInfo [ 'sort' ] ; if ( $ this -> annotationSort ) { $ this -> validateSortInfo ( $ this -> annotationSort , $ this -> annotationColumns ) ; } }
Retrieves the cached annotations from the cache file .
48,603
protected function populateAndCacheAnnotationColumns ( ) { $ gridAnnotations = $ this -> readGridAnnotations ( ) ; $ annotationColumns = $ gridAnnotations [ 'columns' ] ; $ sort = $ gridAnnotations [ 'sort' ] ; if ( $ annotationColumns ) { $ output = "<?php\nreturn array('columns' => array(\n" ; foreach ( $ annotationColumns as $ field => $ info ) { $ class = $ info [ 'class' ] ; $ output .= "'$field' => new $class(" ; $ first = true ; foreach ( $ info [ 'arguments' ] as $ argument ) { if ( $ first ) { $ first = false ; } else { $ output .= ',' ; } $ output .= var_export ( $ argument , true ) ; } $ output .= '),' ; } $ output .= "), 'sort' => array(" ; foreach ( $ sort as $ key => $ value ) { $ output .= "'$key'" . ' => ' ; if ( null === $ value ) { $ output .= 'null,' ; } else { $ output .= "'$value'," ; } } $ output .= "));\n" ; } else { $ output = "<?php\nreturn false;\n" ; } file_put_contents ( $ this -> annotationCacheFilename , $ output ) ; $ this -> includeAnnotationCache ( ) ; }
Caches the annotation columns result into a file .
48,604
protected function getReflectionColumns ( ) { $ metadata = $ this -> getClassMetadata ( ) ; $ fields = $ metadata -> getFieldNames ( ) ; $ identifier = $ metadata -> getIdentifier ( ) ; $ identifier = isset ( $ identifier [ 0 ] ) ? $ identifier [ 0 ] : null ; $ columns = array ( ) ; foreach ( $ fields as $ field ) { $ mapping = $ metadata -> getFieldMapping ( $ field ) ; if ( isset ( $ mapping [ 'options' ] ) && isset ( $ mapping [ 'options' ] [ 'label' ] ) ) { $ label = $ mapping [ 'options' ] [ 'label' ] ; } else { $ label = $ this -> fromCamelCase ( $ field ) ; } if ( $ identifier === $ field ) { if ( isset ( $ mapping [ 'strategy' ] ) && 'auto' == $ mapping [ 'strategy' ] ) { continue ; } } $ columns [ $ field ] = new GridColumn ( $ field , $ label ) ; } return $ columns ; }
Generate Columns based on document s Metadata .
48,605
public function get ( $ entityOrDocumentNameOrId ) { if ( isset ( $ this -> extraGridSources [ $ entityOrDocumentNameOrId ] ) ) { return $ this -> extraGridSources [ $ entityOrDocumentNameOrId ] ; } if ( isset ( $ this -> sourcesByClass [ $ entityOrDocumentNameOrId ] ) ) { return $ this -> sourcesByClass [ $ entityOrDocumentNameOrId ] ; } if ( isset ( $ this -> sourcesByName [ $ entityOrDocumentNameOrId ] ) ) { return $ this -> sourcesByName [ $ entityOrDocumentNameOrId ] ; } try { if ( $ this -> registry && ( $ manager = $ this -> registry -> getManagerForClass ( $ entityOrDocumentNameOrId ) ) && $ gridSource = $ this -> getGridSource ( $ manager , $ entityOrDocumentNameOrId ) ) { return $ gridSource ; } } catch ( \ ReflectionException $ exception ) { } if ( $ this -> mongodbRegistry && ( $ manager = $ this -> mongodbRegistry -> getManagerForClass ( $ entityOrDocumentNameOrId ) ) && $ gridSource = $ this -> getGridSource ( $ manager , $ entityOrDocumentNameOrId ) ) { return $ gridSource ; } throw new \ Exception ( "Can't find grid source for $entityOrDocumentNameOrId" ) ; }
Get a gridsource .
48,606
public function fillForm ( $ selector , $ data = array ( ) , $ submit = false ) { $ jsonData = json_encode ( $ data ) ; $ jsonSubmit = ( $ submit ) ? 'true' : 'false' ; $ fragment = <<<FRAGMENTcasper.then(function () { this.fill('$selector', $jsonData, $jsonSubmit);});FRAGMENT ; $ this -> script .= $ fragment ; return $ this ; }
fill the form with the array of data then submit it if submit is true
48,607
public function run ( ) { $ output = array ( ) ; $ fragment = <<<FRAGMENTcasper.then(function () { this.echo('$this->TAG_CURRENT_URL' + this.getCurrentUrl()); this.echo('$this->TAG_CURRENT_TITLE' + this.getTitle()); this.echo('$this->TAG_CURRENT_PAGE_CONTENT' + this.getPageContent().replace(new RegExp('\\r?\\n','g'), '')); this.echo('$this->TAG_CURRENT_HTML' + this.getHTML().replace(new RegExp('\\r?\\n','g'), '')); this.echo('$this->TAG_CURRENT_HEADERS' + JSON.stringify(this.currentResponse.headers)); this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status); this.echo('$this->TAG_CURRENT_STATUS_TEXT' + this.currentResponse.statusText); this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies));});casper.run();FRAGMENT ; $ this -> script .= $ fragment ; $ filename = tempnam ( $ this -> tempDir , 'php-casperjs-' ) ; file_put_contents ( $ filename , $ this -> script ) ; $ options = '' ; foreach ( $ this -> options as $ option => $ value ) { $ options .= ' --' . $ option . '=' . $ value ; } exec ( $ this -> path2casper . 'casperjs ' . $ filename . $ options , $ output ) ; if ( empty ( $ output ) ) { throw new \ Exception ( 'Can not find CasperJS.' ) ; } $ this -> setOutput ( $ output ) ; $ this -> processOutput ( ) ; unlink ( $ filename ) ; return $ output ; }
run the casperJS script and return the stdOut in using the output variable
48,608
private function processOutput ( ) { foreach ( $ this -> getOutput ( ) as $ outputLine ) { if ( strpos ( $ outputLine , $ this -> TAG_CURRENT_URL ) !== false ) { $ this -> currentUrl = str_replace ( $ this -> TAG_CURRENT_URL , '' , $ outputLine ) ; } if ( strpos ( $ outputLine , "Navigation requested: url=" ) !== false ) { $ frag0 = explode ( 'Navigation requested: url=' , $ outputLine ) ; $ frag1 = explode ( ', type=' , $ frag0 [ 1 ] ) ; $ this -> requestedUrls [ ] = $ frag1 [ 0 ] ; } if ( $ this -> isDebug ( ) ) { syslog ( LOG_INFO , '[PHP-CASPERJS] ' . $ outputLine ) ; } if ( strpos ( $ outputLine , $ this -> TAG_CURRENT_PAGE_CONTENT ) !== false ) { $ this -> currentPageContent = str_replace ( $ this -> TAG_CURRENT_PAGE_CONTENT , '' , $ outputLine ) ; } if ( strpos ( $ outputLine , $ this -> TAG_CURRENT_HTML ) !== false ) { $ this -> currentHtml = str_replace ( $ this -> TAG_CURRENT_HTML , '' , $ outputLine ) ; } if ( strpos ( $ outputLine , " steps in " ) !== false ) { $ frag = explode ( ' steps in ' , $ outputLine ) ; $ this -> loadTime = $ frag [ 1 ] ; } if ( 0 === strpos ( $ outputLine , $ this -> TAG_CURRENT_HEADERS ) ) { $ this -> headers = json_decode ( str_replace ( $ this -> TAG_CURRENT_HEADERS , '' , $ outputLine ) , true ) ; } if ( 0 === strpos ( $ outputLine , $ this -> TAG_CURRENT_STATUS ) ) { $ this -> status = ( int ) str_replace ( $ this -> TAG_CURRENT_STATUS , '' , $ outputLine ) ; } if ( 0 === strpos ( $ outputLine , $ this -> TAG_CURRENT_STATUS_TEXT ) ) { $ this -> statusText = trim ( str_replace ( $ this -> TAG_CURRENT_STATUS_TEXT , '' , $ outputLine ) ) ; } if ( 0 === strpos ( $ outputLine , $ this -> TAG_CURRENT_COOKIES ) ) { $ this -> cookies = json_decode ( str_replace ( $ this -> TAG_CURRENT_COOKIES , '' , $ outputLine ) , true ) ; } } }
process the output after navigation and fill the differents attributes for later usage
48,609
public function delete ( $ token , $ type ) { $ this -> getTable ( ) -> where ( 'token' , $ token ) -> where ( 'type' , $ type ) -> delete ( ) ; }
Delete a token record by token .
48,610
public function createDatabaseDriver ( ) { $ provider = $ this -> createDatabaseProvider ( ) ; return new Guard ( $ provider , $ this -> app [ 'session.store' ] , $ this -> name ) ; }
Create an instance of the database driver .
48,611
public function createEloquentDriver ( ) { $ provider = $ this -> createEloquentProvider ( ) ; return new Guard ( $ provider , $ this -> app [ 'session.store' ] , $ this -> name ) ; }
Create an instance of the Eloquent driver .
48,612
public function signatureParameters ( array $ protocolParameters , array $ requestOptions = [ ] ) { $ parameters = $ protocolParameters ; if ( $ this -> requestOptionsHas ( $ requestOptions , 'query' ) ) { $ parameters = array_merge ( $ parameters , $ requestOptions [ 'query' ] ) ; } if ( $ this -> requestOptionsHas ( $ requestOptions , 'form_params' ) ) { $ parameters = array_merge ( $ parameters , $ requestOptions [ 'form_params' ] ) ; } return $ parameters ; }
Build the signature parameters to be signed .
48,613
public function setupSigner ( ServerIssuedCredentials $ serverIssuedCredentials = null ) { if ( $ this -> shouldSignWithClientCredentials ( ) ) { $ this -> signer -> setClientCredentials ( $ this -> config -> getClientCredentials ( ) ) ; } if ( $ this -> shouldSignWithServerIssuedCredentials ( $ serverIssuedCredentials ) ) { $ this -> signer -> setServerIssuedCredentials ( $ serverIssuedCredentials ) ; } return $ this -> signer ; }
Setup the signer .
48,614
public function requestOptionsHas ( array $ requestOptions , $ key ) { return isset ( $ requestOptions [ $ key ] ) && is_array ( $ requestOptions [ $ key ] ) && count ( $ requestOptions [ $ key ] ) > 0 ; }
Check if request options has the given key option .
48,615
public function normalizeParameters ( array $ parameters ) { $ normalized = [ ] ; foreach ( $ parameters as $ key => $ value ) { $ key = rawurlencode ( rawurldecode ( $ key ) ) ; if ( is_array ( $ value ) ) { $ normalized [ $ key ] = $ this -> normalizeParameters ( $ value ) ; } else { $ normalized [ $ key ] = rawurlencode ( rawurldecode ( $ value ) ) ; } } ksort ( $ normalized ) ; return $ normalized ; }
Normalize the given request parameters .
48,616
public function buildQueryString ( array $ parameters , array $ initialQueryParameters = [ ] , $ previousKey = null ) { $ queryParameters = $ initialQueryParameters ; foreach ( $ parameters as $ key => $ value ) { if ( null !== $ previousKey ) { $ key = "{$previousKey}[{$key}]" ; } if ( is_array ( $ value ) ) { $ queryParameters = $ this -> buildQueryString ( $ value , $ queryParameters , $ key ) ; } else { $ queryParameters [ ] = "{$key}={$value}" ; } } return null !== $ previousKey ? $ queryParameters : implode ( '&' , $ queryParameters ) ; }
Build query string from the given parameters .
48,617
public function getParametersFromResponse ( ResponseInterface $ response ) { $ contents = $ response -> getBody ( ) -> getContents ( ) ; $ parameters = [ ] ; parse_str ( $ contents , $ parameters ) ; return $ parameters ; }
Get parameters from response .
48,618
public function getMissingParameterKey ( array $ parameters , array $ requiredKeys = [ ] ) { foreach ( $ requiredKeys as $ key ) { if ( ! isset ( $ parameters [ $ key ] ) ) { return $ key ; } } }
Get missing parameter s key .
48,619
public function getKey ( ) { $ key = '' ; if ( $ this -> clientCredentials instanceof ClientCredentials ) { $ key .= rawurlencode ( $ this -> clientCredentials -> getSecret ( ) ) ; } $ key .= '&' ; if ( $ this -> serverIssuedCredentials instanceof ServerIssuedCredentials ) { $ key .= rawurlencode ( $ this -> serverIssuedCredentials -> getSecret ( ) ) ; } return $ key ; }
Get the key for signing .
48,620
public function setFromArray ( array $ uris ) { $ this -> validateUris ( $ uris ) ; $ this -> temporaryCredentials = $ this -> parser -> toPsrUri ( $ uris [ 'temporary_credentials_uri' ] ) ; $ this -> authorization = $ this -> parser -> toPsrUri ( $ uris [ 'authorization_uri' ] ) ; $ this -> tokenCredentials = $ this -> parser -> toPsrUri ( $ uris [ 'token_credentials_uri' ] ) ; if ( isset ( $ uris [ 'base_uri' ] ) ) { $ this -> setBase ( $ this -> parser -> toPsrUri ( $ uris [ 'base_uri' ] ) ) ; } if ( isset ( $ uris [ 'callback_uri' ] ) ) { $ this -> callback = $ this -> parser -> toPsrUri ( $ uris [ 'callback_uri' ] ) ; } return $ this ; }
Set URIs from an array .
48,621
public function validateUris ( array $ uris ) { $ requiredParams = [ 'temporary_credentials_uri' , 'authorization_uri' , 'token_credentials_uri' , ] ; foreach ( $ requiredParams as $ param ) { if ( ! isset ( $ uris [ $ param ] ) ) { throw new InvalidArgumentException ( "Missing URI configuration: {$param}." ) ; } } return true ; }
Validate the given URI array .
48,622
public function setBase ( UriInterface $ uri ) { if ( ! $ this -> parser -> isAbsolute ( $ uri ) ) { throw new InvalidArgumentException ( 'The base URI must be absolute.' ) ; } $ this -> base = $ uri ; return $ this ; }
Set the base URI .
48,623
public static function create ( array $ config , $ signer = null ) { if ( null === $ signer ) { $ signer = new HmacSha1Signer ( ) ; } if ( ! $ signer instanceof SignerInterface ) { throw new InvalidArgumentException ( 'The signer must implement the \Risan\OAuth1\Signature\SignerInterface.' ) ; } $ configFactory = new ConfigFactory ( ) ; $ protocolParameter = new ProtocolParameter ( $ configFactory -> createFromArray ( $ config ) , $ signer , new NonceGenerator ( ) ) ; $ authorizationHeader = new AuthorizationHeader ( $ protocolParameter ) ; $ requestFactory = new RequestFactory ( $ authorizationHeader , new UriParser ( ) ) ; return new OAuth1 ( new HttpClient ( ) , $ requestFactory , new CredentialsFactory ( ) ) ; }
Create the new OAuth1Interface instance .
48,624
public function buildBaseString ( $ uri , array $ parameters = [ ] , $ httpMethod = 'POST' ) { return $ this -> getBaseStringBuilder ( ) -> build ( $ httpMethod , $ uri , $ parameters ) ; }
Build the signature base string .
48,625
public function getBaseStringBuilder ( ) { if ( $ this -> baseStringBuilder instanceof BaseStringBuilderInterface ) { return $ this -> baseStringBuilder ; } return $ this -> baseStringBuilder = new BaseStringBuilder ( new UriParser ( ) ) ; }
Get the BaseStringBuilder instance .
48,626
public function setFrom ( $ from ) { $ recipients = $ this -> normalizeRecipients ( $ from ) ; foreach ( $ recipients as $ email => $ name ) { $ this -> mailer -> adapter -> setFrom ( $ email , $ name ) ; break ; } return $ this ; }
Sets the message sender .
48,627
public function setReplyTo ( $ replyTo ) { $ recipients = $ this -> normalizeRecipients ( $ replyTo ) ; foreach ( $ recipients as $ email => $ name ) { $ this -> mailer -> adapter -> addReplyTo ( $ email , $ name ) ; } return $ this ; }
Sets the reply - to address of this message .
48,628
private function reformatArray ( $ source ) { $ result = array ( ) ; foreach ( $ source as $ data ) { $ result [ $ data [ 0 ] ] = ( isset ( $ data [ 1 ] ) ) ? $ data [ 1 ] : '' ; } return $ result ; }
Reformat PHPMailer s recipients arrays for Yii debug purposes
48,629
public static function processResult ( $ result , $ to = '' , $ cc = '' , $ bcc = '' , $ subject = '' , $ body = '' , $ from = '' ) { self :: $ success = $ result ; if ( YII_DEBUG ) { $ msg = ' - Sending email. ' ; $ msg .= ( ! empty ( $ to ) ) ? ( 'To: ' . ( is_array ( $ to ) ? implode ( ';' , $ to ) : $ to ) . '.' ) : '' ; $ msg .= ( ! empty ( $ cc ) ) ? ( 'Cc: ' . ( is_array ( $ cc ) ? implode ( ';' , $ cc ) : $ cc ) . '.' ) : '' ; $ msg .= ( ! empty ( $ bcc ) ) ? ( 'Bcc: ' . ( is_array ( $ bcc ) ? implode ( ';' , $ bcc ) : $ bcc ) . '.' ) : '' ; $ msg .= ' Subject: "' . $ subject . '"' ; if ( $ result ) { Yii :: info ( 'OK' . $ msg , __METHOD__ ) ; } else { Yii :: warning ( 'FAILED' . $ msg , __METHOD__ ) ; } } }
This is a callback function to retrieve result returned by PHPMailer
48,630
public function msgText ( $ text ) { $ this -> isHTML ( false ) ; $ text = self :: html2text ( $ text , true ) ; $ text = self :: normalizeBreaks ( $ text ) ; $ this -> Body = $ text ; }
Sets message plain text content .
48,631
public function getAuthorizeUrl ( $ api_settings = '' , $ callback_url = 'https://api.vk.com/blank.html' , $ test_mode = false ) { $ parameters = array ( 'client_id' => $ this -> app_id , 'scope' => $ api_settings , 'redirect_uri' => $ callback_url , 'response_type' => 'code' ) ; if ( $ test_mode ) $ parameters [ 'test_mode' ] = 1 ; return $ this -> createUrl ( self :: AUTHORIZE_URL , $ parameters ) ; }
Returns authorization link with passed parameters .
48,632
public function getAccessToken ( $ code , $ callback_url = 'https://api.vk.com/blank.html' ) { if ( ! is_null ( $ this -> access_token ) && $ this -> auth ) { throw new VKException ( 'Already authorized.' ) ; } $ parameters = array ( 'client_id' => $ this -> app_id , 'client_secret' => $ this -> api_secret , 'code' => $ code , 'redirect_uri' => $ callback_url ) ; $ rs = json_decode ( $ this -> request ( $ this -> createUrl ( self :: ACCESS_TOKEN_URL , $ parameters ) ) , true ) ; if ( isset ( $ rs [ 'error' ] ) ) { throw new VKException ( $ rs [ 'error' ] . ( ! isset ( $ rs [ 'error_description' ] ) ? : ': ' . $ rs [ 'error_description' ] ) ) ; } else { $ this -> auth = true ; $ this -> access_token = $ rs [ 'access_token' ] ; return $ rs ; } }
Returns access token by code received on authorization link .
48,633
public function checkAccessToken ( $ access_token = null ) { $ token = is_null ( $ access_token ) ? $ this -> access_token : $ access_token ; if ( is_null ( $ token ) ) return false ; $ rs = $ this -> api ( 'getUserSettings' , array ( 'access_token' => $ token ) ) ; return isset ( $ rs [ 'response' ] ) ; }
Check for validity access token .
48,634
public function api ( $ method , $ parameters = array ( ) , $ format = 'array' , $ requestMethod = 'get' ) { $ parameters [ 'timestamp' ] = time ( ) ; $ parameters [ 'api_id' ] = $ this -> app_id ; $ parameters [ 'random' ] = rand ( 0 , 10000 ) ; if ( ! array_key_exists ( 'access_token' , $ parameters ) && ! is_null ( $ this -> access_token ) ) { $ parameters [ 'access_token' ] = $ this -> access_token ; } if ( ! array_key_exists ( 'v' , $ parameters ) && ! is_null ( $ this -> api_version ) ) { $ parameters [ 'v' ] = $ this -> api_version ; } ksort ( $ parameters ) ; $ sig = '' ; foreach ( $ parameters as $ key => $ value ) { $ sig .= $ key . '=' . $ value ; } $ sig .= $ this -> api_secret ; $ parameters [ 'sig' ] = md5 ( $ sig ) ; if ( $ method == 'execute' || $ requestMethod == 'post' ) { $ rs = $ this -> request ( $ this -> getApiUrl ( $ method , $ format == 'array' ? 'json' : $ format ) , "POST" , $ parameters ) ; } else { $ rs = $ this -> request ( $ this -> createUrl ( $ this -> getApiUrl ( $ method , $ format == 'array' ? 'json' : $ format ) , $ parameters ) ) ; } return $ format == 'array' ? json_decode ( $ rs , true ) : $ rs ; }
Execute API method with parameters and return result .
48,635
private function request ( $ url , $ method = 'GET' , $ postfields = array ( ) ) { curl_setopt_array ( $ this -> ch , array ( CURLOPT_USERAGENT => 'VK/1.0 (+https://github.com/vladkens/VK))' , CURLOPT_RETURNTRANSFER => true , CURLOPT_SSL_VERIFYPEER => false , CURLOPT_POST => ( $ method == 'POST' ) , CURLOPT_POSTFIELDS => $ postfields , CURLOPT_URL => $ url ) ) ; return curl_exec ( $ this -> ch ) ; }
Executes request on link .
48,636
public function beforeValidate ( ) { if ( $ this -> owner -> { $ this -> attribute } instanceof UploadedFile ) { $ this -> file = $ this -> owner -> { $ this -> attribute } ; return ; } $ this -> file = UploadedFile :: getInstance ( $ this -> owner , $ this -> attribute ) ; if ( empty ( $ this -> file ) ) { $ this -> file = UploadedFile :: getInstanceByName ( $ this -> attribute ) ; } if ( $ this -> file instanceof UploadedFile ) { $ this -> owner -> { $ this -> attribute } = $ this -> file ; } }
Before validate event .
48,637
public function beforeSave ( ) { if ( $ this -> file instanceof UploadedFile ) { if ( true !== $ this -> owner -> isNewRecord ) { $ oldModel = $ this -> owner -> findOne ( $ this -> owner -> primaryKey ) ; $ behavior = static :: getInstance ( $ oldModel , $ this -> attribute ) ; $ behavior -> cleanFiles ( ) ; } $ this -> owner -> { $ this -> attribute } = implode ( '.' , array_filter ( [ $ this -> file -> baseName , $ this -> file -> extension ] ) ) ; } else { if ( true !== $ this -> owner -> isNewRecord && empty ( $ this -> owner -> { $ this -> attribute } ) ) { $ this -> owner -> { $ this -> attribute } = ArrayHelper :: getValue ( $ this -> owner -> oldAttributes , $ this -> attribute , null ) ; } } }
Before save event .
48,638
public static function getInstance ( Model $ model , $ attribute ) { foreach ( $ model -> behaviors as $ behavior ) { if ( $ behavior instanceof self && $ behavior -> attribute == $ attribute ) { return $ behavior ; } } throw new InvalidCallException ( 'Missing behavior for attribute ' . VarDumper :: dumpAsString ( $ attribute ) ) ; }
Returns behavior instance for specified object and attribute
48,639
public function resolvePath ( $ path ) { $ path = Yii :: getAlias ( $ path ) ; $ pi = pathinfo ( $ this -> owner -> { $ this -> attribute } ) ; $ fileName = ArrayHelper :: getValue ( $ pi , 'filename' ) ; $ extension = strtolower ( ArrayHelper :: getValue ( $ pi , 'extension' ) ) ; return preg_replace_callback ( '|\[\[([\w\_/]+)\]\]|' , function ( $ matches ) use ( $ fileName , $ extension ) { $ name = $ matches [ 1 ] ; switch ( $ name ) { case 'extension' : return $ extension ; case 'filename' : return $ fileName ; case 'basename' : return implode ( '.' , array_filter ( [ $ fileName , $ extension ] ) ) ; case 'app_root' : return Yii :: getAlias ( '@app' ) ; case 'web_root' : return Yii :: getAlias ( '@webroot' ) ; case 'base_url' : return Yii :: getAlias ( '@web' ) ; case 'model' : $ r = new \ ReflectionClass ( $ this -> owner -> className ( ) ) ; return lcfirst ( $ r -> getShortName ( ) ) ; case 'attribute' : return lcfirst ( $ this -> attribute ) ; case 'id' : case 'pk' : $ pk = implode ( '_' , $ this -> owner -> getPrimaryKey ( true ) ) ; return lcfirst ( $ pk ) ; case 'id_path' : return static :: makeIdPath ( $ this -> owner -> getPrimaryKey ( ) ) ; case 'parent_id' : return $ this -> owner -> { $ this -> parentRelationAttribute } ; } if ( preg_match ( '|^attribute_(\w+)$|' , $ name , $ am ) ) { $ attribute = $ am [ 1 ] ; return $ this -> owner -> { $ attribute } ; } if ( preg_match ( '|^md5_attribute_(\w+)$|' , $ name , $ am ) ) { $ attribute = $ am [ 1 ] ; return md5 ( $ this -> owner -> { $ attribute } ) ; } return '[[' . $ name . ']]' ; } , $ path ) ; }
Replaces all placeholders in path variable with corresponding values
48,640
public function afterSave ( ) { if ( $ this -> file instanceof UploadedFile !== true ) { return ; } $ path = $ this -> getUploadedFilePath ( $ this -> attribute ) ; FileHelper :: createDirectory ( pathinfo ( $ path , PATHINFO_DIRNAME ) , 0775 , true ) ; if ( ! $ this -> file -> saveAs ( $ path ) ) { throw new FileUploadException ( $ this -> file -> error , 'File saving error.' ) ; } $ this -> owner -> trigger ( static :: EVENT_AFTER_FILE_SAVE ) ; }
After save event .
48,641
public function getUploadedFilePath ( $ attribute ) { $ behavior = static :: getInstance ( $ this -> owner , $ attribute ) ; if ( ! $ this -> owner -> { $ attribute } ) { return '' ; } return $ behavior -> resolvePath ( $ behavior -> filePath ) ; }
Returns file path for attribute .
48,642
public function getUploadedFileUrl ( $ attribute ) { if ( ! $ this -> owner -> { $ attribute } ) { return null ; } $ behavior = static :: getInstance ( $ this -> owner , $ attribute ) ; return $ behavior -> resolvePath ( $ behavior -> fileUrl ) ; }
Returns file url for the attribute .
48,643
public function resolveProfilePath ( $ path , $ profile ) { $ path = $ this -> resolvePath ( $ path ) ; return preg_replace_callback ( '|\[\[([\w\_/]+)\]\]|' , function ( $ matches ) use ( $ profile ) { $ name = $ matches [ 1 ] ; switch ( $ name ) { case 'profile' : return $ profile ; } return '[[' . $ name . ']]' ; } , $ path ) ; }
Resolves profile path for thumbnail profile .
48,644
public function createThumbs ( ) { $ path = $ this -> getUploadedFilePath ( $ this -> attribute ) ; foreach ( $ this -> thumbs as $ profile => $ config ) { $ thumbPath = static :: getThumbFilePath ( $ this -> attribute , $ profile ) ; if ( is_file ( $ path ) && ! is_file ( $ thumbPath ) ) { if ( isset ( $ config [ 'processor' ] ) && is_callable ( $ config [ 'processor' ] ) ) { $ processor = $ config [ 'processor' ] ; unset ( $ config [ 'processor' ] ) ; } else { $ processor = function ( GD $ thumb ) use ( $ config ) { $ thumb -> adaptiveResize ( $ config [ 'width' ] , $ config [ 'height' ] ) ; } ; } $ thumb = new GD ( $ path , $ config ) ; call_user_func ( $ processor , $ thumb , $ this -> attribute ) ; FileHelper :: createDirectory ( pathinfo ( $ thumbPath , PATHINFO_DIRNAME ) , 0775 , true ) ; $ thumb -> save ( $ thumbPath ) ; } } }
Creates image thumbnails
48,645
private function replace ( array $ data ) : string { $ widget = explode ( ':' , $ data [ 1 ] ) ; if ( class_exists ( $ class = $ widget [ 0 ] ) && method_exists ( $ class , $ method = $ widget [ 1 ] ) ) { return call_user_func ( [ $ class , $ method ] ) ; } return '' ; }
Replaces widget short code on appropriate widget
48,646
public function actionIndex ( ) { $ searchModel = Yii :: createObject ( $ this -> searchClass ) ; $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> queryParams ) ; return $ this -> render ( $ this -> indexView , [ 'dataProvider' => $ dataProvider , 'searchModel' => $ searchModel , ] ) ; }
List of all cms models .
48,647
public function actionCreate ( ) { $ model = Yii :: createObject ( $ this -> modelClass ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'yii2mod.cms' , 'Page has been created.' ) ) ; return $ this -> redirect ( [ 'index' ] ) ; } return $ this -> render ( $ this -> createView , [ 'model' => $ model , ] ) ; }
Creates a new CmsModel .
48,648
public function actionUploadImage ( ) : Response { $ model = Yii :: createObject ( $ this -> attachmentModelClass ) ; $ model -> file = UploadedFile :: getInstanceByName ( 'file' ) ; if ( ! $ model -> save ( ) ) { throw new UnprocessableEntityHttpException ( $ model -> getFirstError ( 'file' ) ) ; } return $ this -> asJson ( [ 'link' => $ model -> getFileUrl ( 'origin' ) , ] ) ; }
Upload an image
48,649
public function actionDeleteImage ( ) : Response { $ model = $ this -> findModel ( $ this -> attachmentModelClass , Yii :: $ app -> request -> post ( 'id' ) ) ; $ model -> delete ( ) ; return $ this -> asJson ( [ 'status' => 'success' , ] ) ; }
Delete the image
48,650
public function actionImages ( ) : Response { $ result = [ ] ; foreach ( AttachmentModel :: find ( ) -> each ( ) as $ attachment ) { $ result [ ] = [ 'id' => $ attachment -> id , 'url' => $ attachment -> getFileUrl ( 'origin' ) , 'thumb' => $ attachment -> getFileUrl ( 'thumbnail' ) , ] ; } return $ this -> asJson ( $ result ) ; }
Return list of all images
48,651
protected function getBaseTemplateParams ( ) { return ArrayHelper :: merge ( $ this -> baseTemplateParams , [ 'homeUrl' => Yii :: $ app -> urlManager -> baseUrl , 'siteName' => Yii :: $ app -> name , ] ) ; }
Return base template params
48,652
protected function initAutoComplete ( & $ options = [ ] ) { $ autocomplete = ArrayHelper :: getValue ( $ options , 'autocomplete' , [ ] ) ; if ( ! is_array ( $ autocomplete ) || empty ( $ autocomplete ) ) { return ; } ArrayHelper :: remove ( $ options , 'autocomplete' ) ; $ view = $ this -> form -> getView ( ) ; Html :: addCssClass ( $ options , [ 'autocomplete' => 'has-autocomplete' ] ) ; MaterializePluginAsset :: register ( $ view ) ; $ autocompleteData [ 'data' ] = $ autocomplete ; $ pluginOptions = Json :: htmlEncode ( $ autocompleteData ) ; $ js = "M.Autocomplete.init(document.querySelectorAll('.has-autocomplete', $pluginOptions))" ; $ view -> registerJs ( $ js ) ; }
Initializes the Materialize autocomplete feature .
48,653
protected function initCharacterCounter ( & $ options = [ ] ) { $ showCharacterCounter = ArrayHelper :: getValue ( $ options , 'showCharacterCounter' , false ) ; if ( $ showCharacterCounter ) { Html :: addCssClass ( $ this -> inputOptions , [ 'character-counter' => 'has-character-counter' ] ) ; $ js = "M.CharacterCounter.init(document.querySelectorAll('.has-character-counter'))" ; $ view = $ this -> form -> getView ( ) ; $ view -> registerJs ( $ js ) ; } }
Initializes the Materialize character counter feature .
48,654
public function checkboxList ( $ items , $ options = [ ] ) { $ this -> template = "{icon}\n{label}\n{input}\n{hint}\n{error}" ; if ( $ this -> form -> validationStateOn === ActiveForm :: VALIDATION_STATE_ON_INPUT ) { $ this -> addErrorClassIfNeeded ( $ options ) ; } Html :: addCssClass ( $ this -> labelOptions , [ 'checkboxlist-label' => 'label-checkbox-list' ] ) ; $ this -> addAriaAttributes ( $ options ) ; $ this -> parts [ '{input}' ] = Html :: activeCheckboxList ( $ this -> model , $ this -> attribute , $ items , $ options ) ; return $ this ; }
Renders a list of checkboxes . A checkbox list allows multiple selections . As a result the corresponding submitted value is an array . The selection of the checkbox list is taken from the value of the model attribute .
48,655
public function dropDownList ( $ items , $ options = [ ] ) { $ view = $ this -> form -> view ; MaterializePluginAsset :: register ( $ view ) ; $ id = $ this -> getInputId ( ) ; $ js = "M.FormSelect.init(document.querySelector('#$id'))" ; $ view -> registerJs ( $ js ) ; return parent :: dropDownList ( $ items , $ options ) ; }
Renders a drop - down list .
48,656
protected function registerPlugin ( $ name , $ selector = null ) { $ view = $ this -> getView ( ) ; MaterializePluginAsset :: register ( $ view ) ; $ id = $ this -> options [ 'id' ] ; if ( is_null ( $ selector ) ) { $ selector = '#' . $ id ; } if ( $ this -> clientOptions !== false ) { $ options = empty ( $ this -> clientOptions ) ? '{}' : Json :: htmlEncode ( $ this -> clientOptions ) ; $ js = "document.addEventListener('DOMContentLoaded', function() {M.$name.init(document.querySelectorAll('$selector'), $options);});" ; $ view -> registerJs ( $ js , View :: POS_END ) ; } $ this -> registerClientEvents ( ) ; }
Registers a specific Materialize plugin and the related events .
48,657
protected function renderSwitch ( ) { $ value = ArrayHelper :: getValue ( $ this -> inputOptions , 'value' , null ) ; if ( $ this -> hasModel ( ) ) { $ attributeValue = Html :: getAttributeValue ( $ this -> model , $ this -> attribute ) ; $ this -> checked = "{$value}" === "{$attributeValue}" ; } $ name = ArrayHelper :: remove ( $ this -> inputOptions , 'name' , null ) ; return implode ( "\n" , [ Html :: beginTag ( 'label' ) , $ this -> renderLabel ( 'off' ) , Html :: checkbox ( $ name , $ this -> checked , $ this -> inputOptions ) , Html :: tag ( 'span' , '' , [ 'class' => 'lever' ] ) , $ this -> renderLabel ( 'on' ) , Html :: endTag ( 'label' ) , ] ) ; }
Render the switch button checkbox .
48,658
protected function renderCollapsible ( $ link , $ items = [ ] , $ isParentActive = false ) { $ itemOptions = [ ] ; if ( $ isParentActive ) { Html :: addCssClass ( $ itemOptions , [ 'item-activation' => 'active' ] ) ; } $ collapsibleItems = [ [ 'header' => [ 'content' => $ link ] , 'body' => [ 'content' => $ this -> buildCollapsibleBody ( $ items ) ] , 'options' => $ itemOptions ] , ] ; return Collapsible :: widget ( [ 'items' => $ collapsibleItems , 'type' => Collapsible :: TYPE_ACCORDION , ] ) ; }
Renders a submenu as Collapsible in side navigation element .
48,659
public function run ( ) { if ( empty ( $ this -> links ) ) { return '' ; } $ html [ ] = Html :: beginTag ( 'nav' , $ this -> containerOptions ) ; $ html [ ] = Html :: beginTag ( $ this -> tag , $ this -> options ) ; if ( $ this -> innerContainerOptions !== false ) { $ innerContainerTag = ArrayHelper :: remove ( $ this -> innerContainerOptions , 'tag' , 'div' ) ; $ html [ ] = Html :: beginTag ( $ innerContainerTag , $ this -> innerContainerOptions ) ; } $ html [ ] = implode ( '' , $ this -> prepareLinks ( ) ) ; if ( $ this -> innerContainerOptions !== false ) { $ html [ ] = Html :: endTag ( $ innerContainerTag ) ; } $ html [ ] = Html :: endTag ( $ this -> tag ) ; $ html [ ] = Html :: endTag ( 'nav' ) ; return implode ( "\n" , $ html ) ; }
Render the widget .
48,660
protected function renderItem ( $ link , $ template ) { $ encodeLabel = ArrayHelper :: remove ( $ link , 'encode' , $ this -> encodeLabels ) ; if ( array_key_exists ( 'label' , $ link ) ) { $ label = $ encodeLabel ? Html :: encode ( $ link [ 'label' ] ) : $ link [ 'label' ] ; } else { throw new InvalidConfigException ( 'The "label" element is required for each link.' ) ; } if ( isset ( $ link [ 'template' ] ) ) { $ template = $ link [ 'template' ] ; } if ( isset ( $ link [ 'url' ] ) ) { $ options = $ link ; Html :: addCssClass ( $ options , [ 'link' => 'breadcrumb' ] ) ; unset ( $ options [ 'template' ] , $ options [ 'label' ] , $ options [ 'url' ] ) ; $ link = Html :: a ( $ label , $ link [ 'url' ] , $ options ) ; } else { $ link = $ label ; } return strtr ( $ template , [ '{link}' => $ link ] ) ; }
Renders a single breadcrumb item .
48,661
protected function prepareLinks ( ) { $ links = [ ] ; if ( $ this -> homeLink === null ) { $ links [ ] = $ this -> renderItem ( [ 'label' => Yii :: t ( 'yii' , 'Home' ) , 'url' => Yii :: $ app -> homeUrl , ] , $ this -> itemTemplate ) ; } elseif ( $ this -> homeLink !== false ) { $ links [ ] = $ this -> renderItem ( $ this -> homeLink , $ this -> itemTemplate ) ; } foreach ( $ this -> links as $ link ) { if ( ! is_array ( $ link ) ) { $ link = [ 'label' => $ link ] ; } $ links [ ] = $ this -> renderItem ( $ link , isset ( $ link [ 'url' ] ) ? $ this -> itemTemplate : $ this -> activeItemTemplate ) ; } return $ links ; }
Generates all breadcrumb links and sets active states .
48,662
protected function renderSlide ( $ slideConfig = [ ] ) { $ imageOptions = ArrayHelper :: getValue ( $ slideConfig , 'image' , [ ] ) ; $ imageSrc = ArrayHelper :: remove ( $ imageOptions , 'src' , null ) ; if ( ! $ imageSrc ) { return '' ; } $ caption = $ this -> renderCaption ( ArrayHelper :: getValue ( $ slideConfig , 'caption' , false ) ) ; $ options = ArrayHelper :: getValue ( $ slideConfig , 'options' , [ ] ) ; $ options = ArrayHelper :: merge ( $ this -> slideOptions , $ options ) ; $ html [ ] = Html :: beginTag ( 'li' , $ options ) ; $ html [ ] = Html :: img ( $ imageSrc , $ imageOptions ) ; $ html [ ] = $ caption ; $ html [ ] = Html :: endTag ( 'li' ) ; return implode ( "\n" , $ html ) ; }
Renders a single slide .
48,663
protected function renderCaption ( $ captionConfig ) { if ( $ captionConfig === false ) { return '' ; } $ content = ArrayHelper :: getValue ( $ captionConfig , 'content' , '' ) ; $ alignment = ArrayHelper :: getValue ( $ captionConfig , 'align' , null ) ; $ options = ArrayHelper :: getValue ( $ captionConfig , 'options' , [ ] ) ; $ options = ArrayHelper :: merge ( $ this -> captionOptions , $ options ) ; Html :: addCssClass ( $ options , [ 'caption' => 'caption' ] ) ; if ( $ alignment ) { Html :: addCssClass ( $ options , [ 'align' => $ alignment ] ) ; } return Html :: tag ( 'div' , $ content , $ options ) ; }
Renders the caption markup .
48,664
protected function registerClientScripts ( ) { $ view = $ this -> getView ( ) ; NoUiSliderAsset :: register ( $ view ) ; $ id = $ this -> sliderOptions [ 'id' ] ; $ varName = $ this -> getUniqueId ( 'slider_' ) ; if ( $ this -> clientOptions !== false ) { $ options = empty ( $ this -> clientOptions ) ? '{}' : Json :: htmlEncode ( $ this -> clientOptions ) ; $ view -> registerJs ( <<<JSvar $varName = document.getElementById('$id');noUiSlider.create($varName, {$options});JS ) ; } $ this -> registerClientEvents ( $ varName ) ; }
Registers all scripts needed by the underlying JS plugin .
48,665
protected function registerClientEvents ( $ sliderVarName = null ) { if ( ! empty ( $ this -> clientEvents ) ) { $ js = [ ] ; foreach ( $ this -> clientEvents as $ event => $ handler ) { $ js [ ] = "$sliderVarName.noUiSlider.on('$event', $handler);" ; } $ this -> getView ( ) -> registerJs ( implode ( "\n" , $ js ) ) ; } }
Registers the events of the slider .
48,666
protected function parseItems ( ) { $ items = $ this -> items ; $ this -> items = [ ] ; foreach ( $ items as $ optionValue => $ item ) { $ this -> parseItem ( $ optionValue , $ item ) ; } }
Parses all items .
48,667
protected function renderItem ( $ item = [ ] ) { $ tag = ArrayHelper :: getValue ( $ item , 'tag' , 'div' ) ; $ content = ArrayHelper :: getValue ( $ item , 'content' , '' ) ; $ options = ArrayHelper :: getValue ( $ item , 'options' , [ ] ) ; $ options = ArrayHelper :: merge ( $ this -> itemOptions , $ options ) ; Html :: addCssClass ( $ options , [ 'item' => 'carousel-item' ] ) ; return Html :: tag ( $ tag , $ content , $ options ) ; }
Renders a single carousel item .
48,668
protected function renderFixedItem ( ) { if ( $ this -> fixedItemOptions === false ) { return '' ; } $ tag = ArrayHelper :: remove ( $ this -> fixedItemOptions , 'tag' , 'div' ) ; $ content = ArrayHelper :: remove ( $ this -> fixedItemOptions , 'content' , '' ) ; Html :: addCssClass ( $ this -> fixedItemOptions , [ 'fixed-item' => 'carousel-fixed-item' ] ) ; return Html :: tag ( $ tag , $ content , $ this -> fixedItemOptions ) ; }
Renders the optional fixed item .
48,669
public function run ( ) { if ( $ this -> toggleButtonOptions !== false ) { $ html [ ] = $ this -> renderToggleButton ( ) ; } $ html [ ] = $ this -> renderItems ( $ this -> items , $ this -> options ) ; return implode ( "\n" , $ html ) ; }
Renders the widget and registers the plugin asset .
48,670
protected function renderToggleButton ( ) { if ( ! isset ( $ this -> toggleButtonOptions [ 'options' ] [ 'data-target' ] ) ) { $ this -> toggleButtonOptions [ 'options' ] [ 'data-target' ] = $ this -> options [ 'id' ] ; } Html :: addCssClass ( $ this -> toggleButtonOptions [ 'options' ] , [ 'toggle-button' => 'dropdown-trigger' ] ) ; return Button :: widget ( $ this -> toggleButtonOptions ) ; }
Renders the dropdown toggle button .
48,671
protected function renderFooter ( ) { if ( ! $ this -> footer && $ this -> closeButtonPosition != self :: CLOSE_BUTTON_POSITION_BEFORE_FOOTER && $ this -> closeButtonPosition != self :: CLOSE_BUTTON_POSITION_AFTER_FOOTER ) { return '' ; } $ html = [ ] ; Html :: addCssClass ( $ this -> footerOptions , [ 'footer' => 'modal-footer' ] ) ; $ html [ ] = Html :: beginTag ( 'div' , $ this -> footerOptions ) ; if ( $ this -> closeButtonPosition === self :: CLOSE_BUTTON_POSITION_BEFORE_FOOTER ) { $ html [ ] = $ this -> renderCloseButton ( ) ; } $ html [ ] = $ this -> footer ; if ( $ this -> closeButtonPosition === self :: CLOSE_BUTTON_POSITION_AFTER_FOOTER ) { $ html [ ] = $ this -> renderCloseButton ( ) ; } $ html [ ] = Html :: endTag ( 'div' ) ; return implode ( "\n" , $ html ) ; }
Renders the Modal footer .
48,672
protected function initDefaults ( ) { switch ( $ this -> modalType ) { case self :: TYPE_FIXED_FOOTER : Html :: addCssClass ( $ this -> options , [ 'modalType' => 'modal-fixed-footer' ] ) ; break ; case self :: TYPE_BOTTOM_SHEET : Html :: addCssClass ( $ this -> options , [ 'modalType' => 'bottom-sheet' ] ) ; break ; default : break ; } Html :: addCssClass ( $ this -> options , [ 'widget' => 'modal' ] ) ; if ( $ this -> closeButton !== false ) { $ this -> closeButton = ArrayHelper :: merge ( [ 'class' => 'modal-close' , ] , $ this -> closeButton ) ; } if ( $ this -> toggleButton !== false ) { $ this -> toggleButton = ArrayHelper :: merge ( [ 'class' => 'modal-trigger btn' , ] , $ this -> toggleButton ) ; } $ this -> clientOptions [ 'opacity' ] = $ this -> overlayOpacity ; $ this -> clientOptions [ 'inDuration' ] = $ this -> inDuration ; $ this -> clientOptions [ 'outDuration' ] = $ this -> outDuration ; $ this -> clientOptions [ 'preventScrolling' ] = $ this -> preventScrolling ; $ this -> clientOptions [ 'dismissible' ] = $ this -> dismissible ; $ this -> clientOptions [ 'startingTop' ] = $ this -> startingTopOffset ; $ this -> clientOptions [ 'endingTop' ] = $ this -> endingTopOffset ; }
Set inital default options .
48,673
private function renderHtml ( $ message , $ options = [ ] ) { $ html = Html :: beginTag ( 'div' , $ options ) ; $ html .= '<div class="card-panel">' ; $ html .= $ message ; $ html .= '</div>' ; $ html .= Html :: endTag ( 'div' ) ; return $ html ; }
Renders a single flash message .
48,674
protected function renderItem ( $ item = [ ] ) { $ itemOptions = ArrayHelper :: getValue ( $ item , 'options' , [ ] ) ; $ headerOptions = ArrayHelper :: getValue ( $ item , 'header' , [ ] ) ; $ headerContent = ArrayHelper :: remove ( $ headerOptions , 'content' ) ; $ headerTag = ArrayHelper :: remove ( $ headerOptions , 'tag' , 'div' ) ; $ bodyOptions = ArrayHelper :: getValue ( $ item , 'body' , [ ] ) ; $ bodyContent = ArrayHelper :: remove ( $ bodyOptions , 'content' , [ ] ) ; $ bodyTag = ArrayHelper :: remove ( $ bodyOptions , 'tag' , 'div' ) ; if ( ! $ headerContent && ! $ bodyContent ) { return '' ; } $ html [ ] = Html :: beginTag ( 'li' , $ itemOptions ) ; if ( $ headerContent ) { Html :: addCssClass ( $ headerOptions , [ 'header' => 'collapsible-header' ] ) ; $ html [ ] = Html :: tag ( $ headerTag , $ headerContent , $ headerOptions ) ; } if ( $ bodyContent ) { Html :: addCssClass ( $ bodyOptions , [ 'body' => 'collapsible-body' ] ) ; $ html [ ] = Html :: tag ( $ bodyTag , $ bodyContent , $ bodyOptions ) ; } $ html [ ] = Html :: endTag ( 'li' ) ; return implode ( "\n" , $ html ) ; }
Render a single item .
48,675
protected function renderItems ( ) { $ elements = [ ] ; $ items = $ this -> items ; foreach ( $ items as $ item ) { if ( isset ( $ item [ 'visible' ] ) && ! $ item [ 'visible' ] ) { continue ; } if ( is_string ( $ item ) ) { $ elements [ ] = $ item ; continue ; } if ( ! array_key_exists ( 'label' , $ item ) ) { throw new InvalidConfigException ( "The 'label' option is required." ) ; } $ encodeLabel = isset ( $ item [ 'encodeLabel' ] ) ? $ item [ 'encodeLabel' ] : $ this -> encodeLabels ; $ label = $ encodeLabel ? Html :: encode ( $ item [ 'label' ] ) : $ item [ 'label' ] ; $ itemOptions = ArrayHelper :: getValue ( $ item , 'options' , [ ] ) ; $ linkOptions = ArrayHelper :: getValue ( $ item , 'linkOptions' , [ ] ) ; Html :: addCssClass ( $ linkOptions , [ 'link' => 'btn-floating' ] ) ; $ url = array_key_exists ( 'url' , $ item ) ? $ item [ 'url' ] : '#' ; $ content = Html :: a ( $ label , $ url , $ linkOptions ) ; $ elements [ ] = Html :: tag ( 'li' , $ content , $ itemOptions ) ; } return Html :: tag ( 'ul' , implode ( "\n" , $ elements ) , $ this -> itemsContainerOptions ) ; }
Renders a list representing the single button items .
48,676
protected function initSidenav ( $ sidenavId ) { $ this -> sidenavToggleButtonOptions = ArrayHelper :: merge ( [ 'label' => false , 'icon' => [ 'name' => 'menu' ] , 'type' => Button :: TYPE_FLAT , ] , $ this -> sidenavToggleButtonOptions ) ; if ( ! isset ( $ this -> sidenavToggleButtonOptions [ 'options' ] [ 'data-target' ] ) ) { $ this -> sidenavToggleButtonOptions [ 'options' ] [ 'data-target' ] = $ sidenavId ; } Html :: addCssClass ( $ this -> sidenavToggleButtonOptions [ 'options' ] , [ 'trigger' => 'sidenav-trigger' ] ) ; }
Initializes the side nav options .
48,677
protected function renderSidenav ( $ sidenavId ) { return SideNav :: widget ( [ 'items' => $ this -> sidenavItems , 'renderToggleButton' => false , 'clientOptions' => $ this -> sidenavClientOptions , 'options' => [ 'id' => $ sidenavId ] , ] ) ; }
Renders the side navigation and corresponding toggle button .
48,678
public static function resolveAliases ( array $ parameters , array $ aliases ) { if ( ! isset ( $ parameters [ 'alias' ] ) ) { return $ parameters ; } $ browser_alias = $ parameters [ 'alias' ] ; unset ( $ parameters [ 'alias' ] ) ; if ( isset ( $ aliases [ $ browser_alias ] ) ) { $ candidate_params = self :: arrayMergeRecursive ( $ aliases [ $ browser_alias ] , $ parameters ) ; return self :: resolveAliases ( $ candidate_params , $ aliases ) ; } throw new \ InvalidArgumentException ( sprintf ( 'Unable to resolve "%s" browser alias' , $ browser_alias ) ) ; }
Resolves browser alias into corresponding browser configuration .
48,679
public function setup ( array $ parameters ) { $ parameters = $ this -> prepareParameters ( $ parameters ) ; if ( isset ( $ parameters [ 'driver' ] ) ) { $ this -> setDriver ( $ parameters [ 'driver' ] ) ; unset ( $ parameters [ 'driver' ] ) ; } foreach ( $ parameters as $ name => $ value ) { $ method = 'set' . ucfirst ( $ name ) ; if ( ! method_exists ( $ this , $ method ) ) { throw new \ InvalidArgumentException ( 'Unable to set unknown parameter "' . $ name . '"' ) ; } $ this -> $ method ( $ value ) ; } return $ this ; }
Initializes a browser with given configuration .
48,680
protected function prepareParameters ( array $ parameters ) { return array_merge ( $ this -> _parameters , self :: resolveAliases ( $ parameters , $ this -> aliases ) ) ; }
Merges together default given parameter and resolves aliases along the way .
48,681
public function setDriver ( $ driver_name ) { if ( ! is_string ( $ driver_name ) ) { throw new \ InvalidArgumentException ( 'The Mink driver name must be a string' ) ; } $ this -> _driverFactory = $ this -> _driverFactoryRegistry -> get ( $ driver_name ) ; $ this -> _mergedDefaults = self :: arrayMergeRecursive ( $ this -> defaults , $ this -> _driverFactory -> getDriverDefaults ( ) ) ; return $ this -> setParameter ( 'driver' , $ driver_name ) ; }
Sets Mink driver to browser configuration .
48,682
protected function setParameter ( $ name , $ value ) { if ( ! isset ( $ this -> _driverFactory ) ) { throw new \ LogicException ( 'Please set "driver" parameter first.' ) ; } $ this -> _parameters [ $ name ] = $ value ; return $ this ; }
Sets parameter .
48,683
protected function getParameter ( $ name ) { $ merged = self :: arrayMergeRecursive ( $ this -> _mergedDefaults , $ this -> _parameters ) ; if ( array_key_exists ( $ name , $ merged ) ) { return $ merged [ $ name ] ; } throw new \ InvalidArgumentException ( 'Unable to get unknown parameter "' . $ name . '"' ) ; }
Returns parameter value .
48,684
public function createDriver ( ) { $ factory = $ this -> _driverFactoryRegistry -> get ( $ this -> getDriver ( ) ) ; return $ factory -> createDriver ( $ this ) ; }
Creates driver based on browser configuration .
48,685
public function getSessionStrategyHash ( ) { $ ret = $ this -> getChecksum ( ) ; if ( $ this -> isShared ( ) ) { $ ret .= '::' . get_class ( $ this -> getTestCase ( ) ) ; } return $ ret ; }
Returns session strategy hash based on given test case and current browser configuration .
48,686
protected static function arrayMergeRecursive ( $ array1 , $ array2 ) { if ( ! is_array ( $ array1 ) || ! is_array ( $ array2 ) ) { return $ array2 ; } foreach ( $ array2 as $ array2_key => $ array2_value ) { if ( isset ( $ array1 [ $ array2_key ] ) ) { $ array1 [ $ array2_key ] = self :: arrayMergeRecursive ( $ array1 [ $ array2_key ] , $ array2_value ) ; } else { $ array1 [ $ array2_key ] = $ array2_value ; } } return $ array1 ; }
Similar to array_merge_recursive but keyed - valued are always overwritten .
48,687
public function createStrategy ( $ strategy_type ) { if ( $ strategy_type == ISessionStrategyFactory :: TYPE_ISOLATED ) { return $ this -> application -> getObject ( 'isolated_session_strategy' ) ; } elseif ( $ strategy_type == ISessionStrategyFactory :: TYPE_SHARED ) { return $ this -> application -> getObject ( 'shared_session_strategy' ) ; } throw new \ InvalidArgumentException ( 'Incorrect session strategy type' ) ; }
Creates specified session strategy .
48,688
public function getDesiredCapabilities ( ) { $ capabilities = parent :: getDesiredCapabilities ( ) ; if ( ! isset ( $ capabilities [ 'platform' ] ) ) { $ capabilities [ 'platform' ] = 'Windows 7' ; } if ( ! isset ( $ capabilities [ 'version' ] ) ) { $ capabilities [ 'version' ] = '' ; } return $ capabilities ; }
Returns desired capabilities from browser configuration .
48,689
public function get ( $ coverage_script_url , $ test_id ) { $ url = $ this -> createUrl ( $ coverage_script_url , $ test_id ) ; $ buffer = $ this -> _remoteUrl -> getPageContent ( $ url ) ; if ( $ buffer !== false ) { $ coverage_data = unserialize ( $ buffer ) ; if ( is_array ( $ coverage_data ) ) { return $ this -> matchLocalAndRemotePaths ( $ coverage_data ) ; } throw new \ RuntimeException ( 'Empty or invalid code coverage data received from url "' . $ url . '"' ) ; } return array ( ) ; }
Retrieves remote coverage information .
48,690
protected function createUrl ( $ coverage_script_url , $ test_id ) { if ( ! $ coverage_script_url || ! $ test_id ) { throw new \ InvalidArgumentException ( 'Both Coverage script URL and Test ID must be filled in' ) ; } $ query_string = array ( 'rct_mode' => 'output' , RemoteCoverageTool :: TEST_ID_VARIABLE => $ test_id , ) ; $ url = $ coverage_script_url ; $ url .= strpos ( $ url , '?' ) === false ? '?' : '&' ; $ url .= http_build_query ( $ query_string ) ; return $ url ; }
Returns url for remote code coverage collection .
48,691
protected function matchLocalAndRemotePaths ( array $ coverage ) { $ coverage_with_local_paths = array ( ) ; foreach ( $ coverage as $ original_remote_path => $ data ) { $ remote_path = $ original_remote_path ; $ separator = $ this -> findDirectorySeparator ( $ remote_path ) ; while ( ! ( $ local_path = stream_resolve_include_path ( $ remote_path ) ) && strpos ( $ remote_path , $ separator ) !== false ) { $ remote_path = substr ( $ remote_path , strpos ( $ remote_path , $ separator ) + 1 ) ; } if ( $ local_path && md5_file ( $ local_path ) == $ data [ 'md5' ] ) { $ coverage_with_local_paths [ $ local_path ] = $ data [ 'coverage' ] ; } } return $ coverage_with_local_paths ; }
Returns only files from remote server that are matching files on test machine .
48,692
public function getDefaultSessionStrategy ( ) { if ( ! $ this -> defaultSessionStrategy ) { $ this -> defaultSessionStrategy = $ this -> _sessionStrategyFactory -> createStrategy ( ISessionStrategyFactory :: TYPE_ISOLATED ) ; } return $ this -> defaultSessionStrategy ; }
Creates default session strategy .
48,693
public function getSessionStrategy ( BrowserConfiguration $ browser ) { $ strategy_type = $ browser -> getSessionStrategy ( ) ; $ strategy_hash = $ browser -> getSessionStrategyHash ( ) ; if ( $ strategy_hash !== $ this -> lastUsedSessionStrategyHash ) { $ this -> sessionStrategiesInUse [ $ strategy_hash ] = $ this -> _sessionStrategyFactory -> createStrategy ( $ strategy_type ) ; } $ this -> lastUsedSessionStrategyHash = $ strategy_hash ; return $ this -> sessionStrategiesInUse [ $ strategy_hash ] ; }
Initializes session strategy using given browser test case .
48,694
public static function init ( $ data_directory = null ) { $ coverage_tool = new self ( $ data_directory ) ; $ mode = isset ( $ _GET [ 'rct_mode' ] ) ? $ _GET [ 'rct_mode' ] : '' ; if ( $ mode == 'output' ) { echo $ coverage_tool -> aggregateCoverageInformation ( ) ; } else { $ coverage_tool -> startCollection ( ) ; register_shutdown_function ( array ( $ coverage_tool , 'stopCollection' ) ) ; } }
Collects & reports coverage information .
48,695
protected function assertDirectory ( $ directory ) { if ( ! is_string ( $ directory ) || ! is_dir ( $ directory ) || ! file_exists ( $ directory ) ) { throw new \ InvalidArgumentException ( 'Directory "' . $ directory . '" is invalid' ) ; } return $ directory ; }
Checks that a directory is valid .
48,696
public function stopCollection ( ) { if ( ! $ this -> enabled ( ) ) { return ; } $ data = xdebug_get_code_coverage ( ) ; xdebug_stop_code_coverage ( ) ; foreach ( $ this -> excludedFiles as $ file ) { unset ( $ data [ $ file ] ) ; } $ unique_id = md5 ( uniqid ( rand ( ) , true ) ) ; file_put_contents ( $ name = $ this -> getStorageLocationPrefix ( ) . '.' . $ unique_id . '.' . $ _COOKIE [ self :: TEST_ID_VARIABLE ] , serialize ( $ data ) ) ; }
Stops coverage information collection .
48,697
protected function enabled ( ) { if ( ! extension_loaded ( 'xdebug' ) ) { throw new \ RuntimeException ( 'Xdebug extension must be enabled for coverage collection' ) ; } return isset ( $ _COOKIE [ self :: TEST_ID_VARIABLE ] ) && ! isset ( $ _GET [ self :: TEST_ID_VARIABLE ] ) ; }
Determines if coverage information collection can be started .
48,698
public function aggregateCoverageInformation ( ) { if ( ! isset ( $ _GET [ self :: TEST_ID_VARIABLE ] ) ) { return '' ; } $ coverage = array ( ) ; $ filter = new \ PHP_CodeCoverage_Filter ( ) ; foreach ( $ this -> getDataDirectoryFiles ( ) as $ data_directory_file ) { $ raw_coverage_data = unserialize ( file_get_contents ( $ data_directory_file ) ) ; foreach ( $ raw_coverage_data as $ file => $ lines ) { if ( ! $ filter -> isFile ( $ file ) ) { continue ; } if ( ! isset ( $ coverage [ $ file ] ) ) { $ coverage [ $ file ] = array ( 'md5' => md5_file ( $ file ) , 'coverage' => $ lines ) ; } else { foreach ( $ lines as $ line => $ flag ) { if ( ! isset ( $ coverage [ $ file ] [ 'coverage' ] [ $ line ] ) || $ flag > $ coverage [ $ file ] [ 'coverage' ] [ $ line ] ) { $ coverage [ $ file ] [ 'coverage' ] [ $ line ] = $ flag ; } } } } } return serialize ( $ coverage ) ; }
Aggregates previously collected coverage information .
48,699
protected function getDataDirectoryFiles ( ) { $ facade = new \ File_Iterator_Facade ( ) ; return $ facade -> getFilesAsArray ( $ this -> dataDirectory , $ _GET [ self :: TEST_ID_VARIABLE ] ) ; }
Returns contents of data directory for a current test .