idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
21,900
protected function getTableDatabase ( $ table ) { if ( ! array_key_exists ( $ table , $ this -> tables ) ) { return false ; } $ database = $ this -> tables [ $ table ] ; if ( is_array ( $ database ) ) { if ( array_key_exists ( $ this -> mode , $ database ) ) { $ database = $ database [ $ this -> mode ] ; } else { $ database = $ database [ "default" ] ; } } return $ database ; }
Get the database that should be used for this table
21,901
protected function getTableName ( $ table ) { $ database = $ this -> getTableDatabase ( $ table ) ; if ( $ database ) { $ database = $ this -> quoteField ( $ database ) ; if ( substr ( $ this -> mode , 0 , 5 ) === "mssql" ) { $ database .= ".dbo" ; } return $ database . "." . $ this -> quoteField ( $ table ) ; } if ( strpos ( $ table , "." ) !== false ) { return $ table ; } return $ this -> quoteField ( $ table ) ; }
Get the full table name including the database .
21,902
protected function quoteChars ( & $ query ) { $ checked = [ ] ; $ chars = $ this -> quoteChars [ $ this -> mode ] ; if ( is_array ( $ chars ) ) { $ newFrom = $ chars [ 0 ] ; $ newTo = $ chars [ 1 ] ; } else { $ newFrom = $ chars ; $ newTo = $ chars ; } foreach ( $ this -> quoteChars as $ mode => $ chars ) { if ( $ mode == $ this -> mode ) { continue ; } if ( is_array ( $ chars ) ) { $ oldFrom = $ chars [ 0 ] ; $ oldTo = $ chars [ 1 ] ; } else { $ oldFrom = $ chars ; $ oldTo = $ chars ; } if ( $ oldFrom == $ newFrom && $ oldTo == $ newTo ) { continue ; } $ match = preg_quote ( $ oldFrom ) . "([^" . preg_quote ( $ oldTo ) . "]*)" . preg_quote ( $ oldTo ) ; if ( in_array ( $ match , $ checked , true ) ) { continue ; } $ checked [ ] = $ match ; $ this -> modifyQuery ( $ query , function ( $ part ) use ( $ match , $ newFrom , $ newTo ) { return preg_replace ( "/" . $ match . "/" , $ newFrom . "$1" . $ newTo , $ part ) ; } ) ; } }
Replace any quote characters used to the appropriate type for the current mode This function attempts to ignore any instances that are surrounded by single quotes as these should not be converted
21,903
protected function functions ( & $ query ) { switch ( $ this -> mode ) { case "mysql" : case "odbc" : case "sqlite" : $ query = preg_replace ( "/\bISNULL\(/" , "IFNULL(" , $ query ) ; break ; case "postgres" : case "redshift" : $ query = preg_replace ( "/\bI[FS]NULL\(/" , "COALESCE(" , $ query ) ; break ; case "mssql" : case "mssqlsrv" : $ query = preg_replace ( "/\bIFNULL\(/" , "ISNULL(" , $ query ) ; break ; } switch ( $ this -> mode ) { case "mysql" : case "postgres" : case "redshift" : case "odbc" : case "mssql" : case "mssqlsrv" : $ query = preg_replace ( "/\bSUBSTR\(/" , "SUBSTRING(" , $ query ) ; break ; case "sqlite" : $ query = preg_replace ( "/\bSUBSTRING\(/" , "SUBSTR(" , $ query ) ; break ; } switch ( $ this -> mode ) { case "postgres" : case "redshift" : $ query = preg_replace ( "/\FROM_UNIXTIME\(([^,\)]+),(\s*)([^\)]+)\)/" , "TO_CHAR(ABSTIME($1), $3)" , $ query ) ; break ; } }
Replace any non - standard functions with the appropriate function for the current mode
21,904
protected function limit ( & $ query ) { switch ( $ this -> mode ) { case "mysql" : case "postgres" : case "redshift" : case "sqlite" : $ query = preg_replace ( "/\bFETCH\s+FIRST\s+([0-9]+)\s+ROW(S?)\s+ONLY\b/i" , "\nLIMIT $1\n" , $ query ) ; break ; case "odbc" : $ query = preg_replace ( "/\bLIMIT\s+([0-9]+)\b/i" , "\nFETCH FIRST $1 ROWS ONLY\n" , $ query ) ; break ; } }
Convert any limit usage Doesn t work with the mssql variety
21,905
protected function paramArrays ( & $ query , & $ params ) { if ( ! is_array ( $ params ) ) { return ; } $ newParams = [ ] ; $ this -> modifyQuery ( $ query , function ( $ part ) use ( & $ params , & $ newParams ) { $ newPart = "" ; $ tmpPart = $ part ; while ( count ( $ params ) > 0 ) { $ pos = strpos ( $ tmpPart , "?" ) ; if ( $ pos === false ) { break ; } $ val = array_shift ( $ params ) ; $ newPart .= substr ( $ tmpPart , 0 , $ pos ) ; $ tmpPart = substr ( $ tmpPart , $ pos + 1 ) ; if ( ! is_array ( $ val ) ) { $ newPart .= "?" ; $ newParams [ ] = $ val ; continue ; } if ( count ( $ val ) < 2 ) { $ newPart = preg_replace ( "/\s*\bNOT\s+IN\s*$/i" , "<>" , $ newPart ) ; $ newPart = preg_replace ( "/\s*\bIN\s*$/i" , "=" , $ newPart ) ; $ newPart .= "?" ; $ newParams [ ] = reset ( $ val ) ; continue ; } $ markers = [ ] ; foreach ( $ val as $ v ) { $ markers [ ] = "?" ; $ newParams [ ] = $ v ; } $ newPart .= "(" . implode ( "," , $ markers ) . ")" ; } $ newPart .= $ tmpPart ; return $ newPart ; } ) ; $ params = $ newParams ; }
If any of the parameters are arrays then convert the single marker from the query to handle them
21,906
protected function namedParams ( & $ query , & $ params ) { if ( ! is_array ( $ params ) ) { return ; } $ pattern = "a-zA-Z0-9_" ; if ( ! preg_match ( "/\?([" . $ pattern . "]+)/" , $ query ) ) { return ; } $ oldParams = $ params ; $ params = [ ] ; reset ( $ oldParams ) ; $ this -> modifyQuery ( $ query , function ( $ part ) use ( & $ params , & $ oldParams , $ pattern ) { return preg_replace_callback ( "/\?([" . $ pattern . "]*)([^" . $ pattern . "]|$)/" , function ( $ match ) use ( & $ params , & $ oldParams ) { if ( $ key = $ match [ 1 ] ) { $ params [ ] = $ oldParams [ $ key ] ; } else { $ params [ ] = current ( $ oldParams ) ; next ( $ oldParams ) ; } return "?" . $ match [ 2 ] ; } , $ part ) ; } ) ; }
If the params array uses named keys then convert them to the regular markers
21,907
public function cache ( $ query , array $ params = null , $ timeout = null ) { $ options = array_merge ( $ this -> cacheOptions , [ "sql" => $ this , "query" => $ query , "params" => $ params , ] ) ; if ( $ timeout ) { $ options [ "timeout" ] = $ timeout ; } return new Cache ( $ options ) ; }
Convienience method to create a cached query instance
21,908
public function where ( $ where , & $ params ) { if ( ! is_array ( $ where ) ) { throw new \ Exception ( "Invalid where clause specified, must be an array" ) ; } $ params = Helper :: toArray ( $ params ) ; $ query = "" ; $ andFlag = false ; foreach ( $ where as $ field => $ value ) { if ( $ andFlag ) { $ query .= "AND " ; } else { $ andFlag = true ; } $ query .= $ this -> quoteField ( $ field ) ; if ( is_array ( $ value ) ) { $ helperMap = [ "<" => "lessThan" , "<=" => "lessThanOrEqualTo" , ">" => "greaterThan" , ">=" => "greaterThanOrEqualTo" , "=" => "equals" , "<>" => "notEqualTo" , ] ; $ clause = ( string ) reset ( $ value ) ; if ( count ( $ value ) === 2 && isset ( $ helperMap [ $ clause ] ) ) { $ method = $ helperMap [ $ clause ] ; $ val = next ( $ value ) ; trigger_error ( "Using arrays for complex where clauses is deprecated in favour of the helper methods, eg Sql::" . $ method . "(" . $ val . ")" , E_USER_DEPRECATED ) ; $ value = static :: $ method ( $ val ) ; } else { $ value = static :: in ( $ value ) ; } } if ( ! is_object ( $ value ) ) { $ value = static :: equals ( $ value ) ; } $ query .= " " . $ value -> getClause ( ) . " " ; foreach ( $ value -> getValues ( ) as $ val ) { $ params [ ] = $ val ; } } return $ query ; }
Convert an array of parameters into a valid where clause
21,909
public function fieldSelect ( $ table , $ fields , $ where , $ orderBy = null ) { $ table = $ this -> getTableName ( $ table ) ; $ query = "SELECT " ; if ( substr ( $ this -> mode , 0 , 5 ) === "mssql" ) { $ query .= "TOP 1 " ; } $ query .= $ this -> selectFields ( $ fields ) ; $ query .= " FROM " . $ table . " " ; $ params = null ; if ( $ where !== self :: NO_WHERE_CLAUSE ) { $ query .= "WHERE " . $ this -> where ( $ where , $ params ) ; } if ( $ orderBy ) { $ query .= $ this -> orderBy ( $ orderBy ) . " " ; } switch ( $ this -> mode ) { case "mysql" : case "postgres" : case "redshift" : case "sqlite" : $ query .= "LIMIT 1" ; break ; case "odbc" : $ query .= "FETCH FIRST 1 ROW ONLY" ; break ; } return $ this -> query ( $ query , $ params ) -> fetch ( ) ; }
Grab specific fields from the first row from a table using the standard select statement
21,910
public function fieldSelectAll ( $ table , $ fields , $ where , $ orderBy = null ) { $ table = $ this -> getTableName ( $ table ) ; $ query = "SELECT " ; $ query .= $ this -> selectFields ( $ fields ) ; $ query .= " FROM " . $ table . " " ; $ params = null ; if ( $ where !== self :: NO_WHERE_CLAUSE ) { $ query .= "WHERE " . $ this -> where ( $ where , $ params ) ; } if ( $ orderBy ) { $ query .= $ this -> orderBy ( $ orderBy ) . " " ; } return $ this -> query ( $ query , $ params ) ; }
Create a standard select statement and return the result
21,911
public function insertOrUpdate ( $ table , array $ set , array $ where ) { if ( $ this -> select ( $ table , $ where ) ) { $ result = $ this -> update ( $ table , $ set , $ where ) ; } else { $ params = array_merge ( $ where , $ set ) ; $ result = $ this -> insert ( $ table , $ params ) ; } return $ result ; }
Insert a new record into a table unless it already exists in which case update it
21,912
public function orderBy ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = explode ( "," , $ fields ) ; } $ orderBy = "" ; foreach ( $ fields as $ field ) { if ( ! $ field = trim ( $ field ) ) { continue ; } if ( ! $ orderBy ) { $ orderBy = "ORDER BY " ; } else { $ orderBy .= ", " ; } if ( strpos ( $ field , " " ) ) { $ orderBy .= $ field ; } else { $ orderBy .= $ this -> quoteField ( $ field ) ; } } return $ orderBy ; }
Create an order by clause from a string of fields or an array of fields
21,913
protected function quoteField ( $ field ) { if ( $ this -> mode == "odbc" ) { return $ field ; } $ field = trim ( $ field ) ; $ chars = $ this -> quoteChars [ $ this -> mode ] ; if ( is_array ( $ chars ) ) { $ from = $ chars [ 0 ] ; $ to = $ chars [ 1 ] ; } else { $ from = $ chars ; $ to = $ chars ; } $ quoted = $ from . $ field . $ to ; return $ quoted ; }
Quote a field with the appropriate characters for this mode
21,914
protected function quoteTable ( $ table ) { if ( $ this -> mode == "odbc" ) { return $ table ; } $ table = trim ( $ table ) ; if ( in_array ( $ this -> mode , [ "postgres" , "redshift" ] , true ) ) { $ this -> connect ( ) ; return pg_escape_identifier ( $ this -> server , $ table ) ; } $ chars = $ this -> quoteChars [ $ this -> mode ] ; if ( is_array ( $ chars ) ) { $ from = $ chars [ 0 ] ; $ to = $ chars [ 1 ] ; } else { $ from = $ chars ; $ to = $ chars ; } $ quoted = $ from . $ table . $ to ; return $ quoted ; }
Quote a table with the appropriate characters for this mode
21,915
public function startTransaction ( ) { $ this -> connect ( ) ; switch ( $ this -> mode ) { case "mysql" : $ result = $ this -> server -> autocommit ( false ) ; break ; case "postgres" : $ result = $ this -> query ( "SET AUTOCOMMIT = OFF" ) ; break ; case "redshift" : $ result = $ this -> query ( "START TRANSACTION" ) ; break ; case "odbc" : $ result = odbc_autocommit ( $ this -> server , false ) ; break ; default : throw new \ Exception ( "startTransaction() not supported in this mode (" . $ this -> mode . ")" ) ; } if ( ! $ result ) { $ this -> error ( ) ; } $ this -> transaction = true ; return true ; }
Start a transaction by turning autocommit off
21,916
public function endTransaction ( $ commit ) { if ( $ commit ) { $ result = $ this -> commit ( ) ; } else { $ result = $ this -> rollback ( ) ; } switch ( $ this -> mode ) { case "mysql" : if ( ! $ this -> server -> autocommit ( true ) ) { $ result = false ; } break ; case "postgres" : $ result = $ this -> query ( "SET AUTOCOMMIT = ON" ) ; break ; case "redshift" : break ; case "odbc" : if ( ! odbc_autocommit ( $ this -> server , true ) ) { $ result = false ; } break ; default : throw new \ Exception ( "endTransaction() not supported in this mode (" . $ this -> mode . ")" ) ; } if ( ! $ result ) { $ this -> error ( ) ; } $ this -> transaction = false ; return true ; }
End a transaction by either committing changes made or reverting them
21,917
public function commit ( ) { switch ( $ this -> mode ) { case "mysql" : $ result = $ this -> server -> commit ( ) ; break ; case "postgres" : case "redshift" : $ result = $ this -> query ( "COMMIT" ) ; break ; case "odbc" : $ result = odbc_commit ( $ this -> server ) ; break ; default : throw new \ Exception ( "commit() not supported in this mode (" . $ this -> mode . ")" ) ; } if ( ! $ result ) { $ this -> error ( ) ; } return true ; }
Commit queries without ending the transaction
21,918
public function rollback ( ) { switch ( $ this -> mode ) { case "mysql" : $ result = $ this -> server -> rollback ( ) ; break ; case "postgres" : case "redshift" : $ result = $ this -> query ( "ROLLBACK" ) ; break ; case "odbc" : $ result = odbc_rollback ( $ this -> server ) ; break ; default : throw new \ Exception ( "rollback() not supported in this mode (" . $ this -> mode . ")" ) ; } if ( ! $ result ) { $ this -> error ( ) ; } return true ; }
Rollback queries without ending the transaction
21,919
public function lockTables ( $ tables ) { $ this -> unlockTables ( ) ; $ tables = Helper :: toArray ( $ tables ) ; if ( $ this -> mode == "odbc" ) { foreach ( $ tables as $ table ) { $ table = $ this -> getTableName ( $ table ) ; $ query = "LOCK TABLE " . $ table . " IN EXCLUSIVE MODE ALLOW READ" ; $ this -> query ( $ query ) ; } return true ; } foreach ( $ tables as & $ table ) { $ table = $ this -> getTableName ( $ table ) ; } unset ( $ table ) ; if ( $ this -> mode == "mysql" ) { $ query = "LOCK TABLES " . implode ( "," , $ tables ) . " WRITE" ; return $ this -> query ( $ query ) ; } if ( in_array ( $ this -> mode , [ "postgres" , "redshift" ] , true ) ) { $ query = "LOCK TABLE " . implode ( "," , $ tables ) . " IN EXCLUSIVE MODE" ; return $ this -> query ( $ query ) ; } throw new \ Exception ( "lockTables() not supported in this mode (" . $ this -> mode . ")" ) ; }
Lock some tables for exlusive write access But allow read access to other processes
21,920
public function unlockTables ( ) { switch ( $ this -> mode ) { case "mysql" : $ query = "UNLOCK TABLES" ; break ; case "postgres" : case "redshift" : case "odbc" : $ query = "COMMIT" ; break ; default : throw new \ Exception ( "unlockTables() not supported in this mode (" . $ this -> mode . ")" ) ; } return $ this -> query ( $ query ) ; }
Unlock all tables previously locked
21,921
public function disconnect ( ) { if ( ! $ this -> connected || ! $ this -> server || ( $ this -> mode == "mysql" && $ this -> server -> connect_error ) ) { return false ; } $ result = false ; switch ( $ this -> mode ) { case "mysql" : case "sqlite" : $ result = $ this -> server -> close ( ) ; break ; case "postgres" : case "redshift" : $ result = pg_close ( $ this -> server ) ; break ; case "odbc" : odbc_close ( $ this -> server ) ; $ result = true ; break ; case "mssql" : $ result = mssql_close ( $ this -> server ) ; break ; case "mssqlsrv" : $ result = sqlsrv_close ( $ this -> server ) ; break ; } if ( $ result ) { $ this -> connected = false ; } return $ result ; }
Close the sql connection
21,922
public function redirectVerified ( $ code , $ destination = null , $ parameters = [ ] ) : void { if ( ! is_numeric ( $ code ) ) { $ parameters = is_array ( $ destination ) ? $ destination : array_slice ( func_get_args ( ) , 1 ) ; $ destination = $ code ; $ code = null ; } elseif ( ! is_array ( $ parameters ) ) { $ parameters = array_slice ( func_get_args ( ) , 2 ) ; } $ presenter = $ this -> getPresenter ( ) ; $ link = $ presenter -> createRequest ( $ this , $ destination , $ parameters , 'redirect' ) ; if ( $ presenter -> getVerifier ( ) -> isLinkVerified ( $ presenter -> getLastCreatedRequest ( ) , $ this ) ) { $ presenter -> redirectUrl ( $ link , $ code ) ; } }
Redirects to destination if all the requirements are met .
21,923
public function linkVerified ( string $ destination , array $ args = [ ] ) : ? string { $ link = $ this -> link ( $ destination , $ args ) ; $ presenter = $ this -> getPresenter ( ) ; return $ presenter -> getVerifier ( ) -> isLinkVerified ( $ presenter -> getLastCreatedRequest ( ) , $ this ) ? $ link : null ; }
Returns link to destination but only if all its requirements are met .
21,924
public function getComponentVerified ( string $ name ) : ? IComponent { $ presenter = $ this -> getPresenter ( ) ; return $ presenter -> getVerifier ( ) -> isComponentVerified ( $ name , $ presenter -> getRequest ( ) , $ this ) ? $ this -> getComponent ( $ name ) : null ; }
Returns specified component but only if all its requirements are met .
21,925
protected function attached ( $ component ) : void { if ( $ component instanceof Presenter ) { $ this -> onPresenter ( $ component ) ; } parent :: attached ( $ component ) ; }
Calls onPresenter event which is used to verify component properties .
21,926
public function getRules ( Reflector $ reflection ) : array { if ( $ reflection instanceof ReflectionMethod ) { $ key = $ reflection -> getDeclaringClass ( ) -> getName ( ) . '::' . $ reflection -> getName ( ) ; } elseif ( $ reflection instanceof ReflectionClass ) { $ key = $ reflection -> getName ( ) ; } elseif ( $ reflection instanceof ReflectionProperty ) { $ key = $ reflection -> getDeclaringClass ( ) -> getName ( ) . '::$' . $ reflection -> getName ( ) ; } else { throw new InvalidArgumentException ( 'Reflection must be an instance of either ReflectionMethod, ReflectionClass or ReflectionProperty.' ) ; } if ( ! isset ( $ this -> cache [ $ key ] ) ) { $ this -> cache [ $ key ] = $ this -> ruleProvider -> getRules ( $ reflection ) ; } return $ this -> cache [ $ key ] ; }
Returns rules that are required for given reflection .
21,927
public function checkRules ( array $ rules , Request $ request , ? string $ component = null ) : void { foreach ( $ rules as $ rule ) { $ class = get_class ( $ rule ) ; $ handler = ( $ this -> handlerResolver ) ( $ class ) ; if ( ! $ handler instanceof RuleHandlerInterface ) { throw new UnexpectedTypeException ( "No rule handler found for type '$class'." ) ; } $ handler -> checkRule ( $ rule , $ request , $ component ) ; } }
Checks whether the given rules are met .
21,928
public function checkReflection ( Reflector $ reflection , Request $ request , ? string $ component = null ) : void { $ rules = $ this -> getRules ( $ reflection ) ; $ this -> checkRules ( $ rules , $ request , $ component ) ; }
Checks whether all rules of the given reflection are met .
21,929
public function isLinkVerified ( Request $ request , Component $ component ) : bool { try { $ parameters = $ request -> getParameters ( ) ; if ( isset ( $ parameters [ Presenter :: SIGNAL_KEY ] ) ) { $ signalId = $ parameters [ Presenter :: SIGNAL_KEY ] ; if ( ! is_string ( $ signalId ) ) { throw new InvalidArgumentException ( 'Signal name is not a string.' ) ; } $ pos = strrpos ( $ signalId , '-' ) ; if ( $ pos !== false ) { $ name = $ component -> getUniqueId ( ) ; if ( $ name !== substr ( $ signalId , 0 , $ pos ) ) { throw new InvalidArgumentException ( "Wrong signal receiver, expected '" . substr ( $ signalId , 0 , $ pos ) . "' component but '$name' was given." ) ; } $ reflection = new ComponentReflection ( $ component ) ; $ signal = substr ( $ signalId , $ pos + 1 ) ; } else { $ name = null ; $ presenter = $ request -> getPresenterName ( ) ; $ reflection = new ComponentReflection ( $ this -> presenterFactory -> getPresenterClass ( $ presenter ) ) ; $ signal = $ signalId ; } $ method = 'handle' . $ signal ; if ( $ reflection -> hasCallableMethod ( $ method ) ) { $ this -> checkReflection ( $ reflection -> getMethod ( $ method ) , $ request , $ name ) ; } } else { $ presenter = $ request -> getPresenterName ( ) ; $ reflection = new ComponentReflection ( $ this -> presenterFactory -> getPresenterClass ( $ presenter ) ) ; $ this -> checkReflection ( $ reflection , $ request ) ; $ action = $ parameters [ Presenter :: ACTION_KEY ] ; $ method = 'action' . $ action ; if ( $ reflection -> hasCallableMethod ( $ method ) ) { $ this -> checkReflection ( $ reflection -> getMethod ( $ method ) , $ request ) ; } } } catch ( VerificationException $ e ) { return false ; } return true ; }
Checks whether it is possible to run the given request .
21,930
public function isComponentVerified ( string $ name , Request $ request , Component $ parent ) : bool { $ reflection = new ComponentReflection ( $ parent ) ; $ method = 'createComponent' . ucfirst ( $ name ) ; if ( $ reflection -> hasMethod ( $ method ) ) { $ factory = $ reflection -> getMethod ( $ method ) ; try { $ this -> checkReflection ( $ factory , $ request , $ parent -> getParent ( ) !== null ? $ parent -> getUniqueId ( ) : null ) ; } catch ( VerificationException $ e ) { return false ; } } return true ; }
Checks whether the parent component can create the subcomponent with given name .
21,931
protected function addRouteToGroup ( \ MvcCore \ IRoute & $ route , $ routeName , $ groupName , $ prepend ) { if ( $ groupName === NULL ) { $ routesGroupsKey = '' ; } else { $ routesGroupsKey = $ groupName ; $ route -> SetGroupName ( $ groupName ) ; } if ( isset ( $ this -> routesGroups [ $ routesGroupsKey ] ) ) { $ groupRoutes = & $ this -> routesGroups [ $ routesGroupsKey ] ; } else { $ groupRoutes = [ ] ; $ this -> routesGroups [ $ routesGroupsKey ] = & $ groupRoutes ; } if ( $ prepend ) { $ newItem = [ $ routeName => $ route ] ; $ groupRoutes = $ newItem + $ groupRoutes ; } else { $ groupRoutes [ $ routeName ] = $ route ; } }
Add route instance into named routes group . Every routes group is chosen in routing moment by first parsed word from requested URL .
21,932
public function HasRoute ( $ routeOrRouteName ) { if ( is_string ( $ routeOrRouteName ) ) { return isset ( $ this -> routes [ $ routeOrRouteName ] ) ; } else { return ( isset ( $ this -> routes [ $ routeOrRouteName -> GetName ( ) ] ) || isset ( $ this -> routes [ $ routeOrRouteName -> GetControllerAction ( ) ] ) ) ; } }
Get TRUE if router has any route by given route name or FALSE if not .
21,933
public function RemoveRoute ( $ routeName ) { $ result = NULL ; if ( isset ( $ this -> routes [ $ routeName ] ) ) { $ result = $ this -> routes [ $ routeName ] ; unset ( $ this -> routes [ $ routeName ] ) ; $ this -> removeRouteFromGroup ( $ result , $ routeName ) ; $ controllerAction = $ result -> GetControllerAction ( ) ; if ( isset ( $ this -> urlRoutes [ $ routeName ] ) ) unset ( $ this -> urlRoutes [ $ routeName ] ) ; if ( isset ( $ this -> urlRoutes [ $ controllerAction ] ) ) unset ( $ this -> urlRoutes [ $ controllerAction ] ) ; $ currentRoute = & $ this -> currentRoute ; if ( $ currentRoute -> GetName ( ) === $ result -> GetName ( ) ) $ this -> currentRoute = NULL ; } if ( ! $ this -> routes && $ this -> preRouteMatchingHandler === NULL ) $ this -> anyRoutesConfigured = FALSE ; return $ result ; }
Remove route from router by given name and return removed route instance . If router has no route by given name NULL is returned .
21,934
public function & GetRoute ( $ routeName ) { if ( isset ( $ this -> routes [ $ routeName ] ) ) return $ this -> routes [ $ routeName ] ; return NULL ; }
Get configured \ MvcCore \ Route route instances by route name NULL if no route presented .
21,935
public function addFile ( $ file , $ resource = null ) { if ( ! file_exists ( $ file ) || ! is_file ( $ file ) ) { throw new \ Exception ( 'The configuration file ' . $ file . ' does not exist.' ) ; } else { if ( $ resource === null ) { $ resource = $ file ; } if ( ! array_key_exists ( $ resource , self :: $ parameters ) ) { self :: $ parameters [ $ resource ] = new ParameterBag ( ) ; } $ content = YamlParser :: parse ( file_get_contents ( $ file ) ) ; if ( $ content !== null ) { $ content = self :: parseImports ( $ content , $ resource ) ; $ content = self :: parseParameters ( $ content , $ resource ) ; self :: addConfig ( $ content , $ resource ) ; } } return self :: getInstance ( ) ; }
Parse . yml file and add it to slim .
21,936
public function addDirectory ( $ directory ) { if ( ! file_exists ( $ directory ) || ! is_dir ( $ directory ) ) { throw new \ Exception ( 'The configuration directory does not exist.' ) ; } else { if ( substr ( $ directory , - 1 ) != DIRECTORY_SEPARATOR ) { $ directory .= DIRECTORY_SEPARATOR ; } foreach ( glob ( $ directory . '*.yml' ) as $ file ) { self :: addFile ( $ file ) ; } } return self :: getInstance ( ) ; }
Parse . yml files in a given directory .
21,937
public function addParameters ( array $ parameters ) { self :: $ global_parameters = array_merge ( self :: $ global_parameters , $ parameters ) ; return self :: getInstance ( ) ; }
Adds global parameters for use by all resources .
21,938
protected function addConfig ( array $ content , $ resource ) { foreach ( $ content as $ key => $ value ) { $ parameterBag = self :: $ parameters [ $ resource ] ; $ value = $ parameterBag -> unescapeValue ( $ parameterBag -> resolveValue ( $ value ) ) ; if ( is_array ( $ value ) && ! is_numeric ( $ key ) ) { $ key = array ( $ key => $ value ) ; $ value = true ; } self :: $ slim -> config ( $ key , $ value ) ; } }
Resolves parameters and adds to Slim s config singleton .
21,939
protected function parseImports ( array $ content , $ resource ) { if ( isset ( $ content [ 'imports' ] ) ) { $ chdir = dirname ( $ resource ) ; foreach ( $ content [ 'imports' ] as $ import ) { self :: addFile ( $ chdir . DIRECTORY_SEPARATOR . $ import [ 'resource' ] , $ resource ) ; } unset ( $ content [ 'imports' ] ) ; } return $ content ; }
Parses the imports section of a resource and includes them .
21,940
public function ratingAction ( Request $ request ) { $ arrData = $ request -> request -> get ( 'data' ) ; $ fltValue = $ request -> request -> get ( 'rating' ) ; if ( ! ( $ arrData && $ arrData [ 'id' ] && $ arrData [ 'pid' ] && $ arrData [ 'item' ] ) ) { $ this -> bail ( 'Invalid request.' ) ; } $ objMetaModel = $ this -> factory -> getMetaModel ( $ this -> factory -> translateIdToMetaModelName ( $ arrData [ 'pid' ] ) ) ; if ( ! $ objMetaModel ) { $ this -> bail ( 'No MetaModel.' ) ; } $ objAttribute = $ objMetaModel -> getAttributeById ( $ arrData [ 'id' ] ) ; if ( ! $ objAttribute ) { $ this -> bail ( 'No Attribute.' ) ; } $ objAttribute -> addVote ( $ arrData [ 'item' ] , ( float ) $ fltValue , true ) ; return new Response ( ) ; }
Process an ajax request .
21,941
public function withAddedKeywords ( array $ keywords = [ ] ) : self { $ existing = array_map ( 'trim' , explode ( ',' , $ this -> getAttribute ( 'content' ) ? : '' ) ) ; $ new = array_merge ( $ existing , $ keywords ) ; return $ this -> withAttribute ( 'content' , implode ( ', ' , $ new ) ) ; }
Returns a new element with the specified keywords added .
21,942
public function GetValues ( $ getNullValues = FALSE , $ includeInheritProperties = TRUE , $ publicOnly = TRUE ) { $ data = [ ] ; $ modelClassName = get_class ( $ this ) ; $ classReflector = new \ ReflectionClass ( $ modelClassName ) ; $ properties = $ publicOnly ? $ classReflector -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) : $ classReflector -> getProperties ( ) ; foreach ( $ properties as $ property ) { if ( ! $ includeInheritProperties && $ property -> class != $ modelClassName ) continue ; $ propertyName = $ property -> name ; if ( isset ( static :: $ protectedProperties [ $ propertyName ] ) ) continue ; if ( ! $ getNullValues && $ this -> $ propertyName === NULL ) continue ; $ data [ $ propertyName ] = $ this -> $ propertyName ; } return $ data ; }
Collect all model class public and inherit field values into array .
21,943
public function & SetCode ( $ code , $ codeMessage = NULL ) { $ this -> code = $ code ; if ( $ codeMessage !== NULL ) $ this -> codeMessage = $ codeMessage ; http_response_code ( $ code ) ; return $ this ; }
Set HTTP response code .
21,944
public function GetCode ( ) { if ( $ this -> code === NULL ) { $ phpCode = http_response_code ( ) ; $ this -> code = $ phpCode === FALSE ? static :: OK : $ phpCode ; } return $ this -> code ; }
Get HTTP response code .
21,945
public function getLocation ( $ component_name , $ path_within_component ) { if ( $ this -> complete_symfony_checkout ) { $ component_location = $ this -> vendor_directory . 'symfony/symfony/src' ; } else { $ component_location = $ this -> vendor_directory . 'symfony/' . $ component_name ; } return $ component_location . $ path_within_component ; }
This plugin is mostly useful if it s included without the symfony framework But this makes sure it works if included with a full Symfony2 installation
21,946
public function getAvailableLanguages ( ) { $ arrayParameters = $ this -> makeArrayFromParameters ( __METHOD__ , func_get_args ( ) ) ; $ arrayParameters = $ this -> sendEvent ( 'melisengine_service_get_available_languages_start' , $ arrayParameters ) ; $ langTable = $ this -> getServiceLocator ( ) -> get ( 'MelisEngineTableCmsLang' ) ; $ results = $ langTable -> fetchAll ( ) -> toArray ( ) ; $ arrayParameters [ 'results' ] = $ results ; $ arrayParameters = $ this -> sendEvent ( 'melisengine_service_get_available_languages_end' , $ arrayParameters ) ; return $ arrayParameters [ 'results' ] ; }
This service gets all available languages
21,947
public function getSiteLanguage ( ) { $ arrayParameters = $ this -> makeArrayFromParameters ( __METHOD__ , func_get_args ( ) ) ; $ arrayParameters = $ this -> sendEvent ( 'melisengine_service_get_site_lang_start' , $ arrayParameters ) ; $ siteModule = getenv ( 'MELIS_MODULE' ) ; $ container = new Container ( 'melisplugins' ) ; $ config = $ this -> getServiceLocator ( ) -> get ( 'config' ) ; $ langId = $ container [ 'melis-plugins-lang-id' ] ; $ langLocale = $ container [ 'melis-plugins-lang-locale' ] ; if ( ! empty ( $ config [ 'site' ] [ $ siteModule ] [ 'language' ] [ 'language_id' ] ) ) $ langId = $ config [ 'site' ] [ $ siteModule ] [ 'language' ] [ 'language_id' ] ; if ( ! empty ( $ config [ 'site' ] [ $ siteModule ] [ 'language' ] [ 'language_locale' ] ) ) $ langLocale = $ config [ 'site' ] [ $ siteModule ] [ 'language' ] [ 'language_locale' ] ; $ result = array ( 'langId' => $ langId , 'langLocale' => $ langLocale , ) ; $ arrayParameters [ 'results' ] = $ result ; $ arrayParameters = $ this -> sendEvent ( 'melisengine_service_get_site_lang_end' , $ arrayParameters ) ; return $ arrayParameters [ 'results' ] ; }
This service return the language id and its locale use for transating text fort
21,948
public static function isEmpty ( $ value ) { if ( ! isset ( $ value ) ) { return true ; } elseif ( is_bool ( $ value ) ) { return false ; } elseif ( $ value === 0 ) { return false ; } elseif ( empty ( $ value ) ) { return true ; } elseif ( is_object ( $ value ) && method_exists ( $ value , 'isEmpty' ) ) { return $ value -> isEmpty ( ) ; } elseif ( static :: isTraversable ( $ value ) ) { foreach ( $ value as $ k => $ val ) { if ( ! static :: isEmpty ( $ val ) ) { return false ; } } return true ; } return false ; }
Determine if a value is empty .
21,949
public static function isTraversable ( $ value ) { return is_array ( $ value ) || ( is_object ( $ value ) && ( get_class ( $ value ) == 'stdClass' || $ value instanceof \ Traversable ) ) ; }
Determine if the value can be traversed with foreach .
21,950
public static function GetSessionMaxTime ( ) { static :: $ sessionMaxTime = static :: $ sessionStartTime ; if ( static :: $ meta -> expirations ) { foreach ( static :: $ meta -> expirations as $ expiration ) { if ( $ expiration > static :: $ sessionMaxTime ) static :: $ sessionMaxTime = $ expiration ; } } return static :: $ sessionMaxTime ; }
Get the highest expiration in seconds for namespace with the highest expiration to set expiration for PHPSESSID cookie .
21,951
public static function assertArray ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertArray' , new ScalarConstraint ( ScalarConstraint :: TYPE_ARRAY ) ) ; }
Assert value is an array .
21,952
public static function assertScalar ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertScalar' , new ScalarConstraint ( ScalarConstraint :: TYPE_SCALAR ) ) ; }
Assert value is a scalar .
21,953
public static function assertString ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertString' , new ScalarConstraint ( ScalarConstraint :: TYPE_STRING ) ) ; }
Assert value is a string .
21,954
public static function assertNotArray ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertNotArray' , new LogicalNot ( new ScalarConstraint ( ScalarConstraint :: TYPE_ARRAY ) ) ) ; }
Assert value is not an array .
21,955
public static function assertNotScalar ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertNotScalar' , new LogicalNot ( new ScalarConstraint ( ScalarConstraint :: TYPE_SCALAR ) ) ) ; }
Assert value is not a scalar .
21,956
public static function assertNotString ( $ actual , string $ message = '' ) { self :: assertTypeOfScalar ( $ actual , $ message , 'assertNotString' , new LogicalNot ( new ScalarConstraint ( ScalarConstraint :: TYPE_STRING ) ) ) ; }
Assert value is not a string .
21,957
public function & SetHelper ( $ helperName , & $ instance , $ forAllTemplates = TRUE ) { $ implementsIHelper = FALSE ; if ( $ forAllTemplates ) { if ( self :: $ _toolClass === NULL ) self :: $ _toolClass = \ MvcCore \ Application :: GetInstance ( ) -> GetToolClass ( ) ; $ toolClass = self :: $ _toolClass ; $ helpersInterface = self :: HELPERS_INTERFACE_CLASS_NAME ; $ className = get_class ( $ instance ) ; $ implementsIHelper = $ toolClass :: CheckClassInterface ( $ className , $ helpersInterface , FALSE , FALSE ) ; self :: $ _globalHelpers [ $ helperName ] = [ & $ instance , $ implementsIHelper ] ; } $ this -> __protected [ 'helpers' ] [ $ helperName ] = & $ instance ; if ( $ implementsIHelper ) $ instance -> SetView ( $ this ) ; return $ this ; }
Set view helper for current template or for all templates globally by default . If view helper already exist in global helpers store - it s overwritten .
21,958
public static function assertXMLMatchesXSD ( $ XSD , $ XML , string $ message = '' ) { if ( ! is_string ( $ XSD ) ) { throw AssertHelper :: createArgumentException ( __TRAIT__ , 'assertXMLMatchesXSD' , 'string' , $ XSD ) ; } AssertHelper :: assertMethodDependency ( __CLASS__ , __TRAIT__ , 'assertXMLMatchesXSD' , [ 'assertThat' ] ) ; self :: assertThat ( $ XML , new XMLMatchesXSDConstraint ( $ XSD ) , $ message ) ; }
Assert string is XML formatted as defined by the XML Schema Definition .
21,959
public static function assertXMLValid ( $ XML , string $ message = '' ) { AssertHelper :: assertMethodDependency ( __CLASS__ , __TRAIT__ , 'assertXMLValid' , [ 'assertThat' ] ) ; self :: assertThat ( $ XML , new XMLValidConstraint ( ) , $ message ) ; }
Assert string is valid XML .
21,960
public function getBlendablePlugin ( $ name ) { $ plugin = new Plugin ( $ this -> modx , $ this -> blender , $ name ) ; return $ plugin -> setSeedsDir ( $ this -> blender -> getSeedsDir ( ) ) ; }
Use this method with your IDE to help manually build a Plugin with PHP
21,961
public function getBlendableSnippet ( $ name ) { $ snippet = new Snippet ( $ this -> modx , $ this -> blender , $ name ) ; return $ snippet -> setSeedsDir ( $ this -> blender -> getSeedsDir ( ) ) ; }
Use this method with your IDE to help manually build a Snippet with PHP
21,962
public function getBlendableTemplate ( $ name ) { $ template = new Template ( $ this -> modx , $ this -> blender , $ name ) ; return $ template -> setSeedsDir ( $ this -> blender -> getSeedsDir ( ) ) ; }
Use this method with your IDE to manually build a template
21,963
public function getBlendableTemplateVariable ( $ name ) { $ tv = new TemplateVariable ( $ this -> modx , $ this -> blender , $ name ) ; return $ tv -> setSeedsDir ( $ this -> blender -> getSeedsDir ( ) ) ; }
Use this method with your IDE to manually build a template variable
21,964
private function assertValidMatrix ( array $ matrix ) { $ count = count ( $ matrix ) ; if ( $ count === 3 ) { for ( $ x = 0 ; $ x < $ count ; $ x ++ ) { if ( ! is_array ( $ matrix [ $ x ] ) ) { throw new \ RuntimeException ( sprintf ( 'Item "%d" In The Given Matrix Is Not An Array' , $ x ) ) ; } $ subcount = count ( $ matrix [ $ x ] ) ; if ( $ subcount < 3 || $ subcount > 3 ) { throw new \ RuntimeException ( sprintf ( 'Item "%d" In The Given Matrix Must Be An Array With (3) ' . 'Flotas But "%d" Float(s) Was Found' , $ x , $ subcount ) ) ; } } } else { throw new \ RuntimeException ( sprintf ( 'Expect Matrix (3*3) But The Given Matrix Length is (%s)' , $ count ) ) ; } }
Assert that the given matrix is valid convolution matrix
21,965
protected function canonicalRedirectQueryStringStrategy ( ) { $ request = & $ this -> request ; $ redirectToCanonicalUrl = FALSE ; $ requestGlobalGet = & $ request -> GetGlobalCollection ( 'get' ) ; $ requestedCtrlDc = isset ( $ requestGlobalGet [ static :: URL_PARAM_CONTROLLER ] ) ? $ requestGlobalGet [ static :: URL_PARAM_CONTROLLER ] : NULL ; $ requestedActionDc = isset ( $ requestGlobalGet [ static :: URL_PARAM_ACTION ] ) ? $ requestGlobalGet [ static :: URL_PARAM_ACTION ] : NULL ; $ toolClass = self :: $ toolClass ; list ( $ dfltCtrlPc , $ dftlActionPc ) = $ this -> application -> GetDefaultControllerAndActionNames ( ) ; $ dfltCtrlDc = $ toolClass :: GetDashedFromPascalCase ( $ dfltCtrlPc ) ; $ dftlActionDc = $ toolClass :: GetDashedFromPascalCase ( $ dftlActionPc ) ; $ requestedParamsClone = array_merge ( [ ] , $ this -> requestedParams ) ; if ( $ requestedCtrlDc !== NULL && $ requestedCtrlDc === $ dfltCtrlDc ) { unset ( $ requestedParamsClone [ static :: URL_PARAM_CONTROLLER ] ) ; $ redirectToCanonicalUrl = TRUE ; } if ( $ requestedActionDc !== NULL && $ requestedActionDc === $ dftlActionDc ) { unset ( $ requestedParamsClone [ static :: URL_PARAM_ACTION ] ) ; $ redirectToCanonicalUrl = TRUE ; } if ( $ redirectToCanonicalUrl ) { $ selfCanonicalUrl = $ this -> UrlByQueryString ( $ this -> selfRouteName , $ requestedParamsClone ) ; $ this -> redirect ( $ selfCanonicalUrl , \ MvcCore \ IResponse :: MOVED_PERMANENTLY ) ; return FALSE ; } return TRUE ; }
If request is routed by query string strategy check if request controller or request action is the same as default values . Then redirect to shorter canonical URL .
21,966
protected function canonicalRedirectRewriteRoutesStrategy ( ) { $ request = & $ this -> request ; $ redirectToCanonicalUrl = FALSE ; $ defaultParams = $ this -> GetDefaultParams ( ) ? : [ ] ; list ( $ selfUrlDomainAndBasePart , $ selfUrlPathAndQueryPart ) = $ this -> currentRoute -> Url ( $ request , $ this -> requestedParams , $ defaultParams , $ this -> getQueryStringParamsSepatator ( ) , TRUE ) ; if ( mb_strpos ( $ selfUrlDomainAndBasePart , '//' ) === FALSE ) $ selfUrlDomainAndBasePart = $ request -> GetDomainUrl ( ) . $ selfUrlDomainAndBasePart ; if ( mb_strlen ( $ selfUrlDomainAndBasePart ) > 0 && $ selfUrlDomainAndBasePart !== $ request -> GetBaseUrl ( ) ) { $ redirectToCanonicalUrl = TRUE ; } else if ( mb_strlen ( $ selfUrlPathAndQueryPart ) > 0 ) { $ path = $ request -> GetPath ( FALSE ) ; $ requestedUrl = $ path === '' ? '/' : $ path ; if ( mb_strpos ( $ selfUrlPathAndQueryPart , '?' ) !== FALSE ) { $ selfUrlPathAndQueryPart = rawurldecode ( $ selfUrlPathAndQueryPart ) ; $ requestedUrl .= $ request -> GetQuery ( TRUE , FALSE ) ; } if ( $ selfUrlPathAndQueryPart !== $ requestedUrl ) $ redirectToCanonicalUrl = TRUE ; } if ( $ redirectToCanonicalUrl ) { $ selfCanonicalUrl = $ this -> Url ( $ this -> selfRouteName , $ this -> requestedParams ) ; $ this -> redirect ( $ selfCanonicalUrl , \ MvcCore \ IResponse :: MOVED_PERMANENTLY ) ; return FALSE ; } return TRUE ; }
If request is routed by rewrite routes strategy try to complete canonical URL by current route . Then compare completed base URL part with requested base URL part or completed path and query part with requested path and query part . If first or second part is different redirect to canonical shorter URL .
21,967
public function load ( $ urlRewriteId ) { $ params = array ( MemberNames :: URL_REWRITE_ID => $ urlRewriteId ) ; $ this -> urlRewriteProductCategoryStmt -> execute ( $ params ) ; return $ this -> urlRewriteProductCategoryStmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; }
Return s the URL rewrite product category relation for the passed URL rewrite ID .
21,968
public function findAllBySku ( $ sku ) { $ params = array ( MemberNames :: SKU => $ sku ) ; $ this -> urlRewriteProductCategoriesBySkuStmt -> execute ( $ params ) ; return $ this -> urlRewriteProductCategoriesBySkuStmt -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; }
Return s an array with the URL rewrite product category relations for the passed SKU .
21,969
public function getStats ( ) { if ( $ this -> stats ) { return $ this -> stats ; } return $ this -> stats = $ this -> api -> stats ( $ this -> getDisplayName ( ) ) ; }
Return the players stats
21,970
public function getCombatLevel ( $ float = false ) { $ stats = $ this -> getStats ( ) ; return $ this -> api -> calculateCombatLevel ( $ stats -> findByClass ( Attack :: class ) -> getLevel ( ) , $ stats -> findByClass ( Strength :: class ) -> getLevel ( ) , $ stats -> findByClass ( Magic :: class ) -> getLevel ( ) , $ stats -> findByClass ( Ranged :: class ) -> getLevel ( ) , $ stats -> findByClass ( Defence :: class ) -> getLevel ( ) , $ stats -> findByClass ( Constitution :: class ) -> getLevel ( ) , $ stats -> findByClass ( Prayer :: class ) -> getLevel ( ) , $ stats -> findByClass ( Summoning :: class ) -> getLevel ( ) , $ float ) ; }
Return the calculated combat level of this player
21,971
public function init ( ) { if ( VERBOSE ) echo 'INIT:' , PHP_EOL ; if ( VERBOSE ) echo ' CONNECTING API' , PHP_EOL ; $ this -> api -> auth ( ) ; if ( VERBOSE ) echo ' API CONNECTED' , PHP_EOL ; if ( VERBOSE ) echo ' CONNECTING SQL' , PHP_EOL ; $ this -> db -> connect ( ) ; if ( VERBOSE ) echo ' SQL CONNECTED' , PHP_EOL ; if ( VERBOSE ) echo ' CHECKING PATHS' , PHP_EOL ; if ( DEBUG ) echo ' CHECKING TMP DIR AT : ' . $ this -> tmp_dir , PHP_EOL ; if ( ! file_exists ( $ this -> tmp_dir ) ) { throw new Exception ( "Path for 'tmp_dir' not found at '" . $ this -> tmp_dir . "'!" ) ; } if ( DEBUG ) echo ' CHECKING DUMP DIR AT : ' . $ this -> dumps_dir , PHP_EOL ; if ( ! file_exists ( $ this -> dumps_dir ) ) { throw new Exception ( "Path for 'dumps_dir' not found at '" . $ this -> dumps_dir . "'!" ) ; } if ( VERBOSE ) echo ' PATHS FOUND' , PHP_EOL ; }
Connects sql and authenticates with client token to the api
21,972
public function importDumps ( ) { if ( VERBOSE ) echo 'GETTING DUMP LIST' , PHP_EOL ; $ dumps = $ this -> api -> api ( '/reports/dumps' , 'GET' ) ; if ( VERBOSE ) echo 'GOT DUMP LIST' , PHP_EOL ; $ dumps = array_reverse ( $ dumps ) ; if ( VERBOSE ) echo 'EXECUTING DUMPS!' , PHP_EOL ; foreach ( $ dumps as $ dump ) { if ( $ dump [ 'status' ] == 1 ) { $ this -> dump ( $ dump [ 'dumpId' ] ) ; } } }
Grab all report dumps and go through them in the order they were created
21,973
public function dump ( $ id ) { if ( VERBOSE ) echo " DUMP $id" , PHP_EOL ; $ filename = $ this -> dumps_dir . 'dump-' . $ id . '.tar.gz' ; if ( file_exists ( $ filename ) ) { if ( VERBOSE ) echo " SKIPPING : $filename exists" , PHP_EOL ; return false ; } else { try { $ tgz_data = $ this -> api -> api ( "/reports/dump/{$id}.tgz" , 'GET' ) ; } catch ( Exception $ e ) { throw new Exception ( 'Could not find dump with id ' . $ id ) ; exit ; } file_put_contents ( $ filename , $ tgz_data ) ; } $ unpacked_files = array ( ) ; chdir ( dirname ( $ filename ) ) ; if ( exec ( "/bin/tar -zxvf $filename -C " . $ this -> tmp_dir , $ output ) ) { $ injects = array ( ) ; foreach ( $ output as $ file ) { $ thisFile = $ this -> tmp_dir . $ file ; $ unpacked_files [ ] = $ thisFile ; if ( file_exists ( $ thisFile ) ) { list ( $ model , ) = explode ( '-' , $ file ) ; if ( isset ( $ this -> modelsToTable [ $ model ] ) ) { $ table = $ this -> modelsToTable [ $ model ] ; } else { if ( DEBUG ) echo " SKIPPING $model : table not found!" , PHP_EOL ; continue ; } $ sql = "LOAD DATA INFILE '$thisFile' REPLACE INTO TABLE $table CHARACTER SET utf8 IGNORE 1 LINES" ; if ( DEBUG ) echo PHP_EOL , 'DEBUG : $sql : ' . $ sql , PHP_EOL ; $ this -> db -> query ( $ sql ) ; } } } else { throw new Exception ( 'File uncompression failed for file ' . $ filename ) ; } foreach ( $ unpacked_files as $ file ) { unlink ( $ file ) ; } return true ; }
If dump id file does not exist download and inject it to db
21,974
public function setType ( $ type ) { if ( ! array_key_exists ( $ type , self :: $ Supported ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid Sharpen Type "%s"' , $ type ) ) ; } $ this -> type = $ type ; }
Set sharpen type
21,975
public function seek ( $ row ) { switch ( $ this -> mode ) { case "mysql" : $ this -> result -> data_seek ( $ row ) ; break ; case "postgres" : case "redshift" : pg_result_seek ( $ this -> result , $ row ) ; break ; case "odbc" : case "mssqlsrv" : break ; case "sqlite" : $ this -> result -> reset ( ) ; for ( $ i = 0 ; $ i < $ row ; $ i ++ ) { $ this -> result -> fetchArray ( ) ; } break ; case "mssql" : mssql_data_seek ( $ this -> result , $ row ) ; break ; } $ this -> position = $ row ; }
Seek to a specific record of the result set
21,976
public function count ( ) { switch ( $ this -> mode ) { case "mysql" : $ rows = $ this -> result -> num_rows ; break ; case "postgres" : case "redshift" : $ rows = pg_num_rows ( $ this -> result ) ; break ; case "odbc" : $ rows = odbc_num_rows ( $ this -> result ) ; if ( $ rows < 1 ) { $ rows = 0 ; if ( odbc_num_fields ( $ this -> result ) > 0 ) { $ position = $ this -> position ; $ this -> seek ( 0 ) ; while ( $ this -> getNextRow ( ) ) { ++ $ rows ; } $ this -> seek ( $ position ) ; } } break ; case "sqlite" : $ rows = 0 ; while ( $ this -> result -> fetchArray ( ) ) { $ rows ++ ; } $ this -> seek ( $ this -> position ) ; break ; case "mssql" : $ rows = mssql_num_rows ( $ this -> result ) ; break ; case "mssqlsrv" : $ rows = sqlsrv_num_rows ( $ this -> result ) ; break ; } if ( $ rows === false || $ rows < 0 ) { throw new \ Exception ( "Failed to get the row count from the result set" ) ; } return $ rows ; }
Get the number of rows in the result set
21,977
public function columnCount ( ) { switch ( $ this -> mode ) { case "mysql" : $ columns = $ this -> result -> field_count ; break ; case "postgres" : case "redshift" : $ columns = pg_num_fields ( $ this -> result ) ; break ; case "odbc" : $ columns = odbc_num_fields ( $ this -> result ) ; break ; case "sqlite" : $ columns = $ this -> result -> numColumns ( ) ; break ; case "mssql" : $ columns = mssql_num_fields ( $ this -> result ) ; break ; case "mssqlsrv" : $ columns = sqlsrv_num_fields ( $ this -> result ) ; break ; } if ( $ columns === false || $ columns < 0 ) { throw new \ Exception ( "Failed to get the column count from the result set" ) ; } return $ columns ; }
Get the number of columns in the result set
21,978
public function free ( ) { switch ( $ this -> mode ) { case "mysql" : $ this -> result -> free ( ) ; break ; case "postgres" : case "redshift" : pg_free_result ( $ this -> result ) ; break ; case "odbc" : odbc_free_result ( $ this -> result ) ; break ; case "sqlite" : $ this -> result -> finalize ( ) ; break ; case "mssql" : mssql_free_result ( $ this -> result ) ; break ; case "mssqlsrv" : sqlsrv_free_stmt ( $ this -> result ) ; break ; } }
Free the memory used by the result resource
21,979
public function getAssetsOnlyRaw ( $ group = null ) { $ assets = $ this -> getAssets ( $ group , true ) -> filter ( function ( $ asset ) { return $ asset -> isRaw ( ) ; } ) ; return $ assets ; }
Get all the assets filtered by a group but only if the assets are raw .
21,980
public function getAssets ( $ group = null , $ raw = true ) { $ assets = clone $ this -> directory -> getAssets ( ) ; foreach ( $ assets as $ key => $ asset ) { if ( ! $ raw and $ asset -> isRaw ( ) or ! is_null ( $ group ) and ! $ asset -> { 'is' . ucfirst ( str_singular ( $ group ) ) } ( ) ) { $ assets -> forget ( $ key ) ; } } $ ordered = array ( ) ; foreach ( $ assets as $ asset ) { $ this -> orderAsset ( $ asset , $ ordered ) ; } return new \ Illuminate \ Support \ Collection ( $ ordered ) ; }
Get all the assets filtered by a group and if to include the raw assets .
21,981
protected function orderAsset ( Asset $ asset , array & $ assets ) { $ order = $ asset -> getOrder ( ) and $ order -- ; if ( array_key_exists ( $ order , $ assets ) ) { array_splice ( $ assets , $ order , 0 , array ( null ) ) ; } $ assets [ $ order ] = $ asset ; ksort ( $ assets ) ; }
Orders the array of assets as they were defined or on a user ordered basis .
21,982
public function build ( ) { $ this -> overseer -> clearRoles ( ) ; if ( isset ( $ this -> config [ 'roles' ] ) ) { $ this -> saveRoles ( $ this -> config [ 'roles' ] ) ; } $ this -> overseer -> clearPermissions ( ) ; if ( isset ( $ this -> config [ 'permissions' ] ) ) { $ this -> savePermissions ( $ this -> config [ 'permissions' ] ) ; } $ this -> overseer -> clearAssignments ( ) ; if ( isset ( $ this -> config [ 'assignments' ] ) ) { $ this -> saveAssignments ( $ this -> config [ 'assignments' ] ) ; } }
Build the assignments roles and permissions based on configuration .
21,983
public function getBody ( ) { if ( ! isset ( $ this -> body ) ) { $ contentType = $ this -> getHeader ( 'Content-Type' ) ; if ( stripos ( $ contentType , 'application/json' ) !== false ) { $ this -> body = json_decode ( $ this -> rawBody , true ) ; } else { $ this -> body = $ this -> rawBody ; } } return $ this -> body ; }
Gets the body of the response decoded according to its content type .
21,984
public function isResponseClass ( string $ class ) : bool { $ pattern = '`^' . str_ireplace ( 'x' , '\d' , preg_quote ( $ class , '`' ) ) . '$`' ; $ result = preg_match ( $ pattern , $ this -> statusCode ) ; return $ result === 1 ; }
Check if the provided response matches the provided response type .
21,985
public function setRawBody ( string $ body ) { $ this -> rawBody = $ body ; $ this -> body = null ; return $ this ; }
Set the raw body of the response .
21,986
public function setStatus ( $ code , $ reasonPhrase = null ) { if ( preg_match ( '`(?:HTTP/([\d.]+)\s+)?(\d{3})\s*(.*)`i' , $ code , $ matches ) ) { $ this -> protocolVersion = $ matches [ 1 ] ? : $ this -> protocolVersion ; $ code = ( int ) $ matches [ 2 ] ; $ reasonPhrase = $ reasonPhrase ? : $ matches [ 3 ] ; } if ( empty ( $ reasonPhrase ) && isset ( static :: $ reasonPhrases [ $ code ] ) ) { $ reasonPhrase = static :: $ reasonPhrases [ $ code ] ; } if ( is_numeric ( $ code ) ) { $ this -> setStatusCode ( ( int ) $ code ) ; } $ this -> setReasonPhrase ( ( string ) $ reasonPhrase ) ; return $ this ; }
Set the status of the response .
21,987
private function parseStatusLine ( $ headers ) : string { if ( empty ( $ headers ) ) { return '' ; } if ( is_string ( $ headers ) ) { if ( preg_match_all ( '`(?:^|\n)(HTTP/[^\r]+)\r\n`' , $ headers , $ matches ) ) { $ firstLine = end ( $ matches [ 1 ] ) ; } else { $ firstLine = trim ( strstr ( $ headers , "\r\n" , true ) ) ; } } else { $ firstLine = ( string ) reset ( $ headers ) ; } if ( strpos ( $ firstLine , 'HTTP/' ) === 0 ) { return $ firstLine ; } return '' ; }
Parse the status line from a header string or array .
21,988
public function offsetGet ( $ offset ) { $ this -> getBody ( ) ; $ result = isset ( $ this -> body [ $ offset ] ) ? $ this -> body [ $ offset ] : null ; return $ result ; }
Retrieve a value at a given array offset .
21,989
public function withScript ( ScriptElement $ script , $ scope = 'header' ) { assert ( in_array ( $ scope , [ 'header' , 'footer' ] ) ) ; $ that = clone ( $ this ) ; $ that -> scripts [ $ scope ] [ ] = $ script ; return $ that ; }
Returns a copy of the page with the script added .
21,990
public function rotate ( $ degree , ColorInterface $ background = null ) { return $ this -> apply ( new Rotate ( $ degree , $ background ) ) ; }
Rotate the working canvas
21,991
public function watermark ( CanvasInterface $ watermark , Coordinate $ cooridnate = null ) { return $ this -> apply ( new Watermark ( $ watermark , $ cooridnate ) ) ; }
Watermakr the working canvas with the given canvas
21,992
public function overlay ( CanvasInterface $ overlay , $ mount = 100 , Box $ box = null ) { return $ this -> apply ( new Overlay ( $ overlay , $ mount , $ box ) ) ; }
Overlay the current canvas with the given canvas
21,993
public function overlayWatermark ( CanvasInterface $ watermark , Coordinate $ cooridnate = null , $ mount = 100 ) { return $ this -> overlay ( $ watermark , $ mount , new Box ( $ watermark -> getDimension ( ) , $ cooridnate ) ) ; }
Watermakr the working canvas with the given canvas using the overlay method
21,994
protected function rewriteRouting ( $ requestCtrlName , $ requestActionName ) { $ request = & $ this -> request ; $ requestedPathFirstWord = $ this -> rewriteRoutingGetReqPathFirstWord ( ) ; $ this -> rewriteRoutingProcessPreHandler ( $ requestedPathFirstWord ) ; $ routes = & $ this -> rewriteRoutingGetRoutesToMatch ( $ requestedPathFirstWord ) ; $ requestMethod = $ request -> GetMethod ( ) ; foreach ( $ routes as & $ route ) { if ( $ this -> rewriteRoutingCheckRoute ( $ route , [ $ requestMethod ] ) ) continue ; $ allMatchedParams = $ route -> Matches ( $ request ) ; if ( $ allMatchedParams !== NULL ) { $ this -> currentRoute = clone $ route ; $ this -> currentRoute -> SetMatchedParams ( $ allMatchedParams ) ; $ this -> rewriteRoutingSetRequestedAndDefaultParams ( $ allMatchedParams , $ requestCtrlName , $ requestActionName ) ; if ( $ this -> rewriteRoutingSetRequestParams ( $ allMatchedParams ) ) continue ; $ this -> rewriteRoutingSetUpCurrentRouteByRequest ( ) ; break ; } } }
Try to parse first word from request path to get proper routes group . If there is no first word in request path get default routes group .
21,995
protected function rewriteRoutingProcessPreHandler ( $ firstPathWord ) { if ( $ this -> preRouteMatchingHandler === NULL ) return ; call_user_func ( $ this -> preRouteMatchingHandler , $ this , $ this -> request , $ firstPathWord ) ; }
Call any configured pre - route matching handler with first parsed word from requested path and with request object to load for example from database only routes you need to use for routing not all of them .
21,996
protected function & rewriteRoutingGetRoutesToMatch ( $ firstPathWord ) { if ( isset ( $ this -> routesGroups [ $ firstPathWord ] ) ) { $ routes = & $ this -> routesGroups [ $ firstPathWord ] ; } else if ( isset ( $ this -> routesGroups [ '' ] ) ) { $ routes = & $ this -> routesGroups [ '' ] ; } else { $ routes = [ ] ; } reset ( $ routes ) ; return $ routes ; }
Get specific routes group by first parsed word from request path if any . If first path word is an empty string there is returned routes with no group word defined . If still there are no such routes in default group returned is an empty array .
21,997
protected function rewriteRoutingCheckRoute ( \ MvcCore \ IRoute & $ route , array $ additionalInfo ) { list ( $ requestMethod , ) = $ additionalInfo ; $ routeMethod = $ route -> GetMethod ( ) ; if ( $ routeMethod !== NULL && $ routeMethod !== $ requestMethod ) return TRUE ; return FALSE ; }
Return TRUE if there is possible by additional info array records to route request by given route as first argument . For example if route object has defined http method and request has the same method or not or much more by additional info array records in extended classes .
21,998
protected function rewriteRoutingSetRequestedAndDefaultParams ( array & $ allMatchedParams , $ requestCtrlName = NULL , $ requestActionName = NULL ) { $ request = & $ this -> request ; $ rawQueryParams = array_merge ( [ ] , $ request -> GetParams ( FALSE ) ) ; list ( $ ctrlDfltNamePc , $ actionDfltNamePc ) = $ this -> application -> GetDefaultControllerAndActionNames ( ) ; $ toolClass = self :: $ toolClass ; if ( $ requestCtrlName !== NULL ) { $ request -> SetControllerName ( $ requestCtrlName ) ; $ allMatchedParams [ static :: URL_PARAM_CONTROLLER ] = $ requestCtrlName ; $ rawQueryParams [ static :: URL_PARAM_CONTROLLER ] = $ requestCtrlName ; } else if ( isset ( $ allMatchedParams [ static :: URL_PARAM_CONTROLLER ] ) ) { $ request -> SetControllerName ( $ allMatchedParams [ static :: URL_PARAM_CONTROLLER ] ) ; } else { $ defaultCtrlNameDashed = $ toolClass :: GetDashedFromPascalCase ( $ ctrlDfltNamePc ) ; $ request -> SetControllerName ( $ defaultCtrlNameDashed ) ; $ allMatchedParams [ static :: URL_PARAM_CONTROLLER ] = $ defaultCtrlNameDashed ; } if ( $ requestActionName !== NULL ) { $ request -> SetActionName ( $ requestActionName ) ; $ allMatchedParams [ static :: URL_PARAM_ACTION ] = $ requestActionName ; $ rawQueryParams [ static :: URL_PARAM_ACTION ] = $ requestActionName ; } else if ( isset ( $ allMatchedParams [ static :: URL_PARAM_ACTION ] ) ) { $ request -> SetActionName ( $ allMatchedParams [ static :: URL_PARAM_ACTION ] ) ; } else { $ defaultActionNameDashed = $ toolClass :: GetDashedFromPascalCase ( $ actionDfltNamePc ) ; $ request -> SetActionName ( $ defaultActionNameDashed ) ; $ allMatchedParams [ static :: URL_PARAM_ACTION ] = $ defaultActionNameDashed ; } $ this -> defaultParams = array_merge ( $ this -> currentRoute -> GetDefaults ( ) , $ this -> defaultParams , $ allMatchedParams , $ rawQueryParams ) ; $ routeReverseParams = $ this -> currentRoute -> GetReverseParams ( ) ? : [ ] ; $ pathOnlyMatchedParams = array_merge ( [ ] , $ allMatchedParams ) ; $ controllerInReverse = in_array ( static :: URL_PARAM_CONTROLLER , $ routeReverseParams , TRUE ) ; $ actionInReverse = in_array ( static :: URL_PARAM_ACTION , $ routeReverseParams , TRUE ) ; if ( ! $ controllerInReverse ) unset ( $ pathOnlyMatchedParams [ static :: URL_PARAM_CONTROLLER ] ) ; if ( ! $ actionInReverse ) unset ( $ pathOnlyMatchedParams [ static :: URL_PARAM_ACTION ] ) ; $ this -> requestedParams = array_merge ( [ ] , $ pathOnlyMatchedParams , $ rawQueryParams ) ; }
When route is matched set up request and default params .
21,999
protected function rewriteRoutingSetRequestParams ( array & $ allMatchedParams ) { $ request = & $ this -> request ; $ defaultParamsBefore = array_merge ( [ ] , $ this -> defaultParams ) ; $ requestParams = array_merge ( [ ] , $ this -> defaultParams ) ; list ( $ success , $ requestParamsFiltered ) = $ this -> currentRoute -> Filter ( $ requestParams , $ this -> defaultParams , \ MvcCore \ IRoute :: CONFIG_FILTER_IN ) ; if ( $ success === FALSE ) { $ this -> defaultParams = $ defaultParamsBefore ; $ this -> requestedParams = [ ] ; $ allMatchedParams = NULL ; $ this -> currentRoute = NULL ; return TRUE ; } $ requestParamsFiltered = $ requestParamsFiltered ? : $ requestParams ; $ request -> SetParams ( $ requestParamsFiltered ) ; if ( isset ( $ requestParamsFiltered [ static :: URL_PARAM_CONTROLLER ] ) ) $ request -> SetControllerName ( $ requestParamsFiltered [ static :: URL_PARAM_CONTROLLER ] ) ; if ( isset ( $ requestParamsFiltered [ static :: URL_PARAM_ACTION ] ) ) $ request -> SetActionName ( $ requestParamsFiltered [ static :: URL_PARAM_ACTION ] ) ; return FALSE ; }
Filter route in and if filtering is not successful return TRUE about continuing another route matching . If filtering is successful set matched controller and action into request object and return TRUE to finish routes matching process .