idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
25,600 | protected function writeFile ( string $ contents , string $ file ) : GraphvizWriter { if ( ! file_put_contents ( $ file , $ contents ) ) { throw ExportException :: create ( 'Couldn\'t write to file "' . $ file . '".' ) ; } return $ this ; } | Writes contents to a file . |
25,601 | protected function checkParams ( $ params ) { foreach ( $ params as $ type ) { if ( $ type instanceof Decorator ) { $ this -> errors [ ] = "Parameter is not well instantiated [" . ( string ) $ type . "]" ; } } } | Check if parameters are usable Mainly if parameters are still decorators it will break the injection |
25,602 | protected function setParams ( $ position , $ required , $ param ) { if ( ! empty ( $ required [ 'class' ] ) && ! is_a ( $ param , $ required [ 'class' ] ) ) { $ this -> errors [ ] = sprintf ( "You can't put an instance of %s in the parameter #%s $%s of type %s" , get_class ( $ param ) , $ position , $ required [ 'name' ] , $ required [ 'class' ] ) ; return false ; } $ this -> methodParams [ $ position ] = $ param ; } | Set into the methodParams array the correct param for the position |
25,603 | public function addToContent ( string $ param , string $ value ) : void { $ this -> content [ $ param ] = $ value ; } | Add a named value to the content part of message . |
25,604 | public function registerService ( string $ className , string $ serviceId ) : void { assert ( Validate :: implementsInterface ( $ className , EventSubscriber :: class ) , sprintf ( 'Invalid subscriber class: %s' , $ className ) ) ; foreach ( $ className :: eventRegistration ( ) as $ eventType => $ params ) { $ eventType = ClassName :: underscore ( $ eventType ) ; if ( is_string ( $ params ) ) { $ this -> addHandlerService ( $ eventType , $ serviceId , $ params ) ; } elseif ( is_string ( $ params [ 0 ] ) ) { $ priority = isset ( $ params [ 1 ] ) ? ( int ) $ params [ 1 ] : 0 ; $ this -> addHandlerService ( $ eventType , $ serviceId , $ params [ 0 ] , $ priority ) ; } else { foreach ( $ params as $ handler ) { $ priority = isset ( $ handler [ 1 ] ) ? ( int ) $ handler [ 1 ] : 0 ; $ this -> addHandlerService ( $ eventType , $ serviceId , $ handler [ 0 ] , $ priority ) ; } } } } | Registers a subscriber service to handle events |
25,605 | public function addHandlerService ( string $ eventType , string $ serviceId , string $ method , int $ priority = 0 ) : void { if ( ! isset ( $ this -> serviceIds [ $ eventType ] ) ) { $ this -> serviceIds [ $ eventType ] = [ ] ; } $ this -> serviceIds [ $ eventType ] [ ] = [ $ serviceId , $ method , $ priority ] ; } | Adds a handler service for a specific event |
25,606 | protected function lazyLoad ( string $ eventType ) : void { if ( isset ( $ this -> serviceIds [ $ eventType ] ) ) { foreach ( $ this -> serviceIds [ $ eventType ] as $ args ) { list ( $ serviceId , $ method , $ priority ) = $ args ; $ service = $ this -> container -> get ( $ serviceId ) ; $ key = sprintf ( '%s.%s' , $ serviceId , $ method ) ; if ( ! isset ( $ this -> services [ $ eventType ] [ $ key ] ) ) { $ this -> addHandler ( $ eventType , [ $ service , $ method ] , $ priority ) ; } elseif ( $ service !== $ this -> services [ $ eventType ] [ $ key ] ) { parent :: removeHandler ( $ eventType , [ $ this -> services [ $ eventType ] [ $ key ] , $ method ] ) ; $ this -> addHandler ( $ eventType , [ $ service , $ method ] , $ priority ) ; } $ this -> services [ $ eventType ] [ $ key ] = $ service ; } } } | Lazy loads event handlers from the service container |
25,607 | private function connection ( ) { $ this -> apply_config_db ( ) ; try { if ( @ $ _ENV [ "daniia_connection" ] && ! $ this -> id_conn ) { $ this -> id_conn = $ _ENV [ "daniia_connection" ] ; } elseif ( ! $ this -> id_conn ) { $ this -> id_conn = new \ PDO ( $ this -> dsn , $ this -> user , $ this -> pass ) ; } } catch ( \ PDOException $ e ) { die ( "Error: " . $ e -> getMessage ( ) . "<br/>" ) ; } $ this -> get_instance ( ) ; return $ this ; } | Establese la coneccion a la Base de Datdos |
25,608 | private function reset ( ) { $ this -> select = " SELECT * " ; $ this -> from = " FROM _table_ " ; $ this -> join = " " ; $ this -> on = " " ; $ this -> where = " " ; $ this -> groupBy = " " ; $ this -> having = " " ; $ this -> orderBy = " " ; $ this -> limit = " " ; $ this -> offset = " " ; $ this -> union = " " ; $ this -> case = "" ; $ this -> when = "" ; $ this -> else = "" ; $ this -> rows = [ ] ; $ this -> placeholder_data = [ ] ; $ _ENV [ "daniia_daniia" ] = null ; $ this -> get_instance ( ) ; return $ this ; } | resetea todas las variables de la clase por defecto |
25,609 | final public function query ( string $ sql , $ closure = NULL ) { $ this -> connection ( ) ; $ this -> last_sql = $ this -> sql = $ sql ; $ this -> fetch ( ) ; $ this -> data = $ this -> rows ; $ this -> reset ( ) ; if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } return $ this -> data ? : [ ] ; } | Ejecuta una sentencia SQL devolviendo un conjunto de resultados como un objeto |
25,610 | final public function queryArray ( string $ sql , $ closure = NULL ) { $ type_fetch = $ this -> type_fetch ; $ this -> type_fetch = 'assoc' ; $ this -> query ( $ sql ) ; $ this -> type_fetch = $ type_fetch ; if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } return $ this -> data ? : [ ] ; } | Ejecuta una sentencia SQL devolviendo un conjunto de resultados como un Array |
25,611 | final public function get ( $ closure = NULL ) { $ this -> connection ( ) ; if ( $ this -> table === NULL ) { if ( ! preg_match ( '/^ *FROM +\(/' , $ this -> from ) ) { $ this -> from = '' ; } } else { if ( preg_match ( '/\./' , $ this -> table ) || ! $ this -> schema ) { $ this -> from = str_replace ( "_table_" , $ this -> table , $ this -> from ) ; } else { $ this -> from = str_replace ( "_table_" , $ this -> schema . '.' . $ this -> table , $ this -> from ) ; } } $ this -> last_sql = $ this -> sql = $ this -> select . ' ' . $ this -> from . ' ' . $ this -> join . ' ' . $ this -> where . ' ' . $ this -> union . ' ' . $ this -> groupBy . ' ' . $ this -> having . ' ' . $ this -> orderBy . ' ' . $ this -> limit . ' ' . $ this -> offset ; if ( $ closure === FALSE ) return $ this -> sql ; $ this -> fetch ( ) ; $ this -> data = $ this -> rows ; $ this -> reset ( ) ; if ( $ this -> tableOrig !== NULL ) { $ this -> table = $ this -> tableOrig ; } if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } return $ this -> data ? : [ ] ; } | Retorna los datos consultados |
25,612 | final public function getArray ( $ closure = NULL ) { $ type_fetch = $ this -> type_fetch ; $ this -> type_fetch = 'assoc' ; $ this -> get ( ) ; $ this -> type_fetch = $ type_fetch ; if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } return $ this -> data ? : [ ] ; } | Retorna los datos consultados en formato Array |
25,613 | final public function find ( $ ids = [ ] ) { if ( func_num_args ( ) > 0 ) { if ( func_num_args ( ) === 1 ) { if ( ! is_array ( $ ids ) ) { $ ids = ( array ) $ ids ; } } else { $ ids = func_get_args ( ) ; } } $ closure = NULL ; if ( count ( func_get_args ( ) ) > 1 ) { if ( $ ids [ count ( $ ids ) - 1 ] instanceof \ Closure ) { $ closure = array_pop ( $ ids ) ; } if ( is_array ( $ ids [ 0 ] ) ) { $ ids = $ ids [ 0 ] ; } } $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = TRUE ; if ( count ( $ ids ) && ! ( @ $ ids [ 0 ] instanceof \ Closure ) ) { if ( $ this -> is_assoc ( $ ids ) ) { $ this -> where ( $ ids ) ; } else { $ this -> where ( $ this -> primaryKey , 'in' , $ ids ) ; } } $ this -> get ( ) ; if ( count ( $ ids ) === 1 && count ( $ this -> data ) === 1 ) { $ this -> data = $ this -> data [ 0 ] ; } if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } return $ this ; } | Busca uno o varios registros en la Base de Datos |
25,614 | final public function save ( $ closure = NULL ) { $ updated = FALSE ; if ( $ this -> find_save_data && @ $ this -> data -> { $ this -> primaryKey } ) { $ updated = $ this -> update ( ( array ) $ this -> data ) ; } $ last_id = NULL ; if ( ( $ this -> find_save_data && ! @ $ this -> data -> { $ this -> primaryKey } ) || ! $ updated ) { $ last_id = $ this -> insertGetId ( ( array ) $ this -> data ) ; } $ this -> find_save_data = FALSE ; $ lastQuery = $ this -> lastQuery ( ) ; $ error = $ this -> error ( ) ; if ( $ error [ 'message' ] ) { return FALSE ; } if ( $ last_id ) { $ this -> where ( $ this -> primaryKey , $ last_id ) ; $ this -> get ( ) ; $ this -> last_sql = $ lastQuery . "\n" . $ this -> lastQuery ( ) ; } if ( $ closure instanceof \ Closure ) { $ this -> data = $ closure ( $ this -> data , $ this ) ; } $ error = $ this -> error ( ) ; return $ error [ 'message' ] ? FALSE : TRUE ; } | actualiza o crea un registro en la base de datos |
25,615 | final public function truncate ( ) { $ this -> connection ( ) ; $ this -> sql = "TRUNCATE TABLE {$this->table};" ; if ( $ this -> driver == 'firebird' || $ this -> driver == 'sqlite' ) $ this -> sql = "DELETE FROM {$this->table};" ; $ this -> fetch ( ) ; return $ this -> resultset ? true : false ; } | elimina todos los datos de una tabla |
25,616 | final public function table ( $ table ) { $ this -> connection ( ) ; if ( func_num_args ( ) > 1 ) $ table = func_get_args ( ) ; else if ( is_string ( $ table ) ) $ table = [ $ table ] ; $ schema = '' ; if ( $ this -> driver == 'pgsql' && $ this -> schema ) $ schema = $ this -> schema ? $ this -> schema . '.' : '' ; $ tmp_table = [ ] ; foreach ( $ table as $ table ) { if ( preg_match ( '/\./' , $ table ) ) { $ tmp_table [ ] = $ table ; } else { $ tmp_table [ ] = $ schema . $ table ; } } $ table = implode ( "," , $ tmp_table ) ; if ( $ this -> extended ) { if ( $ this -> table ) { $ this -> table = $ schema . $ this -> table . "," . $ table ; } else { $ this -> table = $ table ; } } else { $ this -> table = $ table ; } $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } | Establese el nombre de la tabla |
25,617 | final public function select ( $ select = "*" ) { $ this -> connection ( ) ; if ( func_num_args ( ) > 1 ) $ select = func_get_args ( ) ; else if ( is_string ( $ select ) ) { $ select = [ $ select ] ; } $ select_tmp = [ ] ; foreach ( $ select as $ value ) { if ( $ value === NULL ) $ select_tmp [ ] = ' NULL ' ; elseif ( gettype ( $ value ) === 'boolean' ) $ select_tmp [ ] = $ value ? ' TRUE ' : ' FALSE ' ; elseif ( $ value instanceof \ Closure ) { $ value ( new \ Daniia \ Daniia ( ) ) ; if ( preg_match ( "/^CASE/" , $ _ENV [ 'daniia_daniia' ] -> case ) ) { $ select_tmp [ ] = '( ' . $ _ENV [ 'daniia_daniia' ] -> case . ' ' . $ _ENV [ 'daniia_daniia' ] -> when . ' ' . $ _ENV [ 'daniia_daniia' ] -> else . ' END )' ; $ _ENV [ 'daniia_daniia' ] -> case = NULL ; } else { $ select_tmp [ ] = $ _ENV [ 'daniia_daniia' ] -> get_sql ( ) ; $ _ENV [ 'daniia_daniia' ] = null ; } } elseif ( in_array ( strtolower ( trim ( $ value ) ) , $ this -> columnsData , true ) ) $ select_tmp [ ] = $ value ; else { $ select_tmp [ ] = $ value ; } } $ select = implode ( "," , $ select_tmp ) ; $ this -> select = str_replace ( "*" , $ select , $ this -> select ) ; $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } | Establese los nombres dee las columnas a consultar |
25,618 | final public function from ( $ table = "" , $ aliasFrom = "" ) { $ this -> connection ( ) ; $ sql = "" ; $ closure = false ; if ( $ table instanceof \ Closure ) { $ table ( new \ Daniia \ Daniia ( ) ) ; $ sql = $ _ENV [ "daniia_daniia" ] -> get_sql ( ) ; $ _ENV [ "daniia_daniia" ] = null ; $ sql .= " AS " . ( $ aliasFrom ? $ aliasFrom : " _alias_ " ) ; $ closure = true ; } else { if ( func_num_args ( ) > 1 ) { $ table = func_get_args ( ) ; } elseif ( is_string ( $ table ) ) { $ table = [ $ table ] ; } $ schema = '' ; if ( $ this -> driver == 'pgsql' && $ this -> schema ) { $ schema = $ this -> schema ? $ this -> schema . '.' : '' ; } $ tmp_table = [ ] ; foreach ( $ table as $ val ) { if ( preg_match ( '/\./' , $ val ) ) { $ tmp_table [ ] = $ val ; } else { $ tmp_table [ ] = $ schema . $ val ; } } $ table = implode ( "," , $ tmp_table ) ; } if ( $ this -> extended && is_string ( $ table ) && ! $ closure ) { $ table = $ schema . $ this -> table . "," . $ table ; } if ( ! $ this -> bool_group ) { if ( ! $ this -> table && gettype ( $ table ) === 'string' ) { $ this -> table = $ table ; } $ this -> from = str_replace ( "_table_" , ( $ closure ? $ sql : ( $ table ? : $ this -> table ) ) , $ this -> from ) ; } $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } | Establece el nombre de la tabla a consultar |
25,619 | final public function insert ( array $ datas , bool $ returning_id = false ) { if ( is_array ( $ datas ) && count ( $ datas ) ) { if ( ! is_array ( @ $ datas [ 0 ] ) ) $ datas = [ $ datas ] ; $ this -> connection ( ) ; $ this -> columns ( ) ; $ placeholders = [ ] ; $ this -> placeholder_data = [ ] ; foreach ( $ datas as $ data ) { $ placeholder = [ ] ; foreach ( $ this -> columnsData as $ column ) { if ( isset ( $ data [ $ column ] ) ) { $ placeholder [ $ column ] = "NULL" ; if ( gettype ( $ data [ $ column ] ) === 'boolean' ) $ placeholder [ $ column ] = $ data [ $ column ] ? 'TRUE' : 'FALSE' ; elseif ( $ data [ $ column ] !== '' && $ data [ $ column ] !== NULL ) { $ placeholder [ $ column ] = "?" ; $ this -> placeholder_data [ ] = $ data [ $ column ] ; } } } $ placeholders [ ] = "(" . implode ( "," , $ placeholder ) . ")" ; } $ columns = "(" . implode ( "," , array_keys ( $ placeholder ) ) . ")" ; $ placeholders = implode ( "," , $ placeholders ) ; $ schema = '' ; $ returning = '' ; if ( $ this -> driver == 'pgsql' && $ this -> schema ) { if ( ! preg_match ( '/\./' , $ this -> table ) ) { $ schema = $ this -> schema ? $ this -> schema . '.' : '' ; } $ returning = $ returning_id ? 'RETURNING ' . $ this -> primaryKey : '' ; } $ this -> last_sql = $ this -> sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};" ; $ this -> fetch ( ) ; $ this -> data = $ this -> rows ; $ this -> reset ( ) ; if ( $ this -> tableOrig !== NULL ) { $ this -> table = $ this -> tableOrig ; } $ error = $ this -> error ( ) ; return $ error [ 'message' ] ? FALSE : TRUE ; } return FALSE ; } | inserta datos en la base de datos |
25,620 | final public function insertGetId ( array $ datas ) { $ this -> connection ( ) ; $ this -> last_id = NULL ; if ( $ this -> driver == 'pgsql' ) { $ this -> insert ( $ datas , TRUE ) ; if ( @ $ this -> data [ 0 ] ) { $ this -> last_id = @ $ this -> data [ 0 ] -> { $ this -> primaryKey } ; } } else { $ this -> insert ( $ datas ) ; $ this -> last_id = $ this -> id_conn -> lastInsertId ( ) ; } return ( int ) $ this -> last_id ; } | inserta y luego retorna la clave primaria del registro |
25,621 | final public function delete ( $ ids = [ ] ) { if ( func_num_args ( ) > 0 ) { if ( func_num_args ( ) == 1 ) { if ( ! is_array ( $ ids ) ) { $ ids = ( array ) $ ids ; } } else { $ ids = func_get_args ( ) ; } } $ this -> connection ( ) ; if ( $ this -> find_delete_data ) { if ( is_object ( $ this -> data ) && $ this -> data ) { $ ids [ ] = $ this -> data -> { $ this -> primaryKey } ; } if ( is_array ( $ this -> data ) && $ this -> data ) { foreach ( $ this -> data as $ data ) $ ids [ ] = $ data -> { $ this -> primaryKey } ; } $ this -> find_delete_data = FALSE ; if ( ! count ( $ ids ) ) { return FALSE ; } } if ( $ this -> is_assoc ( $ ids ) ) { $ this -> where ( $ ids ) ; $ ids = NULL ; } else { $ this -> placeholder_data = $ ids ; $ placeholder = $ this -> get_placeholder ( $ ids ) ; } $ where = '' ; if ( $ ids ) { if ( preg_match ( "/WHERE/" , $ this -> where ) ) $ where = " {$this->where} AND {$this->primaryKey} IN({$placeholder}) " ; else $ where = " WHERE {$this->primaryKey} IN({$placeholder}) " ; } else { if ( preg_match ( "/WHERE/" , $ this -> where ) ) $ where = $ this -> where ; } $ schema = '' ; if ( $ this -> driver == 'pgsql' && $ this -> schema ) { if ( ! preg_match ( '/\./' , $ this -> table ) ) { $ schema = $ this -> schema ? $ this -> schema . '.' : '' ; } } $ this -> last_sql = $ this -> sql = "DELETE FROM {$schema}{$this->table} {$where}" ; $ this -> fetch ( ) ; $ this -> reset ( ) ; if ( $ this -> tableOrig !== null ) { $ this -> table = $ this -> tableOrig ; } $ error = $ this -> error ( ) ; return $ error [ 'message' ] ? false : true ; } | elimina un registro en la base de datos |
25,622 | final public function orderBy ( $ fields ) { if ( func_num_args ( ) > 0 ) { if ( func_num_args ( ) == 1 ) { if ( ! is_array ( $ fields ) ) { $ fields = ( array ) $ fields ; } } else { $ fields = func_get_args ( ) ; } $ order = '' ; if ( strtoupper ( $ fields [ count ( $ fields ) - 1 ] ) == 'ASC' || strtoupper ( $ fields [ count ( $ fields ) - 1 ] ) == 'DESC' ) { $ order = $ fields [ count ( $ fields ) - 1 ] ; unset ( $ fields [ count ( $ fields ) - 1 ] ) ; } $ this -> orderBy = " ORDER BY " . implode ( ',' , $ fields ) . ' ' . strtoupper ( $ order ) ; $ this -> get_instance ( ) ; return $ this ; } return null ; } | agrega el query ORDER BY basico |
25,623 | final public function groupBy ( $ fields ) { if ( func_num_args ( ) > 0 ) { if ( func_num_args ( ) == 1 ) { if ( ! is_array ( $ fields ) ) { $ fields = ( array ) $ fields ; } } else { $ fields = func_get_args ( ) ; } $ this -> groupBy = " GROUP BY " . implode ( ',' , $ fields ) ; $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } return null ; } | agrega el query GROUP BY basico |
25,624 | final public function limit ( $ limit , $ offset = null ) { if ( is_numeric ( $ limit ) || is_array ( $ limit ) ) { if ( is_array ( $ limit ) ) { $ temp = $ limit ; $ limit = $ temp [ 0 ] ; $ offset = @ $ temp [ 1 ] ; } $ this -> limit = " LIMIT {$limit} " ; if ( is_numeric ( $ offset ) ) { $ this -> offset ( $ offset ) ; } $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } return null ; } | agrega el query basico LIMIT |
25,625 | final public function offset ( $ offset ) { if ( is_numeric ( $ offset ) ) { $ this -> offset = " OFFSET {$offset} " ; $ this -> find_first_data = $ this -> find_save_data = $ this -> find_delete_data = FALSE ; $ this -> get_instance ( ) ; return $ this ; } return null ; } | agrega el query basico OFFSET |
25,626 | final public function union ( $ closure ) { if ( $ closure instanceof \ Closure ) { $ closure ( new \ Daniia \ Daniia ( ) ) ; $ str = $ _ENV [ "daniia_daniia" ] -> get_sql ( ) ; $ _ENV [ "daniia_daniia" ] = null ; $ this -> union .= ' UNION ' . $ str ; } $ this -> get_instance ( ) ; return $ this ; } | genera una lista dependiendo de los datos consultados |
25,627 | public function countryFilter ( $ country , $ default = '' , $ locale = null ) { $ locale = $ locale == null ? \ Locale :: getDefault ( ) : $ locale ; $ countries = Intl :: getRegionBundle ( ) -> getCountryNames ( $ locale ) ; return array_key_exists ( $ country , $ countries ) ? $ countries [ $ country ] : $ default ; } | Translate a country indicator to its locale full name Uses default system locale by default . Pass another locale string to force a different translation |
25,628 | public function convertFilter ( $ value , $ sourceUnit , $ destinationUnit , $ unitName , $ locale = null ) { if ( null !== $ value ) { $ translatedUnitName = $ this -> translator -> trans ( $ unitName , array ( ) , 'SasedevExtraToolsBundle' ) ; $ value = $ this -> converter -> convert ( $ value , $ sourceUnit , $ destinationUnit , $ locale ) ; $ value = $ value . ' ' . $ translatedUnitName ; } return $ value ; } | Convert a value into another unit . Returns null if fails or not supported . |
25,629 | public function render ( HierarchyInterface $ node = null , $ criteria = null , $ options = [ ] , $ includeNode = null ) { return $ this -> getMapper ( ) -> childrenHierarchy ( $ node , null === $ criteria ? $ this -> direct ( ) : $ criteria , array_replace_recursive ( $ this -> getOptions ( ) , $ options ) , null === $ includeNode ? $ this -> includeNode ( ) : $ includeNode ) ; } | Render node s hierarchy |
25,630 | public function setClasses ( $ classes , $ override = true ) { foreach ( $ classes as $ key => $ class ) { if ( $ override || ! isset ( $ this -> _classes [ $ key ] ) ) { $ this -> _classes [ $ key ] = $ class ; } } } | Set classes . |
25,631 | private function replaceProcessingTypes ( $ dbname , $ table , Connection $ connection ) { $ dbNsName = $ this -> titleize ( $ dbname ) ; $ rowClassName = $ this -> titleize ( $ table ) ; $ collectionClassName = $ rowClassName . "Collection" ; $ namespace = 'Prooph\Link\Application\DataType\SqlConnector\\' . $ dbNsName ; $ this -> dataTypeLocation -> addDataTypeClass ( $ namespace . '\\' . $ rowClassName , $ this -> generateRowTypeClass ( $ namespace , $ rowClassName , $ table , $ connection ) , $ forceReplace = true ) ; $ this -> dataTypeLocation -> addDataTypeClass ( $ namespace . '\\' . $ collectionClassName , $ this -> generateRowCollectionTypeClass ( $ namespace , $ collectionClassName , $ rowClassName ) , $ forceReplace = true ) ; return [ $ namespace . '\\' . $ rowClassName , $ namespace . '\\' . $ collectionClassName ] ; } | Does the same like generateProcessingTypesIfNotExist but overrides any existing type classes . Use this method with care . |
25,632 | private function loadPropertiesForTable ( $ table , Connection $ connection ) { $ columns = $ connection -> getSchemaManager ( ) -> listTableColumns ( $ table ) ; $ props = [ ] ; foreach ( $ columns as $ name => $ column ) { $ processingType = $ this -> doctrineColumnToProcessingType ( $ column ) ; $ props [ $ name ] = [ 'processing_type' => $ processingType , 'doctrine_type' => $ column -> getType ( ) -> getName ( ) , ] ; } return $ props ; } | Inspect given table and creates a map containing the mapped processing type and the original doctrine type The map is indexed by column names which become the property names |
25,633 | private function loadPrimaryKeyforTable ( $ table , Connection $ connection ) { $ indexes = $ connection -> getSchemaManager ( ) -> listTableIndexes ( $ table ) ; $ primaryKey = null ; foreach ( $ indexes as $ index ) { if ( $ index -> isPrimary ( ) ) { $ columns = $ index -> getColumns ( ) ; $ primaryKey = implode ( "_" , $ columns ) ; break ; } } return $ primaryKey ; } | If table has a primary key this becomes the identifier of the row type . If primary key consists of more then one column the name of the identifier is generated by concatenating the column names with a underscore . Such a row type needs to be manually adjusted to deal with the identifier! |
25,634 | public function removeSkills ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Object not found.' ] ) ; } try { $ this -> doRemoveSkills ( $ model , $ data ) ; } catch ( ErrorsException $ e ) { return new NotValid ( [ 'errors' => $ e -> getErrors ( ) ] ) ; } $ this -> dispatch ( ObjectEvent :: PRE_SKILLS_REMOVE , $ model , $ data ) ; $ this -> dispatch ( ObjectEvent :: PRE_SAVE , $ model , $ data ) ; $ rows = $ model -> save ( ) ; $ this -> dispatch ( ObjectEvent :: POST_SKILLS_REMOVE , $ model , $ data ) ; $ this -> dispatch ( ObjectEvent :: POST_SAVE , $ model , $ data ) ; if ( $ rows > 0 ) { return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Removes Skills from Object |
25,635 | public function setSportId ( $ id , $ relatedId ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Object not found.' ] ) ; } if ( $ this -> doSetSportId ( $ model , $ relatedId ) ) { $ this -> dispatch ( ObjectEvent :: PRE_SPORT_UPDATE , $ model ) ; $ this -> dispatch ( ObjectEvent :: PRE_SAVE , $ model ) ; $ model -> save ( ) ; $ this -> dispatch ( ObjectEvent :: POST_SPORT_UPDATE , $ model ) ; $ this -> dispatch ( ObjectEvent :: POST_SAVE , $ model ) ; return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Sets the Sport id |
25,636 | public function update ( $ id , $ data ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Object not found.' ] ) ; } $ serializer = Object :: getSerializer ( ) ; $ model = $ serializer -> hydrate ( $ model , $ data ) ; $ this -> hydrateRelationships ( $ model , $ data ) ; $ this -> dispatch ( ObjectEvent :: PRE_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ObjectEvent :: PRE_SAVE , $ model , $ data ) ; $ validator = $ this -> getValidator ( ) ; if ( $ validator !== null && ! $ validator -> validate ( $ model ) ) { return new NotValid ( [ 'errors' => $ validator -> getValidationFailures ( ) ] ) ; } $ rows = $ model -> save ( ) ; $ this -> dispatch ( ObjectEvent :: POST_UPDATE , $ model , $ data ) ; $ this -> dispatch ( ObjectEvent :: POST_SAVE , $ model , $ data ) ; $ payload = [ 'model' => $ model ] ; if ( $ rows === 0 ) { return new NotUpdated ( $ payload ) ; } return new Updated ( $ payload ) ; } | Updates a Object with the given idand the provided data |
25,637 | protected function doUpdateSkills ( Object $ model , $ data ) { SkillQuery :: create ( ) -> filterByObject ( $ model ) -> delete ( ) ; $ errors = [ ] ; foreach ( $ data as $ entry ) { if ( ! isset ( $ entry [ 'id' ] ) ) { $ errors [ ] = 'Missing id for Skill' ; } else { $ related = SkillQuery :: create ( ) -> findOneById ( $ entry [ 'id' ] ) ; $ model -> addSkill ( $ related ) ; } } if ( count ( $ errors ) > 0 ) { throw new ErrorsException ( $ errors ) ; } } | Internal update mechanism of Skills on Object |
25,638 | public function batchInsert ( array $ data ) { $ ids = [ ] ; foreach ( $ data as $ item ) { if ( isset ( $ item [ 'id' ] ) ) { if ( array_key_exists ( $ item [ 'id' ] , $ this -> table -> data [ 'data' ] ) ) { continue ; } } else { $ item = [ 'id' => $ this -> generateId ( ) ] + $ item ; } $ ids [ ] = $ this -> insert ( $ item ) ; } return $ ids ; } | Batch insert multiple records |
25,639 | public function orderBy ( $ column , $ order = 'asc' ) { $ this -> order [ 0 ] = $ column ; $ this -> order [ 1 ] = strtolower ( $ order ) == 'desc' ? 'desc' : 'asc' ; return $ this ; } | Set sort column and order |
25,640 | public function first ( ) { $ data = $ this -> getData ( ) ; if ( ! $ this -> where ) { return $ data ? $ this -> convertItem ( reset ( $ data ) ) : null ; } foreach ( $ data as & $ rs ) { if ( $ this -> matchWhere ( $ rs ) ) { return $ this -> convertItem ( $ rs ) ; } } return null ; } | Get first record |
25,641 | public function offset ( $ offset ) { if ( intval ( $ offset ) != $ offset ) { throw new \ Exception ( 'The offset must be an integer' ) ; } $ this -> offset = ( int ) $ offset ; return $ this ; } | Offset the result |
25,642 | public function where ( $ column , $ operator , $ value = null ) { if ( is_null ( $ value ) ) { if ( is_callable ( $ operator ) ) { $ this -> where [ ] = [ $ column , 'func' , $ operator ] ; } else { $ this -> where [ ] = [ $ column , '=' , $ operator ] ; } } else { $ this -> where [ ] = [ $ column , $ operator , $ value ] ; } return $ this ; } | Value must exist in the array |
25,643 | protected function getData ( ) { if ( is_null ( $ this -> order [ 0 ] ) ) { return $ this -> table -> data [ 'data' ] ; } $ items = $ this -> table -> data [ 'data' ] ; $ col = $ this -> order [ 0 ] ; $ order = $ this -> order [ 1 ] ; usort ( $ items , function ( $ a , $ b ) use ( $ col , $ order ) { if ( ! isset ( $ a [ $ col ] ) && ! isset ( $ b [ $ col ] ) ) { return 0 ; } if ( is_array ( $ a [ $ col ] ) || is_array ( $ b [ $ col ] ) ) { return 0 ; } if ( ! isset ( $ a [ $ col ] ) || is_array ( $ a [ $ col ] ) ) { return $ order == 'asc' ? - 1 : 1 ; } if ( ! isset ( $ b [ $ col ] ) || is_array ( $ b [ $ col ] ) ) { return $ order == 'asc' ? 1 : - 1 ; } return $ order == 'asc' ? strnatcmp ( ( string ) $ a [ $ col ] , ( string ) $ b [ $ col ] ) : strnatcmp ( ( string ) $ b [ $ col ] , ( string ) $ a [ $ col ] ) ; } ) ; return $ items ; } | Order the table |
25,644 | protected function convertItem ( $ rs ) { if ( 'array' == $ this -> returnAs ) { return $ rs ; } if ( 'stdclass' == $ this -> returnAs ) { return ( object ) $ rs ; } return new $ this -> returnAs ( $ rs ) ; } | Convert a record set |
25,645 | protected function matchWhere ( $ rs ) { foreach ( $ this -> where as $ where ) { list ( $ key , $ op , $ test ) = $ where ; $ found = array_key_exists ( $ key , $ rs ) ; $ real = $ found ? $ rs [ $ key ] : null ; if ( $ this -> filters -> match ( $ op , $ found , $ real , $ test ) === false ) { return false ; } } return true ; } | Match an item with the where conditions |
25,646 | public function getEventName ( ) { if ( $ this -> eventName !== NULL ) { return $ this -> eventName ; } if ( $ this -> reflection === NULL ) { $ this -> reflection = new \ ReflectionMethod ( $ this -> object , $ this -> methodName ) ; } $ params = $ this -> reflection -> getParameters ( ) ; if ( empty ( $ params ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Method listener %s->%s() must accept an event argument' , $ this -> reflection -> getDeclaringClass ( ) -> name , $ this -> reflection -> name ) ) ; } if ( NULL !== ( $ paramTypeName = $ this -> getParamType ( $ params [ 0 ] ) ) ) { $ this -> eventName = $ paramTypeName ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Event callback param "%s" of %s->%s() must declare an event type hint' , $ params [ 0 ] -> name , $ this -> reflection -> getDeclaringClass ( ) -> name , $ this -> reflection -> name ) ) ; } return $ this -> eventName ; } | Get the name of the event being assembled using reflection . |
25,647 | private function commandResponseInfo ( ) { $ configCode = '' ; $ configCode .= 'App\Providers\Bindings\\' ; if ( $ this -> getFolderOptionInput ( ) ) { $ configCode .= $ this -> getFolderOptionInput ( ) . '\\' ; } $ configCode .= $ this -> getNameInput ( ) . 'ServiceProvider::class' ; return $ configCode ; } | Command response info . |
25,648 | protected function generateMissingExceptionMessage ( $ type , $ name , array $ prefixes , array $ locales , array $ formats , array $ handlers ) { $ searchedPaths = [ ] ; if ( $ prefixes ) { foreach ( $ prefixes as $ prefix ) { $ searchedPaths [ ] = $ prefix . '/' . $ name ; } } else { $ searchedPaths [ ] = $ name ; } if ( $ this -> lookupContext -> paths ) { $ lookupPaths = sprintf ( "* %s" , implode ( "\n * " , $ this -> lookupContext -> paths ) ) ; } else { $ lookupPaths = '[no lookup paths]' ; } return sprintf ( "Missing %s '%s' with [locales=>[%s], formats=>[%s], handlers=>[%s]], searched in:\n%s" , $ type , implode ( "', '" , $ searchedPaths ) , implode ( ', ' , $ locales ) , implode ( ', ' , $ formats ) , implode ( ', ' , $ handlers ) , $ lookupPaths ) ; } | Generate missing exception message |
25,649 | public static function bytes ( $ n , & $ method = null ) { $ bytes = self :: php7Bytes ( $ n ) ; $ method = 'php7' ; if ( ! isset ( $ bytes ) ) { $ bytes = self :: mcryptBytes ( $ n ) ; $ method = 'mcrypt' ; } if ( ! isset ( $ bytes ) ) { $ bytes = self :: opensslBytes ( $ n ) ; $ method = 'openssl' ; } if ( ! isset ( $ bytes ) ) { $ bytes = self :: urandomBytes ( $ n ) ; $ method = 'urandom' ; } if ( ! isset ( $ bytes ) ) { $ bytes = self :: mtRandBytes ( $ n ) ; $ method = 'mt_rand' ; } $ l = Binary :: length ( $ bytes ) ; if ( $ l < $ n ) { $ bytes .= self :: mtRandBytes ( $ n - $ l ) ; } return $ bytes ; } | Generate a random sequence of bytes . |
25,650 | protected function updateBlocks ( Database $ db ) { $ this -> write ( ' + Updating block documents' ) ; $ this -> write ( ' + updating medias in tinyMce attributes' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . ' db.block.find({}).snapshot().forEach(function(block) { var updated = false; for (var attributeName in block.attributes) { if (block.attributes.hasOwnProperty(attributeName) && (typeof block.attributes[attributeName] == "string")) { var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g; var matches = pattern.execAll(block.attributes[attributeName]); for (var i = 0; i < matches.length; i++) { var mediaId = getMediaIdFromMatch(matches[i]); var format = getMediaFormatFromMatch(matches[i]); block.attributes[attributeName] = updateAttribute(block.attributes[attributeName], mediaId, format, getMediaAlt(mediaId, block.language)); updated = true; } } } if (updated) { db.block.update({_id: block._id}, block); } }); ' ) ) ; $ this -> write ( ' + updating medias in block attributes' ) ; $ configMediaFieldType = $ this -> container -> getParameter ( 'open_orchestra_migration.media_configuration' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . ' var blockMediaFieldAttribute = ' . json_encode ( $ configMediaFieldType [ 'block_media_field_attribute' ] ) . '; db.block.find({}).snapshot().forEach(function(block) { var updated = false; for (var attributeName in block.attributes) { if ( block.attributes.hasOwnProperty(attributeName) && blockMediaFieldAttribute.indexOf(attributeName) > -1 ) { var alt = ""; if ( null !== block.attributes[attributeName].id & "" !== block.attributes[attributeName].id ) { alt = getMediaAlt(block.attributes[attributeName].id, block.language); } block.attributes[attributeName].alt = alt; block.attributes[attributeName].legend = ""; updated = true; } } if (updated) { db.block.update({_id: block._id}, block); } }); ' ) ) ; } | Add alt + legend to tinyMce attributes in blocks alt is taken from the media document |
25,651 | protected function updateContents ( Database $ db ) { $ this -> write ( ' + Updating content documents' ) ; $ this -> updateTinyMCEInContent ( $ db ) ; $ this -> updateMediaInContent ( $ db ) ; } | Update Content documents |
25,652 | protected function updateTinyMCEInContent ( Database $ db ) { $ this -> write ( ' + Updating medias in tinyMce attributes' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . ' db.content.find({}).snapshot().forEach(function(content) { var updated = false; for (var attributeName in content.attributes) { if (content.attributes.hasOwnProperty(attributeName) && "wysiwyg" == content.attributes[attributeName].type) { var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g; var matches = pattern.execAll(content.attributes[attributeName].value); for (var i = 0; i < matches.length; i++) { var mediaId = getMediaIdFromMatch(matches[i]); var format = getMediaFormatFromMatch(matches[i]); content.attributes[attributeName].value = updateAttribute(content.attributes[attributeName].value, mediaId, format, getMediaAlt(mediaId, content.language)); updated = true; } } } if (updated) { db.content.update({_id: content._id}, content); } }); ' ) ) ; } | Add alt + legend to tinyMce attributes in contents alt is taken from the media document |
25,653 | protected function updateMediaInContent ( Database $ db ) { $ this -> write ( ' + Updating orchestra_media attributes' ) ; $ configMediaFieldType = $ this -> container -> getParameter ( 'open_orchestra_migration.media_configuration' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . ' var contentMediaFieldType = ' . json_encode ( $ configMediaFieldType [ 'content_media_field_type' ] ) . '; db.content.find({}).snapshot().forEach(function(content) { var updated = false; for (var attributeName in content.attributes) { if ( content.attributes.hasOwnProperty(attributeName) && contentMediaFieldType.indexOf(content.attributes[attributeName].type) > -1 && content.attributes[attributeName].hasOwnProperty("value") ) { var alt = ""; if ( null !== content.attributes[attributeName].value.id & "" !== content.attributes[attributeName].value.id ) { alt = getMediaAlt(content.attributes[attributeName].value.id, content.language); } content.attributes[attributeName].value.alt = alt; content.attributes[attributeName].value.legend = ""; updated = true; } } if (updated) { db.content.update({_id: content._id}, content); } }); ' ) ) ; } | Update Medias in contents by adding alt and legend alt is taken from the media document |
25,654 | protected function updateFolders ( Database $ db ) { $ this -> write ( ' + Updating media folder documents' ) ; $ this -> createFolderId ( $ db ) ; $ this -> createFolderPath ( ) ; $ this -> updateFolderNames ( $ db ) ; } | Update folder documents |
25,655 | protected function updateMedias ( Database $ db ) { $ this -> write ( ' + Updating media documents' ) ; $ this -> write ( ' + Removing alts' ) ; $ this -> checkExecute ( $ db -> execute ( ' db.media.update({}, {$unset: {alts: ""}}, {multi: true}); ' ) ) ; } | Update media documents |
25,656 | protected function createFolderPath ( ) { $ this -> write ( ' + Adding folderPath' ) ; $ rootFolders = $ this -> container -> get ( 'open_orchestra_media.repository.media_folder' ) -> findBy ( array ( 'parent' => null ) ) ; foreach ( $ rootFolders as $ folder ) { $ oldPath = $ folder -> getPath ( ) ; $ folder -> setPath ( '/' ) ; $ event = $ this -> container -> get ( 'open_orchestra_media_admin.event.folder_event.factory' ) -> createFolderEvent ( ) ; $ event -> setFolder ( $ folder ) ; $ event -> setPreviousPath ( $ oldPath ) ; $ this -> container -> get ( 'event_dispatcher' ) -> dispatch ( FolderEvents :: PATH_UPDATED , $ event ) ; } $ this -> container -> get ( 'object_manager' ) -> flush ( ) ; } | Add Path to each folder |
25,657 | protected function updateFolderNames ( Database $ db ) { $ this -> write ( ' + Updating folderNames' ) ; $ this -> checkExecute ( $ db -> execute ( ' var backLanguages = ' . json_encode ( $ this -> container -> getParameter ( 'open_orchestra_base.administration_languages' ) ) . '; db.folder.find({}).snapshot().forEach(function(folder) { var name = folder.name; folder.names = {}; for (var language in backLanguages) { folder.names[backLanguages[language]] = name; } delete folder.name; db.folder.update({_id: folder._id}, folder); }); ' ) ) ; } | Internationalize Folder name |
25,658 | protected function help ( ) { $ style = new Style ( ' *** RUN - HELP ***' ) ; Out :: std ( $ style -> color ( 'fg' , Style :: COLOR_GREEN ) -> get ( ) ) ; Out :: std ( '' ) ; $ help = new Help ( '...' , true ) ; $ help -> addArgument ( '' , 'color' , 'Activate colors (do not activate when redirect output in log file, colors are non-printable chars)' , false , false ) ; $ help -> addArgument ( '' , 'debug' , 'Activate debug mode (trace on exception if script is terminated with an exception)' , false , false ) ; $ help -> addArgument ( '' , 'time-limit' , 'Specified time limit in seconds (default: 0 - unlimited)' , true , false ) ; $ help -> addArgument ( '' , 'error-reporting' , 'Specified value for error-reporting (default: -1 - all)' , true , false ) ; $ help -> addArgument ( '' , 'error-display' , 'Specified value for display_errors setting. Values: 0|1 Default: 1 (display)' , true , false ) ; $ help -> addArgument ( '' , 'quiet' , 'Force disabled console lib messages (header, footer, timer...)' , false , false ) ; $ help -> addArgument ( '' , 'name' , 'Console class script to run (Example: \Eureka\Component\Database\Console' , true , true ) ; $ help -> display ( ) ; } | Display console lib help |
25,659 | public function before ( ) { $ this -> time = - microtime ( true ) ; error_reporting ( ( int ) $ this -> argument -> get ( 'error-reporting' , null , - 1 ) ) ; ini_set ( 'display_errors' , ( bool ) $ this -> argument -> get ( 'error-display' , null , 1 ) ) ; set_time_limit ( ( int ) $ this -> argument -> get ( 'time-limit' , null , 0 ) ) ; $ this -> isVerbose = ! $ this -> argument -> has ( 'quiet' ) ; } | This method is executed before main method of console . - init timer - init error_reporting - init time limit for script - init verbose mode |
25,660 | protected function handleObject ( $ object , $ view ) { $ check = $ this -> trackObjectVisits ( $ object ) ; if ( $ check instanceof \ stdClass ) { return $ check ; } else { $ output = new \ stdClass ( ) ; $ output -> _hash = $ check ; } $ reflection = new \ ReflectionClass ( $ object ) ; $ classContext = $ this -> classBuilder -> buildClassContext ( $ reflection , $ check , $ view ) ; foreach ( $ classContext -> properties as $ property ) { $ output = $ this -> handleProperty ( $ property , $ classContext , $ object , $ output ) ; } return $ output ; } | Used to handle representing objects |
25,661 | public function expect ( $ type , $ value = null , $ message = null ) { $ token = $ this -> current ; if ( ! $ token -> test ( $ type , $ value ) ) { throw new SyntaxError ( sprintf ( '%sUnexpected token "%s" of value "%s" ("%s" expected%s)' , $ message ? $ message . '. ' : '' , $ token -> type , $ token -> value , $ type , $ value ? sprintf ( ' with value "%s"' , $ value ) : '' ) , $ token -> cursor ) ; } $ this -> next ( ) ; } | Tests a token . |
25,662 | public function removeByKey ( string $ key ) : bool { if ( isset ( $ this -> routes [ $ key ] ) ) { unset ( $ this -> routes [ $ key ] ) ; return true ; } return false ; } | Remove route using the key |
25,663 | public function makeBinding ( ) { $ this -> sortByConditionPriority ( ) ; foreach ( $ this -> routes as $ route ) { $ condition = $ route [ 'condition' ] ; $ action = $ route [ 'action' ] ; $ condition -> bindWithAction ( $ action ) ; } } | Bind all routes condition - action couples |
25,664 | protected function sortByConditionPriority ( ) { $ wpQueryRoutes = [ ] ; $ otherRoutes = [ ] ; foreach ( $ this -> routes as $ key => $ curRoute ) { if ( $ curRoute [ 'condition' ] instanceof WpQueryCondition ) { if ( ! is_numeric ( $ key ) ) { $ wpQueryRoutes [ $ key ] = $ curRoute ; } else { $ wpQueryRoutes [ ] = $ curRoute ; } } else { if ( ! is_numeric ( $ key ) ) { $ otherRoutes [ $ key ] = $ curRoute ; } else { $ otherRoutes [ ] = $ curRoute ; } } } uasort ( $ wpQueryRoutes , function ( $ a , $ b ) { $ aCondition = $ a [ 'condition' ] ; $ bCondition = $ b [ 'condition' ] ; $ aAnyFactor = ( int ) ( ! in_array ( 'any' , $ aCondition -> getKeywords ( ) ) ) ; $ bAnyFactor = ( int ) ( ! in_array ( 'any' , $ bCondition -> getKeywords ( ) ) ) ; if ( $ aAnyFactor !== $ bAnyFactor ) { return $ bAnyFactor - $ aAnyFactor ; } $ aQueryParamsCount = count ( $ aCondition -> getQueryParams ( ) ) ; $ bQueryParamsCount = count ( $ bCondition -> getQueryParams ( ) ) ; $ qpFactor = $ aQueryParamsCount - $ bQueryParamsCount ; if ( 0 !== $ qpFactor ) { return - $ qpFactor ; } $ aKeywordsCount = count ( $ aCondition -> getKeywords ( ) ) ; $ bKeywordsCount = count ( $ bCondition -> getKeywords ( ) ) ; $ kwFactor = $ aKeywordsCount - $ bKeywordsCount ; return $ kwFactor ; } ) ; $ this -> routes = array_merge ( $ otherRoutes , $ wpQueryRoutes ) ; } | Sort routes by priority |
25,665 | public function string ( $ index = '' , $ isTrim = true ) { $ value = '' ; if ( isset ( $ _POST [ $ index ] ) ) { $ value = $ _POST [ $ index ] ; } else if ( isset ( $ _GET [ $ index ] ) ) { $ value = $ _GET [ $ index ] ; } return $ isTrim ? trim ( $ value ) : $ value ; } | Fetch an item from either the GET array or the POST |
25,666 | function intval ( $ index = '' , $ default = 0 ) { $ value = $ default ; if ( isset ( $ _POST [ $ index ] ) ) { $ value = $ _POST [ $ index ] ; } else if ( isset ( $ _GET [ $ index ] ) ) { $ value = $ _GET [ $ index ] ; } return intval ( $ value ) ; } | Fetch an item from either the GET array or the POST and covert into int |
25,667 | public function floatval ( $ index = '' , $ default = 0 ) { $ value = $ default ; if ( isset ( $ _POST [ $ index ] ) ) { $ value = $ _POST [ $ index ] ; } else if ( isset ( $ _GET [ $ index ] ) ) { $ value = $ _GET [ $ index ] ; } return floatval ( $ value ) ; } | Fetch an item from either the GET array or the POST and covert into float |
25,668 | public function doubleval ( $ index = '' , $ default = 0 ) { $ value = $ default ; if ( isset ( $ _POST [ $ index ] ) ) { $ value = $ _POST [ $ index ] ; } else if ( isset ( $ _GET [ $ index ] ) ) { $ value = $ _GET [ $ index ] ; } return doubleval ( $ value ) ; } | Fetch an item from either the GET array or the POST and covert into double |
25,669 | function ipAddress ( ) { if ( $ this -> _ipAddress !== FALSE ) { return $ this -> _ipAddress ; } $ proxyIps = Cfg :: get ( 'proxy_ips' ) ; if ( $ proxyIps != '' && $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] && $ _SERVER [ 'REMOTE_ADDR' ] ) { $ proxies = preg_split ( '/[\s,]/' , $ proxyIps , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ proxies = is_array ( $ proxies ) ? $ proxies : array ( $ proxies ) ; $ this -> _ipAddress = in_array ( $ _SERVER [ 'REMOTE_ADDR' ] , $ proxies ) ? $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] : $ _SERVER [ 'REMOTE_ADDR' ] ; } elseif ( $ _SERVER [ 'REMOTE_ADDR' ] && $ _SERVER [ 'HTTP_CLIENT_IP' ] ) { $ this -> _ipAddress = $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } elseif ( $ _SERVER [ 'REMOTE_ADDR' ] ) { $ this -> _ipAddress = $ _SERVER [ 'REMOTE_ADDR' ] ; } elseif ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) { $ this -> _ipAddress = $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } elseif ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) { $ this -> _ipAddress = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } if ( $ this -> _ipAddress === FALSE ) { $ this -> _ipAddress = '0.0.0.0' ; return $ this -> _ipAddress ; } if ( strpos ( $ this -> _ipAddress , ',' ) !== FALSE ) { $ x = explode ( ',' , $ this -> _ipAddress ) ; $ this -> _ipAddress = trim ( end ( $ x ) ) ; } return $ this -> _ipAddress ; } | Fetch the IP Address |
25,670 | private function _clean_input_data ( $ str ) { if ( is_array ( $ str ) ) { $ new_array = array ( ) ; foreach ( $ str as $ key => $ val ) { $ new_array [ $ this -> _clean_input_keys ( $ key ) ] = $ this -> _clean_input_data ( $ val ) ; } return $ new_array ; } if ( get_magic_quotes_gpc ( ) ) { $ str = stripslashes ( $ str ) ; } $ str = Security :: remove_invisible_characters ( $ str ) ; if ( $ this -> _enable_xss === TRUE ) { $ str = Security :: xss_clean ( $ str ) ; } if ( $ this -> _standardize_newlines == TRUE ) { if ( strpos ( $ str , "\r" ) !== FALSE ) { $ str = str_replace ( array ( "\r\n" , "\r" , "\r\n\n" ) , PHP_EOL , $ str ) ; } } return $ str ; } | Clean Input Data |
25,671 | public function objectName ( $ object ) { $ names = explode ( '\\' , get_class ( $ object ) ) ; return $ this -> getService ( 'inflector' ) -> underscore ( end ( $ names ) ) ; } | Returns the underscored version of the class name of an object . If the class name has namespaces they are removed . This method is intended to be used only by the system . It is public because it s also used by other classes . |
25,672 | public function validate ( array $ data = null ) { $ data = $ data ? : $ this -> getInput ( ) ; $ this -> validation = $ this -> validator -> make ( $ data , $ this -> rules ( ) , $ this -> messages ( ) ) ; if ( $ this -> validation -> fails ( ) ) { $ this -> failed ( ) ; return false ; } return true ; } | Validate the given data . |
25,673 | protected function getOAuth2Request ( $ params = null ) { $ zf2Request = $ this -> getRequest ( ) ; $ headers = $ zf2Request -> getHeaders ( ) ; $ contentType = '' ; if ( $ headers -> has ( 'Content-Type' ) ) { $ contentType = $ headers -> get ( 'Content-Type' ) -> getFieldValue ( ) ; } $ server = array ( ) ; if ( $ zf2Request instanceof PhpEnvironmentRequest ) { $ server = $ zf2Request -> getServer ( ) -> toArray ( ) ; } elseif ( ! empty ( $ _SERVER ) ) { $ server = $ _SERVER ; } $ server [ 'REQUEST_METHOD' ] = $ zf2Request -> getMethod ( ) ; $ headers = $ headers -> toArray ( ) ; if ( isset ( $ server [ 'PHP_AUTH_USER' ] ) ) { $ headers [ 'PHP_AUTH_USER' ] = $ server [ 'PHP_AUTH_USER' ] ; } if ( isset ( $ server [ 'PHP_AUTH_PW' ] ) ) { $ headers [ 'PHP_AUTH_PW' ] = $ server [ 'PHP_AUTH_PW' ] ; } $ bodyParams = $ this -> bodyParams ( ) ? : array ( ) ; return new OAuth2Request ( $ params ? $ params : $ zf2Request -> getQuery ( ) -> toArray ( ) , $ this -> bodyParams ( ) , array ( ) , array ( ) , array ( ) , $ server , $ zf2Request -> getContent ( ) , $ headers ) ; } | Create an OAuth2 request based on the ZF2 request object |
25,674 | private function setHttpResponse ( OAuth2Response $ response ) { $ httpResponse = $ this -> getResponse ( ) ; $ httpResponse -> setStatusCode ( $ response -> getStatusCode ( ) ) ; $ headers = $ httpResponse -> getHeaders ( ) ; $ headers -> addHeaders ( $ response -> getHttpHeaders ( ) ) ; $ headers -> addHeaderLine ( 'Content-type' , 'application/json' ) ; $ httpResponse -> setContent ( $ response -> getResponseBody ( ) ) ; return $ httpResponse ; } | Convert the OAuth2 response to a \ Zend \ Http \ Response |
25,675 | protected function parseData ( ) { $ values = [ ] ; foreach ( $ this -> parts [ 'data' ] as $ key => $ data ) { foreach ( $ data as $ value ) { if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } foreach ( $ value as $ insertValue ) { $ values [ $ key ] [ ] = $ this -> getManager ( ) -> getAdapter ( ) -> quote ( $ insertValue ) ; } } } foreach ( $ values as & $ value ) { $ value = "(" . implode ( ", " , $ value ) . ")" ; } return ' VALUES ' . implode ( ', ' , $ values ) ; } | Parses INSERT data |
25,676 | public static function decode ( $ json , $ assoc = false , $ options = 0 ) { if ( ! is_string ( $ json ) ) { throw new \ InvalidArgumentException ( 'Argument json is not a string' ) ; } $ result = json_decode ( $ json , ( bool ) $ assoc , 512 , ( int ) $ options ) ; if ( $ result === null ) { throw new \ RuntimeException ( static :: $ errorMessages [ json_last_error ( ) ] ) ; } return $ result ; } | Decode a JSON string into a php representation . |
25,677 | public static function encode ( $ value , $ options = 0 ) { $ result = json_encode ( $ value , ( int ) $ options ) ; if ( $ result === false ) { throw new \ RuntimeException ( static :: $ errorMessages [ json_last_error ( ) ] ) ; } return $ result ; } | Encode a PHP value into a JSON representation . |
25,678 | protected function getMissingEntityMessage ( $ entityId ) { $ singleName = $ this -> getEntityNameSingular ( ) ; $ message = "The {$singleName} with ID %s was not found." ; return sprintf ( $ this -> translate ( $ message ) , $ entityId ) ; } | Get missing entity warning message |
25,679 | public function show ( $ entityId = 0 ) { $ entityId = StaticFilter :: filter ( 'text' , $ entityId ) ; $ entity = null ; try { $ entity = $ this -> getEntity ( $ entityId ) ; $ this -> set ( $ this -> getEntityNameSingular ( ) , $ entity ) ; } catch ( EntityNotFoundException $ caught ) { Log :: logger ( ) -> addNotice ( $ caught -> getMessage ( ) ) ; $ this -> addWarningMessage ( $ this -> getMissingEntityMessage ( $ entityId ) ) ; $ this -> redirectFromMissingEntity ( ) ; } return $ entity ; } | Handles the request to view an entity |
25,680 | protected function generateUrl ( $ name , $ parameters = array ( ) , $ referenceType = RouterInterface :: ABSOLUTE_PATH ) { return $ this -> router -> generate ( $ name , $ parameters , $ referenceType ) ; } | Generate url . |
25,681 | public function send ( ) { foreach ( $ this -> cookies as $ cookie ) { setcookie ( $ cookie -> getName ( ) , $ cookie -> getValue ( ) , $ cookie -> getExpire ( ) , $ cookie -> getPath ( ) , $ cookie -> getDomain ( ) , $ cookie -> getSecure ( ) , $ cookie -> getHttponly ( ) ) ; } } | Send all cookies to the browser |
25,682 | public function & createCookie ( string $ name ) { $ cookie = new Cookie ( ) ; $ cookie -> setName ( $ name ) ; $ this -> addCookie ( $ cookie ) ; return $ cookie ; } | Creates a cookie object adds it to the cookies stack and returns an reference to this cookie |
25,683 | public function setHeader ( HeaderElementInterface $ header , $ options = array ( ) ) { $ this -> listColumn -> setHeader ( $ header , $ options ) ; return $ this ; } | Adds header definition to the column |
25,684 | public function setCell ( CellInterface $ cell , $ options = array ( ) ) { $ this -> listColumn -> setCell ( $ cell , $ options ) ; return $ this ; } | Adds cell definition to the column |
25,685 | protected function showGeneratorHelp ( GeneratorInterface $ generator , OutputInterface $ output ) { $ definition = new InputDefinition ( $ generator -> getDefinition ( ) ) ; $ output -> writeln ( "<comment>Generator:</comment> <info>{$generator->getName()}</info>" ) ; $ output -> writeln ( " {$generator->getDescription()}" ) ; $ output -> writeln ( "" ) ; $ output -> writeln ( "<comment>Usage:</comment>" ) ; $ output -> writeln ( " {$this->getName()} {$generator->getName()} {$definition->getSynopsis()}" ) ; $ output -> writeln ( "" ) ; $ descriptor = new DescriptorHelper ( ) ; $ descriptor -> describe ( $ output , $ definition ) ; } | Show the help for a single generator . |
25,686 | protected function showGeneratorList ( OutputInterface $ output ) { $ output -> writeln ( "<comment>Available generators:</comment>" ) ; $ helpCommand = "<info>{$this->getName()} help [generator]</info>" ; $ output -> writeln ( "Use {$helpCommand} for more information on each generator." ) ; $ rows = [ ] ; foreach ( $ this -> dispatcher -> getRegistry ( ) -> getGenerators ( ) as $ generator ) { $ rows [ ] = array ( "<info>{$generator->getName()}</info>" , $ generator -> getDescription ( ) ) ; } $ table = $ this -> getHelper ( 'table' ) ; $ table -> setLayout ( TableHelper :: LAYOUT_BORDERLESS ) ; $ table -> setHorizontalBorderChar ( '' ) ; $ table -> setRows ( $ rows ) ; $ table -> render ( $ output ) ; } | Show the list of generators available . |
25,687 | public function html ( WebException $ exception ) { $ message = $ exception -> getMessage ( ) ; $ statusCode = $ exception -> getStatusCode ( ) ; $ details = $ exception -> getDetails ( ) === null ? "" : $ exception -> getDetails ( ) ; return " <!DOCTYPE html> <html> <head><title>$message</title></head> <body> <h1>HTTP $statusCode: $message</h1> <p>$details</p> </body> </html> " ; } | Returns a html view for the thrown exception |
25,688 | private function getContainerConfigObjects ( ) : array { $ config = ( new ConfigAggregator ( $ this -> getConfigProviders ( ) ) ) -> getMergedConfig ( ) ; $ containerConfigs = [ ] ; foreach ( $ this -> getContainerConfigs ( ) as $ containerConfig ) { $ containerConfigs [ ] = new $ containerConfig ( $ config ) ; } return $ containerConfigs ; } | Get container config objects |
25,689 | static function downloadToTempfile ( $ url ) { $ download_path = Files :: getTempFilename ( ) ; $ fp = fopen ( $ download_path , 'w+' ) ; fwrite ( $ fp , file_get_contents ( $ url ) ) ; fclose ( $ fp ) ; return $ download_path ; } | Downloads file and returns the temporary filename . |
25,690 | static function getStorageObject ( $ filename ) { $ scheme = parse_url ( $ filename , PHP_URL_SCHEME ) ; $ bucket = parse_url ( $ filename , PHP_URL_HOST ) ; $ path = parse_url ( $ filename , PHP_URL_PATH ) ; $ object_name = trim ( $ path , "/" ) ; if ( $ scheme == "gs" ) { $ client = self :: getStorageClient ( ) ; $ bucket = $ client -> bucket ( $ bucket ) ; $ object = $ bucket -> object ( $ object_name ) ; return $ object ; } else { syslog ( LOG_WARNING , "Trying to get storage object on invalid url: $filename" ) ; return false ; } } | Objects are the individual pieces of data that you store in Google Cloud Storage . This function let you fetch object from Cloud Storage from the devserver . |
25,691 | public function toInteger ( ) : int { return ( $ this -> myOctets [ 0 ] << 24 ) + ( $ this -> myOctets [ 1 ] << 16 ) + ( $ this -> myOctets [ 2 ] << 8 ) + $ this -> myOctets [ 3 ] ; } | Returns the IP address as an integer . |
25,692 | public function withMask ( IPAddressInterface $ mask ) : IPAddressInterface { $ octets = $ this -> getParts ( ) ; $ maskOctets = $ mask -> getParts ( ) ; for ( $ i = 0 ; $ i < 4 ; $ i ++ ) { $ octets [ $ i ] = $ octets [ $ i ] & $ maskOctets [ $ i ] ; } return new self ( $ octets ) ; } | Returns a copy of the IP address instance masked with the specified mask . |
25,693 | public static function fromParts ( array $ octets ) : IPAddressInterface { if ( ! self :: myValidateOctets ( $ octets , $ error ) ) { throw new IPAddressInvalidArgumentException ( 'Octets are invalid: ' . $ error ) ; } return new self ( $ octets ) ; } | Creates an IP address from octets . |
25,694 | private static function myParse ( string $ ipAddress , ? array & $ octets = null , ? string & $ error = null ) : bool { if ( $ ipAddress === '' ) { $ error = 'IP address "' . $ ipAddress . '" is empty.' ; return false ; } $ ipAddressParts = explode ( '.' , $ ipAddress ) ; if ( count ( $ ipAddressParts ) !== 4 ) { $ error = 'IP address "' . $ ipAddress . '" is invalid: IP address must consist of four octets.' ; return false ; } $ octets = [ ] ; foreach ( $ ipAddressParts as $ ipAddressPart ) { if ( ! self :: myValidateIpAddressPart ( $ ipAddressPart , $ octet , $ error ) ) { $ error = 'IP address "' . $ ipAddress . '" is invalid: ' . $ error ; return false ; } $ octets [ ] = $ octet ; } return true ; } | Tries to parse an IP address and returns the result or error text . |
25,695 | private static function myValidateIpAddressPart ( string $ ipAddressPart , ? int & $ octet , ? string & $ error ) : bool { if ( $ ipAddressPart === '' ) { $ error = 'Octet "' . $ ipAddressPart . '" is empty.' ; return false ; } if ( preg_match ( '/[^0-9]/' , $ ipAddressPart , $ matches ) ) { $ error = 'Octet "' . $ ipAddressPart . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } $ octet = intval ( $ ipAddressPart ) ; if ( ! self :: myValidateOctet ( $ octet , $ error ) ) { return false ; } return true ; } | Validates an IP address part . |
25,696 | private static function myValidateOctets ( array $ octets , ? string & $ error ) : bool { if ( count ( $ octets ) !== 4 ) { $ error = 'IP address must consist of four octets.' ; return false ; } foreach ( $ octets as $ octet ) { if ( ! is_int ( $ octet ) ) { throw new \ InvalidArgumentException ( '$octets is not an array of integers.' ) ; } if ( ! self :: myValidateOctet ( $ octet , $ error ) ) { return false ; } } return true ; } | Validates an array of octets . |
25,697 | private static function myValidateOctet ( int $ octet , ? string & $ error ) : bool { if ( $ octet < 0 ) { $ error = 'Octet ' . $ octet . ' is out of range: Minimum value for an octet is 0.' ; return false ; } if ( $ octet > 255 ) { $ error = 'Octet ' . $ octet . ' is out of range: Maximum value for an octet is 255.' ; return false ; } return true ; } | Validates an octet . |
25,698 | protected function makeYml ( $ path , $ inputAuthor , $ inputName ) { $ data = [ 'name' => $ inputName , 'author' => $ inputAuthor , 'version' => '1.0' , ] ; $ yml = Yaml :: dump ( $ data ) ; $ this -> files -> put ( dirname ( $ path ) . '/module.yml' , $ yml ) ; } | create yml file info about module |
25,699 | public function peek ( ) { if ( isset ( $ this -> data [ $ this -> position + 1 ] ) ) { return $ this -> data [ $ this -> position + 1 ] ; } return null ; } | Return the next element without increasing position . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.