idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
59,300
public static function instance ( $ name = null ) { $ fieldset = \ Fieldset :: instance ( $ name ) ; return $ fieldset === false ? false : $ fieldset -> form ( ) ; }
Returns the default instance of Form
59,301
public static function password ( $ field , $ value = null , array $ attributes = array ( ) ) { return static :: $ instance -> password ( $ field , $ value , $ attributes ) ; }
Create a password input field
59,302
public static function checkbox ( $ field , $ value = null , $ checked = null , array $ attributes = array ( ) ) { return static :: $ instance -> checkbox ( $ field , $ value , $ checked , $ attributes ) ; }
Create a checkbox
59,303
public function save ( Language $ model ) : void { if ( ! $ model -> save ( ) ) { throw new \ RuntimeException ( $ this -> i18n -> t ( 'setrun/sys' , 'Saving error' ) ) ; } }
Save a language item .
59,304
public function remove ( Language $ model ) : void { if ( ! $ model -> delete ( ) ) { throw new \ RuntimeException ( $ this -> i18n -> t ( 'setrun/sys' , 'Removing error' ) ) ; } }
Remove a language item .
59,305
public function getUser ( ) { if ( $ this -> _user !== NULL ) return $ this -> _user ; else $ this -> _user = Users :: model ( ) -> findByAttributes ( array ( 'email' => $ this -> username ) ) ; if ( $ this -> _user == NULL ) $ this -> errorCode = YII_DEBUG ? self :: ERROR_USERNAME_INVALID : self :: ERROR_UNKNOWN_IDENTITY ; return $ this -> _user ; }
Retrieves the user s model and presets an error code if one does not exists
59,306
private function setup ( $ force = false ) { $ this -> errorCode = NULL ; $ this -> force = $ force ; $ this -> getUser ( ) ; $ this -> _cost = Cii :: getBcryptCost ( ) ; $ this -> getPasswordAttempts ( ) ; return ; }
Handles setting up all the data necessary for the workflow
59,307
protected function getPasswordAttempts ( ) { if ( $ this -> _user == NULL ) return false ; $ this -> _attempts = UserMetadata :: model ( ) -> getPrototype ( 'UserMetadata' , array ( 'user_id' => $ this -> getUser ( ) -> id , 'key' => 'passwordAttempts' ) , array ( 'user_id' => $ this -> getUser ( ) -> id , 'key' => 'passwordAttempts' , 'value' => 0 ) ) ; return $ this -> _attempts ; }
Retrieves the number of password login attempts so that we can automatically lock users out of they attempt a brute force attack
59,308
private function validateTwoFactorCode ( ) { $ otpSeed = $ this -> getUser ( ) -> getMetadataObject ( 'OTPSeed' , false ) -> value ; if ( $ otpSeed === false ) return false ; $ otplib = new TOTP ( Cii :: decrypt ( $ otpSeed ) ) ; return $ otplib -> validate ( $ this -> twoFactorCode ) ; }
Validates the users two factor authentication code
59,309
public function authenticate ( $ force = false ) { $ this -> setup ( $ force ) ; if ( $ this -> errorCode != NULL ) return ! $ this -> errorCode ; $ this -> validatePassword ( ) ; if ( $ this -> _attempts -> value >= 5 ) { if ( ( strtotime ( $ this -> _attempts -> updated ) + strtotime ( "+15 minutes" ) ) >= time ( ) ) { $ this -> _attempts -> save ( ) ; $ this -> errorCode = self :: ERROR_UNKNOWN_IDENTITY ; } else { $ this -> _attempts -> value = 0 ; $ this -> _attempts -> save ( ) ; } } if ( $ this -> getUser ( ) -> needsTwoFactorAuth ( ) ) { if ( $ this -> twoFactorCode === false ) $ this -> errorCode = self :: REQUIRE_TWO_FACTOR_AUTH ; else { if ( ! $ this -> validateTwoFactorCode ( ) ) $ this -> errorCode = self :: INVALID_TWO_FACTOR_AUTH ; } } if ( $ this -> errorCode != NULL ) return ! $ this -> errorCode ; else $ this -> setIdentity ( ) ; return ! $ this -> errorCode ; }
Authenticates the user into the system
59,310
public function validatePassword ( ) { if ( $ this -> _user -> status == Users :: BANNED || $ this -> _user -> status == Users :: INACTIVE || $ this -> _user -> status == Users :: PENDING_INVITATION ) $ this -> errorCode = self :: ERROR_UNKNOWN_IDENTITY ; else if ( ! $ this -> password_verify_with_rehash ( $ this -> password , $ this -> _user -> password ) ) $ this -> errorCode = YII_DEBUG ? self :: ERROR_PASSWORD_INVALID : self :: ERROR_UNKNOWN_IDENTITY ; if ( $ this -> errorCode === 100 || $ this -> errorCode === NULL || $ this -> errorCode === self :: REQUIRE_TWO_FACTOR_AUTH ) return true ; return false ; }
Do some basic password validation
59,311
protected function setIdentity ( ) { $ this -> _id = $ this -> _user -> id ; $ this -> setState ( 'email' , $ this -> _user -> email ) ; $ this -> setState ( 'username' , $ this -> _user -> username ) ; $ this -> setState ( 'displayName' , $ this -> _user -> username ) ; $ this -> setState ( 'status' , $ this -> _user -> status ) ; $ this -> setState ( 'role' , $ this -> _user -> user_role ) ; $ this -> setstate ( 'apiKey' , $ this -> generateAPIKey ( ) ) ; $ this -> errorCode = self :: ERROR_NONE ; return ; }
Sets the identity attributes
59,312
protected function generateApiKey ( ) { $ factory = new CryptLib \ Random \ Factory ; $ meta = UserMetadata :: model ( ) -> getPrototype ( 'UserMetadata' , array ( 'user_id' => $ this -> getUser ( ) -> id , 'key' => 'api_key' . $ this -> app_name ) , array ( 'user_id' => $ this -> getUser ( ) -> id , 'key' => 'api_key' . $ this -> app_name ) ) ; $ meta -> value = $ factory -> getLowStrengthGenerator ( ) -> generateString ( 16 ) ; if ( $ meta -> save ( ) ) return $ meta -> value ; throw new CHttpException ( 500 , Yii :: t ( 'ciims.models.LoginForm' , 'Unable to create API key, please try again.' ) ) ; }
Generates a new API key for this application
59,313
public static function getInfo ( $ image ) { if ( is_string ( $ image ) && false !== ( $ info = getimagesizefromstring ( $ image ) ) && ! ! ( $ width = $ info [ 0 ] ) && ! ! ( $ height = $ info [ 1 ] ) ) { $ result = imagecreatefromstring ( $ image ) ; } else if ( is_resource ( $ image ) && ! ! ( $ width = imagesx ( $ image ) ) && ! ! ( $ height = imagesy ( $ image ) ) ) { $ result = $ image ; } else { return false ; } return [ 'image' => $ result , 'width' => $ width , 'height' => $ height ] ; }
Returns an array holding width height and an image resource for the specified image . If these details cannot be obtained FALSE is returned .
59,314
public static function parse ( RouteInterface $ route ) { extract ( self :: transpilePattern ( $ route -> getPattern ( ) , false , $ route -> getConstraints ( ) , $ route -> getDefaults ( ) ) ) ; $ host = self :: parseHostVars ( $ route ) ; return new RouteContext ( $ staticPath , $ expression , $ tokens , $ host [ 'expression' ] , $ host [ 'tokens' ] ) ; }
Parses a route object .
59,315
public static function transpilePattern ( $ pattern , $ host = false , array $ requirements = [ ] , array $ defaults = [ ] ) { $ tokens = self :: tokenizePattern ( $ pattern , $ host , $ requirements , $ defaults ) ; $ staticPath = ! $ tokens [ 0 ] instanceof Variable ? $ tokens [ 0 ] -> value : '/' ; $ regex = self :: transpileMatchRegex ( $ tokens ) ; return self :: getCompact ( $ staticPath , $ regex , $ tokens ) ; }
Transpiles the the given pattern into a useful format .
59,316
public static function transpileMatchRegex ( array $ tokens ) { $ regex = [ ] ; foreach ( $ tokens as $ token ) { $ var = $ token instanceof Variable ? $ token : ( $ token instanceof Delimiter ? $ token -> next : null ) ; if ( null !== $ var && $ var instanceof Variable && null !== ( $ optgrp = self :: makeOptGrp ( $ var ) ) ) { $ regex [ ] = $ optgrp ; break ; } $ regex [ ] = $ token ; } return implode ( '' , $ regex ) ; }
Transpiles tokens to a regex .
59,317
private static function makeOptGrp ( Variable $ var ) { if ( $ var -> required ) { return ; } list ( $ next , $ nextIsOpt ) = self :: findNextOpt ( $ var ) ; if ( ! $ nextIsOpt ) { return ; } $ optgrp = null !== $ next ? self :: makeOptGrp ( $ next ) : '' ; $ p = $ var -> prev instanceof Delimiter ? $ var -> prev : '' ; return sprintf ( '(?:%s%s%s)?' , $ p , $ var , $ optgrp ) ; }
Recursively iterates over tailing optional variables .
59,318
private static function findNextOpt ( Variable $ var ) { $ nextIsOpt = true ; $ next = null ; $ n = $ var -> next ; while ( null !== $ n ) { if ( ! $ n instanceof Variable ) { $ n = $ n -> next ; $ nextIsOpt = true ; continue ; } if ( ! $ n -> required ) { $ nextIsOpt = true ; $ next = $ n ; break ; } $ nextIsOpt = false ; $ n = $ n -> next ; } return [ $ next , $ nextIsOpt ] ; }
Finds next optional valiable token
59,319
public function handle ( RequestInterface $ request ) { $ response = $ request -> send ( ) ; $ headers = $ response -> getHeaders ( ) -> getAll ( ) ; $ body = $ response -> getBody ( true ) ; $ statusCode = $ response -> getStatusCode ( ) ; $ symfonyHeaders = array ( ) ; foreach ( $ headers as $ keys ) { if ( $ keys -> getName ( ) == "Transfer-Encoding" && $ keys -> __toString ( ) === 'chunked' ) { continue ; } $ symfonyHeaders [ $ keys -> getName ( ) ] = $ keys -> __toString ( ) ; } return new Response ( $ body , $ statusCode , $ symfonyHeaders ) ; }
This method wrapper Guzzle response in symfony response
59,320
public function sendRequest ( $ method = 'GET' , $ uri = null , $ headers = null , $ body = null ) { $ request = $ this -> createRequest ( $ method , $ uri , $ headers , $ body ) ; return $ this -> handle ( $ request ) ; }
Send a request from client for the api
59,321
public function create_record ( array $ data ) { if ( is_array ( $ data ) && count ( $ data ) ) { $ params = array ( ) ; $ sqlFields = "" ; $ sqlValues = "" ; foreach ( $ data as $ field => $ value ) { $ sqlFields = ToolBox :: create_list ( $ sqlFields , $ field , ", " ) ; $ sqlValues = ToolBox :: create_list ( $ sqlValues , ':' . $ field , ", " ) ; $ params [ $ field ] = $ value ; } $ sql = 'INSERT INTO ' . $ this -> tableName . ' (' . $ sqlFields . ') VALUES (' . $ sqlValues . ')' ; try { $ newId = $ this -> dbObj -> run_insert ( $ sql , $ params , $ this -> seqName ) ; } catch ( Exception $ e ) { throw new Exception ( __METHOD__ . ":: failed to create record, DETAILS::: " . $ e -> getMessage ( ) ) ; } } else { throw new Exception ( __METHOD__ . ":: no data passed" ) ; } return ( $ newId ) ; }
Insert a new record into the table .
59,322
public function get_records ( array $ filter = null , $ orderBy = null , $ limit = null , $ offset = null ) { $ data = null ; $ limitOffsetStr = '' ; if ( is_numeric ( $ limit ) && $ limit > 0 ) { $ limitOffsetStr = ' LIMIT ' . $ limit ; if ( is_numeric ( $ offset ) && $ offset > 0 ) { $ limitOffsetStr .= ' OFFSET ' . $ offset ; } } $ orderByStr = ' ORDER BY ' . $ this -> pkeyField ; if ( is_string ( $ orderBy ) && strlen ( $ orderBy ) ) { $ orderByStr = ' ORDER BY ' . $ orderBy ; } $ filterStr = '' ; $ params = array ( ) ; $ filterStr = "" ; if ( is_array ( $ filter ) && count ( $ filter ) > 0 ) { foreach ( $ filter as $ field => $ value ) { $ filterStr = ToolBox :: create_list ( $ filterStr , $ field . '=:' . $ field , ' AND ' ) ; $ params [ $ field ] = $ value ; } $ filterStr = ' WHERE ' . $ filterStr ; } $ sql = 'SELECT * FROM ' . $ this -> tableName . $ filterStr . $ orderByStr . $ limitOffsetStr ; try { $ numRows = $ this -> dbObj -> run_query ( $ sql , $ params ) ; if ( $ numRows > 0 ) { $ data = $ this -> dbObj -> farray_fieldnames ( $ this -> pkeyField ) ; } } catch ( Exception $ e ) { throw new Exception ( __METHOD__ . ":: failed to retrieve records, DETAILS::: " . $ e -> getMessage ( ) ) ; } return ( $ data ) ; }
Retrieves a number of records based on arguments .
59,323
public function update_record ( $ recId , array $ updates ) { if ( ( ( is_numeric ( $ recId ) && $ recId >= 0 ) OR ( is_array ( $ recId ) && count ( $ recId ) ) ) && is_array ( $ updates ) && count ( $ updates ) > 0 ) { $ updateString = "" ; $ params = array ( ) ; foreach ( $ updates as $ f => $ v ) { $ updateString = ToolBox :: create_list ( $ updateString , $ f . '=:' . $ f , ', ' ) ; $ params [ $ f ] = $ v ; } if ( is_array ( $ recId ) ) { foreach ( $ recId as $ f => $ v ) { $ whereClause = ToolBox :: create_list ( $ whereClause , $ f . '=:' . $ f , ' AND ' ) ; $ params [ $ f ] = $ v ; } } else { $ whereClause = $ this -> pkeyField . '=:id' ; $ params [ 'id' ] = $ recId ; } $ sql = 'UPDATE ' . $ this -> tableName . ' SET ' . $ updateString . ' WHERE ' . $ whereClause ; try { $ retval = $ this -> dbObj -> run_update ( $ sql , $ params ) ; } catch ( Exception $ e ) { throw new Exception ( __METHOD__ . ":: failed to update record (" . $ recId . "), DETAILS::: " . $ e -> getMessage ( ) ) ; } } }
Update a single record with the given changes .
59,324
public function execute ( array $ variables = null ) { if ( null === $ variables ) { $ variables = $ _SERVER ; } $ arguments = $ this -> arguments ( $ variables ) ; if ( count ( $ arguments ) < 1 ) { throw new RuntimeException ( 'No arguments provided.' ) ; } switch ( $ arguments [ 0 ] ) { case '-h' : case '--help' : $ this -> executeUsage ( ) ; return ; case '-v' : case '--version' : $ this -> executeVersion ( ) ; return ; } $ this -> executeLaunch ( $ arguments ) ; }
Runs the Liftoff command line application .
59,325
protected function arguments ( array $ variables ) { if ( ! array_key_exists ( 'argv' , $ variables ) || ! is_array ( $ variables [ 'argv' ] ) ) { throw new RuntimeException ( 'Unable to determine arguments.' ) ; } $ arguments = $ variables [ 'argv' ] ; array_shift ( $ arguments ) ; return $ arguments ; }
Parse the command line arguments from the supplied environment variables .
59,326
public function prepareForm ( ModelInterface $ model = null , array $ data = null , $ useInputFilter = false , $ useHydrator = false ) { $ argv = compact ( 'model' , 'data' ) ; $ argv = $ this -> prepareEventArguments ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( self :: EVENT_PRE_PREPARE_FORM , $ this , $ argv ) ; $ data = $ argv [ 'data' ] ; $ form = $ this -> getForm ( null , $ this -> formOptions ) ; if ( $ useInputFilter ) { $ form -> setInputFilter ( $ this -> getInputFilter ( ) ) ; } if ( $ useHydrator ) { $ form -> setHydrator ( $ this -> getHydrator ( ) ) ; } if ( $ model ) { $ form -> bind ( $ model ) ; } if ( $ data ) { $ form -> setData ( $ data ) ; } $ argv = compact ( 'form' , 'model' , 'data' ) ; $ argv = $ this -> prepareEventArguments ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( self :: EVENT_POST_PREPARE_FORM , $ this , $ argv ) ; return $ form ; }
Prepares form for the service .
59,327
public function getForm ( string $ name = null , array $ options = [ ] ) : Form { $ name = $ name ?? $ this -> form ?? $ this -> serviceAlias ; $ sl = $ this -> getServiceLocator ( ) ; $ formElementManager = $ sl -> get ( 'FormElementManager' ) ; $ argv = compact ( 'options' ) ; $ argv = $ this -> prepareEventArguments ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( self :: EVENT_PRE_FORM_INIT , $ this , $ argv ) ; $ form = $ formElementManager -> get ( $ name , $ options ) ; $ argv = compact ( 'form' , 'options' ) ; $ argv = $ this -> prepareEventArguments ( $ argv ) ; $ this -> getEventManager ( ) -> trigger ( self :: EVENT_POST_FORM_INIT , $ this , $ argv ) ; return $ form ; }
Gets the default form or on specified for the service .
59,328
public function getModel ( $ model = null ) { $ model = $ model ?? $ this -> model ?? $ this -> serviceAlias ; $ sl = $ this -> getServiceLocator ( ) ; $ modelManager = $ sl -> get ( ModelManager :: class ) ; $ model = $ modelManager -> get ( $ model ) ; return $ model ; }
Gets model from ModelManager
59,329
public function getInputFilter ( $ inputFilter = null ) { $ inputFilter = $ inputFilter ?? $ this -> inputFilter ?? $ this -> serviceAlias ; $ sl = $ this -> getServiceLocator ( ) ; $ inputFilterManager = $ sl -> get ( 'InputFilterManager' ) ; $ inputFilter = $ inputFilterManager -> get ( $ inputFilter ) ; return $ inputFilter ; }
Gets input filter from InputFilterManager
59,330
public function getHydrator ( $ hydrator = null ) { $ hydrator = $ hydrator ?? $ this -> hydrator ?? $ this -> serviceAlias ; $ sl = $ this -> getServiceLocator ( ) ; $ hydratorManager = $ sl -> get ( 'HydratorManager' ) ; $ hydrator = $ hydratorManager -> get ( $ hydrator ) ; return $ hydrator ; }
Gets hydrator from HydratorManager
59,331
public function getAction ( Request $ request , $ name ) { $ value = $ this -> getDynamicVariableManager ( ) -> getVariableValueByName ( $ name ) ; $ view = $ this -> view ( $ value ) ; return $ this -> handleView ( $ view ) ; }
Get value by code from variables vars
59,332
protected function createFile ( $ filePath , $ contents ) { $ this -> createDirectory ( dirname ( $ filePath ) ) ; if ( is_file ( $ filePath ) ) { $ this -> output -> setDecorated ( true ) ; $ this -> output -> writeln ( sprintf ( "<comment>file exists <cyan>%s</cyan></comment>" , $ this -> prettyPath ( $ filePath ) ) ) ; } else { $ this -> output -> writeln ( sprintf ( "<info>create <cyan>%s</cyan></info>" , $ this -> prettyPath ( $ filePath ) ) ) ; file_put_contents ( $ filePath , $ contents ) ; } }
Creates a file with console otput .
59,333
protected function createDirectory ( $ dirPath ) { if ( ! is_dir ( $ dirPath ) ) { $ this -> output -> writeln ( sprintf ( "<info>create <cyan>%s</cyan></info>" , $ this -> prettyPath ( $ dirPath ) ) ) ; mkdir ( $ dirPath , 0775 , true ) ; } }
Creates a directory with console otput .
59,334
public function clear ( ) { $ this -> setCookies ( array ( ) ) ; $ this -> setStatusCode ( 200 ) ; $ this -> setHeaders ( array ( ) ) ; $ this -> setHeader ( 'Content-Type' , 'application/json; charset=utf8' ) ; $ this -> setCacheControl ( 'no-cache' ) ; $ this -> setCharSet ( 'utf8' ) ; $ this -> setBody ( '' ) ; $ this -> setFileBody ( '' ) ; return $ this ; }
clear - Clear all properties
59,335
public function setCompression ( bool $ active = true , int $ level = - 1 ) { if ( $ active ) { $ acceptEncoding = getAllheaders ( ) [ 'Accept-Encoding' ] ?? '' ; if ( strpos ( $ acceptEncoding , 'gzip' ) !== FALSE ) { ini_set ( "zlib.output_compression" , 2048 ) ; ini_set ( "zlib.output_compression_level" , - 1 ) ; } else { ini_set ( "zlib.output_compression_level" , 0 ) ; } } else { ini_set ( "zlib.output_compression_level" , 0 ) ; } return $ this ; }
Sets Output Compression On or OFf
59,336
public function send ( ) { http_response_code ( $ this -> statusCode ) ; if ( empty ( $ this -> getHeader ( 'Cache-Control' ) ) ) { $ this -> setHeader ( 'Cache-Control' , $ this -> cacheControl ) ; } foreach ( $ this -> headers as $ header => $ value ) { header ( $ header . ': ' . $ value ) ; } foreach ( $ this -> cookies as $ idx => $ cookie ) { setCookie ( $ cookie [ 'name' ] , $ cookie [ 'value' ] , $ cookie [ 'expire' ] , $ cookie [ 'path' ] , $ cookie [ 'domain' ] , $ cookie [ 'secure' ] , $ cookie [ 'httponly' ] ) ; } if ( ! empty ( $ this -> getBody ( ) ) ) { echo $ this -> getBody ( ) ; } else if ( ! empty ( $ this -> getFileBody ( ) ) ) { readfile ( $ this -> getFileBody ( ) ) ; } return $ this ; }
Send response to client
59,337
public function getHeader ( string $ header , string $ default = '' ) : string { return array_change_key_case ( $ this -> headers , CASE_LOWER ) [ strtolower ( $ header ) ] ?? $ default ; }
Gets the value of a header
59,338
public function setJsonBody ( array $ data , int $ options = JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK ) { $ this -> setContentType ( 'application/json' ) -> setBody ( json_encode ( $ data , $ options ) ) ; return $ this ; }
setJsonBody - Encodes array as JSON response
59,339
public function setFileBody ( string $ fileBody , string $ contentType = '' ) { $ this -> setBody ( '' ) ; if ( ! empty ( $ contentType ) ) { $ this -> setContentType ( $ contentType ) ; } $ this -> fileBody = $ fileBody ; return $ this ; }
Set a file as the response with optional content - type
59,340
public function setCookie ( string $ name , string $ value = '' , int $ expire = 0 , string $ path = '' , string $ domain = '' , bool $ secure = false , bool $ httponly = false ) { $ cookie = array ( ) ; $ cookie [ 'name' ] = $ name ; $ cookie [ 'value' ] = $ value ; $ cookie [ 'expire' ] = $ expire ; $ cookie [ 'path' ] = $ path ; $ cookie [ 'domain' ] = $ domain ; $ cookie [ 'secure' ] = $ secure ; $ cookie [ 'httponly' ] = $ httponly ; $ this -> cookies [ $ name ] = $ cookie ; return $ this ; }
Sets a Cookie in the Response
59,341
protected function getPageUrls ( $ SHDObject ) { $ urls = array ( ) ; foreach ( $ SHDObject -> find ( '.txt_lg' ) as $ object ) { $ href = $ object -> href ; $ urls [ ] = $ this -> cleanUrl ( $ href , array ( '/^\/url\?q=/' , '/\/&amp;sa=.*/' , '/&amp;sa.*/' ) ) ; } return $ this -> normalizeResult ( $ urls ) ; }
Get all urls for a given Ask SERP page .
59,342
protected function initDirection ( string $ direction ) { $ direction = \ strtoupper ( \ trim ( $ direction ) ) ; if ( \ strlen ( $ direction ) != 1 ) { throw new GISError ( GISError :: ERROR_TYPE_DIRECTION , \ sprintf ( "'%s' is not allowed." , $ direction ) ) ; } if ( 'O' == $ direction ) { $ direction = 'E' ; } $ allowedDirections = $ this -> properties [ 'islatitude' ] ? array ( 'N' , 'S' ) : array ( 'E' , 'W' ) ; if ( ! \ in_array ( $ direction , $ allowedDirections ) ) { throw new GISError ( GISError :: ERROR_TYPE_DIRECTION , \ sprintf ( "'%s' isnt allowed. Please use '%s'" , $ direction , \ join ( "' or '" , $ allowedDirections ) ) ) ; } $ this -> properties [ 'direction' ] = $ direction ; }
Changes the current direction value .
59,343
protected function initMinutes ( $ minutes , $ seconds ) { if ( ! TypeTool :: IsDecimal ( $ minutes ) ) { throw new GISError ( GISError :: ERROR_TYPE_MINUTES , \ sprintf ( "'%s' is not of required decimal number format." , $ minutes ) ) ; } $ this -> extractTime ( $ minutes , $ seconds ) ; }
Changes the current minutes value .
59,344
public function copyWithFile ( $ object , $ file ) { if ( $ object instanceof \ Puzzlout \ Framework \ Interfaces \ IDocument ) { $ object -> setFilename ( $ this -> GetFileNameToSaveInDatabase ( $ file ) ) ; $ fileExists = \ Puzzlout \ Framework \ Core \ DirectoryManager :: FileExists ( $ this -> GetUploadDirectory ( $ object ) . "/" . $ object -> Filename ( ) ) ; $ extensions = $ object -> ValidExtensions ( ) ; if ( is_array ( $ extensions ) ) { $ validExtension = $ this -> CheckExtension ( $ file , $ extensions ) ; } else { $ validExtension = true ; } if ( ! $ fileExists && $ validExtension ) { \ Puzzlout \ Framework \ Core \ DirectoryManager :: CreateDirectory ( $ this -> GetUploadDirectory ( $ object ) ) ; $ object -> setContentSize ( $ this -> GetSizeInKb ( $ file ) ) ; $ object -> setContentType ( $ this -> GetExtension ( $ file ) ) ; if ( copy ( $ file [ 'tmp_name' ] , $ this -> GetUploadDirectory ( $ object ) . '/' . $ object -> Filename ( ) ) ) { return parent :: add ( $ object ) ; } } else { return - 1 ; } } }
Location specific PDF document requirement Copies the file which is passed to it with the generated name
59,345
private function getResolvableValue ( \ Twig_Node_Expression $ node ) { if ( $ node instanceof \ Twig_Node_Expression_Constant && 'not_used' !== $ node -> getAttribute ( 'value' ) ) { return $ node -> getAttribute ( 'value' ) ; } return false ; }
Check an expression node to be sure it is a constant value we can resolve at compile time .
59,346
protected function getQuery ( $ table = null ) { $ qSchema = $ this -> adapter -> quoteValue ( $ this -> schema ) ; if ( $ table !== null ) { $ qTable = $ this -> adapter -> quoteValue ( $ table ) ; $ table_clause = "and (t.TABLE_NAME = $qTable or (kcu.referenced_table_name = $qTable and kcu.constraint_name = 'FOREIGN KEY'))" ; $ table_join_condition = '(t.table_name = kcu.table_name or kcu.referenced_table_name = t.table_name)' ; } else { $ table_join_condition = 't.table_name = kcu.table_name' ; $ table_clause = '' ; } $ query = " SELECT t.table_name, c.column_name, c.data_type, c.column_type, c.extra, tc.constraint_type, kcu.constraint_name, kcu.referenced_table_name, kcu.referenced_column_name, c.column_default, c.is_nullable, c.numeric_precision, c.numeric_scale, c.character_octet_length, c.character_maximum_length, c.ordinal_position, c.column_key, -- UNI/MUL/PRI c.character_set_name, c.collation_name, c.column_comment, t.table_type, t.engine, t.table_comment, t.table_collation FROM `INFORMATION_SCHEMA`.`COLUMNS` c INNER JOIN `INFORMATION_SCHEMA`.`TABLES` t on c.TABLE_NAME = t.TABLE_NAME LEFT JOIN `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` kcu on ( $table_join_condition and kcu.table_schema = t.table_schema and kcu.column_name = c.column_name ) LEFT JOIN `INFORMATION_SCHEMA`.`TABLE_CONSTRAINTS` tc on ( t.table_name = tc.table_name and tc.table_schema = t.table_schema and tc.constraint_name = kcu.constraint_name ) where c.TABLE_SCHEMA = $qSchema and t.TABLE_SCHEMA = $qSchema $table_clause and (kcu.table_schema = $qSchema or kcu.table_schema is null) and (kcu.column_name = c.column_name or kcu.column_name is null) order by t.table_name, c.ordinal_position " ; return $ query ; }
Return information schema query .
59,347
protected function executeQuery ( $ table = null ) { $ query = $ this -> getQuery ( $ table ) ; $ this -> disableInnoDbStats ( ) ; try { $ results = $ this -> adapter -> query ( $ query ) -> getArrayObject ( ) ; } catch ( \ Exception $ e ) { $ this -> restoreInnoDbStats ( ) ; throw new Exception \ ErrorException ( __METHOD__ . ': ' . $ e -> getMessage ( ) ) ; } $ this -> restoreInnoDbStats ( ) ; return $ results ; }
Execute information schema query .
59,348
public static function createContactsFromObjects ( array $ objects = null ) { if ( $ objects === null ) { return null ; } $ contacts = [ ] ; foreach ( $ objects as $ object ) { $ contact = new static ( ) ; $ contact -> updateFromObject ( $ object ) ; $ contacts [ ] = $ contact ; } return $ contacts ; }
Create an array of contacts from an array of stdClass objects .
59,349
private function getCustomerBalanceBase ( \ Magento \ Quote \ Model \ Quote $ quote ) { $ result = 0 ; $ customerId = $ quote -> getCustomerId ( ) ; $ storeId = $ quote -> getStoreId ( ) ; if ( $ customerId ) { $ account = $ this -> daoAccount -> getCustomerAccByAssetCode ( $ customerId , Cfg :: CODE_TYPE_ASSET_WALLET ) ; if ( $ account ) { $ result = $ account -> getBalance ( ) ; $ result = $ this -> hlpWalletCur -> walletToStore ( $ result , $ storeId ) ; $ result = $ this -> hlpFormat -> toNumber ( $ result ) ; } } return $ result ; }
Get customer balance nominated in base currency .
59,350
private function validateBalance ( $ quote , $ balanceBase , $ partialBase , $ partial ) { if ( $ partialBase > $ balanceBase ) { if ( $ balanceBase > 0 ) { $ partialBase = $ balanceBase ; $ currTo = $ quote -> getQuoteCurrencyCode ( ) ; $ partial = $ this -> priceCurrency -> convertAndRound ( $ partialBase , null , $ currTo ) ; } else { $ partial = $ partialBase = 0 ; } } return [ $ partialBase , $ partial ] ; }
Partial amounts should not be greater then customer balance .
59,351
public function beforeValidate ( $ event ) { $ formName = $ event -> sender -> formName ( ) ; $ primaryKey = $ event -> sender -> primaryKey ; $ sender = $ event -> sender ; $ metaTags = $ sender -> { $ this -> relationName } ; if ( ! $ metaTags ) { $ metaTags = Yii :: createObject ( MetaTags :: class ) ; $ metaTags -> model = $ formName ; $ metaTags -> model_id = $ primaryKey ; $ metaTags -> language = $ this -> lang ( ) ; $ metaTags -> load ( Yii :: $ app -> request -> post ( ) ) ; } $ sender -> populateRelation ( $ this -> relationName , $ metaTags ) ; }
before validate event function - populate relation
59,352
public function delete ( $ event ) { $ formName = $ event -> sender -> formName ( ) ; $ primaryKey = $ event -> sender -> primaryKey ; $ this -> model :: deleteAll ( [ 'model' => $ formName , 'model_id' => $ primaryKey , ] ) ; }
Delete event function
59,353
public function handleCommand ( Event $ event , Queue $ queue ) { $ queue -> ircPrivmsg ( $ event -> getSource ( ) , $ this -> getResponse ( $ event ) ) ; }
Handle the main pong command
59,354
public function handleCommandHelp ( Event $ event , Queue $ queue ) { foreach ( $ this -> getHelpLines ( ) as $ helpLine ) { $ queue -> ircPrivmsg ( $ event -> getSource ( ) , $ helpLine ) ; } }
Handle the help command
59,355
final public function setDomain ( $ dir , $ domain , $ codeset = 'UTF-8' ) { bindtextdomain ( $ domain , $ dir ) ; bind_textdomain_codeset ( $ domain , $ codeset ) ; $ this -> domains [ ] = $ domain ; return $ this ; }
Set domain name .
59,356
public function setDomainWithAlias ( $ alias , $ dir , $ domain , $ codeset = 'UTF-8' ) { $ this -> setDomain ( $ dir , $ domain , $ codeset ) ; $ this -> aliases [ $ alias ] = $ domain ; return $ this ; }
Set domain name with it s alias .
59,357
public function getDomain ( $ alias ) { if ( isset ( $ this -> aliases [ $ alias ] ) ) { return $ this -> aliases [ $ alias ] ; } return $ alias ; }
Provide domain name by it s alias .
59,358
public function withExpression ( string $ expression ) : self { if ( ! ( new \ ReflectionClass ( $ expression ) ) -> implementsInterface ( Expression :: class ) ) { throw new DomainException ( $ expression ) ; } $ self = clone $ this ; $ self -> expression = new $ expression ( $ self -> name ) ; return $ self ; }
Not ideal technic but didn t find a better to reduce duplicated code
59,359
protected function _prefixField ( $ pField , $ pDbContainer = NULL ) { if ( $ pDbContainer === NULL ) { $ dbContainer = $ this -> _dbContainer ; } else { $ dbContainer = $ pDbContainer ; } return $ dbContainer . static :: PREFIX_SEPARATOR . $ pField ; }
Prefix field according to DB container .
59,360
protected function _loadByAttribute ( $ pAttribute , $ pValue , array $ pArgs = array ( ) ) { $ args = $ pArgs ; if ( ! isset ( $ args [ DbInterface :: FILTER_CONDITIONS ] ) or ! $ args [ DbInterface :: FILTER_CONDITIONS ] instanceof Conditions ) { $ args [ DbInterface :: FILTER_CONDITIONS ] = new Conditions ( ) ; } $ args [ DbInterface :: FILTER_CONDITIONS ] -> add ( $ pAttribute , Conditions :: EQ , $ pValue ) ; return $ this -> load ( $ args ) ; }
Load item by attribute code and value .
59,361
public function loadById ( $ pId ) { if ( ! $ pId instanceof Id ) { $ id = new Id ( $ pId ) ; } else { $ id = $ pId ; } return $ this -> _loadByAttribute ( static :: IDFIELD , $ id -> getOrig ( ) ) ; }
Load item by ID .
59,362
public function load ( $ pArgs = array ( ) ) { if ( ! is_array ( $ pArgs ) ) { return $ this -> loadById ( $ pArgs ) ; } $ select = new Select ( $ this -> _dbContainer ) ; if ( isset ( $ pArgs [ DbInterface :: FILTER_ORDER ] ) ) { $ select -> addOrder ( $ pArgs [ DbInterface :: FILTER_ORDER ] ) ; } else { $ select -> addOrder ( array ( $ this -> getIdField ( ) => Db :: ORDER_DESC ) ) ; } if ( isset ( $ pArgs [ DbInterface :: FILTER_CONDITIONS ] ) and $ pArgs [ DbInterface :: FILTER_CONDITIONS ] instanceof Conditions ) { $ select -> loadConditions ( $ pArgs [ DbInterface :: FILTER_CONDITIONS ] ) ; } $ select -> findOne ( ) ; if ( $ select -> count ( ) ) { $ fields = $ select -> fetchAll ( true ) ; } else { $ fields = array ( ) ; } $ this -> _fields = $ fields ; $ this -> _origFields = $ fields ; $ idField = $ this -> getIdField ( ) ; if ( isset ( $ this -> _fields [ $ idField ] ) ) { $ this -> setId ( $ this -> _fields [ $ idField ] ) ; } return $ this ; }
Load an item with conditions filtering .
59,363
public function setId ( $ pValue ) { $ idField = $ this -> _dbContainer . static :: PREFIX_SEPARATOR . static :: IDFIELD ; if ( ! $ pValue instanceof Id ) { $ id = new Id ( $ pValue ) ; } else { $ id = $ pValue ; } $ this -> _fields [ $ idField ] = $ id ; $ this -> _origFields [ $ idField ] = $ id ; return $ this ; }
Set the Item ID .
59,364
public function getIdField ( $ pDbContainer = NULL ) { if ( $ pDbContainer === NULL ) { $ pDbContainer = $ this -> _dbContainer ; } return $ pDbContainer . static :: PREFIX_SEPARATOR . static :: IDFIELD ; }
Return the prefixed ID field name .
59,365
public function getFieldValue ( $ pField , $ pRaw = false ) { if ( ! $ pRaw ) { $ field = $ this -> _dbContainer . static :: PREFIX_SEPARATOR . $ pField ; } else { $ field = $ pField ; } if ( isset ( $ this -> _fields [ $ field ] ) ) { return $ this -> _fields [ $ field ] ; } return NULL ; }
Return the value corresponding to and attribute code if exists .
59,366
public function getOrigFieldValue ( $ pField , $ pRaw = false ) { if ( ! $ pRaw ) { $ field = $ this -> _dbContainer . static :: PREFIX_SEPARATOR . $ pField ; } else { $ field = $ pField ; } if ( isset ( $ this -> _origFields [ $ field ] ) ) { return $ this -> _origFields [ $ field ] ; } return NULL ; }
Return the value corresponding to and attribute code if exists . Search in the origFields array .
59,367
public function save ( ) { if ( ! $ this -> getOrigFieldValue ( static :: IDFIELD ) ) { throw new Exception ( "Cannot save an item without ID" ) ; } Observer :: dispatch ( Observer :: EVENT_ITEM_SAVE_BEFORE , array ( 'item' => $ this ) ) ; $ this -> { static :: DATEUPDATEFIELD } = DateData :: now ( ) ; $ update = new Update ( $ this ) ; $ update -> commit ( ) ; $ this -> _origFields = $ this -> _fields ; Observer :: dispatch ( Observer :: EVENT_ITEM_SAVE_AFTER , array ( 'item' => $ this ) ) ; return $ this ; }
Save the item in the database . By default the update query is conditioned to the item s ID .
59,368
public function insert ( ) { Observer :: dispatch ( Observer :: EVENT_ITEM_INSERT_BEFORE , array ( 'item' => $ this ) ) ; $ this -> { static :: DATEADDFIELD } = DateData :: now ( ) ; $ insert = new Insert ( $ this -> _dbContainer ) ; $ insert -> addFields ( $ this -> _fields ) ; $ insert -> commit ( ) ; $ this -> setId ( $ insert -> getId ( ) ) ; $ this -> _origFields = $ this -> _fields ; Observer :: dispatch ( Observer :: EVENT_ITEM_INSERT_AFTER , array ( 'item' => $ this ) ) ; return $ this ; }
Insert a new item in the database .
59,369
public function delete ( $ pWithChilds = false ) { Observer :: dispatch ( Observer :: EVENT_ITEM_DELETE_BEFORE , array ( 'item' => $ this ) ) ; $ delete = new Delete ( $ this ) ; $ delete -> commit ( $ pWithChilds ) ; Observer :: dispatch ( Observer :: EVENT_ITEM_DELETE_AFTER , array ( 'item' => $ this ) ) ; return $ this ; }
Delete the item from the database .
59,370
public function getParents ( $ pDbContainer , array $ pArgs = array ( ) , $ pFirst = false ) { Agl :: validateParams ( array ( 'RewritedString' => $ pDbContainer ) ) ; if ( ! $ this -> getId ( ) ) { throw new Exception ( "getParents: Item must exist in database" ) ; } $ args = $ pArgs ; if ( isset ( $ args [ DbInterface :: FILTER_CONDITIONS ] ) and $ args [ DbInterface :: FILTER_CONDITIONS ] instanceof Conditions ) { $ conditions = $ args [ DbInterface :: FILTER_CONDITIONS ] ; } else { $ conditions = new Conditions ( ) ; } $ ids = $ this -> getFieldValue ( $ this -> _prefixField ( static :: IDFIELD , $ pDbContainer ) , true ) ; if ( $ ids === NULL ) { if ( $ pFirst ) { return Agl :: getModel ( $ pDbContainer ) ; } return Agl :: getCollection ( $ pDbContainer ) ; } $ conditions -> add ( static :: IDFIELD , Conditions :: IN , array ( $ ids ) ) ; $ args [ DbInterface :: FILTER_CONDITIONS ] = $ conditions ; if ( $ pFirst ) { $ args [ DbInterface :: FILTER_LIMIT ] = array ( 0 , 1 ) ; } $ collection = Agl :: getCollection ( $ pDbContainer ) ; $ collection -> load ( $ args ) ; if ( $ pFirst ) { if ( $ collection -> count ( ) ) { return $ collection -> current ( ) ; } return Agl :: getModel ( $ pDbContainer ) ; } return $ collection ; }
Return a collection of parents or a single parent in the required collection .
59,371
public function getChilds ( $ pDbContainer , array $ pArgs = array ( ) , $ pFirst = false ) { Agl :: validateParams ( array ( 'RewritedString' => $ pDbContainer ) ) ; if ( ! $ this -> getId ( ) ) { throw new Exception ( "getChilds: Item must exist in database" ) ; } $ args = $ pArgs ; if ( isset ( $ args [ DbInterface :: FILTER_CONDITIONS ] ) and $ args [ DbInterface :: FILTER_CONDITIONS ] instanceof Conditions ) { $ conditions = $ args [ DbInterface :: FILTER_CONDITIONS ] ; } else { $ conditions = new Conditions ( ) ; } $ conditions -> addGroup ( array ( $ this -> getIdField ( ) , Conditions :: EQ , $ this -> getId ( ) ) , array ( $ this -> getIdField ( ) , Conditions :: INSET , $ this -> getId ( ) ) ) ; $ args [ DbInterface :: FILTER_CONDITIONS ] = $ conditions ; if ( $ pFirst ) { $ args [ DbInterface :: FILTER_LIMIT ] = array ( 0 , 1 ) ; } $ collection = Agl :: getCollection ( $ pDbContainer ) ; $ collection -> load ( $ args ) ; if ( $ pFirst ) { if ( $ collection -> count ( ) ) { return $ collection -> current ( ) ; } return Agl :: getModel ( $ pDbContainer ) ; } return $ collection ; }
Return a collection of childs or a single child in the required collection .
59,372
public function addParent ( ItemAbstract $ pItem ) { if ( ! $ pItem -> getId ( ) ) { throw new Exception ( "addParent: Parent must exist in database" ) ; } $ parentsValue = $ this -> getFieldValue ( $ pItem -> getIdField ( ) , true ) ; if ( ! $ parentsValue ) { $ parents = array ( ) ; } else { $ parents = explode ( ',' , $ parentsValue ) ; } $ parents [ ] = $ pItem -> getId ( ) -> getOrig ( ) ; $ parents = array_unique ( $ parents ) ; $ this -> _fields [ $ pItem -> getIdField ( ) ] = implode ( ',' , $ parents ) ; return $ this ; }
Add a parent relation to the current Item .
59,373
public function removeParent ( ItemAbstract $ pItem ) { if ( ! $ pItem -> getId ( ) ) { throw new Exception ( "addParent: Parent must exist in database" ) ; } $ parentsValue = $ this -> getFieldValue ( $ pItem -> getIdField ( ) , true ) ; if ( ! $ parentsValue ) { $ parents = array ( ) ; } else { $ parents = explode ( ',' , $ parentsValue ) ; } $ key = array_search ( $ pItem -> getId ( ) -> getOrig ( ) , $ parents ) ; if ( $ key !== false ) { unset ( $ parents [ $ key ] ) ; } if ( empty ( $ parents ) ) { $ this -> _fields [ $ pItem -> getIdField ( ) ] = NULL ; } else { $ this -> _fields [ $ pItem -> getIdField ( ) ] = implode ( ',' , $ parents ) ; } return $ this ; }
Remove a parent relation to the current Item .
59,374
public function removeChilds ( $ pDbContainer = NULL ) { if ( $ pDbContainer === NULL ) { $ containers = Agl :: app ( ) -> getDb ( ) -> listCollections ( array ( $ this -> getIdField ( ) ) ) ; } else { $ containers = array ( $ pDbContainer ) ; } foreach ( $ containers as $ container ) { if ( $ container === $ this -> getDbContainer ( ) ) { continue ; } $ childs = $ this -> getChilds ( $ container ) ; foreach ( $ childs as $ child ) { $ child -> removeParent ( $ this ) -> save ( ) ; } } return $ this ; }
Remove Item s childs in the given DB container or in all containers .
59,375
public function build ( ) { if ( isset ( $ this -> attribute [ 'href' ] ) && ( ! isset ( $ this -> attribute [ 'alt' ] ) ) ) { $ this -> attribute [ 'alt' ] = $ this -> attribute [ 'href' ] ; } return parent :: build ( ) ; }
Build method with href and set alt check
59,376
public function add ( $ error , $ key = NULL ) { if ( $ key ) { $ errorContainer = $ this -> get ( $ key , new static ( ) ) ; $ errorContainer -> push ( $ error ) ; $ this [ $ key ] = $ errorContainer ; } else { $ this -> push ( $ error ) ; } }
Add an error to the collection
59,377
public function parse ( \ Request $ request ) { $ uri = $ request -> uri -> get ( ) ; $ method = $ request -> get_method ( ) ; if ( $ uri === '' and $ this -> path === '_root_' ) { return $ this -> matched ( ) ; } $ result = $ this -> _parse_search ( $ uri , null , $ method ) ; if ( $ result ) { return $ result ; } return false ; }
Attempts to find the correct route for the given URI
59,378
public function matched ( $ uri = '' , $ named_params = array ( ) ) { foreach ( $ named_params as $ key => $ val ) { if ( is_numeric ( $ key ) ) { unset ( $ named_params [ $ key ] ) ; } } $ this -> named_params = $ named_params ; if ( $ this -> translation instanceof \ Closure ) { $ this -> callable = $ this -> translation ; } else { $ path = $ this -> translation ; if ( $ uri != '' ) { if ( $ this -> strip_extension and strrchr ( $ uri , '.' ) == $ ext = '.' . \ Input :: extension ( ) ) { $ uri = substr ( $ uri , 0 , - ( strlen ( $ ext ) ) ) ; } if ( $ this -> case_sensitive ) { $ path = preg_replace ( '#^' . $ this -> search . '$#uD' , $ this -> translation , $ uri ) ; } else { $ path = preg_replace ( '#^' . $ this -> search . '$#uiD' , $ this -> translation , $ uri ) ; } } $ this -> segments = explode ( '/' , trim ( $ path , '/' ) ) ; } return $ this ; }
Parses a route match and returns the controller action and params .
59,379
public static function homePage ( ) { if ( ! class_exists ( 'SiteTree' ) || self :: $ site_home ) { return self :: $ site_home ; } $ home = null ; if ( class_exists ( 'HomePage' ) ) { $ home = DataList :: create ( 'HomePage' ) -> first ( ) ; } if ( ! $ home ) { $ home = \ SiteTree :: get_by_link ( \ RootUrlController :: get_homepage_link ( ) ) ; } if ( ! $ home ) { $ home = DataList :: create ( 'Page' ) -> first ( ) ; } self :: $ site_home = $ home ; return $ home ; }
Get home page
59,380
public static function query_string ( $ request = null ) { if ( ! $ request ) { $ request = Controller :: curr ( ) -> Request ; } if ( ! $ request ) { return '' ; } $ vars = $ request -> getVars ( ) ; if ( isset ( $ vars [ 'url' ] ) ) { unset ( $ vars [ 'url' ] ) ; } return empty ( $ vars ) ? '' : '?' . http_build_query ( $ vars ) ; }
Convert the get vars into a query string automatically eliminates the url get var
59,381
protected function setCast ( $ key , $ value ) { if ( is_null ( $ value ) ) { return $ value ; } $ type = $ this -> getCastType ( $ key ) ; $ method = 'setCast' . Str :: studly ( $ type ) . 'Type' ; if ( method_exists ( $ this , $ method ) ) { return $ this -> $ method ( $ key , $ value ) ; } return $ value ; }
Set an attribute and cast value to a native PHP type .
59,382
protected function setCasStringType ( $ key , $ value ) { if ( ( $ key == '_id' ) && ( is_string ( $ value ) ) ) { return Builder :: convertKey ( $ value ) ; } return trim ( ( string ) $ value ) ; }
SET Type string and _id .
59,383
protected function setCastDatetimeType ( $ key , $ value ) { if ( $ value instanceof UTCDateTime ) { return $ value ; } $ value = $ this -> getCastDateTimeType ( $ key , $ value ) ; return new UTCDateTime ( $ value -> getTimestamp ( ) * 1000 ) ; }
SET Type datetime .
59,384
public function addArticleItem ( WxSendNewsMsgItem $ item ) { if ( sizeof ( $ this -> articles ) >= self :: MAX_ITEMS_COUNT ) { array_shift ( $ this -> articles ) ; } $ this -> articles [ ] = $ item ; }
add a article item
59,385
public function fire ( $ name , $ params = [ ] ) { if ( $ this -> prefixEventName === null ) { $ reflector = new \ ReflectionClass ( $ this ) ; $ this -> prefixEventName = 'e' . $ reflector -> getShortName ( ) ; } $ event = new Event ( $ params ) ; if ( method_exists ( $ this , $ this -> prefixEventHandler . $ name ) ) { call_user_func ( [ $ this , $ this -> prefixEventHandler . $ name ] , $ event ) ; } Yii :: $ app -> trigger ( $ this -> prefixEventName . ucfirst ( $ name ) , $ event ) ; }
Trigger global event
59,386
public function consumeReadBuffer ( int $ bytes ) : string { if ( $ this -> getBufferLength ( ) < $ bytes ) { throw new \ RuntimeException ( "BufferedSocket::getAndConsumeReadBuffer requested more bytes than are currently available. Requested=" . $ bytes . ", available=" . $ this -> getBufferLength ( ) . "." ) ; } $ data = \ substr ( $ this -> getReadBuffer ( ) , 0 , $ bytes ) ; $ this -> reduceReadBuffer ( $ bytes ) ; return $ data ; }
This is a convenience method for when you know the exact size of the message
59,387
protected function getListCommands ( ) { $ commands = $ this -> application -> all ( ) ; $ commandsArray = array ( ) ; foreach ( $ commands as $ command ) { $ commandsArray [ ] = array ( 'class' => get_class ( $ command ) , 'name' => $ command -> getName ( ) ) ; } return $ commandsArray ; }
Get list commands to array strings
59,388
protected function initSymfonyConsoleProvider ( ) { if ( ! $ this -> mvc -> hasCvpp ( 'symfony.console' ) ) { $ this -> mvc -> registerProvider ( new ConsoleSymfonyProvider ( array ( 'modules' => $ this -> mvc -> setModules ( ) , 'commands' => array ( new ListCommand ( ) ) ) ) ) ; } return $ this ; }
Init the Symfony Console Provider
59,389
public function clear ( ? string $ documentClass = null ) : void { if ( null === $ documentClass ) { $ this -> identityMap = $ this -> objects = $ this -> documentStates = $ this -> documentPersisters = $ this -> documentDeletions = $ this -> documentUpdates = $ this -> documentChangeSets = $ this -> readOnlyObjects = $ this -> originalDocumentData = [ ] ; } else { throw new \ Exception ( 'Not implemented yet.' ) ; } if ( $ this -> evm -> hasListeners ( Events :: onClear ) ) { $ this -> evm -> dispatchEvent ( Events :: onClear , new Events \ OnClearEventArgs ( $ this -> manager , $ documentClass ) ) ; } }
Clears the unit of work . If document class is given only documents of that class will be detached .
59,390
public function getDocumentPersister ( string $ documentClass ) : DocumentPersister { if ( isset ( $ this -> documentPersisters [ $ documentClass ] ) ) { return $ this -> documentPersisters [ $ documentClass ] ; } return $ this -> documentPersisters [ $ documentClass ] = new DocumentPersister ( $ this -> manager , $ this -> manager -> getClassMetadata ( $ documentClass ) ) ; }
Gets the document persister for a given document class .
59,391
public function isInIdentityMap ( $ object ) : bool { $ oid = spl_object_hash ( $ object ) ; if ( ! isset ( $ this -> objects [ $ oid ] ) ) { return false ; } $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ id = $ class -> getSingleIdentifier ( $ object ) ; if ( empty ( $ id ) ) { return false ; } return isset ( $ this -> identityMap [ $ class -> name ] [ $ id ] ) ; }
Checks if a document is attached to this unit of work .
59,392
public function getDocumentState ( $ document , ? int $ assume = null ) { $ oid = spl_object_hash ( $ document ) ; if ( isset ( $ this -> documentStates [ $ oid ] ) ) { return $ this -> documentStates [ $ oid ] ; } if ( null !== $ assume ) { return $ assume ; } $ class = $ this -> manager -> getClassMetadata ( get_class ( $ document ) ) ; $ id = $ class -> getSingleIdentifier ( $ document ) ; if ( empty ( $ id ) ) { return self :: STATE_NEW ; } if ( $ this -> tryGetById ( $ id , $ class ) ) { return self :: STATE_DETACHED ; } $ persister = $ this -> getDocumentPersister ( $ class -> name ) ; if ( $ persister -> exists ( [ '_id' => $ id ] ) ) { return self :: STATE_DETACHED ; } return self :: STATE_NEW ; }
Gets the document state .
59,393
public function commit ( ) { if ( $ this -> evm -> hasListeners ( Events :: preFlush ) ) { $ this -> evm -> dispatchEvent ( Events :: preFlush , new PreFlushEventArgs ( $ this -> manager ) ) ; } $ this -> computeChangeSets ( ) ; if ( ! ( $ this -> documentInsertions || $ this -> documentDeletions || $ this -> documentUpdates || $ this -> documentChangeSets ) ) { $ this -> dispatchOnFlush ( ) ; $ this -> dispatchPostFlush ( ) ; return ; } $ classOrder = $ this -> getCommitOrder ( ) ; $ this -> dispatchOnFlush ( ) ; foreach ( $ classOrder as $ className ) { $ this -> executeInserts ( $ className ) ; $ this -> executeUpdates ( $ className ) ; $ this -> executeDeletions ( $ className ) ; $ this -> getDocumentPersister ( $ className ) -> refreshCollection ( ) ; } $ this -> dispatchPostFlush ( ) ; $ this -> postCommitCleanup ( ) ; }
Commits all the operations pending in this unit of work .
59,394
private function addToIdentityMap ( $ object ) { $ oid = spl_object_hash ( $ object ) ; if ( isset ( $ this -> objects [ $ oid ] ) ) { return ; } $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ id = $ class -> getSingleIdentifier ( $ object ) ; if ( empty ( $ id ) ) { throw new InvalidIdentifierException ( 'Documents must have an identifier in order to be added to the identity map.' ) ; } $ this -> objects [ $ oid ] = $ object ; $ this -> identityMap [ $ class -> name ] [ $ id ] = $ object ; $ this -> documentStates [ $ oid ] = self :: STATE_MANAGED ; }
Adds a document to the identity map . The identifier MUST be set before trying to add the document or this method will throw an InvalidIdentifierException .
59,395
private function removeFromIdentityMap ( $ object ) { $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ id = $ class -> getSingleIdentifier ( $ object ) ; if ( empty ( $ id ) ) { throw new InvalidIdentifierException ( 'Documents must have an identifier in order to be added to the identity map.' ) ; } unset ( $ this -> identityMap [ $ class -> name ] [ $ id ] ) ; }
Removes an object from identity map .
59,396
private function doPersist ( $ object , array & $ visited ) : void { $ oid = spl_object_hash ( $ object ) ; if ( isset ( $ visited [ $ oid ] ) ) { return ; } $ visited [ $ oid ] = true ; $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ documentState = $ this -> getDocumentState ( $ object , self :: STATE_NEW ) ; switch ( $ documentState ) { case self :: STATE_MANAGED : break ; case self :: STATE_NEW : $ this -> persistNew ( $ class , $ object ) ; break ; case self :: STATE_REMOVED : unset ( $ this -> documentDeletions [ $ oid ] ) ; $ this -> documentStates [ $ oid ] = self :: STATE_MANAGED ; break ; } $ this -> cascadePersist ( $ object , $ visited ) ; }
Executes a persist operation .
59,397
private function doRemove ( $ object , array & $ visited ) : void { $ oid = spl_object_hash ( $ object ) ; if ( isset ( $ visited [ $ oid ] ) ) { return ; } $ visited [ $ oid ] = true ; $ this -> cascadeRemove ( $ object , $ visited ) ; $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ documentState = $ this -> getDocumentState ( $ object ) ; switch ( $ documentState ) { case self :: STATE_NEW : case self :: STATE_REMOVED : break ; case self :: STATE_MANAGED : $ this -> lifecycleEventManager -> preRemove ( $ class , $ object ) ; $ this -> scheduleForDeletion ( $ object ) ; break ; case self :: STATE_DETACHED : throw new \ InvalidArgumentException ( 'Detached document cannot be removed' ) ; default : throw new \ InvalidArgumentException ( 'Unexpected document state ' . $ documentState ) ; } }
Executes a remove operation .
59,398
private function doDetach ( $ object , array & $ visited ) { $ oid = spl_object_hash ( $ object ) ; if ( isset ( $ visited [ $ oid ] ) ) { return ; } $ visited [ $ oid ] = true ; $ state = $ this -> getDocumentState ( $ object , self :: STATE_DETACHED ) ; if ( self :: STATE_MANAGED !== $ state ) { return ; } unset ( $ this -> documentStates [ $ oid ] , $ this -> objects [ $ oid ] , $ this -> originalDocumentData [ $ oid ] ) ; $ this -> removeFromIdentityMap ( $ object ) ; $ this -> cascadeDetach ( $ object , $ visited ) ; }
Execute detach operation .
59,399
private function scheduleForInsert ( $ object ) { $ oid = spl_object_hash ( $ object ) ; $ class = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; $ this -> documentInsertions [ $ oid ] = $ object ; if ( null !== $ class -> getSingleIdentifier ( $ object ) ) { $ this -> addToIdentityMap ( $ object ) ; } }
Schedule a document for insertion . If the document already has an identifier it will be added to the identity map .