idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
1,900
protected function addFormatter ( & $ manager , $ model , $ formatter ) { $ config = ( include $ this -> configPath . '/' . $ model . '.php' ) ; if ( ! isset ( $ config [ $ formatter ] ) ) return ; $ formatterClass = 'kriskbx\mikado\Formatters\\' . $ formatter ; if ( is_array ( $ config [ $ formatter ] ) && count ( $ config [ $ formatter ] ) > 0 ) { $ manager -> add ( new $ formatterClass ( $ config [ $ formatter ] ) ) ; } }
Add formatter to manager .
1,901
protected function isJson ( $ string ) { if ( ! is_string ( $ string ) || is_numeric ( $ string ) ) { return false ; } $ result = @ json_decode ( $ string ) ; return ( json_last_error ( ) == JSON_ERROR_NONE ) ; }
Check to see if a string is JSON .
1,902
public static function fetchSettings ( $ environment = null , $ website_id = null , $ group = 'config' ) { $ model = static :: where ( 'group' , '=' , $ group ) ; $ model -> where ( function ( $ query ) use ( $ environment ) { if ( empty ( $ environment ) ) { $ query -> whereNull ( 'environment' ) ; } else { $ query -> where ( 'environment' , '=' , $ environment ) -> orWhereNull ( 'environment' ) ; } } ) ; $ model -> where ( function ( $ query ) use ( $ website_id ) { if ( empty ( $ website_id ) ) { $ query -> whereNull ( 'website_id' ) ; } else { $ query -> where ( 'website_id' , '=' , $ website_id ) -> orWhereNull ( 'website_id' ) ; } } ) ; $ model -> orderBy ( DB :: raw ( 'CASE WHEN website_id IS NOT NULL AND environment IS NOT NULL THEN 1 WHEN website_id IS NOT NULL THEN 2 WHEN environment IS NOT NULL THEN 3 ELSE 4 END' ) ) ; $ collection = $ model -> get ( ) ; return static :: normaliseCollection ( $ collection ) ; }
Return the configuration data for a specific environment & group .
1,903
public static function fetchExactSettings ( $ environment = null , $ website_id = null , $ group = 'config' ) { $ model = static :: where ( 'group' , '=' , $ group ) ; $ model -> where ( function ( $ query ) use ( $ environment ) { if ( empty ( $ environment ) ) { $ query -> whereNull ( 'environment' ) ; } else { $ query -> where ( 'environment' , '=' , $ environment ) ; } } ) ; $ model -> where ( function ( $ query ) use ( $ website_id ) { if ( empty ( $ website_id ) ) { $ query -> whereNull ( 'website_id' ) ; } else { $ query -> where ( 'website_id' , '=' , $ website_id ) ; } } ) ; $ collection = $ model -> get ( ) ; return static :: normaliseCollection ( $ collection ) ; }
Return the exact configuration data for a specific environment & group .
1,904
public static function fetchAllGroups ( ) { $ model = new self ; $ result = [ ] ; try { foreach ( $ model -> select ( 'group' ) -> distinct ( ) -> get ( ) as $ row ) { $ result [ ] = $ row -> group ; } } catch ( \ Exception $ e ) { } return $ result ; }
Return an array of all groups .
1,905
public static function set ( $ key , $ value , $ group = 'config' , $ environment = null , $ website_id = null , $ type = 'string' ) { $ arrayHandling = false ; $ keyExploded = explode ( '.' , $ key ) ; if ( count ( $ keyExploded ) > 1 ) { $ arrayHandling = true ; $ key = array_shift ( $ keyExploded ) ; if ( $ type == 'array' ) { $ value = static :: getValueAttribute ( $ value ) ; } } $ model = static :: where ( 'key' , '=' , $ key ) -> where ( 'group' , '=' , $ group ) ; if ( empty ( $ environment ) ) { $ model -> whereNull ( 'environment' ) ; } else { $ model -> where ( 'environment' , '=' , $ environment ) ; } if ( empty ( $ website_id ) ) { $ model -> whereNull ( 'website_id' ) ; } else { $ model -> where ( 'website_id' , '=' , $ website_id ) ; } $ model = $ model -> first ( ) ; if ( empty ( $ model ) ) { if ( $ arrayHandling ) { $ array = [ ] ; self :: buildArrayPath ( $ keyExploded , $ value , $ array ) ; $ value = $ array ; $ type = 'array' ; } return static :: create ( [ 'website_id' => $ website_id , 'environment' => $ environment , 'group' => $ group , 'key' => $ key , 'value' => $ value , 'type' => $ type , ] ) ; } if ( $ arrayHandling ) { $ array = [ ] ; self :: buildArrayPath ( $ keyExploded , $ value , $ array ) ; if ( $ model -> type == 'array' && ! empty ( $ model -> value ) ) { $ array = array_replace_recursive ( $ model -> value , $ array ) ; } $ value = $ array ; $ type = 'array' ; } $ model -> value = $ value ; $ model -> type = $ type ; $ model -> save ( ) ; return $ model ; }
Store a group of settings into the database .
1,906
protected static function buildArrayPath ( $ map , $ value , & $ array ) { $ key = array_shift ( $ map ) ; if ( count ( $ map ) !== 0 ) { $ array [ $ key ] = [ ] ; self :: buildArrayPath ( $ map , $ value , $ array [ $ key ] ) ; } else { $ array [ $ key ] = $ value ; } }
This inserts a value into an array at a point in the array path .
1,907
public function getColumnContent ( $ gridField , $ record , $ columnName ) { if ( ! DataObject :: has_extension ( $ gridField -> getModelClass ( ) , Versioned :: class ) ) { user_error ( $ gridField -> getModelClass ( ) . ' does not have the Versioned extension' , E_USER_WARNING ) ; return ; } $ isDeletedFromDraft = ( ! $ record -> hasMethod ( 'isOnDraft' ) ? $ record -> isOnLiveOnly ( ) : ! $ record -> isOnDraft ( ) ) ; if ( $ gridField -> State -> ListDisplayMode -> ShowDeletedItems == 'Y' && $ isDeletedFromDraft ) { return ; } return parent :: getColumnContent ( $ gridField , $ record , $ columnName ) ; }
Gets the content for the column this basically says if it s deleted from the stage you can t delete it
1,908
public function tokenize ( $ httpField , $ fromField ) { $ quoteSeparators = array ( '"' , "'" ) ; $ tokenList = array ( ) ; $ stringAccumulator = '' ; $ lastQuote = '' ; for ( $ i = 0 ; $ i < strlen ( $ httpField ) ; $ i ++ ) { $ chr = substr ( $ httpField , $ i , 1 ) ; switch ( true ) { case $ chr === $ lastQuote : $ tokenList [ ] = $ stringAccumulator ; $ stringAccumulator = '' ; $ lastQuote = '' ; break ; case in_array ( $ chr , $ quoteSeparators ) : $ lastQuote = $ chr ; break ; case strlen ( $ lastQuote ) : $ stringAccumulator .= $ chr ; break ; case Tokens :: isSeparator ( $ chr , Preference :: MIME === $ fromField ) : if ( strlen ( $ stringAccumulator ) ) { $ tokenList [ ] = $ stringAccumulator ; $ stringAccumulator = '' ; } $ tokenList [ ] = $ chr ; break ; default : $ stringAccumulator .= $ chr ; break ; } } if ( strlen ( $ stringAccumulator ) ) { $ tokenList [ ] = $ stringAccumulator ; } $ tokenList = array_map ( 'trim' , $ tokenList ) ; return $ tokenList ; }
Tokenize the HTTP field for subsequent processing .
1,909
private function _getRequiredVars ( $ template_identifier ) { if ( ! ( isset ( $ this -> _available_templates [ $ template_identifier ] ) ) ) { trigger_error ( "Template identifier not found." , E_USER_ERROR ) ; } $ template_path = ROOT_PATH . '/' . $ this -> _available_templates [ $ template_identifier ] ; if ( ! ( $ template_source = file_get_contents ( $ template_path ) ) ) { trigger_error ( "{$template_path} not found." , E_USER_ERROR ) ; } if ( ! ( preg_match_all ( '/{.*\$([a-z_\-]*).*}/' , $ template_source , $ matchs ) ) ) { trigger_error ( "Not found in use vars in the tpl source." , E_USER_WARNING ) ; } $ required_vars = array_unique ( $ matchs [ 1 ] ) ; unset ( $ required_vars [ array_search ( 'url' , $ required_vars ) ] ) ; return $ required_vars ; }
Return the found in use vars in tpl .
1,910
private function createInstaller ( ) { $ this -> say ( "Creating package installer" ) ; $ sourceFolder = $ this -> getSourceFolder ( ) . "/administrator/manifests/packages" ; $ targetFolder = $ this -> getBuildFolder ( ) . "/administrator/manifests/packages" ; $ xmlFile = $ targetFolder . "/pkg_" . $ this -> getExtensionName ( ) . ".xml" ; $ scriptFile = $ targetFolder . "/" . $ this -> getExtensionName ( ) . "/script.php" ; $ this -> _copy ( $ sourceFolder . "/pkg_" . $ this -> getExtensionName ( ) . ".xml" , $ xmlFile ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( array ( '##DATE##' , '##YEAR##' , '##VERSION##' ) ) -> to ( array ( $ this -> getDate ( ) , date ( 'Y' ) , $ this -> getJConfig ( ) -> version ) ) -> run ( ) ; if ( is_file ( $ sourceFolder . "/" . $ this -> getExtensionName ( ) . "/script.php" ) ) { $ this -> _copy ( $ sourceFolder . "/" . $ this -> getExtensionName ( ) . "/script.php" , $ scriptFile ) ; $ this -> taskReplaceInFile ( $ scriptFile ) -> from ( array ( '##DATE##' , '##YEAR##' , '##VERSION##' ) ) -> to ( array ( $ this -> getDate ( ) , date ( 'Y' ) , $ this -> getJConfig ( ) -> version ) ) -> run ( ) ; } $ f = $ this -> generateLanguageFileList ( $ this -> getFiles ( 'frontendLanguage' ) ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( '##LANGUAGE_FILES##' ) -> to ( $ f ) -> run ( ) ; }
Generate the installer xml file for the package
1,911
public static function getConfiguration ( ) { if ( self :: $ configuration === null && file_exists ( self :: $ configFilePath ) ) { $ settings = include __DIR__ . '/../../config/configuration.php' ; self :: $ configuration = DWDUtil :: array_to_object ( $ settings ) ; if ( DWDConfiguration :: $ configuration === null ) throw new ParseError ( 'Error, configuration file could not be found or contains invalid lines.' ) ; } return DWDConfiguration :: $ configuration ; }
Returns the complete configuration file to the callee
1,912
public function getValidInput ( $ clean = false ) { $ input = array_dot ( $ this -> all ( ) ) ; $ rules = array_keys ( $ this -> rules ( ) ) ; $ keys = collect ( $ rules ) -> map ( function ( string $ rule ) use ( $ input ) { $ regex = '/^' . str_replace ( [ '.' , '*' ] , [ '\.' , '(.*)' ] , $ rule ) . '$/' ; return preg_grep ( $ regex , array_keys ( $ input ) ) ; } ) ; $ input = array_only ( $ input , $ keys -> flatten ( ) -> toArray ( ) ) ; $ expanded = [ ] ; foreach ( $ input as $ key => $ value ) { array_set ( $ expanded , $ key , $ value ) ; } if ( $ clean ) { $ expanded = $ this -> sanitizeInput ( $ expanded ) ; } return $ expanded ; }
Get validated user input .
1,913
public function sanitizeInput ( array $ input ) { return $ input = collect ( $ input ) -> reject ( function ( $ value ) { return is_null ( $ value ) || empty ( $ value ) ; } ) -> toArray ( ) ; }
Remove null and empty values from the input .
1,914
public function instance ( $ name ) { if ( empty ( $ this -> instances [ $ name ] ) ) { if ( empty ( $ this -> aliases [ $ name ] ) ) { $ this -> aliasDefault ( $ name ) ; } $ this -> instances [ $ name ] = new $ this -> aliases [ $ name ] ; } return $ this -> instances [ $ name ] ; }
Get the callable for an Underscore method alias .
1,915
public function alias ( $ name , $ spec ) { if ( is_callable ( $ spec ) ) { $ this -> instances [ $ name ] = $ spec ; } else { $ this -> aliases [ $ name ] = $ spec ; unset ( $ this -> instances [ $ name ] ) ; } }
Alias method name to a callable .
1,916
private function aliasDefault ( $ name ) { $ spec = sprintf ( '\Underscore\Mutator\%sMutator' , ucfirst ( $ name ) ) ; if ( ! class_exists ( $ spec ) ) { $ spec = sprintf ( '\Underscore\Accessor\%sAccessor' , ucfirst ( $ name ) ) ; } if ( ! class_exists ( $ spec ) ) { $ spec = sprintf ( '\Underscore\Initializer\%sInitializer' , ucfirst ( $ name ) ) ; } if ( ! class_exists ( $ spec ) ) { throw new \ BadMethodCallException ( sprintf ( 'Unknown method Underscore->%s()' , $ name ) ) ; } $ this -> aliases [ $ name ] = $ spec ; }
Define a default mutator accessor or initializer for a method name .
1,917
public function refresh ( ) { $ response = $ this -> client -> get ( $ this -> path ( ) ) ; $ this -> setData ( $ response -> json ( ) ) ; }
Refresh the Command Info
1,918
protected function addCheck ( $ name , $ type , $ args ) { $ func = $ type . 'Check' ; if ( method_exists ( $ this , $ func ) ) { $ type = strtolower ( str_replace ( $ type , '' , $ name ) ) ; $ this -> $ func ( $ type , $ name , $ args ) ; } else { throw new \ InvalidArgumentException ( 'Invalid check type: ' . $ type ) ; } }
Add a new check to the set
1,919
public static function load ( $ dslString ) { $ policy = self :: instance ( ) ; $ parts = explode ( '||' , $ dslString ) ; foreach ( $ parts as $ match ) { $ args = [ ] ; list ( $ method , $ value ) = explode ( ':' , $ match ) ; if ( preg_match ( '/:\((.+?)\)/' , $ match , $ matches ) > 0 ) { if ( isset ( $ matches [ 1 ] ) ) { $ value = explode ( ',' , $ matches [ 1 ] ) ; } } $ args [ ] = $ value ; if ( preg_match ( '/\[(.+?)\]$/' , $ match , $ matches ) > 0 ) { if ( isset ( $ matches [ 1 ] ) ) { $ args [ ] = strtolower ( $ matches [ 1 ] ) ; } } call_user_func_array ( [ $ policy , $ method ] , $ args ) ; } return $ policy ; }
Load a policy from a string DSL See the README for formatting
1,920
private function check ( $ matchType , $ type , $ name , $ args ) { $ value = array_shift ( $ args ) ; if ( ! isset ( $ args [ 0 ] ) ) { $ args [ 0 ] = [ 'rule' => Policy :: ANY ] ; } if ( is_string ( $ args [ 0 ] ) && ( $ args [ 0 ] === Policy :: ANY || $ args [ 0 ] === Policy :: ALL ) ) { $ args [ 'rule' ] = $ args [ 0 ] ; unset ( $ args [ 0 ] ) ; } elseif ( is_array ( $ args [ 0 ] ) ) { $ args = $ args [ 0 ] ; } $ this -> checks [ $ type ] [ ] = new Check ( $ matchType , $ value , $ args ) ; }
Add a new check to the current set for the policy
1,921
private function cannotCheck ( $ type , $ name , $ args ) { if ( isset ( $ args [ 0 ] ) && ( is_object ( $ args [ 0 ] ) && get_class ( $ args [ 0 ] ) === 'Closure' ) ) { $ type = 'closure' ; $ args [ 1 ] = $ args [ 0 ] ; } elseif ( is_string ( $ args [ 0 ] ) && strpos ( $ args [ 0 ] , '::' ) !== false ) { $ type = 'method' ; } $ this -> check ( 'not-equals' , $ type , $ name , $ args ) ; }
Add a cannot check to the set
1,922
public static function add ( $ method , $ target , $ handler , $ name = null ) { array_push ( static :: $ prefixRoutes , [ 'method' => $ method , 'target' => $ target , 'handler' => $ handler , 'name' => $ name , ] ) ; }
Support method to add group of routes .
1,923
public static function group ( $ prefix , Closure $ callback ) { $ callback -> call ( new static ( ) ) ; foreach ( static :: $ prefixRoutes as $ key => $ prefixRoute ) { $ target = $ prefix . $ prefixRoute [ 'target' ] ; $ handler = $ prefixRoute [ 'handler' ] ; $ name = $ prefixRoute [ 'name' ] ; unset ( static :: $ prefixRoutes [ $ key ] ) ; call_user_func_array ( [ new static ( ) , strtolower ( $ prefixRoute [ 'method' ] ) ] , [ $ target , $ handler , $ name ] ) ; } }
Route Group .
1,924
public static function resource ( $ target , $ handler ) { $ route = $ target ; $ sanitized = str_replace ( '/' , '' , $ target ) ; static :: get ( $ route , $ handler . '@index' , $ sanitized . '_index' ) ; static :: get ( $ target . '/create' , $ handler . '@showCreateForm' , $ sanitized . '_create_form' ) ; static :: post ( $ target , $ handler . '@save' , $ sanitized . '_save' ) ; static :: get ( $ target . '/[i:id]' , $ handler . '@show' , $ sanitized . '_display' ) ; static :: get ( $ target . '/[i:id]/edit' , $ handler . '@showEditForm' , $ sanitized . '_edit_form' ) ; static :: post ( $ target . '/[i:id]' , $ handler . '@update' , $ sanitized . '_update' ) ; static :: get ( $ target . '/[i:id]/delete' , $ handler . '@delete' , $ sanitized . '_delete' ) ; }
Create a Rest Resource .
1,925
function file_save_data ( $ data , $ destination = NULL , $ replace = FILE_EXISTS_RENAME ) { return file_save_data ( $ data , $ destination , $ replace ) ; }
Saves a file to the specified destination and creates a database entry .
1,926
public function execute ( InputInterface $ input , OutputInterface $ output ) { chdir ( 'public' ) ; if ( $ input -> hasOption ( 'hostname' ) && $ input -> getOption ( 'hostname' ) != null ) { $ this -> hostname = $ input -> getOption ( 'hostname' ) ; } if ( $ input -> hasOption ( 'port' ) && $ input -> getOption ( 'port' ) != null ) { $ this -> port = $ input -> getOption ( 'port' ) ; } if ( $ input -> hasOption ( 'path' ) && $ input -> getOption ( 'path' ) != null ) { $ this -> phpexec = $ input -> getOption ( 'path' ) ; } $ output -> writeln ( '<info>Legato development server started</info>' ) ; $ output -> writeln ( "<info>Open your browser and navigate to: </info> <http://{$this->hostname}:{$this->port}>" ) ; $ output -> writeln ( '<info>CTRL C to quit </info>' ) ; passthru ( $ this -> startPHP ( ) ) ; }
You command logic .
1,927
public function offsetSet ( $ index , $ value ) : void { if ( ! is_object ( $ value ) ) { throw new \ InvalidArgumentException ( "Excepcted object, got " . gettype ( $ value ) ) ; } if ( ! isset ( $ this -> class ) ) { $ this -> class = get_class ( $ value ) ; } if ( get_class ( $ value ) === $ this -> class ) { parent :: offsetSet ( $ index , $ value ) ; } else { throw new \ InvalidArgumentException ( "Excepcted $this->class, got " . get_class ( $ value ) ) ; } }
Sets the value at the specified index to value if value s class matches the one set . If a class has not been set it will set the given object s class as the only allowed class .
1,928
private function formatParameter ( ReflectionParameter $ parameter ) : string { return $ parameter -> hasType ( ) ? sprintf ( '%s $%s' , $ parameter -> getType ( ) , $ parameter -> getName ( ) ) : sprintf ( '$%s' , $ parameter -> getName ( ) ) ; }
Formats parameter depending on type
1,929
public function controller ( ) { if ( $ this -> restful ) { return filesystem ( ) -> exists ( realpath ( __DIR__ . '/../../../../../app/controllers' ) ) ? realpath ( __DIR__ . '/../Templates/controller/restful.stub' ) : realpath ( __DIR__ . '/../Templates/controller/restful.core.stub' ) ; } return filesystem ( ) -> exists ( realpath ( __DIR__ . '/../../../../../app/controllers' ) ) ? realpath ( __DIR__ . '/../Templates/controller/plain.stub' ) : realpath ( __DIR__ . '/../Templates/controller/core.stub' ) ; }
Get the template for creating a controller .
1,930
public static function parseComments ( $ comments ) { $ ret = [ ] ; $ comments = str_replace ( array ( '/*' , '*' , '**' ) , '' , $ comments ) ; $ array_comments = explode ( "\n" , $ comments ) ; foreach ( $ array_comments as $ k => $ line ) { $ line = trim ( $ line ) ; if ( self :: startsWith ( $ line , "@" ) ) { $ params = explode ( " " , $ line ) ; $ c = trim ( str_replace ( "@" , "" , array_shift ( $ params ) ) ) ; $ ret [ $ c ] = $ params ; } } return $ ret ; }
Parse comment used only when generate php
1,931
public function applyConclusiveMatch ( $ userAgent ) { $ tolerance = Utils :: firstCloseParen ( $ userAgent ) ; return $ this -> getDeviceIDFromRIS ( $ userAgent , $ tolerance ) ; }
If UA starts with Mozilla apply LD with tollerance 5 .
1,932
public function getImageData ( ) { if ( $ this -> imageData === null ) { $ this -> imageData = $ this -> download ( $ this -> url ) ; } return $ this -> imageData ; }
Returns the complete image data wherever it may have come from .
1,933
public function read ( $ params , $ data , $ key = false , $ single = false ) { global $ smcFunc ; $ dataResult = [ ] ; $ query = $ smcFunc [ 'db_query' ] ( '' , ' SELECT ' . $ params [ 'rows' ] . ' FROM {db_prefix}' . $ params [ 'table' ] . ' ' . ( ! empty ( $ params [ 'join' ] ) ? 'LEFT JOIN ' . $ params [ 'join' ] : '' ) . ' ' . ( ! empty ( $ params [ 'where' ] ) ? 'WHERE ' . $ params [ 'where' ] : '' ) . ' ' . ( ! empty ( $ params [ 'and' ] ) ? 'AND ' . $ params [ 'and' ] : '' ) . ' ' . ( ! empty ( $ params [ 'andTwo' ] ) ? 'AND ' . $ params [ 'andTwo' ] : '' ) . ' ' . ( ! empty ( $ params [ 'order' ] ) ? 'ORDER BY ' . $ params [ 'order' ] : '' ) . ' ' . ( ! empty ( $ params [ 'limit' ] ) ? 'LIMIT ' . $ params [ 'limit' ] : '' ) . '' , $ data ) ; if ( ! empty ( $ single ) ) while ( $ row = $ smcFunc [ 'db_fetch_assoc' ] ( $ query ) ) $ dataResult = $ row ; elseif ( ! empty ( $ key ) && empty ( $ single ) ) while ( $ row = $ smcFunc [ 'db_fetch_assoc' ] ( $ query ) ) $ dataResult [ $ row [ $ key ] ] = $ row ; elseif ( empty ( $ single ) && empty ( $ key ) ) while ( $ row = $ smcFunc [ 'db_fetch_assoc' ] ( $ query ) ) $ dataResult [ ] = $ row ; $ smcFunc [ 'db_free_result' ] ( $ query ) ; return $ dataResult ; }
Reads data from a table .
1,934
public function delete ( $ value , $ table = '' , $ column = '' ) { global $ smcFunc ; if ( empty ( $ id ) || empty ( $ table ) || empty ( $ column ) ) return false ; return $ smcFunc [ 'db_query' ] ( '' , ' DELETE FROM {db_prefix}' . ( $ table ) . ' WHERE ' . ( $ column ) . ' = ' . ( $ value ) . '' , array ( ) ) ; }
Deletes an entry from X table .
1,935
public function load ( ) { $ data = [ ] ; if ( is_file ( $ this -> filePath ) ) { $ data = json_decode ( file_get_contents ( $ this -> filePath ) , true ) ; } return $ data ; }
Prepare the data for driver operations
1,936
public function setInput ( $ input ) { $ this -> input = preg_replace ( "/\r\n|\r/" , "\n" , $ input ) ; $ this -> lineno = 1 ; $ this -> deferred = array ( ) ; $ this -> indentStack = array ( ) ; $ this -> stash = array ( ) ; }
Set lexer input .
1,937
protected function scan ( $ regex , $ type ) { if ( preg_match ( $ regex , $ this -> input , $ matches ) ) { $ this -> consume ( $ matches [ 0 ] ) ; return $ this -> token ( $ type , isset ( $ matches [ 1 ] ) && mb_strlen ( $ matches [ 1 ] ) > 0 ? $ matches [ 1 ] : '' ) ; } }
Helper to create tokens
1,938
public function lookahead ( $ number = 1 ) { $ fetch = $ number - count ( $ this -> stash ) ; while ( $ fetch -- > 0 ) { $ this -> stash [ ] = $ this -> next ( ) ; } return $ this -> stash [ -- $ number ] ; }
Lookahead token n .
1,939
protected function scanEOS ( ) { if ( ! $ this -> length ( ) ) { if ( count ( $ this -> indentStack ) ) { array_shift ( $ this -> indentStack ) ; return $ this -> token ( 'outdent' ) ; } return $ this -> token ( 'eos' ) ; } }
Scan EOS from input & return it if found .
1,940
protected function scanComment ( ) { if ( preg_match ( '/^ *\/\/(-)?([^\n]*)/' , $ this -> input , $ matches ) ) { $ this -> consume ( $ matches [ 0 ] ) ; $ token = $ this -> token ( 'comment' , isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : '' ) ; $ token -> buffer = '-' !== $ matches [ 1 ] ; return $ token ; } }
Scan comment from input & return it if found .
1,941
public static function isConstraintsValidationEnabled ( $ objectClasses , $ annotationReader ) { $ enabled = Configuration :: isConstraintsValidationEnabled ( ) ; foreach ( $ objectClasses as $ class ) { if ( $ annotationReader -> getClassAnnotation ( $ class , self :: $ disableConstraintsValidationAnnotationClass ) !== null ) { $ enabled = false ; break ; } if ( $ annotationReader -> getClassAnnotation ( $ class , self :: $ enableConstraintsValidationAnnotationClass ) !== null ) { $ enabled = true ; break ; } } return $ enabled ; }
Indicates wether the constraints validation is enabled or not for the given object .
1,942
public static function validatePropertyValue ( $ object , $ property , $ value ) { return Configuration :: getConstraintsValidator ( ) -> validatePropertyValue ( $ object , $ property , $ value ) ; }
Validates the given value compared to given property constraints . If the value is valid a call to count to the object returned by this method should give 0 .
1,943
protected function onBeforeWrite ( ) { parent :: onBeforeWrite ( ) ; $ this -> Content = str_replace ( '&#13;' , '' , $ this -> Content ) ; $ formatter = $ this -> getFormatter ( ) ; $ formatter -> analyseSavedContent ( $ this ) ; if ( ! $ this -> WikiLockExpiry ) { $ this -> WikiLockExpiry = date ( 'Y-m-d H:i:s' ) ; } if ( Member :: currentUser ( ) ) { $ this -> WikiLastEditor = Member :: currentUser ( ) -> Email ; } }
Before writing convert any page links to appropriate new non - published pages
1,944
public function getCMSFields ( ) { $ fields = parent :: getCMSFields ( ) ; $ options = $ this -> getEditorTypeOptions ( ) ; $ fields -> addFieldToTab ( 'Root.Behaviour' , new OptionsetField ( 'EditorType' , _t ( 'WikiPage.EDITORTYPE' , 'Editor Type' ) , $ options ) ) ; $ formatter = $ this -> getFormatter ( ) ; if ( $ formatter ) { $ formatter -> updateCMSFields ( $ fields ) ; } return $ fields ; }
Get the CMS fields
1,945
public function getActualEditorType ( ) { if ( $ this -> EditorType && $ this -> EditorType != 'Inherit' ) { return $ this -> EditorType ; } $ parent = $ this -> getParent ( ) ; $ editorType = 'Wiki' ; while ( $ parent != null && $ parent instanceof WikiPage ) { if ( $ parent -> EditorType && $ parent -> EditorType != 'Inherit' ) { return $ parent -> EditorType ; } $ parent = $ parent -> getParent ( ) ; } return 'Wiki' ; }
Return the editor type to use for this item . Will interrogate parents if needbe
1,946
public function getFormatter ( $ formatter = null ) { if ( ! $ formatter ) { $ formatter = $ this -> getActualEditorType ( ) ; } if ( ! isset ( self :: $ registered_formatters [ $ formatter ] ) ) { throw new Exception ( "Formatter $formatter does not exist" ) ; } return self :: $ registered_formatters [ $ formatter ] ; }
Gets the formatter for a given type . If none specified gets the current formatter
1,947
public function ParsedContent ( ) { $ formatter = $ this -> getFormatter ( ) ; $ content = $ formatter -> formatContent ( $ this ) ; if ( self :: $ purify_output ) { include_once SIMPLEWIKI_DIR . '/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier.auto.php' ; $ purifier = new HTMLPurifier ( ) ; $ content = $ purifier -> purify ( $ content ) ; $ content = preg_replace_callback ( '/\%5B(.*?)\%5D/' , array ( $ this , 'reformatShortcodes' ) , $ content ) ; } return $ content ; }
Retrieves the page s content passed through any necessary parsing eg Wiki based content
1,948
public function getWikiRoot ( ) { $ current = $ this ; $ parent = $ current -> Parent ( ) ; while ( $ parent instanceof WikiPage ) { $ current = $ parent ; $ parent = $ current -> Parent ( ) ; } return $ current ; }
Get the root of the wiki that this wiki page exists in
1,949
public function lock ( $ member = null ) { if ( ! $ member ) { $ member = Member :: currentUser ( ) ; } $ this -> WikiLastEditor = $ member -> Email ; $ this -> WikiLockExpiry = date ( 'Y-m-d H:i:s' , time ( ) + $ this -> config ( ) -> get ( 'lock_time' ) ) ; $ this -> write ( ) ; }
Lock the page for the current user
1,950
public function edit ( ) { HtmlEditorField :: include_js ( ) ; $ existing = $ this -> getEditingLocks ( $ this -> data ( ) , true ) ; if ( $ existing && $ existing [ 'user' ] != Member :: currentUser ( ) -> Email ) { return $ this -> redirect ( $ this -> data ( ) -> Link ( ) ) ; } if ( ! $ this -> data ( ) -> canEdit ( ) ) { return Security :: permissionFailure ( $ this ) ; } $ this -> form = $ this -> EditForm ( ) ; return $ this -> renderWith ( array ( 'WikiPage' , 'Page' ) ) ; }
Action handler for editing this wiki page
1,951
public function EditForm ( ) { $ record = DataObject :: get_by_id ( 'WikiPage' , $ this -> data ( ) -> ID ) ; $ formatter = $ record -> getFormatter ( ) ; $ editorField = $ formatter -> getEditingField ( $ record ) ; $ helpLink = $ formatter -> getHelpUrl ( ) ; $ fields = FieldList :: create ( new LiteralField ( 'Preview' , '<div data-url="' . $ this -> Link ( 'livepreview' ) . '" id="editorPreview"></div>' ) , new LiteralField ( 'DialogContent' , '<div id="dialogContent" style="display:none;"></div>' ) , $ editorField , new DropdownField ( 'EditorType' , _t ( 'WikiPage.EDITORTYPE' , 'Editor Type' ) , $ this -> data ( ) -> getEditorTypeOptions ( ) ) , new HiddenField ( 'LockUpdate' , '' , $ this -> data ( ) -> Link ( 'updatelock' ) ) , new HiddenField ( 'LockLength' , '' , $ this -> config ( ) -> get ( 'lock_time' ) - 10 ) ) ; if ( $ helpLink ) { $ fields -> push ( new LiteralField ( 'HelpLink' , '<a target="_blank" href="' . $ helpLink . '">' . _t ( 'WikiPage.EDITOR_HELP_LINK' , 'Editor Help' ) . '</a>' ) ) ; } $ actions = null ; if ( ! WikiPage :: $ auto_publish ) { $ actions = FieldList :: create ( new FormAction ( 'save' , _t ( 'WikiPage.SAVE' , 'Save' ) ) , new FormAction ( 'done' , _t ( 'WikiPage.DONE' , 'Done (Draft)' ) ) , new FormAction ( 'publish' , _t ( 'WikiPage.PUBLISH' , 'Publish' ) ) ) ; } else { $ actions = FieldList :: create ( new FormAction ( 'save' , _t ( 'WikiPage.SAVE' , 'Save' ) ) , new FormAction ( 'publish' , _t ( 'WikiPage.FINISHED' , 'Finished' ) ) ) ; } $ actions -> push ( new FormAction ( 'cancel' , _t ( 'WikiPage.CANCEL_EDIT' , 'Cancel' ) ) ) ; $ actions -> push ( new FormAction ( 'revert' , _t ( 'WikiPage.REVERT_EDIT' , 'Revert' ) ) ) ; if ( Permission :: check ( MANAGE_WIKI_PAGES ) ) { $ actions -> push ( new FormAction ( 'addpage_t' , _t ( 'WikiPage.ADD_PAGE' , 'New Page' ) ) ) ; $ actions -> push ( new FormAction ( 'delete' , _t ( 'WikiPage.DELETE_PAGE' , 'Delete Page' ) ) ) ; } $ form = new Form ( $ this , "EditForm" , $ fields , $ actions ) ; $ form -> loadDataFrom ( $ record ) ; $ this -> extend ( 'updateWikiEditForm' , $ form ) ; return $ form ; }
Creates the form used for editing the page s content
1,952
public function revert ( ) { if ( $ this -> data ( ) -> IsModifiedOnStage ) { $ this -> data ( ) -> doRevertToLive ( ) ; } return $ this -> redirect ( $ this -> data ( ) -> Link ( ) . '?stage=Live' ) ; }
Option for the user to revert the changes made since it was last published
1,953
public function delete ( ) { $ page = $ this -> data ( ) ; if ( $ page ) { $ parent = $ page -> Parent ( ) ; $ ID = $ page -> ID ; $ page -> deleteFromStage ( 'Live' ) ; if ( WikiPage :: $ auto_publish ) { $ page -> ID = $ ID ; $ page -> deleteFromStage ( 'Stage' ) ; } return $ this -> redirect ( $ parent -> Link ( ) ) ; return ; } throw new Exception ( "Invalid request" ) ; }
Deletes the current page and returns the user to the parent of the now deleted page .
1,954
public function addpage ( $ args ) { if ( ! Permission :: check ( MANAGE_WIKI_PAGES ) ) { return Security :: permissionFailure ( $ this ) ; } $ pageName = trim ( $ args [ 'NewPageName' ] ) ; $ createType = $ args [ 'CreateType' ] ? $ args [ 'CreateType' ] : 'child' ; if ( ! strlen ( $ pageName ) ) { throw new Exception ( "Invalid page name" ) ; } $ createContext = $ this -> data ( ) ; if ( $ args [ 'CreateContext' ] ) { $ createContext = DataObject :: get_by_id ( 'WikiPage' , $ args [ 'CreateContext' ] ) ; } if ( ! $ createContext instanceof WikiPage ) { throw new Exception ( "You must select an existing wiki page." ) ; } $ page = new WikiPage ( ) ; $ page -> Title = $ pageName ; $ page -> MenuTitle = $ pageName ; switch ( $ createType ) { case 'sibling' : { $ page -> ParentID = $ createContext -> ParentID ; break ; } case 'child' : default : { $ page -> ParentID = $ createContext -> ID ; break ; } } $ page -> writeToStage ( 'Stage' ) ; if ( WikiPage :: $ auto_publish ) { $ page -> doPublish ( ) ; } return $ this -> redirect ( $ page -> Link ( 'edit' ) . '?stage=Stage' ) ; }
Creates an entirely new page as a child of the current page or after a selected page .
1,955
public function save ( $ data , $ form ) { if ( ! $ this -> data ( ) -> canEdit ( ) ) { return Security :: permissionFailure ( $ this ) ; } $ existing = $ this -> getEditingLocks ( $ this -> data ( ) , true ) ; if ( $ existing && $ existing [ 'user' ] != Member :: currentUser ( ) -> Email ) { return "Someone somehow locked it while you were gone, this shouldn't happen like this :(" ; } $ this -> savePage ( $ this -> data ( ) , $ form ) ; if ( WikiPage :: $ auto_publish ) { $ this -> data ( ) -> doPublish ( ) ; } return $ this -> redirect ( $ this -> data ( ) -> Link ( 'edit' ) . '?stage=Stage' ) ; }
Save the submitted data
1,956
public function Form ( ) { $ append = '' ; if ( ! $ this -> form ) { if ( WikiPage :: $ show_edit_button || $ this -> data ( ) -> canEdit ( ) ) { $ this -> form = $ this -> StatusForm ( ) ; } } else { if ( Permission :: check ( MANAGE_WIKI_PAGES ) ) { $ append = $ this -> CreatePageForm ( ) -> forTemplate ( ) ; } } return $ this -> form -> forTemplate ( ) . $ append ; }
Return the form to the user if it exists otherwise some information about who is currently editing
1,957
public function StatusForm ( ) { $ existing = $ this -> getEditingLocks ( $ this -> data ( ) ) ; if ( $ existing && $ existing [ 'user' ] != Member :: currentUser ( ) -> Email ) { $ fields = FieldList :: create ( new ReadonlyField ( 'ExistingEditor' , '' , _t ( 'WikiPage.EXISTINGEDITOR' , 'This page is currently locked for editing by ' . $ existing [ 'user' ] . ' until ' . $ existing [ 'expires' ] ) ) ) ; $ actions = FieldList :: create ( ) ; } else { $ fields = FieldList :: create ( ) ; $ actions = FieldList :: create ( new FormAction ( 'startediting' , _t ( 'WikiPage.STARTEDIT' , 'Edit Page' ) ) ) ; } return new Form ( $ this , 'StatusForm' , $ fields , $ actions ) ; }
Gets the status form that is used by users to trigger the editing mode if they have the relevant access to it .
1,958
public function updatelock ( $ data ) { if ( $ this -> data ( ) -> ID && $ this -> data ( ) -> canEdit ( ) ) { $ lock = $ this -> getEditingLocks ( $ this -> data ( ) , true ) ; $ response = new stdClass ( ) ; $ response -> status = 1 ; if ( $ lock != null && $ lock [ 'user' ] != Member :: currentUser ( ) -> Email ) { $ response -> status = 0 ; $ response -> message = _t ( 'WikiPage.LOCK_STOLEN' , "Another user (" . $ lock [ 'user' ] . ") has forcefully taken this lock" ) ; } return Convert :: raw2json ( $ response ) ; } }
Updates the lock timeout for the given object
1,959
protected function getEditingLocks ( $ page , $ doLock = false ) { $ currentStage = Versioned :: current_stage ( ) ; Versioned :: reading_stage ( 'Stage' ) ; $ filter = array ( 'WikiPage.ID' => $ page -> ID , 'WikiLockExpiry' => date ( 'Y-m-d H:i:s' ) , ) ; $ user = Member :: currentUser ( ) ; $ currentLock = WikiPage :: get ( ) -> filter ( $ filter ) -> first ( ) ; $ lock = null ; if ( $ currentLock && $ currentLock -> ID ) { $ lock = array ( 'user' => $ currentLock -> WikiLastEditor , 'expires' => $ currentLock -> WikiLockExpiry , ) ; } if ( $ doLock && ( $ currentLock == null || ! $ currentLock -> ID || $ currentLock -> WikiLastEditor == $ user -> Email ) ) { $ page -> lock ( ) ; } Versioned :: reading_stage ( $ currentStage ) ; return $ lock ; }
Lock the page for editing
1,960
public function objectdetails ( ) { $ response = new stdClass ; if ( isset ( $ _GET [ 'ID' ] ) ) { $ type = null ; if ( isset ( $ _GET [ 'type' ] ) ) { $ type = $ _GET [ 'type' ] == 'href' ? 'SiteTree' : 'File' ; } else { $ type = 'SiteTree' ; } $ object = DataObject :: get_by_id ( $ type , $ _GET [ 'ID' ] ) ; $ response -> Title = $ object -> Title ; $ response -> Link = $ object -> Link ( ) ; if ( $ object instanceof Image ) { $ response -> Name = $ object -> Name ; $ response -> Filename = $ object -> Filename ; $ response -> width = $ object -> getWidth ( ) ; $ response -> height = $ object -> getHeight ( ) ; } $ response -> error = 0 ; } else { $ response -> error = 1 ; $ response -> message = "Invalid image ID" ; } echo json_encode ( $ response ) ; }
Retrieves information about a selected image for the frontend image insertion tool - hacky for now ideally need to pull through the backend ImageForm
1,961
public function setValue ( string $ rawValue ) : void { if ( strlen ( $ rawValue ) < 8 ) { throw new PasswordPolicyException ( 'Password is too short@' . __METHOD__ ) ; } $ this -> rawValue = $ rawValue ; }
Set password value .
1,962
public function verify ( string $ hash ) : bool { if ( is_null ( $ this -> rawValue ) ) { return false ; } return password_verify ( $ this -> rawValue , $ hash ) ; }
Verify password hash
1,963
public function getParameterNames ( ) { if ( isset ( $ this -> parameterNames ) ) { return $ this -> parameterNames ; } return $ this -> parameterNames = $ this -> compileParameterNames ( ) ; }
Get all of the parameter names for the route .
1,964
public function getParameter ( $ name , $ default = null ) { try { return ArrayHelper :: get ( $ this -> getParameters ( ) , $ name , $ default ) ; } catch ( Exception $ ex ) { return $ default ; } }
Get a given parameter from the route .
1,965
protected function compileRoute ( ) { $ uri = preg_replace ( '/\{(\w+?)\?\}/' , '{$1}' , $ this -> uri ) ; $ this -> compiled = ( new SymfonyRoute ( $ uri , $ optionals = [ ] , $ requirements = [ ] , [ ] , $ domain = '' ) ) -> compile ( ) ; }
Compile the current route .
1,966
protected function runCallable ( ) { $ parameters = $ this -> resolveMethodDependencies ( $ this -> getParametersWithoutNulls ( ) , new ReflectionFunction ( $ this -> action [ 'uses' ] ) ) ; $ callable = $ this -> action [ 'uses' ] ; return call_user_func_array ( $ callable , $ parameters ) ; }
Run the route action as callable and return the response .
1,967
public function getBatchSerial ( $ namespace ) { if ( empty ( $ this -> serials [ $ namespace ] ) ) { $ batch = $ this -> getBatch ( $ namespace ) ; unset ( $ batch [ 'DefinitionRev' ] ) ; $ this -> serials [ $ namespace ] = md5 ( serialize ( $ batch ) ) ; } return $ this -> serials [ $ namespace ] ; }
Returns a md5 signature of a segment of the configuration object that uniquely identifies that particular configuration
1,968
public function getSerial ( ) { if ( empty ( $ this -> serial ) ) { $ this -> serial = md5 ( serialize ( $ this -> getAll ( ) ) ) ; } return $ this -> serial ; }
Returns a md5 signature for the entire configuration object that uniquely identifies that particular configuration
1,969
public function getAll ( ) { if ( ! $ this -> finalized ) $ this -> autoFinalize ( ) ; $ ret = array ( ) ; foreach ( $ this -> plist -> squash ( ) as $ name => $ value ) { list ( $ ns , $ key ) = explode ( '.' , $ name , 2 ) ; $ ret [ $ ns ] [ $ key ] = $ value ; } return $ ret ; }
Retrieves all directives organized by namespace
1,970
public static function prepareArrayFromForm ( $ array , $ index = false , $ allowed = true , $ mq_fix = true , $ schema = null ) { if ( $ index !== false ) $ array = ( isset ( $ array [ $ index ] ) && is_array ( $ array [ $ index ] ) ) ? $ array [ $ index ] : array ( ) ; $ mq = $ mq_fix && function_exists ( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc ( ) ; $ allowed = HTMLPurifier_Config :: getAllowedDirectivesForForm ( $ allowed , $ schema ) ; $ ret = array ( ) ; foreach ( $ allowed as $ key ) { list ( $ ns , $ directive ) = $ key ; $ skey = "$ns.$directive" ; if ( ! empty ( $ array [ "Null_$skey" ] ) ) { $ ret [ $ ns ] [ $ directive ] = null ; continue ; } if ( ! isset ( $ array [ $ skey ] ) ) continue ; $ value = $ mq ? stripslashes ( $ array [ $ skey ] ) : $ array [ $ skey ] ; $ ret [ $ ns ] [ $ directive ] = $ value ; } return $ ret ; }
Prepares an array from a form into something usable for the more strict parts of HTMLPurifier_Config
1,971
protected function triggerError ( $ msg , $ no ) { $ backtrace = debug_backtrace ( ) ; if ( $ this -> chatty && isset ( $ backtrace [ 1 ] ) ) { $ frame = $ backtrace [ 1 ] ; $ extra = " on line {$frame['line']} in file {$frame['file']}" ; } else { $ extra = '' ; } trigger_error ( $ msg . $ extra , $ no ) ; }
Produces a nicely formatted error message by supplying the stack frame information from two levels up and OUTSIDE of HTMLPurifier_Config .
1,972
public static function send ( $ params ) { $ params = array_merge ( [ 'subject' => '' , 'view' => '' , 'body' => '' , 'bodyHtml' => '' , 'to' => [ ] , 'bcc' => [ ] , 'cc' => [ ] , 'replyTo' => [ ] , 'file' => '' , ] , $ params ) ; $ message = ( new static ( ) ) -> to ( $ params [ 'to' ] ) -> from ( $ params [ 'from' ] ) -> subject ( $ params [ 'subject' ] ) -> bcc ( $ params [ 'bcc' ] ) -> cc ( $ params [ 'cc' ] ) -> reply ( $ params [ 'replyTo' ] ) ; if ( $ params [ 'view' ] != '' ) { $ message -> body ( makeMail ( $ params [ 'view' ] , [ 'data' => $ params [ 'body' ] ] ) , 'text/html' ) ; } else { $ message -> body ( $ params [ 'body' ] ) ; } if ( $ params [ 'file' ] != '' ) { $ message -> attachment ( $ params [ 'file' ] ) ; } return self :: getMailerClient ( ) -> send ( $ message ) ; }
Send message using chosen driver .
1,973
protected function build_attachment_fields ( Vulnerabilities $ vulnerabilities ) { $ fields = [ ] ; foreach ( $ vulnerabilities as $ vulnerability ) { $ fixed_in = $ vulnerability -> fixed_in ? 'Fixed in v' . $ vulnerability -> fixed_in : 'Not fixed yet' ; $ wpvdb_url = "https://wpvulndb.com/vulnerabilities/{$vulnerability->id}" ; $ fields [ ] = [ 'title' => $ vulnerability -> title , 'value' => "{$fixed_in} - <{$wpvdb_url}|More info>" , ] ; } return $ fields ; }
Generates the fields array for the message attachment .
1,974
public function query ( $ query , $ options = 0 ) { $ result = $ this -> wpdb -> get_results ( ( string ) $ query ) ; $ this -> last_affected_rows = ( int ) $ this -> wpdb -> rows_affected ; $ this -> last_insert_id = ( int ) $ this -> wpdb -> insert_id ; $ this -> last_statement = NULL ; if ( ! is_array ( $ result ) ) $ result = [ ] ; return new GenericResult ( $ result ) ; }
Executes a plain SQL query and return the results
1,975
public function query_statement ( Statement $ statement , array $ data , $ options = 0 ) { $ query = call_user_func_array ( [ $ this -> wpdb , 'prepare' ] , array_merge ( [ ( string ) $ statement ] , $ data ) ) ; $ result = $ this -> query ( $ query ) ; $ this -> last_statement = $ statement ; return $ result ; }
Executes a Statement and return a Result
1,976
public function execute_statement ( Statement $ statement , array $ data , $ options = 0 ) { $ this -> query_statement ( $ statement , $ data , $ options ) ; return $ this -> last_affected_rows ( ) ; }
Executes a Statement and return the number of affected rows
1,977
public function last_insert_id ( Statement $ statement = NULL ) { if ( $ statement && ! $ this -> last_statement === $ statement ) return FALSE ; return $ this -> last_insert_id ; }
Returns the inserted ID of the last executed statement . If a statement is provided it should be verified that it is the same as the last executed one .
1,978
public function last_affected_rows ( Statement $ statement = NULL ) { if ( $ statement && ! $ this -> last_statement === $ statement ) return FALSE ; return $ this -> last_affected_rows ; }
Returns the number of affected rows of the last executed statement . If a statement is provided it should be verified that it is the same as the last executed one .
1,979
public function paramExists ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } if ( strlen ( $ name ) == 1 ) { return isset ( $ this -> shortNames [ $ name ] ) ; } else { return isset ( $ this -> longNames [ $ name ] ) ; } }
checks if parameter is allowed
1,980
public function allowsValue ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } $ longName = ( strlen ( $ name ) == 1 ? ( isset ( $ this -> shortNames [ $ name ] ) ? $ this -> shortNames [ $ name ] : '' ) : $ name ) ; if ( isset ( $ this -> longNames [ $ longName ] ) ) { return $ this -> longNames [ $ longName ] [ 'parameterType' ] !== false ? true : false ; } else { return false ; } }
checks if parameter allows a value if so what type
1,981
public function getValueType ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } $ longName = ( strlen ( $ name ) == 1 ? ( isset ( $ this -> shortNames [ $ name ] ) ? $ this -> shortNames [ $ name ] : '' ) : $ name ) ; if ( isset ( $ this -> longNames [ $ longName ] [ 'parameterType' ] ) && $ this -> longNames [ $ longName ] [ 'parameterType' ] !== false ) { return $ this -> longNames [ $ longName ] [ 'parameterType' ] ; } else { return '' ; } }
returns the type of value allowed
1,982
public function getShortName ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } if ( isset ( $ this -> longNames [ $ name ] ) ) { return $ this -> longNames [ $ name ] [ 'shortName' ] ; } else { return null ; } }
retreive short name of a parameter using its long name
1,983
public function getLongName ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } if ( isset ( $ this -> shortNames [ $ name ] ) ) { return $ this -> shortNames [ $ name ] ; } else { return null ; } }
retreive long name of a parameter using its short name
1,984
public function getDescription ( $ name ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } $ longName = ( strlen ( $ name ) == 1 ? ( isset ( $ this -> shortNames [ $ name ] ) ? $ this -> shortNames [ $ name ] : '' ) : $ name ) ; if ( isset ( $ this -> longNames [ $ longName ] ) ) { return $ this -> longNames [ $ longName ] [ 'description' ] ; } else { return null ; } }
retreive description of a paramter
1,985
public function getUsage ( ) { if ( ! $ this -> isParsed ) { $ this -> parseDefinitions ( ) ; } $ firstCol = array ( ) ; $ longestDef = 0 ; foreach ( array_keys ( $ this -> longNames ) as $ longName ) { ob_start ( ) ; echo "--{$longName}|-{$this->getShortName($longName)}" ; if ( $ this -> allowsValue ( $ longName ) ) { echo "={$this->getValueType($longName)}" ; } if ( $ this -> allowsMultiple ( $ longName ) ) { echo "+" ; } $ defLength = ob_get_length ( ) ; $ longestDef = max ( $ longestDef , $ defLength ) ; $ firstCol [ $ longName ] = ob_get_contents ( ) ; ob_end_clean ( ) ; } $ firstColMaxWidth = $ longestDef + 4 ; ob_start ( ) ; foreach ( $ firstCol as $ longName => $ def ) { $ currentDefLength = strlen ( $ def ) ; $ padding = str_repeat ( " " , $ firstColMaxWidth - $ currentDefLength ) ; echo "{$def}{$padding}{$this->getDescription($longName)}" , PHP_EOL ; } echo PHP_EOL ; $ usage = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ usage ; }
builds a usage definition based on definition of params
1,986
protected function parseDefinitions ( ) { foreach ( $ this -> definitions as $ nameDef => $ description ) { $ nameParts = explode ( "|" , $ nameDef ) ; if ( sizeof ( $ nameParts ) !== 2 ) { throw new \ UnexpectedValueException ( "Unexpected argument name definition expecting \"longName|char\"" ) ; } $ longName = $ nameParts [ 0 ] ; $ isMulti = false ; $ parameterType = false ; $ shortNameLength = strlen ( $ nameParts [ 1 ] ) ; if ( $ shortNameLength == 1 ) { $ shortName = $ nameParts [ 1 ] ; } else { $ secondChar = substr ( $ nameParts [ 1 ] , 1 , 1 ) ; switch ( $ secondChar ) { case '=' : $ shortNameParts = explode ( "=" , $ nameParts [ 1 ] ) ; $ shortName = $ shortNameParts [ 0 ] ; $ parameterTypeString = $ shortNameParts [ 1 ] ; if ( substr ( $ parameterTypeString , - 1 ) === '+' ) { $ isMulti = true ; $ parameterTypeString = substr ( $ parameterTypeString , 0 , - 1 ) ; } switch ( $ parameterTypeString ) { case 'i' : case 'int' : case 'integer' : $ parameterType = 'integer' ; break ; case 's' : case 'str' : case 'string' : $ parameterType = 'string' ; break ; default : throw new \ UnexpectedValueException ( "Expecting parameter type" . " to be either integer or string" ) ; break ; } break ; case '+' : if ( $ shortNameLength > 2 ) { throw new \ UnexpectedValueException ( "Multiple flag charachter (+)" . " should be last character in definition" ) ; } $ shortName = substr ( $ nameParts [ 1 ] , 0 , 1 ) ; $ isMulti = true ; break ; default : throw new \ UnexpectedValueException ( "Expecting short name definition to be a single char" ) ; break ; } } if ( isset ( $ this -> longNames [ $ longName ] ) ) { throw new \ UnexpectedValueException ( "Cannot redefine long name {$longName}" ) ; } if ( isset ( $ this -> shortNames [ $ shortName ] ) ) { throw new \ UnexpectedValueException ( "Cannot redefine short name {$shortName}" ) ; } $ this -> longNames [ $ longName ] = array ( 'shortName' => $ shortName , 'isMultipleAllowed' => $ isMulti , 'parameterType' => $ parameterType , 'description' => $ description ) ; $ this -> shortNames [ $ shortName ] = $ longName ; } $ this -> isParsed = true ; }
parses the definitions
1,987
public function acquire ( ) { if ( ! $ this -> locked ) { $ this -> fp = @ fopen ( $ this -> filePath , 'a' ) ; if ( ! $ this -> fp || ! flock ( $ this -> fp , LOCK_EX | LOCK_NB ) ) { throw new LockException ( "Could not get lock on {$this->filePath}" ) ; } else { $ this -> locked = true ; } } return $ this ; }
Acquire a lock on the resource .
1,988
public function release ( ) { if ( $ this -> locked ) { flock ( $ this -> fp , LOCK_UN ) ; fclose ( $ this -> fp ) ; $ this -> fp = null ; $ this -> locked = false ; } return $ this ; }
Release the lock on the resource if we have one .
1,989
public function addKeys ( $ keys ) { foreach ( ( array ) $ keys as $ position => $ key ) { $ this -> keys [ $ position ] = $ key ; } return $ this ; }
Sets the keys for the properties Existing keys will be overridden only when necessary
1,990
public function setKey ( $ location , $ key ) { $ this -> keys [ ( integer ) $ location ] = ( string ) $ key ; return $ this ; }
Sets the key for a property
1,991
public function resetModifiers ( $ key = false ) { if ( $ key ) { unset ( $ this -> modifiers [ $ key ] ) ; } else { $ this -> modifiers = array ( ) ; } return $ this ; }
resets the modifiers
1,992
public function parse ( ) { $ lines = str_getcsv ( $ this -> source , $ this -> newline , $ this -> enclosure , $ this -> escape ) ; if ( $ this -> getSourceHasHeadline ( ) ) { $ keys = explode ( $ this -> delimiter , $ lines [ 0 ] ) ; $ this -> addKeys ( $ keys ) ; unset ( $ lines [ 0 ] ) ; } foreach ( $ lines as $ line ) { $ values = str_getcsv ( $ line , $ this -> delimiter , $ this -> enclosure , $ this -> escape ) ; foreach ( $ values as $ key => $ value ) { $ values [ $ key ] = str_replace ( $ this -> escape . $ this -> enclosure , $ this -> enclosure , $ value ) ; if ( $ this -> trim ) { $ values [ $ key ] = trim ( $ values [ $ key ] ) ; } } $ dataset = array ( ) ; foreach ( $ values as $ position => $ rawValue ) { $ key = isset ( $ this -> keys [ $ position ] ) ? $ this -> keys [ $ position ] : $ position ; $ processedValue = $ rawValue ; if ( isset ( $ this -> modifiers [ $ key ] ) ) { foreach ( ( array ) $ this -> modifiers [ $ key ] as $ modifier ) { $ processedValue = call_user_func ( $ modifier , $ processedValue ) ; } } $ dataset [ $ key ] = $ processedValue ; } $ this -> result [ ] = $ dataset ; } return $ this -> result ; }
main function parses the source and returns the result array
1,993
public function squash ( $ force = false ) { if ( $ this -> cache !== null && ! $ force ) return $ this -> cache ; if ( $ this -> parent ) { return $ this -> cache = array_merge ( $ this -> parent -> squash ( $ force ) , $ this -> data ) ; } else { return $ this -> cache = $ this -> data ; } }
Squashes this property list and all of its property lists into a single array and returns the array . This value is cached by default .
1,994
public function handleExit ( \ Closure $ callback ) { $ this -> append ( SIGHUP , $ callback ) ; $ this -> append ( SIGINT , $ callback ) ; $ this -> append ( SIGQUIT , $ callback ) ; $ this -> append ( SIGTERM , $ callback ) ; }
Handle application exit signals
1,995
public function append ( $ signal , Closure $ callback ) { if ( empty ( $ this -> listeners ) ) { declare ( ticks = 1 ) ; } $ this -> listeners [ $ signal ] = $ callback ; pcntl_signal ( $ signal , [ $ this , "executeListener" ] ) ; return $ this ; }
Add signal listener
1,996
public function executeListener ( $ signal , $ exit = true ) { $ return = null ; if ( isset ( $ this -> listeners [ $ signal ] ) ) { $ return = call_user_func_array ( $ this -> listeners [ $ signal ] , [ $ signal ] ) ; } if ( true === $ exit ) { posix_kill ( posix_getpid ( ) , SIGKILL ) ; } return $ return ; }
Method which is executed when a signal is received
1,997
public static function create ( $ type , $ value , $ extra = null ) { switch ( strtolower ( $ type ) ) { case 'int' : case 'integer' : return self :: createInt ( $ value ) ; case 'float' : case 'double' : return self :: createFloat ( $ value ) ; case 'string' : return self :: createString ( $ value ) ; case 'bool' : case 'boolean' : return self :: createBool ( $ value ) ; case 'digit' : return self :: createDigit ( $ value ) ; case 'natural' : return self :: createNatural ( $ value ) ; case 'whole' : return self :: createWhole ( $ value ) ; case 'complex' : return self :: createComplex ( $ value , $ extra ) ; case 'rational' : return self :: createRational ( $ value , $ extra ) ; default : throw new InvalidTypeException ( strtolower ( $ type ) ) ; } }
Generic type factory
1,998
public static function createInt ( $ value ) { if ( $ value instanceof NumericTypeInterface ) { return $ value -> asIntType ( ) ; } if ( ! is_numeric ( $ value ) ) { throw new \ InvalidArgumentException ( "'{$value}' is no valid numeric for IntType" ) ; } if ( self :: getRequiredType ( ) == self :: TYPE_GMP ) { return new GMPIntType ( $ value ) ; } return new IntType ( $ value ) ; }
Create an IntType
1,999
public static function createFloat ( $ value ) { if ( $ value instanceof NumericTypeInterface ) { return $ value -> asFloatType ( ) ; } if ( ! is_numeric ( $ value ) ) { throw new \ InvalidArgumentException ( "'{$value}' is no valid numeric for FloatType" ) ; } if ( self :: getRequiredType ( ) == self :: TYPE_GMP ) { return RationalTypeFactory :: create ( $ value ) ; } return new FloatType ( $ value ) ; }
Create a FloatType