idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
20,900 | public function Label ( $ TranslationCode , $ FieldName = '' , $ Attributes = FALSE ) { $ DefaultFor = ( $ FieldName == '' ) ? $ TranslationCode : $ FieldName ; $ For = ArrayValueI ( 'for' , $ Attributes , ArrayValueI ( 'id' , $ Attributes , $ this -> EscapeID ( $ DefaultFor , FALSE ) ) ) ; return '<label for="' . $ For . '"' . $ this -> _AttributesToString ( $ Attributes ) . '>' . T ( $ TranslationCode ) . "</label>\n" ; } | Returns XHTML for a label element . |
20,901 | public static function LabelCode ( $ Item ) { if ( is_array ( $ Item ) ) { if ( isset ( $ Item [ 'LabelCode' ] ) ) return $ Item [ 'LabelCode' ] ; $ LabelCode = $ Item [ 'Name' ] ; } else { $ LabelCode = $ Item ; } if ( strpos ( $ LabelCode , '.' ) !== FALSE ) $ LabelCode = trim ( strrchr ( $ LabelCode , '.' ) , '.' ) ; $ LabelCode = preg_replace ( '`(?<![A-Z0-9])([A-Z0-9])`' , ' $1' , $ LabelCode ) ; $ LabelCode = preg_replace ( '`([A-Z0-9])(?=[a-z])`' , ' $1' , $ LabelCode ) ; $ LabelCode = trim ( $ LabelCode ) ; return $ LabelCode ; } | Generate a friendly looking label translation code from a camel case variable name |
20,902 | public function Radio ( $ FieldName , $ Label = '' , $ Attributes = FALSE ) { $ Value = ArrayValueI ( 'Value' , $ Attributes , 'TRUE' ) ; $ Attributes [ 'value' ] = $ Value ; $ FormValue = $ this -> GetValue ( $ FieldName , ArrayValueI ( 'Default' , $ Attributes ) ) ; if ( $ FormValue == $ Value ) $ Attributes [ 'checked' ] = 'checked' ; $ Attributes [ 'InlineErrors' ] = FALSE ; $ Input = $ this -> Input ( $ FieldName , 'radio' , $ Attributes ) ; if ( $ Label != '' ) { $ Input = '<label for="' . ArrayValueI ( 'id' , $ Attributes , $ this -> EscapeID ( $ FieldName , FALSE ) ) . '" class="RadioLabel">' . $ Input . ' ' . T ( $ Label ) . '</label>' ; } return $ Input ; } | Returns XHTML for a radio input element . |
20,903 | public function RadioList ( $ FieldName , $ DataSet , $ Attributes = FALSE ) { $ List = GetValue ( 'list' , $ Attributes ) ; $ Return = '' ; if ( $ List ) { $ Return .= '<ul' . ( isset ( $ Attributes [ 'listclass' ] ) ? " class=\"{$Attributes['listclass']}\"" : '' ) . '>' ; $ LiOpen = '<li>' ; $ LiClose = '</li>' ; } else { $ LiOpen = '' ; $ LiClose = ' ' ; } $ ShowErrors = ( $ this -> _InlineErrors && array_key_exists ( $ FieldName , $ this -> _ValidationResults ) ) ; if ( $ ShowErrors ) $ this -> AddErrorClass ( $ Attributes ) ; if ( is_object ( $ DataSet ) ) { $ ValueField = ArrayValueI ( 'ValueField' , $ Attributes , 'value' ) ; $ TextField = ArrayValueI ( 'TextField' , $ Attributes , 'text' ) ; $ Data = $ DataSet -> FirstRow ( ) ; if ( property_exists ( $ Data , $ ValueField ) && property_exists ( $ Data , $ TextField ) ) { foreach ( $ DataSet -> Result ( ) as $ Data ) { $ Attributes [ 'value' ] = $ Data -> $ ValueField ; $ Return .= $ LiOpen . $ this -> Radio ( $ FieldName , $ Data -> $ TextField , $ Attributes ) . $ LiClose ; } } } elseif ( is_array ( $ DataSet ) ) { foreach ( $ DataSet as $ ID => $ Text ) { $ Attributes [ 'value' ] = $ ID ; $ Return .= $ LiOpen . $ this -> Radio ( $ FieldName , $ Text , $ Attributes ) . $ LiClose ; } } if ( $ List ) $ Return .= '</ul>' ; if ( $ ShowErrors && ArrayValueI ( 'InlineErrors' , $ Attributes , TRUE ) ) $ Return .= $ this -> InlineError ( $ FieldName ) ; return $ Return ; } | Returns XHTML for an unordered list of radio button elements . |
20,904 | public function TextBox ( $ FieldName , $ Attributes = FALSE ) { if ( ! is_array ( $ Attributes ) ) $ Attributes = array ( ) ; $ MultiLine = ArrayValueI ( 'MultiLine' , $ Attributes ) ; if ( $ MultiLine ) { $ Attributes [ 'rows' ] = ArrayValueI ( 'rows' , $ Attributes , '6' ) ; $ Attributes [ 'cols' ] = ArrayValueI ( 'cols' , $ Attributes , '100' ) ; } $ ShowErrors = $ this -> _InlineErrors && array_key_exists ( $ FieldName , $ this -> _ValidationResults ) ; $ CssClass = ArrayValueI ( 'class' , $ Attributes ) ; if ( $ CssClass == FALSE ) $ Attributes [ 'class' ] = $ MultiLine ? 'TextBox' : 'InputBox' ; if ( $ ShowErrors ) $ this -> AddErrorClass ( $ Attributes ) ; $ Return = '' ; $ Wrap = GetValue ( 'Wrap' , $ Attributes , FALSE , TRUE ) ; if ( $ Wrap ) $ Return .= '<div class="TextBoxWrapper">' ; $ Return .= $ MultiLine === TRUE ? '<textarea' : '<input type="' . GetValue ( 'type' , $ Attributes , 'text' ) . '"' ; $ Return .= $ this -> _IDAttribute ( $ FieldName , $ Attributes ) ; $ Return .= $ this -> _NameAttribute ( $ FieldName , $ Attributes ) ; $ Return .= $ MultiLine === TRUE ? '' : $ this -> _ValueAttribute ( $ FieldName , $ Attributes ) ; $ Return .= $ this -> _AttributesToString ( $ Attributes ) ; $ Value = ArrayValueI ( 'value' , $ Attributes , $ this -> GetValue ( $ FieldName ) ) ; $ Return .= $ MultiLine === TRUE ? '>' . htmlentities ( $ Value , ENT_COMPAT , 'UTF-8' ) . '</textarea>' : ' />' ; if ( $ ShowErrors ) $ Return .= $ this -> InlineError ( $ FieldName ) ; if ( $ Wrap ) $ Return .= '</div>' ; return $ Return ; } | Returns the xhtml for a text - based input . |
20,905 | public function AddHidden ( $ FieldName , $ Value = NULL , $ ForceValue = FALSE ) { if ( $ this -> IsPostBack ( ) && $ ForceValue === FALSE ) $ Value = $ this -> GetFormValue ( $ FieldName , $ Value ) ; $ this -> HiddenInputs [ $ FieldName ] = $ Value ; } | Adds a hidden input value to the form . |
20,906 | public function EscapeFieldName ( $ FieldName ) { $ Return = $ this -> InputPrefix ; if ( $ Return != '' ) $ Return .= '/' ; return $ Return . $ this -> EscapeString ( $ FieldName ) ; } | Returns the provided fieldname with non - alpha - numeric values stripped . |
20,907 | public function IsMyPostBack ( ) { switch ( strtolower ( $ this -> Method ) ) { case 'get' : return count ( $ _GET ) > 0 || ( is_array ( $ this -> FormValues ( ) ) && count ( $ this -> FormValues ( ) ) > 0 ) ? TRUE : FALSE ; default : return Gdn :: Request ( ) -> IsPostBack ( ) ; } } | Check if THIS particular form was submitted |
20,908 | public function Save ( ) { $ SaveResult = FALSE ; if ( $ this -> ErrorCount ( ) == 0 ) { if ( ! isset ( $ this -> _Model ) ) trigger_error ( ErrorMessage ( "You cannot call the form's save method if a model has not been defined." , "Form" , "Save" ) , E_USER_ERROR ) ; $ Data = $ this -> FormValues ( ) ; if ( method_exists ( $ this -> _Model , 'FilterForm' ) ) $ Data = $ this -> _Model -> FilterForm ( $ this -> FormValues ( ) ) ; $ Args = array_merge ( func_get_args ( ) , array ( NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ) ) ; $ SaveResult = $ this -> _Model -> Save ( $ Data , $ Args [ 0 ] , $ Args [ 1 ] , $ Args [ 2 ] , $ Args [ 3 ] , $ Args [ 4 ] , $ Args [ 5 ] , $ Args [ 6 ] , $ Args [ 7 ] , $ Args [ 8 ] , $ Args [ 9 ] ) ; if ( $ SaveResult === FALSE ) { $ this -> SetValidationResults ( $ this -> _Model -> ValidationResults ( ) ) ; } } return $ SaveResult ; } | This is a convenience method so that you don t have to code this every time you want to save a simple model s data . |
20,909 | public function SetData ( $ Data ) { if ( is_object ( $ Data ) === TRUE ) { if ( $ Data instanceof DataSet ) { $ ResultSet = $ Data -> ResultArray ( ) ; if ( count ( $ ResultSet ) > 0 ) $ this -> _DataArray = $ ResultSet [ 0 ] ; } else { $ this -> _DataArray = Gdn_Format :: ObjectAsArray ( $ Data ) ; } } else if ( is_array ( $ Data ) ) { $ this -> _DataArray = $ Data ; } } | Assign a set of data to be displayed in the form elements . |
20,910 | public function RemoveFormValue ( $ FieldName ) { $ this -> FormValues ( ) ; if ( ! is_array ( $ FieldName ) ) $ FieldName = array ( $ FieldName ) ; foreach ( $ FieldName as $ Field ) unset ( $ this -> _FormValues [ $ Field ] ) ; } | Remove an element from a form |
20,911 | public function ValidateModel ( ) { $ this -> _Model -> DefineSchema ( ) ; if ( $ this -> _Model -> Validation -> Validate ( $ this -> FormValues ( ) ) === FALSE ) $ this -> _ValidationResults = $ this -> _Model -> ValidationResults ( ) ; return $ this -> ErrorCount ( ) ; } | If not saving data directly to the model this method allows you to utilize a model s schema to validate a form s inputs regardless . |
20,912 | public function ValidateRule ( $ FieldName , $ Rule , $ CustomError = '' ) { $ Value = $ this -> GetFormValue ( $ FieldName ) ; $ Valid = Gdn_Validation :: ValidateRule ( $ Value , $ FieldName , $ Rule , $ CustomError ) ; if ( $ Valid === TRUE ) return TRUE ; else { $ this -> AddError ( '@' . $ Valid ) ; return FALSE ; } } | Validates a rule on the form and adds its result to the errors collection . |
20,913 | public function add ( string $ name , string $ value ) : void { $ header = $ this -> make ( ) ; $ header -> name = $ name ; $ header -> value = $ value ; $ this -> set ( $ header ) ; } | Add a custom header . |
20,914 | public function createRevision ( Model $ Model ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return false ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return false ; } $ habtm = array ( ) ; $ allHabtm = $ Model -> getAssociated ( 'hasAndBelongsToMany' ) ; foreach ( $ allHabtm as $ assocAlias ) { if ( isset ( $ Model -> ShadowModel -> _schema [ $ assocAlias ] ) ) { $ habtm [ ] = $ assocAlias ; } } $ data = $ Model -> find ( 'first' , array ( 'conditions' => array ( $ Model -> alias . '.' . $ Model -> primaryKey => $ Model -> id ) , 'contain' => $ habtm ) ) ; $ Model -> ShadowModel -> create ( $ data ) ; $ Model -> ShadowModel -> set ( 'version_created' , date ( 'Y-m-d H:i:s' ) ) ; foreach ( $ habtm as $ assocAlias ) { $ foreignKeys = Hash :: extract ( $ data , '{n}.' . $ assocAlias . '.' . $ Model -> { $ assocAlias } -> primaryKey ) ; $ Model -> ShadowModel -> set ( $ assocAlias , implode ( ',' , $ foreignKeys ) ) ; } return ( bool ) $ Model -> ShadowModel -> save ( ) ; } | Manually create a revision of the current record of Model - > id |
20,915 | public function diff ( Model $ Model , $ fromVersionId = null , $ toVersionId = null , $ options = array ( ) ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return array ( ) ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return array ( ) ; } if ( isset ( $ options [ 'conditions' ] ) ) { $ conditions = array_merge ( $ options [ 'conditions' ] , array ( $ Model -> primaryKey => $ Model -> id ) ) ; } else { $ conditions = array ( $ Model -> primaryKey => $ Model -> id ) ; } if ( is_numeric ( $ fromVersionId ) || is_numeric ( $ toVersionId ) ) { if ( is_numeric ( $ fromVersionId ) && is_numeric ( $ toVersionId ) ) { $ conditions [ 'version_id' ] = array ( $ fromVersionId , $ toVersionId ) ; if ( $ Model -> ShadowModel -> find ( 'count' , array ( 'conditions' => $ conditions ) ) < 2 ) { return array ( ) ; } } else { if ( is_numeric ( $ fromVersionId ) ) { $ conditions [ 'version_id' ] = $ fromVersionId ; } else { $ conditions [ 'version_id' ] = $ toVersionId ; } if ( $ Model -> ShadowModel -> find ( 'count' , array ( 'conditions' => $ conditions ) ) < 1 ) { return array ( ) ; } } } $ conditions = array ( $ Model -> primaryKey => $ Model -> id ) ; if ( is_numeric ( $ fromVersionId ) ) { $ conditions [ 'version_id >=' ] = $ fromVersionId ; } if ( is_numeric ( $ toVersionId ) ) { $ conditions [ 'version_id <=' ] = $ toVersionId ; } $ options [ 'conditions' ] = $ conditions ; $ all = $ this -> revisions ( $ Model , $ options , true ) ; if ( ! $ all ) { return array ( ) ; } $ unified = array ( ) ; $ keys = array_keys ( $ all [ 0 ] [ $ Model -> alias ] ) ; foreach ( $ keys as $ field ) { $ allValues = Hash :: extract ( $ all , '{n}.' . $ Model -> alias . '.' . $ field ) ; $ allValues = array_reverse ( array_unique ( array_reverse ( $ allValues , true ) ) , true ) ; if ( sizeof ( $ allValues ) == 1 ) { $ unified [ $ field ] = reset ( $ allValues ) ; } else { $ unified [ $ field ] = $ allValues ; } } return array ( $ Model -> alias => $ unified ) ; } | Returns an array that maps to the Model only with multiple values for fields that has been changed |
20,916 | protected function _init ( Model $ Model , $ page , $ limit ) { $ habtm = array ( ) ; $ allHabtm = $ Model -> getAssociated ( 'hasAndBelongsToMany' ) ; foreach ( $ allHabtm as $ assocAlias ) { if ( isset ( $ Model -> ShadowModel -> _schema [ $ assocAlias ] ) ) { $ habtm [ ] = $ assocAlias ; } } $ all = $ Model -> find ( 'all' , array ( 'limit' => $ limit , 'page' => $ page , 'contain' => $ habtm ) ) ; $ versionCreated = date ( 'Y-m-d H:i:s' ) ; foreach ( $ all as $ data ) { $ Model -> ShadowModel -> create ( $ data ) ; $ Model -> ShadowModel -> set ( 'version_created' , $ versionCreated ) ; $ Model -> ShadowModel -> save ( ) ; } } | Saves revisions for rows matching page and limit given |
20,917 | public function newest ( Model $ Model , $ options = array ( ) ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return array ( ) ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return array ( ) ; } if ( isset ( $ options [ 'conditions' ] ) ) { $ options [ 'conditions' ] = array_merge ( $ options [ 'conditions' ] , array ( $ Model -> alias . '.' . $ Model -> primaryKey => $ Model -> id ) ) ; } else { $ options [ 'conditions' ] = array ( $ Model -> alias . '.' . $ Model -> primaryKey => $ Model -> id ) ; } return $ Model -> ShadowModel -> find ( 'first' , $ options ) ; } | Finds the newest revision including the current one . Use with caution the live model may be different depending on the usage of ignore fields . |
20,918 | public function oldest ( Model $ Model , $ options = array ( ) ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return array ( ) ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return array ( ) ; } if ( isset ( $ options [ 'conditions' ] ) ) { $ options [ 'conditions' ] = array_merge ( $ options [ 'conditions' ] , array ( $ Model -> primaryKey => $ Model -> id ) ) ; } else { $ options [ 'conditions' ] = array ( $ Model -> primaryKey => $ Model -> id ) ; } $ options [ 'order' ] = 'version_created ASC, version_id ASC' ; return $ Model -> ShadowModel -> find ( 'first' , $ options ) ; } | Find the oldest revision for the current Model - > id If no limit is used on revision and revision has been enabled for the model since start this call will return the original first record . |
20,919 | public function previous ( Model $ Model , $ options = array ( ) ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return array ( ) ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return array ( ) ; } $ options [ 'limit' ] = 1 ; $ options [ 'page' ] = 2 ; if ( isset ( $ options [ 'conditions' ] ) ) { $ options [ 'conditions' ] = array_merge ( $ options [ 'conditions' ] , array ( $ Model -> primaryKey => $ Model -> id ) ) ; } else { $ options [ 'conditions' ] = array ( $ Model -> primaryKey => $ Model -> id ) ; } $ revisions = $ Model -> ShadowModel -> find ( 'all' , $ options ) ; if ( ! $ revisions ) { return array ( ) ; } return $ revisions [ 0 ] ; } | Find the second newest revisions including the current one . |
20,920 | public function revertAll ( Model $ Model , $ options = array ( ) ) { if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return false ; } if ( empty ( $ options ) || ! isset ( $ options [ 'date' ] ) ) { return false ; } if ( ! isset ( $ options [ 'conditions' ] ) ) { $ options [ 'conditions' ] = array ( ) ; } $ all = $ Model -> find ( 'all' , array ( 'conditions' => $ options [ 'conditions' ] , 'fields' => $ Model -> primaryKey ) ) ; $ allIds = Hash :: extract ( $ all , '{n}.' . $ Model -> alias . '.' . $ Model -> primaryKey ) ; $ cond = $ options [ 'conditions' ] ; $ cond [ 'version_created <' ] = $ options [ 'date' ] ; $ createdBeforeDate = $ Model -> ShadowModel -> find ( 'all' , array ( 'order' => $ Model -> primaryKey , 'conditions' => $ cond , 'fields' => array ( 'version_id' , $ Model -> primaryKey ) ) ) ; $ createdBeforeDateIds = Hash :: extract ( $ createdBeforeDate , '{n}.' . $ Model -> alias . '.' . $ Model -> primaryKey ) ; $ deleteIds = array_diff ( $ allIds , $ createdBeforeDateIds ) ; $ Model -> deleteAll ( array ( $ Model -> alias . '.' . $ Model -> primaryKey => $ deleteIds ) , false , true ) ; unset ( $ cond [ 'version_created <' ] ) ; $ cond [ 'version_created >=' ] = $ options [ 'date' ] ; $ createdAfterDate = $ Model -> ShadowModel -> find ( 'all' , array ( 'order' => $ Model -> primaryKey , 'conditions' => $ cond , 'fields' => array ( 'version_id' , $ Model -> primaryKey ) ) ) ; $ createdAfterDateIds = Hash :: extract ( $ createdAfterDate , '{n}.' . $ Model -> alias . '.' . $ Model -> primaryKey ) ; $ updateIds = array_diff ( $ createdAfterDateIds , $ deleteIds ) ; $ revertSuccess = true ; foreach ( $ updateIds as $ mid ) { $ Model -> id = $ mid ; if ( ! $ Model -> revertToDate ( $ options [ 'date' ] ) ) { $ revertSuccess = false ; } } return $ revertSuccess ; } | Revert all rows matching conditions to given date . Model rows outside condition or not edited will not be affected . Edits since date will be reverted and rows created since date deleted . |
20,921 | public function revertTo ( Model $ Model , $ versionId ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return false ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return false ; } $ data = $ Model -> ShadowModel -> find ( 'first' , array ( 'conditions' => array ( 'version_id' => $ versionId ) ) ) ; if ( ! $ data ) { return false ; } foreach ( $ Model -> getAssociated ( 'hasAndBelongsToMany' ) as $ assocAlias ) { if ( isset ( $ Model -> ShadowModel -> _schema [ $ assocAlias ] ) ) { $ data [ $ assocAlias ] [ $ assocAlias ] = explode ( ',' , $ data [ $ Model -> alias ] [ $ assocAlias ] ) ; } } return ( bool ) $ Model -> save ( $ data ) ; } | Revert current Model - > id to the given revision id Will return false if version id is invalid or save fails |
20,922 | public function undo ( Model $ Model ) { if ( ! $ Model -> id ) { trigger_error ( 'RevisionBehavior: Model::id must be set' , E_USER_WARNING ) ; return null ; } if ( ! $ Model -> ShadowModel ) { trigger_error ( 'RevisionBehavior: ShadowModel doesnt exist.' , E_USER_WARNING ) ; return false ; } $ data = $ this -> previous ( $ Model ) ; if ( ! $ data ) { $ Model -> logableAction [ 'Revision' ] = 'undo add' ; $ Model -> delete ( $ Model -> id ) ; return false ; } foreach ( $ Model -> getAssociated ( 'hasAndBelongsToMany' ) as $ assocAlias ) { if ( isset ( $ Model -> ShadowModel -> _schema [ $ assocAlias ] ) ) { $ data [ $ assocAlias ] [ $ assocAlias ] = explode ( ',' , $ data [ $ Model -> alias ] [ $ assocAlias ] ) ; } } $ Model -> logableAction [ 'Revision' ] = 'undo changes' ; return ( bool ) $ Model -> save ( $ data ) ; } | Update to previous revision |
20,923 | public function afterDelete ( Model $ Model ) { if ( $ this -> settings [ $ Model -> alias ] [ 'auto' ] === false ) { return ; } if ( ! $ Model -> ShadowModel ) { return ; } if ( isset ( $ this -> deleteUpdates [ $ Model -> alias ] ) && ! empty ( $ this -> deleteUpdates [ $ Model -> alias ] ) ) { foreach ( $ this -> deleteUpdates [ $ Model -> alias ] as $ assocAlias => $ assocIds ) { $ Model -> { $ assocAlias } -> updateRevisions ( $ assocIds ) ; } unset ( $ this -> deleteUpdates [ $ Model -> alias ] ) ; } } | Causes revision for habtm associated models if that model does version control on their relationship . BeforeDelete identifies the related models that will need to do the revision update in afterDelete . Uses |
20,924 | public function beforeDelete ( Model $ Model , $ cascade = true ) { if ( $ this -> settings [ $ Model -> alias ] [ 'auto' ] === false ) { return true ; } if ( ! $ Model -> ShadowModel ) { return true ; } foreach ( $ Model -> hasAndBelongsToMany as $ assocAlias => $ a ) { if ( isset ( $ Model -> { $ assocAlias } -> ShadowModel -> _schema [ $ Model -> alias ] ) ) { $ joins = $ Model -> { $ a [ 'with' ] } -> find ( 'all' , array ( 'recursive' => - 1 , 'conditions' => array ( $ a [ 'foreignKey' ] => $ Model -> id ) ) ) ; $ this -> deleteUpdates [ $ Model -> alias ] [ $ assocAlias ] = Hash :: extract ( $ joins , '{n}.' . $ a [ 'with' ] . '.' . $ a [ 'associationForeignKey' ] ) ; } } return true ; } | Causes revision for habtm associated models if that model does version control on their relationship . BeforeDelete identifies the related models that will need to do the revision update in afterDelete . |
20,925 | public function beforeSave ( Model $ Model , $ options = array ( ) ) { if ( $ this -> settings [ $ Model -> alias ] [ 'auto' ] === false ) { return true ; } if ( ! $ Model -> ShadowModel ) { return true ; } $ Model -> ShadowModel -> create ( ) ; if ( ! isset ( $ Model -> data [ $ Model -> alias ] [ $ Model -> primaryKey ] ) && ! $ Model -> id ) { return true ; } $ habtm = array ( ) ; foreach ( $ Model -> getAssociated ( 'hasAndBelongsToMany' ) as $ assocAlias ) { if ( isset ( $ Model -> ShadowModel -> _schema [ $ assocAlias ] ) ) { $ habtm [ ] = $ assocAlias ; } } $ this -> _oldData [ $ Model -> alias ] = $ Model -> find ( 'first' , array ( 'contain' => $ habtm , 'conditions' => array ( $ Model -> alias . '.' . $ Model -> primaryKey => $ Model -> id ) ) ) ; return true ; } | Revision uses the beforeSave callback to remember the old data for comparison in afterSave |
20,926 | public function getServices ( ) { return [ self :: INFLECTOR => function ( ) { return Inflector :: get ( 'en' ) ; } , self :: APPLICATION_RUNTIME => function ( ) { return new ApplicationRuntime ( ) ; } , self :: CONFIG_FACTORY => function ( ) { return new ConfigFactory ( ) ; } ] ; } | Get the details of the services we are providing |
20,927 | public static function validateImage ( UploadControl $ control ) { $ file = $ control -> getValue ( ) ; if ( ! in_array ( $ file -> getContentType ( ) , [ 'image/gif' , 'image/png' , 'image/jpeg' , 'image/svg+xml' ] , true ) ) { return false ; } return true ; } | Validace obrazku + svg |
20,928 | public static function beansOfType ( ApplicationInterface $ applicationContext , $ class ) { $ objectManager = $ applicationContext -> search ( "ObjectManagerInterface" ) ; $ initialContext = new InitialContext ( ) ; $ initialContext -> injectApplication ( $ applicationContext ) ; $ beans = array ( ) ; foreach ( $ objectManager -> getObjectDescriptors ( ) as $ descriptor ) { if ( $ descriptor instanceof ComponentDescriptorInterface ) { if ( is_subclass_of ( $ descriptor -> getClassName ( ) , $ class ) ) { $ beans [ $ descriptor -> getName ( ) ] = $ initialContext -> lookup ( $ descriptor -> getName ( ) ) ; } } } return $ beans ; } | Returns beans of a specific type |
20,929 | public function getFactorableInstance ( string $ factorableClassName ) { $ factorable = $ this -> loadFromRegistry ( $ factorableClassName ) ; if ( ! $ factorable instanceof AbstractService ) { $ factorable = parent :: getFactorableInstance ( $ factorableClassName ) ; } return $ factorable ; } | Gets a service |
20,930 | public static function create ( array $ params = [ ] ) { $ headers = new static ( ) ; foreach ( $ params as $ key => $ value ) { $ headers -> set ( $ key , $ value ) ; } return $ headers ; } | Create the default values from httpMessages array . |
20,931 | public static function toPreserveCase ( $ name ) { $ params = explode ( '-' , $ name ) ; $ newName = [ ] ; foreach ( $ params as $ param ) { $ newName [ ] = ucwords ( $ param ) ; } return implode ( '-' , $ newName ) ; } | Replace name to preserve case format . |
20,932 | public function allPreserveCase ( ) { $ fields = $ this -> all ( ) ; $ raw = [ ] ; foreach ( $ fields as $ key => $ field ) { $ raw [ static :: toPreserveCase ( $ key ) ] = $ field ; } return $ raw ; } | Get all header fields with Preserve Case format . |
20,933 | protected function buildRequestReplacements ( ) { $ name = $ this -> getNameInput ( ) ; $ rootNamespace = trim ( $ this -> laravel -> getNamespace ( ) . 'Http\Requests' . '\\' . $ this -> getNamespace ( $ name ) , '\\' ) ; $ storeRequest = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'StoreRequest' ; $ updateRequest = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'UpdateRequest' ; if ( ! class_exists ( $ storeRequest ) ) { if ( $ this -> confirm ( "A {$storeRequest} request does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:request' , [ 'name' => $ storeRequest ] ) ; } } if ( ! class_exists ( $ updateRequest ) ) { if ( $ this -> confirm ( "A {$updateRequest} request does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:request' , [ 'name' => $ updateRequest ] ) ; } } return [ 'DummyFullStoreRequestClass' => $ storeRequest , 'DummyStoreRequestClass' => class_basename ( $ storeRequest ) , 'DummyFullUpdateRequestClass' => $ updateRequest , 'DummyUpdateRequestClass' => class_basename ( $ updateRequest ) , ] ; } | Build the request replacement values . |
20,934 | protected function buildResourceReplacements ( array $ replace ) { $ name = $ this -> getNameInput ( ) ; $ rootNamespace = trim ( $ this -> laravel -> getNamespace ( ) . 'Http\Resources' . '\\' . $ this -> getNamespace ( $ name ) , '\\' ) ; $ indexResource = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'IndexResource' ; $ showResource = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'ShowResource' ; $ storeResource = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'StoreResource' ; $ updateResource = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'UpdateResource' ; $ deleteResource = $ rootNamespace . '\\' . str_replace ( 'Controller' , '' , class_basename ( $ name ) ) . 'DeleteResource' ; if ( ! class_exists ( $ indexResource ) ) { if ( $ this -> confirm ( "A {$indexResource} resource does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:resource' , [ 'name' => $ indexResource , '--collection' => true ] ) ; } } if ( ! class_exists ( $ showResource ) ) { if ( $ this -> confirm ( "A {$showResource} resource does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:resource' , [ 'name' => $ showResource ] ) ; } } if ( ! class_exists ( $ storeResource ) ) { if ( $ this -> confirm ( "A {$storeResource} resource does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:resource' , [ 'name' => $ storeResource ] ) ; } } if ( ! class_exists ( $ updateResource ) ) { if ( $ this -> confirm ( "A {$updateResource} resource does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:resource' , [ 'name' => $ updateResource ] ) ; } } if ( ! class_exists ( $ deleteResource ) ) { if ( $ this -> confirm ( "A {$deleteResource} resource does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:resource' , [ 'name' => $ deleteResource ] ) ; } } return array_merge ( $ replace , [ 'DummyFullIndexResourceClass' => $ indexResource , 'DummyIndexResourceClass' => class_basename ( $ indexResource ) , 'DummyFullShowResourceClass' => $ showResource , 'DummyShowResourceClass' => class_basename ( $ showResource ) , 'DummyFullStoreResourceClass' => $ storeResource , 'DummyStoreResourceClass' => class_basename ( $ storeResource ) , 'DummyFullUpdateResourceClass' => $ updateResource , 'DummyUpdateResourceClass' => class_basename ( $ updateResource ) , 'DummyFullDeleteResourceClass' => $ deleteResource , 'DummyDeleteResourceClass' => class_basename ( $ deleteResource ) , ] ) ; } | Build the resource replacement values . |
20,935 | protected function buildRepositoryReplacements ( array $ replace ) { $ repository = $ this -> parseRepository ( $ this -> option ( 'repository' ) ) ; if ( empty ( trim ( $ repository , $ this -> laravel -> getNamespace ( ) . 'Repositories\\' ) ) ) { $ repository = $ this -> parseRepository ( $ this -> ask ( 'witch repository do you want to injected to the controller?' ) ) ; } if ( ! class_exists ( $ repository ) ) { if ( $ this -> confirm ( "A {$repository} repository does not exist. Do you want to generate it?" , true ) ) { $ this -> call ( 'make:repository' , [ 'name' => $ repository , '--model' => $ this -> modelClass ] ) ; } } return array_merge ( $ replace , [ 'DummyFullRepositoryClass' => $ repository , 'DummyRepositoryClass' => class_basename ( $ repository ) , 'DummyRepositoryVariable' => lcfirst ( class_basename ( $ repository ) ) , ] ) ; } | Build the repository replacement values . |
20,936 | protected function parseRepository ( $ repository ) { if ( preg_match ( '([^A-Za-z0-9_/\\\\])' , $ repository ) ) { throw new InvalidArgumentException ( 'Repository name contains invalid characters.' ) ; } $ repository = trim ( str_replace ( '/' , '\\' , $ repository ) , '\\' ) ; if ( ! Str :: startsWith ( $ repository , $ rootNamespace = $ this -> laravel -> getNamespace ( ) ) ) { $ repository = $ rootNamespace . 'Repositories' . '\\' . $ repository ; } return $ repository ; } | Get the fully - qualified repository class name . |
20,937 | protected function getViewModuleFiles ( $ view ) { $ rootPath = resource_path ( 'views/' . str_replace ( '.' , '/' , $ view ) ) ; return [ $ rootPath . '/index' , $ rootPath . '/show' , $ rootPath . '/create' , $ rootPath . '/edit' ] ; } | Get the view files . |
20,938 | public function convertTitle ( ) { if ( $ this -> title === null ) { return '' ; } foreach ( $ this -> splitWords ( ) as $ index => $ word ) { if ( $ this -> wordShouldBeUppercase ( $ index , $ word ) ) { $ this -> rebuildTitle ( $ index , $ this -> uppercaseWord ( $ word ) ) ; } } return $ this -> title ; } | Converts the initial title to a correctly formatted one |
20,939 | protected function setTitle ( $ title ) { $ title = trim ( preg_replace ( '/\s\s+/' , ' ' , str_replace ( "\n" , " " , $ title ) ) ) ; if ( $ title != '' ) { $ this -> title = $ title ; } } | Sets the title after cleaning up extra spaces |
20,940 | protected function splitWords ( ) { $ indexedWords = [ ] ; $ offset = 0 ; $ words = explode ( $ this -> separator , $ this -> title ) ; foreach ( $ words as $ word ) { if ( mb_strlen ( $ word , $ this -> encoding ) == 0 ) { continue ; } $ wordIndex = $ this -> getWordIndex ( $ word , $ offset ) ; if ( $ this -> hasDash ( $ word ) ) { $ word = TextFormatter :: titleCase ( $ word , '-' ) ; $ this -> rebuildTitle ( $ wordIndex , $ word ) ; } $ indexedWords [ $ wordIndex ] = $ word ; $ offset += mb_strlen ( $ word , $ this -> encoding ) + 1 ; } return $ this -> indexedWords = $ indexedWords ; } | Creates an array of words from the title to be formatted |
20,941 | protected function getWordIndex ( $ word , $ offset ) { $ index = mb_strpos ( $ this -> title , $ word , $ offset , $ this -> encoding ) ; return $ this -> correctIndexOffset ( $ index ) ; } | Finds the correct index of the word within the title |
20,942 | protected function correctIndexOffset ( $ index ) { return mb_strlen ( mb_substr ( $ this -> title , 0 , $ index , $ this -> encoding ) , $ this -> encoding ) ; } | Corrects the potential offset issue with some UTF - 8 characters |
20,943 | protected function rebuildTitle ( $ index , $ word ) { $ this -> title = mb_substr ( $ this -> title , 0 , $ index , $ this -> encoding ) . $ word . mb_substr ( $ this -> title , $ index + mb_strlen ( $ word , $ this -> encoding ) , mb_strlen ( $ this -> title , $ this -> encoding ) , $ this -> encoding ) ; } | Replaces a formatted word within the current title |
20,944 | protected function uppercaseWord ( $ word ) { $ prefix = '' ; $ hasPunctuation = true ; do { $ first = mb_substr ( $ word , 0 , 1 , $ this -> encoding ) ; if ( $ this -> isPunctuation ( $ first ) ) { $ prefix .= $ first ; $ word = mb_substr ( $ word , 1 , - 1 , $ this -> encoding ) ; } else { $ hasPunctuation = false ; } } while ( $ hasPunctuation === true ) ; return $ prefix . ucwords ( $ word ) ; } | Performs the uppercase action on the given word |
20,945 | protected function wordShouldBeUppercase ( $ index , $ word ) { return ( $ this -> isFirstWordOfSentence ( $ index ) || $ this -> isLastWord ( $ word ) || ! $ this -> isIgnoredWord ( $ word ) ) && ( ! $ this -> hasUppercaseLetter ( $ word ) ) ; } | Condition to see if the given word should be uppercase |
20,946 | protected function isFirstWordOfSentence ( $ index ) { if ( $ index == 0 ) { return true ; } $ twoCharactersBack = mb_substr ( $ this -> title , $ index - 2 , 1 , $ this -> encoding ) ; if ( $ this -> isPunctuation ( $ twoCharactersBack ) ) { return true ; } return false ; } | Checks to see if the word the start of a new sentence |
20,947 | protected function hasDash ( $ word ) { $ wordWithoutDashes = str_replace ( '-' , '' , $ word ) ; return preg_match ( "/\-/" , $ word ) && mb_strlen ( $ wordWithoutDashes , $ this -> encoding ) > 1 ; } | Checks to see if the word has a dash |
20,948 | public function getLinks ( ) : Array { if ( ! $ this -> isJsonCheck ( ) || $ this -> refresh === true ) { $ result = $ this -> getApiResult ( ) ; if ( ! is_object ( $ result ) ) { throw new Exception \ BadRequestURLException ( $ this -> address ) ; } $ this -> putJsonContent ( $ result ) ; } $ result = $ this -> decodeArrrayJsonContent ( ) ; return $ this -> convertArrayByKeyValues ( $ result ) ; } | Gets links . |
20,949 | public function getUserMenu ( ) { $ event = new BuildUserMenuEvent ( ) ; $ this -> trigger ( self :: EVENT_BUILD_USER_MENU , $ event ) ; $ menu = [ ] ; foreach ( $ event -> items as $ block => $ items ) { foreach ( $ items as $ item ) { $ menu [ ] = $ item ; } } return $ menu ; } | Collecting side menu over modules |
20,950 | public static function open ( $ key , $ private = false , $ secure = false ) { if ( ! isset ( self :: $ privates [ $ key ] ) && ( $ private === true ) ) { self :: $ privates [ $ key ] = new Container ; self :: $ privates [ $ key ] -> name = $ key ; self :: $ privates [ $ key ] -> secure = false ; if ( $ secure ) { self :: $ privates [ $ key ] -> secure = true ; } return self :: $ privates [ $ key ] ; } if ( ! isset ( self :: $ instance [ $ key ] ) && ( $ private === false ) ) { self :: $ instance [ $ key ] = new Container ; self :: $ instance [ $ key ] -> name = $ key ; self :: $ instance [ $ key ] -> secure = false ; if ( $ secure ) { self :: $ instance [ $ key ] -> secure = true ; } return self :: $ instance [ $ key ] ; } else if ( $ private === false ) { return self :: $ instance [ $ key ] ; } throw new Exception ( "Container instance cannot be opened!" ) ; } | Method is used to open specific instance of container . |
20,951 | public function getLabel ( BuildInterface $ build ) { $ buildNo = $ build -> getNumber ( ) ; if ( $ buildNo == null ) { $ buildNo = $ this -> _firstBuild ; } $ buildLabel = $ this -> _prefix . $ buildNo ; $ build -> setProperty ( 'build.label' , $ buildLabel ) ; return $ buildLabel ; } | Return the label for this build . |
20,952 | public static function prepareContainer ( Container $ container ) { if ( ! isset ( $ container [ 'config' ] ) ) { $ container [ 'config' ] = [ ] ; } if ( ! isset ( $ container [ 'files' ] ) ) { $ container [ 'files' ] = new Filesystem ( ) ; } if ( ! isset ( $ container [ 'providers' ] ) ) { $ container [ 'providers' ] = [ ] ; } $ providers = $ container [ 'providers' ] ; $ providers [ ] = 'Consolet\DefaultCommandsProvider' ; $ container [ 'providers' ] = $ providers ; return $ container ; } | prepare default dependencies |
20,953 | public function init ( $ parameters ) { if ( ! empty ( $ parameters [ "app_root" ] ) ) { $ this -> app_root = $ parameters [ "app_root" ] ; } if ( empty ( $ parameters [ "log_path" ] ) ) { throw new \ Exception ( "Log path is not specified!" ) ; } $ this -> log_path = $ parameters [ "log_path" ] ; $ file = $ this -> log_path . "trace.log" ; if ( ! file_exists ( $ this -> log_path ) || ! is_writable ( $ this -> log_path ) || ( file_exists ( $ file ) && ! is_writable ( $ file ) ) ) { throw new \ Exception ( sprintf ( "The trace file '%s' is not writable!" , $ file ) ) ; } return true ; } | Initializes the error handler with parameters . |
20,954 | public function handleError ( $ errno , $ errstr , $ errfile , $ errline ) { $ this -> setLastError ( $ errstr ) ; $ errortype = [ E_ERROR => "Error" , E_WARNING => "Warning" , E_PARSE => "Parsing Error" , E_NOTICE => "Notice" , E_CORE_ERROR => "Core Error" , E_CORE_WARNING => "Core Warning" , E_COMPILE_ERROR => "Compile Error" , E_COMPILE_WARNING => "Compile Warning" , E_USER_ERROR => "User Error" , E_USER_WARNING => "User Warning" , E_USER_NOTICE => "User Notice" , E_STRICT => "Runtime Notice" , E_DEPRECATED => "Deprecated Notice" ] ; if ( empty ( $ errortype [ $ errno ] ) ) { $ etype = $ errno ; } else { $ etype = $ errortype [ $ errno ] ; } $ this -> trace_message ( $ this -> format_backtrace ( debug_backtrace ( ) ) ) ; event ( ) -> fireEvent ( "php_error" , [ "etype" => $ etype , "errstr" => $ errstr , "errfile" => $ errfile , "errline" => $ errline ] ) ; } | This is the function for handling of the PHP errors . It is set a the error handler . |
20,955 | public function replace ( $ handler , $ bindTo = true ) { if ( $ bindTo && $ handler instanceof Closure ) { $ handler = $ handler -> bindTo ( $ this , $ this ) ; } $ this -> handler = $ handler ; } | Replace class handle method . |
20,956 | public function reorder ( Menu $ menu , $ field = 'position' ) { $ roots = $ this -> menuItemRepository -> getRootNodes ( ) ; $ rootItem = null ; foreach ( $ roots as $ root ) { if ( $ root -> getMenu ( ) == $ menu ) { $ rootItem = $ root ; } } if ( $ rootItem ) { $ this -> menuItemRepository -> reorder ( $ rootItem , $ field ) ; return true ; } return false ; } | Reorder Menu tree . |
20,957 | public static function Ab ( array $ pnat , array $ v , $ s , $ bm1 , array & $ ppr ) { $ i ; $ pdv ; $ w1 ; $ w2 ; $ r2 ; $ w ; $ p = [ ] ; $ r ; $ pdv = static :: Pdp ( $ pnat , $ v ) ; $ w1 = 1.0 + $ pdv / ( 1.0 + $ bm1 ) ; $ w2 = SRS / $ s ; $ r2 = 0.0 ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ w = $ pnat [ $ i ] * $ bm1 + $ w1 * $ v [ $ i ] + $ w2 * ( $ v [ $ i ] - $ pdv * $ pnat [ $ i ] ) ; $ p [ $ i ] = $ w ; $ r2 = $ r2 + $ w * $ w ; } $ r = sqrt ( $ r2 ) ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ ppr [ $ i ] = $ p [ $ i ] / $ r ; } } | - - - - - - i a u A b - - - - - - |
20,958 | private function registerFirewallSecurity ( array $ firewall = [ ] ) { if ( true === $ firewall [ 'status' ] ) { if ( isset ( $ firewall [ 'ip_firewall' ] ) ) { $ this -> registerIpFirewall ( $ firewall [ 'ip_firewall' ] ) ; } if ( isset ( $ firewall [ 'full_firewall' ] ) ) { $ this -> registerFullFirewall ( $ firewall [ 'full_firewall' ] ) ; } } } | register the firewall |
20,959 | private function prepareCsrfInstance ( array $ configs = [ ] ) { $ configs = Config :: get ( 'security.csrf' ) ; $ field = $ configs [ 'field_name' ] ; $ this -> singleton ( 'security.csrf' , function ( ) use ( $ field ) { return ( new CsrfToken ( ) ) -> setFormFieldName ( $ field ) ; } ) ; } | register the csrf token |
20,960 | protected function getModel ( $ id ) { return isset ( $ this -> models [ $ id ] ) ? $ this -> models [ $ id ] : null ; } | Return model . |
20,961 | public function create ( array $ config = [ ] , array $ data = [ ] ) { $ here = $ this -> _View -> request -> here ( ) ; $ menu = new MenuGroup ( $ config , $ here ) ; return $ menu -> render ( $ data ) ; } | Creates the menu |
20,962 | public function getMatchingCookies ( $ uri , $ matchSessionCookies = true , $ ret_as = self :: COOKIE_OBJECT , $ now = null ) { if ( is_string ( $ uri ) ) $ uri = Zend_Uri :: factory ( $ uri ) ; if ( ! $ uri instanceof Zend_Uri_Http ) { throw new Zend_Http_Exception ( "Invalid URI string or object passed" ) ; } $ cookies = $ this -> _matchDomain ( $ uri -> getHost ( ) ) ; $ cookies = $ this -> _matchPath ( $ cookies , $ uri -> getPath ( ) ) ; $ cookies = $ this -> _flattenCookiesArray ( $ cookies , self :: COOKIE_OBJECT ) ; $ ret = array ( ) ; foreach ( $ cookies as $ cookie ) if ( $ cookie -> match ( $ uri , $ matchSessionCookies , $ now ) ) $ ret [ ] = $ cookie ; $ ret = $ this -> _flattenCookiesArray ( $ ret , $ ret_as ) ; if ( $ ret_as == self :: COOKIE_STRING_CONCAT_STRICT ) { $ ret = rtrim ( trim ( $ ret ) , ';' ) ; } return $ ret ; } | Return an array of all cookies matching a specific request according to the request URI whether session cookies should be sent or not and the time to consider as now when checking cookie expiry time . |
20,963 | public function getCookie ( $ uri , $ cookie_name , $ ret_as = self :: COOKIE_OBJECT ) { if ( is_string ( $ uri ) ) { $ uri = Zend_Uri :: factory ( $ uri ) ; } if ( ! $ uri instanceof Zend_Uri_Http ) { throw new Zend_Http_Exception ( 'Invalid URI specified' ) ; } $ path = $ uri -> getPath ( ) ; $ path = substr ( $ path , 0 , strrpos ( $ path , '/' ) ) ; if ( ! $ path ) $ path = '/' ; if ( isset ( $ this -> cookies [ $ uri -> getHost ( ) ] [ $ path ] [ $ cookie_name ] ) ) { $ cookie = $ this -> cookies [ $ uri -> getHost ( ) ] [ $ path ] [ $ cookie_name ] ; switch ( $ ret_as ) { case self :: COOKIE_OBJECT : return $ cookie ; break ; case self :: COOKIE_STRING_CONCAT_STRICT : return rtrim ( trim ( $ cookie -> __toString ( ) ) , ';' ) ; break ; case self :: COOKIE_STRING_ARRAY : case self :: COOKIE_STRING_CONCAT : return $ cookie -> __toString ( ) ; break ; default : throw new Zend_Http_Exception ( "Invalid value passed for \$ret_as: {$ret_as}" ) ; break ; } } else { return false ; } } | Get a specific cookie according to a URI and name |
20,964 | protected function createImageObject ( ) { if ( ! is_file ( $ this -> originalImagePath ) ) { throw new Exception ( sprintf ( '%s: No image found.' , $ this -> originalImagePath ) ) ; } $ this -> imageType = exif_imagetype ( $ this -> originalImagePath ) ; list ( $ this -> width , $ this -> height ) = getimagesize ( $ this -> originalImagePath ) ; switch ( $ this -> imageType ) { case IMAGETYPE_GIF : $ this -> image = imagecreatefromgif ( $ this -> originalImagePath ) ; break ; case IMAGETYPE_PNG : $ this -> image = @ imagecreatefrompng ( $ this -> originalImagePath ) ; break ; case IMAGETYPE_JPEG : $ this -> image = @ imagecreatefromjpeg ( $ this -> originalImagePath ) ; break ; case IMAGETYPE_BMP : $ this -> image = imagecreatefromwbmp ( $ this -> originalImagePath ) ; break ; default : throw new Exception ( sprintf ( 'This MimeType is not supported: %s. Image processed: %s' , image_type_to_mime_type ( $ this -> imageType ) , $ this -> originalImagePath ) ) ; break ; } if ( ! $ this -> image ) { throw new Exception ( sprintf ( 'We could not open this image: %s' , $ this -> originalImagePath ) ) ; } } | Create GD Image object based on the mime_type |
20,965 | public function save ( $ path ) { switch ( $ this -> imageType ) { case IMAGETYPE_GIF : $ returnData = imagegif ( $ this -> image , $ path ) ; break ; case IMAGETYPE_PNG : $ returnData = imagepng ( $ this -> image , $ path ) ; break ; case IMAGETYPE_JPEG : $ returnData = imagejpeg ( $ this -> image , $ path ) ; break ; case IMAGETYPE_BMP : $ returnData = imagewbmp ( $ this -> image , $ path ) ; break ; default : throw new Exception ( sprintf ( 'This MimeType is not supported: %s. Image processed: %s' , image_type_to_mime_type ( $ this -> imageType ) , $ this -> originalImagePath ) ) ; break ; } return $ this ; } | Save the working image to the new path |
20,966 | public function cropToFit ( $ width , $ height , $ focusPointX = 0 , $ focusPointY = 0 ) { $ debug = $ width == 100 && $ height == 100 ; if ( ! is_resource ( $ this -> image ) ) { throw new RuntimeException ( 'No image set' ) ; } $ originalWidth = imagesx ( $ this -> image ) ; $ originalHeight = imagesy ( $ this -> image ) ; $ width = $ width ? : $ originalWidth ; $ height = $ height ? : $ originalHeight ; $ originalAspectRatio = $ originalWidth / $ originalHeight ; $ desiredAspectRatio = $ width / $ height ; if ( $ originalAspectRatio > $ desiredAspectRatio ) { $ temp_height = $ height ; $ temp_width = ( int ) ( $ height * $ originalAspectRatio ) ; } else { $ temp_width = $ width ; $ temp_height = ( int ) ( $ width / $ originalAspectRatio ) ; } $ x0 = ( $ temp_width - $ width ) * ( ( $ focusPointX + 1 ) * .5 ) ; $ y0 = ( $ temp_height - $ height ) * ( ( $ focusPointY + 1 ) * .5 ) ; if ( ! ctype_digit ( $ x0 ) || ! ctype_digit ( $ y0 ) ) { $ temp_width ++ ; $ temp_height ++ ; } $ this -> resize ( $ temp_width , $ temp_height ) ; $ canvas = $ this -> createCanvas ( $ width , $ height ) ; imagecopy ( $ canvas , $ this -> image , 0 , 0 , $ x0 , $ y0 , $ width , $ height ) ; $ this -> replace ( $ canvas ) ; return $ this ; } | Crop image To the width and height of the image |
20,967 | public function resize ( $ width = null , $ height = null ) { $ sourceWidth = imagesx ( $ this -> image ) ; $ sourceHeight = imagesy ( $ this -> image ) ; $ sourceAspectRatio = $ sourceWidth / $ sourceHeight ; if ( ! $ width && ! $ height ) { $ width = $ sourceWidth ; $ height = $ sourceHeight ; } else if ( ! $ width ) { $ width = $ height * $ sourceAspectRatio ; } else { $ height = $ width / $ sourceAspectRatio ; } $ maxCanvasWidth = $ width ; $ maxCanvasHeight = $ height ; $ thumbnailAspectRatio = $ maxCanvasWidth / $ maxCanvasHeight ; $ canvas = $ this -> createCanvas ( $ width , $ height ) ; imagecopyresampled ( $ canvas , $ this -> image , 0 , 0 , 0 , 0 , $ width , $ height , $ sourceWidth , $ sourceHeight ) ; $ this -> replace ( $ canvas ) ; return $ this ; } | Resize the GD Image |
20,968 | protected function createCanvas ( $ width , $ height ) { $ canvas = imagecreatetruecolor ( $ width , $ height ) ; if ( $ this -> imageType == IMAGETYPE_GIF || $ this -> imageType == IMAGETYPE_PNG ) { imagealphablending ( $ canvas , false ) ; imagesavealpha ( $ canvas , true ) ; } return $ canvas ; } | Create a new canvas element |
20,969 | public function replace ( $ res ) { if ( ! is_resource ( $ res ) ) { throw new UnexpectedValueException ( 'Invalid resource' ) ; } if ( is_resource ( $ this -> image ) ) { imagedestroy ( $ this -> image ) ; } $ this -> image = $ res ; return $ this ; } | Replaces the image with the new image |
20,970 | public static function getOldInput ( $ model , $ property ) { if ( \ Session :: getOldInput ( $ property ) !== null ) { return \ Session :: getOldInput ( $ property ) ; } return $ model -> $ property ; } | Get old input when validate has errors |
20,971 | public static function transparentImage ( int $ width , int $ height ) : Image { $ image = imagecreatetruecolor ( max ( $ width , 1 ) , max ( $ height , 1 ) ) ; $ transparent = imagecolorallocatealpha ( $ image , 0 , 0 , 0 , 127 ) ; imagefill ( $ image , 0 , 0 , $ transparent ) ; imagesavealpha ( $ image , true ) ; return new Image ( $ image ) ; } | Creates empty transparent GD image |
20,972 | public static function sortSymbols ( $ a , $ b ) { $ i1 = $ a -> index + 10000000 * ( ord ( $ a -> name [ 0 ] ) > ord ( 'Z' ) ) ; $ i2 = $ b -> index + 10000000 * ( ord ( $ b -> name [ 0 ] ) > ord ( 'Z' ) ) ; return $ i1 - $ i2 ; } | Sort function helper for symbols |
20,973 | public static function same_symbol ( PHP_ParserGenerator_Symbol $ a , PHP_ParserGenerator_Symbol $ b ) { if ( $ a === $ b ) return 1 ; if ( $ a -> type != self :: MULTITERMINAL ) return 0 ; if ( $ b -> type != self :: MULTITERMINAL ) return 0 ; if ( $ a -> nsubsym != $ b -> nsubsym ) return 0 ; for ( $ i = 0 ; $ i < $ a -> nsubsym ; $ i ++ ) { if ( $ a -> subsym [ $ i ] != $ b -> subsym [ $ i ] ) return 0 ; } return 1 ; } | Return true if two symbols are the same . |
20,974 | public function getEditForm ( $ id = null , $ fields = null ) { $ form = parent :: getEditForm ( $ id , $ fields ) ; Requirements :: css ( KAPOST_DIR . '/css/KapostAdmin.css' ) ; Requirements :: javascript ( KAPOST_DIR . '/javascript/KapostAdmin.js' ) ; if ( $ this -> modelClass == 'KapostObject' && $ gridField = $ form -> Fields ( ) -> dataFieldByName ( 'KapostObject' ) ) { $ gridField -> setList ( $ gridField -> getList ( ) -> filter ( 'IsKapostPreview' , 0 ) ) ; $ gridField -> getConfig ( ) -> addComponent ( new KapostGridFieldRefreshButton ( 'before' ) ) -> removeComponentsByType ( 'GridFieldAddNewButton' ) -> getComponentByType ( 'GridFieldDataColumns' ) -> setFieldCasting ( array ( 'Created' => 'SS_Datetime->FormatFromSettings' , 'KapostChangeType' => 'KapostFieldCaster->NiceChangeType' , 'ToPublish' => 'KapostFieldCaster->NiceToPublish' ) ) ; $ gridField -> getConfig ( ) -> getComponentByType ( 'GridFieldDetailForm' ) -> setItemRequestClass ( 'KapostGridFieldDetailForm_ItemRequest' ) ; } else if ( $ this -> modelClass == 'KapostConversionHistory' && $ gridField = $ form -> Fields ( ) -> dataFieldByName ( 'KapostConversionHistory' ) ) { $ gridField -> getConfig ( ) -> removeComponentsByType ( 'GridFieldAddNewButton' ) -> addComponent ( new KapostDestinationAction ( ) , 'GridFieldEditButton' ) ; $ dataColumns = $ gridField -> getConfig ( ) -> getComponentByType ( 'GridFieldDataColumns' ) ; $ dataColumns -> setFieldCasting ( array ( 'Created' => 'SS_Datetime->FormatFromSettings' ) ) ; $ columns = $ dataColumns -> getDisplayFields ( $ gridField ) ; $ columns [ 'DestinationTypeNice' ] = _t ( 'KapostConversionHistory.db_DestinationType' , '_Destination Type' ) ; $ columns [ 'KapostChangeTypeNice' ] = _t ( 'KapostConversionHistory.db_KapostChangeType' , '_Change Type' ) ; $ columns = $ dataColumns -> setDisplayFields ( $ columns ) ; $ gridField -> getConfig ( ) -> getComponentByType ( 'GridFieldDetailForm' ) -> setItemEditFormCallback ( function ( Form $ form ) { $ form -> addExtraClass ( 'KapostAdmin' ) ; } ) ; } $ form -> addExtraClass ( 'KapostAdmin' ) ; return $ form ; } | Form used for displaying the gridfield in the model admin |
20,975 | public function getList ( ) { $ context = $ this -> getSearchContext ( ) ; $ params = $ this -> getRequest ( ) -> requestVar ( 'q' ) ; if ( is_array ( $ params ) ) { if ( array_key_exists ( 'Created' , $ params ) && is_array ( $ params [ 'Created' ] ) ) { $ params [ 'Created' ] = implode ( ' ' , $ params [ 'Created' ] ) ; } $ params = array_map ( 'trim' , $ params ) ; } $ list = $ context -> getResults ( $ params ) ; $ this -> extend ( 'updateList' , $ list ) ; return $ list ; } | Gets the list used in the ModelAdmin |
20,976 | public function filter ( array $ data ) : array { $ result = [ ] ; foreach ( $ data as $ item ) { $ key = implode ( '|' , $ item -> getKeys ( ) ) ; if ( ! isset ( $ result [ $ key ] ) || $ result [ $ key ] -> getOrder ( ) < $ item -> getOrder ( ) ) { $ result [ $ key ] = $ item ; } } return array_values ( $ result ) ; } | Filters the data to only contain the items with the highest order . |
20,977 | public static function classUses ( $ class , string $ find ) : bool { $ uses = class_uses ( $ class ) ; if ( in_array ( $ find , $ uses ) ) { return true ; } $ uses = array_merge ( $ uses , class_parents ( $ class ) ) ; foreach ( $ uses as $ use ) { if ( static :: classUses ( $ use , $ find ) ) { return true ; } } return false ; } | Check to see if the class uses the provided item |
20,978 | public function whatIs ( $ pattern ) { if ( ! $ this -> adapter -> isAbsolute ( $ pattern ) ) { $ pattern = $ this -> rootPath . $ pattern ; } $ paths = $ this -> adapter -> glob ( $ pattern ) ; if ( count ( $ paths ) == 0 ) return 'nothing' ; if ( count ( $ paths ) == 1 ) return ( $ this -> adapter -> isFile ( $ paths [ 0 ] ) ) ? 'file' : 'dir' ; return 'collection' ; } | Tells what is the given pattern matching returns file or dir if a single file or directory matches the pattern . Returns collection if there are multiple matches and nothing if no match found . |
20,979 | protected function is ( $ path , $ type ) { if ( ! $ this -> adapter -> isAbsolute ( $ path ) ) { $ path = $ this -> rootPath . $ path ; } switch ( $ type ) { case 'readable' : return $ this -> adapter -> isReadable ( $ path ) ; case 'writable' : return $ this -> adapter -> isWritable ( $ path ) ; case 'executable' : return $ this -> adapter -> isExecutable ( $ path ) ; case 'file' : return $ this -> adapter -> isFile ( $ path ) ; case 'dir' : return $ this -> adapter -> isDir ( $ path ) ; case 'any' : return $ this -> adapter -> fileExists ( $ path ) ; default : throw new FilesystemException ( "Unknown file type '{$type}'" ) ; } } | Checks if the given path is of the given type . |
20,980 | protected function are ( $ paths , $ type ) { foreach ( $ paths as $ path ) { if ( ! $ this -> is ( $ path , $ type ) ) { return false ; } } return ( count ( $ paths ) == 0 ) ? false : true ; } | Checks if the given paths are all of the given type . |
20,981 | public function file ( $ path , $ createMissing = false ) { if ( ! $ this -> adapter -> isAbsolute ( $ path ) ) { $ path = $ this -> rootPath . $ path ; } if ( ! $ createMissing && ! $ this -> isFile ( $ path , true ) ) { throw new FilesystemException ( "Cannot find the file '{$path}'" ) ; } return new File ( $ path , $ this -> adapter ) ; } | Gets a file by relative or absolute path optionally creates the file if missing . |
20,982 | public function files ( $ paths = false , $ createMissing = false ) { if ( $ paths === false ) { return $ this -> find ( '*' ) -> files ( ) ; } $ list = new Collection ; foreach ( $ paths as $ path ) { $ list -> add ( $ this -> file ( $ path , $ createMissing ) ) ; } return $ list ; } | Gets files by relative or absolute path optionally creates missing files . |
20,983 | public function dir ( $ path , $ createMissing = false ) { if ( ! $ this -> adapter -> isAbsolute ( $ path ) ) { $ path = $ this -> rootPath . $ path ; } if ( ! $ createMissing && ! $ this -> isDir ( $ path , true ) ) { throw new FilesystemException ( "Cannot find the directory '{$path}'" ) ; } return new Directory ( $ path , $ this -> adapter ) ; } | Gets a directory by relative or absolute path optionally creates the directory if missing . |
20,984 | public function dirs ( $ paths = false , $ createMissing = false ) { if ( $ paths === false ) { return $ this -> find ( '*' ) -> dirs ( ) ; } $ list = new Collection ; foreach ( $ paths as $ path ) { $ list -> add ( $ this -> dir ( $ path , $ createMissing ) ) ; } return $ list ; } | Gets directories by relative or absolute path optionally creates missing directories . |
20,985 | public function find ( $ pattern ) { if ( ! $ this -> adapter -> isAbsolute ( $ pattern ) ) { $ pattern = $ this -> rootPath . $ pattern ; } $ list = new Collection ; foreach ( $ this -> adapter -> glob ( $ pattern ) as $ path ) { if ( $ this -> isFile ( $ path , true ) ) { $ list -> add ( new File ( $ path , $ this -> adapter ) ) ; } else { $ list -> add ( new Directory ( $ path , $ this -> adapter ) ) ; } } return $ list ; } | Finds files and directories matching the given pattern and returns a collection containing them . |
20,986 | public function remove ( $ path ) { if ( ! $ this -> adapter -> isAbsolute ( $ path ) ) { $ path = $ this -> rootPath . $ path ; } if ( $ this -> isFile ( $ path , true ) ) { $ this -> adapter -> unlink ( $ path ) ; } else { $ path = rtrim ( $ path , '/' ) . '/' ; foreach ( $ this -> adapter -> glob ( $ path . '*' ) as $ itemPath ) { $ this -> remove ( $ itemPath , true ) ; } $ this -> adapter -> rmdir ( $ path ) ; } return $ this ; } | Removes a file or directory recursively . |
20,987 | public function set ( $ id , $ item , $ tagArg = null ) { if ( ! is_callable ( $ item ) ) $ this -> instances [ $ id ] = $ item ; else { $ this -> callables [ $ id ] = $ item ; unset ( $ this -> instances [ $ id ] ) ; } if ( ! $ tagArg ) return $ this ; $ tag = is_array ( $ tagArg ) ? $ tagArg : [ 'name' => $ tagArg ] ; $ tag [ 'service_id' ] = $ id ; $ name = $ tag [ 'name' ] ; $ this -> tags [ $ name ] [ ] = $ tag ; return $ this ; } | Add a service with optional tagging |
20,988 | public function getTags ( $ name = null ) { if ( ! $ name ) return $ this -> tags ; return isset ( $ this -> tags [ $ name ] ) ? $ this -> tags [ $ name ] : [ ] ; } | List of services for a given tag |
20,989 | public static function assertIsDir ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_dir ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is a directory path . |
20,990 | public static function assertIsFile ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_file ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is a file path . |
20,991 | public static function assertIsLink ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_link ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is a link path . |
20,992 | public static function assertIsReadable ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_readable ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is readable . |
20,993 | public static function assertIsWritable ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_writable ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is writable . |
20,994 | public static function assertIsExecutable ( string $ path , Throwable $ exception ) : string { static :: makeAssertion ( \ is_executable ( $ path ) , $ exception ) ; return $ path ; } | Asserts that the given path is executable . |
20,995 | public function execute ( ) { $ this -> initialiseHandle ( ) ; $ this -> applyOptionsToHandle ( ) ; $ content = curl_exec ( $ this -> handle ) ; $ this -> info = $ this -> getInfoFromHandle ( ) ; $ this -> errorCode = $ this -> getErrorCodeFromHandle ( ) ; $ this -> errorMessage = $ this -> getErrorMessageFromHandle ( ) ; $ this -> closeHandle ( ) ; return $ content ; } | Execute the request and return the content . |
20,996 | public function getErrorCodeFromHandle ( ) { $ errorNumber = null ; if ( $ this -> handle !== null ) { $ errorNumber = curl_errno ( $ this -> handle ) ; } return $ errorNumber === 0 ? null : $ errorNumber ; } | Get the last error code that occurred or null if there were no problems . |
20,997 | public function getErrorMessageFromHandle ( ) { $ errorMessage = null ; if ( $ this -> handle !== null ) { $ errorMessage = curl_errno ( $ this -> handle ) ; } return $ errorMessage === '' ? null : $ errorMessage ; } | Get the message for the last error that occurred or null if there were no problems . |
20,998 | public function importIssueFiles ( $ issue , $ oldId , $ slug ) { $ issueFilesSql = "SELECT * FROM issue_files WHERE issue_id = :id" ; $ issueFilesStatement = $ this -> dbalConnection -> prepare ( $ issueFilesSql ) ; $ issueFilesStatement -> bindValue ( 'id' , $ oldId ) ; $ issueFilesStatement -> execute ( ) ; $ issueFiles = $ issueFilesStatement -> fetchAll ( ) ; foreach ( $ issueFiles as $ issueFile ) { $ this -> importIssueFile ( $ issueFile [ 'file_id' ] , $ oldId , $ issue , $ slug ) ; } } | Imports files of given issue |
20,999 | public function Model ( ) { $ file = $ this -> getAddressModel ( ) ; if ( file_exists ( $ file ) ) { $ model = $ this -> getClassModel ( ) ; $ this -> model = new $ model ( ) ; } } | Carrega a model |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.