idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
8,800
|
function contruye_excel ( $ id ) { $ this -> layout = 'excel' ; Configure :: write ( 'debug' , 0 ) ; $ this -> RequestHandler -> setContent ( 'xls' , 'application/vnd.ms-excel' ) ; $ res = $ this -> Query -> findById ( $ id ) ; $ sql = $ res [ 'Query' ] [ 'query' ] ; $ this -> Query -> recursive = - 1 ; $ consulta_ejecutada = $ this -> Query -> query ( $ sql ) ; $ precols = array_keys ( $ consulta_ejecutada [ 0 ] ) ; $ quitar_columnas = $ consulta_ejecutada [ 0 ] [ 0 ] ; while ( list ( $ key , $ value ) = each ( $ quitar_columnas ) ) : $ columnas [ ] = $ key ; endwhile ; $ this -> set ( 'nombre' , $ res [ 'Query' ] [ 'name' ] ) ; $ this -> set ( 'columnas' , $ columnas ) ; $ this -> set ( 'filas' , $ consulta_ejecutada ) ; }
|
esto me construye un excel en la vista con el id de la query
|
8,801
|
private function db_update ( $ file ) { require $ file ; if ( isset ( $ table ) ) { $ config = wp_parse_args ( $ table , [ 'name' => str_replace ( '.php' , '' , basename ( $ file ) ) , 'version' => false , 'engine' => Engine :: INNODB , 'columns' => false , 'primary_key' => [ ] , 'indexes' => [ ] , 'unique' => [ ] , 'fulltext' => [ ] , ] ) ; $ table_name = $ config [ 'name' ] ; if ( $ config [ 'name' ] && $ config [ 'version' ] && $ config [ 'indexes' ] ) { if ( $ this -> need_update ( $ table_name , $ config [ 'version' ] ) ) { $ config [ 'name' ] = $ this -> db -> prefix . $ config [ 'name' ] ; $ query = $ this -> make_query ( $ config ) ; if ( ! function_exists ( 'dbDelta' ) ) { require_once ABSPATH . "wp-admin/includes/upgrade.php" ; } $ result = dbDelta ( $ query ) ; if ( isset ( $ result [ $ config [ 'name' ] ] ) ) { $ message = sprintf ( '<code>%s</code> created.' , $ config [ 'name' ] ) ; } else { $ message = sprintf ( '<code>%s</code> updated.' , $ config [ 'name' ] ) ; } if ( ! empty ( $ this -> db -> last_error ) ) { $ message .= sprintf ( ' <small>(Error: %s)</small>' , $ this -> db -> last_error ) ; } if ( $ this -> table_exists ( $ config [ 'name' ] ) ) { update_option ( $ this -> option_key , array_merge ( $ this -> option , [ $ table_name => $ config [ 'version' ] , ] ) ) ; } else { $ message = sprintf ( 'Failed to create or update <code>%s</code>' , $ config [ 'name' ] ) ; } return $ message ; } } else { throw new \ Exception ( sprintf ( 'Config file %s is wrong.' , $ file ) ) ; } } else { throw new \ Exception ( sprintf ( 'Config file %s must be PHP Array format.' , $ file ) ) ; } return '' ; }
|
Update db if possible
|
8,802
|
private function make_query ( $ config ) { extract ( $ config ) ; if ( empty ( $ columns ) ) { throw new \ Exception ( sprintf ( 'Columns of %s shouldn\'t be empty.' , $ name ) , 500 ) ; } $ column_query = [ ] ; foreach ( $ columns as $ name => $ column ) { $ column_query [ ] = Column :: build_query ( $ name , $ column ) ; } if ( ! empty ( $ primary_key ) ) { $ column_query [ ] = sprintf ( 'PRIMARY KEY (%s)' , implode ( ', ' , $ primary_key ) ) ; } if ( ! empty ( $ indexes ) ) { foreach ( $ indexes as $ name => $ index ) { $ keys = ( array ) $ index ; $ column_query [ ] = sprintf ( 'KEY %s (%s)' , $ name , implode ( ', ' , $ index ) ) ; } } if ( ! empty ( $ unique ) ) { foreach ( $ unique as $ name => $ index ) { $ keys = ( array ) $ index ; $ column_query [ ] = sprintf ( 'UNIQUE (%s)' , implode ( ', ' , $ index ) ) ; } } if ( ! empty ( $ fulltext ) ) { foreach ( $ fulltext as $ name => $ index ) { $ keys = ( array ) $ index ; $ column_query [ ] = sprintf ( 'FULLTEXT %s (%s)' , $ name , implode ( ', ' , $ index ) ) ; } } if ( ! isset ( $ charset ) ) { $ charset = 'utf8' ; } $ sql = <<<SQLCREATE TABLE %s ( %s) ENGINE = %s CHARACTER SET %sSQL ; $ sql = sprintf ( $ sql , $ config [ 'name' ] , implode ( ',' . PHP_EOL . ' ' , $ column_query ) , $ engine , $ charset ) ; return $ sql ; }
|
Build create query
|
8,803
|
protected function need_update ( $ name , $ version ) { return ! isset ( $ this -> option [ $ name ] ) || ! $ this -> option [ $ name ] || version_compare ( $ this -> option [ $ name ] , $ version , '<' ) ; }
|
Detect if source version is greater than existing db
|
8,804
|
public function setTheme ( $ name ) { $ this -> getResponse ( ) -> setThemeName ( $ name ) ; $ this -> getResponse ( ) -> getTheme ( ) -> setName ( $ name ) ; }
|
Set the theme name in both the response and the theme objects
|
8,805
|
public function setBodyTitle ( $ title ) { $ this -> getResponse ( ) -> getTheme ( ) -> setBodyTitle ( $ title ) ; $ this -> _title = $ title ; }
|
Set page content title to be themed in the view
|
8,806
|
public function addView ( $ view , $ data = null ) { if ( ! is_object ( $ view ) ) $ view = new \ erdiko \ core \ View ( $ view , $ data ) ; if ( $ data != null ) $ view -> setData ( $ data ) ; $ this -> appendContent ( $ view -> toHtml ( ) ) ; }
|
Add a view from the current theme with the given data
|
8,807
|
public function getLayout ( $ layoutName , $ data = null , $ templateRootFolder = null ) { $ layout = new \ erdiko \ core \ Layout ( $ layoutName , $ data , $ this -> getThemeName ( ) ) ; $ layout -> setTitle ( $ this -> getBodyTitle ( ) ) ; if ( $ templateRootFolder != null ) { $ layout -> setViewRootFolder ( $ templateRootFolder ) ; $ layout -> setTemplateRootFolder ( $ templateRootFolder ) ; } return $ layout -> toHtml ( ) ; }
|
Load a layout with the given data
|
8,808
|
public function setMeta ( $ meta ) { foreach ( $ meta as $ name => $ content ) $ this -> getResponse ( ) -> getTheme ( ) -> addMeta ( $ name , $ content ) ; }
|
Set multiple meta fields at once
|
8,809
|
public function addPhpToJs ( $ key , $ value ) { if ( is_bool ( $ value ) ) { $ value = $ value ? "true" : "false" ; } elseif ( is_string ( $ value ) ) { $ value = "\"$value\"" ; } elseif ( is_array ( $ value ) ) { $ value = json_encode ( $ value ) ; } elseif ( is_object ( $ value ) && method_exists ( $ value , "toArray" ) ) { $ value = json_encode ( $ value -> toArray ( ) ) ; } else { throw new \ Exception ( "Can not translate a parameter from PHP to JS\n" . print_r ( $ value , true ) ) ; } $ this -> _themeExtras [ 'phpToJs' ] [ $ key ] = $ value ; }
|
Add phpToJs variable to be set on the current page
|
8,810
|
public function setShipping ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ Shipping \ Shipping $ shipping = null ) { $ this -> shipping = $ shipping ; return $ this ; }
|
Set shipping .
|
8,811
|
public function groups ( ) { $ a = & $ this -> class_cfg [ 'arch' ] ; $ t = & $ this -> class_cfg [ 'tables' ] ; $ id = $ this -> db -> cfn ( $ a [ 'groups' ] [ 'id' ] , $ t [ 'groups' ] , 1 ) ; $ group = $ this -> db -> cfn ( $ a [ 'groups' ] [ 'group' ] , $ t [ 'groups' ] , 1 ) ; $ id_group = $ this -> db -> cfn ( $ a [ 'users' ] [ 'id_group' ] , $ t [ 'users' ] , 1 ) ; $ active = $ this -> db -> cfn ( $ a [ 'users' ] [ 'active' ] , $ t [ 'users' ] , 1 ) ; $ users_id = $ this -> db -> cfn ( $ a [ 'users' ] [ 'id' ] , $ t [ 'users' ] , 1 ) ; $ groups = $ this -> db -> escape ( $ t [ 'groups' ] ) ; $ users = $ this -> db -> escape ( $ t [ 'users' ] ) ; return $ this -> db -> get_rows ( " SELECT $id, $group, COUNT($users_id) AS `num` FROM $groups LEFT JOIN $users ON $id_group = $id GROUP BY $id" ) ; }
|
Returns all the users groups - with or without admin
|
8,812
|
public function call ( $ method , Array $ params = [ ] ) { $ params = $ this -> mergeParams ( $ method , $ params ) ; try { $ result = $ this -> soapClient -> __soapCall ( $ method , $ params ) ; } catch ( SoapFault $ fault ) { throw $ fault ; } return $ result ; }
|
Prepare and issue a call
|
8,813
|
protected function mergeParams ( $ method , Array $ params = [ ] ) { $ mergedParams = array_merge ( $ this -> defaultParams , $ params ) ; $ newParams = [ $ method => $ mergedParams ] ; return $ newParams ; }
|
Default way to merge params
|
8,814
|
protected function deleteExtraRecords ( ) { try { $ limit = ( int ) ( $ this -> limitMax ) ; } catch ( \ Exception $ ex ) { Yii :: error ( $ ex -> getMessage ( ) , __METHOD__ ) ; return 0 ; } $ host = $ this -> host ; $ count = static :: find ( ) -> createdBy ( $ host ) -> count ( ) ; Yii :: info ( $ host -> getReadableGUID ( ) . " has $count login logs." , __METHOD__ ) ; if ( $ count > $ limit ) { foreach ( static :: find ( ) -> createdBy ( $ host ) -> orderByCreatedAt ( ) -> limit ( $ count - $ limit ) -> all ( ) as $ login ) { $ result = $ login -> delete ( ) ; if ( YII_ENV_DEV ) { Yii :: info ( $ host -> getReadableGUID ( ) . ": ($result) login record created at (" . $ login -> getCreatedAt ( ) . ") was just deleted." , __METHOD__ ) ; } } } return $ count - $ limit ; }
|
Delete extra records .
|
8,815
|
protected function deleteExpiredRecords ( ) { try { $ limit = ( int ) ( $ this -> limitDuration ) ; } catch ( \ Exception $ ex ) { Yii :: error ( $ ex -> getMessage ( ) , __METHOD__ ) ; return 0 ; } $ count = 0 ; $ host = $ this -> host ; foreach ( static :: find ( ) -> createdBy ( $ host ) -> andWhere ( [ '<=' , $ this -> createdAtAttribute , $ this -> offsetDatetime ( $ this -> currentUtcDatetime ( ) , - $ limit ) ] ) -> all ( ) as $ login ) { $ result = $ login -> delete ( ) ; $ count += $ result ; if ( YII_ENV_DEV ) { Yii :: info ( $ host -> getReadableGUID ( ) . ": ($result) login record created at (" . $ login -> getCreatedAt ( ) . ") was just deleted." , __METHOD__ ) ; } } return $ count ; }
|
Delete expired records .
|
8,816
|
public function has_data ( $ idx = null ) { if ( ! \ is_array ( $ this -> data ) ) { return false ; } if ( \ is_null ( $ idx ) ) { return ! empty ( $ this -> data ) ; } $ args = \ func_get_args ( ) ; foreach ( $ args as $ arg ) { if ( ! isset ( $ this -> data [ $ idx ] ) ) { return false ; } } return true ; }
|
Checks if data exists or if a specific index exists in the data
|
8,817
|
protected function _findSource ( ) { $ path = $ this -> _manager -> getPath ( ) ; if ( $ path -> isVirtual ( $ this -> _source ) ) { $ path = $ path -> get ( $ this -> _source ) ; $ isStrictMode = $ this -> _manager -> getParams ( ) -> get ( 'strict_mode' , false , 'bool' ) ; if ( $ isStrictMode && ! $ path ) { throw new Exception ( "Asset file not found: {$this->_source}" ) ; } return $ path ; } if ( Url :: isAbsolute ( $ this -> _source ) ) { return $ this -> _source ; } $ fullPath = $ path -> get ( 'root:' . $ this -> _source ) ; return $ fullPath ; }
|
Find source in variants .
|
8,818
|
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ appConfig = $ serviceLocator ; $ config = array_key_exists ( $ appConfig [ 'view_helper_date' ] ) ? $ appConfig [ 'view_helper_date' ] : array ( ) ; if ( array_key_exists ( 'formats' , $ config ) ) { $ this -> addFormats ( $ config [ 'formats' ] ) ; } }
|
Create and configure instance
|
8,819
|
public function addFormats ( array $ formats ) { foreach ( $ formats as $ name => $ format ) { $ this -> formats [ $ name ] = $ format ; } }
|
Add datetime formats
|
8,820
|
protected function options ( ) { $ areas = app ( AreaManager :: class ) -> getAreas ( ) ; $ options = [ ] ; foreach ( $ areas as $ area ) { array_set ( $ options , $ area -> getId ( ) , $ area -> getLabel ( ) ) ; } return $ options ; }
|
Filter instance dataprovider
|
8,821
|
public static function findByKey ( $ array , $ key , $ value ) { foreach ( $ array as $ element ) if ( call_user_func ( array ( $ element , $ key ) ) === $ value ) return $ element ; return null ; }
|
Finds an array element by comparing a member with the given value .
|
8,822
|
public static function sortByKey ( $ _array , $ key ) { $ array = $ _array ; $ result = usort ( $ array , function ( $ a , $ b ) use ( $ key ) { return strcmp ( call_user_func ( array ( $ a , $ key ) ) , call_user_func ( array ( $ b , $ key ) ) ) ; } ) ; if ( ! $ result ) throw new ArrayException ( "sorting by \"$key\" failed" ) ; return $ array ; }
|
Sorts an array in ascending order regarding a member .
|
8,823
|
protected function prepareToIndent ( ) { foreach ( $ this -> lines as $ lineNumber => $ line ) { $ this -> lines [ $ lineNumber ] = trim ( $ line ) ; } $ this -> outputLines = $ this -> lines ; }
|
Pre - process all the lines so they are ready to be indented
|
8,824
|
public function createAndExecute ( ) { $ request = $ this -> createRequest ( ) ; $ response = $ this -> api -> execute ( $ request , $ this ) ; $ this -> response = $ response ; return $ response ; }
|
Create and execute the operation returning the raw response from the server .
|
8,825
|
public function dispatchAsync ( \ Amp \ Artax \ Request $ request , callable $ callable ) { return $ this -> api -> executeAsync ( $ request , $ this , $ callable ) ; }
|
Dispatch the request for this operation and process the response asynchronously . Allows you to modify the request before it is sent .
|
8,826
|
public static function getGeneratorMap ( ) { $ generatorMap = array ( ) ; foreach ( self :: getGenerators ( ) as $ generator ) $ generatorMap [ call_user_func ( array ( $ generator , "getKey" ) ) ] = $ generator ; return $ generatorMap ; }
|
Returns a map from all generator keys to class names .
|
8,827
|
public function generateFiles ( ) { if ( $ this -> files === null ) { $ this -> files = array ( ) ; $ this -> tracingLinks = array ( ) ; $ this -> _generateFiles ( ) ; } if ( $ this -> settings -> getOptional ( "logFile" , false ) ) return array_merge ( array ( $ this -> logFile ) , $ this -> files ) ; else return $ this -> files ; }
|
Generates the files for all registered artifacts . If the files have already been generated returns the cached files . The generator s log file is included .
|
8,828
|
protected function isSelectedFeature ( $ featureName ) { $ isSelected = false ; foreach ( $ this -> selectedArtifacts as $ selectedArtifact ) if ( $ featureName === $ selectedArtifact -> getFeature ( ) -> getName ( ) ) $ isSelected = true ; return $ isSelected ; }
|
Returns whether a feature s artifact is selected .
|
8,829
|
public function createObject ( $ builder , $ parameters = array ( ) ) { if ( is_string ( $ builder ) ) { if ( class_exists ( $ builder ) ) { $ response = $ parameters [ 'response' ] ; $ nextMiddleware = $ parameters [ 'next' ] ; if ( $ response == null ) { throw new InvalidArgumentException ( "'response' parameters must be 'Psr\Http\Message\ResponseInterface' instance." ) ; } if ( $ nextMiddleware != null ) { if ( ( $ nextMiddleware instanceof BaseMiddleware ) == false ) { throw new InvalidArgumentException ( "'next' parameters must be 'Ken\Http\BaseMiddleware' instance." ) ; } } return new $ builder ( $ response , $ nextMiddleware ) ; } throw new InvalidArgumentException ( "Class '{$builder}' not found." ) ; } throw new InvalidArgumentException ( "'builder' must be a fully qualified namespace of middleware class." ) ; }
|
Creates a middleware instance
|
8,830
|
public static function get_files ( $ dir , $ including_dirs = false , $ hidden = false , $ extension = null ) { $ dir = self :: clean ( $ dir ) ; clearstatcache ( ) ; if ( $ dir === './' ) { $ dir = '.' ; } if ( is_dir ( $ dir ) && ( ( $ dir === '.' ) || ( ( strpos ( basename ( $ dir ) , '.' ) !== 0 ) || $ hidden ) ) ) { $ files = [ ] ; $ fs = scandir ( $ dir , SCANDIR_SORT_ASCENDING ) ; foreach ( $ fs as $ f ) { if ( $ f !== '.' && $ f !== '..' ) { if ( $ hidden || ( strpos ( basename ( $ f ) , '.' ) !== 0 ) ) { if ( $ including_dirs ) { $ files [ ] = self :: cur ( $ dir . '/' ) . $ f ; } else if ( is_file ( $ dir . '/' . $ f ) ) { if ( ! $ extension || ( strtolower ( $ extension ) === strtolower ( bbn \ str :: file_ext ( $ f ) ) ) ) { $ files [ ] = self :: cur ( $ dir . '/' ) . $ f ; } } } } } if ( \ count ( $ files ) > 0 ) { bbn \ x :: sort ( $ files ) ; } return $ files ; } return false ; }
|
Returns an array of files contained in the given directory . Returns the full path of files .
|
8,831
|
public static function delete ( string $ dir , bool $ full = true ) : bool { $ dir = self :: clean ( $ dir ) ; if ( is_dir ( $ dir ) ) { $ files = self :: get_files ( $ dir , 1 , 1 ) ; foreach ( $ files as $ file ) { self :: delete ( $ file ) ; } if ( $ full ) { return rmdir ( $ dir ) ; } return true ; } if ( is_file ( $ dir ) ) { return unlink ( $ dir ) ; } return false ; }
|
Deletes the given directory and all its content .
|
8,832
|
public static function scan ( string $ dir , string $ type = null , bool $ hidden = false ) : array { $ all = [ ] ; $ dir = self :: clean ( $ dir ) ; $ dirs = self :: get_dirs ( $ dir ) ; if ( \ is_array ( $ dirs ) ) { if ( $ type && ( strpos ( $ type , 'file' ) === 0 ) ) { $ all = self :: get_files ( $ dir , false , $ hidden ) ; } else if ( $ type && ( ( strpos ( $ type , 'dir' ) === 0 ) || ( strpos ( $ type , 'fold' ) === 0 ) ) ) { $ all = $ dirs ; } else if ( $ type ) { $ all = array_filter ( self :: get_files ( $ dir , false , $ hidden ) , function ( $ a ) use ( $ type ) { $ ext = bbn \ str :: file_ext ( $ a ) ; return strtolower ( $ ext ) === strtolower ( $ type ) ; } ) ; } else { $ files = self :: get_files ( $ dir , false , $ hidden ) ; if ( \ is_array ( $ files ) ) { $ all = array_merge ( $ dirs , $ files ) ; } } foreach ( $ dirs as $ d ) { $ all = array_merge ( \ is_array ( $ all ) ? $ all : [ ] , self :: scan ( $ d , $ type , $ hidden ) ) ; } } return $ all ; }
|
Returns an array with all the content of the given directory .
|
8,833
|
public static function get_tree ( string $ dir , bool $ only_dir = false , callable $ filter = null , bool $ hidden = false ) : array { $ r = [ ] ; $ dir = self :: clean ( $ dir ) ; $ dirs = self :: get_dirs ( $ dir , $ hidden ) ; if ( \ is_array ( $ dirs ) ) { foreach ( $ dirs as $ d ) { $ x = [ 'name' => $ d , 'type' => 'dir' , 'num_children' => 0 , 'items' => self :: get_tree ( $ d , $ only_dir , $ filter , $ hidden ) ] ; $ x [ 'num_children' ] = \ count ( $ x [ 'items' ] ) ; if ( $ filter ) { if ( $ filter ( $ x ) ) { $ r [ ] = $ x ; } } else { $ r [ ] = $ x ; } } if ( ! $ only_dir ) { $ files = self :: get_files ( $ dir , false , $ hidden ) ; foreach ( $ files as $ f ) { $ x = [ 'name' => $ f , 'type' => 'file' , 'ext' => bbn \ str :: file_ext ( $ f ) ] ; if ( $ filter ) { if ( $ filter ( $ x ) ) { $ r [ ] = $ x ; } } else { $ r [ ] = $ x ; } } } } return $ r ; }
|
Return an array with the tree of the folder s content .
|
8,834
|
public static function create_path ( string $ dir , $ chmod = false ) { if ( ! $ dir || ! \ is_string ( $ dir ) ) { return false ; } clearstatcache ( ) ; if ( ! is_dir ( $ dir ) ) { $ bits = explode ( '/' , $ dir ) ; $ path = empty ( $ bits [ 0 ] ) ? '/' : '' ; foreach ( $ bits as $ i => $ b ) { if ( ! empty ( $ b ) ) { $ path .= $ b ; if ( ! is_dir ( $ path ) ) { if ( ! mkdir ( $ path ) || ! is_dir ( $ path ) ) { return false ; } if ( $ chmod ) { @ chmod ( $ path , $ chmod ) ; } } $ path .= '/' ; } } } return $ dir ; }
|
Creates a folder with the given path .
|
8,835
|
public static function move ( $ orig , $ dest , $ st = '_v' , $ length = 0 ) : bool { if ( file_exists ( $ orig ) && self :: create_path ( \ dirname ( $ dest ) ) ) { if ( file_exists ( $ dest ) ) { if ( $ st === true ) { self :: delete ( $ dest ) ; } else { $ i = 1 ; while ( $ i ) { $ dir = \ dirname ( $ dest ) . '/' ; $ file_name = bbn \ str :: file_ext ( $ dest , 1 ) ; $ file = $ file_name [ 0 ] . $ st ; if ( $ length > 0 ) { $ len = \ strlen ( bbn \ str :: cast ( $ i ) ) ; if ( $ len > $ length ) { return false ; } $ file .= str_repeat ( '0' , $ length - $ len ) ; } $ file .= bbn \ str :: cast ( $ i ) ; if ( ! empty ( $ file_name [ 1 ] ) ) { $ file .= '.' . $ file_name [ 1 ] ; } $ i ++ ; if ( ! file_exists ( $ dir . $ file ) ) { $ dest = $ dir . $ file ; $ i = false ; } } } } if ( rename ( $ orig , $ dest ) ) { return true ; } } return false ; }
|
Moves a file or directory to a new location
|
8,836
|
public static function copy ( $ src , $ dst ) : bool { if ( is_file ( $ src ) ) { return copy ( $ src , $ dst ) ; } if ( is_dir ( $ src ) && self :: create_path ( $ dst ) ) { $ files = self :: get_files ( $ src ) ; $ dirs = self :: get_dirs ( $ src ) ; foreach ( $ files as $ f ) { copy ( $ f , $ dst . '/' . basename ( $ f ) ) ; } foreach ( $ dirs as $ f ) { self :: copy ( $ f , $ dst . '/' . basename ( $ f ) ) ; } return true ; } else { return false ; } }
|
Will move the content of the given folder to a new destination . Doesn t move the hidden files .
|
8,837
|
public function appendText ( $ value ) { $ text = $ this -> stringify ( $ value ) ; $ this -> message = $ this -> message . $ text ; return $ this ; }
|
Append the text to the last .
|
8,838
|
public function appendSpace ( $ length ) { $ paddingLength = ( int ) $ length ; $ this -> message = $ this -> message . str_pad ( '' , $ paddingLength , ' ' ) ; return $ this ; }
|
Append the length space .
|
8,839
|
public function appendValue ( $ value ) { $ appendValue = $ this -> formatValue ( $ value ) ; $ this -> message = $ this -> message . $ appendValue ; return $ this ; }
|
Append the value to the last .
|
8,840
|
public function appendValues ( array $ values ) { $ appendValues = [ ] ; foreach ( $ values as $ value ) { $ appendValues [ ] = $ this -> formatValue ( $ value ) ; } $ this -> message = $ this -> message . implode ( ', ' , $ appendValues ) ; return $ this ; }
|
Append the values to the last .
|
8,841
|
public function respond ( int $ statusCode = null , array $ headers = [ ] ) : JsonResponse { if ( ! is_null ( $ statusCode ) ) { $ this -> setStatus ( $ statusCode ) ; } $ data = $ this -> toArray ( ) ; $ data = $ this -> includeStatusCode ( $ data ) ; $ data = $ this -> includeSuccessFlag ( $ data ) ; return $ this -> responseFactory -> json ( $ data , $ this -> statusCode , $ headers ) ; }
|
Serialize the data and wrap it in a JSON response object .
|
8,842
|
public function load ( $ resource , $ type = null ) { $ repository = $ this -> delegatingLoader -> load ( $ resource , $ type ) ; if ( ! $ repository instanceof ConfigRepositoryInterface ) { throw new \ UnexpectedValueException ( 'The loader must return a repository instance' ) ; } return $ repository ; }
|
Loads a resource like file or inline configuration
|
8,843
|
public static function routes ( ) { $ area = area ( ) ; Route :: post ( $ area . '/notifications/notifications' , NotificationController :: class . '@index' ) ; Route :: post ( $ area . '/notifications/widgets/send' , NotificationController :: class . '@send' ) ; }
|
Widgets routes implementations
|
8,844
|
public function render ( ) { app ( 'antares.asset' ) -> container ( 'antares/foundation::application' ) -> add ( 'webpack_forms_basic' , '/webpack/forms_basic.js' , [ 'app_cache' ] ) ; publish ( 'notifications' , [ 'js/notification-widget.js' ] ) ; return view ( 'antares/notifications::widgets.send_notification' , [ 'form' => $ this -> form -> get ( ) ] ) -> render ( ) ; }
|
Renders widget content
|
8,845
|
protected function replaceInlineExamples ( DescriptorAbstract $ element ) { $ description = $ element -> getDescription ( ) ; $ matches = array ( ) ; if ( ! $ description || ! preg_match_all ( '/\{@example\s(.+?)\}/' , $ description , $ matches ) || count ( $ matches [ 0 ] ) < 1 ) { return $ description ; } $ matched = array ( ) ; foreach ( $ matches [ 0 ] as $ index => $ match ) { if ( isset ( $ matched [ $ match ] ) ) { continue ; } $ matched [ $ match ] = true ; $ exampleReflector = new ExampleTag ( 'example' , $ matches [ 1 ] [ $ index ] ) ; $ example = $ this -> exampleAssembler -> create ( $ exampleReflector ) ; $ replacement = '`' . $ example -> getExample ( ) . '`' ; if ( $ example -> getDescription ( ) ) { $ replacement = '*' . $ example -> getDescription ( ) . '*' . $ replacement ; } $ description = str_replace ( $ match , $ replacement , $ description ) ; } return $ description ; }
|
Replaces the example tags in the description with the contents of the found example .
|
8,846
|
protected function processSchema ( array $ tables ) { $ schemaDefinition = array ( ) ; array_walk ( $ tables , create_function ( '&$item,$key' , '$item = $item[0];' ) ) ; $ prefix = ezcDbSchema :: $ options -> tableNamePrefix ; foreach ( $ tables as $ tableName ) { $ tableNameWithoutPrefix = substr ( $ tableName , strlen ( $ prefix ) ) ; if ( $ prefix === '' || $ tableName !== $ tableNameWithoutPrefix ) { $ fields = $ this -> fetchTableFields ( $ tableName ) ; $ indexes = $ this -> fetchTableIndexes ( $ tableName ) ; $ schemaDefinition [ $ tableNameWithoutPrefix ] = ezcDbSchema :: createNewTable ( $ fields , $ indexes ) ; } } return $ schemaDefinition ; }
|
Loops over all the table names in the array and extracts schema information .
|
8,847
|
protected function lowercase ( array $ source ) { $ result = array ( ) ; foreach ( $ source as $ key => $ value ) $ result [ strtolower ( $ key ) ] = $ value ; return $ result ; }
|
Lowercase all array keys to conform default Database behaviour
|
8,848
|
private function applyAttribs ( Tokens $ tokens , $ index , array $ attribs ) { $ toInsert = [ ] ; foreach ( $ attribs as $ attrib ) { if ( null !== $ attrib && '' !== $ attrib -> getContent ( ) ) { $ toInsert [ ] = $ attrib ; $ toInsert [ ] = new Token ( [ T_WHITESPACE , ' ' ] ) ; } } if ( ! empty ( $ toInsert ) ) { $ tokens -> insertAt ( $ index , $ toInsert ) ; } }
|
Apply token attributes .
|
8,849
|
private function grabAttribsBeforeMethodToken ( Tokens $ tokens , $ index ) { static $ tokenAttribsMap = [ T_PRIVATE => 'visibility' , T_PROTECTED => 'visibility' , T_PUBLIC => null , T_ABSTRACT => 'abstract' , T_FINAL => 'final' , T_STATIC => 'static' , ] ; return $ this -> grabAttribsBeforeToken ( $ tokens , $ index , $ tokenAttribsMap , [ 'abstract' => null , 'final' => null , 'visibility' => null , 'static' => null , ] ) ; }
|
Grab attributes before method token at given index .
|
8,850
|
private function grabAttribsBeforePropertyToken ( Tokens $ tokens , $ index ) { static $ tokenAttribsMap = [ T_VAR => null , T_PRIVATE => 'visibility' , T_PROTECTED => 'visibility' , T_PUBLIC => 'visibility' , T_STATIC => 'static' , ] ; $ result = $ this -> grabAttribsBeforeToken ( $ tokens , $ index , $ tokenAttribsMap , [ 'visibility' => new Token ( [ T_PUBLIC , 'public' ] ) , 'static' => null , ] ) ; if ( $ result [ 'visibility' ] && 'public' === $ result [ 'visibility' ] -> getContent ( ) ) { if ( $ result [ 'static' ] ) { $ result [ 'visibility' ] = null ; } } return $ result ; }
|
Grab attributes before property token at given index .
|
8,851
|
private function grabAttribsBeforeToken ( Tokens $ tokens , $ index , array $ tokenAttribsMap , array $ attribs ) { while ( true ) { $ token = $ tokens [ -- $ index ] ; if ( ! $ token -> isArray ( ) ) { if ( $ token -> equalsAny ( [ '{' , '}' , '(' , ')' ] ) ) { break ; } continue ; } if ( array_key_exists ( $ token -> getId ( ) , $ tokenAttribsMap ) ) { if ( $ tokenAttribsMap [ $ token -> getId ( ) ] ) { $ attribs [ $ tokenAttribsMap [ $ token -> getId ( ) ] ] = clone $ token ; } $ tokens [ $ index ] -> clear ( ) ; $ tokens [ $ index + 1 ] -> clear ( ) ; continue ; } if ( $ token -> isGivenKind ( [ T_WHITESPACE , T_COMMENT , T_DOC_COMMENT ] ) ) { continue ; } break ; } return $ attribs ; }
|
Grab attributes before token at given index .
|
8,852
|
public function confirmDelete ( Permission $ permission ) { $ this -> authorize ( 'delete' , Permission :: class ) ; return view ( 'laralum::pages.confirmation' , [ 'method' => 'DELETE' , 'action' => route ( 'laralum::permissions.destroy' , [ 'permission' => $ permission -> id ] ) , ] ) ; }
|
Displays a view to confirm delete .
|
8,853
|
protected function sendNotificationMail ( $ exception ) { $ message = array ( ) ; $ message [ ] = 'Title: ' . $ this -> getTitle ( $ exception ) ; $ message [ ] = 'Message: ' . PHP_EOL . $ this -> getMessage ( $ exception ) ; $ message [ ] = 'Server name: ' . filter_input ( INPUT_SERVER , 'SERVER_NAME' ) ; $ message [ ] = 'Request URI: ' . PHP_EOL . filter_input ( INPUT_SERVER , 'SERVER_NAME' ) . filter_input ( INPUT_SERVER , 'REQUEST_URI' ) ; $ message [ ] = 'Request-Info: ' . PHP_EOL . print_r ( filter_input_array ( INPUT_SERVER ) , true ) ; $ message [ ] = 'POST: ' . PHP_EOL . print_r ( filter_input_array ( INPUT_POST ) , true ) ; $ message [ ] = 'GET: ' . PHP_EOL . print_r ( filter_input_array ( INPUT_GET ) , true ) ; try { $ mail = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Core\\Mail\\MailMessage' ) ; $ mail -> setFrom ( MailUtility :: getSystemFrom ( ) ) -> setTo ( array ( $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'BE' ] [ 'warning_email_addr' ] ) ) -> setSubject ( MailUtility :: getSystemFromName ( ) . ' - ' . $ this -> getTitle ( $ exception ) ) -> setBody ( implode ( PHP_EOL . PHP_EOL , $ message ) ) -> send ( ) ; } catch ( \ Exception $ e ) { $ logger = GeneralUtility :: makeInstance ( 'TYPO3\CMS\Core\Log\LogManager' ) -> getLogger ( __CLASS__ ) ; $ logger -> error ( 'Could not send exception message to system admin!' , array ( $ e -> __toString ( ) ) ) ; } }
|
Sends an exception as notification e - mail
|
8,854
|
protected function isValid ( $ item ) { if ( ( ! $ item instanceof stdClass ) || ! isset ( $ item -> type ) || ! isset ( $ item -> modifiers ) ) { return false ; } if ( $ this -> doctypeValidationEnabled ) { if ( ! isset ( $ item -> content ) && ( ! $ this -> view -> plugin ( 'doctype' ) -> isHtml5 ( ) || ( ! $ this -> view -> plugin ( 'doctype' ) -> isHtml5 ( ) && $ item -> type !== 'charset' ) ) ) { return false ; } if ( ! $ this -> view -> plugin ( 'doctype' ) -> isHtml5 ( ) && $ item -> type === 'itemprop' ) { return false ; } if ( ! $ this -> view -> plugin ( 'doctype' ) -> isRdfa ( ) && $ item -> type === 'property' ) { return false ; } } return true ; }
|
Determine if item is valid
|
8,855
|
public function describe ( $ table ) { $ schema = $ this -> db -> connection ( ) -> getDoctrineConnection ( ) -> getSchemaManager ( ) ; return $ this -> parseSchema ( $ schema -> listTableColumns ( $ table ) ) ; }
|
Describe all columns in a single table
|
8,856
|
protected function parseSchema ( array $ columns ) { $ schema = [ ] ; foreach ( $ columns as $ name => $ column ) { $ schema [ ] = [ 'name' => $ column -> getName ( ) , 'type' => $ column -> getType ( ) -> getName ( ) ] ; } return $ schema ; }
|
Convert the DBAL schema to an assoc array .
|
8,857
|
public static function flatten ( array $ value ) : array { $ result = [ ] ; array_walk_recursive ( $ value , function ( $ item ) use ( & $ result ) { $ result [ ] = $ item ; } ) ; return $ result ; }
|
Given a multi - dimensional array flatten the array to a single level .
|
8,858
|
public function requestAccessToken ( $ code , $ redirectUri , $ expiresIn = null , $ state = null ) { $ parameters = [ 'code' => $ code , 'grant_type' => 'authorization_code' , 'client_id' => $ this -> clientId , 'redirect_uri' => $ redirectUri , ] ; if ( $ expiresIn != null ) { $ parameters [ 'expires_in' ] = $ expiresIn ; } if ( $ state != null ) { $ parameters [ 'state' ] = $ state ; } return $ this -> tokenRequest ( 'oauth2/token' , $ parameters ) ; }
|
Request new Fitbit access token .
|
8,859
|
public function refreshAccessToken ( $ refreshToken , $ expiresIn = null ) { $ parameters = [ 'grant_type' => 'refresh_token' , 'refresh_token' => $ refreshToken , ] ; if ( $ expiresIn != null ) { $ parameters [ 'expires_in' ] = $ expiresIn ; } return $ this -> tokenRequest ( 'oauth2/token' , $ parameters ) ; }
|
Refresh Fitbit token .
|
8,860
|
private function tokenRequest ( $ namespace , $ parameters ) { $ client = new Client ( [ 'headers' => [ 'content-type' => 'application/x-www-form-urlencoded' , 'Authorization' => 'Basic ' . base64_encode ( $ this -> clientId . ':' . $ this -> secret ) , ] ] ) ; return $ client -> post ( self :: FITBIT_API_URL . $ namespace . '?' . http_build_query ( $ parameters ) ) ; }
|
Request token action .
|
8,861
|
public function send ( $ url , $ method = 'GET' , $ data = [ ] ) { $ method = strtolower ( $ method ) ; $ settings = [ 'headers' => array_merge ( [ 'Authorization' => 'Bearer ' . $ this -> getToken ( ) , 'Content-Type' => 'application/x-www-form-urlencoded' , ] , $ this -> getHeaders ( ) ) , ] ; if ( $ method == 'post' ) { $ settings [ 'form_params' ] = $ data ; } return $ this -> client -> $ method ( $ url , $ settings ) ; }
|
Send authorized request to Fitbit API .
|
8,862
|
public function setExtension ( $ ext ) { $ this -> extension = $ ext ; if ( ! $ this -> extensionMap -> has ( $ ext ) ) { throw new Exceptions \ InvalidExtension ( $ ext ) ; } return $ this ; }
|
Sets the extension
|
8,863
|
public function process ( $ data = '' ) { $ this -> data = $ data ; $ ext = $ this -> extensionMap -> get ( $ this -> extension ) ; $ arr = $ ext -> load ( $ data ) -> toArray ( ) ; $ this -> paramBag = new ParamBag ( $ arr ) ; return true ; }
|
Loads an extension class to convert the data to an array and pass it back as a param bag
|
8,864
|
public function toNative ( ParamBag $ paramBag ) { $ ext = $ this -> extensionMap -> get ( $ this -> extension ) ; $ native = $ ext -> load ( $ paramBag -> all ( ) ) -> toNative ( ) ; return $ native ; }
|
Converts the parambag instance of the native extension format
|
8,865
|
public function transform ( $ lang ) { $ lang = $ this -> entityToArray ( Lang :: class , $ lang ) ; return [ 'code' => $ lang [ 'code' ] , 'i18n' => $ lang [ 'i18n' ] , 'isEnabled' => ( bool ) $ lang [ 'is_enabled' ] , 'isDefault' => ( bool ) $ lang [ 'is_default' ] , ] ; }
|
Transforms lang entity
|
8,866
|
public function decorate ( $ contents , array $ options = array ( ) ) { return $ this -> getTwigEnvironment ( ) -> render ( $ this -> getTemplateFilename ( ) , array_merge ( array ( 'contents' => $ contents ) , $ options ) ) ; }
|
Applies the relevant template upon the given content .
|
8,867
|
public function getAssets ( ) { $ finder = new Finder ( ) ; return iterator_to_array ( $ finder -> files ( ) -> in ( $ this -> path . DIRECTORY_SEPARATOR . $ this -> name ) -> depth ( '> 0' ) -> notName ( '*.twig' ) -> sortByName ( ) ) ; }
|
Returns a list of files that need to be copied to the destination location .
|
8,868
|
public function setBaseRequest ( ServerRequestInterface $ request ) { if ( $ request instanceof GlobalEnvironmentInterface && $ request -> isStale ( ) ) { throw new \ RuntimeException ( "Unable to set base request: ServerRequest is stale" ) ; } $ this -> baseRequest = $ request ; }
|
Set the base request
|
8,869
|
public function getBaseRequest ( ) { if ( ! isset ( $ this -> baseRequest ) ) { $ this -> baseRequest = new ServerRequest ( ) ; } $ request = $ this -> baseRequest ; if ( $ request instanceof GlobalEnvironmentInterface && $ request -> isStale ( ) === false ) { $ request = $ request -> withGlobalEnvironment ( true ) ; } return $ request ; }
|
Get the base request
|
8,870
|
public function setBaseResponse ( ResponseInterface $ response ) { if ( $ response instanceof GlobalEnvironmentInterface && $ response -> isStale ( ) ) { throw new \ RuntimeException ( "Unable to set base response: Response is stale" ) ; } $ this -> baseResponse = $ response ; }
|
Set the base response
|
8,871
|
public function getBaseResponse ( ) { if ( ! isset ( $ this -> baseResponse ) ) { $ this -> baseResponse = new Response ( ) ; } $ response = $ this -> baseResponse ; if ( $ response instanceof GlobalEnvironmentInterface && $ response -> isStale ( ) === false ) { $ response = $ response -> withGlobalEnvironment ( true ) ; } return $ response ; }
|
Get the base response
|
8,872
|
protected function resetOutput ( ) { if ( $ this -> baseResponse instanceof GlobalEnvironmentInterface ) { $ this -> baseResponse = $ this -> baseResponse -> revive ( ) ; } if ( isset ( $ this -> baseResponse ) && $ this -> baseResponse -> getBody ( ) instanceof OutputBufferStream ) { $ this -> baseResponse = $ this -> baseResponse -> withBody ( clone $ this -> baseResponse -> getBody ( ) ) ; } }
|
Reset the response
|
8,873
|
public function setHttpVersion ( $ version ) { $ pattern = '~^1\.[01]$~' ; if ( ! preg_match ( $ pattern , $ version ) ) return false ; $ this -> httpVersion = $ version ; return true ; }
|
Set the HTTP Protocol version of the Message
|
8,874
|
public function setRequestMethod ( $ method ) { if ( $ this -> getType ( ) !== self :: TYPE_REQUEST ) return false ; $ method = strtoupper ( $ method ) ; $ REQUEST_METHODS = array ( 'OPTIONS' , 'GET' , 'HEAD' , 'POST' , 'PUT' , 'DELETE' , 'TRACE' ) ; if ( ! in_array ( $ method , $ REQUEST_METHODS ) ) return false ; $ this -> requestMethod = $ method ; return true ; }
|
Set the Request Method of the HTTP Message
|
8,875
|
public function transform ( $ option ) { $ options = $ this -> entityToArray ( OptionCategory :: class , $ option ) ; $ data = [ 'data' => [ ] ] ; foreach ( $ options as $ option ) { $ data [ 'data' ] [ ] = [ 'key' => $ option , ] ; } return $ data ; }
|
Transforms option category entity
|
8,876
|
public function query_vars ( array $ vars ) { if ( ! empty ( $ this -> query_var ) ) { foreach ( $ this -> query_var as $ var ) { if ( false === array_search ( $ var , $ vars ) ) { $ vars [ ] = $ var ; } } } return $ vars ; }
|
Add query var filter
|
8,877
|
public function rewrite_rules_array ( array $ rules ) { if ( ! empty ( $ this -> rewrites ) ) { $ rules = array_merge ( $ this -> rewrites , $ rules ) ; } return $ rules ; }
|
Register rewrite rules
|
8,878
|
final public function detect_title ( \ WP_Query & $ wp_query ) { if ( $ wp_query -> is_main_query ( ) && $ this -> is_valid_query ( $ wp_query ) ) { add_filter ( 'wp_title' , [ $ this , 'wp_title' ] , 10 , 3 ) ; } }
|
Add wp_title filter if required
|
8,879
|
protected function add_meta_query ( \ WP_Query & $ wp_query , array $ meta_query ) { $ old_query = ( array ) $ wp_query -> get ( 'meta_query' ) ; array_push ( $ old_query , $ meta_query ) ; $ wp_query -> set ( 'meta_query' , $ old_query ) ; }
|
Add meta query
|
8,880
|
public function clear ( $ name = null ) { if ( $ name === null ) { $ this -> data = array ( ) ; } elseif ( is_array ( $ name ) ) { foreach ( $ name as $ index ) unset ( $ this -> data [ $ index ] ) ; } else { unset ( $ this -> data [ $ name ] ) ; } }
|
clears a the entire data or only the given key
|
8,881
|
public function assign ( $ name , $ val = null ) { if ( is_array ( $ name ) ) { reset ( $ name ) ; while ( list ( $ k , $ v ) = each ( $ name ) ) $ this -> data [ $ k ] = $ v ; } else { $ this -> data [ $ name ] = $ val ; } }
|
assigns a value or an array of values to the data object
|
8,882
|
public function build ( $ action , array $ data , CliInput $ input , Mapping $ mapping ) { $ context = new ZMQContext ( ) ; $ socket = new ZMQSocket ( $ context , ZMQ :: SOCKET_REQ ) ; $ socket -> setSockOpt ( ZMQ :: SOCKOPT_LINGER , 0 ) ; if ( $ input -> getMapping ( ) === 'compact' ) { $ transportMapper = new CompactTransportMapper ( ) ; $ runtimeCallMapper = new CompactRuntimeCallMapper ( $ transportMapper ) ; } else { $ transportMapper = new ExtendedTransportMapper ( ) ; $ runtimeCallMapper = new ExtendedRuntimeCallMapper ( $ transportMapper ) ; } $ caller = new ZeroMQRuntimeCaller ( new MessagePackSerializer ( ) , new CompactTransportMapper ( ) , $ socket , $ runtimeCallMapper , new Timer ( ) ) ; $ transport = $ this -> mapper -> getTransport ( $ data ) ; return new ActionApi ( $ this -> logger -> getRequestLogger ( $ transport -> getMeta ( ) -> getId ( ) ) , $ this -> component , $ mapping , dirname ( realpath ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ) , $ input -> getName ( ) , $ input -> getVersion ( ) , $ input -> getFrameworkVersion ( ) , $ input -> getVariables ( ) , $ input -> isDebug ( ) , $ action , $ caller , $ transport , new TypeCatalog ( ) , $ this -> mapper -> getParams ( $ data ) ) ; }
|
Build an Action Api class instance
|
8,883
|
public function getLastVersion ( $ post_id ) { $ qb = $ this -> createQueryBuilder ( 'p' ) ; $ qb -> where ( 'p.original=:post_id' ) -> orderBy ( 'p.createdAt' , 'DESC' ) -> setParameter ( ':post_id' , $ post_id ) ; $ result = $ qb -> getQuery ( ) -> setMaxResults ( 1 ) -> getResult ( Query :: HYDRATE_OBJECT ) ; if ( is_null ( $ result ) ) { $ qb2 = $ this -> createQueryBuilder ( 'p' ) ; $ qb2 -> where ( 'p.id=:post_id' ) -> setParameter ( ':post_id' , $ post_id ) ; $ result = $ qb -> getQuery ( ) -> getResult ( Query :: HYDRATE_OBJECT ) ; } return $ result ; }
|
Get last version for a post
|
8,884
|
public function getAllLastVersion ( ) { $ qb = $ this -> createQueryBuilder ( 'p' ) ; $ qb -> where ( 'p.original IS NULL AND p.state=:state' ) -> setParameter ( ':state' , DocumentModel :: STATE_PUBLISHED ) ; $ result = $ qb -> getQuery ( ) -> getResult ( ) ; $ return = array ( ) ; foreach ( $ result as $ original ) { $ return [ ] = $ this -> getLastVersion ( $ original -> getId ( ) ) ; } return $ return ; }
|
Get all posts in their last version
|
8,885
|
private function attachFiles ( ) { if ( count ( $ this -> attachments ) === 0 ) { return ; } $ mimeMessage = $ this -> message -> getBody ( ) ; if ( is_string ( $ mimeMessage ) ) { $ originalBodyPart = new Mime \ Part ( $ mimeMessage ) ; $ originalBodyPart -> type = $ mimeMessage != strip_tags ( $ mimeMessage ) ? Mime \ Mime :: TYPE_HTML : Mime \ Mime :: TYPE_TEXT ; $ this -> setBody ( $ originalBodyPart ) ; $ mimeMessage = $ this -> message -> getBody ( ) ; ; } $ oldParts = $ mimeMessage -> getParts ( ) ; $ attachmentParts = [ ] ; $ info = new \ finfo ( FILEINFO_MIME_TYPE ) ; foreach ( $ this -> attachments as $ key => $ attachment ) { if ( ! is_file ( $ attachment ) ) { continue ; } $ basename = is_string ( $ key ) ? $ key : basename ( $ attachment ) ; $ part = new Mime \ Part ( fopen ( $ attachment , 'r' ) ) ; $ part -> id = $ basename ; $ part -> filename = $ basename ; $ part -> type = $ info -> file ( $ attachment ) ; $ part -> encoding = Mime \ Mime :: ENCODING_BASE64 ; $ part -> disposition = Mime \ Mime :: DISPOSITION_ATTACHMENT ; $ attachmentParts [ ] = $ part ; } $ body = new Mime \ Message ( ) ; $ body -> setParts ( array_merge ( $ oldParts , $ attachmentParts ) ) ; $ this -> message -> setBody ( $ body ) ; }
|
Attaches files to the message if any
|
8,886
|
public function post ( $ endpoint , array $ options = [ ] ) { $ jsonValues = [ ] ; if ( isset ( $ options [ 'json' ] ) ) { $ jsonValues = $ options [ 'json' ] ; } return $ this -> httpClient -> request ( 'POST' , 'https://api.craftcms.com/v1/' . $ endpoint , [ 'auth' => $ this -> setAuth ( ) , 'json' => $ jsonValues ] ) ; }
|
Sends a POST request to the Craftnet API
|
8,887
|
public function load ( ) { if ( file_exists ( $ this -> filepath ) && ( $ contents = file_get_contents ( $ this -> filepath ) ) ) { $ yaml = new Parser ( ) ; $ config = $ yaml -> parse ( $ contents ) ; if ( null === $ config ) { $ config = array ( ) ; } $ processor = new Processor ( ) ; $ configDefinition = new ConfigDefinition ( ) ; $ processedConfiguration = $ processor -> processConfiguration ( $ configDefinition , $ config ) ; if ( empty ( $ processedConfiguration ) ) { throw new Exception ( 'You need to specify at least one gaguge in the configuration file' ) ; } return $ processedConfiguration ; } else { throw new \ RuntimeException ( sprintf ( 'Configuration file does not exist or is not accessible %s' , $ this -> filepath ) ) ; } }
|
Process configuration and make sure the configuration format is as expected
|
8,888
|
public static function registerPlugin ( BlockView $ view , $ pluginName ) { $ optionsArray = $ view -> vars [ 'block_prefixes' ] ; array_splice ( $ optionsArray , - 1 , 1 , [ $ pluginName , end ( $ optionsArray ) ] ) ; $ view -> vars [ 'block_prefixes' ] = $ optionsArray ; }
|
Registers the plugin for the block type . You can use this method to add the additional block prefix that allow you to create an additional template for existing block type .
|
8,889
|
public static function normalizeTransValue ( $ text , $ parameters = null ) { if ( is_string ( $ text ) && ! empty ( $ text ) ) { $ text = [ 'label' => $ text ] ; } if ( ! empty ( $ parameters ) && is_array ( $ text ) && ! isset ( $ text [ 'parameters' ] ) ) { $ text [ 'parameters' ] = $ parameters ; } return $ text ; }
|
Normalizes the given value to the format that can be translated by a renderer .
|
8,890
|
public static function processUrl ( BlockView $ view , Options $ options , $ required = false , $ prefix = null ) { $ pathName = null !== $ prefix ? $ prefix . '_path' : 'path' ; $ routeName = null !== $ prefix ? $ prefix . '_route_name' : 'route_name' ; if ( $ options -> isExistsAndNotEmpty ( $ pathName ) ) { $ view -> vars [ $ pathName ] = $ options [ $ pathName ] ; } elseif ( $ options -> isExistsAndNotEmpty ( $ routeName ) ) { $ view -> vars [ $ routeName ] = $ options [ $ routeName ] ; $ routeParamName = null !== $ prefix ? $ prefix . '_route_parameters' : 'route_parameters' ; $ view -> vars [ $ routeParamName ] = isset ( $ options [ $ routeParamName ] ) ? $ options [ $ routeParamName ] : [ ] ; } elseif ( $ required ) { throw new MissingOptionsException ( sprintf ( 'Either "%s" or "%s" must be set.' , $ pathName , $ routeName ) ) ; } }
|
Gets the url related options and pass them to the block view .
|
8,891
|
public function removePreProcessor ( $ callback ) { if ( ( $ index = array_search ( $ callback , $ this -> processors [ 'pre' ] , true ) ) !== false ) { unset ( $ this -> processors [ 'pre' ] [ $ index ] ) ; } elseif ( ( $ index = array_search ( 'Dwoo_Processor_' . str_replace ( 'Dwoo_Processor_' , '' , $ callback ) , $ this -> processors [ 'pre' ] , true ) ) !== false ) { unset ( $ this -> processors [ 'pre' ] [ $ index ] ) ; } else { $ class = 'Dwoo_Processor_' . str_replace ( 'Dwoo_Processor_' , '' , $ callback ) ; foreach ( $ this -> processors [ 'pre' ] as $ index => $ proc ) { if ( is_array ( $ proc ) && ( $ proc [ 0 ] instanceof $ class ) || ( isset ( $ proc [ 'class' ] ) && $ proc [ 'class' ] == $ class ) ) { unset ( $ this -> processors [ 'pre' ] [ $ index ] ) ; break ; } } } }
|
removes a preprocessor from the compiler
|
8,892
|
public function addPostProcessor ( $ callback , $ autoload = false ) { if ( $ autoload ) { $ name = str_replace ( 'Dwoo_Processor_' , '' , $ callback ) ; $ class = 'Dwoo_Processor_' . $ name ; if ( class_exists ( $ class , false ) ) { $ callback = array ( new $ class ( $ this ) , 'process' ) ; } elseif ( function_exists ( $ class ) ) { $ callback = $ class ; } else { $ callback = array ( 'autoload' => true , 'class' => $ class , 'name' => $ name ) ; } $ this -> processors [ 'post' ] [ ] = $ callback ; } else { $ this -> processors [ 'post' ] [ ] = $ callback ; } }
|
adds a postprocessor to the compiler it will be called before the template is compiled
|
8,893
|
protected function loadProcessor ( $ class , $ name ) { if ( ! class_exists ( $ class , false ) && ! function_exists ( $ class ) ) { try { $ this -> dwoo -> getLoader ( ) -> loadPlugin ( $ name ) ; } catch ( Dwoo_Exception $ e ) { throw new Dwoo_Exception ( 'Processor ' . $ name . ' could not be found in your plugin directories, please ensure it is in a file named ' . $ name . '.php in the plugin directory' ) ; } } if ( class_exists ( $ class , false ) ) { return array ( new $ class ( $ this ) , 'process' ) ; } if ( function_exists ( $ class ) ) { return $ class ; } throw new Dwoo_Exception ( 'Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"' ) ; }
|
internal function to autoload processors at runtime if required
|
8,894
|
protected function resolveSubTemplateDependencies ( $ function ) { $ body = $ this -> templatePlugins [ $ function ] [ 'body' ] ; foreach ( $ this -> templatePlugins as $ func => $ attr ) { if ( $ func !== $ function && ! isset ( $ attr [ 'called' ] ) && strpos ( $ body , 'Dwoo_Plugin_' . $ func ) !== false ) { $ this -> templatePlugins [ $ func ] [ 'called' ] = true ; $ this -> resolveSubTemplateDependencies ( $ func ) ; } } $ this -> templatePlugins [ $ function ] [ 'checked' ] = true ; }
|
checks what sub - templates are used in every sub - template so that we re sure they are all compiled
|
8,895
|
public function setScope ( $ scope , $ absolute = false ) { $ old = $ this -> scopeTree ; if ( $ scope === null ) { unset ( $ this -> scope ) ; $ this -> scope = null ; } if ( is_array ( $ scope ) === false ) { $ scope = explode ( '.' , $ scope ) ; } if ( $ absolute === true ) { $ this -> scope = & $ this -> data ; $ this -> scopeTree = array ( ) ; } while ( ( $ bit = array_shift ( $ scope ) ) !== null ) { if ( $ bit === '_parent' || $ bit === '_' ) { array_pop ( $ this -> scopeTree ) ; reset ( $ this -> scopeTree ) ; $ this -> scope = & $ this -> data ; $ cnt = count ( $ this -> scopeTree ) ; for ( $ i = 0 ; $ i < $ cnt ; $ i ++ ) $ this -> scope = & $ this -> scope [ $ this -> scopeTree [ $ i ] ] ; } elseif ( $ bit === '_root' || $ bit === '__' ) { $ this -> scope = & $ this -> data ; $ this -> scopeTree = array ( ) ; } elseif ( isset ( $ this -> scope [ $ bit ] ) ) { $ this -> scope = & $ this -> scope [ $ bit ] ; $ this -> scopeTree [ ] = $ bit ; } else { $ this -> scope [ $ bit ] = array ( ) ; $ this -> scope = & $ this -> scope [ $ bit ] ; $ this -> scopeTree [ ] = $ bit ; } } return $ old ; }
|
sets the scope
|
8,896
|
public function addBlock ( $ type , array $ params , $ paramtype ) { $ class = 'Dwoo_Plugin_' . $ type ; if ( class_exists ( $ class , false ) === false ) { $ this -> dwoo -> getLoader ( ) -> loadPlugin ( $ type ) ; } $ params = $ this -> mapParams ( $ params , array ( $ class , 'init' ) , $ paramtype ) ; $ this -> stack [ ] = array ( 'type' => $ type , 'params' => $ params , 'custom' => false , 'class' => $ class , 'buffer' => null ) ; $ this -> curBlock = & $ this -> stack [ count ( $ this -> stack ) - 1 ] ; return call_user_func ( array ( $ class , 'preProcessing' ) , $ this , $ params , '' , '' , $ type ) ; }
|
adds a block to the top of the block stack
|
8,897
|
public function injectBlock ( $ type , array $ params ) { $ class = 'Dwoo_Plugin_' . $ type ; if ( class_exists ( $ class , false ) === false ) { $ this -> dwoo -> getLoader ( ) -> loadPlugin ( $ type ) ; } $ this -> stack [ ] = array ( 'type' => $ type , 'params' => $ params , 'custom' => false , 'class' => $ class , 'buffer' => null ) ; $ this -> curBlock = & $ this -> stack [ count ( $ this -> stack ) - 1 ] ; }
|
injects a block at the top of the plugin stack without calling its preProcessing method
|
8,898
|
public function removeBlock ( $ type ) { $ output = '' ; $ pluginType = $ this -> getPluginType ( $ type ) ; if ( $ pluginType & Dwoo :: SMARTY_BLOCK ) { $ type = 'smartyinterface' ; } while ( true ) { while ( $ top = array_pop ( $ this -> stack ) ) { if ( $ top [ 'custom' ] ) { $ class = $ top [ 'class' ] ; } else { $ class = 'Dwoo_Plugin_' . $ top [ 'type' ] ; } if ( count ( $ this -> stack ) ) { $ this -> curBlock = & $ this -> stack [ count ( $ this -> stack ) - 1 ] ; $ this -> push ( call_user_func ( array ( $ class , 'postProcessing' ) , $ this , $ top [ 'params' ] , '' , '' , $ top [ 'buffer' ] ) , 0 ) ; } else { $ null = null ; $ this -> curBlock = & $ null ; $ output = call_user_func ( array ( $ class , 'postProcessing' ) , $ this , $ top [ 'params' ] , '' , '' , $ top [ 'buffer' ] ) ; } if ( $ top [ 'type' ] === $ type ) { break 2 ; } } throw new Dwoo_Compilation_Exception ( $ this , 'Syntax malformation, a block of type "' . $ type . '" was closed but was not opened' ) ; break ; } return $ output ; }
|
removes the closest - to - top block of the given type and all other blocks encountered while going down the block stack
|
8,899
|
public function & findBlock ( $ type , $ closeAlong = false ) { if ( $ closeAlong === true ) { while ( $ b = end ( $ this -> stack ) ) { if ( $ b [ 'type' ] === $ type ) { return $ this -> stack [ key ( $ this -> stack ) ] ; } $ this -> push ( $ this -> removeTopBlock ( ) , 0 ) ; } } else { end ( $ this -> stack ) ; while ( $ b = current ( $ this -> stack ) ) { if ( $ b [ 'type' ] === $ type ) { return $ this -> stack [ key ( $ this -> stack ) ] ; } prev ( $ this -> stack ) ; } } throw new Dwoo_Compilation_Exception ( $ this , 'A parent block of type "' . $ type . '" is required and can not be found' ) ; }
|
returns a reference to the first block of the given type encountered and optionally closes all blocks until it finds it
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.