idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
20,000 | public static function parseFloat ( $ floatString ) { $ LocaleInfo = localeconv ( ) ; $ floatString = str_replace ( $ LocaleInfo [ "mon_thousands_sep" ] , "" , $ floatString ) ; $ floatString = str_replace ( $ LocaleInfo [ "mon_decimal_point" ] , "." , $ floatString ) ; return floatval ( $ floatString ) ; } | Parse a float value with localization in mind |
20,001 | public function bind ( $ name , $ params ) { $ this -> instances [ $ name ] = $ params ; $ this -> bind [ $ name ] = true ; } | Register service to the container |
20,002 | private function resolve ( $ name ) { $ this -> resolved [ $ name ] = true ; if ( is_string ( $ this -> instances [ $ name ] ) && class_exists ( $ this -> instances [ $ name ] ) ) { $ object = $ this -> instances [ $ name ] ; return new $ object ( ) ; } elseif ( is_callable ( $ this -> instances [ $ name ] ) ) { $ callable = $ this -> instances [ $ name ] ; return $ callable ( ) ; } return $ this -> instances [ $ name ] ; } | Try to resolve the service |
20,003 | public static function fromStringifable ( Stringifable $ object ) : self { if ( $ object instanceof Text ) { return self :: fromText ( $ object ) ; } $ text = Text :: make ( $ object -> stringify ( ) ) ; return new static ( $ text ) ; } | Crea una nueva instancia a partir de un objeto Stringifable |
20,004 | public function last ( callable $ callback = null , $ default = null ) { if ( is_null ( $ callback ) ) { if ( ! empty ( $ this -> items ) ) { return end ( $ this -> items ) ; } } else { foreach ( array_reverse ( $ this -> items , true ) as $ key => $ value ) { if ( call_user_func ( $ callback , $ value , $ key ) ) { return $ value ; } } } return $ default instanceof Closure ? $ default ( ) : $ default ; } | Get the last item from the collection . |
20,005 | public function createPayload ( ) { $ payload = $ this -> extras ; $ payload [ 'job' ] = $ this -> job ; $ payload [ 'data' ] = $ this -> data ; if ( $ this -> job instanceof \ Closure ) { $ payload [ 'closure' ] = serialize ( new SerializableClosure ( $ this -> job ) ) ; $ payload [ 'job' ] = $ this -> closureClass ; } return $ payload ; } | Creates a serialized payload |
20,006 | public static function createFromPayload ( array $ payload ) { $ job = $ payload [ 'job' ] ; $ data = $ payload [ 'data' ] ; unset ( $ payload [ 'job' ] , $ payload [ 'data' ] ) ; return new static ( $ job , $ data , [ ] , $ payload ) ; } | Creates a new Job from payload |
20,007 | public function addAllowedRole ( $ role , $ attribute = 'access' ) { $ roleStr = ( string ) $ role ; if ( ! isset ( $ this -> allowedRoles [ $ roleStr ] ) ) { $ this -> allowedRoles [ $ roleStr ] = array ( ) ; } $ this -> allowedRoles [ $ roleStr ] [ ( string ) $ attribute ] = true ; return $ this ; } | Allow user role to access |
20,008 | public function isRoleAllowed ( $ role , $ attribute = 'access' ) { if ( is_array ( $ role ) ) { foreach ( $ role as $ r ) { if ( $ this -> isRoleAllowed ( $ r , $ attribute ) ) { return true ; } } return false ; } else { $ roleStr = ( string ) $ role ; $ attrStr = ( string ) $ attribute ; if ( isset ( $ this -> allowedRoles [ $ roleStr ] ) ) { return ( isset ( $ this -> allowedRoles [ $ roleStr ] [ $ attrStr ] ) ? $ this -> allowedRoles [ $ roleStr ] [ $ attrStr ] : false ) || ( isset ( $ this -> allowedRoles [ $ roleStr ] [ 'any' ] ) ? $ this -> allowedRoles [ $ roleStr ] [ 'any' ] : false ) ; } return false ; } } | Check if a specific user role is allowed to access |
20,009 | public function addAllowedUsername ( $ username , $ attribute = 'access' ) { $ usernameStr = ( string ) $ username ; if ( ! isset ( $ this -> allowedUsernames [ $ usernameStr ] ) ) { $ this -> allowedUsernames [ $ usernameStr ] = array ( ) ; } $ this -> allowedUsernames [ $ usernameStr ] [ ( string ) $ attribute ] = true ; return $ this ; } | Allow username to access |
20,010 | public function isUsernameAllowed ( $ username , $ attribute = 'access' ) { $ usernameStr = ( string ) $ username ; $ attrStr = ( string ) $ attribute ; return ( isset ( $ this -> allowedUsernames [ $ usernameStr ] ) && isset ( $ this -> allowedUsernames [ $ usernameStr ] [ $ attrStr ] ) ) ? $ this -> allowedUsernames [ $ usernameStr ] [ $ attrStr ] : false ; } | Check if a specific username is allowed to access this context |
20,011 | public static function isEmpty ( $ line , $ strict = false ) { if ( ! is_array ( $ line ) ) { throw new \ RuntimeException ( "got a string that should already have been split into an array" ) ; } $ test = array_filter ( $ line , function ( $ element ) use ( $ strict ) { return ! Reader :: isEmpty ( $ element , $ strict ) ; } ) ; return empty ( $ test ) ; } | Check whether a line is to be considered empty . |
20,012 | protected function set_plugin ( $ the__file__ ) { if ( ! function_exists ( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php' ; } $ this -> plugin [ 'fullpath' ] = $ the__file__ ; $ this -> plugin [ 'basename' ] = plugin_basename ( $ this -> plugin [ 'fullpath' ] ) ; list ( $ this -> plugin [ 'dirname' ] , $ this -> plugin [ 'filename' ] ) = explode ( '/' , $ this -> plugin [ 'basename' ] ) ; $ plugin_data = get_plugin_data ( $ this -> plugin [ 'fullpath' ] ) ; $ this -> plugin [ 'name' ] = $ plugin_data [ 'Name' ] ; } | Set paths name etc for a plugin |
20,013 | protected function set_params ( $ params ) { $ this -> requirements_details_url = ! empty ( $ params [ 'requirements_details_url' ] ) ? esc_url ( trim ( ( string ) $ params [ 'requirements_details_url' ] ) ) : $ this -> requirements_details_url ; $ this -> version_compare_operator = ! empty ( $ params [ 'version_compare_operator' ] ) ? ( string ) $ params [ 'version_compare_operator' ] : $ this -> version_compare_operator ; $ this -> not_valid_actions = ! empty ( $ params [ 'not_valid_actions' ] ) ? ( array ) $ params [ 'not_valid_actions' ] : $ this -> not_valid_actions ; $ this -> show_valid_results = isset ( $ params [ 'show_valid_results' ] ) ? ( bool ) $ params [ 'show_valid_results' ] : $ this -> show_valid_results ; } | Redefine all params by those that were submitted by a user . |
20,014 | protected function validate_php ( $ php ) { $ result = $ required = array ( ) ; foreach ( $ php as $ type => $ data ) { switch ( $ type ) { case 'version' : $ result [ $ type ] = version_compare ( phpversion ( ) , $ data , $ this -> version_compare_operator ) ; $ required [ $ type ] = $ data ; break ; case 'extensions' : foreach ( ( array ) $ data as $ extension ) { if ( $ extension && is_string ( $ extension ) ) { $ result [ $ type ] [ $ extension ] = extension_loaded ( $ extension ) ; $ required [ $ type ] [ ] = $ extension ; } } break ; } } $ this -> results [ 'php' ] = $ result ; $ this -> required [ 'php' ] = $ required ; } | Check all PHP related data like version and extensions |
20,015 | protected function validate_wordpress ( $ wordpress ) { global $ wp_version ; $ result = $ required = array ( ) ; foreach ( $ wordpress as $ type => $ data ) { switch ( $ type ) { case 'version' : $ result [ $ type ] = version_compare ( $ wp_version , $ data , '>=' ) ; $ required [ $ type ] = $ data ; break ; case 'plugins' : if ( ! function_exists ( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php' ; } foreach ( ( array ) $ data as $ plugin => $ required_version ) { if ( $ plugin && is_string ( $ plugin ) ) { $ required [ $ type ] [ $ plugin ] = $ required_version ; $ is_plugin_active = is_plugin_active ( $ plugin ) ; if ( is_bool ( $ required_version ) ) { $ result [ $ type ] [ $ plugin ] = ( $ is_plugin_active === $ required_version ) ; } else { $ raw_data = get_plugin_data ( WP_PLUGIN_DIR . '/' . $ plugin , false , false ) ; $ is_plugin_version_ok = ( ! isset ( $ raw_data [ 'Version' ] ) || version_compare ( $ raw_data [ 'Version' ] , $ required_version , $ this -> version_compare_operator ) ) ; $ result [ $ type ] [ $ plugin ] = $ is_plugin_active && $ is_plugin_version_ok ; } } } break ; case 'theme' : $ theme = ( array ) $ data ; $ current_theme = wp_get_theme ( ) ; foreach ( $ theme as $ slug => $ required_version ) { if ( ( $ current_theme -> get_template ( ) === $ slug || $ current_theme -> get_stylesheet ( ) === $ slug ) && version_compare ( $ current_theme -> get ( 'Version' ) , $ required_version , $ this -> version_compare_operator ) ) { $ result [ $ type ] [ $ slug ] = true ; } else { $ result [ $ type ] [ $ slug ] = false ; } $ required [ $ type ] [ $ slug ] = $ required_version ; } break ; } } $ this -> results [ 'wordpress' ] = $ result ; $ this -> required [ 'wordpress' ] = $ required ; } | Check all WordPress related data like version plugins and theme |
20,016 | public function process_failure ( ) { if ( ! count ( $ this -> results ) || ! count ( $ this -> not_valid_actions ) ) { return ; } foreach ( $ this -> not_valid_actions as $ action ) { switch ( $ action ) { case 'deactivate' : deactivate_plugins ( $ this -> get_plugin ( 'basename' ) , true ) ; if ( isset ( $ _GET [ 'activate' ] ) ) { unset ( $ _GET [ 'activate' ] ) ; } break ; case 'admin_notice' : add_action ( 'admin_notices' , array ( $ this , 'display_admin_notice' ) ) ; break ; } } } | Get the list of registered actions and do everything defined by them |
20,017 | public function display_admin_notice ( ) { echo '<div class="notice is-dismissible error">' ; echo '<p>' ; printf ( esc_html__ ( '%s will not function correctly because your site doesn\'t meet some of the requirements:' , 'wp-requirements' ) , '<strong>' . esc_html ( $ this -> get_plugin ( 'name' ) ) . '</strong>' ) ; echo '</p>' ; if ( $ this -> requirements_details_url ) { printf ( '<p>' . esc_html__ ( 'Please read more details %s here %s.' , 'wp-requirements' ) . '</p>' , '<a href="' . esc_url ( $ this -> requirements_details_url ) . '">' , '</a>' ) ; } else { echo '<ul>' ; foreach ( $ this -> results as $ type => $ data ) { $ notices = $ this -> php_mysql_notices ( $ type , $ data ) ; echo '<li>' . implode ( '</li><li>' , $ notices ) . '</li>' ; } echo '</ul>' ; } echo '</div>' ; } | Display an admin notice in WordPress admin area |
20,018 | public function get_plugin ( $ data = '' ) { if ( ! $ data ) { return $ this -> plugin ; } if ( ! empty ( $ this -> plugin [ $ data ] ) ) { return $ this -> plugin [ $ data ] ; } return null ; } | Retrieve current plugin data like paths name etc |
20,019 | protected function load_json ( ) { $ json_file = $ this -> locate_configuration_file ( ) ; $ json_data = '{}' ; if ( '' !== $ json_file ) { $ json_data = file_get_contents ( $ json_file ) ; } return $ json_data ? $ this -> parse_json ( $ json_data ) : array ( ) ; } | Load wp - requirements . json |
20,020 | protected function locate_configuration_file ( ) { $ located = '' ; $ folders = array ( dirname ( $ this -> get_plugin ( 'fullpath' ) ) ) ; $ folders = ( array ) apply_filters ( 'wp_requirements_configuration_folders' , $ folders ) ; foreach ( $ folders as $ folder ) { $ path = trailingslashit ( $ folder ) . self :: CONFIG_FILE_NAME ; if ( is_readable ( $ path ) ) { $ located = $ path ; break ; } } return $ located ; } | Search for a configuration file . |
20,021 | protected function parse_json ( $ json ) { $ data = json_decode ( $ json , true ) ; if ( ! is_array ( $ data ) ) { $ data = array ( ) ; } return $ data ; } | Parse JSON string to make it an array that is usable for us |
20,022 | public static function validate ( $ the__file__ , array $ requirements = array ( ) ) { $ _wpr = new WP_Requirements ( $ the__file__ , $ requirements ) ; $ is_valid = $ _wpr -> valid ( ) ; if ( ! $ is_valid ) { $ _wpr -> process_failure ( ) ; } return $ is_valid ; } | Shortcut to construct the object and process the failure actions . |
20,023 | private function getTreeQueryAsArray ( \ Doctrine \ ORM \ Query $ query ) { $ items = array ( ) ; $ index = array ( ) ; $ nodes = $ query -> getResult ( ) ; $ count = count ( $ nodes ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ node = $ nodes [ $ i ] ; $ newItem = array ( 'id' => $ node -> getId ( ) , 'name' => $ node -> getName ( ) , 'slug' => $ node -> getSlug ( ) ) ; if ( $ i == 0 ) { $ newItem = array_merge ( $ this -> getParentTreeParams ( $ node ) , $ newItem ) ; } foreach ( $ node -> getNodeAttributes ( ) as $ attribute ) { $ newItem [ $ attribute -> getName ( ) ] = $ attribute -> getValue ( ) ; } if ( ( $ node -> getParent ( ) ) && isset ( $ index [ $ node -> getParent ( ) -> getId ( ) ] ) ) { $ _path = $ index [ $ node -> getParent ( ) -> getId ( ) ] ; eval ( '$parent = &$items' . $ _path . ';' ) ; if ( ! isset ( $ parent [ 'items' ] ) ) { $ parent [ 'items' ] = array ( ) ; } foreach ( $ parent as $ paramKey => $ paramValue ) { if ( substr ( $ paramKey , 0 , 5 ) == 'tree_' ) { $ newItem [ $ paramKey ] = $ paramValue ; } } $ index [ $ node -> getId ( ) ] = $ _path . '["items"][' . count ( $ parent [ 'items' ] ) . ']' ; $ parent [ 'items' ] [ ] = $ newItem ; } else { $ index [ $ node -> getId ( ) ] = '[' . count ( $ items ) . ']' ; $ items [ ] = $ newItem ; } } return $ items ; } | Returns doctrine query nested set as an array for json |
20,024 | private function getParentTreeParams ( \ Coral \ ContentBundle \ Entity \ Node $ node ) { $ params = $ this -> getDoctrine ( ) -> getManager ( ) -> createQuery ( 'SELECT n.level, na.name, na.value FROM CoralContentBundle:NodeAttribute na INNER JOIN na.node n WITH (n.lft < :lft AND n.rgt > :rgt) INNER JOIN n.account a WITH (a.id = :account_id) WHERE na.name LIKE \'tree_%\' ORDER BY n.level ASC' ) -> setParameter ( 'account_id' , $ this -> getAccount ( ) -> getId ( ) ) -> setParameter ( 'lft' , $ node -> getLft ( ) ) -> setParameter ( 'rgt' , $ node -> getRgt ( ) ) -> getResult ( \ Doctrine \ ORM \ AbstractQuery :: HYDRATE_ARRAY ) ; $ treeParams = array ( ) ; foreach ( $ params as $ param ) { $ treeParams [ $ param [ 'name' ] ] = $ param [ 'value' ] ; } return $ treeParams ; } | Fetches all parent params and returns as array |
20,025 | final public function showDefault ( ) { $ request = Request :: instance ( ) ; $ t = new Template ( '.app/system/default' , 'systemDefault' ) ; $ t -> assign ( [ 'action' => $ request -> src . '::' . $ request -> controller . '::' . $ request -> action ] ) ; return $ t -> show ( ) ; } | display a default template |
20,026 | public function extract ( $ file , $ destination = false ) { $ archive = $ this -> getArchiver ( ) -> open ( $ file ) ; if ( $ archive ) { $ this -> getArchiver ( ) -> extractTo ( $ destination ) ; return $ this -> getArchiver ( ) -> close ( ) ; } } | Extracts a compressed file to the destination |
20,027 | public function create ( $ name ) { $ this -> setArchiveName ( $ name ) ; $ this -> getArchiver ( ) -> open ( $ this -> getArchiveName ( ) , \ ZipArchive :: CREATE | \ ZipArchive :: OVERWRITE ) ; return $ this ; } | Starts the process of creating an archive |
20,028 | public function archiveSingle ( $ file , $ desination = false ) { if ( $ file == '' ) { throw new CompressException ( '__exception_compress_file_value_empty' ) ; } if ( ! file_exists ( $ file ) ) { throw new CompressException ( '__exception_compress_file_not_exist' ) ; } if ( ! is_readable ( $ file ) ) { throw new CompressException ( '__exception_compress_file_not_readable' ) ; } $ old_cwd = getcwd ( ) ; $ path = dirname ( $ file ) ; chdir ( $ path ) ; $ name = $ this -> getArchiveName ( ) ; $ zip = $ this -> getArchiver ( ) ; $ zip -> open ( $ name , \ ZipArchive :: CREATE ) ; if ( file_exists ( $ file ) ) { $ zip -> addFile ( basename ( $ file ) ) ; } if ( $ zip -> status != '0' ) { throw new CompressException ( '__exception_compression' ) ; } $ zip -> close ( ) ; if ( ! $ this -> getKeepOriginal ( ) && file_exists ( $ file ) ) { unlink ( $ file ) ; } if ( $ desination ) { $ desination = realpath ( $ desination ) . DIRECTORY_SEPARATOR . $ name ; copy ( $ name , $ desination ) ; unlink ( $ name ) ; $ name = $ desination ; } else { $ name = $ path . DIRECTORY_SEPARATOR . $ name ; } chdir ( $ old_cwd ) ; return $ name ; } | Compresses a single file |
20,029 | public function pay ( $ amount , $ parameters ) { $ payment = new InvoicePayment ( ) ; $ payment -> amount = $ amount ; $ payment -> setPreCommitMetadataArray ( $ parameters [ 'metadata' ] ) ; $ payment -> invoice ( ) -> associate ( $ this ) ; $ payment -> type ( ) -> associate ( $ parameters [ 'type' ] ) ; if ( isset ( $ parameters [ 'id' ] ) ) { $ payment -> payment_id = $ parameters [ 'id' ] ; } $ payment -> save ( ) ; return $ payment ; } | Apply a payment to this invoice . |
20,030 | public function offsetGet ( $ offset ) { if ( ! $ this -> has ( $ offset ) ) { throw new UnknownIdentifierException ( $ offset ) ; } if ( ! isset ( $ this -> _frozen [ $ offset ] ) ) { $ entry = & $ this -> _store [ $ offset ] ; if ( is_callable ( $ entry ) ) { $ entry = $ entry ( $ this ) ; } $ this -> _frozen [ $ offset ] = & $ entry ; } return $ this -> _frozen [ $ offset ] ; } | Retrieve an entry to return . |
20,031 | public function offsetSet ( $ offset , $ value ) { if ( $ this -> has ( $ offset ) ) { throw new StoreReattachException ( 'The entry is exists.' ) ; } $ this -> _store [ $ offset ] = $ value ; } | Assign a value to the specified entry id . |
20,032 | public function offsetUnset ( $ offset ) { if ( $ this -> has ( $ offset ) ) { unset ( $ this -> _store [ $ offset ] , $ this -> _frozen [ $ offset ] ) ; } } | Unset an Entry |
20,033 | public function clear ( ) { foreach ( $ this -> keys ( ) as $ key ) { unset ( $ this -> _store [ $ key ] ) ; } $ frozenKeys = \ array_keys ( $ this -> _frozen ) ; foreach ( $ frozenKeys as $ key ) { unset ( $ this -> _frozen [ $ key ] ) ; } } | Clear store and frozen entrys |
20,034 | public function addRelation ( Relation $ relation ) { $ relation -> setPrimaryModel ( $ this ) ; $ this -> _relations [ $ relation -> getAlias ( ) ] = $ relation ; $ this -> _aliases [ $ relation -> getRelatedClass ( ) ] = $ relation -> getAlias ( ) ; $ this -> reserved [ ] = $ relation -> getAlias ( ) ; $ this -> on ( 'relation' , $ relation ) ; return $ this ; } | Add a relation between two models . |
20,035 | public function belongsTo ( $ alias , $ class , $ foreignKey = null , Closure $ conditions = null ) { $ relation = ( new ManyToOne ( $ alias , $ class ) ) -> setPrimaryForeignKey ( $ foreignKey ) ; if ( $ conditions ) { $ relation -> setConditions ( $ conditions ) ; } return $ this -> addRelation ( $ relation ) ; } | Add a many - to - one relationship . |
20,036 | public function belongsToMany ( $ alias , $ class , $ junction , $ foreignKey = null , $ relatedKey = null , Closure $ conditions = null ) { $ relation = ( new ManyToMany ( $ alias , $ class ) ) -> setJunction ( $ junction ) -> setPrimaryForeignKey ( $ foreignKey ) -> setRelatedForeignKey ( $ relatedKey ) ; if ( $ conditions ) { $ relation -> setConditions ( $ conditions ) ; } return $ this -> addRelation ( $ relation ) ; } | Add a many - to - many relationship . |
20,037 | public function delete ( array $ options = [ ] ) { $ options = $ options + [ 'atomic' => true ] ; $ id = $ this -> get ( $ this -> primaryKey ) ; if ( ! $ id ) { throw new MissingPrimaryKeyException ( sprintf ( 'Cannot delete %s record if no ID is present' , get_class ( $ this ) ) ) ; } $ model = $ this ; $ operation = function ( ) use ( $ model , $ id , $ options ) { if ( $ count = $ model -> getRepository ( ) -> delete ( $ id , $ options ) ) { $ model -> flush ( ) ; return $ count ; } return 0 ; } ; if ( $ options [ 'atomic' ] ) { try { $ count = $ this -> getRepository ( ) -> getDriver ( ) -> transaction ( $ operation ) ; } catch ( Exception $ e ) { return 0 ; } } else { $ count = call_user_func ( $ operation ) ; } return $ count ; } | Delete the record that is currently present in the model instance . |
20,038 | public function fill ( array $ data ) { if ( $ this -> isFullyGuarded ( ) ) { throw new MassAssignmentException ( sprintf ( 'Cannot assign attributes as %s is locked' , get_class ( $ this ) ) ) ; } foreach ( $ data as $ key => $ value ) { if ( $ this -> isFillable ( $ key ) && ! $ this -> isGuarded ( $ key ) ) { $ this -> set ( $ key , $ value ) ; } } return $ this ; } | Fill the model with data to be sent to the database layer . |
20,039 | public function flush ( ) { $ this -> _attributes = [ ] ; $ this -> _original = [ ] ; $ this -> _changed = false ; $ this -> _exists = false ; $ this -> _errors = [ ] ; $ this -> _validator = null ; return $ this ; } | Empty all data in the model . |
20,040 | public function get ( $ key ) { $ value = null ; if ( $ this -> has ( $ key ) ) { $ value = $ this -> _attributes [ $ key ] ; } if ( ! $ value && $ this -> hasRelation ( $ key ) ) { $ value = $ this -> getRelation ( $ key ) -> fetchRelation ( ) ; $ this -> set ( $ key , $ value ) ; } else if ( $ method = $ this -> hasAccessor ( $ key ) ) { $ value = $ this -> { $ method } ( $ value ) ; } return $ value ; } | Get an attribute on the model . If the attribute points to a relation fetch the related records through the relation object . If an accessor is defined pass the non - relation attribute through it . |
20,041 | public function getChanged ( ) { $ attributes = [ ] ; if ( $ this -> changed ( ) ) { $ attributes = array_diff_assoc ( $ this -> _attributes , $ this -> _original ) ; $ attributes = Hash :: exclude ( $ attributes , $ this -> reserved ) ; } return $ attributes ; } | Return an array of data that only includes attributes that have changed . |
20,042 | public function getRelation ( $ alias ) { if ( $ this -> hasRelation ( $ alias ) ) { return $ this -> _relations [ $ alias ] ; } throw new MissingRelationException ( sprintf ( 'Repository relation %s does not exist' , $ alias ) ) ; } | Return a relation by alias . |
20,043 | public function getRelations ( $ type = null ) { if ( ! $ type ) { return $ this -> _relations ; } $ relations = [ ] ; foreach ( $ this -> _relations as $ relation ) { if ( $ relation -> getType ( ) === $ type ) { $ relations [ $ relation -> getAlias ( ) ] = $ relation ; } } return $ relations ; } | Return all relations or all relations by type . |
20,044 | public function getValidator ( ) { if ( ! $ this -> _validator ) { $ this -> setValidator ( Validator :: makeFromShorthand ( [ ] , $ this -> validate ) ) ; } return $ this -> _validator ; } | Return the validator instance . |
20,045 | public function hasMutator ( $ field ) { $ method = sprintf ( 'set%sAttribute' , Inflector :: camelCase ( $ field ) ) ; if ( method_exists ( $ this , $ method ) ) { return $ method ; } return null ; } | Check to see if a mutator method exists on the current model . If so return the method name else return null . |
20,046 | public function hasOne ( $ alias , $ class , $ relatedKey = null , Closure $ conditions = null ) { $ relation = ( new OneToOne ( $ alias , $ class ) ) -> setRelatedForeignKey ( $ relatedKey ) ; if ( $ conditions ) { $ relation -> setConditions ( $ conditions ) ; } return $ this -> addRelation ( $ relation ) ; } | Add a one - to - one relationship . |
20,047 | public function hasMany ( $ alias , $ class , $ relatedKey = null , Closure $ conditions = null ) { $ relation = ( new OneToMany ( $ alias , $ class ) ) -> setRelatedForeignKey ( $ relatedKey ) ; if ( $ conditions ) { $ relation -> setConditions ( $ conditions ) ; } return $ this -> addRelation ( $ relation ) ; } | Add a one - to - many relationship . |
20,048 | public function link ( Model $ model ) { $ this -> getRelation ( $ this -> getAlias ( get_class ( $ model ) ) ) -> link ( $ model ) ; return $ this ; } | Link an external model to the primary model . Once the primary is saved the links will be saved as well . |
20,049 | public function linkMany ( ) { $ models = func_get_args ( ) ; if ( is_array ( $ models [ 0 ] ) ) { $ models = $ models [ 0 ] ; } foreach ( $ models as $ model ) { $ this -> link ( $ model ) ; } return $ this ; } | Link multiple models at once . |
20,050 | public function loadRelations ( ) { foreach ( [ Relation :: MANY_TO_ONE => $ this -> belongsTo , Relation :: MANY_TO_MANY => $ this -> belongsToMany , Relation :: ONE_TO_ONE => $ this -> hasOne , Relation :: ONE_TO_MANY => $ this -> hasMany ] as $ type => $ relations ) { foreach ( $ relations as $ alias => $ relation ) { if ( is_string ( $ relation ) ) { $ relation = [ 'model' => $ relation ] ; } $ relation = $ relation + [ 'model' => null , 'foreignKey' => null , 'relatedForeignKey' => null , 'conditions' => null , 'junction' => null ] ; switch ( $ type ) { case Relation :: MANY_TO_ONE : $ this -> belongsTo ( $ alias , $ relation [ 'model' ] , $ relation [ 'foreignKey' ] , $ relation [ 'conditions' ] ) ; break ; case Relation :: MANY_TO_MANY : $ this -> belongsToMany ( $ alias , $ relation [ 'model' ] , $ relation [ 'junction' ] , $ relation [ 'foreignKey' ] , $ relation [ 'relatedForeignKey' ] , $ relation [ 'conditions' ] ) ; break ; case Relation :: ONE_TO_ONE : $ this -> hasOne ( $ alias , $ relation [ 'model' ] , $ relation [ 'relatedForeignKey' ] , $ relation [ 'conditions' ] ) ; break ; case Relation :: ONE_TO_MANY : $ this -> hasMany ( $ alias , $ relation [ 'model' ] , $ relation [ 'relatedForeignKey' ] , $ relation [ 'conditions' ] ) ; break ; } } } return $ this ; } | Load relationships by reflecting current model properties . |
20,051 | public function mapData ( array $ data ) { $ this -> flush ( ) ; if ( ! empty ( $ data [ $ this -> primaryKey ] ) ) { $ this -> _exists = true ; } $ this -> _original = Hash :: exclude ( $ data , $ this -> reserved ) ; $ this -> _attributes = $ data ; return $ this ; } | When data is mapped through the constructor set the exists flag if necessary and save the original data state to monitor for changes . |
20,052 | public function save ( array $ options = [ ] ) { $ options = $ options + [ 'validate' => true , 'atomic' => true , 'force' => false ] ; $ passed = $ options [ 'validate' ] ? $ this -> validate ( ) : true ; if ( ! $ passed ) { return 0 ; } $ data = $ this -> getChanged ( ) ; if ( ! $ data || $ options [ 'force' ] ) { $ data = $ this -> toArray ( ) ; } if ( empty ( $ data [ $ this -> primaryKey ] ) && ( $ id = $ this -> id ( ) ) ) { $ data [ $ this -> primaryKey ] = $ id ; } $ model = $ this ; $ operation = function ( ) use ( $ model , $ data , $ options ) { if ( $ id = $ model -> getRepository ( ) -> upsert ( $ data , null , $ options ) ) { $ model -> mapData ( $ model -> _attributes ) ; $ model -> set ( $ model -> getPrimaryKey ( ) , $ id ) ; $ model -> _exists = true ; $ model -> _changed = false ; return $ id ; } $ model -> _exists = false ; return 0 ; } ; if ( $ options [ 'atomic' ] ) { try { $ id = $ this -> getRepository ( ) -> getDriver ( ) -> transaction ( $ operation ) ; } catch ( Exception $ e ) { return 0 ; } } else { $ id = call_user_func ( $ operation ) ; } return $ id ; } | Save a record to the database table using the data that has been set to the model . Will return the record ID or 0 on failure . |
20,053 | public function set ( $ key , $ value = null ) { if ( ! $ this -> hasRelation ( $ key ) ) { if ( $ value != $ this -> get ( $ key ) && ! in_array ( $ key , $ this -> reserved ) ) { $ this -> _changed = true ; } if ( $ method = $ this -> hasMutator ( $ key ) ) { $ this -> { $ method } ( $ value ) ; return $ this ; } } $ this -> _attributes [ $ key ] = $ value ; return $ this ; } | Set an attribute defined by key . If the key does not point to a relation pass the value through a mutator and set a changed flag . |
20,054 | public function setValidator ( Validator $ validator ) { $ this -> _validator = $ validator ; $ this -> on ( 'model' , $ this ) ; return $ this ; } | Set the validator instance . |
20,055 | public function toArray ( ) { return array_map ( function ( $ value ) { return ( $ value instanceof Arrayable ) ? $ value -> toArray ( ) : $ value ; } , $ this -> _attributes ) ; } | Return the model attributes as an array . |
20,056 | public function unlink ( Model $ model ) { $ this -> getRelation ( $ this -> getAlias ( get_class ( $ model ) ) ) -> unlink ( $ model ) ; return $ this ; } | Unlink an external model that has been tied to this model . |
20,057 | public function unlinkMany ( ) { $ models = func_get_args ( ) ; if ( is_array ( $ models [ 0 ] ) ) { $ models = $ models [ 0 ] ; } foreach ( $ models as $ model ) { $ this -> unlink ( $ model ) ; } return $ this ; } | Unlink multiple models at once . |
20,058 | public function validate ( ) { $ this -> _errors = [ ] ; if ( ! $ this -> validate ) { return true ; } $ validator = $ this -> getValidator ( ) ; $ validator -> reset ( ) ; $ validator -> addMessages ( $ this -> messages ) ; $ validator -> setData ( $ this -> toArray ( ) ) ; $ event = $ this -> emit ( 'model.preValidate' , [ $ this , $ validator ] ) ; if ( $ event -> getData ( ) === false ) { return false ; } $ status = $ validator -> validate ( ) ; $ this -> _errors = $ validator -> getErrors ( ) ; $ this -> _validator = null ; $ this -> emit ( 'model.postValidate' , [ $ this , $ status ] ) ; return $ status ; } | Validate the current set of data against the models validation rules . |
20,059 | public static function create ( array $ data , array $ options = [ ] ) { $ model = new static ( ) ; $ model -> fill ( $ data ) ; if ( $ model -> save ( $ options ) ) { return $ model ; } return null ; } | Create a new model instance fill with data and attempt to save . Return the model instance on success or a null on failure . |
20,060 | public static function findBy ( $ field , $ value , array $ options = [ ] ) { if ( $ record = static :: select ( ) -> where ( $ field , $ value ) -> first ( $ options ) ) { return $ record ; } return new static ( ) ; } | Will attempt to find a record by a field s value and return a model instance with data pre - filled . If no record can be found an empty model instance will be returned . |
20,061 | public static function update ( $ id , array $ data , array $ options = [ ] ) { $ model = static :: find ( $ id ) ; if ( $ model -> exists ( ) ) { $ model -> fill ( $ data ) ; if ( $ model -> save ( $ options ) ) { return $ model ; } } return null ; } | Update a model by ID by finding the record in the database filling the data and attempting to save . Return the model instance on success or a null on failure . |
20,062 | public function filter ( ? callable $ callback = null ) : Sequence { if ( is_null ( $ callback ) ) { return $ this -> duplicate ( $ this -> items -> filter ( ) ) ; } return $ this -> duplicate ( $ this -> items -> filter ( $ callback ) ) ; } | Returns a new sequence containing only the values for which a callback returns true . A boolean test will be used if a callback is not provided . |
20,063 | public function find ( $ value ) : ? int { $ founded = $ this -> items -> find ( $ value ) ; if ( false === $ founded ) { return null ; } return ( int ) $ founded ; } | Returns the index of a given value or null if it could not be found . |
20,064 | public function findAll ( $ value ) : ? array { $ founded = array_keys ( $ this -> items -> toArray ( ) , $ value , true ) ; if ( 0 === count ( $ founded ) ) { return null ; } return $ founded ; } | Returns the all the index of a given value or null if it could not be found . |
20,065 | public function insert ( int $ index , ... $ values ) : Sequence { $ this -> resolver -> values ( function ( \ DS \ Map $ map ) use ( $ index ) : void { $ values = $ map -> values ( ) ; $ this -> items -> insert ( $ index , ... $ values ) ; } , $ values ) ; return $ this ; } | Inserts zero or more values at a given index . |
20,066 | public function map ( callable $ callback ) : Sequence { $ items = $ this -> items -> map ( $ callback ) ; return $ this -> duplicate ( $ items ) ; } | Returns a new sequence using the results of applying a callback to each value . |
20,067 | public function merge ( iterable $ values ) : Sequence { $ items = $ this -> items -> merge ( $ values ) ; return $ this -> duplicate ( $ items ) ; } | Returns the result of adding all given values to the sequence . |
20,068 | public function pushAll ( iterable $ values ) : Sequence { foreach ( $ values as $ value ) { $ this [ ] = $ value ; } return $ this ; } | Pushes all values of either an array or traversable object . |
20,069 | public function set ( int $ index , $ value ) : Sequence { $ this -> offsetSet ( $ index , $ value ) ; return $ this ; } | Replaces the value at a given index in the sequence with a new value . |
20,070 | public function slice ( int $ index , ? int $ length = null ) : Sequence { $ items = $ length ? $ this -> items -> slice ( $ index , $ length ) : $ this -> items -> slice ( $ index ) ; return $ this -> duplicate ( $ items ) ; } | Returns a sub - sequence of a given length starting at a specified index . |
20,071 | public function sort ( ? callable $ comparator = null ) : Sequence { $ comparator ? $ this -> items -> sort ( $ comparator ) : $ this -> items -> sort ( ) ; return $ this ; } | Sorts the sequence in - place based on an optional callable comparator . |
20,072 | public function sorted ( ? callable $ comparator = null ) : Sequence { $ items = $ comparator ? $ this -> items -> sorted ( $ comparator ) : $ this -> items -> sorted ( ) ; return $ this -> duplicate ( $ items ) ; } | Returns a sorted copy of the sequence based on an optional callable comparator . Natural ordering will be used if a comparator is not given . |
20,073 | public function unshift ( ... $ values ) : Sequence { $ this -> resolver -> values ( function ( \ DS \ Map $ values ) : void { $ this -> items -> unshift ( ... $ values -> values ( ) ) ; } , $ values ) ; return $ this ; } | Adds zero or more values to the front of the sequence . |
20,074 | protected function buildJsonpResponse ( Response $ response ) { $ content = ( string ) $ response -> getBody ( ) ; $ contentType = $ response -> getHeaderLine ( 'Content-Type' ) ; if ( strpos ( $ contentType , 'application/json' ) === false ) { $ content = '"' . $ content . '"' ; } $ callback = "{$this->callbackName}({$content});" ; $ newResponse = new Response ( 200 ) ; $ newResponse -> getBody ( ) -> write ( $ callback ) ; return $ newResponse -> withHeader ( 'Content-Type' , 'application/javascript' ) ; } | Build Response with the callback . |
20,075 | public function isBlank ( $ value ) { if ( $ value === null || strlen ( $ value ) === 0 || trim ( $ value ) === '' ) { return true ; } return false ; } | Check if the value is blank or not . |
20,076 | public function days ( $ date = null ) { return is_string ( $ date ) ? ( new \ DateTime ( $ date , self :: $ utc ) ) -> diff ( $ this -> date ) -> days : $ date -> diff ( $ this -> date ) -> days ; } | Returns the difference between two dates in days |
20,077 | public function diff ( $ date = 'now' ) { if ( $ date instanceof static ) return $ this -> date -> diff ( $ date -> date ) ; else if ( $ date instanceof \ DateTime ) return $ this -> date -> diff ( $ date ) ; else if ( is_string ( $ date ) ) return $ this -> date -> diff ( new \ DateTime ( $ date , self :: $ utc ) ) ; } | Returns the difference between two dates |
20,078 | public static function create ( $ time = 'now' , $ timezone = null ) { return new static ( new \ DateTime ( $ time , $ timezone === null ? self :: $ utc : ( is_string ( $ timezone ) ? new \ DateTimeZone ( $ timezone ) : $ timezone ) ) ) ; } | Create a Twister \ Date object or returns null |
20,079 | public function setTagsAllowed ( $ tagsAllowed ) { if ( ! is_array ( $ tagsAllowed ) ) { $ tagsAllowed = [ $ tagsAllowed ] ; } foreach ( $ tagsAllowed as $ index => $ element ) { if ( is_int ( $ index ) && is_string ( $ element ) ) { $ tagName = strtolower ( $ element ) ; $ this -> tagsAllowed [ $ tagName ] = [ ] ; } elseif ( is_string ( $ index ) && ( is_array ( $ element ) || is_string ( $ element ) ) ) { $ tagName = strtolower ( $ index ) ; if ( is_string ( $ element ) ) { $ element = [ $ element ] ; } $ this -> tagsAllowed [ $ tagName ] = [ ] ; foreach ( $ element as $ attribute ) { if ( is_string ( $ attribute ) ) { $ attributeName = strtolower ( $ attribute ) ; $ this -> tagsAllowed [ $ tagName ] [ $ attributeName ] = null ; } } } } return $ this ; } | Sets the tagsAllowed option |
20,080 | public function setAttributesAllowed ( $ attributesAllowed ) { if ( ! is_array ( $ attributesAllowed ) ) { $ attributesAllowed = [ $ attributesAllowed ] ; } foreach ( $ attributesAllowed as $ attribute ) { if ( is_string ( $ attribute ) ) { $ attributeName = strtolower ( $ attribute ) ; $ this -> attributesAllowed [ $ attributeName ] = null ; } } return $ this ; } | Sets the attributesAllowed option |
20,081 | public static function Pom00 ( $ xp , $ yp , $ sp , array & $ rpom ) { IAU :: Ir ( $ rpom ) ; IAU :: Rz ( $ sp , $ rpom ) ; IAU :: Ry ( - $ xp , $ rpom ) ; IAU :: Rx ( - $ yp , $ rpom ) ; return ; } | - - - - - - - - - - i a u P o m 0 0 - - - - - - - - - - |
20,082 | public function hasDirective ( $ name ) { $ inSubDirective = false ; foreach ( $ this -> directives as $ directive ) { if ( $ directive -> getName ( ) == $ name ) { return true ; } $ inSubDirective = $ this -> hasInnerDirective ( $ name , $ inSubDirective , $ directive ) ; } return $ inSubDirective ; } | Confirms if the directive contains a specified directive . |
20,083 | private function hasInnerDirective ( $ name , $ inSubDirective , DirectiveInterface $ directive ) { if ( ! $ directive -> isSimple ( ) ) { $ inSubDirective = $ inSubDirective || $ directive -> hasDirective ( $ name ) ; } return $ inSubDirective ; } | Looks into sub directives to confirm if the actual contains a specified directive . |
20,084 | public function dump ( ServerInterface $ server , $ spaces = 0 ) { $ config = '' ; foreach ( $ this -> directives as $ directive ) { $ config .= $ directive -> dump ( $ server , $ spaces + ( $ this -> isMainContext ( ) ? 0 : 4 ) ) ; } return $ this -> dumpBlock ( $ server -> getDumperStartDirective ( ) , $ spaces ) . $ config . $ this -> dumpBlock ( $ server -> getDumperEndDirective ( ) , $ spaces ) ; } | Dumps the directive respecting a server syntax . |
20,085 | public function add ( MRoute $ route ) { $ this -> validateRoute ( $ route ) ; $ this -> routeList -> insert ( $ route -> getRole ( ) , $ route ) ; } | Adds a new definition of Route . |
20,086 | protected static function parseAttrs ( $ attrs = array ( ) ) { if ( ! is_array ( $ attrs ) ) throw new HtmlException ( 'Sem itens para parsear' . __CLASS__ . '::' . __FUNCTION__ , 1 ) ; $ return = NULL ; foreach ( $ attrs as $ atr => $ val ) { $ return .= ' ' ; $ return .= trim ( $ atr ) . '="' . $ val . '"' ; } $ return = trim ( $ return ) ; return $ return ; } | Realiza o parse dos atributos em uma tag |
20,087 | public static function js ( $ fileName , $ base_path = true ) { if ( ! is_array ( $ fileName ) ) $ fileName = array ( $ fileName ) ; $ data = null ; foreach ( $ fileName as $ file ) { $ data .= '<script src="' ; $ data .= ( $ base_path ) ? self :: getJSLink ( ) : '' ; $ data .= $ file . '"></script>' . PHP_EOL ; } return $ data ; } | Gera a tag de script |
20,088 | public static function css ( $ fileName , $ base_path = true ) { if ( ! is_array ( $ fileName ) ) $ fileName = array ( $ fileName ) ; $ data = null ; foreach ( $ fileName as $ file ) { $ url = "" ; $ url .= ( $ base_path ) ? self :: getCSSLink ( ) : '' ; $ url .= $ file ; $ data .= '<link rel="stylesheet" type="text/css" href="' . $ url . '"/>' . PHP_EOL ; } return $ data ; } | Gera a tag de link |
20,089 | protected function parseQueryParams ( ) : void { $ queryParams = [ ] ; $ queryString = $ this -> request -> getUri ( ) -> getQuery ( ) ; parse_str ( $ queryString , $ queryParams ) ; $ this -> queryParams = $ queryParams ; } | Parse the query params . |
20,090 | protected function getQueryParam ( string $ param ) : ? string { if ( $ this -> queryParams === null ) { $ this -> parseQueryParams ( ) ; } return $ this -> queryParams [ $ param ] ?? null ; } | Gets a query param . |
20,091 | protected function setResponseStatus ( int $ code , string $ reasonPhrase = '' ) : void { $ this -> response = $ this -> response -> withStatus ( $ code , $ reasonPhrase ) ; } | Sets the response status . |
20,092 | protected function getSortFields ( ) { return array ( 'a.lft' => JText :: _ ( 'JGRID_HEADING_ORDERING' ) , 'a.published' => JText :: _ ( 'JSTATUS' ) , 'a.title' => JText :: _ ( 'JGLOBAL_TITLE' ) , 'a.access' => JText :: _ ( 'JGRID_HEADING_ACCESS' ) , 'language' => JText :: _ ( 'JGRID_HEADING_LANGUAGE' ) , 'a.id' => JText :: _ ( 'JGRID_HEADING_ID' ) ) ; } | Returns an array of fields the table can be sorted by |
20,093 | static function error ( $ type , $ message , $ file , $ line ) { $ error = <<<ERROR<pre><a href="corebrowser:$file:$line">$file:$line</a>#$type $message</pre>ERROR ; if ( $ type !== E_NOTICE ) { die ( $ error ) ; } } | Handlers errors in the app . |
20,094 | public function getArguments ( $ asString = false ) { if ( $ asString ) { $ str = ( string ) $ this -> arguments ; return $ str ; } return $ this -> arguments -> all ( ) ; } | Get the argument string |
20,095 | public function removeArgument ( $ arg ) { if ( $ this -> hasArgument ( $ arg ) ) { $ this -> arguments -> remove ( $ arg ) ; } return $ this ; } | Remove an argument |
20,096 | public static function Set ( $ sKey , $ mValue ) { $ oThis = self :: CreateInstanceIfNotExists ( ) ; $ oThis -> aList [ $ sKey ] = $ mValue ; } | Function to store data |
20,097 | public static function SetArray ( $ sKey , $ sKeyInArray , $ mValue ) { $ oThis = self :: CreateInstanceIfNotExists ( ) ; if ( ! array_key_exists ( $ sKey , $ oThis -> aList ) ) $ oThis -> aList [ $ sKey ] = array ( ) ; $ oThis -> aList [ $ sKey ] [ $ sKeyInArray ] = $ mValue ; } | Function to store data in list |
20,098 | public static function Get ( $ sKey , $ mDefault = false ) { $ oThis = self :: CreateInstanceIfNotExists ( ) ; return ( array_key_exists ( $ sKey , $ oThis -> aList ) ) ? $ oThis -> aList [ $ sKey ] : $ mDefault ; } | Function to return data stored |
20,099 | public static function GetArray ( $ sKey , $ sKeyInArray , $ mDefault = false ) { $ oThis = self :: CreateInstanceIfNotExists ( ) ; return ( array_key_exists ( $ sKey , $ oThis -> aList ) ) ? ( ( array_key_exists ( $ sKeyInArray , $ oThis -> aList [ $ sKey ] ) ? $ oThis -> aList [ $ sKey ] [ $ sKeyInArray ] : $ mDefault ) ) : $ mDefault ; } | Function to return data stored in list |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.