idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
15,700
final public function getError ( $ i = null , $ toString = true ) { if ( $ i === null ) { $ error = end ( self :: $ errors ) ; } else if ( ! array_key_exists ( $ i , self :: $ errors ) ) { return false ; } else { $ error = self :: $ errors [ $ i ] ; } return $ error ; }
Returns a referenced error
15,701
final public function getErrorString ( ) { $ errors = self :: getErrors ( ) ; $ string = '<ul>' ; foreach ( $ errors as $ error ) { $ string .= '<li>' . $ error . '</li>' ; } return $ string . '</ul>' ; }
Returns the error string
15,702
public function set ( $ property , $ value = null , $ overwrite = false ) { $ previous = isset ( $ this -> $ property ) ? $ this -> $ property : null ; $ this -> $ property = $ value ; return $ previous ; }
Sets an object property
15,703
final private function referencedArgs ( & $ arr ) { if ( strnatcmp ( phpversion ( ) , '5.3' ) >= 0 ) { $ refs = array ( ) ; foreach ( $ arr as $ key => $ value ) $ refs [ ] = & $ arr [ $ key ] ; return $ refs ; } return $ arr ; }
Solution to passing data by reference
15,704
public function itemsFilterIds ( $ params ) { if ( empty ( $ params [ 'orderby' ] ) ) { $ params [ 'orderby' ] = $ this -> leftKeyName ; } return parent :: itemsFilterIds ( $ params ) ; }
Filters items and return array of IDs
15,705
public function itemsFilterHash ( $ params ) { $ db = \ Brilliant \ BFactory :: getDBO ( ) ; $ itemshash = parent :: itemsFilterHash ( $ params ) ; if ( isset ( $ params [ 'level' ] ) ) { $ itemshash .= ':level=' . $ params [ 'level' ] ; } if ( isset ( $ params [ 'parent' ] ) ) { $ itemshash .= ':parent=' . $ params [ 'parent' ] ; } if ( isset ( $ params [ 'parenttree' ] ) ) { $ itemid = ( int ) $ params [ 'parenttree' ] ; $ item = $ this -> itemGet ( $ itemid ) ; if ( empty ( $ item ) ) { return false ; } $ itemshash .= ':parenttree-' . $ item -> lft . '-' . $ item -> rgt ; } if ( ( isset ( $ params [ 'parenttree_lft' ] ) ) && ( isset ( $ params [ 'parenttree_rgt' ] ) ) ) { $ lft = $ params [ 'parenttree_lft' ] ; $ rgt = $ params [ 'parenttree_rgt' ] ; if ( ( $ lft < 1 ) || ( $ rgt < 1 ) || ( $ lft >= $ rgt ) ) { return false ; } $ itemshash .= ':parenttree-' . $ lft . '-' . $ rgt ; } if ( isset ( $ params [ 'parentchain' ] ) ) { $ itemid = ( int ) $ params [ 'parentchain' ] ; $ item = $ this -> itemGet ( $ itemid ) ; if ( empty ( $ item ) ) { return false ; } $ itemshash .= ':parentchain-' . $ item -> lft . '-' . $ item -> rgt ; } if ( ( isset ( $ params [ 'parentchain_lft' ] ) ) && ( isset ( $ params [ 'parentchain_rgt' ] ) ) ) { $ lft = $ params [ 'parentchain_lft' ] ; $ rgt = $ params [ 'parentchain_rgt' ] ; if ( ( $ lft < 1 ) || ( $ rgt < 1 ) || ( $ lft >= $ rgt ) ) { return false ; } $ itemshash .= ':parentchain-' . $ lft . '-' . $ rgt ; } return $ itemshash ; }
News categories tree cache hash .
15,706
public function getSimpleTreeRecursive ( $ fields = array ( ) , $ transfields = array ( ) , $ lang = '' , $ wh = array ( ) ) { $ list = $ this -> getSimpleTree ( $ fields , $ transfields , $ lang , $ wh ) ; if ( ! is_array ( $ list ) ) { return array ( ) ; } $ tree = array ( ) ; foreach ( $ list as $ li ) { $ id = ( int ) $ li -> { $ this -> primaryKeyName } ; $ ti = $ li ; $ ti -> children = array ( ) ; $ tree [ ] = $ ti ; } return $ tree ; }
Get recursive tree
15,707
public function setCache ( $ cachetime , $ etag = true ) { $ this -> _cachetime = $ cachetime ; $ this -> _cacheetag = $ etag ; }
Sets the caching time for the current page .
15,708
public function getAll ( $ handle ) { array_unshift ( $ this -> _header , 'Content-Type: text/html; charset=utf-8' ) ; $ this -> _header [ ] = 'Vary:' ; rewind ( $ handle ) ; $ hash = hash_init ( 'md5' ) ; hash_update_stream ( $ hash , $ handle ) ; $ hash = hash_final ( $ hash ) ; $ hash = md5 ( $ hash . implode ( '' , $ this -> _header ) ) ; if ( $ this -> _cacheetag ) $ this -> _header [ ] = 'ETag: ' . $ hash ; if ( $ this -> _cachetime === null ) { if ( $ this -> _cacheetag ) $ this -> _header [ ] = 'Cache-Control: no-cache, must-revalidate' ; else $ this -> _header [ ] = 'Cache-Control: no-store, no-cache, must-revalidate' ; } else { $ fileexpired = strtotime ( $ this -> _cachetime ) ; $ filemaxage = $ fileexpired - time ( ) ; $ this -> _header [ ] = 'Pragma: ' ; $ this -> _header [ ] = 'Expires: ' . gmdate ( "D, d M Y H:i:s" , $ fileexpired ) . " GMT" ; $ this -> _header [ ] = 'Cache-Control: public, max-age=' . $ filemaxage ; } if ( ! isset ( $ _SERVER [ 'HTTP_CACHE_CONTROL' ] ) || ! preg_match ( '/max-age=0|no-cache/i' , $ _SERVER [ 'HTTP_CACHE_CONTROL' ] ) ) if ( isset ( $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] ) && $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] == $ hash ) { $ this -> _etag_is_different = false ; $ this -> _header [ ] = 'HTTP/1.1 304 Not Modified' ; } if ( ! empty ( $ this -> _filename ) ) { $ this -> _header [ ] = 'Content-Type: ' . $ this -> getMimeType ( $ this -> _filename ) ; $ this -> _header [ ] = 'Content-Disposition: attachment; filename=' . basename ( $ this -> _filename ) ; } return $ this -> _header ; }
Returns all headers for a given content . This is internally used by the \ Morrow \ Core \ Frontcontroller class .
15,709
public function DataUrl ( $ relativeOrAbsolutePath ) { $ currentDirFullPath = $ this -> view -> GetCurrentViewDirectory ( ) ; $ searchedPaths = [ ] ; array_unshift ( $ searchedPaths , $ currentDirFullPath . '/' . $ relativeOrAbsolutePath ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { array_unshift ( $ searchedPaths , $ this -> appRoot . '/' . ltrim ( $ relativeOrAbsolutePath , '/' ) ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { array_unshift ( $ searchedPaths , $ relativeOrAbsolutePath ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { $ selfClass = version_compare ( PHP_VERSION , '5.5' , '>' ) ? self :: class : __CLASS__ ; throw new \ InvalidArgumentException ( "[" . $ selfClass . "] File not found in paths: '" . implode ( "', '" , array_reverse ( $ searchedPaths ) ) . "'." ) ; } } } $ fileFullPath = $ searchedPaths [ 0 ] ; $ imageData = base64_encode ( file_get_contents ( $ fileFullPath ) ) ; $ result = 'data: ' . mime_content_type ( $ fileFullPath ) . ';base64,' . $ imageData ; return $ result ; }
Return any file content by given relative or absolute path in data url . Path could be relative from currently rendered view relative from application root or absolute path to file .
15,710
protected function registerSearchSettings ( array $ config , ContainerBuilder $ container ) { if ( empty ( $ config [ 'configs' ] ) ) { throw ConfigManagerException :: error ( 'At least 1 configuration should be present under configs.' ) ; } $ definition = $ container -> getDefinition ( 'rz_search.manager.config' ) ; foreach ( $ config [ 'configs' ] as $ name => $ configuration ) { if ( $ configuration [ 'model' ] [ 'processor' ] && $ configuration [ 'model' ] [ 'identifier' ] ) { $ definition -> addMethodCall ( 'setConfig' , array ( $ name , $ configuration ) ) ; $ definition -> addMethodCall ( 'setIndex' , array ( $ name , $ configuration [ 'model' ] [ 'identifier' ] ) ) ; } } }
Registers ckeditor widget .
15,711
public function render ( $ template , $ data = null ) { $ twig = $ this -> getTwig ( ) ; $ parser = $ twig -> loadTemplate ( $ template ) ; return $ parser -> render ( $ this -> all ( ) , $ data ) ; }
Custom render method
15,712
public function add ( MetaSetInterface $ metaSet ) { $ this -> metaSets [ $ metaSet -> getId ( ) ] = $ metaSet ; $ this -> nameMap [ $ metaSet -> getName ( ) ] = $ metaSet -> getId ( ) ; return $ this ; }
Add meta set .
15,713
public static function Config ( $ Name = FALSE , $ Default = FALSE ) { $ Config = self :: $ _Config ; if ( $ Name === FALSE ) $ Result = $ Config ; else $ Result = $ Config -> Get ( $ Name , $ Default ) ; return $ Result ; }
Get a configuration setting for the application .
15,714
public static function Controller ( $ Value = NULL ) { static $ Controller = NULL ; if ( $ Value !== NULL ) $ Controller = $ Value ; return $ Controller ; }
The current controller being targetted .
15,715
public static function Factory ( $ Alias = FALSE ) { if ( is_null ( self :: $ _Factory ) ) { self :: SetFactory ( new Gdn_Factory ( ) ) ; self :: FactoryOverwrite ( FALSE ) ; } if ( $ Alias === FALSE ) return self :: $ _Factory ; $ Args = func_get_args ( ) ; array_shift ( $ Args ) ; return self :: $ _Factory -> Factory ( $ Alias , $ Args ) ; }
Get an object from the factory .
15,716
public static function FactoryInstallDependency ( $ Alias , $ PropertyName , $ SourceAlias ) { self :: Factory ( ) -> InstallDependency ( $ Alias , $ PropertyName , $ SourceAlias ) ; }
Installs a dependency to the factory .
15,717
public static function FactoryInstallDependencyFromConfig ( $ Config , $ Alias = NULL ) { if ( is_string ( $ Config ) ) $ Config = self :: Config ( $ Config ) ; if ( is_null ( $ Alias ) ) $ Alias = $ Config [ 'Alias' ] ; $ PropertyName = $ Config [ 'PropertyName' ] ; $ SourceAlias = $ Config [ 'SourceAlias' ] ; $ Override = ArrayValue ( 'Override' , $ Config , TRUE ) ; self :: FactoryInstallDependency ( $ Alias , $ PropertyName , $ SourceAlias , $ Override ) ; }
Installs a dependency to the factory with the settings from a configuration .
15,718
public static function FactoryInstallFromConfig ( $ Config , $ Alias = NULL ) { if ( is_string ( $ Config ) ) $ Config = self :: Config ( $ Config ) ; if ( is_null ( $ Alias ) ) $ Alias = $ Config [ 'Alias' ] ; $ FactoryType = $ Config [ 'FactoryType' ] ; $ Data = ArrayValue ( 'Data' , $ Config , NULL ) ; $ Override = ArrayValue ( 'Override' , $ Config , TRUE ) ; self :: FactoryInstall ( $ Alias , $ Config [ 'ClassName' ] , $ Config [ 'Path' ] , $ FactoryType , $ Data , $ Override ) ; if ( array_key_exists ( 'Dependencies' , $ Config ) ) { $ Dependencies = $ Config [ 'Dependencies' ] ; foreach ( $ Dependencies as $ Index => $ DependencyConfig ) { self :: FactoryInstallFromConfig ( $ DependencyConfig , $ Alias ) ; } } }
Installs a class to the factory with the settings from a configuration .
15,719
public static function Request ( $ NewRequest = NULL ) { $ Request = self :: $ _Request ; if ( ! is_null ( $ NewRequest ) ) { if ( is_string ( $ NewRequest ) ) $ Request -> WithURI ( $ NewRequest ) ; elseif ( is_object ( $ NewRequest ) ) $ Request -> FromImport ( $ NewRequest ) ; } return $ Request ; }
Get or set the current request object .
15,720
public static function Slice ( $ Slice ) { $ Result = self :: Factory ( self :: AliasSlice ) ; return $ Result -> Execute ( $ Slice ) ; }
Get a reference to the Gdn_Slice
15,721
public static function SetFactory ( $ Factory , $ Override = TRUE ) { if ( $ Override || is_null ( self :: $ _Factory ) ) self :: $ _Factory = $ Factory ; }
Set the object used as the factory for the api .
15,722
public function execute ( TallantoMethodInterface $ method ) { $ options = [ ] ; if ( $ method instanceof AbstractSecuredTallantoMethod ) { if ( $ method -> isSecured ( ) ) { $ options [ 'auth' ] = [ $ method -> getLogin ( ) , $ method -> getPassword ( ) ] ; } } if ( ! is_null ( $ jsonData = $ method -> getJsonData ( ) ) ) { $ options [ 'json' ] = $ jsonData ; } $ options [ 'query' ] = $ method -> getQueryParameters ( ) ; $ options [ 'headers' ] = $ method -> getRequestHeaders ( ) ; if ( $ method instanceof PageableTallantoMethodInterface ) { $ options [ 'query' ] [ 'total_count' ] = 'true' ; $ options [ 'query' ] [ 'page_size' ] = $ method -> getPageSize ( ) ; $ options [ 'query' ] [ 'page_number' ] = $ method -> getPageNumber ( ) ; } $ this -> logger -> debug ( 'Performing Guzzle {method} request to {uri}' , [ 'method' => $ method -> getMethod ( ) , 'uri' => $ method -> getUri ( ) , 'options' => $ options , ] ) ; try { $ response = $ this -> getClient ( ) -> request ( $ method -> getMethod ( ) , $ method -> getUri ( ) , $ options ) ; } catch ( RequestException $ e ) { throw new TransportTallantoException ( 'Guzzle request failed: ' . $ e -> getResponse ( ) -> getBody ( ) -> getContents ( ) , 0 , $ e ) ; } catch ( \ Exception $ e ) { throw new TransportTallantoException ( 'Guzzle request failed.' , 0 , $ e ) ; } $ method -> setResponse ( $ response ) ; }
Executes API method .
15,723
public function writeToFile ( $ filename , $ data , $ header = '' ) { $ ini = $ this -> writeToString ( $ data , $ header ) ; if ( ! file_put_contents ( $ filename , $ ini ) ) throw new IniWritingException ( sprintf ( 'Impossible to write to file %s' , $ filename ) ) ; }
Convert an array or an IniCollection to INI string in file .
15,724
public function writeToString ( $ data , $ header = '' ) { if ( $ data instanceof IniCollection ) $ data = $ data -> toArray ( ) ; else if ( ! is_array ( $ data ) ) throw new IniWritingException ( 'The expected type is array or \NoczCore\Ini\IniCollection' ) ; $ ini = '' ; if ( ! empty ( $ header ) ) $ ini .= $ header . PHP_EOL ; foreach ( $ data as $ k => $ v ) { if ( is_array ( $ v ) ) { if ( empty ( $ v ) ) continue ; $ ini .= "[$k]" . PHP_EOL ; foreach ( $ this -> convertRecursive ( $ v ) as $ key => $ value ) { $ last = explode ( '.' , $ key ) ; $ last = end ( $ last ) ; if ( strpos ( $ key , '.' ) !== false && is_numeric ( $ last ) ) $ key = substr ( $ key , 0 , - strlen ( '.' . $ last ) ) . '[]' ; $ ini .= "$key = {$this->encode($value)}" . PHP_EOL ; } } else { $ ini .= "$k = {$this->encode($v)}" . PHP_EOL ; } } return $ ini ; }
Convert an array or an IniCollection to INI string .
15,725
private function convertRecursive ( array $ array , $ parentKey = null ) { $ return = [ ] ; if ( ! is_null ( $ parentKey ) ) $ parentKey .= '.' ; foreach ( $ array as $ k => $ v ) { if ( is_array ( $ v ) ) $ return [ ] = $ this -> convertRecursive ( $ v , $ parentKey . $ k ) ; else $ return [ $ parentKey . $ k ] = $ v ; } return $ this -> array_flatten ( $ return ) ; }
Transform a recursive array to a basic array with a point for the recursive keys .
15,726
private function encode ( $ value ) { if ( $ value === true ) $ value = "true" ; else if ( $ value === false ) $ value = "false" ; else if ( is_string ( $ value ) ) $ value = "\"$value\"" ; return $ value ; }
Encode value .
15,727
public static function forge ( $ body = null , $ status = 200 , array $ headers = array ( ) ) { $ response = new static ( $ body , $ status , $ headers ) ; \ Event :: instance ( ) -> has_events ( 'response_created' ) and \ Event :: instance ( ) -> trigger ( 'response_created' , '' , 'none' ) ; return $ response ; }
Creates an instance of the Response class
15,728
public static function redirect_back ( $ url = '' , $ method = 'location' , $ code = 302 ) { if ( $ referrer = \ Input :: referrer ( ) ) { if ( strpos ( $ referrer , \ Uri :: base ( ) ) === 0 and $ referrer != \ Uri :: current ( ) ) { static :: redirect ( $ referrer , $ method , $ code ) ; } } static :: redirect ( $ url , $ method , $ code ) ; }
Redirects back to the previous page if that page is within the current application . If not it will redirect to the given url and if none is given back to the application root
15,729
public function set_header ( $ name , $ value , $ replace = true ) { if ( $ replace ) { $ this -> headers [ $ name ] = $ value ; } else { $ this -> headers [ ] = array ( $ name , $ value ) ; } return $ this ; }
Adds a header to the queue
15,730
public function get_header ( $ name = null ) { if ( func_num_args ( ) ) { return isset ( $ this -> headers [ $ name ] ) ? $ this -> headers [ $ name ] : null ; } else { return $ this -> headers ; } }
Gets header information from the queue
15,731
public function send_headers ( ) { if ( ! headers_sent ( ) ) { if ( ! empty ( $ _SERVER [ 'FCGI_SERVER_VERSION' ] ) ) { header ( 'Status: ' . $ this -> status . ' ' . static :: $ statuses [ $ this -> status ] ) ; } else { $ protocol = \ Input :: server ( 'SERVER_PROTOCOL' ) ? \ Input :: server ( 'SERVER_PROTOCOL' ) : 'HTTP/1.1' ; header ( $ protocol . ' ' . $ this -> status . ' ' . static :: $ statuses [ $ this -> status ] ) ; } foreach ( $ this -> headers as $ name => $ value ) { if ( is_int ( $ name ) and is_array ( $ value ) ) { isset ( $ value [ 0 ] ) and $ name = $ value [ 0 ] ; isset ( $ value [ 1 ] ) and $ value = $ value [ 1 ] ; } is_string ( $ name ) and $ value = "{$name}: {$value}" ; header ( $ value , true ) ; } return true ; } return false ; }
Sends the headers if they haven t already been sent . Returns whether they were sent or not .
15,732
public function send ( $ send_headers = false ) { $ body = $ this -> __toString ( ) ; if ( $ send_headers ) { $ this -> send_headers ( ) ; } if ( $ this -> body != null ) { echo $ body ; } }
Sends the response to the output buffer . Optionally will send the headers .
15,733
public static function fromFile ( string $ file , string $ driver = null ) : ConfigInterface { if ( ! $ driver ) { $ ext = strtolower ( ( string ) pathinfo ( $ file , PATHINFO_EXTENSION ) ) ; if ( $ ext === 'yml' ) { $ ext = ConfigAdapterInterface :: ADAPTER_YAML ; } $ driver = isset ( static :: $ availableAdapter [ $ ext ] ) ? static :: $ availableAdapter [ $ ext ] : static :: $ availableAdapter [ static :: DEFAULT_ADAPTER ] ; } if ( ! is_subclass_of ( $ driver , ConfigAdapterInterface :: class ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Config Driver invalid. Driver %s must be implement interface %s' , $ driver , ConfigAdapterInterface :: class ) , E_WARNING ) ; } return $ driver :: fromFile ( $ file ) ; }
Get from file
15,734
public function didef ( $ thing , $ file ) { $ this -> thingList [ $ thing ] = $ file ; $ args = func_get_args ( ) ; array_shift ( $ args ) ; array_shift ( $ args ) ; if ( count ( $ args ) ) { $ this -> thingArgList [ $ thing ] = $ args ; } }
Define a file as a thing . Any extra arguments are saved and used as constructor arguments
15,735
public function attachServices ( $ obj ) { $ args = get_class_vars ( get_class ( $ obj ) ) ; foreach ( $ args as $ _k => $ _v ) { if ( substr ( $ _k , - 7 ) == 'Service' ) { $ obj -> $ _k = _makePromise ( $ _k ) ; } } }
Set a DI promise object on every class var that ends with Service
15,736
private function validateCustomerBalance ( $ balance , $ amount , $ useDelta = false ) { if ( $ useDelta ) { $ result = ( ( $ balance + self :: CONVERSION_DELTA ) >= $ amount ) ; } else { $ result = ( $ balance >= $ amount ) ; } return $ result ; }
Customer balance should be greater or equal to transaction amount .
15,737
public function rootPath ( ) { return ( 'phar:' === substr ( $ this -> basePath , 0 , 5 ) ) ? dirname ( str_replace ( 'phar://' , '' , $ this -> basePath ) ) : $ this -> basePath ; }
Get the path of root
15,738
public function storagePath ( ) { if ( $ this -> storagePath ) return $ this -> storagePath ; return $ this -> storagePath ? : $ this -> rootPath ( ) . DIRECTORY_SEPARATOR . 'storage' ; }
Get the path to the application configuration files .
15,739
public function createCsrfField ( ) { $ fieldName = Config :: get ( 'security.csrf.field_name' ) ; $ input = new Input ( $ this -> form -> expression ( 'input' ) , [ 'name' => $ fieldName , 'value' => $ this -> createToken ( ) , 'type' => 'hidden' ] ) ; return $ input -> execute ( ) ; }
create csrf token field
15,740
public function process ( string $ string , int $ strategy = EnumMacroProcessStorategy :: STRATEGY_LAST ) { $ ret = $ string ; $ replace_exists = false ; $ keyword_list = self :: findMacroKeywords ( $ ret ) ; foreach ( $ keyword_list as $ keyword ) { $ replace = $ this -> callHandlers ( $ keyword , $ strategy ) ; if ( $ replace !== null ) { $ replace_exists |= $ this -> checkIfReplaceIncludeMacro ( $ replace ) ; $ ret = str_replace ( "%$keyword%" , $ replace , $ ret ) ; } } return $ replace_exists ? $ this -> process ( $ ret , $ strategy ) : $ ret ; }
Expand string by macro keyword
15,741
private function checkIfReplaceIncludeMacro ( string $ replace ) : bool { $ keyword_list = self :: findMacroKeywords ( $ replace ) ; foreach ( $ keyword_list as $ keyword ) { $ replace = $ this -> callHandlers ( $ keyword , EnumMacroProcessStorategy :: STRATEGY_FISRT ) ; if ( $ replace !== null ) { return true ; } } return false ; }
Check if replace string has macro
15,742
private function callHandlers ( string $ keyword , int $ strategy ) { if ( $ this -> handlers ) { $ stack = null ; foreach ( $ this -> handlers as $ handler ) { $ replace = $ handler ( $ keyword ) ; if ( ! is_null ( $ replace ) ) { if ( $ strategy === EnumMacroProcessStorategy :: STRATEGY_FISRT ) { return $ replace ; } $ stack [ ] = $ replace ; } } if ( $ strategy === EnumMacroProcessStorategy :: STRATEGY_LAST && ! empty ( $ stack ) ) { return array_pop ( $ stack ) ; } } return null ; }
Callback all handlers
15,743
public static function initByPath ( $ path , array $ options = [ 'registry' => Recursive :: ALL_INCLUSIVE , ] ) { if ( ! file_exists ( $ path ) || ! is_readable ( $ path ) ) { throw new RuntimeException ( sprintf ( "Cannot open config file \"%s\"" , $ path ) , self :: EX_CANNOT_OPEN_CONFIG ) ; } $ config = \ donbidon \ Lib \ Config \ Ini :: parse ( file_get_contents ( $ path ) , true ) ; if ( ! is_array ( $ config ) ) { throw new RuntimeException ( sprintf ( "Cannot parse config file \"%s\"" , $ path ) , self :: EX_CANNOT_PARSE_CONFIG ) ; } $ registry = static :: initByArray ( $ config , $ options ) ; return $ registry ; }
Initializes environment by config file path .
15,744
public static function initByArray ( array $ config , array $ options = [ 'registry' => Recursive :: ALL_INCLUSIVE , ] ) { if ( ! is_array ( $ config ) ) { throw new InvalidArgumentException ( sprintf ( "Passed argument isn't array (%s)" , gettype ( $ config ) ) , self :: EX_INVALID_ARG ) ; } $ registry = static :: getRegistry ( $ config , $ options [ 'registry' ] ) ; $ registry -> set ( 'core/env' , isset ( $ _SERVER [ 'DOCUMENT_URI' ] ) ? "web" : "CLI" ) ; $ evtManager = new Event \ Manager ; $ evtManager -> setDebug ( $ registry -> get ( 'core/event/debug' , false ) ) ; Log \ Factory :: run ( $ registry , $ evtManager ) ; $ registry -> set ( 'core/event/manager' , $ evtManager ) ; return $ registry ; }
Initializes environment by config array .
15,745
public function exists ( $ category ) { $ ds = DIRECTORY_SEPARATOR ; $ path = app_path ( ) . $ ds . 'lablog' . $ ds . $ category ; if ( $ this -> fs -> isDirectory ( $ path ) ) { return true ; } return false ; }
Check if a given category exists or not .
15,746
public function getSubCategories ( $ category ) { $ ds = DIRECTORY_SEPARATOR ; $ categoryPath = str_replace ( '/' , $ ds , $ category ) ; $ basePath = app_path ( ) . $ ds . 'lablog' . $ ds ; $ path = $ basePath . $ categoryPath ; if ( ! $ this -> exists ( $ category ) ) { return array ( ) ; } $ categories = $ this -> fs -> directories ( $ path ) ; $ allCategories = array ( ) ; foreach ( $ categories as $ category ) { $ cat = str_replace ( $ basePath , '' , $ category ) ; $ allCategories [ ] = $ this -> getCategory ( $ cat ) ; } return $ allCategories ; }
Get a given categories sub categories .
15,747
public function getCategory ( $ category ) { $ ds = DIRECTORY_SEPARATOR ; $ categoryPath = str_replace ( '/' , $ ds , $ category ) ; $ path = app_path ( ) . $ ds . 'lablog' . $ ds . $ categoryPath ; if ( ! $ this -> exists ( $ category ) ) { return ( object ) array ( ) ; } $ categoryExplode = explode ( '/' , $ category ) ; $ categoryName = end ( $ categoryExplode ) ; $ linkPrefix = \ Config :: get ( 'lablog::prefix' ) == '/' ? '' : \ Config :: get ( 'lablog::prefix' ) ; $ baseCategory = $ category ; $ categoryLink = $ linkPrefix . '/category/' . $ category ; $ fullCategory = $ category ; $ category = new Category ; $ category -> name = $ categoryName ; $ category -> link = $ baseCategory ; $ category -> url = \ URL :: to ( $ categoryLink ) ; return $ category ; }
Get a given category information .
15,748
public function create ( $ delim = '#' , $ data = PHP_EOL ) { if ( $ this -> read ( $ delim ) ) { $ this -> update ( $ delim , $ data ) ; } else { file_put_contents ( $ this -> file , PHP_EOL . '# ' . $ delim . PHP_EOL . $ data . PHP_EOL . '# \\' . $ delim . PHP_EOL , FILE_APPEND ) ; } }
Create or update an entry in the . htaccess file
15,749
public function read ( $ delim = '#' ) { $ file = file_get_contents ( $ this -> file ) ; $ delim = preg_quote ( $ delim ) ; if ( preg_match ( "/#\s$delim\s(.*?)\s#\s\\\\$delim/s" , $ file , $ matches ) ) { return trim ( $ matches [ 1 ] ) ; } else { return false ; } }
Read entry from . htaccess file
15,750
public function update ( $ delim = '#' , $ data = PHP_EOL ) { $ data = str_replace ( array ( '$1' , '$2' , '$3' , '$4' , '$5' ) , array ( '\$1' , '\$2' , '\$3' , '\$4' , '\$5' ) , $ data ) ; $ delim = preg_quote ( $ delim ) ; file_put_contents ( $ this -> file , trim ( preg_replace ( "/#\s$delim\s(.*?)\s#\s\\\\$delim/s" , '# ' . $ delim . PHP_EOL . $ data . PHP_EOL . '# \\' . $ delim , file_get_contents ( $ this -> file ) ) ) ) ; }
Update entry in . htaccess file
15,751
public function delete ( $ delim = '#' ) { $ file = file_get_contents ( $ this -> file ) ; $ delim = preg_quote ( $ delim ) ; if ( preg_match ( "/#\s$delim\s(.*?)\s#\s\\\\$delim/s" , $ file , $ matches ) ) { file_put_contents ( $ this -> file , str_replace ( PHP_EOL . $ matches [ 0 ] . PHP_EOL , '' , $ file ) ) ; return true ; } else { return false ; } }
Delete entry from . htaccess file
15,752
protected function _setTokenizer ( $ tokenizer ) { if ( $ tokenizer !== null && ! ( $ tokenizer instanceof TokenizerInterface ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid tokenizer' ) , null , null , $ tokenizer ) ; } $ this -> tokenizer = $ tokenizer ; }
Assigns a tokenizer to this instance .
15,753
protected function chooseCMS ( $ availableInputSystems , $ availableOutputSystems ) { $ this -> info ( "\n************************************************" ) ; $ this -> info ( "\n********* CMS Migration Manager ************" ) ; $ this -> info ( "\n************************************************" ) ; $ in = $ this -> choice ( 'Which input format?' , array_keys ( $ availableInputSystems ) ) ; $ out = $ this -> choice ( 'Which output format?' , array_keys ( $ availableOutputSystems ) ) ; return array ( $ in , $ out ) ; }
Starts Console Menu Asks User to choose Input and Output CMS returns array with the two integer
15,754
protected function getInputAndOutputDisk ( ) { $ validInputPath = FALSE ; $ validOutputPath = FALSE ; while ( ! $ validInputPath ) { $ goBack = FALSE ; $ rootInput = $ this -> choice ( 'Which input disk?' , array_keys ( config ( 'filesystems.disks.cms.migrations' ) ) , 0 ) ; if ( $ rootInput == 'custom_input' ) { while ( ! $ validInputPath && ! $ goBack ) { $ rootInput = $ this -> ask ( 'Please enter root-Path for Input-CMS' ) ; if ( $ rootInput === 'x' ) { $ goBack = TRUE ; } if ( ! file_exists ( $ rootInput ) ) { $ this -> info ( 'Invalid Path! Please enter valid Root-Path' ) ; $ this -> info ( "\n" . '[x] -> Go back' ) ; } else { $ validInputPath = TRUE ; } } } else { $ validInputPath = TRUE ; } } while ( ! $ validOutputPath ) { $ goBack = FALSE ; $ rootOutput = $ this -> choice ( 'Which output disk?' , array_keys ( config ( 'filesystems.disks.cms.migrations' ) ) , 1 ) ; if ( $ rootOutput == 'custom_output' ) { while ( ! $ validOutputPath && ! $ goBack ) { $ rootOutput = $ this -> ask ( 'Please enter root-Path for Output-CMS' ) ; if ( $ rootOutput === 'x' ) { $ goBack = TRUE ; } if ( ! file_exists ( $ rootOutput ) ) { $ this -> info ( 'Invalid Path! Please enter valid Root-Path' ) ; $ this -> info ( "\n" . '[x] -> Go back' ) ; } else { $ validOutputPath = TRUE ; } } } else { $ validOutputPath = TRUE ; } } return array ( $ rootInput , $ rootOutput ) ; }
Asks User to enter Root - Path of Input and Output CMS
15,755
public function load ( $ path , $ data = array ( ) ) { extract ( $ data ) ; $ fullPath = $ this -> transformPath ( $ path ) ; if ( is_file ( $ fullPath ) ) { return include ( $ fullPath ) ; } else { throw new NonexistentFileException ( 'Script not found: ' . $ fullPath ) ; } }
Includes a PHP file and returns any result returned by the file .
15,756
public function editAction ( ) { $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) -> setLocale ( $ this -> getAdminLocale ( ) ) ; $ form = $ locator -> get ( 'Form' ) -> create ( 'Grid\Paragraph\Content' ) ; if ( ( $ id = $ params -> fromRoute ( 'id' ) ) ) { $ paragraph = $ model -> find ( $ id ) ; if ( empty ( $ paragraph ) ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( ! $ paragraph -> isEditable ( ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } } else { if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( 'paragraph.content' , 'create' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ userId = $ this -> getAuthenticationService ( ) -> getIdentity ( ) -> id ; $ paragraph = $ model -> create ( array ( 'type' => 'content' , 'created' => time ( ) , 'userId' => $ userId , 'editUsers' => array ( $ userId ) , ) ) ; } $ form -> setHydrator ( $ model -> getMapper ( ) ) -> bind ( $ paragraph ) ; if ( $ request -> isPost ( ) ) { $ form -> setData ( $ request -> getPost ( ) ) ; if ( $ form -> isValid ( ) && $ paragraph -> save ( ) ) { $ this -> messenger ( ) -> add ( 'paragraph.form.content.success' , 'paragraph' , Message :: LEVEL_INFO ) ; return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } else { $ this -> messenger ( ) -> add ( 'paragraph.form.content.failed' , 'paragraph' , Message :: LEVEL_ERROR ) ; } } $ form -> setCancel ( $ this -> url ( ) -> fromRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ) ; return array ( 'form' => $ form , 'paragraph' => $ paragraph , ) ; }
Edit a content
15,757
public function cloneAction ( ) { if ( ! $ this -> getPermissionsModel ( ) -> isAllowed ( 'paragraph.content' , 'create' ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } $ params = $ this -> params ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) -> setLocale ( $ this -> getAdminLocale ( ) ) ; $ paragraph = $ model -> find ( $ params -> fromRoute ( 'id' ) ) ; if ( empty ( $ paragraph ) || $ paragraph -> type !== 'content' ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } $ cloneId = $ model -> cloneFrom ( $ paragraph -> id ) ; if ( $ cloneId ) { $ clone = $ model -> find ( $ cloneId ) ; if ( ! empty ( $ clone ) ) { $ userId = $ this -> getAuthenticationService ( ) -> getIdentity ( ) -> id ; if ( empty ( $ clone -> userId ) ) { $ clone -> userId = $ userId ; } if ( ! in_array ( $ userId , $ clone -> editUsers ) ) { $ clone -> editUsers = array_merge ( $ clone -> editUsers , array ( $ userId ) ) ; } $ clone -> name = rtrim ( $ clone -> name ) . ' ' . $ locator -> get ( 'Zork\I18n\Translator\Translator' ) -> translate ( 'default.cloned' , 'default' ) ; $ clone -> save ( ) ; } $ this -> messenger ( ) -> add ( 'paragraph.action.clone.success' , 'paragraph' , Message :: LEVEL_INFO ) ; } else { $ this -> messenger ( ) -> add ( 'paragraph.action.clone.failed' , 'paragraph' , Message :: LEVEL_ERROR ) ; } return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
Clone a content
15,758
public function deleteAction ( ) { $ params = $ this -> params ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ model = $ locator -> get ( 'Grid\Paragraph\Model\Paragraph\Model' ) ; $ paragraph = $ model -> find ( $ params -> fromRoute ( 'id' ) ) ; if ( empty ( $ paragraph ) || $ paragraph -> type !== 'content' ) { $ this -> getResponse ( ) -> setStatusCode ( 404 ) ; return ; } if ( ! $ paragraph -> isDeletable ( ) ) { $ this -> getResponse ( ) -> setStatusCode ( 403 ) ; return ; } if ( $ paragraph -> delete ( ) ) { $ this -> messenger ( ) -> add ( 'paragraph.action.delete.success' , 'paragraph' , Message :: LEVEL_INFO ) ; } else { $ this -> messenger ( ) -> add ( 'paragraph.action.delete.failed' , 'paragraph' , Message :: LEVEL_ERROR ) ; } return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Content\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
Delete a content
15,759
public function description ( $ description = null ) { if ( $ description === null ) { return $ this -> description ; } $ this -> description = $ description ; }
Set or get the description of the migration
15,760
public function classname ( $ classname = null ) { if ( $ classname === null ) { return $ this -> classname ; } $ this -> classname = $ classname ; }
Set or get the name of the migration class
15,761
public function setDecoratedObject ( $ decorated ) { if ( ! is_object ( $ decorated ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected an object but got an argument of type "%s" instead.' , gettype ( $ decorated ) ) ) ; } $ this -> decoratedObject = $ decorated ; }
Sets the decorated object .
15,762
public function parseFtpString ( $ ftpUrl ) { if ( is_null ( $ this -> ftpUsername ) ) { if ( preg_match ( '/^(?:ftp:\/\/)?([^:]+):([^@]+)@(.*)$/' , $ ftpUrl , $ matches ) ) { $ this -> ftpUsername = $ matches [ 1 ] ; $ this -> ftpPassword = $ matches [ 2 ] ; $ this -> ftpDomain = $ matches [ 3 ] ; } else { throw new \ Exception ( 'Ftp string in wrong format, use [ftp://]username:password@domain.com' ) ; } } }
helper function to set local vars
15,763
protected function buildUnion ( $ prefix , array $ settings ) { $ clause = & $ this -> getClause ( 'UNION' ) ; $ flat = $ this -> flatSettings ( $ settings ) ; $ res = '' ; foreach ( $ clause as $ idx => $ field ) { $ parts = [ ] ; $ prefix = $ idx ? $ field [ 1 ] : '' ; $ parts [ ] = $ this -> quoteItem ( $ field [ 0 ] , $ flat ) ; $ res .= $ this -> joinClause ( $ prefix , '' , $ parts , $ settings ) ; } return ltrim ( $ res ) ; }
Build unioned SELECT
15,764
public function makeMove ( array $ boardState , $ player = Game :: PLAYER_A ) { $ this -> setBoard ( $ boardState ) ; $ recommendedMove = $ this -> getMove ( $ player ) ? : [ ] ; return $ recommendedMove ? array_merge ( $ recommendedMove , [ $ player ] ) : [ ] ; }
Get move for a particular player
15,765
public function registerContainerConfiguration ( LoaderInterface $ loader ) { $ classInfo = new \ ReflectionClass ( $ this ) ; $ dir = dirname ( $ classInfo -> getFileName ( ) ) ; $ loader -> load ( $ dir . '/config.yml' ) ; }
Register container configuration
15,766
public static function implementsInterface ( $ class_name , $ interface_name ) { if ( is_object ( $ class_name ) ) { $ class_name = get_class ( $ class_name ) ; } if ( class_exists ( $ class_name ) ) { $ interfaces = class_implements ( $ class_name ) ; return ( bool ) in_array ( $ interface_name , $ interfaces ) || in_array ( trim ( $ interface_name , '\\' ) , $ interfaces ) ; } return false ; }
Check if a class implements a certain interface
15,767
public static function extendsClass ( $ class_name , $ mother_name ) { if ( is_object ( $ class_name ) ) { $ class_name = get_class ( $ class_name ) ; } if ( class_exists ( $ class_name ) ) { return ( bool ) is_subclass_of ( $ class_name , $ mother_name ) ; } return false ; }
Check if a class extends a certain class
15,768
public static function isClassInstance ( $ object , $ class_name ) { if ( class_exists ( $ class_name ) && is_object ( $ object ) ) { return ( bool ) ( $ object instanceof $ class_name ) ; } return false ; }
Check if a an object is an instance of a class
15,769
public static function namespaceExists ( $ namespace ) { $ namespace = trim ( $ namespace , self :: NAMESPACE_SEPARATOR ) ; $ namespace .= self :: NAMESPACE_SEPARATOR ; foreach ( get_declared_classes ( ) as $ name ) { if ( strpos ( $ name , $ namespace ) === 0 ) { return true ; } } if ( class_exists ( $ _composer_loader = self :: COMPOSER_AUTOLOADER_CLASSNAME ) ) { $ _composer_reflection = new \ ReflectionClass ( $ _composer_loader ) ; $ _loader_filename = $ _composer_reflection -> getFilename ( ) ; $ _classmap_filename = dirname ( $ _loader_filename ) . DIRECTORY_SEPARATOR . self :: COMPOSER_COMMON_NAMESPACES_AUTOLOADER ; if ( file_exists ( $ _classmap_filename ) ) { $ namespaces_map = include $ _classmap_filename ; foreach ( $ namespaces_map as $ _ns => $ _dir ) { $ _ns = trim ( $ _ns , self :: NAMESPACE_SEPARATOR ) ; if ( strpos ( $ _ns , $ namespace ) === 0 ) { return true ; } if ( substr ( $ namespace , 0 , strlen ( $ _ns ) ) === $ _ns ) { if ( false !== $ pos = strrpos ( $ namespace , self :: NAMESPACE_SEPARATOR ) ) { $ namespace_path = strtr ( substr ( $ namespace , 0 , $ pos ) , self :: NAMESPACE_SEPARATOR , DIRECTORY_SEPARATOR ) ; $ namespace_name = substr ( $ namespace , $ pos + 1 ) ; } else { $ namespace_path = null ; $ namespace_name = $ namespace ; } $ namespace_path .= strtr ( $ namespace_name , '_' , DIRECTORY_SEPARATOR ) ; if ( ! is_array ( $ _dir ) ) { $ _dir = array ( $ _dir ) ; } foreach ( $ _dir as $ _testdir ) { $ _d = DirectoryHelper :: slashDirname ( $ _testdir ) . $ namespace_path ; if ( file_exists ( $ _d ) && is_dir ( $ _d ) ) { return true ; } } } } } } return false ; }
Test if a namespace can be found in declared classes or via Composer autoloader if so
15,770
public static function fetchArguments ( $ method_name = null , $ arguments = null , $ class_name = null , & $ logs = array ( ) ) { $ args_def = self :: organizeArguments ( $ method_name , $ arguments , $ class_name , $ logs ) ; if ( ! empty ( $ class_name ) ) { if ( is_callable ( array ( $ class_name , $ method_name ) ) ) { return call_user_func_array ( array ( $ class_name , $ method_name ) , $ args_def ) ; } else { $ _cls = is_object ( $ class_name ) ? get_class ( $ class_name ) : $ class_name ; throw new \ InvalidArgumentException ( sprintf ( 'Method "%s" of class object "%s" is not callable!' , $ method_name , $ _cls ) ) ; } } else { return call_user_func_array ( $ method_name , $ args_def ) ; } }
Launch a function or class s method fetching it arguments according to its declaration
15,771
public function get_physical_table_name ( $ table_name ) { $ prefix = $ this -> conf ( ) -> prefix ; if ( strlen ( $ prefix ) ) { $ prefix = preg_replace ( '/\_*$/' , '_' , $ prefix ) ; } return $ prefix . $ table_name ; }
getting table prefix
15,772
public static function parse ( $ object ) { $ len = \ strlen ( $ object ) ; if ( Number :: between ( $ len , MySQL :: getConstant ( 'CHAR_LEN_MIN' ) , MySQL :: getConstant ( 'CHAR_LEN_MAX' ) ) ) { return new static ( $ len , static :: CHAR ) ; } else if ( Number :: between ( $ len , MySQL :: getConstant ( 'VARCHAR_LEN_MIN' ) , MySQL :: getConstant ( 'VARCHAR_LEN_MAX' ) ) ) { return new static ( $ len , static :: VARCHAR ) ; } else if ( Number :: between ( $ len , MySQL :: getConstant ( 'MEDIUMTEXT_LEN_MIN' ) , MySQL :: getConstant ( 'MEDIUMTEXT_LEN_MAX' ) ) ) { return new static ( $ len , static :: MEDIUMTEXT ) ; } else if ( Number :: between ( $ len , MySQL :: getConstant ( 'LONGTEXT_LEN_MIN' ) , MySQL :: getConstant ( 'LONGTEXT_LEN_MAX' ) ) ) { return new static ( $ len , static :: LONGTEXT ) ; } return null ; }
Parse a string object to a MySQL string type Prefers VARCHARs over BLOBs
15,773
public function getRouteCollectionForRequest ( Request $ request ) { $ slug = '/' . trim ( $ request -> getPathInfo ( ) , '/' ) ; $ document = $ this -> repository -> findOneBy ( array ( 'slug' => $ slug ) ) ; $ collection = new RouteCollection ( ) ; if ( $ document ) { $ controller = $ this -> templateControllers [ $ document -> getTemplate ( ) ] ; $ route = new Route ( $ document -> getSlug ( ) , array ( '_controller' => $ controller , 'document' => $ document ) ) ; $ collection -> add ( 'test' , $ route ) ; } return $ collection ; }
Finds routes that may potentially match the request .
15,774
protected function catchException ( \ Exception $ e ) { foreach ( $ this -> onException as $ call ) { call_user_func_array ( $ call , [ $ e ] ) ; } throw $ e ; }
Catch tick exception and throw it .
15,775
public function load ( $ filename ) { if ( ! file_exists ( $ filename ) ) { throw new \ Exception ( 'Ini file "' . $ filename . '" doesn\'t exist.' ) ; return false ; } $ this -> filename = $ filename ; return $ this ; }
Load INI file
15,776
public function pushEvent ( string $ name , $ data = null ) : Event { $ event = new Event ( $ name , $ data ) ; $ this -> queue -> enqueue ( $ event ) ; return $ event ; }
Add an event to event queue
15,777
protected function addHandler ( TypedHandler $ handler ) { $ this -> addHandlerTypes ( $ handler ) ; $ this -> handlers [ ] = $ handler ; return $ this ; }
Add a handler to the adapter . The handler s supported types will be added to the adapter s supported types .
15,778
protected function assignToHandlers ( array $ objects ) { $ result = [ ] ; $ perType = TypedUtils :: groupByType ( $ objects ) ; foreach ( $ this -> handlers as $ handler ) { $ remainingTypes = array_keys ( $ perType ) ; $ handlerTypes = $ handler -> getSupportedEntityTypes ( ) ; $ useTypes = $ handlerTypes === null ? $ remainingTypes : array_intersect ( $ handlerTypes , $ remainingTypes ) ; if ( count ( $ useTypes ) > 0 ) { $ assigned = [ ] ; foreach ( $ useTypes as $ type ) { $ assigned [ ] = $ perType [ $ type ] ; unset ( $ perType [ $ type ] ) ; } $ result [ ] = [ $ handler , Arrays :: flatten ( $ assigned ) ] ; if ( count ( $ perType ) === 0 ) { break ; } } } return $ result ; }
Assign every entity to the first handler that supports it
15,779
protected function checkUnsupportedTypes ( array $ objects ) { if ( $ this -> supportedTypes !== null ) { $ unsupportedTypes = array_diff ( TypedUtils :: uniqueTypes ( $ objects ) , $ this -> supportedTypes ) ; if ( count ( $ unsupportedTypes ) > 0 ) { throw new Exception ( sprintf ( 'Encountered unsupported types %s (supported: %s)' , implode ( ', ' , $ unsupportedTypes ) , count ( $ this -> supportedTypes ) > 0 ? implode ( ', ' , $ this -> supportedTypes ) : '*none*' ) ) ; } } }
Validate that all the entity types from a request are supported by this adapter
15,780
final public function table ( $ table , $ getData = false , $ dataType = null ) { if ( ! empty ( $ table ) ) { $ this -> from ( $ table ) ; } return $ this ; }
Specifies the table upon which a read or write query is performed
15,781
final public function traceTableAlias ( $ table ) { if ( is_array ( $ table ) ) { foreach ( $ table as $ t ) { $ this -> traceTableAlias ( $ t ) ; } return ; } if ( strpos ( $ table , ',' ) !== FALSE ) { return $ this -> traceTableAlias ( explode ( ',' , $ table ) ) ; } if ( strpos ( $ table , " " ) !== FALSE ) { $ table = preg_replace ( '/ AS /i' , ' ' , $ table ) ; $ table = trim ( strrchr ( $ table , " " ) ) ; if ( ! in_array ( $ table , $ this -> arrayAliasedTables ) ) { $ this -> arrayAliasedTables [ ] = $ table ; } } }
This method allows us to preserve and track table aliasis as we build the query statement
15,782
final public function identifiers ( $ identifier ) { $ identifier = preg_replace ( '/[\t ]+/' , ' ' , $ identifier ) ; $ alias = '' ; if ( strpos ( $ identifier , ' ' ) !== FALSE ) { $ alias = strstr ( $ identifier , " " ) ; $ identifier = substr ( $ identifier , 0 , - strlen ( $ alias ) ) ; } if ( strpos ( $ identifier , '.' ) !== FALSE ) { } return $ identifier . $ alias ; }
Helper method for modifying any indentifiers in the query
15,783
final public function orderBy ( $ orderby , $ direction = '' ) { if ( strtolower ( $ direction ) == 'random' ) { $ orderby = '' ; $ direction = $ this -> _randomKeyword ; } elseif ( trim ( $ direction ) != '' ) { $ direction = ( in_array ( strtoupper ( trim ( $ direction ) ) , array ( 'ASC' , 'DESC' ) , TRUE ) ) ? ' ' . $ direction : ' ASC' ; } if ( strpos ( $ orderby , ',' ) !== FALSE ) { $ temp = array ( ) ; foreach ( explode ( ',' , $ orderby ) as $ part ) { $ part = trim ( $ part ) ; if ( ! in_array ( $ part , $ this -> arrayAliasedTables ) ) { $ part = $ this -> identifiers ( trim ( $ part ) ) ; } $ temp [ ] = $ part ; } $ orderby = implode ( ', ' , $ temp ) ; } else if ( $ direction != $ this -> _randomKeyword ) { $ orderby = $ this -> identifiers ( $ orderby ) ; } $ orderbyStatement = $ orderby . $ direction ; $ this -> arrayOrderBy [ ] = $ orderbyStatement ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheOrderBy [ ] = $ orderbyStatement ; $ this -> arrayCacheExists [ ] = 'orderby' ; } return $ this ; }
Adds the ORDER BY clause to the query statement
15,784
final public function count ( $ table = '' , $ resetselect = true ) { if ( ! empty ( $ table ) ) { $ this -> traceTableAlias ( $ table ) ; $ this -> fromTable ( $ table ) ; } $ sql = $ this -> compile ( $ this -> _countString . $ this -> identifiers ( 'totalcount' ) , true ) ; $ statement = $ this -> DBO -> prepare ( $ sql ) ; $ results = $ statement -> execute ( ) ; if ( $ resetselect ) $ this -> resetSelect ( ) ; if ( $ results -> rowCount ( ) == 0 ) return '0' ; $ row = $ results -> fetchObject ( ) ; return $ row -> totalcount ; }
Counts all the records in the specified table Or records which satisfy the compiled SQL statement
15,785
final public function where ( $ key , $ value = NULL , $ type = 'AND' , $ escape = TRUE ) { if ( empty ( $ key ) ) { return $ this ; } if ( ! is_array ( $ key ) ) { if ( is_null ( $ value ) ) { return $ this ; } $ key = array ( $ key => $ value ) ; } foreach ( $ key as $ k => $ v ) { $ prefix = ( count ( $ this -> arrayWhere ) == 0 AND count ( $ this -> arrayCacheWhere ) == 0 ) ? '' : $ type . "\t" ; if ( is_null ( $ v ) && ! $ this -> hasOperator ( $ k ) ) { $ k .= ' IS NULL' ; } if ( ! is_null ( $ v ) ) { if ( $ escape === TRUE ) { $ k = $ this -> identifiers ( $ k ) ; $ v = '' . $ this -> escape ( $ v ) ; } if ( ! $ this -> hasOperator ( $ k ) ) { $ k .= ' =' ; } } else { $ k = $ this -> identifiers ( $ k ) ; } $ this -> arrayWhere [ ] = $ prefix . $ k . $ v ; if ( $ this -> arrayCaching ) { $ this -> arrayCacheWhere [ ] = $ prefix . $ k . $ v ; $ this -> arrayCacheExists [ ] = 'where' ; } } return $ this ; }
Adds a WHERE condition to the Query statement . NOTE to change the operatory append the desired operator to the key names for example use
15,786
final public function hasOperator ( $ string ) { $ string = trim ( $ string ) ; $ matches = array ( ) ; if ( ! preg_match ( "/(\<|>|!|=|is null|BETWEEN|is not null)/i" , $ string , $ matches ) ) { return FALSE ; } return TRUE ; }
Searches for a standard MySQL operator in a specified string
15,787
final public function join ( $ table , $ cond , $ type = 'LEFT' ) { if ( $ type != '' ) { $ type = strtoupper ( trim ( $ type ) ) ; if ( ! in_array ( $ type , array ( 'LEFT' , 'RIGHT' , 'OUTER' , 'INNER' , 'LEFT OUTER' , 'RIGHT OUTER' ) ) ) { $ type = '' ; } else { $ type .= ' ' ; } } $ this -> traceTableAlias ( $ table ) ; if ( preg_match ( '/([\w\.]+)([\W\s]+)(.+)/' , $ cond , $ match ) ) { $ match [ 1 ] = $ this -> identifiers ( $ match [ 1 ] ) ; $ match [ 3 ] = $ this -> identifiers ( $ match [ 3 ] ) ; $ cond = $ match [ 1 ] . $ match [ 2 ] . $ match [ 3 ] ; } $ join = $ type . 'JOIN ' . $ this -> identifiers ( $ table ) . ' ON ' . $ cond ; $ this -> arrayJoin [ ] = $ join ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheJoin [ ] = $ join ; $ this -> arrayCacheExists [ ] = 'join' ; } return $ this ; }
Adds a JOIN query statement
15,788
final public function getWhere ( $ key , $ values = NULL , $ type = 'AND' ) { return $ this -> where ( $ key , $ values , $ type ) ; }
Returns the result set from a compiled Query representing the where conditions .
15,789
final public function notIn ( $ key , $ values ) { if ( empty ( $ key ) || empty ( $ values ) ) { return $ this ; } if ( ! is_array ( $ values ) ) { $ values = array ( $ values ) ; } return $ this -> in ( $ key , $ values , TRUE ) ; }
adds a NOT IN clause to the statement
15,790
final public function like ( $ field , $ match = '' , $ type = 'AND ' , $ side = 'both' , $ not = '' ) { if ( ! is_array ( $ field ) ) { $ field = array ( $ field => $ match ) ; } foreach ( $ field as $ k => $ v ) { $ k = $ this -> identifiers ( $ k ) ; $ prefix = ( count ( $ this -> arrayLike ) == 0 ) ? '' : $ type ; $ v = $ this -> escape ( $ v ) ; $ likeStatement = '' ; if ( $ side == 'before' ) { $ likeStatement = $ prefix . " $k $not LIKE '%{$v}'" ; } elseif ( $ side == 'after' ) { $ likeStatement = $ prefix . " $k $not LIKE '{$v}%'" ; } else { $ likeStatement = $ prefix . " $k $not LIKE '%{$v}%'" ; } $ this -> arrayLike [ ] = $ likeStatement ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheLike [ ] = $ likeStatement ; $ this -> arrayCacheExists [ ] = 'like' ; } } return $ this ; }
Adds a LIKE cluase to the query statement
15,791
final public function notLike ( $ field , $ match = '' , $ type = 'AND' , $ side = 'both' ) { return $ this -> like ( $ field , $ match , $ type , $ side , 'NOT' ) ; }
Adds a NOT LIKE to the statement
15,792
final public function groupBy ( $ by ) { if ( is_string ( $ by ) ) { $ by = explode ( ',' , $ by ) ; } foreach ( $ by as $ val ) { $ val = trim ( $ val ) ; if ( $ val != '' ) { $ this -> arrayGroupBy [ ] = $ this -> identifiers ( $ val ) ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheGroupBy [ ] = $ this -> identifiers ( $ val ) ; $ this -> arrayCacheExists [ ] = 'groupby' ; } } } return $ this ; }
Adds a group by clause to a query statement
15,793
final public function distinct ( $ boolean = TRUE ) { $ this -> arrayDistinct = ( is_bool ( $ boolean ) ) ? $ boolean : TRUE ; return $ this ; }
Adds a distinct clause to a select query statement
15,794
final public function having ( $ key , $ value = '' , $ type = 'AND ' , $ escape = TRUE ) { if ( ! is_array ( $ key ) ) { $ key = array ( $ key => $ value ) ; } foreach ( $ key as $ k => $ v ) { $ prefix = ( count ( $ this -> arrayHaving ) == 0 ) ? '' : $ type ; if ( $ escape === TRUE ) { $ k = $ this -> identifiers ( $ k ) ; } if ( ! $ this -> hasOperator ( $ k ) ) { $ k .= ' = ' ; } if ( $ v != '' ) { $ v = ' ' . $ this -> escape ( $ v ) ; } $ this -> arrayHaving [ ] = $ prefix . $ k . $ v ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheHaving [ ] = $ prefix . $ k . $ v ; $ this -> arrayCacheExists [ ] = 'having' ; } } return $ this ; }
Adds a having clause to a query statement
15,795
final public function limit ( $ value , $ offset = '' ) { $ this -> arrayLimit = $ value ; if ( $ offset != '' ) { $ this -> arrayOffset = $ offset ; } return $ this ; }
Adds a limit to the query statement
15,796
final public function prepare ( ) { $ DB = $ this -> DBO ; $ QUERY = $ this -> compile ( ) ; $ STATEMENT = $ DB -> prepare ( $ QUERY ) ; return $ STATEMENT ; }
Runs a compiled Statement i . e prepare
15,797
public function complexAttrib ( $ name , $ value , $ delimiter = ' ' , $ check = false ) { $ this -> attributes -> setComplexAttrib ( $ name , $ value , $ delimiter , $ check ) ; return $ this ; }
Sets or appends to a composable attribute .
15,798
public function booleanAttrib ( $ name , $ value = true , $ comparisonAttribute = null ) { $ this -> attributes -> setBooleanAttrib ( $ name , $ value , $ comparisonAttribute ) ; return $ this ; }
Sets a boolean attribute if applicable by comparing a value with the value of another attribute .
15,799
public static function fromXml ( \ DOMNodeList $ xml ) { $ items = array ( ) ; foreach ( $ xml as $ xmlTag ) { $ items [ ] = StringLiteral :: create ( $ xmlTag -> textContent ) ; } return new static ( $ items ) ; }
Builds a Collection object from XML .