idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
17,400
protected function processFormData ( WebRequest $ request , Response $ response , User $ user ) { $ result = $ this -> layout -> validateFormData ( $ request , $ response , function ( $ formValues ) use ( $ user ) { return $ this -> validateData ( $ user , $ formValues [ 'required-data.username' ] , $ formValues [ 'required-data.password' ] , $ formValues [ 'required-data.password-confirmed' ] ) ; } ) ; if ( $ result == Form :: DATA_VALID ) { $ result = $ this -> saveUser ( $ request , $ user ) ; } return $ result ; }
Validates the form data updates the user and saves the user into the database .
17,401
protected function isUsernameInUse ( $ username , User $ user ) { return ( $ this -> userManager -> hasUserForUsername ( $ username ) && $ this -> userManager -> getUserForUsername ( $ username ) -> getUuid ( ) != $ user -> getUuid ( ) ) ; }
Returns true if the username is in use and not is the edited user .
17,402
public function render ( $ view , $ data = [ ] ) { $ this -> writeFile ( $ view ) ; $ blade = new Blade ( $ this -> getViewPath ( ) , $ this -> getCachePath ( ) ) ; if ( is_array ( $ data ) ) { return $ blade -> view ( ) -> make ( $ view , $ data ) -> render ( ) ; } else { throw new Exception ( 'data pass into view must be an array.' ) ; } }
return blade template
17,403
public function writeFile ( $ path ) { $ fullPath = $ this -> viewDir . DIRECTORY_SEPARATOR . $ this -> transformDotToSlash ( $ path ) . '.blade.php' ; if ( ! FacadeStorage :: has ( $ fullPath ) ) { FacadeStorage :: createDir ( dirname ( $ fullPath ) ) ; return FacadeStorage :: write ( $ fullPath , '' ) ; } return false ; }
create blade file
17,404
public function createCacheDir ( ) { if ( ! FacadeStorage :: has ( $ this -> cacheDir ) ) { return FacadeStorage :: createDir ( $ this -> cacheDir ) ; } return false ; }
create cache folder
17,405
public function create ( Strategy $ strategy ) { $ this -> getEm ( ) -> persist ( $ strategy ) ; $ this -> getEm ( ) -> flush ( ) ; return $ strategy ; }
Create a new Strategy .
17,406
public static function getInstance ( array $ scope = [ ] , $ options = self :: ACTION_ALL ) { if ( ! is_object ( self :: $ instance ) ) { self :: $ instance = new static ( $ scope , $ options ) ; } return self :: $ instance ; }
Returns static registry instance .
17,407
public function override ( array $ scope ) { $ this -> checkPermissions ( null , self :: ACTION_OVERRIDE ) ; $ this -> scope = $ scope ; }
Overrides scope .
17,408
protected function checkPermissions ( $ key , $ action ) { if ( ! ( $ action & $ this -> options ) ) { $ originalKey = is_null ( $ this -> key ) ? $ key : $ this -> key ; $ this -> key = null ; $ text = Friendlification :: getConstNameByValue ( __CLASS__ , $ action ) ; throw new RuntimeException ( is_null ( $ key ) ? sprintf ( "%s: no permissions" , $ text ) : sprintf ( "%s: no permissions for key '%s'" , $ text , $ originalKey ) , $ action ) ; } }
Check action permissions .
17,409
protected function getByRef ( $ key , & $ value ) { if ( ! $ this -> checkRefs || ! is_string ( $ value ) ) { return ; } $ this -> checkRefs = false ; $ references = [ $ key ] ; $ key = $ value ; while ( $ this -> isRef ( $ key ) ) { if ( in_array ( $ key , $ references ) ) { $ this -> checkRefs = true ; $ this -> key = null ; $ references [ ] = $ key ; throw new RuntimeException ( sprintf ( "Cyclic reference detected: %s" , implode ( " ~~> " , $ references ) ) ) ; } $ references [ ] = $ key ; $ previous = $ key ; $ key = $ this -> get ( $ key , null , false ) ; } ; $ this -> checkRefs = true ; if ( isset ( $ previous ) ) { if ( $ this -> exists ( $ previous ) ) { $ value = $ key ; } else { $ this -> key = null ; $ references [ sizeof ( $ references ) - 1 ] .= " (missing key)" ; throw new RuntimeException ( sprintf ( "Invalid reference detected: %s" , implode ( " ~~> " , $ references ) ) ) ; } } }
Gets value by reference if possible .
17,410
protected function isRef ( & $ value , $ modify = true ) { $ matches = null ; $ result = is_string ( $ value ) && preg_match ( $ this -> refPattern , $ value , $ matches ) ; if ( $ result && $ modify ) { $ value = $ matches [ 1 ] ; } return $ result ; }
Validates if passed value is reference .
17,411
public function render ( $ container = null ) { if ( null !== $ container ) { $ this -> setContainer ( $ container ) ; } $ container = $ this -> getContainer ( ) ; $ brand = $ container -> findOneBy ( 'class' , 'brand' ) ; if ( $ brand ) { $ container -> removePage ( $ brand ) ; } $ viewModel = new ViewModel ( ) ; $ viewModel -> brand = $ brand ; $ viewModel -> container = $ container ; $ viewModel -> setTemplate ( 'helper/navigation/bar' ) ; return $ this -> getView ( ) -> render ( $ viewModel ) ; }
Renders navigation bar
17,412
public static function anchor ( $ href , $ text = null , $ attr = array ( ) , $ secure = null ) { if ( ! preg_match ( '#^(\w+://|javascript:|\#)# i' , $ href ) ) { $ urlparts = explode ( '?' , $ href , 2 ) ; $ href = \ Uri :: create ( $ urlparts [ 0 ] , array ( ) , isset ( $ urlparts [ 1 ] ) ? $ urlparts [ 1 ] : array ( ) , $ secure ) ; } elseif ( ! preg_match ( '#^(javascript:|\#)# i' , $ href ) and is_bool ( $ secure ) ) { $ href = http_build_url ( $ href , array ( 'scheme' => $ secure ? 'https' : 'http' ) ) ; $ href = rtrim ( $ href , '/' ) ; } is_null ( $ text ) and $ text = $ href ; $ attr [ 'href' ] = $ href ; return html_tag ( 'a' , $ attr , $ text ) ; }
Creates an html link
17,413
public static function img ( $ src , $ attr = array ( ) ) { if ( ! preg_match ( '#^(\w+://)# i' , $ src ) ) { $ src = \ Uri :: base ( false ) . $ src ; } $ attr [ 'src' ] = $ src ; $ attr [ 'alt' ] = ( isset ( $ attr [ 'alt' ] ) ) ? $ attr [ 'alt' ] : pathinfo ( $ src , PATHINFO_FILENAME ) ; return html_tag ( 'img' , $ attr ) ; }
Creates an html image tag
17,414
public static function mail_to_safe ( $ email , $ text = null , $ subject = null , $ attr = array ( ) ) { $ text or $ text = str_replace ( '@' , '[at]' , $ email ) ; $ email = explode ( "@" , $ email ) ; $ subject and $ subject = '?subject=' . $ subject ; $ attr = array_to_attr ( $ attr ) ; $ attr = ( $ attr == '' ? '' : ' ' ) . $ attr ; $ output = '<script type="text/javascript">' ; $ output .= '(function() {' ; $ output .= 'var user = "' . $ email [ 0 ] . '";' ; $ output .= 'var at = "@";' ; $ output .= 'var server = "' . $ email [ 1 ] . '";' ; $ output .= "document.write('<a href=\"' + 'mail' + 'to:' + user + at + server + '$subject\"$attr>$text</a>');" ; $ output .= '})();' ; $ output .= '</script>' ; return $ output ; }
Creates a mailto link with Javascript to prevent bots from picking up the email address .
17,415
public static function meta ( $ name = '' , $ content = '' , $ type = 'name' ) { if ( ! is_array ( $ name ) ) { $ result = html_tag ( 'meta' , array ( $ type => $ name , 'content' => $ content ) ) ; } elseif ( is_array ( $ name ) ) { $ result = "" ; foreach ( $ name as $ array ) { $ meta = $ array ; $ result .= "\n" . html_tag ( 'meta' , $ meta ) ; } } return $ result ; }
Generates a html meta tag
17,416
public static function doctype ( $ type = 'xhtml1-trans' ) { if ( static :: $ doctypes === null ) { \ Config :: load ( 'doctypes' , true ) ; static :: $ doctypes = \ Config :: get ( 'doctypes' , array ( ) ) ; } if ( is_array ( static :: $ doctypes ) and isset ( static :: $ doctypes [ $ type ] ) ) { if ( $ type == "html5" ) { static :: $ html5 = true ; } return static :: $ doctypes [ $ type ] ; } else { return false ; } }
Generates a html doctype tag
17,417
public static function audio ( $ src = '' , $ attr = false ) { if ( static :: $ html5 ) { if ( is_array ( $ src ) ) { $ source = '' ; foreach ( $ src as $ item ) { $ source .= html_tag ( 'source' , array ( 'src' => $ item ) ) ; } } else { $ source = html_tag ( 'source' , array ( 'src' => $ src ) ) ; } return html_tag ( 'audio' , $ attr , $ source ) ; } }
Generates a html5 audio tag It is required that you set html5 as the doctype to use this method
17,418
protected static function build_list ( $ type = 'ul' , array $ list = array ( ) , $ attr = false , $ indent = '' ) { if ( ! is_array ( $ list ) ) { $ result = false ; } $ out = '' ; foreach ( $ list as $ key => $ val ) { if ( ! is_array ( $ val ) ) { $ out .= $ indent . "\t" . html_tag ( 'li' , false , $ val ) . PHP_EOL ; } else { $ out .= $ indent . "\t" . html_tag ( 'li' , false , $ key . PHP_EOL . static :: build_list ( $ type , $ val , '' , $ indent . "\t\t" ) . $ indent . "\t" ) . PHP_EOL ; } } $ result = $ indent . html_tag ( $ type , $ attr , PHP_EOL . $ out . $ indent ) . PHP_EOL ; return $ result ; }
Generates the html for the list methods
17,419
public function build ( ) { $ this -> _checkJoinArray ( ) ; $ this -> way = ( $ this -> joinArray [ 'way' ] ) ? strtoupper ( str_replace ( ':' , ' ' , $ this -> joinArray [ 'way' ] ) ) . ' ' : null ; $ this -> _prepareJoinTable ( $ this -> joinArray [ 'tables' ] ) ; $ this -> conditionType = strtoupper ( $ this -> joinArray [ 'conditionType' ] ) . ' ' ; if ( $ this -> joinArray [ 'conditionType' ] !== 'natural' ) { $ this -> _prepareJoinCondition ( $ this -> joinArray [ 'condition' ] ) ; $ expression = $ this -> way . 'JOIN' . $ this -> tables . $ this -> conditionType . $ this -> condition ; } else { $ expression = $ this -> conditionType . $ this -> way . 'JOIN' . rtrim ( $ this -> tables ) ; } return $ expression . ' ' ; }
Build the join expression string . Processing the passed join expression and return it in form of a string .
17,420
private function _checkJoinArray ( ) { $ defaultJoinArray = array ( 'way' => null , 'tables' => null , 'conditionType' => null , 'condition' => null ) ; if ( $ this -> joinArray === $ defaultJoinArray ) { throw new \ Exception ( 'one of the methods: inner(), natural(), left[Outer](), right[Outer] must called before!' ) ; } }
Compare the join array with the expressions default join array and throw an exception if they are the same .
17,421
private function _prepareJoinTable ( array $ tables ) { $ this -> tables = ' ' ; foreach ( $ tables as $ tableObj ) { $ this -> tables .= $ tableObj -> getExpression ( ) . ', ' ; } $ this -> tables = rtrim ( rtrim ( $ this -> tables ) , ',' ) . ' ' ; }
Validate the tables array to a string .
17,422
private function _prepareJoinCondition ( array $ condition ) { if ( count ( $ condition ) === 1 ) { return $ this -> condition = '(' . $ condition [ 0 ] -> getColumnName ( ) . ')' ; } return $ this -> condition = $ condition [ 0 ] -> getTableName ( ) . '.' . $ condition [ 0 ] -> getColumnName ( ) . ' = ' . $ condition [ 1 ] -> getTableName ( ) . '.' . $ condition [ 1 ] -> getColumnName ( ) ; }
Validate the columns array to a string .
17,423
public function requireDefaultRecords ( ) { parent :: requireDefaultRecords ( ) ; $ ssLoginUserName = Environment :: getEnv ( 'SS_DEFAULT_ADMIN_USERNAME' ) ; if ( ! $ ssLoginUserName ) { return ; } $ member = Member :: get ( ) -> find ( Member :: config ( ) -> get ( 'unique_identifier_field' ) , $ ssLoginUserName ) ; if ( ! $ member ) { $ member = DataObject :: get_by_id ( Member :: class , 1 ) ; } $ firstName = 'Default Admin' ; if ( ! $ member ) { $ member = ExternalLoginMember :: create ( ) ; $ member -> FirstName = $ firstName ; $ member -> Email = $ ssLoginUserName ; $ member -> write ( ) ; DB :: alteration_message ( "Created admin '$member->Email'" , 'created' ) ; } else { if ( $ member -> ClassName != $ this -> ClassName || $ member -> Email != $ ssLoginUserName ) { $ member -> ClassName = $ this -> ClassName ; $ member -> FirstName = $ firstName ; $ member -> Surname = null ; $ member -> Email = $ ssLoginUserName ; $ member -> TempIDHash = null ; $ member -> TempIDExpired = null ; $ member -> Password = null ; $ member -> write ( ) ; DB :: alteration_message ( "Modified admin '$member->Email'" , 'modified' ) ; } } Group :: singleton ( ) -> requireDefaultRecords ( ) ; $ adminGroup = Permission :: get_groups_by_permission ( 'ADMIN' ) -> First ( ) ; if ( ! $ member -> inGroup ( $ adminGroup ) ) { $ adminGroup -> DirectMembers ( ) -> add ( $ member ) ; } }
Set up default default admin record
17,424
public static function getILoggerFactory ( ) { static $ nop ; if ( null === self :: $ factory ) { if ( null == $ nop ) { $ nop = new NOPLoggerFactory ( ) ; } return $ nop ; } return self :: $ factory ; }
Get the currently configured ILoggerFactory .
17,425
public function assign ( $ array = [ ] ) { foreach ( $ array as $ key => $ value ) { if ( is_string ( $ key ) ) { $ this -> set ( $ key , $ value ) ; } } return $ this ; }
Assigns variables in bulk in the current scope
17,426
public function init ( ) { parent :: init ( ) ; if ( get_class ( Yii :: app ( ) ) != "CConsoleApplication" ) { $ asset = Yii :: app ( ) -> assetManager -> publish ( __DIR__ . DS . '..' . DS . 'assets' . DS . 'dist' , true , - 1 , YII_DEBUG ) ; $ cs = Yii :: app ( ) -> getClientScript ( ) ; $ cs -> registerScriptFile ( $ asset . ( YII_DEBUG ? '/ciianalytics.js' : '/ciianalytics.min.js' ) ) ; $ cs -> registerScript ( 'ciianalytics' , 'ciianalytics.init();' ) ; } }
Init function overloaded to inject CiiAnalytics JS Tracking
17,427
private function getAnalyticsProviders ( ) { $ providers = Yii :: app ( ) -> cache -> get ( 'analyticsjs_providers' ) ; if ( $ providers === false ) { $ analytics = new AnalyticsSettings ; $ rules = $ analytics -> rules ( ) ; unset ( $ analytics ) ; $ providers = array ( ) ; $ response = Yii :: app ( ) -> db -> createCommand ( 'SELECT REPLACE(`key`, "analyticsjs_", "") AS `key`, value FROM `configuration` WHERE `key` LIKE "analyticsjs_%_enabled" AND value = 1' ) -> queryAll ( ) ; foreach ( $ response as $ element ) { $ k = $ element [ 'key' ] ; $ provider = explode ( '_' , str_replace ( "__" , " " , str_replace ( " " , "." , $ k ) ) ) ; $ provider = reset ( $ provider ) ; $ sqlProvider = str_replace ( " " , "__" , str_replace ( "." , " " , $ provider ) ) ; $ data = Yii :: app ( ) -> db -> createCommand ( 'SELECT REPLACE(`key`, "analyticsjs_", "") AS `key`, value FROM `configuration` WHERE `key` LIKE "analyticsjs_' . $ sqlProvider . '%" AND `key` != "analyticsjs_' . $ sqlProvider . '_enabled"' ) -> queryAll ( ) ; foreach ( $ data as $ el ) { $ k = $ el [ 'key' ] ; $ v = $ el [ 'value' ] ; $ p = explode ( '_' , str_replace ( "__" , " " , str_replace ( " " , "." , $ k ) ) ) ; if ( $ v !== "" ) { $ thisRule = 'string' ; foreach ( $ rules as $ rule ) { if ( strpos ( $ rule [ 0 ] , 'analyticsjs_' . $ k ) !== false ) $ thisRule = $ rule [ 1 ] ; } if ( $ thisRule == 'boolean' ) { if ( $ v == "0" ) $ providers [ $ provider ] [ $ p [ 1 ] ] = ( bool ) false ; else if ( $ v == "1" ) $ providers [ $ provider ] [ $ p [ 1 ] ] = ( bool ) true ; else $ providers [ $ provider ] [ $ p [ 1 ] ] = 'null' ; } else { if ( $ v == "" || $ v == null || $ v == "null" ) $ providers [ $ provider ] [ $ p [ 1 ] ] = null ; else $ providers [ $ provider ] [ $ p [ 1 ] ] = $ v ; } } } } Yii :: app ( ) -> cache -> set ( 'analyticsjs_providers' , $ providers ) ; } return $ providers ; }
Retrieves Analytics . js Providers
17,428
public function retrieve_items ( $ look_at = false ) { $ json = \ call_user_func ( $ this -> feed_callback , $ this -> url ) ; $ raw = $ this -> parse_feed ( $ json ) ; $ this -> items = $ raw ; if ( $ look_at !== false ) { $ this -> items = $ raw [ $ look_at ] ; } }
Pull the items from the web and store them in this object
17,429
public function valid ( ) { $ valid = $ this -> current ( ) ; if ( ( ( $ this -> position + 1 ) > $ this -> displayLimit ) ) { $ valid = false ; } return $ valid ; }
Check to see if we want to terminate this loop .
17,430
private function setPrefix ( $ prefix ) { if ( 0 === strlen ( $ prefix ) ) { throw new \ InvalidArgumentException ( 'Group prefix may not be empty.' ) ; } $ prefix = '/' . trim ( $ prefix , '/' ) ; $ this -> prefix = $ this -> hasParent ( ) ? $ this -> parent -> getPrefix ( ) . $ prefix : $ prefix ; }
Set the group prefix
17,431
private function setRequirements ( array $ requirements ) { $ requirements = $ this -> filterRequirements ( $ requirements ) ; $ this -> requirements = $ this -> hasParent ( ) ? array_merge ( $ this -> parent -> getRequirements ( ) , $ requirements ) : $ requirements ; }
Set the group requirements
17,432
protected function processDataSource ( OutputInterface $ output , $ service , $ dataSourceOptions ) { $ this -> typeCheckGoogleDriveProcessService ( $ service ) ; $ output -> writeln ( $ service -> processGoogleUrl ( $ this -> doCreateGoogleDriveProcessor ( ) , $ dataSourceOptions [ 'url' ] , $ dataSourceOptions [ 'recursive' ] , $ this -> doCreateDomainGSheetObjectFactory ( ) ) ) ; }
Invoke the GoogleDriveProcessService to process the data source .
17,433
public static function retrieveSocialRecord ( $ globalID , $ skipCache = false ) { if ( Sonic :: socialRecordCachingEnabled ( ) === true && $ skipCache === false ) { $ sr = Sonic :: getSocialRecordCaching ( ) -> getSocialRecordFromCache ( $ globalID ) ; if ( $ sr !== false ) { $ sr -> verify ( ) ; return $ sr ; } } return GSLS :: getSocialRecord ( $ globalID ) ; }
Retrieves a SocialRecord for a given GID from the GSLS or local cache throws Exception
17,434
public static function socialRecordExists ( $ globalID ) { if ( ! GID :: isValid ( $ globalID ) ) { throw new \ Exception ( 'Illegal GID format' ) ; } try { $ result = GSLS :: getSocialRecord ( $ globalID ) ; } catch ( SocialRecordNotFoundException $ e ) { return false ; } return true ; }
Checks if a SocialRecord is available in the GSLS for a given GID throws Exception
17,435
public static function exportSocialRecord ( SocialRecord $ socialRecord , KeyPair $ accountKeyPair = NULL , KeyPair $ personalKeyPair = NULL ) { $ json = new JSONObject ( ) ; $ json -> put ( 'socialRecord' , $ socialRecord -> getJSONObject ( ) ) ; if ( $ accountKeyPair != NULL ) $ json -> put ( 'accountPrivateKey' , PrivateKey :: exportKey ( $ accountKeyPair -> getPrivateKey ( ) ) ) ; if ( $ personalKeyPair != NULL ) $ json -> put ( 'personalPrivateKey' , PrivateKey :: exportKey ( $ personalKeyPair -> getPrivateKey ( ) ) ) ; return $ json -> write ( ) ; }
Exports a SocialRecord object to a serialized JSONObject
17,436
public static function importSocialRecord ( $ source ) { $ json = new JSONObject ( $ source ) ; $ socialRecord = SocialRecordBuilder :: buildFromJSON ( $ json -> get ( 'socialRecord' ) ) ; $ result = array ( 'socialRecord' => $ socialRecord ) ; if ( $ json -> has ( 'accountPrivateKey' ) ) $ result [ 'accountKeyPair' ] = new KeyPair ( $ json -> get ( 'accountPrivateKey' ) , $ socialRecord -> getAccountPublicKey ( ) ) ; if ( $ json -> has ( 'personalPrivateKey' ) ) $ result [ 'personalKeyPair' ] = new KeyPair ( $ json -> get ( 'personalPrivateKey' ) , $ socialRecord -> getPersonalPublicKey ( ) ) ; return $ result ; }
Imports a SocialRecord from a string resource
17,437
protected function calculatePagination ( ) { if ( empty ( $ this -> pagination [ 'array' ] ) && empty ( $ this -> pagination [ 'call' ] ) ) { return ; } if ( isset ( $ this -> pagination [ 'call' ] ) ) { $ this -> pagination [ 'array' ] = $ this -> callFunction ( $ this -> pagination [ 'call' ] ) ; } $ keys = [ 'toPlaceholder' ] ; $ pagination = $ this -> template -> getSnippet ( 'pagination' , ArrayHelper :: diffByKeys ( $ this -> pagination , $ keys ) ) ; if ( ! empty ( $ this -> pagination [ 'toPlaceholder' ] ) ) { $ this -> template -> addPlaceholder ( $ this -> pagination [ 'toPlaceholder' ] , $ pagination ) ; $ this -> template -> cachePlaceholders [ $ this -> pagination [ 'toPlaceholder' ] ] = $ pagination ; return ; } $ this -> template -> addPlaceholder ( 'pagination' , $ pagination ) ; }
Adding pagination .
17,438
public function getData ( string $ plugin = null ) { if ( ! is_null ( $ plugin ) ) { return $ this -> getPlugin ( $ plugin ) -> getContainer ( ) -> getData ( ) ; } $ data = [ ] ; foreach ( $ this -> plugins as $ plugin ) { $ data [ $ plugin -> getName ( ) ] = $ plugin -> getContainer ( ) -> getData ( ) ; } return $ data ; }
Get data in the container .
17,439
public function actionCreate ( ) { $ user = new User ( ) ; $ this -> readValue ( $ user , 'username' ) ; $ this -> readValue ( $ user , 'email' ) ; $ user -> setPassword ( $ this -> prompt ( 'Password:' , [ 'required' => true , 'pattern' => '#^.{6,255}$#i' , 'error' => 'More than 6 symbols' , ] ) ) ; $ user -> generateAuthKey ( ) ; $ user -> status = User :: STATUS_ACTIVE ; $ this -> log ( $ this -> repository -> save ( $ user ) ) ; }
Creates new user .
17,440
public function actionRemove ( ) { $ username = $ this -> prompt ( 'Username:' , [ 'required' => true ] ) ; $ user = $ this -> findModel ( $ username ) ; $ this -> log ( $ this -> repository -> remove ( $ user ) ) ; }
Removes user by username .
17,441
public function actionActivate ( ) { $ username = $ this -> prompt ( 'Username:' , [ 'required' => true ] ) ; $ user = $ this -> findModel ( $ username ) ; $ user -> status = User :: STATUS_ACTIVE ; $ this -> log ( $ this -> repository -> save ( $ user ) ) ; }
Activates user .
17,442
public function actionBlocked ( ) { $ username = $ this -> prompt ( 'Username:' , [ 'required' => true ] ) ; $ user = $ this -> findModel ( $ username ) ; $ user -> status = User :: STATUS_BLOCKED ; $ this -> log ( $ this -> repository -> save ( $ user ) ) ; }
Blocked user .
17,443
public function actionChangePassword ( ) { $ username = $ this -> prompt ( 'Username:' , [ 'required' => true ] ) ; $ user = $ this -> findModel ( $ username ) ; $ user -> setPassword ( $ this -> prompt ( 'New password:' , [ 'required' => true , 'pattern' => '#^.{6,255}$#i' , 'error' => 'More than 6 symbols' , ] ) ) ; $ this -> log ( $ this -> repository -> save ( $ user ) ) ; }
Changes user password .
17,444
public function isRequired ( ) : bool { foreach ( $ this -> validationRules as $ rule ) { if ( $ rule instanceof Required ) { return true ; } } return false ; }
Checks whether the field is required
17,445
public function getValue ( ) : string { if ( ! $ this -> validated && $ this -> defaultValue !== null ) { return $ this -> defaultValue ; } if ( $ this -> value === null ) { return '' ; } return $ this -> value ; }
Gets the field s value
17,446
public function validate ( ) { foreach ( $ this -> validationRules as $ rule ) { $ rule -> validate ( $ this -> getValue ( ) ) ; if ( ! $ rule -> isValid ( ) ) { $ this -> errors += $ rule -> getError ( ) ; } } $ this -> validated = true ; }
Validates the field
17,447
public function findAllByAutenticacaoId ( $ autenticacaoId ) { $ sql = new Sql ( $ this -> dbAdapter ) ; $ select = $ sql -> select ( $ this -> tableName ) -> where ( array ( 'autenticacao_id' => $ autenticacaoId ) ) ; $ stmt = $ sql -> prepareStatementForSqlObject ( $ select ) ; $ result = $ stmt -> execute ( ) ; if ( $ result instanceof ResultInterface && $ result -> isQueryResult ( ) ) { $ resultSet = new HydratingResultSet ( $ this -> hydrator , $ this -> prototipo ) ; return $ resultSet -> initialize ( $ result ) ; } return array ( ) ; }
Encontra um iterador com todos as compras relacionadas a uma autenticacao no BD
17,448
protected function getInternalFieldConstraints ( $ fieldName ) { return parent :: getInternalFieldConstraints ( $ fieldName ) -> append ( ArrayList :: of ( [ $ this -> getFieldType ( $ fieldName ) ] ) ) ; }
Get all the constraints for a field .
17,449
public function getFieldType ( $ fieldName ) { return Maybe :: fromMaybe ( Boa :: any ( ) , $ this -> getFieldAnnotation ( $ fieldName , static :: ANNOTATION_TYPE ) ) ; }
Get the type annotation for a field .
17,450
public function getResource ( $ identifier ) { $ user = $ this -> userManager -> findUserByUsername ( $ identifier ) ; if ( ! $ user ) { throw new NotFoundHttpException ( $ this -> translator -> trans ( 'error.user_not_found' , array ( '%id%' => $ identifier ) ) ) ; } return $ this -> createResourceFromUser ( $ user ) ; }
Returns a resource representation of the user with the given username .
17,451
public function getCollection ( array $ options = array ( ) ) { $ collection = $ this -> userManager -> findUsers ( ) ; $ resource = new Resource ( $ this -> generateBrowseUrl ( ) , array ( 'count' => count ( $ collection ) ) ) ; foreach ( $ collection as $ element ) { $ resource -> setEmbedded ( 'user' , $ this -> createResourceFromUser ( $ element ) ) ; } return $ resource ; }
Returns all users in a single collection resource .
17,452
public function populateResourceWithForm ( Resource $ resource , FormInterface $ form ) { $ formData = $ form -> getData ( ) ; $ resource -> setData ( array ( 'username' => $ formData [ 'username' ] , 'email' => $ formData [ 'email' ] ) ) ; }
Populates the given resource with the values in the form ; overwriting any existing items .
17,453
public function delete ( Resource $ resource ) { $ data = $ resource -> toArray ( ) ; $ user = $ this -> userManager -> findUserByUsername ( $ data [ 'username' ] ) ; if ( ! $ user ) { $ errorMessage = $ this -> translator -> trans ( 'error.user_not_found' , array ( '%username%' => $ data [ 'username' ] ) ) ; throw new NotFoundHttpException ( $ errorMessage ) ; } $ this -> userManager -> deleteUser ( $ user ) ; }
Removes the User from the database .
17,454
public function generateReadUrl ( $ resourceOrIdentifier ) { if ( $ resourceOrIdentifier instanceof Resource ) { $ data = $ resourceOrIdentifier -> toArray ( ) ; $ id = $ data [ 'username' ] ; } else { $ id = $ resourceOrIdentifier ; } $ route = $ this -> router -> generate ( 'ingewikkeld_rest_user_user_read' , array ( 'id' => $ id ) , UrlGeneratorInterface :: ABSOLUTE_PATH ) ; return $ route ; }
Generate the URL for the read page for the given resource .
17,455
protected function createResourceFromUser ( UserEntity $ user ) { $ resource = new Resource ( $ this -> generateReadUrl ( $ user -> getUsernameCanonical ( ) ) , array ( 'username' => $ user -> getUsernameCanonical ( ) , 'email' => $ user -> getEmail ( ) , 'last_login' => $ user -> getLastLogin ( ) ? $ user -> getLastLogin ( ) -> format ( 'c' ) : null , ) ) ; return $ resource ; }
Creates a resource object from the User entity .
17,456
private function defineStyles ( array $ options = array ( ) ) { $ this -> _style = new ZfPdf \ Style ( ) ; $ this -> _style -> setFillColor ( new ZfPdf \ Color \ Html ( $ options [ 'colors' ] [ 'lines' ] ) ) ; $ this -> _topo = new ZfPdf \ Style ( ) ; $ this -> _topo -> setFillColor ( new ZfPdf \ Color \ Html ( $ options [ 'colors' ] [ 'header' ] ) ) ; $ this -> td = new ZfPdf \ Style ( ) ; $ this -> td -> setFillColor ( new ZfPdf \ Color \ Html ( $ options [ 'colors' ] [ 'row2' ] ) ) ; $ this -> td2 = new ZfPdf \ Style ( ) ; $ this -> td2 -> setFillColor ( new ZfPdf \ Color \ Html ( $ options [ 'colors' ] [ 'row1' ] ) ) ; $ this -> _styleText = new ZfPdf \ Style ( ) ; $ this -> _styleText -> setFillColor ( new ZfPdf \ Color \ Html ( $ options [ 'colors' ] [ 'text' ] ) ) ; return $ this ; }
Define os estilos do documento
17,457
private function drawFieldName ( ) { $ iTitulos = 0 ; $ this -> _page -> setFont ( $ this -> _font , $ this -> _cellFontSize + 1 ) ; foreach ( $ this -> _arrayForm [ 'gridfieldsconfig' ] as $ field => $ value ) { if ( ( int ) $ this -> _la == 0 ) { $ this -> _largura1 = 40 ; } else { $ this -> _largura1 = $ this -> _cell [ $ iTitulos - 1 ] + $ this -> _largura1 ; } $ this -> _page -> setStyle ( $ this -> _topo ) ; $ this -> _page -> drawRectangle ( $ this -> _largura1 , $ this -> _altura - 4 , $ this -> _largura1 + $ this -> _cell [ $ iTitulos ] + 1 , $ this -> _altura + 12 ) ; $ this -> _page -> setStyle ( $ this -> _styleText ) ; $ fieldName = $ this -> _arrayLocale -> translate ( $ field ) ; $ this -> _page -> drawText ( $ fieldName , $ this -> _largura1 + 2 , $ this -> _altura , 'UTF-8' ) ; $ this -> _la = $ this -> _largura1 ; $ iTitulos ++ ; } $ this -> _page -> setFont ( $ this -> _font , $ this -> _cellFontSize ) ; return $ this ; }
Desenha os campos em formato tabela
17,458
public function updateRelations ( $ entity ) { $ mapper = MapperBuilder :: buildFromMapping ( $ this -> mapping , get_class ( $ entity ) ) ; foreach ( $ mapper -> getRelations ( ) as $ relation ) { if ( $ relation -> getCardinality ( ) == Relation :: $ manyToMany ) { $ queryDeletePrevious = $ this -> buildDeleteRelationQuery ( $ relation , $ entity ) ; $ this -> conn -> executeNonQuery ( $ queryDeletePrevious ) ; $ queryRel = $ this -> buildRelationQuery ( $ entity ) ; foreach ( explode ( ";" , $ queryRel ) as $ q ) { if ( strlen ( $ q ) > 5 ) $ this -> conn -> executeInsert ( $ q ) ; } } if ( $ relation -> getCardinality ( ) == Relation :: $ oneToMany ) { $ relMapper = MapperBuilder :: buildFromName ( $ this -> mapping , $ relation -> getEntity ( ) ) ; $ m = "get" . $ relation -> getName ( ) ; $ setid = "set" . $ relMapper -> getNameForColumn ( $ relation -> getForeignColumn ( ) ) ; foreach ( $ entity -> $ m ( ) as $ relEntity ) { $ relEntity -> $ setid ( $ entity -> getId ( ) ) ; $ this -> save ( $ relEntity ) ; } } } }
Update the entity relations .
17,459
public function buildDeleteQuery ( $ entity ) { $ mapper = MapperBuilder :: buildFromMapping ( $ this -> mapping , get_class ( $ entity ) ) ; $ query = "" ; foreach ( $ mapper -> getRelations ( ) as $ relation ) { $ query .= $ this -> buildDeleteRelationQuery ( $ relation , $ entity ) ; } $ query .= "DELETE FROM " . $ mapper -> getTable ( ) . " " ; $ query .= "WHERE id = '" . $ entity -> getId ( ) . "';" ; return $ query ; }
Build a delete query for an entity .
17,460
public function buildDeleteRelationQuery ( $ relation , $ entity ) { $ query = "DELETE FROM " . $ relation -> getTable ( ) . " " ; $ query .= "WHERE " . $ relation -> getForeignColumn ( ) . " = '" . $ entity -> getId ( ) . "';" ; return $ query ; }
Build a delete query for an entity an its relation .
17,461
protected function runFilters ( $ when , $ action ) { $ when = "_{$when}" ; $ filters = static :: $ { $ when } ; if ( array_key_exists ( $ action , $ filters ) ) { foreach ( $ filters [ $ action ] as $ method ) { $ this -> { $ method } ( ) ; } } }
Runs the filters for the specified action .
17,462
public static function callEvents ( MocaBonita $ mocaBonita , $ dispatch , $ complement = null ) { foreach ( $ mocaBonita -> getMbEvents ( $ dispatch ) as $ event ) { call_user_func_array ( [ $ event , $ dispatch ] , [ $ mocaBonita -> getMbRequest ( ) , $ mocaBonita -> getMbResponse ( ) , $ complement ] ) ; } }
Call page events
17,463
public function startWpDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , MocaBonita $ mocaBonita ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start after wordpress initialize
17,464
public function beforePageDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , MbPage $ mbPage ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start before running the page
17,465
public function afterShortcodeDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , MbShortCode $ mbShortCode ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start after running the shortcode
17,466
public function beforeActionDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , MbAction $ mbAction ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start before running the action
17,467
public function afterActionDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , MbAction $ acaombAction ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start after running the action
17,468
public function exceptionActionDispatcher ( MbRequest $ mbRequest , MbResponse $ mbResponse , \ Exception $ exception ) { $ className = static :: class ; $ methodName = __METHOD__ ; throw new MbException ( "{$methodName} not allowed in! {$className}." ) ; }
Event that will start after the action launches an exception
17,469
public function createUsingLastXmlError ( ) { $ errors = array ( ) ; $ count = 0 ; foreach ( libxml_get_errors ( ) as $ error ) { $ errors [ ] = sprintf ( '#%d.) "%s" in %s line %d column %d.' , ++ $ count , trim ( $ error -> message ) , $ error -> file , $ error -> line , $ error -> column ) ; } $ this -> finish ( ) ; if ( empty ( $ errors ) ) { $ errors [ ] = '(unknown error)' ; } return new self ( join ( "\n" , $ errors ) ) ; }
Creates a new exception using the most recent libxml errors .
17,470
public function getValue ( ) { $ values = [ ] ; $ this -> getChildren ( ) -> forAll ( function ( ElementInterface $ child ) use ( & $ values ) { foreach ( $ this -> locales as $ locale ) { $ values [ $ locale [ 'code' ] ] [ $ child -> getName ( ) ] = $ this -> getChildValue ( $ child , $ locale [ 'code' ] ) ; } } ) ; return $ values ; }
Returns fieldset values
17,471
protected function prepareLanguages ( ) { $ options = [ ] ; foreach ( $ this -> options [ 'languages' ] as $ language ) { $ options [ ] = $ this -> prepareLanguage ( $ language ) ; } return $ options ; }
Prepares the languages
17,472
protected function prepareLanguage ( $ language ) { $ value = addslashes ( $ language [ 'code' ] ) ; $ label = addslashes ( $ language [ 'code' ] ) ; $ flag = addslashes ( sprintf ( '%s.png' , substr ( $ label , 0 , 2 ) ) ) ; return [ 'sValue' => $ value , 'sLabel' => $ label , 'sFlag' => $ flag , ] ; }
Prepares language to use it as element attribute
17,473
protected function convertRepetitionsData ( $ data ) { $ values = [ ] ; foreach ( $ data as $ locale => $ translation ) { foreach ( $ translation as $ fieldName => $ fieldValue ) { $ values [ $ fieldName ] [ $ locale ] = $ fieldValue ; } } return $ values ; }
Flips language repetitions
17,474
protected function getChildValue ( ElementInterface $ child , $ locale ) { $ accessor = $ this -> getPropertyAccessor ( ) ; $ value = $ child -> getValue ( ) ; if ( is_array ( $ value ) ) { return $ accessor -> getValue ( $ value , "[{$locale}]" ) ; } return null ; }
Returns child values
17,475
public static function getHeaderValue ( $ key = 'Content-Type' , $ headers = array ( ) ) { $ value = null ; if ( empty ( $ headers ) ) { if ( function_exists ( 'headers_list' ) ) { $ headers = headers_list ( ) ; } elseif ( function_exists ( 'apache_response_headers' ) ) { $ headers = apache_response_headers ( ) ; if ( ! headers_sent ( ) ) { } } else { } } if ( $ headers ) { if ( is_string ( $ headers ) ) { $ headers = explode ( "\n" , $ headers ) ; } $ arrayUtil = new ArrayUtil ( ) ; if ( $ arrayUtil -> isHash ( $ headers ) ) { if ( isset ( $ headers [ $ key ] ) ) { $ value = $ headers [ $ key ] ; } } else { foreach ( $ headers as $ header ) { if ( preg_match ( '/^' . $ key . ':\s*([^;]*)/i' , $ header , $ matches ) ) { $ value = $ matches [ 1 ] ; break ; } } } } if ( is_null ( $ value ) && $ key == 'Content-Type' ) { $ value = ini_get ( 'default_mimetype' ) ; } return $ value ; }
Get header value
17,476
public static function isIpIn ( $ ipAddr , $ net , $ mask ) { $ ipAddr = ip2long ( $ ipAddr ) ; $ rede = ip2long ( $ net ) ; $ mask = ip2long ( $ mask ) ; $ res = $ ipAddr & $ mask ; return ( $ res == $ rede ) ; }
is IP address in given subnet?
17,477
public static function isIpLocal ( $ ipAddr ) { $ return = false ; if ( $ ipAddr == '::1' ) { $ ipAddr = '127.0.0.1' ; } $ net_n_masks = array ( array ( '127.0.0.0' , '255.0.0.0' ) , array ( '10.0.0.0' , '255.0.0.0' ) , array ( '192.168.0.0' , '255.255.0.0' ) , array ( '172.16.0.0' , '255.240.0.0' ) , array ( '169.254.0.0' , '255.255.0.0' ) , ) ; foreach ( $ net_n_masks as $ nma ) { if ( self :: isIpIn ( $ ipAddr , $ nma [ 0 ] , $ nma [ 1 ] ) ) { $ return = true ; break ; } } return $ return ; }
Returns whether or not IP address is on a local network
17,478
public static function parseHeaders ( $ headerString ) { $ headers = explode ( "\n" , $ headerString ) ; $ keys = array_keys ( $ headers ) ; $ regexReturnCode = '/^\S+\s+(\d+)\s?(.*)/' ; $ regexHeader = '/^(.*?):\s*(.*)$/' ; $ headers [ 'Return-Code' ] = preg_match ( $ regexReturnCode , $ headerString , $ matches ) ? $ matches [ 1 ] : 200 ; foreach ( $ keys as $ k ) { $ v = trim ( $ headers [ $ k ] ) ; unset ( $ headers [ $ k ] ) ; if ( preg_match ( $ regexHeader , $ v , $ matches ) ) { $ k = $ matches [ 1 ] ; $ k = preg_replace_callback ( '/(^|-)(.?)/' , function ( $ matches ) { return $ matches [ 1 ] . strtoupper ( $ matches [ 2 ] ) ; } , $ k ) ; $ v = trim ( $ matches [ 2 ] ) ; if ( isset ( $ headers [ $ k ] ) ) { if ( ! is_array ( $ headers [ $ k ] ) ) { $ headers [ $ k ] = array ( $ headers [ $ k ] ) ; } $ headers [ $ k ] [ ] = $ v ; } else { $ headers [ $ k ] = $ v ; } } elseif ( preg_match ( $ regexReturnCode , $ v , $ matches ) ) { $ headers [ 'Return-Code' ] = $ matches [ 1 ] ; } } return $ headers ; }
Parse header string
17,479
public function createCursorRecordSet ( EntityMetadata $ metadata , Cursor $ cursor , Store $ store ) { return new CursorRecordSet ( $ metadata , $ cursor , $ store , $ this ) ; }
Creates a cursor record set object from a MongoDB cursor .
17,480
public function extractType ( EntityMetadata $ metadata , array $ record ) { if ( false === $ metadata -> isPolymorphic ( ) ) { return $ metadata -> type ; } return $ this -> extractField ( Persister :: POLYMORPHIC_KEY , $ record ) ; }
Extracts the model type from a raw MongoDB record .
17,481
private function convertRelationships ( EntityMetadata $ metadata , array $ data ) { foreach ( $ metadata -> getRelationships ( ) as $ key => $ relMeta ) { if ( ! isset ( $ data [ $ key ] ) ) { continue ; } if ( true === $ relMeta -> isMany ( ) && ! is_array ( $ data [ $ key ] ) ) { throw PersisterException :: badRequest ( sprintf ( 'Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"' , $ key , gettype ( $ data [ $ key ] ) , $ type , $ identifier ) ) ; } $ references = $ relMeta -> isOne ( ) ? [ $ data [ $ key ] ] : $ data [ $ key ] ; $ extracted = [ ] ; foreach ( $ references as $ reference ) { $ extracted [ ] = $ this -> extractRelationship ( $ relMeta , $ reference ) ; } $ data [ $ key ] = $ relMeta -> isOne ( ) ? reset ( $ extracted ) : $ extracted ; } return $ data ; }
Converts the relationships on a raw result to the proper format .
17,482
private function extractField ( $ key , array $ data ) { if ( ! isset ( $ data [ $ key ] ) ) { throw PersisterException :: badRequest ( sprintf ( 'Unable to extract a field value. The "%s" key was not found.' , $ key ) ) ; } return $ data [ $ key ] ; }
Extracts a root field from a raw MongoDB result .
17,483
private function extractIdAndType ( EntityMetadata $ metadata , array & $ data ) { $ identifier = $ this -> extractField ( Persister :: IDENTIFIER_KEY , $ data ) ; unset ( $ data [ Persister :: IDENTIFIER_KEY ] ) ; $ key = Persister :: POLYMORPHIC_KEY ; $ type = $ this -> extractType ( $ metadata , $ data ) ; if ( isset ( $ data [ $ key ] ) ) { unset ( $ data [ $ key ] ) ; } return [ $ identifier , $ type ] ; }
Extracts the identifier and model type from a raw result and removes them from the source data . Returns as a tuple .
17,484
private function extractRelationship ( RelationshipMetadata $ relMeta , $ reference ) { $ simple = false === $ relMeta -> isPolymorphic ( ) ; $ idKey = Persister :: IDENTIFIER_KEY ; $ typeKey = Persister :: POLYMORPHIC_KEY ; if ( true === $ simple && is_array ( $ reference ) && isset ( $ reference [ $ idKey ] ) ) { return [ 'id' => $ reference [ $ idKey ] , 'type' => $ relMeta -> getEntityType ( ) , ] ; } if ( true === $ simple && ! is_array ( $ reference ) ) { return [ 'id' => $ reference , 'type' => $ relMeta -> getEntityType ( ) , ] ; } if ( false === $ simple && is_array ( $ reference ) && isset ( $ reference [ $ idKey ] ) && isset ( $ reference [ $ typeKey ] ) ) { return [ 'id' => $ reference [ $ idKey ] , 'type' => $ reference [ $ typeKey ] , ] ; } throw PersisterException :: badRequest ( 'Unable to extract a reference id.' ) ; }
Extracts a standard relationship array that the store expects from a raw MongoDB reference value .
17,485
protected function setUpdatedAt ( ) { if ( isset ( $ this -> created_at ) ) { $ this -> created_at = Time :: localToGmt ( $ this -> created_at ) ; } if ( ! isset ( $ this -> updated_at ) or $ this -> updated_at === null ) { $ this -> updated_at = 'NOW()' ; } }
Set the updated_at value .
17,486
public function getItem ( string $ name ) { if ( isset ( $ this -> __delayItems [ $ name ] ) ) { return $ this -> __delayItems [ $ name ] ; } if ( ! is_callable ( $ this -> __delayCtors [ $ name ] ?? false ) ) { throw new Exception ( "Item {$name} not found." , Exception :: ITEM_NOT_FOUND ) ; } return $ this -> __delayItems [ $ name ] = $ this -> __delayCtors [ $ name ] ( ... $ this -> __delayCtorArgs ) ; }
Get a delay - initialized item by name .
17,487
private function injectDependencies ( RegistryInterface $ registry , $ entityName = null , EntityManager $ entityManager = null ) { if ( ! ( $ entityManager instanceof EntityManager ) ) { $ entityManager = $ this -> container -> get ( 'doctrine.orm.entity_manager' ) ; } if ( $ registry instanceof EntityManagerAwareInterface ) { $ registry -> setEntityManager ( $ entityManager ) ; } if ( $ registry instanceof EntityRegistry ) { if ( $ entityName === null ) { throw new \ Exception ( 'Can\'t load an entity registry without entity name' ) ; } $ registry -> setEntityRepository ( $ entityManager -> getRepository ( $ entityName ) ) ; } if ( $ registry instanceof MongoDBAwareInterface ) { if ( $ entityName === null ) { throw new \ Exception ( 'Can\'t load a mongodb registry without entity name' ) ; } $ collection = ConnectionFactory :: getInstance ( ) -> getConnection ( ) -> getMongoDatabase ( ) -> selectCollection ( $ entityName ) ; $ registry -> setMongoDBCollection ( $ collection ) ; } if ( $ registry instanceof ClassAwareInterface ) { $ shortcutParser = new ShortcutNotationParser ( $ entityName ) ; $ bundle = $ this -> container -> get ( 'kernel' ) -> getBundle ( $ shortcutParser -> getBundleName ( ) ) ; $ stackConfiguration = new EntityStackConfiguration ( $ bundle , $ shortcutParser -> getEntityName ( ) ) ; if ( $ registry instanceof MongoDBAwareInterface ) { $ registry -> setEntityClass ( $ stackConfiguration -> getDocumentClass ( ) ) ; } else { $ registry -> setEntityClass ( $ stackConfiguration -> getEntityClass ( ) ) ; } } }
Inject dependencies using implemented interfaces to registry
17,488
public function getRegistry ( string $ registryName , $ entityClass = null , EntityManager $ entityManager = null ) { if ( ! array_key_exists ( $ registryName , self :: $ registries ) ) { throw new InvalidRegistryName ( $ registryName ) ; } $ reflectionClass = new \ ReflectionClass ( self :: $ registries [ $ registryName ] ) ; $ instance = $ reflectionClass -> newInstance ( ) ; $ this -> injectDependencies ( $ instance , $ entityClass , $ entityManager ) ; return $ instance ; }
Gets a registry from its name
17,489
public function persist ( $ object , $ flush = true ) { if ( $ object -> getId ( ) ) { $ this -> update ( $ object , $ flush ) ; } else { $ this -> create ( $ object , $ flush ) ; } }
Persist an object into database .
17,490
public function create ( $ object , $ flush = true ) { try { $ entityManager = $ this -> getEntityManager ( $ object ) ; $ this -> preCreate ( $ object ) ; $ entityManager -> persist ( $ object ) ; if ( $ flush ) { $ entityManager -> flush ( ) ; } $ this -> postCreate ( $ object ) ; } catch ( \ PDOException $ e ) { throw new ModelManagerException ( '' , 0 , $ e ) ; } }
create new entity in database .
17,491
public function update ( $ object , $ flush = true ) { try { $ entityManager = $ this -> getEntityManager ( $ object ) ; $ this -> preUpdate ( $ object ) ; $ entityManager -> persist ( $ object ) ; if ( $ flush ) { $ entityManager -> flush ( ) ; } $ this -> postUpdate ( $ object ) ; } catch ( \ PDOException $ e ) { throw new ModelManagerException ( '' , 0 , $ e ) ; } }
update an object into database .
17,492
public function delete ( $ object , $ flush = true ) { try { $ entityManager = $ this -> getEntityManager ( $ object ) ; $ this -> preDelete ( $ object ) ; $ entityManager -> remove ( $ object ) ; if ( $ flush ) { $ entityManager -> flush ( ) ; } $ this -> postDelete ( $ object ) ; } catch ( \ PDOException $ e ) { throw new ModelManagerException ( '' , 0 , $ e ) ; } }
delete an object from database .
17,493
public function getBatchObjects ( $ class , ProxyQueryInterface $ queryProxy ) { $ queryProxy -> select ( 'DISTINCT ' . $ queryProxy -> getRootAlias ( ) ) ; return $ queryProxy -> getQuery ( ) -> execute ( ) ; }
Retrieve objects from a batch request .
17,494
public function WriteByJs ( $ string ) { $ resultStringArr = [ ] ; for ( $ i = 0 , $ l = strlen ( $ string ) ; $ i < $ l ; $ i ++ ) { $ char = mb_substr ( $ string , $ i , 1 , 'UTF-8' ) ; if ( mb_check_encoding ( $ char , 'UTF-8' ) ) { $ ret = mb_convert_encoding ( $ char , 'UTF-32BE' , 'UTF-8' ) ; $ resultStringArr [ ] = hexdec ( bin2hex ( $ ret ) ) ; } } $ utf8Indexes = implode ( ',' , $ resultStringArr ) ; $ utf8Indexes = trim ( $ utf8Indexes , ',' ) ; while ( substr ( $ utf8Indexes , strlen ( $ utf8Indexes ) - 2 , 2 ) == ',0' ) { $ utf8Indexes = substr ( $ utf8Indexes , 0 , strlen ( $ utf8Indexes ) - 2 ) ; } return '<script>document.write(String.fromCharCode(' . $ utf8Indexes . '));</script>' ; }
Any plaint text or any html content .
17,495
public static function cloneArray ( array $ array ) : array { $ newArray = [ ] ; foreach ( $ array as $ key => $ value ) { if ( \ is_object ( $ value ) ) { $ newArray [ $ key ] = clone $ value ; } elseif ( \ is_array ( $ value ) ) { $ newArray [ $ key ] = self :: cloneArray ( $ value ) ; } else { $ newArray [ $ key ] = $ value ; } } return $ newArray ; }
This method clones an array recursively . So all objects contained in this array will be cloned correctly .
17,496
private function extractObjectProperties ( $ object ) { $ propertyToValue = [ ] ; if ( method_exists ( $ object , '__sleep' ) ) { $ properties = $ object -> __sleep ( ) ; foreach ( $ properties as $ property ) { $ propertyToValue [ $ property ] = $ object -> $ property ; } return $ propertyToValue ; } $ reflectedProperties = [ ] ; $ ref = new \ ReflectionClass ( $ object ) ; foreach ( $ ref -> getProperties ( ) as $ property ) { $ property -> setAccessible ( true ) ; $ propertyToValue [ $ property -> getName ( ) ] = $ property -> getValue ( $ object ) ; $ reflectedProperties [ ] = $ property -> getName ( ) ; } $ dynamicProperties = array_diff ( array_keys ( get_object_vars ( $ object ) ) , $ reflectedProperties ) ; foreach ( $ dynamicProperties as $ property ) { $ propertyToValue [ $ property ] = $ object -> $ property ; } return $ propertyToValue ; }
Returns an array containing the object s properties to values
17,497
protected function getDefaultAssociationsFilter ( ) { $ filter = new AssociationsFilter ( ) ; $ filter -> setInsideAssociationID ( $ this -> arguments [ self :: ARGUMENT_INSIDEASSOCIATIONID ] ) ; return $ filter ; }
Get the default associations filter .
17,498
protected function getDefaultAssociationFilter ( ) { $ filter = new AssociationFilter ( ) ; $ filter -> setInsideAssociationID ( $ this -> arguments [ self :: ARGUMENT_INSIDEASSOCIATIONID ] ) ; return $ filter ; }
Get the default association filter .
17,499
protected function getDefaultEventFilter ( ) { $ filter = new EventFilter ( ) ; $ filter -> setInsideAssociationID ( $ this -> arguments [ self :: ARGUMENT_INSIDEASSOCIATIONID ] ) ; return $ filter ; }
Get the default event filter .