idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
59,000
|
public static function setBaseDirectory ( $ directory ) { if ( ! is_dir ( $ directory ) ) throw new \ InvalidArgumentException ( 'm\View\GenericView: Given string "' . $ directory . '" is not a valid directory.' ) ; static :: $ _defaultDir = ( string ) rtrim ( $ directory , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; }
|
Sets the directory for the view files .
|
59,001
|
public function setFile ( $ file ) { $ path = pathinfo ( ( string ) $ file ) ; if ( ! $ path [ 'extension' ] ) $ file .= '.' . static :: $ _defaultExt ; $ this -> _file = trim ( $ file , DIRECTORY_SEPARATOR ) ; return $ this ; }
|
Set the view file name . If an extension is provided that extension will be used over the default .
|
59,002
|
public function clearMany ( $ keys ) { if ( ! is_array ( $ keys ) ) $ keys = func_get_args ( ) ; foreach ( $ keys as $ key ) { unset ( $ this -> _data [ $ key ] ) ; } return $ this ; }
|
Clear any matching items from the view data .
|
59,003
|
public function setDevKey ( $ key ) { $ this -> validator -> validateDeveloperKey ( $ key ) ; $ this -> devKey = $ key ; return $ this ; }
|
Sets the developer key .
|
59,004
|
public function verify ( ) { $ this -> resetApiParameters ( ) ; $ this -> setCommonApiParameters ( ) ; $ wrongKeys = array ( ) ; foreach ( $ this -> getApiKeys ( ) as $ key ) { $ this -> setApiParameter ( 'apikey' , $ key ) ; try { $ this -> callApi ( self :: API_URL_VERIFY ) ; } catch ( RuntimeException $ e ) { $ wrongKeys [ ] = $ key ; } } if ( ! empty ( $ wrongKeys ) ) { throw new InvalidArgumentException ( sprintf ( 'Following API keys are invalid: %s' , var_export ( implode ( ',' , $ wrongKeys ) , true ) ) , 401 ) ; } return $ this ; }
|
Verifies the given API keys .
|
59,005
|
public function notify ( $ application , $ event , $ description , $ priority = 0 , $ url = '' , $ html = false ) { $ this -> validator -> validateApplication ( $ application ) -> validateEvent ( $ event ) -> validateDescription ( $ description ) -> validatePriority ( $ priority ) -> validateUrl ( $ url ) ; $ this -> resetApiParameters ( ) ; $ this -> setCommonApiParameters ( ) ; $ this -> setApiParameter ( 'application' , $ application ) ; $ this -> setApiParameter ( 'event' , $ event ) ; $ this -> setApiParameter ( 'description' , $ description ) ; $ this -> setApiParameter ( 'priority' , $ priority ) ; if ( '' !== $ url ) { $ this -> setApiParameter ( 'url' , $ url ) ; } if ( true === $ html ) { $ this -> setApiParameter ( 'content-type' , 'text/html' ) ; } return $ this -> callApi ( self :: API_URL_NOTIFY ) ; }
|
Sends a notification with the given parameters .
|
59,006
|
protected function setCommonApiParameters ( ) { if ( ! empty ( $ this -> devKey ) ) { $ this -> setApiParameter ( 'developerkey' , $ this -> devKey ) ; } $ this -> validator -> validateApiKeys ( $ this -> apiKeys ) ; $ this -> setApiParameter ( 'apikey' , implode ( ',' , $ this -> apiKeys ) ) ; return $ this ; }
|
Sets common API request parameters .
|
59,007
|
protected function callApi ( $ url ) { $ url = $ this -> apiBaseUrl . $ url ; $ options = array ( 'http' => array ( 'method' => 'POST' , 'header' => 'Content-Type: application/x-www-form-urlencoded' , 'ignore_errors' => true , 'content' => http_build_query ( $ this -> parameters , '' , '&' ) ) ) ; $ context = stream_context_create ( $ options ) ; $ fp = fopen ( $ url , 'rb' , false , $ context ) ; if ( ! $ fp ) { throw new RuntimeException ( sprintf ( 'Could not connect to NMA API URL %s' , var_export ( $ url , true ) ) , 500 ) ; } $ res = stream_get_contents ( $ fp ) ; if ( $ res === false ) { throw new RuntimeException ( sprintf ( 'Could not fetch data from NMA API URL %s' , var_export ( $ url , true ) ) , 500 ) ; } $ xml = simplexml_load_string ( $ res ) ; if ( $ xml === null ) { throw new RuntimeException ( sprintf ( 'Could not decode NMA API response for URL %s as XML. ' . 'Response was: %s' , var_export ( $ url , true ) , var_export ( $ res , true ) ) , 500 ) ; } return $ this -> processXmlReturn ( $ xml ) ; }
|
Calls the API with the given parameters .
|
59,008
|
private function processXmlReturn ( SimpleXMLElement $ xml ) { if ( isset ( $ xml -> error ) ) { if ( isset ( $ xml -> error [ '@attributes' ] ) ) { $ this -> lastStatus = ( int ) $ xml -> error [ '@attributes' ] [ 'code' ] ; if ( isset ( $ xml -> error [ '@attributes' ] [ 'resettimer' ] ) ) { $ this -> apiLimitReset = ( int ) $ xml -> error [ '@attributes' ] [ 'resettimer' ] ; } } throw new RuntimeException ( $ xml -> error , $ this -> lastStatus ) ; } if ( ! isset ( $ xml -> success ) ) { throw new RuntimeException ( 'Unexpected NMA API response' , 500 ) ; } $ this -> lastStatus = ( int ) $ xml -> success [ '@attributes' ] [ 'code' ] ; $ this -> apiCallsRemaining = ( int ) $ xml -> success [ '@attributes' ] [ 'remaining' ] ; $ this -> apiLimitReset = ( int ) $ xml -> success [ '@attributes' ] [ 'resettimer' ] ; return $ this ; }
|
Processes the XML API response .
|
59,009
|
public function dispatch ( ) { $ this -> lock -> acquire ( ) ; $ this -> guardThatHistoryRepositoryDoesNotHaveMoreUnitsOfWork ( ) ; $ workloadRepository = $ this -> sourceRepository -> diff ( $ this -> historyRepository ) ; foreach ( $ workloadRepository as $ unitOfWork ) { $ this -> executeMigration ( $ unitOfWork ) ; } $ this -> historyRepository -> persist ( ) ; $ this -> lock -> release ( ) ; }
|
Dispatches the migration process
|
59,010
|
private function guardThatHistoryRepositoryDoesNotHaveMoreUnitsOfWork ( ) { $ historyDiffRepository = $ this -> historyRepository -> diff ( $ this -> sourceRepository ) ; if ( 0 < $ historyDiffRepository -> count ( ) ) { throw new HistoryHasSourceUnknownUnitsOfWorkException ( ) ; } }
|
Guards the there are no units of work in the history repository that are not also in the source repository
|
59,011
|
private function executeMigration ( UnitOfWork $ unitOfWork ) { try { $ unitOfWork -> migrate ( $ this -> connection ) ; $ this -> historyRepository -> add ( $ unitOfWork ) ; } catch ( QueryNotSuccessfulException $ e ) { } }
|
Executes the given migration against the database connection
|
59,012
|
public static function Tdbtt ( $ tdb1 , $ tdb2 , $ dtr , & $ tt1 , & $ tt2 ) { $ dtrd ; $ dtrd = $ dtr / DAYSEC ; if ( $ tdb1 > $ tdb2 ) { $ tt1 = $ tdb1 ; $ tt2 = $ tdb2 - $ dtrd ; } else { $ tt1 = $ tdb1 - $ dtrd ; $ tt2 = $ tdb2 ; } return 0 ; }
|
- - - - - - - - - i a u T d b t t - - - - - - - - -
|
59,013
|
private function getJ2000Day ( \ DateTime $ dateTime ) { $ day = ( integer ) $ dateTime -> format ( 'j' ) ; $ month = ( integer ) $ dateTime -> format ( 'n' ) ; $ year = ( integer ) $ dateTime -> format ( 'Y' ) ; return floor ( 367 * $ year - ( 7 * ( $ year + ( ( $ month + 9 ) / 12 ) ) ) / 4 + ( 275 * $ month ) / 9 + $ day - 730530 ) ; }
|
Returns the number of days from J2000 . 0 .
|
59,014
|
public static function extend ( ) { if ( func_num_args ( ) < 2 ) { throw new BadFunctionCallException ( "Not enough parameters" ) ; } $ args = func_get_args ( ) ; $ merged = array_shift ( $ args ) ; foreach ( $ args as $ source ) { foreach ( $ source as $ key => $ value ) { if ( is_array ( $ value ) && isset ( $ merged [ $ key ] ) && is_array ( $ merged [ $ key ] ) ) { $ merged [ $ key ] = static :: merge ( $ merged [ $ key ] , $ value ) ; } else { $ merged [ $ key ] = $ value ; } } } return $ merged ; }
|
Extends array parameters recursively .
|
59,015
|
public static function slice ( $ data , $ keys ) { $ removed = array_intersect_key ( $ data , array_fill_keys ( ( array ) $ keys , true ) ) ; $ data = array_diff_key ( $ data , $ removed ) ; return [ $ data , $ removed ] ; }
|
Slices an array into two separating them determined by an array of keys .
|
59,016
|
public static function normalize ( $ data ) { $ result = [ ] ; foreach ( $ data as $ key => $ value ) { if ( ! is_int ( $ key ) ) { $ result [ $ key ] = $ value ; continue ; } if ( ! is_scalar ( $ value ) ) { throw new Exception ( "Invalid array format, a value can't be normalized" ) ; } $ result [ $ value ] = null ; } return $ result ; }
|
Normalizes an array and converts it to an array of key = > value pairs where keys must be strings .
|
59,017
|
public function getPanel ( ) { $ app = \ MvcCore \ Application :: GetInstance ( ) ; $ requestCode = \ Tracy \ Dumper :: toHtml ( $ app -> GetRequest ( ) -> InitAll ( ) , [ \ Tracy \ Dumper :: LIVE => TRUE , \ Tracy \ Dumper :: COLLAPSE => 1 , \ Tracy \ Dumper :: DEPTH => 4 , ] ) ; $ responseCode = \ Tracy \ Dumper :: toHtml ( $ app -> GetResponse ( ) , [ \ Tracy \ Dumper :: LIVE => TRUE , \ Tracy \ Dumper :: COLLAPSE => 1 , \ Tracy \ Dumper :: DEPTH => 2 , \ Tracy \ Dumper :: TRUNCATE => 40 ] ) ; $ routerCode = \ Tracy \ Dumper :: toHtml ( $ app -> GetRouter ( ) , [ \ Tracy \ Dumper :: LIVE => TRUE , \ Tracy \ Dumper :: COLLAPSE => 1 , \ Tracy \ Dumper :: DEPTH => 5 , ] ) ; $ ctrlCode = \ Tracy \ Dumper :: toHtml ( $ app -> GetController ( ) , [ \ Tracy \ Dumper :: LIVE => TRUE , \ Tracy \ Dumper :: COLLAPSE => 1 , \ Tracy \ Dumper :: COLLAPSE_COUNT => 1 , \ Tracy \ Dumper :: DEPTH => 3 , ] ) ; $ appCode = \ Tracy \ Dumper :: toHtml ( $ app , [ \ Tracy \ Dumper :: LIVE => TRUE , \ Tracy \ Dumper :: COLLAPSE => 1 , \ Tracy \ Dumper :: DEPTH => 1 , ] ) ; $ result = '<h1>MvcCore</h1>' . '<style>#tracy-debug-panel-mvccore-panel pre.tracy-dump{display:block !important;}</style>' . $ appCode . $ requestCode . $ responseCode . $ routerCode . $ ctrlCode ; return $ result ; }
|
Return rendered debug panel content window HTML code .
|
59,018
|
public function getData ( $ ip = "" ) { $ this -> ip = $ ip ; if ( empty ( $ this -> ip ) ) { throw new AddressNotFoundException ( json_encode ( [ 'error' => 'No IP found for the user' ] ) ) ; } try { $ request_params = $ this -> generateRequestParams ( ) ; $ res = self :: client ( ) -> get ( self :: api_url ( ) . 'data' , $ request_params ) ; } catch ( RequestException $ e ) { if ( $ e -> hasResponse ( ) ) { throw new GeotRequestException ( $ e -> getResponse ( ) ) ; } } $ this -> validateResponse ( $ res ) ; return $ this -> cleanResponse ( $ res ) ; }
|
Main function that return User data
|
59,019
|
private function validateResponse ( $ res ) { if ( null === $ res ) throw new GeotException ( json_encode ( [ 'error' => 'Null reponse from guzzle' ] ) ) ; $ code = $ res -> getStatusCode ( ) ; switch ( $ code ) { case '404' : throw new AddressNotFoundException ( ( string ) $ res -> getBody ( ) ) ; case '500' : throw new InvalidIPException ( ( string ) $ res -> getBody ( ) ) ; case '401' : throw new InvalidLicenseException ( ( string ) $ res -> getBody ( ) ) ; case '403' : throw new OutofCreditsException ( ( string ) $ res -> getBody ( ) ) ; case '200' : break ; default : throw new GeotException ( ( string ) $ res -> getBody ( ) ) ; break ; } }
|
Check returned response
|
59,020
|
public static function getCities ( $ iso_code ) { $ response = self :: client ( ) -> get ( self :: api_url ( ) . 'cities' , [ 'query' => [ 'iso_code' => $ iso_code ] ] ) ; if ( $ response -> getStatusCode ( ) != '200' ) return [ 'error' => 'Something wrong happened' ] ; $ response = ( string ) $ response -> getBody ( ) ; return $ response ; }
|
Helper function that get cities for given country
|
59,021
|
public function setMapping ( string $ item , string $ file ) : object { $ this -> mapping [ $ item ] = $ file ; return $ this ; }
|
Set a specific configuration file to load for a particluar item .
|
59,022
|
public function load ( string $ item ) : array { if ( empty ( $ this -> dirs ) ) { throw new Exception ( "The array for configuration directories can not be empty." ) ; } $ found = false ; $ config = [ ] ; $ mapping = $ this -> mapping [ $ item ] ?? null ; if ( $ mapping ) { $ config [ "file" ] = $ mapping ; $ config [ "config" ] = require $ mapping ; return $ config ; } foreach ( $ this -> dirs as $ dir ) { $ path = "$dir/$item" ; $ file = "$path.php" ; if ( is_readable ( $ path ) && is_file ( $ path ) ) { $ found = true ; $ config [ "file" ] = $ path ; $ config [ "config" ] = require $ path ; break ; } if ( is_readable ( $ file ) && is_file ( $ file ) ) { $ found = true ; $ config [ "file" ] = $ file ; $ config [ "config" ] = require $ file ; } if ( is_readable ( $ path ) && is_dir ( $ path ) ) { $ found = true ; $ config [ "items" ] = $ this -> loadFromDir ( $ path ) ; } if ( $ found ) { break ; } } if ( ! $ found ) { throw new Exception ( "Configure item '$item' can not be found." ) ; } return $ config ; }
|
Read configuration from file or directory if a file look though all base dirs and use the first configuration that is found . A configuration item can be combined from a file and a directory when available in the same base directory .
|
59,023
|
public function getVariable ( $ name ) { $ encodedValue = $ this -> getEnvironmentVariable ( $ name ) ; if ( $ encodedValue === null ) { return null ; } return $ this -> decode ( $ encodedValue ) ; }
|
Decode and decrypt a previously set environment variable .
|
59,024
|
public function getAttributeValue ( $ key ) { $ value = $ this -> getAttributeFromArray ( $ key ) ; if ( $ this -> hasGetMutator ( $ key ) ) { $ method = sprintf ( $ this -> methodNameGetMutator , Str :: studly ( $ key ) ) ; return call_user_func_array ( [ $ this , $ method ] , [ $ value ] ) ; } return $ value ; }
|
Return attribute key value .
|
59,025
|
public function setAttribute ( $ key , $ value ) { if ( $ this -> hasSetMutator ( $ key ) ) { $ method = sprintf ( $ this -> methodNameSetMutator , Str :: studly ( $ key ) ) ; return $ this -> { $ method } ( $ value ) ; } $ this -> attributes [ $ key ] = $ value ; return $ this ; }
|
Set attribute key and value .
|
59,026
|
protected function hasGetMutator ( $ key ) { return method_exists ( $ this , sprintf ( $ this -> methodNameGetMutator , Str :: studly ( $ key ) ) ) ; }
|
Return if attribute has method get .
|
59,027
|
protected function hasSetMutator ( $ key ) { return method_exists ( $ this , sprintf ( $ this -> methodNameSetMutator , Str :: studly ( $ key ) ) ) ; }
|
Return if attribute has method set .
|
59,028
|
public function span ( $ value , $ attributes = [ ] ) { $ tag = new Tag ( 'span' , $ attributes ) ; $ tag -> setText ( $ value ) ; return $ tag ; }
|
span tag render
|
59,029
|
public function getPhrase ( ) : string { return isset ( self :: $ phrases [ $ this -> code ] ) ? self :: $ phrases [ $ this -> code ] : '' ; }
|
Returns the phrase for the code .
|
59,030
|
private function filterStatus ( $ code ) : int { if ( ! is_numeric ( $ code ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Status code "%s" is not numeric.' , is_scalar ( $ code ) ? $ code : gettype ( $ code ) ) ) ; } $ result = ( int ) $ code ; if ( ! self :: isValid ( $ result ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid status code "%s".' , $ result ) ) ; } return $ result ; }
|
Validates the given HTTP status code and returns an integer if correct .
|
59,031
|
protected function getCmd ( $ refresh = false ) { if ( is_null ( $ this -> cmd ) || $ refresh ) { $ this -> cmd = new Command ( ) ; } return $ this -> cmd ; }
|
Returns the Cmd object
|
59,032
|
public function input ( $ question , $ default = '' , $ options = [ ] ) { if ( empty ( $ default ) ) { $ this -> write ( $ question . ' ' ) ; } elseif ( empty ( $ options ) ) { $ this -> write ( $ question . ' [' . $ default . '] ' ) ; } else { $ available_options = [ ] ; foreach ( strtolower ( $ options ) as $ option ) { if ( $ option === strtolower ( $ default ) ) { $ option = strtoupper ( $ option ) ; } $ available_options [ ] = $ option ; } $ available_opts = rtrim ( implode ( $ available_options , '/' ) , '/' ) ; $ this -> write ( $ question . ' [' . $ available_opts . '] ' ) ; } $ answer = rtrim ( fgets ( STDIN ) , PHP_EOL ) ; if ( empty ( $ answer ) ) { return $ default ; } if ( count ( $ options ) > 0 ) { if ( ! in_array ( strtolower ( $ answer ) , array_map ( 'strtolower' , $ options ) ) ) { return $ this -> input ( $ question , $ default , $ options ) ; } return $ answer ; } return $ answer ; }
|
Request user input
|
59,033
|
public function translate ( $ key , $ param = array ( ) , $ defaultLine = '' ) { $ line = $ this -> replaceParam ( $ this -> getLine ( $ key , $ defaultLine ) , $ param ) ; if ( ! $ line ) { return ( $ this -> isDebugMode ( ) ) ? '{{ ' . $ key . ' }}' : $ line ; } return $ line ; }
|
Translate a language
|
59,034
|
public function choice ( $ key , $ count = 1 , $ param = array ( ) ) { $ line = $ this -> getLine ( $ key ) ; $ lines = explode ( '|' , $ line ) ; if ( isset ( $ lines [ $ count - 1 ] ) ) { $ line = $ lines [ $ count - 1 ] ; $ param [ 'count' ] = $ count ; return $ this -> replaceParam ( $ line , $ param ) ; } return ( $ this -> isDebugMode ( ) ) ? '{{ ' . $ key . ' }}' : $ line ; }
|
Retrieve a translation string that is different depending on a count .
|
59,035
|
protected function getLine ( $ key , $ default = null ) { $ lang = $ this -> lang ; $ key = $ this -> sanitize ( $ key ) ; if ( ! $ this -> hasLanguage ( $ lang ) ) { $ message = 'Language [' . $ lang . '] is not available' ; throw new LangException ( $ message ) ; } $ line = $ this -> arrayGet ( $ lang . '.' . $ key , $ default ) ; return $ line ; }
|
Get raw translated line
|
59,036
|
protected function arrayGet ( $ key , $ default = null ) { if ( isset ( $ this -> list [ $ key ] ) ) { return $ this -> list [ $ key ] ; } foreach ( explode ( '.' , $ key ) as $ segment ) { if ( ! is_array ( $ this -> list ) || ! array_key_exists ( $ segment , $ this -> list ) ) { return ( is_callable ( $ default ) ) ? $ default ( ) : $ default ; } $ this -> list = $ this -> list [ $ segment ] ; } return $ this -> list ; }
|
Get line in dot notation
|
59,037
|
protected function replaceParam ( $ line , array $ param ) { if ( ! empty ( $ param ) and is_array ( $ param ) ) { foreach ( $ param as $ key => $ value ) { $ line = str_replace ( ':' . $ key , $ value , $ line ) ; } } return $ line ; }
|
Replace word from parameters
|
59,038
|
public function resetFlashes ( ) { $ newValues = $ this -> get ( $ this -> getFlashKey ( 'new' ) , [ ] ) ; $ this -> set ( $ this -> getFlashKey ( 'old' ) , $ newValues ) ; $ this -> set ( $ this -> getFlashKey ( 'new' ) , [ ] ) ; }
|
Reset flashes .
|
59,039
|
public function map ( $ method , $ match , $ callback ) { $ match = $ this -> base . $ match ; $ route = $ this -> routeService -> attach ( $ method , $ match , $ callback ) -> setGroup ( $ this ) ; return $ route ; }
|
Regist a http route .
|
59,040
|
public function addLocale ( Locale $ locale ) { $ key = self :: canonicalize ( $ locale -> getCode ( ) ) ; if ( isset ( $ this -> _locales [ $ key ] ) ) { return $ this -> _locales [ $ key ] ; } foreach ( $ this -> getResourcePaths ( ) as $ domain => $ paths ) { $ locale -> addResourcePaths ( $ domain , $ paths ) ; } $ locale -> initialize ( ) ; $ this -> _locales [ $ key ] = $ locale ; if ( $ parent = $ locale -> getParentLocale ( ) ) { $ this -> addLocale ( $ parent ) ; } if ( ! $ this -> _fallback ) { $ this -> setFallback ( $ key ) ; } return $ locale ; }
|
Sets up the application with the defined locale key ; the key will be formatted to a lowercase dashed URL friendly format . The system will then attempt to load the locale resource bundle and finalize configuration settings .
|
59,041
|
public static function canonicalize ( $ key , $ format = self :: FORMAT_1 ) { $ parts = explode ( '-' , str_replace ( '_' , '-' , mb_strtolower ( $ key ) ) ) ; $ return = $ parts [ 0 ] ; if ( isset ( $ parts [ 1 ] ) ) { switch ( $ format ) { case self :: FORMAT_1 : $ return .= '-' . $ parts [ 1 ] ; break ; case self :: FORMAT_2 : $ return .= '-' . mb_strtoupper ( $ parts [ 1 ] ) ; break ; case self :: FORMAT_3 : $ return .= '_' . mb_strtoupper ( $ parts [ 1 ] ) ; break ; case self :: FORMAT_4 : $ return .= mb_strtoupper ( $ parts [ 1 ] ) ; break ; } } return $ return ; }
|
Convert a locale key to 3 possible formats .
|
59,042
|
public function cascade ( ) { return $ this -> cache ( [ __METHOD__ , $ this -> current ( ) -> getCode ( ) ] , function ( ) { $ cycle = [ ] ; foreach ( [ $ this -> current ( ) , $ this -> getFallback ( ) ] as $ locale ) { while ( $ locale instanceof Locale ) { $ cycle [ ] = $ locale -> getCode ( ) ; $ locale = $ locale -> getParentLocale ( ) ; } } $ cycle = array_unique ( $ cycle ) ; $ this -> emit ( 'g11n.onCascade' , [ $ this , & $ cycle ] ) ; return $ cycle ; } ) ; }
|
Get a list of locales and fallback locales in descending order starting from the current locale .
|
59,043
|
public function getResourcePaths ( $ domain = null ) { return isset ( $ this -> _paths [ $ domain ] ) ? $ this -> _paths [ $ domain ] : $ this -> _paths ; }
|
Return all resource paths or filtered by domain .
|
59,044
|
public function initialize ( ) { if ( ! $ this -> isEnabled ( ) ) { return ; } $ current = null ; if ( ! empty ( $ _COOKIE [ 'locale' ] ) && isset ( $ this -> _locales [ $ _COOKIE [ 'locale' ] ] ) ) { $ current = $ _COOKIE [ 'locale' ] ; } else if ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { $ header = mb_strtolower ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; if ( mb_strpos ( $ header , ';' ) !== false ) { $ header = mb_strstr ( $ header , ';' , true ) ; } $ header = explode ( ',' , $ header ) ; if ( count ( $ header ) > 0 ) { foreach ( $ header as $ key ) { if ( isset ( $ this -> _locales [ $ key ] ) ) { $ current = $ key ; break ; } } } } if ( $ current === null ) { $ current = $ this -> _fallback -> getCode ( ) ; } if ( ! $ this -> _translator ) { throw new MissingTranslatorException ( 'A translator is required for G11n message parsing' ) ; } $ this -> emit ( 'g11n.onInit' , [ $ this , & $ current ] ) ; $ this -> useLocale ( $ current ) ; }
|
Detect which locale to use based on the clients Accept - Language header .
|
59,045
|
public function is ( $ key ) { $ code = $ this -> current ( ) -> getCode ( ) ; return ( $ code === $ key || $ this -> canonicalize ( $ code ) === $ key ) ; }
|
Does the current locale matched the passed key?
|
59,046
|
public function resolveRoute ( Event $ event , Router $ router , $ url ) { if ( PHP_SAPI === 'cli' ) { return ; } $ locales = $ this -> getLocales ( ) ; $ redirect = '/' . $ this -> getFallback ( ) -> getCode ( ) ; $ base = $ router -> base ( ) ; if ( $ base !== '/' ) { $ redirect = $ base . $ redirect ; } if ( ! preg_match ( '/^\/' . LocaleRoute :: LOCALE . '\/(.*)?/' , $ url , $ matches ) ) { if ( empty ( $ locales [ trim ( $ url , '/' ) ] ) ) { header ( 'Location: ' . $ redirect . $ url ) ; exit ( ) ; } } else if ( empty ( $ locales [ $ matches [ 1 ] ] ) ) { header ( 'Location: ' . $ redirect . $ matches [ 2 ] ) ; exit ( ) ; } }
|
When the Router initializes check for the existence of a locale in the URL . If the locale exists verify it . If either of these fail redirect with the fallback locale . This event must be bound to the Router to work .
|
59,047
|
public function setFallback ( $ key ) { $ key = $ this -> canonicalize ( $ key ) ; if ( ! isset ( $ this -> _locales [ $ key ] ) ) { throw new MissingLocaleException ( sprintf ( 'Locale %s has not been setup' , $ key ) ) ; } $ this -> _fallback = $ this -> _locales [ $ key ] ; Config :: set ( 'titon.locale.fallback' , $ key ) ; return $ this ; }
|
Define the fallback locale to use if none can be found or is not supported .
|
59,048
|
public function unsignedIntId ( Table $ table ) { $ id = new Column ( ) ; $ id -> setIdentity ( true ) -> setType ( 'integer' ) -> setOptions ( [ 'limit' => 11 , 'signed' => false , 'null' => false ] ) ; $ table -> changeColumn ( 'id' , $ id ) ; }
|
Make the id primary column an unsigned integer .
|
59,049
|
public function add ( $ index , $ value ) : Utility { if ( is_null ( $ this -> get ( $ index ) ) ) { return $ this -> set ( $ index , $ value ) ; } return $ this ; }
|
Add a value to an index if it doesn t exit
|
59,050
|
public function containsAll ( $ needles ) : bool { $ needlesBag = $ this -> transformToBag ( $ needles ) ; return ! array_diff ( $ needlesBag , $ this -> bag ) ; }
|
Are all the values in the needle bag in the haystack bag
|
59,051
|
public function containsAny ( $ needles ) : bool { $ needlesBag = $ this -> transformToBag ( $ needles ) ; return ! ! array_intersect ( $ needlesBag , $ this -> bag ) ; }
|
Are any of the needle values in the haystack bag
|
59,052
|
public function isAssociative ( ) : bool { if ( count ( $ this -> bag ) === 0 ) { return false ; } return array_keys ( $ this -> bag ) !== range ( 0 , count ( $ this -> bag ) - 1 ) ; }
|
Is the bag holding associative data key = value opposed to 123 = value
|
59,053
|
public function isMultiDimensional ( ) : bool { if ( sizeof ( $ this -> bag ) === 0 ) { return false ; } return count ( $ this -> bag ) !== count ( $ this -> bag , COUNT_RECURSIVE ) ; }
|
Is the bag holding multidimensional data
|
59,054
|
public function push ( ... $ values ) : Utility { $ newBag = $ this -> toArray ( ) ; foreach ( $ values as $ value ) { array_push ( $ newBag , $ value ) ; } return new self ( $ newBag ) ; }
|
Push a value onto the end of the bag
|
59,055
|
public function remove ( $ index ) : Utility { if ( $ this -> exists ( $ index ) ) { $ newBag = $ this -> toArray ( ) ; unset ( $ newBag [ $ index ] ) ; return new self ( $ newBag ) ; } return $ this ; }
|
Remove an value from the bag via its index
|
59,056
|
public function removeEmpty ( ) : Utility { $ filteredBag = array_filter ( $ this -> bag , function ( $ value ) { return ! empty ( $ value ) ; } ) ; if ( ! $ this -> isAssociative ( ) ) { $ filteredBag = array_values ( $ filteredBag ) ; } return new static ( $ filteredBag ) ; }
|
Remove all empty values from the bag An empty value could be null 0 false
|
59,057
|
public function set ( $ index , $ value ) : Utility { $ newBag = $ this -> toArray ( ) ; $ newBag [ $ index ] = $ value ; return new self ( $ newBag ) ; }
|
Set an array index with a given value
|
59,058
|
public function toKeyValueString ( $ glue = ' ' , $ keyPrefix = '' , $ keyPostfix = '' , $ keyJoint = '=' , $ valuePrefix = '\'' , $ valuePostfix = '\'' ) { return implode ( $ glue , array_map ( function ( $ v , $ k ) use ( $ keyPrefix , $ keyPostfix , $ keyJoint , $ valuePrefix , $ valuePostfix ) { return sprintf ( $ keyPrefix . "%s" . $ keyPostfix . $ keyJoint . $ valuePrefix . "%s" . $ valuePostfix , $ k , $ v ) ; } , $ this -> bag , array_keys ( $ this -> bag ) ) ) ; }
|
Implode the the bag to show a key = value string
|
59,059
|
private function transformToBag ( $ bag ) : array { if ( is_object ( $ bag ) ) { $ bag = get_object_vars ( $ bag ) ; } $ bag = is_array ( $ bag ) ? $ bag : [ $ bag ] ; $ bag = array_map ( function ( $ e ) { return ( is_object ( $ e ) || is_array ( $ e ) ) ? $ this -> transformToBag ( $ e ) : $ e ; } , $ bag ) ; return $ bag ; }
|
Transform the constructor parameter to a usable array for the utility to use
|
59,060
|
public function byClosure ( Closure $ closure ) { $ this -> controller = new Controller ( ) ; if ( $ this -> hasContainer ( ) && method_exists ( $ this -> controller , 'raikiri' ) ) $ this -> controller -> setContainer ( $ this -> raikiri ( ) ) ; $ this -> action = $ closure -> bindTo ( $ this -> controller ) ; }
|
initialize by closure
|
59,061
|
public function byClassMethod ( $ class , $ method ) { $ this -> controller = new $ class ( ) ; $ this -> controller = is_object ( $ class ) ? $ class : new $ class ( ) ; if ( $ this -> hasContainer ( ) && method_exists ( $ this -> controller , 'raikiri' ) ) $ this -> controller -> setContainer ( $ this -> raikiri ( ) ) ; $ this -> action = function ( ) use ( $ method ) { $ args = func_get_args ( ) ; return call_user_func_array ( [ $ this -> controller , $ method ] , $ args ) ; } ; }
|
initialize by class and method
|
59,062
|
public function create_global_plugin ( & $ plugin ) { $ GLOBALS [ 'BCA_' . get_class ( $ plugin ) ] = $ plugin ; $ GLOBALS [ 'BCA_' . get_class ( $ plugin ) ] -> boot ( ) ; }
|
Registra una clase Plugin de forma global
|
59,063
|
public function getHoursWithUnit ( ) { if ( $ this -> hours == 1 ) { $ postfix = ' hour' ; } else { $ postfix = ' hours' ; } return $ this -> hours . $ postfix . ' on ' . $ this -> log_date . '' ; }
|
Get hours with unit .
|
59,064
|
public static function forge ( $ name = 'default' , array $ config = array ( ) ) { if ( $ exists = static :: instance ( $ name ) ) { \ Error :: notice ( 'Asset with this name exists already, cannot be overwritten.' ) ; return $ exists ; } static :: $ _instances [ $ name ] = new \ Asset_Instance ( array_merge ( static :: $ default_config , \ Config :: get ( 'asset' ) , $ config ) ) ; if ( $ name == 'default' ) { static :: $ _instance = static :: $ _instances [ $ name ] ; } return static :: $ _instances [ $ name ] ; }
|
Gets a new instance of the Asset class .
|
59,065
|
public function execute ( ) { $ eventHandler = $ this -> make ( EventHandler :: class ) ; $ eventHandler -> trigger ( BeforeExecute :: class ) ; $ request = $ this -> make ( Request :: class ) ; $ request -> compute ( ) ; }
|
Executes the Application by loading the requested Controller .
|
59,066
|
public function loadConfigs ( ... $ names ) { $ config = $ this -> make ( Config :: class ) ; foreach ( $ names as $ name ) { $ config -> load ( $ name ) ; } }
|
Loads an Array of config files .
|
59,067
|
public function getCommand ( $ group , $ command ) : string { $ config = $ this -> make ( Config :: class ) ; $ commands = $ config [ 'commands' ] ; if ( isset ( $ commands [ $ group ] ) ) { $ group = $ commands [ $ group ] ; if ( isset ( $ group [ $ command ] ) ) { return $ group [ $ command ] ; } else { throw new ConsoleException ( "Command '" . $ command . "' not found!" ) ; } } else { throw new ConsoleException ( "Command group '" . $ group . "' not found!" ) ; } }
|
Returns the class name for a registered command .
|
59,068
|
public function runCommand ( $ command , array $ parameters = [ ] , $ silent = false ) { $ class = $ this -> make ( $ command ) ; if ( $ class instanceof Command ) { if ( $ silent ) { $ class -> setSilent ( true ) ; } $ class -> run ( $ parameters ) ; } else { throw new ConsoleException ( 'Class has to be a instance of ' . Command :: class . '!' ) ; } }
|
Executes a registered command .
|
59,069
|
public static function build ( \ PHPUnit_Framework_TestCase $ testCase , $ config = [ ] ) { $ mock = static :: get ( $ testCase , $ config ) ; return $ mock -> buildMock ( ) ; }
|
Mock Factory method
|
59,070
|
public function findByIdentifier ( $ identifier ) { $ accessTokenResult = $ this -> cache -> get ( $ identifier ) ; if ( $ accessTokenResult instanceof AccessToken ) { return $ accessTokenResult ; } return NULL ; }
|
Find an access token by identifier
|
59,071
|
public function add ( AccessToken $ accessToken ) { $ lifetime = $ accessToken -> getExpiryTime ( ) - time ( ) ; $ this -> cache -> set ( $ accessToken -> getIdentifier ( ) , $ accessToken , array ( ) , $ lifetime ) ; }
|
Add the given access token to persistence
|
59,072
|
public function indexAction ( ) { return $ this -> forward ( ) -> dispatch ( $ this -> params ( ) -> fromRoute ( 'controller' , get_called_class ( ) ) , array ( 'action' => 'list' , 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
|
Index displays to list by default
|
59,073
|
private function getOptionByRegExpr ( string $ pattern ) : array { $ purgedArgs = $ this -> getRawArgs ( true ) ; return preg_grep ( "/" . $ pattern . "/" , $ purgedArgs ) ; }
|
Get the arguments list and applies and extract data according to the regexpr passed parameter
|
59,074
|
protected function initializeOtherValues ( ) : ConsoleInputInterface { $ this -> domainName = "" ; $ this -> actionName = "" ; $ this -> options = [ ] ; $ this -> params = [ ] ; $ this -> shortOptionsValued = [ ] ; $ this -> shortOptionsVoid = [ ] ; $ this -> longOptionsValued = [ ] ; $ this -> longOptionsVoid = [ ] ; return $ this ; }
|
Set default values to empty for properties before processing command line
|
59,075
|
protected function process ( ) : void { list ( $ commandName , $ actionName ) = $ this -> checkArguments ( ) ; $ this -> options = array_merge ( $ this -> extractShortOptionsWithParams ( ) , $ this -> extractShortOptionsVoid ( ) , $ this -> extractLongOptionsWithValues ( ) , $ this -> extractLongOptionsVoid ( ) ) ; $ this -> setDomainName ( $ commandName ) ; $ this -> setActionName ( $ actionName ) ; $ this -> analyzeAndSetParams ( ) ; }
|
Process the command line and set the environment
|
59,076
|
public function getEmailByEmailId ( $ emailID ) { $ email = $ this -> model -> where ( 'id' , $ emailID ) -> first ( ) ; return $ email -> title ; }
|
Get the email title by ID
|
59,077
|
public function createNewRecord ( $ data ) { $ email = new $ this -> model ; $ email -> email_type_id = $ data [ 'email_type_id' ] ; $ email -> title = $ data [ 'title' ] ; $ email -> description = $ data [ 'description' ] ; $ email -> comments = $ data [ 'comments' ] ; $ email -> created_at = $ data [ 'created_at' ] ; $ email -> created_by = $ data [ 'created_by' ] ; $ email -> updated_at = $ data [ 'updated_at' ] ; $ email -> updated_by = $ data [ 'updated_by' ] ; $ email -> locked_at = null ; $ email -> locked_by = null ; if ( $ email -> save ( ) ) { return $ email -> id ; } return false ; }
|
INSERT INTO email
|
59,078
|
function onAfterInit ( ) { foreach ( ( array ) $ this -> owner -> config ( ) -> include_requirements_from_class as $ class => $ method ) { if ( is_numeric ( $ class ) ) { singleton ( $ method ) -> includes ( $ this -> owner ) ; } else { singleton ( $ class ) -> $ method ( $ this -> owner ) ; } } if ( $ this -> owner instanceof \ KickAssets ) { return ; } Requirements :: javascript ( singleton ( 'env' ) -> get ( 'mwm-utilities.dir' , basename ( rtrim ( dirname ( dirname ( dirname ( dirname ( __FILE__ ) ) ) ) , DIRECTORY_SEPARATOR ) ) ) . '/js/mwm.core.leftandmain.js' ) ; }
|
Add additional requirements from a LeftAndMain specific class and globally
|
59,079
|
protected function respondWithMessage ( $ success = true , $ message = '' , $ code = 0 ) { if ( ! $ message ) { if ( $ success ) { $ message = rawurlencode ( _t ( 'CMSMain.ACTION_COMPLETE' , 'Done' ) ) ; } else { $ message = rawurlencode ( _t ( 'CMSMain.ACTION_FAILED' , 'Could not complete action' ) ) ; } } if ( ! $ code ) { $ code = $ success ? 200 : 400 ; } $ this -> owner -> Response -> setStatusCode ( $ code ) ; $ this -> owner -> Response -> addHeader ( 'X-Status' , $ message ) ; return $ this -> owner -> getResponseNegotiator ( ) -> respond ( $ this -> owner -> Request , [ 'SiteTree' => function ( ) { } ] ) ; }
|
Respond with a message in LeftAndMain
|
59,080
|
public function EXE ( I_O $ IO ) { return $ IO -> _O ( $ IO -> I_ ( Type :: BOOL ) xor $ IO -> I_ ( Type :: BOOL ) ) ; }
|
Applies the XOR operator to a couple of booleans .
|
59,081
|
public function equals ( HostInterface $ host ) : bool { if ( $ this -> getIPAddress ( ) !== null && $ host -> getIPAddress ( ) !== null ) { return $ this -> getIPAddress ( ) -> equals ( $ host -> getIPAddress ( ) ) ; } return $ this -> getHostname ( ) -> equals ( $ host -> getHostname ( ) ) ; }
|
Returns true if the host equals other host false otherwise .
|
59,082
|
public function getHostname ( ) : HostnameInterface { if ( $ this -> myHostname !== null ) { return $ this -> myHostname ; } $ ipAddressParts = $ this -> myIpAddress -> getParts ( ) ; return Hostname :: fromParts ( [ strval ( $ ipAddressParts [ 3 ] ) , strval ( $ ipAddressParts [ 2 ] ) , strval ( $ ipAddressParts [ 1 ] ) , strval ( $ ipAddressParts [ 0 ] ) , 'in-addr' , ] , 'arpa' ) ; }
|
Returns the hostname of the host .
|
59,083
|
private static function myParse ( string $ host , ? HostnameInterface & $ hostname = null , ? IPAddressInterface & $ ipAddress = null , ? string & $ error = null ) : bool { if ( $ host === '' ) { $ error = 'Host "' . $ host . '" is empty.' ; return false ; } try { $ hostname = Hostname :: parse ( $ host ) ; } catch ( HostnameInvalidArgumentException $ e ) { $ error = 'Host "' . $ host . '" is invalid: ' . $ e -> getMessage ( ) ; $ ipAddress = IPAddress :: tryParse ( $ host ) ; if ( $ ipAddress === null ) { return false ; } } return true ; }
|
Tries to parse a host and returns the result or error text .
|
59,084
|
public function getConnection ( array $ params , $ type ) { if ( $ type == 'S' ) { $ host = ( ! empty ( $ params [ 'num_ip' ] ) ) ? $ params [ 'num_ip' ] : '127.0.0.1' ; $ community = ( ! empty ( $ params [ 'des_snmp_community' ] ) ) ? $ params [ 'des_snmp_community' ] : 'public' ; $ version = ( ! empty ( $ params [ 'des_snmp_version' ] ) ) ? $ params [ 'des_snmp_version' ] : '2c' ; $ seclevel = ( ! empty ( $ params [ 'des_snmp_sec_level' ] ) ) ? $ params [ 'des_snmp_sec_level' ] : 'noAuthNoPriv' ; $ authprotocol = ( ! empty ( $ params [ 'des_snmp_auth_protocol' ] ) ) ? $ params [ 'des_snmp_auth_protocol' ] : 'MD5' ; $ authpassphrase = ( ! empty ( $ params [ 'des_snmp_auth_passphrase' ] ) ) ? $ params [ 'des_snmp_auth_passphrase' ] : 'None' ; $ privprotocol = ( ! empty ( $ params [ 'des_snmp_priv_protocol' ] ) ) ? $ params [ 'des_snmp_priv_protocol' ] : 'DES' ; $ privpassphrase = ( ! empty ( $ params [ 'des_snmp_priv_passphrase' ] ) ) ? $ params [ 'des_snmp_priv_passphrase' ] : 'None' ; $ connection = new \ Cityware \ Snmp \ SNMP ( $ host , $ community , $ version , $ seclevel , $ authprotocol , $ authpassphrase , $ privprotocol , $ privpassphrase ) ; $ connection -> setSecLevel ( 3 ) ; $ connection -> disableCache ( ) ; $ this -> setSnmpCon ( $ connection ) ; } else if ( $ type == 'W' ) { $ host = ( ! empty ( $ params [ 'num_ip' ] ) ) ? $ params [ 'num_ip' ] : '127.0.0.1' ; $ username = ( ! empty ( $ params [ 'des_wmi_user' ] ) ) ? $ params [ 'des_wmi_user' ] : null ; $ password = ( ! empty ( $ params [ 'des_wmi_password' ] ) ) ? $ params [ 'des_wmi_password' ] : null ; $ domain = ( ! empty ( $ params [ 'des_wmi_domain' ] ) ) ? $ params [ 'des_wmi_domain' ] : null ; $ wmi = new \ Cityware \ Wmi \ Wmi ( $ host , $ username , $ password , $ domain ) ; $ connection = $ wmi -> connect ( 'root\\cimv2' ) ; $ this -> setWmiCon ( $ connection ) ; } return $ connection ; }
|
Return connection base type device
|
59,085
|
public function view ( UserPolicy $ user , Portfolio $ portfolio ) { if ( $ user -> canDo ( 'portfolio.portfolio.view' ) && $ user -> isAdmin ( ) ) { return true ; } return $ portfolio -> user_id == user_id ( ) && $ portfolio -> user_type == user_type ( ) ; }
|
Determine if the given user can view the portfolio .
|
59,086
|
public function destroy ( UserPolicy $ user , Portfolio $ portfolio ) { return $ portfolio -> user_id == user_id ( ) && $ portfolio -> user_type == user_type ( ) ; }
|
Determine if the given user can delete the given portfolio .
|
59,087
|
public function restoreLoginFromCookie ( ) { if ( ! $ this -> cookieIsSet ( ) ) { return false ; } $ fields = $ this -> config ( 'fields' ) ; $ cookieKey = $ this -> config ( 'cookieKey' ) ; $ loginData = [ ] ; foreach ( $ fields as $ field ) { if ( $ this -> Cookie -> check ( "$cookieKey.$field" ) ) { $ loginData [ $ field ] = $ this -> Cookie -> read ( "$cookieKey.$field" ) ; } } $ controller = $ this -> _registry -> getController ( ) ; $ tempRequest = $ controller -> request -> data ; $ controller -> request -> data = $ loginData ; $ user = $ controller -> Auth -> identify ( ) ; $ controller -> request -> data = $ tempRequest ; if ( $ user ) { $ controller -> Auth -> setUser ( $ user ) ; return true ; } return false ; }
|
Logs the user in using cookie
|
59,088
|
public function setCookie ( $ data = [ ] ) { $ controller = $ this -> _registry -> getController ( ) ; if ( empty ( $ data ) ) { $ data = $ controller -> request -> data ; } if ( empty ( $ data ) ) { $ data = $ controller -> Auth -> user ( ) ; } if ( empty ( $ data ) ) { return false ; } $ fields = $ this -> config ( 'fields' ) ; $ cookieKey = $ this -> config ( 'cookieKey' ) ; foreach ( $ fields as $ field ) { if ( isset ( $ data [ $ field ] ) && ! empty ( $ data [ $ field ] ) ) { $ this -> Cookie -> write ( "$cookieKey.$field" , $ data [ $ field ] ) ; } } return true ; }
|
Sets the cookie with the passed data request data or session data
|
59,089
|
public function addData ( $ mixedData ) { if ( false === isset ( $ this -> cases [ $ this -> currentCaseTitle ] ) ) { throw new \ UnexpectedValueException ( sprintf ( 'You cannot add data - you have to add a case first by using %s->addCase().' , __CLASS__ ) ) ; } $ this -> cases [ $ this -> currentCaseTitle ] [ $ this -> getParamTitle ( ) ] = $ mixedData ; return $ this ; }
|
Add data to current case
|
59,090
|
public function rule ( $ str_to_change , $ str_new ) { if ( ! is_scalar ( $ str_to_change ) || ! is_scalar ( $ str_new ) ) { throw new \ InvalidArgumentException ( 'New rule to replace character must be two valid string or scalar value.' ) ; } if ( strlen ( $ str_new ) > 0 ) { if ( preg_match ( '/[^a-z0-9-]/' , ( string ) $ str_new ) ) { throw new \ InvalidArgumentException ( 'Replacement string contains not allowed characters!' ) ; } } $ this -> arr_rules [ ( string ) $ str_to_change ] = ( string ) $ str_new ; return $ this ; }
|
Adds custom rule to replace some characters .
|
59,091
|
public function value ( $ str ) { if ( ! is_scalar ( $ str ) ) { throw new \ InvalidArgumentException ( 'Argument for constructor of' . __CLASS__ . ' must be a scalar!' ) ; } if ( ! extension_loaded ( 'mbstring' ) ) { trigger_error ( 'You have not multibyte extension, this may create weird result!' , E_USER_WARNING ) ; $ this -> str = strtolower ( ( string ) $ str ) ; } else { $ this -> str = mb_strtolower ( ( string ) $ str , 'UTF-8' ) ; } $ this -> str_out = null ; return $ this ; }
|
New value to slugify using current slug object configuration .
|
59,092
|
public function render ( ) { if ( is_null ( $ this -> str_out ) ) { $ str_prov = $ this -> str ; if ( count ( $ this -> arr_rules ) ) { $ str_prov = strtr ( $ str_prov , $ this -> arr_rules ) ; } $ str_prov = transliterator_transliterate ( "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();" , $ str_prov ) ; $ str = trim ( preg_replace ( '/[^a-z0-9-]+/' , '-' , $ str_prov ) , '-' ) ; if ( ! $ this -> use_history ) { $ this -> str_out = $ str ; return $ this -> str_out ; } if ( ! in_array ( $ str , self :: $ arr_history ) ) { self :: $ arr_history [ ] = $ str ; $ this -> str_out = $ str ; } else { $ int_start = 2 ; $ str_prov = $ str . '-' . $ int_start ; while ( in_array ( $ str_prov , self :: $ arr_history ) ) { $ str_prov = $ str . '-' . $ int_start ; $ int_start ++ ; } if ( ! in_array ( $ str_prov , self :: $ arr_history ) ) { self :: $ arr_history [ ] = $ str_prov ; $ this -> str_out = $ str_prov ; } } return $ this -> str_out ; } return $ this -> str_out ; }
|
Renders original string as a slug .
|
59,093
|
protected function generateIdentifier ( ) { if ( extension_loaded ( 'mongodb' ) ) { $ newObjectId = new \ MongoDB \ BSON \ ObjectID ( ) ; $ uuid = $ newObjectId -> __toString ( ) ; } else { $ uuid = bin2hex ( openssl_random_pseudo_bytes ( 12 ) ) ; } return $ uuid ; }
|
Generate a UUID .
|
59,094
|
public function parse ( ) : array { $ buffer = $ this -> routing_rule ; $ section_list_set = [ ] ; $ current_list = [ ] ; do { $ pos = strpos ( substr ( $ buffer , 1 ) , '/' ) ; $ section = $ pos !== false ? substr ( $ buffer , 1 , $ pos ) : substr ( $ buffer , 1 ) ; $ buffer = $ pos !== false ? substr ( $ buffer , $ pos + 1 ) : '' ; $ length = strlen ( $ section ) ; if ( $ length === 0 ) { $ current_list [ ] = new class implements EmptyRoutingPathInterface { } ; if ( ! empty ( $ buffer ) ) { throw new RoutingRuleParseException ( $ this -> routing_rule , "Empty routing section is allowed only for last element" ) ; } break ; } $ first = $ section [ 0 ] ; $ last = $ section [ $ length - 1 ] ; if ( $ first === '[' && $ last === ']' ) { $ section_list_set [ ] = $ current_list + [ '()' ] ; $ inside = substr ( $ section , 1 , $ length - 2 ) ; if ( $ inside [ 0 ] === ':' ) { $ current_list [ ] = self :: parseVariablePattern ( $ inside ) ; } else { $ current_list [ ] = $ inside ; } } else if ( $ first === ':' ) { $ current_list [ ] = self :: parseVariablePattern ( $ section ) ; } else { $ current_list [ ] = $ section ; } } while ( ! empty ( $ buffer ) ) ; $ section_list_set [ ] = $ current_list ; return $ section_list_set ; }
|
Parse routing rule
|
59,095
|
private static function parseVariablePattern ( string $ patern ) : array { static $ supported_types = [ 'string' , 'integer' , 'int' , 'float' , 'double' , 'boolean' , 'bool' , ] ; $ tmp = explode ( ':' , $ patern ) ; $ varname = $ tmp [ 1 ] ?? null ; $ regex = $ tmp [ 2 ] ?? null ; $ type = $ tmp [ 3 ] ?? null ; if ( ! preg_match ( '/^[a-zA-Z_][0-9a-zA-Z_]*(\[\])?$/' , $ varname ) ) { throw new RoutingRuleParseException ( $ patern , "illegal variable name: $varname" ) ; } if ( $ regex && ! preg_match ( '/^[0-9a-zA-Z@#_=%\\\^\$\.\[\]\|\(\)\?\*\+\{\}\^\-]*$/' , $ regex ) ) { throw new RoutingRuleParseException ( $ patern , "illegal variable regex pattern: $regex" ) ; } if ( $ type && ! in_array ( $ type , $ supported_types ) ) { throw new RoutingRuleParseException ( $ patern , "unsupported variable type: $type" ) ; } $ res = [ ] ; if ( $ varname ) { $ res [ 'varname' ] = $ varname ; } if ( $ regex ) { $ res [ 'regex' ] = $ regex ; } if ( $ type ) { $ res [ 'type' ] = $ type ; } return $ res ; }
|
Parse variable pattern
|
59,096
|
public function addMenu ( array $ menu , string $ namespace = null , int $ position = null ) : void { foreach ( $ menu as $ name => $ row ) { if ( ! isset ( $ row [ 'link' ] ) ) { throw new InvalidArgumentException ( 'First level of Menu must have set link' ) ; } else { $ link = new Link ( $ name , $ row [ 'link' ] , isset ( $ row [ 'arguments' ] ) ? $ row [ 'arguments' ] : [ ] ) ; $ link -> setNamespace ( $ namespace ) ; if ( ! empty ( $ row [ 'toBlank' ] ) ) { $ link -> toBlank ( ) ; } $ this -> addItem ( $ link , $ position ) ; $ this -> attachLink ( $ link ) ; unset ( $ row [ 'link' ] , $ row [ 'arguments' ] , $ row [ 'toBlank' ] ) ; $ this -> addMenuItems ( $ link , $ row ) ; } } }
|
Prida do Menu polozky
|
59,097
|
private function addMenuItems ( Item $ parent , array $ menu ) : void { foreach ( $ menu as $ name => $ item ) { if ( array_key_exists ( 'link' , $ item ) ) { $ link = $ parent -> addLink ( $ name , $ item [ 'link' ] , isset ( $ item [ 'arguments' ] ) ? $ item [ 'arguments' ] : [ ] ) ; if ( ! empty ( $ item [ 'toBlank' ] ) ) { $ link -> toBlank ( ) ; } if ( ! empty ( $ item [ 'count' ] ) ) { $ this -> setCount ( $ link , $ item [ 'count' ] ) ; } unset ( $ item [ 'link' ] , $ item [ 'arguments' ] , $ item [ 'toBlank' ] , $ item [ 'count' ] ) ; } else { $ link = $ parent -> addGroup ( $ name ) ; } $ this -> addMenuItems ( $ link , $ item ) ; } }
|
Prida polozky do Menu
|
59,098
|
public function setBaseUrl ( string $ name , string $ link ) : void { $ this -> baseUrl = new \ stdClass ; $ this -> baseUrl -> name = $ name ; $ this -> baseUrl -> link = $ link ; }
|
Nastavi korenovou url
|
59,099
|
public function isLinkAllowed ( string $ link ) : bool { $ this -> prepareLink ( $ link ) ; return $ this -> links [ $ link ] -> allowed ; }
|
Je aktualni stranka povolena
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.