idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
3,300
public function getPrimaryKeyColumns ( ) { $ primaryKey = $ this -> getPrimaryKey ( ) ; if ( $ primaryKey === null ) { throw new DBALException ( 'Table ' . $ this -> getName ( ) . ' has no primary key.' ) ; } return $ primaryKey -> getColumns ( ) ; }
Returns the primary key columns .
3,301
public function hasIndex ( $ indexName ) { $ indexName = $ this -> normalizeIdentifier ( $ indexName ) ; return isset ( $ this -> _indexes [ $ indexName ] ) ; }
Returns whether this table has an Index with the given name .
3,302
public function getIndex ( $ indexName ) { $ indexName = $ this -> normalizeIdentifier ( $ indexName ) ; if ( ! $ this -> hasIndex ( $ indexName ) ) { throw SchemaException :: indexDoesNotExist ( $ indexName , $ this -> _name ) ; } return $ this -> _indexes [ $ indexName ] ; }
Returns the Index with the given name .
3,303
public function isAutoIncrementsFor ( Table $ table ) { $ primaryKey = $ table -> getPrimaryKey ( ) ; if ( $ primaryKey === null ) { return false ; } $ pkColumns = $ primaryKey -> getColumns ( ) ; if ( count ( $ pkColumns ) !== 1 ) { return false ; } $ column = $ table -> getColumn ( $ pkColumns [ 0 ] ) ; if ( ! $ column -> getAutoincrement ( ) ) { return false ; } $ sequenceName = $ this -> getShortestName ( $ table -> getNamespaceName ( ) ) ; $ tableName = $ table -> getShortestName ( $ table -> getNamespaceName ( ) ) ; $ tableSequenceName = sprintf ( '%s_%s_seq' , $ tableName , $ column -> getShortestName ( $ table -> getNamespaceName ( ) ) ) ; return $ tableSequenceName === $ sequenceName ; }
Checks if this sequence is an autoincrement sequence for a given table .
3,304
private function setDriverOptions ( array $ driverOptions = [ ] ) { $ supportedDriverOptions = [ MYSQLI_OPT_CONNECT_TIMEOUT , MYSQLI_OPT_LOCAL_INFILE , MYSQLI_INIT_COMMAND , MYSQLI_READ_DEFAULT_FILE , MYSQLI_READ_DEFAULT_GROUP , ] ; if ( defined ( 'MYSQLI_SERVER_PUBLIC_KEY' ) ) { $ supportedDriverOptions [ ] = MYSQLI_SERVER_PUBLIC_KEY ; } $ exceptionMsg = "%s option '%s' with value '%s'" ; foreach ( $ driverOptions as $ option => $ value ) { if ( $ option === static :: OPTION_FLAGS ) { continue ; } if ( ! in_array ( $ option , $ supportedDriverOptions , true ) ) { throw new MysqliException ( sprintf ( $ exceptionMsg , 'Unsupported' , $ option , $ value ) ) ; } if ( @ mysqli_options ( $ this -> conn , $ option , $ value ) ) { continue ; } $ msg = sprintf ( $ exceptionMsg , 'Failed to set' , $ option , $ value ) ; $ msg .= sprintf ( ', error: %s (%d)' , mysqli_error ( $ this -> conn ) , mysqli_errno ( $ this -> conn ) ) ; throw new MysqliException ( $ msg , $ this -> conn -> sqlstate , $ this -> conn -> errno ) ; } }
Apply the driver options to the connection .
3,305
private function setSecureConnection ( array $ params ) { if ( ! isset ( $ params [ 'ssl_key' ] ) && ! isset ( $ params [ 'ssl_cert' ] ) && ! isset ( $ params [ 'ssl_ca' ] ) && ! isset ( $ params [ 'ssl_capath' ] ) && ! isset ( $ params [ 'ssl_cipher' ] ) ) { return ; } $ this -> conn -> ssl_set ( $ params [ 'ssl_key' ] ?? null , $ params [ 'ssl_cert' ] ?? null , $ params [ 'ssl_ca' ] ?? null , $ params [ 'ssl_capath' ] ?? null , $ params [ 'ssl_cipher' ] ?? null ) ; }
Establish a secure connection
3,306
public function tryMethod ( ) { $ args = func_get_args ( ) ; $ method = $ args [ 0 ] ; unset ( $ args [ 0 ] ) ; $ args = array_values ( $ args ) ; $ callback = [ $ this , $ method ] ; assert ( is_callable ( $ callback ) ) ; try { return call_user_func_array ( $ callback , $ args ) ; } catch ( Throwable $ e ) { return false ; } }
Tries any method on the schema manager . Normally a method throws an exception when your DBMS doesn t support it or if an error occurs . This method allows you to try and method on your SchemaManager instance and will return false if it does not work or is not supported .
3,307
public function listDatabases ( ) { $ sql = $ this -> _platform -> getListDatabasesSQL ( ) ; $ databases = $ this -> _conn -> fetchAll ( $ sql ) ; return $ this -> _getPortableDatabasesList ( $ databases ) ; }
Lists the available databases for this connection .
3,308
public function listNamespaceNames ( ) { $ sql = $ this -> _platform -> getListNamespacesSQL ( ) ; $ namespaces = $ this -> _conn -> fetchAll ( $ sql ) ; return $ this -> getPortableNamespacesList ( $ namespaces ) ; }
Returns a list of all namespaces in the current database .
3,309
public function listSequences ( $ database = null ) { if ( $ database === null ) { $ database = $ this -> _conn -> getDatabase ( ) ; } $ sql = $ this -> _platform -> getListSequencesSQL ( $ database ) ; $ sequences = $ this -> _conn -> fetchAll ( $ sql ) ; return $ this -> filterAssetNames ( $ this -> _getPortableSequencesList ( $ sequences ) ) ; }
Lists the available sequences for this connection .
3,310
public function listTableColumns ( $ table , $ database = null ) { if ( ! $ database ) { $ database = $ this -> _conn -> getDatabase ( ) ; } $ sql = $ this -> _platform -> getListTableColumnsSQL ( $ table , $ database ) ; $ tableColumns = $ this -> _conn -> fetchAll ( $ sql ) ; return $ this -> _getPortableTableColumnList ( $ table , $ database , $ tableColumns ) ; }
Lists the columns for a given table .
3,311
public function tablesExist ( $ tableNames ) { $ tableNames = array_map ( 'strtolower' , ( array ) $ tableNames ) ; return count ( $ tableNames ) === count ( array_intersect ( $ tableNames , array_map ( 'strtolower' , $ this -> listTableNames ( ) ) ) ) ; }
Returns true if all the given tables exist .
3,312
public function listTableNames ( ) { $ sql = $ this -> _platform -> getListTablesSQL ( ) ; $ tables = $ this -> _conn -> fetchAll ( $ sql ) ; $ tableNames = $ this -> _getPortableTablesList ( $ tables ) ; return $ this -> filterAssetNames ( $ tableNames ) ; }
Returns a list of all tables in the current database .
3,313
protected function filterAssetNames ( $ assetNames ) { $ filter = $ this -> _conn -> getConfiguration ( ) -> getSchemaAssetsFilter ( ) ; if ( ! $ filter ) { return $ assetNames ; } return array_values ( array_filter ( $ assetNames , $ filter ) ) ; }
Filters asset names if they are configured to return only a subset of all the found elements .
3,314
public function listViews ( ) { $ database = $ this -> _conn -> getDatabase ( ) ; $ sql = $ this -> _platform -> getListViewsSQL ( $ database ) ; $ views = $ this -> _conn -> fetchAll ( $ sql ) ; return $ this -> _getPortableViewsList ( $ views ) ; }
Lists the views this connection has .
3,315
public function dropIndex ( $ index , $ table ) { if ( $ index instanceof Index ) { $ index = $ index -> getQuotedName ( $ this -> _platform ) ; } $ this -> _execSql ( $ this -> _platform -> getDropIndexSQL ( $ index , $ table ) ) ; }
Drops the index from the given table .
3,316
public function dropConstraint ( Constraint $ constraint , $ table ) { $ this -> _execSql ( $ this -> _platform -> getDropConstraintSQL ( $ constraint , $ table ) ) ; }
Drops the constraint from the given table .
3,317
public function dropForeignKey ( $ foreignKey , $ table ) { $ this -> _execSql ( $ this -> _platform -> getDropForeignKeySQL ( $ foreignKey , $ table ) ) ; }
Drops a foreign key from a table .
3,318
public function createConstraint ( Constraint $ constraint , $ table ) { $ this -> _execSql ( $ this -> _platform -> getCreateConstraintSQL ( $ constraint , $ table ) ) ; }
Creates a constraint on a table .
3,319
public function createIndex ( Index $ index , $ table ) { $ this -> _execSql ( $ this -> _platform -> getCreateIndexSQL ( $ index , $ table ) ) ; }
Creates a new index on a table .
3,320
public function createForeignKey ( ForeignKeyConstraint $ foreignKey , $ table ) { $ this -> _execSql ( $ this -> _platform -> getCreateForeignKeySQL ( $ foreignKey , $ table ) ) ; }
Creates a new foreign key .
3,321
public function createView ( View $ view ) { $ this -> _execSql ( $ this -> _platform -> getCreateViewSQL ( $ view -> getQuotedName ( $ this -> _platform ) , $ view -> getSql ( ) ) ) ; }
Creates a new view .
3,322
public function dropAndCreateConstraint ( Constraint $ constraint , $ table ) { $ this -> tryMethod ( 'dropConstraint' , $ constraint , $ table ) ; $ this -> createConstraint ( $ constraint , $ table ) ; }
Drops and creates a constraint .
3,323
public function dropAndCreateIndex ( Index $ index , $ table ) { $ this -> tryMethod ( 'dropIndex' , $ index -> getQuotedName ( $ this -> _platform ) , $ table ) ; $ this -> createIndex ( $ index , $ table ) ; }
Drops and creates a new index on a table .
3,324
public function dropAndCreateForeignKey ( ForeignKeyConstraint $ foreignKey , $ table ) { $ this -> tryMethod ( 'dropForeignKey' , $ foreignKey , $ table ) ; $ this -> createForeignKey ( $ foreignKey , $ table ) ; }
Drops and creates a new foreign key .
3,325
public function dropAndCreateSequence ( Sequence $ sequence ) { $ this -> tryMethod ( 'dropSequence' , $ sequence -> getQuotedName ( $ this -> _platform ) ) ; $ this -> createSequence ( $ sequence ) ; }
Drops and create a new sequence .
3,326
public function dropAndCreateTable ( Table $ table ) { $ this -> tryMethod ( 'dropTable' , $ table -> getQuotedName ( $ this -> _platform ) ) ; $ this -> createTable ( $ table ) ; }
Drops and creates a new table .
3,327
public function dropAndCreateView ( View $ view ) { $ this -> tryMethod ( 'dropView' , $ view -> getQuotedName ( $ this -> _platform ) ) ; $ this -> createView ( $ view ) ; }
Drops and creates a new view .
3,328
public function alterTable ( TableDiff $ tableDiff ) { $ queries = $ this -> _platform -> getAlterTableSQL ( $ tableDiff ) ; if ( ! is_array ( $ queries ) || ! count ( $ queries ) ) { return ; } foreach ( $ queries as $ ddlQuery ) { $ this -> _execSql ( $ ddlQuery ) ; } }
Alters an existing tables schema .
3,329
public function renameTable ( $ name , $ newName ) { $ tableDiff = new TableDiff ( $ name ) ; $ tableDiff -> newName = $ newName ; $ this -> alterTable ( $ tableDiff ) ; }
Renames a given table to another name .
3,330
protected function _getPortableTableColumnList ( $ table , $ database , $ tableColumns ) { $ eventManager = $ this -> _platform -> getEventManager ( ) ; $ list = [ ] ; foreach ( $ tableColumns as $ tableColumn ) { $ column = null ; $ defaultPrevented = false ; if ( $ eventManager !== null && $ eventManager -> hasListeners ( Events :: onSchemaColumnDefinition ) ) { $ eventArgs = new SchemaColumnDefinitionEventArgs ( $ tableColumn , $ table , $ database , $ this -> _conn ) ; $ eventManager -> dispatchEvent ( Events :: onSchemaColumnDefinition , $ eventArgs ) ; $ defaultPrevented = $ eventArgs -> isDefaultPrevented ( ) ; $ column = $ eventArgs -> getColumn ( ) ; } if ( ! $ defaultPrevented ) { $ column = $ this -> _getPortableTableColumnDefinition ( $ tableColumn ) ; } if ( ! $ column ) { continue ; } $ name = strtolower ( $ column -> getQuotedName ( $ this -> _platform ) ) ; $ list [ $ name ] = $ column ; } return $ list ; }
Independent of the database the keys of the column list result are lowercased .
3,331
protected function _getPortableTableIndexesList ( $ tableIndexRows , $ tableName = null ) { $ result = [ ] ; foreach ( $ tableIndexRows as $ tableIndex ) { $ indexName = $ keyName = $ tableIndex [ 'key_name' ] ; if ( $ tableIndex [ 'primary' ] ) { $ keyName = 'primary' ; } $ keyName = strtolower ( $ keyName ) ; if ( ! isset ( $ result [ $ keyName ] ) ) { $ options = [ 'lengths' => [ ] , ] ; if ( isset ( $ tableIndex [ 'where' ] ) ) { $ options [ 'where' ] = $ tableIndex [ 'where' ] ; } $ result [ $ keyName ] = [ 'name' => $ indexName , 'columns' => [ ] , 'unique' => ! $ tableIndex [ 'non_unique' ] , 'primary' => $ tableIndex [ 'primary' ] , 'flags' => $ tableIndex [ 'flags' ] ?? [ ] , 'options' => $ options , ] ; } $ result [ $ keyName ] [ 'columns' ] [ ] = $ tableIndex [ 'column_name' ] ; $ result [ $ keyName ] [ 'options' ] [ 'lengths' ] [ ] = $ tableIndex [ 'length' ] ?? null ; } $ eventManager = $ this -> _platform -> getEventManager ( ) ; $ indexes = [ ] ; foreach ( $ result as $ indexKey => $ data ) { $ index = null ; $ defaultPrevented = false ; if ( $ eventManager !== null && $ eventManager -> hasListeners ( Events :: onSchemaIndexDefinition ) ) { $ eventArgs = new SchemaIndexDefinitionEventArgs ( $ data , $ tableName , $ this -> _conn ) ; $ eventManager -> dispatchEvent ( Events :: onSchemaIndexDefinition , $ eventArgs ) ; $ defaultPrevented = $ eventArgs -> isDefaultPrevented ( ) ; $ index = $ eventArgs -> getIndex ( ) ; } if ( ! $ defaultPrevented ) { $ index = new Index ( $ data [ 'name' ] , $ data [ 'columns' ] , $ data [ 'unique' ] , $ data [ 'primary' ] , $ data [ 'flags' ] , $ data [ 'options' ] ) ; } if ( ! $ index ) { continue ; } $ indexes [ $ indexKey ] = $ index ; } return $ indexes ; }
Aggregates and groups the index results according to the required data result .
3,332
public function createSchema ( ) { $ namespaces = [ ] ; if ( $ this -> _platform -> supportsSchemas ( ) ) { $ namespaces = $ this -> listNamespaceNames ( ) ; } $ sequences = [ ] ; if ( $ this -> _platform -> supportsSequences ( ) ) { $ sequences = $ this -> listSequences ( ) ; } $ tables = $ this -> listTables ( ) ; return new Schema ( $ tables , $ sequences , $ this -> createSchemaConfig ( ) , $ namespaces ) ; }
Creates a schema instance for the current database .
3,333
public function createSchemaConfig ( ) { $ schemaConfig = new SchemaConfig ( ) ; $ schemaConfig -> setMaxIdentifierLength ( $ this -> _platform -> getMaxIdentifierLength ( ) ) ; $ searchPaths = $ this -> getSchemaSearchPaths ( ) ; if ( isset ( $ searchPaths [ 0 ] ) ) { $ schemaConfig -> setName ( $ searchPaths [ 0 ] ) ; } $ params = $ this -> _conn -> getParams ( ) ; if ( ! isset ( $ params [ 'defaultTableOptions' ] ) ) { $ params [ 'defaultTableOptions' ] = [ ] ; } if ( ! isset ( $ params [ 'defaultTableOptions' ] [ 'charset' ] ) && isset ( $ params [ 'charset' ] ) ) { $ params [ 'defaultTableOptions' ] [ 'charset' ] = $ params [ 'charset' ] ; } $ schemaConfig -> setDefaultTableOptions ( $ params [ 'defaultTableOptions' ] ) ; return $ schemaConfig ; }
Creates the configuration for this schema .
3,334
public function extractDoctrineTypeFromComment ( $ comment , $ currentType ) { if ( $ comment !== null && preg_match ( '(\(DC2Type:(((?!\)).)+)\))' , $ comment , $ match ) ) { return $ match [ 1 ] ; } return $ currentType ; }
Given a table comment this method tries to extract a typehint for Doctrine Type or returns the type given as default .
3,335
private function buildDsn ( $ host , $ port , $ server , $ dbname , $ username = null , $ password = null , array $ driverOptions = [ ] ) { $ host = $ host ? : 'localhost' ; $ port = $ port ? : 2638 ; if ( ! empty ( $ server ) ) { $ server = ';ServerName=' . $ server ; } return 'HOST=' . $ host . ':' . $ port . $ server . ';DBN=' . $ dbname . ';UID=' . $ username . ';PWD=' . $ password . ';' . implode ( ';' , array_map ( static function ( $ key , $ value ) { return $ key . '=' . $ value ; } , array_keys ( $ driverOptions ) , $ driverOptions ) ) ; }
Build the connection string for given connection parameters and driver options .
3,336
public static function getTypesMap ( ) { return array_map ( static function ( Type $ type ) : string { return get_class ( $ type ) ; } , self :: getTypeRegistry ( ) -> getMap ( ) ) ; }
Gets the types array map which holds all registered types and the corresponding type class
3,337
private function _constructPdoDsn ( array $ params , array $ connectionOptions ) { $ dsn = 'sqlsrv:server=' ; if ( isset ( $ params [ 'host' ] ) ) { $ dsn .= $ params [ 'host' ] ; } if ( isset ( $ params [ 'port' ] ) && ! empty ( $ params [ 'port' ] ) ) { $ dsn .= ',' . $ params [ 'port' ] ; } if ( isset ( $ params [ 'dbname' ] ) ) { $ connectionOptions [ 'Database' ] = $ params [ 'dbname' ] ; } if ( isset ( $ params [ 'MultipleActiveResultSets' ] ) ) { $ connectionOptions [ 'MultipleActiveResultSets' ] = $ params [ 'MultipleActiveResultSets' ] ? 'true' : 'false' ; } return $ dsn . $ this -> getConnectionOptionsDsn ( $ connectionOptions ) ; }
Constructs the Sqlsrv PDO DSN .
3,338
private function getConnectionOptionsDsn ( array $ connectionOptions ) : string { $ connectionOptionsDsn = '' ; foreach ( $ connectionOptions as $ paramName => $ paramValue ) { $ connectionOptionsDsn .= sprintf ( ';%s=%s' , $ paramName , $ paramValue ) ; } return $ connectionOptionsDsn ; }
Converts a connection options array to the DSN
3,339
private function _constructPdoDsn ( array $ params ) { $ dsn = 'pgsql:' ; if ( isset ( $ params [ 'host' ] ) && $ params [ 'host' ] !== '' ) { $ dsn .= 'host=' . $ params [ 'host' ] . ';' ; } if ( isset ( $ params [ 'port' ] ) && $ params [ 'port' ] !== '' ) { $ dsn .= 'port=' . $ params [ 'port' ] . ';' ; } if ( isset ( $ params [ 'dbname' ] ) ) { $ dsn .= 'dbname=' . $ params [ 'dbname' ] . ';' ; } elseif ( isset ( $ params [ 'default_dbname' ] ) ) { $ dsn .= 'dbname=' . $ params [ 'default_dbname' ] . ';' ; } else { $ dsn .= 'dbname=postgres;' ; } if ( isset ( $ params [ 'sslmode' ] ) ) { $ dsn .= 'sslmode=' . $ params [ 'sslmode' ] . ';' ; } if ( isset ( $ params [ 'sslrootcert' ] ) ) { $ dsn .= 'sslrootcert=' . $ params [ 'sslrootcert' ] . ';' ; } if ( isset ( $ params [ 'sslcert' ] ) ) { $ dsn .= 'sslcert=' . $ params [ 'sslcert' ] . ';' ; } if ( isset ( $ params [ 'sslkey' ] ) ) { $ dsn .= 'sslkey=' . $ params [ 'sslkey' ] . ';' ; } if ( isset ( $ params [ 'sslcrl' ] ) ) { $ dsn .= 'sslcrl=' . $ params [ 'sslcrl' ] . ';' ; } if ( isset ( $ params [ 'application_name' ] ) ) { $ dsn .= 'application_name=' . $ params [ 'application_name' ] . ';' ; } return $ dsn ; }
Constructs the Postgres PDO DSN .
3,340
public function generateCacheKeys ( $ query , $ params , $ types , array $ connectionParams = [ ] ) { $ realCacheKey = 'query=' . $ query . '&params=' . serialize ( $ params ) . '&types=' . serialize ( $ types ) . '&connectionParams=' . hash ( 'sha256' , serialize ( $ connectionParams ) ) ; if ( $ this -> cacheKey === null ) { $ cacheKey = sha1 ( $ realCacheKey ) ; } else { $ cacheKey = $ this -> cacheKey ; } return [ $ cacheKey , $ realCacheKey ] ; }
Generates the real cache key from query params types and connection parameters .
3,341
private function bindTypedParameters ( ) { $ streams = $ values = [ ] ; $ types = $ this -> types ; foreach ( $ this -> _bindedValues as $ parameter => $ value ) { if ( ! isset ( $ types [ $ parameter - 1 ] ) ) { $ types [ $ parameter - 1 ] = static :: $ _paramTypeMap [ ParameterType :: STRING ] ; } if ( $ types [ $ parameter - 1 ] === static :: $ _paramTypeMap [ ParameterType :: LARGE_OBJECT ] ) { if ( is_resource ( $ value ) ) { if ( get_resource_type ( $ value ) !== 'stream' ) { throw new InvalidArgumentException ( 'Resources passed with the LARGE_OBJECT parameter type must be stream resources.' ) ; } $ streams [ $ parameter ] = $ value ; $ values [ $ parameter ] = null ; continue ; } $ types [ $ parameter - 1 ] = static :: $ _paramTypeMap [ ParameterType :: STRING ] ; } $ values [ $ parameter ] = $ value ; } if ( ! $ this -> _stmt -> bind_param ( $ types , ... $ values ) ) { throw new MysqliException ( $ this -> _stmt -> error , $ this -> _stmt -> sqlstate , $ this -> _stmt -> errno ) ; } $ this -> sendLongData ( $ streams ) ; }
Binds parameters with known types previously bound to the statement
3,342
private function bindUntypedValues ( array $ values ) { $ params = [ ] ; $ types = str_repeat ( 's' , count ( $ values ) ) ; foreach ( $ values as & $ v ) { $ params [ ] = & $ v ; } return $ this -> _stmt -> bind_param ( $ types , ... $ params ) ; }
Binds a array of values to bound parameters .
3,343
public static function fromSQLAnywhereError ( $ conn = null , $ stmt = null ) { $ state = $ conn ? sasql_sqlstate ( $ conn ) : sasql_sqlstate ( ) ; $ code = null ; $ message = null ; if ( $ stmt ) { $ code = sasql_stmt_errno ( $ stmt ) ; $ message = sasql_stmt_error ( $ stmt ) ; } if ( $ conn && ! $ code ) { $ code = sasql_errorcode ( $ conn ) ; $ message = sasql_error ( $ conn ) ; } if ( ! $ conn || ! $ code ) { $ code = sasql_errorcode ( ) ; $ message = sasql_error ( ) ; } if ( $ message ) { return new self ( 'SQLSTATE [' . $ state . '] [' . $ code . '] ' . $ message , $ state , $ code ) ; } return new self ( 'SQL Anywhere error occurred but no error message was retrieved from driver.' , $ state , $ code ) ; }
Helper method to turn SQL Anywhere error into exception .
3,344
protected function _setName ( $ name ) { if ( $ this -> isIdentifierQuoted ( $ name ) ) { $ this -> _quoted = true ; $ name = $ this -> trimQuotes ( $ name ) ; } if ( strpos ( $ name , '.' ) !== false ) { $ parts = explode ( '.' , $ name ) ; $ this -> _namespace = $ parts [ 0 ] ; $ name = $ parts [ 1 ] ; } $ this -> _name = $ name ; }
Sets the name of this asset .
3,345
public function getQuotedName ( AbstractPlatform $ platform ) { $ keywords = $ platform -> getReservedKeywordsList ( ) ; $ parts = explode ( '.' , $ this -> getName ( ) ) ; foreach ( $ parts as $ k => $ v ) { $ parts [ $ k ] = $ this -> _quoted || $ keywords -> isKeyword ( $ v ) ? $ platform -> quoteIdentifier ( $ v ) : $ v ; } return implode ( '.' , $ parts ) ; }
Gets the quoted representation of this asset but only if it was defined with one . Otherwise return the plain unquoted value as inserted .
3,346
protected function _generateIdentifierName ( $ columnNames , $ prefix = '' , $ maxSize = 30 ) { $ hash = implode ( '' , array_map ( static function ( $ column ) { return dechex ( crc32 ( $ column ) ) ; } , $ columnNames ) ) ; return strtoupper ( substr ( $ prefix . '_' . $ hash , 0 , $ maxSize ) ) ; }
Generates an identifier from a list of column names obeying a certain string length .
3,347
public function nextValue ( $ sequenceName ) { if ( isset ( $ this -> sequences [ $ sequenceName ] ) ) { $ value = $ this -> sequences [ $ sequenceName ] [ 'value' ] ; $ this -> sequences [ $ sequenceName ] [ 'value' ] ++ ; if ( $ this -> sequences [ $ sequenceName ] [ 'value' ] >= $ this -> sequences [ $ sequenceName ] [ 'max' ] ) { unset ( $ this -> sequences [ $ sequenceName ] ) ; } return $ value ; } $ this -> conn -> beginTransaction ( ) ; try { $ platform = $ this -> conn -> getDatabasePlatform ( ) ; $ sql = 'SELECT sequence_value, sequence_increment_by' . ' FROM ' . $ platform -> appendLockHint ( $ this -> generatorTableName , LockMode :: PESSIMISTIC_WRITE ) . ' WHERE sequence_name = ? ' . $ platform -> getWriteLockSQL ( ) ; $ stmt = $ this -> conn -> executeQuery ( $ sql , [ $ sequenceName ] ) ; $ row = $ stmt -> fetch ( FetchMode :: ASSOCIATIVE ) ; if ( $ row !== false ) { $ row = array_change_key_case ( $ row , CASE_LOWER ) ; $ value = $ row [ 'sequence_value' ] ; $ value ++ ; if ( $ row [ 'sequence_increment_by' ] > 1 ) { $ this -> sequences [ $ sequenceName ] = [ 'value' => $ value , 'max' => $ row [ 'sequence_value' ] + $ row [ 'sequence_increment_by' ] , ] ; } $ sql = 'UPDATE ' . $ this -> generatorTableName . ' ' . 'SET sequence_value = sequence_value + sequence_increment_by ' . 'WHERE sequence_name = ? AND sequence_value = ?' ; $ rows = $ this -> conn -> executeUpdate ( $ sql , [ $ sequenceName , $ row [ 'sequence_value' ] ] ) ; if ( $ rows !== 1 ) { throw new DBALException ( 'Race-condition detected while updating sequence. Aborting generation' ) ; } } else { $ this -> conn -> insert ( $ this -> generatorTableName , [ 'sequence_name' => $ sequenceName , 'sequence_value' => 1 , 'sequence_increment_by' => 1 ] ) ; $ value = 1 ; } $ this -> conn -> commit ( ) ; } catch ( Throwable $ e ) { $ this -> conn -> rollBack ( ) ; throw new DBALException ( 'Error occurred while generating ID with TableGenerator, aborted generation: ' . $ e -> getMessage ( ) , 0 , $ e ) ; } return $ value ; }
Generates the next unused value for the given sequence name .
3,348
protected function getCreateColumnCommentSQL ( $ tableName , $ columnName , $ comment ) { if ( strpos ( $ tableName , '.' ) !== false ) { [ $ schemaSQL , $ tableSQL ] = explode ( '.' , $ tableName ) ; $ schemaSQL = $ this -> quoteStringLiteral ( $ schemaSQL ) ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableSQL ) ; } else { $ schemaSQL = "'dbo'" ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableName ) ; } return $ this -> getAddExtendedPropertySQL ( 'MS_Description' , $ comment , 'SCHEMA' , $ schemaSQL , 'TABLE' , $ tableSQL , 'COLUMN' , $ columnName ) ; }
Returns the SQL statement for creating a column comment .
3,349
public function getDefaultConstraintDeclarationSQL ( $ table , array $ column ) { if ( ! isset ( $ column [ 'default' ] ) ) { throw new InvalidArgumentException ( "Incomplete column definition. 'default' required." ) ; } $ columnName = new Identifier ( $ column [ 'name' ] ) ; return ' CONSTRAINT ' . $ this -> generateDefaultConstraintName ( $ table , $ column [ 'name' ] ) . $ this -> getDefaultValueDeclarationSQL ( $ column ) . ' FOR ' . $ columnName -> getQuotedName ( $ this ) ; }
Returns the SQL snippet for declaring a default constraint .
3,350
private function _appendUniqueConstraintDefinition ( $ sql , Index $ index ) { $ fields = [ ] ; foreach ( $ index -> getQuotedColumns ( $ this ) as $ field ) { $ fields [ ] = $ field . ' IS NOT NULL' ; } return $ sql . ' WHERE ' . implode ( ' AND ' , $ fields ) ; }
Extend unique key constraint with required filters
3,351
private function getAlterTableAddDefaultConstraintClause ( $ tableName , Column $ column ) { $ columnDef = $ column -> toArray ( ) ; $ columnDef [ 'name' ] = $ column -> getQuotedName ( $ this ) ; return 'ADD' . $ this -> getDefaultConstraintDeclarationSQL ( $ tableName , $ columnDef ) ; }
Returns the SQL clause for adding a default constraint in an ALTER TABLE statement .
3,352
private function alterColumnRequiresDropDefaultConstraint ( ColumnDiff $ columnDiff ) { if ( ! $ columnDiff -> fromColumn instanceof Column ) { return false ; } if ( $ columnDiff -> fromColumn -> getDefault ( ) === null ) { return false ; } if ( $ columnDiff -> hasChanged ( 'default' ) ) { return true ; } return $ columnDiff -> hasChanged ( 'type' ) || $ columnDiff -> hasChanged ( 'fixed' ) ; }
Checks whether a column alteration requires dropping its default constraint first .
3,353
protected function getAlterColumnCommentSQL ( $ tableName , $ columnName , $ comment ) { if ( strpos ( $ tableName , '.' ) !== false ) { [ $ schemaSQL , $ tableSQL ] = explode ( '.' , $ tableName ) ; $ schemaSQL = $ this -> quoteStringLiteral ( $ schemaSQL ) ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableSQL ) ; } else { $ schemaSQL = "'dbo'" ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableName ) ; } return $ this -> getUpdateExtendedPropertySQL ( 'MS_Description' , $ comment , 'SCHEMA' , $ schemaSQL , 'TABLE' , $ tableSQL , 'COLUMN' , $ columnName ) ; }
Returns the SQL statement for altering a column comment .
3,354
protected function getDropColumnCommentSQL ( $ tableName , $ columnName ) { if ( strpos ( $ tableName , '.' ) !== false ) { [ $ schemaSQL , $ tableSQL ] = explode ( '.' , $ tableName ) ; $ schemaSQL = $ this -> quoteStringLiteral ( $ schemaSQL ) ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableSQL ) ; } else { $ schemaSQL = "'dbo'" ; $ tableSQL = $ this -> quoteStringLiteral ( $ tableName ) ; } return $ this -> getDropExtendedPropertySQL ( 'MS_Description' , 'SCHEMA' , $ schemaSQL , 'TABLE' , $ tableSQL , 'COLUMN' , $ columnName ) ; }
Returns the SQL statement for dropping a column comment .
3,355
public function getAddExtendedPropertySQL ( $ name , $ value = null , $ level0Type = null , $ level0Name = null , $ level1Type = null , $ level1Name = null , $ level2Type = null , $ level2Name = null ) { return 'EXEC sp_addextendedproperty ' . 'N' . $ this -> quoteStringLiteral ( $ name ) . ', N' . $ this -> quoteStringLiteral ( ( string ) $ value ) . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level0Type ) . ', ' . $ level0Name . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level1Type ) . ', ' . $ level1Name . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level2Type ) . ', ' . $ level2Name ; }
Returns the SQL statement for adding an extended property to a database object .
3,356
public function getDropExtendedPropertySQL ( $ name , $ level0Type = null , $ level0Name = null , $ level1Type = null , $ level1Name = null , $ level2Type = null , $ level2Name = null ) { return 'EXEC sp_dropextendedproperty ' . 'N' . $ this -> quoteStringLiteral ( $ name ) . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level0Type ) . ', ' . $ level0Name . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level1Type ) . ', ' . $ level1Name . ', ' . 'N' . $ this -> quoteStringLiteral ( ( string ) $ level2Type ) . ', ' . $ level2Name ; }
Returns the SQL statement for dropping an extended property from a database object .
3,357
private function getTableWhereClause ( $ table , $ schemaColumn , $ tableColumn ) { if ( strpos ( $ table , '.' ) !== false ) { [ $ schema , $ table ] = explode ( '.' , $ table ) ; $ schema = $ this -> quoteStringLiteral ( $ schema ) ; $ table = $ this -> quoteStringLiteral ( $ table ) ; } else { $ schema = 'SCHEMA_NAME()' ; $ table = $ this -> quoteStringLiteral ( $ table ) ; } return sprintf ( '(%s = %s AND %s = %s)' , $ tableColumn , $ table , $ schemaColumn , $ schema ) ; }
Returns the where clause to filter schema and table name in a query .
3,358
private function isOrderByInTopNSubquery ( $ query , $ currentPosition ) { $ subQueryBuffer = '' ; $ parenCount = 0 ; while ( $ parenCount >= 0 && $ currentPosition >= 0 ) { if ( $ query [ $ currentPosition ] === '(' ) { $ parenCount -- ; } elseif ( $ query [ $ currentPosition ] === ')' ) { $ parenCount ++ ; } $ subQueryBuffer = ( $ parenCount === 0 ? $ query [ $ currentPosition ] : ' ' ) . $ subQueryBuffer ; $ currentPosition -- ; } return ( bool ) preg_match ( '/SELECT\s+(DISTINCT\s+)?TOP\s/i' , $ subQueryBuffer ) ; }
Check an ORDER BY clause to see if it is in a TOP N query or subquery .
3,359
private function generateIdentifierName ( $ identifier ) { $ identifier = new Identifier ( $ identifier ) ; return strtoupper ( dechex ( crc32 ( $ identifier -> getName ( ) ) ) ) ; }
Returns a hash value for a given identifier .
3,360
public function get ( string $ name ) : Type { if ( ! isset ( $ this -> instances [ $ name ] ) ) { throw DBALException :: unknownColumnType ( $ name ) ; } return $ this -> instances [ $ name ] ; }
Finds a type by the given name .
3,361
public function lookupName ( Type $ type ) : string { $ name = $ this -> findTypeName ( $ type ) ; if ( $ name === null ) { throw DBALException :: typeNotRegistered ( $ type ) ; } return $ name ; }
Finds a name for the given type .
3,362
public function register ( string $ name , Type $ type ) : void { if ( isset ( $ this -> instances [ $ name ] ) ) { throw DBALException :: typeExists ( $ name ) ; } if ( $ this -> findTypeName ( $ type ) !== null ) { throw DBALException :: typeAlreadyRegistered ( $ type ) ; } $ this -> instances [ $ name ] = $ type ; }
Registers a custom type to the type map .
3,363
public static function fromConnectionParameters ( array $ params ) : self { if ( ! empty ( $ params [ 'connectstring' ] ) ) { return new self ( $ params [ 'connectstring' ] ) ; } if ( empty ( $ params [ 'host' ] ) ) { return new self ( $ params [ 'dbname' ] ?? '' ) ; } $ connectData = [ ] ; if ( isset ( $ params [ 'servicename' ] ) || isset ( $ params [ 'dbname' ] ) ) { $ serviceKey = 'SID' ; if ( ! empty ( $ params [ 'service' ] ) ) { $ serviceKey = 'SERVICE_NAME' ; } $ serviceName = $ params [ 'servicename' ] ?? $ params [ 'dbname' ] ; $ connectData [ $ serviceKey ] = $ serviceName ; } if ( ! empty ( $ params [ 'instancename' ] ) ) { $ connectData [ 'INSTANCE_NAME' ] = $ params [ 'instancename' ] ; } if ( ! empty ( $ params [ 'pooled' ] ) ) { $ connectData [ 'SERVER' ] = 'POOLED' ; } return self :: fromArray ( [ 'DESCRIPTION' => [ 'ADDRESS' => [ 'PROTOCOL' => 'TCP' , 'HOST' => $ params [ 'host' ] , 'PORT' => $ params [ 'port' ] ?? 1521 , ] , 'CONNECT_DATA' => $ connectData , ] , ] ) ; }
Creates the object from the given DBAL connection parameters .
3,364
private static function formatParameters ( array $ params ) { return '[' . implode ( ', ' , array_map ( static function ( $ param ) { if ( is_resource ( $ param ) ) { return ( string ) $ param ; } $ json = @ json_encode ( $ param ) ; if ( ! is_string ( $ json ) || $ json === 'null' && is_string ( $ param ) ) { return sprintf ( '"%s"' , preg_replace ( '/.{2}/' , '\\x$0' , bin2hex ( $ param ) ) ) ; } return $ json ; } , $ params ) ) . ']' ; }
Returns a human - readable representation of an array of parameters . This properly handles binary data by returning a hex representation .
3,365
public function getSchemaSearchPaths ( ) { $ params = $ this -> _conn -> getParams ( ) ; $ schema = explode ( ',' , $ this -> _conn -> fetchColumn ( 'SHOW search_path' ) ) ; if ( isset ( $ params [ 'user' ] ) ) { $ schema = str_replace ( '"$user"' , $ params [ 'user' ] , $ schema ) ; } return array_map ( 'trim' , $ schema ) ; }
Returns an array of schema search paths .
3,366
public function determineExistingSchemaSearchPaths ( ) { $ names = $ this -> getSchemaNames ( ) ; $ paths = $ this -> getSchemaSearchPaths ( ) ; $ this -> existingSchemaPaths = array_filter ( $ paths , static function ( $ v ) use ( $ names ) { return in_array ( $ v , $ names ) ; } ) ; }
Sets or resets the order of the existing schemas in the current search path of the user .
3,367
public function hasNamespace ( $ namespaceName ) { $ namespaceName = strtolower ( $ this -> getUnquotedAssetName ( $ namespaceName ) ) ; return isset ( $ this -> namespaces [ $ namespaceName ] ) ; }
Does this schema have a namespace with the given name?
3,368
public function hasTable ( $ tableName ) { $ tableName = $ this -> getFullQualifiedAssetName ( $ tableName ) ; return isset ( $ this -> _tables [ $ tableName ] ) ; }
Does this schema have a table with the given name?
3,369
public function createNamespace ( $ namespaceName ) { $ unquotedNamespaceName = strtolower ( $ this -> getUnquotedAssetName ( $ namespaceName ) ) ; if ( isset ( $ this -> namespaces [ $ unquotedNamespaceName ] ) ) { throw SchemaException :: namespaceAlreadyExists ( $ unquotedNamespaceName ) ; } $ this -> namespaces [ $ unquotedNamespaceName ] = $ namespaceName ; return $ this ; }
Creates a new namespace .
3,370
public function dropTable ( $ tableName ) { $ tableName = $ this -> getFullQualifiedAssetName ( $ tableName ) ; $ this -> getTable ( $ tableName ) ; unset ( $ this -> _tables [ $ tableName ] ) ; return $ this ; }
Drops a table from the schema .
3,371
public function createSequence ( $ sequenceName , $ allocationSize = 1 , $ initialValue = 1 ) { $ seq = new Sequence ( $ sequenceName , $ allocationSize , $ initialValue ) ; $ this -> _addSequence ( $ seq ) ; return $ seq ; }
Creates a new sequence .
3,372
public function toSql ( AbstractPlatform $ platform ) { $ sqlCollector = new CreateSchemaSqlCollector ( $ platform ) ; $ this -> visit ( $ sqlCollector ) ; return $ sqlCollector -> getQueries ( ) ; }
Returns an array of necessary SQL queries to create the schema on the given platform .
3,373
public function toDropSql ( AbstractPlatform $ platform ) { $ dropSqlCollector = new DropSchemaSqlCollector ( $ platform ) ; $ this -> visit ( $ dropSqlCollector ) ; return $ dropSqlCollector -> getQueries ( ) ; }
Return an array of necessary SQL queries to drop the schema on the given platform .
3,374
private function createStripHostsPatterns ( $ stripHostsConfig ) { if ( ! is_array ( $ stripHostsConfig ) ) { return $ stripHostsConfig ; } $ patterns = [ ] ; foreach ( $ stripHostsConfig as $ entry ) { if ( ! strlen ( $ entry ) ) { continue ; } if ( '/private' === $ entry || '/local' === $ entry ) { $ patterns [ ] = [ $ entry ] ; continue ; } elseif ( false !== strpos ( $ entry , ':' ) ) { $ type = 'ipv6' ; if ( ! defined ( 'AF_INET6' ) ) { $ this -> output -> writeln ( '<error>Unable to use IPv6.</error>' ) ; continue ; } } elseif ( 0 === preg_match ( '#[^/.\\d]#' , $ entry ) ) { $ type = 'ipv4' ; } else { $ type = 'name' ; $ host = '#^(?:.+\.)?' . preg_quote ( $ entry , '#' ) . '$#ui' ; $ patterns [ ] = [ $ type , $ host ] ; continue ; } @ list ( $ host , $ mask ) = explode ( '/' , $ entry , 2 ) ; $ host = @ inet_pton ( $ host ) ; if ( false === $ host || ( int ) $ mask != $ mask ) { $ this -> output -> writeln ( sprintf ( '<error>Invalid subnet "%s"</error>' , $ entry ) ) ; continue ; } $ host = unpack ( 'N*' , $ host ) ; if ( null === $ mask ) { $ mask = 'ipv4' === $ type ? 32 : 128 ; } else { $ mask = ( int ) $ mask ; if ( $ mask < 0 || 'ipv4' === $ type && $ mask > 32 || 'ipv6' === $ type && $ mask > 128 ) { continue ; } } $ patterns [ ] = [ $ type , $ host , $ mask ] ; } return $ patterns ; }
Create patterns from strip - hosts
3,375
private function applyStripHosts ( ) { if ( false === $ this -> stripHosts ) { return ; } foreach ( $ this -> selected as $ uniqueName => $ package ) { $ sources = [ ] ; if ( $ package -> getSourceType ( ) ) { $ sources [ ] = 'source' ; } if ( $ package -> getDistType ( ) ) { $ sources [ ] = 'dist' ; } foreach ( $ sources as $ i => $ s ) { $ url = 'source' === $ s ? $ package -> getSourceUrl ( ) : $ package -> getDistUrl ( ) ; if ( 'dist' === $ s && null !== $ this -> archiveEndpoint && substr ( $ url , 0 , strlen ( $ this -> archiveEndpoint ) ) === $ this -> archiveEndpoint ) { continue ; } if ( $ this -> matchStripHostsPatterns ( $ url ) ) { if ( 'dist' === $ s ) { $ package -> setDistType ( null ) ; } else { $ package -> setSourceType ( null ) ; } unset ( $ sources [ $ i ] ) ; if ( 0 === count ( $ sources ) ) { $ this -> output -> writeln ( sprintf ( '<error>%s has no source left after applying the strip-hosts filters and will be removed</error>' , $ package -> getUniqueName ( ) ) ) ; unset ( $ this -> selected [ $ uniqueName ] ) ; } } } } }
Apply the patterns from strip - hosts
3,376
private function matchStripHostsPatterns ( $ url ) { if ( Filesystem :: isLocalPath ( $ url ) ) { return true ; } if ( is_array ( $ this -> stripHosts ) ) { $ url = trim ( parse_url ( $ url , PHP_URL_HOST ) , '[]' ) ; if ( false !== filter_var ( $ url , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { $ urltype = 'ipv4' ; } elseif ( false !== filter_var ( $ url , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { $ urltype = 'ipv6' ; } else { $ urltype = 'name' ; } if ( 'ipv4' === $ urltype || 'ipv6' === $ urltype ) { $ urlunpack = unpack ( 'N*' , @ inet_pton ( $ url ) ) ; } foreach ( $ this -> stripHosts as $ pattern ) { @ list ( $ type , $ host , $ mask ) = $ pattern ; if ( '/local' === $ type ) { if ( 'name' === $ urltype && 'localhost' === strtolower ( $ url ) || ( 'ipv4' === $ urltype || 'ipv6' === $ urltype ) && false === filter_var ( $ url , FILTER_VALIDATE_IP , FILTER_FLAG_NO_RES_RANGE ) ) { return true ; } } elseif ( '/private' === $ type ) { if ( ( 'ipv4' === $ urltype || 'ipv6' === $ urltype ) && false === filter_var ( $ url , FILTER_VALIDATE_IP , FILTER_FLAG_NO_PRIV_RANGE ) ) { return true ; } } elseif ( 'ipv4' === $ type || 'ipv6' === $ type ) { if ( $ urltype === $ type && $ this -> matchAddr ( $ urlunpack , $ host , $ mask ) ) { return true ; } } elseif ( 'name' === $ type ) { if ( 'name' === $ urltype && preg_match ( $ host , $ url ) ) { return true ; } } } } }
Match an URL against the patterns from strip - hosts
3,377
private function matchAddr ( $ addr1 , $ addr2 , $ len = 0 , $ chunklen = 32 ) { for ( ; $ len > 0 ; $ len -= $ chunklen , next ( $ addr1 ) , next ( $ addr2 ) ) { $ shift = $ len >= $ chunklen ? 0 : $ chunklen - $ len ; if ( ( current ( $ addr1 ) >> $ shift ) !== ( current ( $ addr2 ) >> $ shift ) ) { return false ; } } return true ; }
Test if two addresses have the same prefix
3,378
private function addRepositories ( Pool $ pool , array $ repos ) { foreach ( $ repos as $ repo ) { try { $ pool -> addRepository ( $ repo ) ; } catch ( \ Exception $ exception ) { if ( ! $ this -> skipErrors ) { throw $ exception ; } $ this -> output -> writeln ( sprintf ( "<error>Skipping Exception '%s'.</error>" , $ exception -> getMessage ( ) ) ) ; } } }
Add repositories to a pool
3,379
private function setSelectedAsAbandoned ( ) { foreach ( $ this -> selected as $ name => $ package ) { if ( array_key_exists ( $ package -> getName ( ) , $ this -> abandoned ) ) { $ package -> setAbandoned ( $ this -> abandoned [ $ package -> getName ( ) ] ) ; } } }
Marks selected packages as abandoned by Configuration file
3,380
private function getFilteredLinks ( Composer $ composer ) { $ links = array_values ( $ composer -> getPackage ( ) -> getRequires ( ) ) ; if ( $ this -> hasFilterForPackages ( ) ) { $ packagesFilter = $ this -> packagesFilter ; $ links = array_filter ( $ links , function ( Link $ link ) use ( $ packagesFilter ) { return in_array ( $ link -> getTarget ( ) , $ packagesFilter ) ; } ) ; } return array_values ( $ links ) ; }
Gets a list of filtered Links .
3,381
private function getAllLinks ( $ repos , $ minimumStability , $ verbose ) { $ links = [ ] ; foreach ( $ repos as $ repo ) { if ( $ repo instanceof ComposerRepository && $ repo -> hasProviders ( ) ) { foreach ( $ repo -> getProviderNames ( ) as $ name ) { $ links [ ] = new Link ( '__root__' , $ name , new EmptyConstraint ( ) , 'requires' , '*' ) ; } } else { $ packages = $ this -> getPackages ( $ repo ) ; foreach ( $ packages as $ package ) { if ( $ package instanceof AliasPackage ) { continue ; } if ( BasePackage :: $ stabilities [ $ package -> getStability ( ) ] > BasePackage :: $ stabilities [ $ minimumStability ] ) { if ( $ verbose ) { $ this -> output -> writeln ( 'Skipped ' . $ package -> getPrettyName ( ) . ' (' . $ package -> getStability ( ) . ')' ) ; } continue ; } $ links [ ] = $ package ; } } } return $ links ; }
Gets all Links .
3,382
private function getDepRepos ( Composer $ composer ) { $ depRepos = [ ] ; if ( \ is_array ( $ this -> depRepositories ) ) { $ rm = $ composer -> getRepositoryManager ( ) ; foreach ( $ this -> depRepositories as $ index => $ repoConfig ) { $ name = \ is_int ( $ index ) && isset ( $ repoConfig [ 'url' ] ) ? $ repoConfig [ 'url' ] : $ index ; $ type = $ repoConfig [ 'type' ] ?? '' ; $ depRepos [ $ index ] = $ rm -> createRepository ( $ type , $ repoConfig , $ name ) ; } } return $ depRepos ; }
Create the additional repositories
3,383
private function getPackages ( RepositoryInterface $ repo ) { $ packages = [ ] ; if ( $ this -> hasFilterForPackages ( ) ) { foreach ( $ this -> packagesFilter as $ filter ) { $ packages += $ repo -> findPackages ( $ filter ) ; } } else { $ packages = $ repo -> getPackages ( ) ; } return $ packages ; }
Gets All or filtered Packages of a Repository .
3,384
private function getRequired ( PackageInterface $ package , bool $ isRoot ) { $ required = [ ] ; if ( $ this -> requireDependencies ) { $ required = $ package -> getRequires ( ) ; } if ( ( $ isRoot || ! $ this -> requireDependencyFilter ) && $ this -> requireDevDependencies ) { $ required = array_merge ( $ required , $ package -> getDevRequires ( ) ) ; } return $ required ; }
Gets the required Links if needed .
3,385
private function filterRepositories ( array $ repositories ) { $ url = $ this -> repositoryFilter ; return array_filter ( $ repositories , function ( $ repository ) use ( $ url ) { if ( ! ( $ repository instanceof ConfigurableRepositoryInterface ) ) { return false ; } $ config = $ repository -> getRepoConfig ( ) ; if ( ! isset ( $ config [ 'url' ] ) || $ config [ 'url' ] !== $ url ) { return false ; } return true ; } ) ; }
Filter given repositories .
3,386
private function setDependencies ( array $ packages ) : self { $ dependencies = [ ] ; foreach ( $ packages as $ package ) { foreach ( $ package -> getRequires ( ) as $ link ) { $ dependencies [ $ link -> getTarget ( ) ] [ $ link -> getSource ( ) ] = $ link -> getSource ( ) ; } } $ this -> dependencies = $ dependencies ; return $ this ; }
Defines the required packages .
3,387
private function getMappedPackageList ( array $ packages ) : array { $ groupedPackages = $ this -> groupPackagesByName ( $ packages ) ; $ mappedPackages = [ ] ; foreach ( $ groupedPackages as $ name => $ packages ) { $ highest = $ this -> getHighestVersion ( $ packages ) ; $ mappedPackages [ $ name ] = [ 'highest' => $ highest , 'abandoned' => $ highest instanceof CompletePackageInterface ? $ highest -> isAbandoned ( ) : false , 'replacement' => $ highest instanceof CompletePackageInterface ? $ highest -> getReplacementPackage ( ) : null , 'versions' => $ this -> getDescSortedVersions ( $ packages ) , ] ; } return $ mappedPackages ; }
Gets a list of packages grouped by name with a list of versions .
3,388
private function groupPackagesByName ( array $ packages ) : array { $ groupedPackages = [ ] ; foreach ( $ packages as $ package ) { $ groupedPackages [ $ package -> getName ( ) ] [ ] = $ package ; } return $ groupedPackages ; }
Gets a list of packages grouped by name .
3,389
private function getHighestVersion ( array $ packages ) : ? PackageInterface { $ highestVersion = null ; foreach ( $ packages as $ package ) { if ( null === $ highestVersion || version_compare ( $ package -> getVersion ( ) , $ highestVersion -> getVersion ( ) , '>=' ) ) { $ highestVersion = $ package ; } } return $ highestVersion ; }
Gets the highest version of packages .
3,390
private function getDescSortedVersions ( array $ packages ) : array { usort ( $ packages , function ( PackageInterface $ a , PackageInterface $ b ) { return version_compare ( $ b -> getVersion ( ) , $ a -> getVersion ( ) ) ; } ) ; return $ packages ; }
Sorts by version the list of packages .
3,391
public function parse ( ) { if ( ! $ this -> isHbbTv ( ) ) { return false ; } parent :: parse ( ) ; $ this -> deviceType = self :: DEVICE_TYPE_TV ; return true ; }
Parses the current UA and checks whether it contains HbbTv information
3,392
public function setUserAgent ( $ userAgent ) { if ( $ this -> userAgent != $ userAgent ) { $ this -> reset ( ) ; } $ this -> userAgent = $ userAgent ; }
Sets the useragent to be parsed
3,393
public function isDesktop ( ) { $ osShort = $ this -> getOs ( 'short_name' ) ; if ( empty ( $ osShort ) || self :: UNKNOWN == $ osShort ) { return false ; } if ( $ this -> usesMobileBrowser ( ) ) { return false ; } $ decodedFamily = OperatingSystem :: getOsFamily ( $ osShort ) ; return in_array ( $ decodedFamily , self :: $ desktopOsArray ) ; }
Returns if the parsed UA was identified as desktop device Desktop devices are all devices with an unknown type that are running a desktop os
3,394
public function getOs ( $ attr = '' ) { if ( $ attr == '' ) { return $ this -> os ; } if ( ! isset ( $ this -> os [ $ attr ] ) ) { return self :: UNKNOWN ; } return $ this -> os [ $ attr ] ; }
Returns the operating system data extracted from the parsed UA
3,395
public function getClient ( $ attr = '' ) { if ( $ attr == '' ) { return $ this -> client ; } if ( ! isset ( $ this -> client [ $ attr ] ) ) { return self :: UNKNOWN ; } return $ this -> client [ $ attr ] ; }
Returns the client data extracted from the parsed UA
3,396
public function parse ( ) { if ( $ this -> isParsed ( ) ) { return ; } $ this -> parsed = true ; if ( empty ( $ this -> userAgent ) || ! preg_match ( '/([a-z])/i' , $ this -> userAgent ) ) { return ; } $ this -> parseBot ( ) ; if ( $ this -> isBot ( ) ) { return ; } $ this -> parseOs ( ) ; $ this -> parseClient ( ) ; $ this -> parseDevice ( ) ; }
Triggers the parsing of the current user agent
3,397
protected function parseBot ( ) { if ( $ this -> skipBotDetection ) { $ this -> bot = false ; return false ; } $ parsers = $ this -> getBotParsers ( ) ; foreach ( $ parsers as $ parser ) { $ parser -> setUserAgent ( $ this -> getUserAgent ( ) ) ; $ parser -> setYamlParser ( $ this -> getYamlParser ( ) ) ; $ parser -> setCache ( $ this -> getCache ( ) ) ; if ( $ this -> discardBotInformation ) { $ parser -> discardDetails ( ) ; } $ bot = $ parser -> parse ( ) ; if ( ! empty ( $ bot ) ) { $ this -> bot = $ bot ; break ; } } }
Parses the UA for bot information using the Bot parser
3,398
public static function getInfoFromUserAgent ( $ ua ) { $ deviceDetector = new DeviceDetector ( $ ua ) ; $ deviceDetector -> parse ( ) ; if ( $ deviceDetector -> isBot ( ) ) { return array ( 'user_agent' => $ deviceDetector -> getUserAgent ( ) , 'bot' => $ deviceDetector -> getBot ( ) ) ; } $ osFamily = OperatingSystem :: getOsFamily ( $ deviceDetector -> getOs ( 'short_name' ) ) ; $ browserFamily = \ DeviceDetector \ Parser \ Client \ Browser :: getBrowserFamily ( $ deviceDetector -> getClient ( 'short_name' ) ) ; $ processed = array ( 'user_agent' => $ deviceDetector -> getUserAgent ( ) , 'os' => $ deviceDetector -> getOs ( ) , 'client' => $ deviceDetector -> getClient ( ) , 'device' => array ( 'type' => $ deviceDetector -> getDeviceName ( ) , 'brand' => $ deviceDetector -> getBrand ( ) , 'model' => $ deviceDetector -> getModel ( ) , ) , 'os_family' => $ osFamily !== false ? $ osFamily : 'Unknown' , 'browser_family' => $ browserFamily !== false ? $ browserFamily : 'Unknown' , ) ; return $ processed ; }
Parses a useragent and returns the detected data
3,399
public function setCache ( $ cache ) { if ( $ cache instanceof Cache || ( class_exists ( '\Doctrine\Common\Cache\CacheProvider' ) && $ cache instanceof \ Doctrine \ Common \ Cache \ CacheProvider ) ) { $ this -> cache = $ cache ; return ; } throw new \ Exception ( 'Cache not supported' ) ; }
Sets the Cache class