idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
44,800
public function setOptions ( $ options ) { $ options = is_array ( $ options ) ? $ options : array ( $ options ) ; foreach ( $ options as $ option ) { $ this -> addOption ( $ option ) ; } return $ this ; }
Batch add options to command .
44,801
public function renderAlternatives ( $ wrongName , $ exception ) { $ message = $ exception -> getMessage ( ) ; $ autoComplete = '' ; $ alternatives = array ( ) ; foreach ( $ this -> children as $ command ) { $ commandName = $ command -> getName ( ) ; if ( levenshtein ( $ wrongName , $ commandName ) <= ( strlen ( $ wrongName ) / 3 ) || strpos ( $ commandName , $ wrongName ) !== false ) { $ alternatives [ ] = " " . $ commandName ; } } if ( count ( $ alternatives ) ) { $ autoComplete = "Did you mean one of these?\n" ; $ autoComplete .= implode ( $ alternatives ) ; } $ this -> out ( '' ) ; $ this -> err ( "<error>{$message}</error>" ) ; $ this -> out ( '' ) ; $ this -> err ( $ autoComplete ) ; }
Render auto complete alternatives .
44,802
public function offsetUnset ( $ key ) { $ _key = $ this -> sql -> real_escape_string ( $ key ) ; if ( ! $ this -> sql -> query ( "DELETE FROM `{$this->table}` WHERE `app` = '{$this->app}' AND `key` = '$_key'" ) ) { throw new AppMetadata_Exception ( "Unable to delete app metadata (`$_key`). {$this->sql->error}" , AppMetadata_Exception :: DELETE_FAIL ) ; } $ result = parent :: offsetUnset ( $ key ) ; $ this -> updateDerivedValues ( $ key ) ; return $ result ; }
Transparently expunge the persistent app_metadata store when the data is unset
44,803
public function buildDatabase ( ) { if ( $ this -> sql ) { if ( $ this -> sql -> query ( " CREATE TABLE IF NOT EXISTS `{$this->table}` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(255) NOT NULL, `value` text, `validate` text, `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `app` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ); " ) ) { $ this -> initialized = true ; $ this -> sql -> query ( " ALTER TABLE `{$this->table}` DROP PRIMARY KEY, ADD `id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT FIRST; " ) ; } } return $ this -> initialized ; }
Create the supporting database table
44,804
private function updateDerivedValues ( $ key = null , $ value = null ) { $ derived = array ( ) ; $ derivedPattern = '%@_%' ; if ( ! empty ( $ key ) ) { $ _key = $ this -> sql -> real_escape_string ( $ key ) ; $ derivedPattern = "%@$_key%" ; if ( ! empty ( $ value ) && is_string ( $ value ) ) { $ derived [ $ key ] = $ value ; } } if ( $ result = $ this -> sql -> query ( " SELECT * FROM `{$this->table}` WHERE `value` LIKE '$derivedPattern' " ) ) { while ( $ row = $ result -> fetch_assoc ( ) ) { $ value = unserialize ( $ row [ 'value' ] ) ; if ( is_string ( $ value ) ) { $ derived [ $ row [ 'key' ] ] = $ value ; } } } while ( count ( $ derived ) > 0 ) { $ next = array ( ) ; foreach ( $ derived as $ key => $ value ) { preg_match_all ( '/@(\w+)/' , $ value , $ sources , PREG_SET_ORDER ) ; $ dirty = false ; foreach ( $ sources as $ source ) { if ( $ this -> offsetExists ( $ source [ 1 ] ) && is_string ( $ this -> offsetGet ( $ source [ 1 ] ) ) ) { $ value = preg_replace ( "/{$source[0]}/" , $ this -> offsetGet ( $ source [ 1 ] ) , $ value ) ; $ dirty = true ; } } if ( $ dirty ) { $ next [ $ key ] = $ value ; } else { $ this -> _offsetSet ( $ key , $ value , false ) ; } } $ derived = $ next ; } }
Calculate the derived value for a particular offset
44,805
public function derivedValues ( $ s ) { preg_match_all ( '/@(\w+)/' , $ s , $ possibilities , PREG_SET_ORDER ) ; foreach ( $ possibilities as $ possibility ) { if ( $ this -> offsetExists ( $ possibility [ 1 ] ) && is_string ( $ this -> offsetGet ( $ possibility [ 1 ] ) ) ) { $ s = str_replace ( $ possibility [ 0 ] , $ this -> offsetGet ( $ possibility [ 1 ] ) , $ s ) ; } } return $ s ; }
Replace derived values in an abitrary string using AppMetadata
44,806
public function getGoodsSN ( ) { $ step = 5000 ; $ start = 100 ; $ max = Goods :: max ( 'sn' ) ; $ max = count ( $ max ) && $ max > $ start ? $ max : $ start ; $ sn = $ max + 1 ; $ sn_str = strval ( $ sn ) ; if ( str_contains ( $ sn_str , '4' ) ) { $ sn_str = str_replace ( '4' , '5' , $ sn_str ) ; } $ sn = intval ( $ sn_str ) ; $ in_offer = Offer :: where ( 'sn' , $ sn ) -> first ( ) ; $ max_offer = Offer :: max ( 'sn' ) ; if ( count ( $ in_offer ) ) { $ sn = $ step * ceil ( $ max_offer / $ step ) + $ step ; } return $ sn ; }
get shop sn
44,807
public function getOfferSN ( ) { $ start = 5000 ; $ step = 5000 ; $ max = Offer :: max ( 'sn' ) ; $ max = count ( $ max ) && $ max > $ start ? $ max : $ start ; $ sn = $ max + 1 ; $ sn_str = strval ( $ sn ) ; if ( str_contains ( $ sn_str , '4' ) ) { $ sn_str = str_replace ( '4' , '5' , $ sn_str ) ; } $ sn = intval ( $ sn_str ) ; $ in_goods = Goods :: where ( 'sn' , $ sn ) -> first ( ) ; $ max_goods = Goods :: max ( 'sn' ) ; if ( count ( $ in_goods ) ) { $ sn = $ step * ceil ( $ max_goods / $ step ) + $ step ; } return $ sn ; }
get offer sn
44,808
public function encode ( $ data ) { return openssl_encrypt ( $ data , $ this -> method , $ this -> key , 0 , $ this -> iv ) ; }
Encode data by openssl_encrypt
44,809
public function decode ( $ data ) { return openssl_decrypt ( $ data , $ this -> method , $ this -> key , 0 , $ this -> iv ) ; }
Decode data by openssl_decrypt
44,810
public function initialize ( ) { if ( ! $ this -> type ) { throw new DbException ( "Invalid database type provided" ) ; } switch ( $ this -> type ) { case 'mysql' : return new MySQL ( $ this -> options ) ; break ; default : throw new DbException ( "Valid database type provided" ) ; break ; } }
This method initializes a database connection
44,811
protected function blockFencedCode ( $ line ) { $ regex = '/^([' . $ line [ 'text' ] [ 0 ] . ']{3,})[ ]*([\w-]+)?[ ]*$/' ; if ( preg_match ( $ regex , $ line [ 'text' ] , $ matches ) ) { $ element = [ 'name' => 'code' , 'text' => '' , ] ; if ( isset ( $ matches [ 2 ] ) ) { $ class = $ this -> getConfig ( 'fenced_code_lang_class' , 'prettyprint lang-{LANG}' ) ; $ class = str_replace ( '{LANG}' , $ matches [ 2 ] , $ class ) ; $ element [ 'attributes' ] = [ 'class' => $ class ] ; } $ block = [ 'char' => $ line [ 'text' ] [ 0 ] , 'element' => [ 'name' => 'pre' , 'handler' => 'element' , 'text' => $ element , ] , ] ; return $ block ; } }
Parse fenced code blocks .
44,812
protected function blockTable ( $ line , array $ block = null ) { if ( ! isset ( $ block ) or isset ( $ block [ 'type' ] ) or isset ( $ block [ 'interrupted' ] ) ) { return ; } if ( strpos ( $ block [ 'element' ] [ 'text' ] , '|' ) !== false and chop ( $ line [ 'text' ] , ' -:|' ) === '' ) { $ alignments = array ( ) ; $ divider = $ line [ 'text' ] ; $ divider = trim ( $ divider ) ; $ divider = trim ( $ divider , '|' ) ; $ dividerCells = explode ( '|' , $ divider ) ; foreach ( $ dividerCells as $ dividerCell ) { $ dividerCell = trim ( $ dividerCell ) ; if ( $ dividerCell === '' ) { continue ; } $ alignment = null ; if ( $ dividerCell [ 0 ] === ':' ) { $ alignment = 'left' ; } if ( substr ( $ dividerCell , - 1 ) === ':' ) { $ alignment = $ alignment === 'left' ? 'center' : 'right' ; } $ alignments [ ] = $ alignment ; } $ headerElements = array ( ) ; $ header = $ block [ 'element' ] [ 'text' ] ; $ header = trim ( $ header ) ; $ header = trim ( $ header , '|' ) ; $ headerCells = explode ( '|' , $ header ) ; foreach ( $ headerCells as $ index => $ headerCell ) { $ headerCell = trim ( $ headerCell ) ; $ headerElement = [ 'name' => 'th' , 'text' => $ headerCell , 'handler' => 'line' , ] ; if ( isset ( $ alignments [ $ index ] ) ) { $ alignment = $ alignments [ $ index ] ; $ headerElement [ 'attributes' ] = [ 'style' => 'text-align: ' . $ alignment . ';' , ] ; } $ headerElements [ ] = $ headerElement ; } $ block = [ 'alignments' => $ alignments , 'identified' => true , 'element' => [ 'name' => 'table' , 'handler' => 'elements' , 'attributes' => [ 'class' => 'table table-striped table-bordered' ] , ] , ] ; $ block [ 'element' ] [ 'text' ] [ ] = [ 'name' => 'thead' , 'handler' => 'elements' , ] ; $ block [ 'element' ] [ 'text' ] [ ] = [ 'name' => 'tbody' , 'handler' => 'elements' , 'text' => array ( ) , ] ; $ block [ 'element' ] [ 'text' ] [ 0 ] [ 'text' ] [ ] = [ 'name' => 'tr' , 'handler' => 'elements' , 'text' => $ headerElements , ] ; return $ block ; } }
Parse tables .
44,813
protected function validate ( array $ rules , bool $ throwError = true ) { $ validations = [ ] ; $ data = [ ] ; foreach ( $ rules as $ key => $ rule ) { $ value = $ this -> request -> get ( $ key ) ; $ violations = $ this -> validator -> validate ( $ value , $ rule ) ; if ( count ( $ violations ) > 0 ) { $ validations [ $ key ] = [ ] ; foreach ( $ violations as $ violation ) { $ validations [ $ key ] [ ] = $ violation -> getMessage ( ) ; } } else { $ data [ $ key ] = $ value ; } } if ( $ throwError && count ( $ validations ) ) { throw new HttpValidationException ( $ validations ) ; } return $ data ; }
validate input value from request
44,814
final protected function auth ( $ member ) { if ( $ member ) { $ this -> session -> set ( 'auth_member_id' , $ member -> getId ( ) ) ; } else { $ this -> session -> remove ( 'auth_member_id' ) ; } return $ this ; }
set auth user to session
44,815
private function convertToBytes ( $ memoryLimit ) { if ( '-1' === $ memoryLimit ) { return - 1 ; } $ memoryLimit = strtolower ( $ memoryLimit ) ; $ max = strtolower ( ltrim ( $ memoryLimit , '+' ) ) ; if ( 0 === strpos ( $ max , '0x' ) ) { $ max = intval ( $ max , 16 ) ; } elseif ( 0 === strpos ( $ max , '0' ) ) { $ max = intval ( $ max , 8 ) ; } else { $ max = intval ( $ max ) ; } switch ( substr ( $ memoryLimit , - 1 ) ) { case 't' : $ max *= 1024 ; case 'g' : $ max *= 1024 ; case 'm' : $ max *= 1024 ; case 'k' : $ max *= 1024 ; } return $ max ; }
Convert mixed to bytes .
44,816
function getAlbum ( ) { $ photos = new Zend_Gdata_Photos ( $ this -> client ) ; $ query = new Zend_Gdata_Photos_AlbumQuery ( ) ; $ query -> setUser ( $ this -> user ) ; $ query -> setAlbumId ( $ this -> album ) ; $ albumFeed = $ photos -> getAlbumFeed ( $ query ) ; return $ albumFeed ; }
Retrieve photos from specified album
44,817
function getPhotoById ( $ photoId ) { $ photos = new Zend_Gdata_Photos ( $ this -> client ) ; $ query = new Zend_Gdata_Photos_PhotoQuery ( ) ; $ query -> setUser ( $ this -> user ) ; $ query -> setAlbumId ( $ this -> album ) ; $ query -> setPhotoId ( $ photoId ) ; $ query = $ query -> getQueryUrl ( ) . "?kind=comment,tag&imgmax=1600" ; $ photoFeed = $ photos -> getPhotoFeed ( $ query ) ; return $ photoFeed ; }
Select a photo from specified album
44,818
function addPhoto ( $ photo ) { if ( ! file_exists ( $ photo [ 'tmp_name' ] ) || ! is_uploaded_file ( $ photo [ 'tmp_name' ] ) ) { $ o = array ( 'state' => false ) ; } else { $ photos = new Zend_Gdata_Photos ( $ this -> client ) ; $ fd = $ photos -> newMediaFileSource ( $ photo [ "tmp_name" ] ) ; $ fd -> setContentType ( $ photo [ "type" ] ) ; $ entry = new Zend_Gdata_Photos_PhotoEntry ( ) ; $ entry -> setMediaSource ( $ fd ) ; $ entry -> setTitle ( $ photos -> newTitle ( $ photo [ "name" ] ) ) ; $ albumQuery = new Zend_Gdata_Photos_AlbumQuery ; $ albumQuery -> setUser ( $ this -> user ) ; $ albumQuery -> setAlbumId ( $ this -> album ) ; $ albumEntry = $ photos -> getAlbumEntry ( $ albumQuery ) ; $ result = $ photos -> insertPhotoEntry ( $ entry , $ albumEntry ) ; if ( $ result ) { $ o = array ( 'state' => true , 'id' => $ result -> getGphotoId ( ) ) ; } else { $ o = array ( 'state' => false ) ; } } return $ o ; }
Add a photo to specific picasa web album
44,819
function deletePhoto ( $ photoId ) { $ photos = new Zend_Gdata_Photos ( $ this -> client ) ; $ photoQuery = new Zend_Gdata_Photos_PhotoQuery ; $ photoQuery -> setUser ( $ this -> user ) ; $ photoQuery -> setAlbumId ( $ this -> album ) ; $ photoQuery -> setPhotoId ( $ photoId ) ; $ photoQuery -> setType ( 'entry' ) ; $ entry = $ photos -> getPhotoEntry ( $ photoQuery ) ; $ photos -> deletePhotoEntry ( $ entry , true ) ; }
Deletes the specified photo
44,820
public function override ( $ configFile , $ strict = false ) { parent :: override ( $ this -> _parse ( $ configFile , $ strict ) ) ; }
override Merges the configuration from this yaml file with the base configuration override values
44,821
public function from ( $ mail , $ name = null ) { $ this -> mailer -> setFrom ( $ mail , $ name ) ; return $ this ; }
Set the address information sent by mail .
44,822
public function body ( $ body = '' , $ contentType = 'text/html' ) { $ this -> mailer -> Body = $ body ; $ this -> mailer -> ContentType = $ contentType ; return $ this ; }
register the message body
44,823
public function issue ( ) { foreach ( $ this -> headers as $ key => $ value ) { header ( "{$key}: {$value}" , true ) ; } if ( $ this -> contentType ) { header ( "content-type: {$this->contentType}; charset={$this->encoding}" ) ; } $ statusMessage = sprintf ( '%d %s' , $ this -> status , HttpClient :: getStatusCodeMessage ( $ this -> status ) ) ; header ( 'Status: ' . $ statusMessage ) ; }
The default output of an HTTP response is composed of the headers .
44,824
public function setStatus ( $ status ) { $ result = \ Eix \ Services \ Net \ Http :: isStatusCodeValid ( $ status ) ; if ( $ result ) { $ this -> status = $ status ; } return $ result ; }
Sets the status if it is a valid HTTP status code .
44,825
protected function addStatusMessage ( $ type , $ messages ) { if ( ! is_array ( $ messages ) ) { $ messages = array ( $ messages ) ; } $ this -> addData ( 'status' , array ( $ type => $ messages ) ) ; }
Adds one or more status messages to the response data .
44,826
public static function findByPasswordResetToken ( $ token ) { $ expire = Yii :: $ app -> params [ 'user.passwordResetTokenExpire' ] ; $ parts = explode ( '_' , $ token ) ; $ timestamp = ( int ) end ( $ parts ) ; if ( $ timestamp + $ expire < time ( ) ) { return null ; } return static :: findOne ( [ 'password_reset_token' => $ token , 'status' => self :: STATUS_ACTIVE , ] ) ; }
Finds user by password reset token
44,827
private function categories ( ) { $ package = Package :: where ( 'name' , 'Core' ) -> first ( ) ; $ core = ConfigCategory :: create ( [ 'key' => 'core' , 'package_id' => $ package -> id ] ) ; ConfigCategory :: create ( [ 'key' => 'core_mail' , 'parent_id' => $ core -> id , 'package_id' => $ core -> package_id ] ) ; ConfigCategory :: create ( [ 'key' => 'core_general' , 'parent_id' => $ core -> id , 'package_id' => $ core -> package_id ] ) ; $ this -> general ( ) ; $ this -> mail ( ) ; }
Method for creating configuration categories
44,828
public function createService ( string $ key , ServiceLocatorInterface $ serviceLocator , array $ extra = null ) : object { $ config = $ serviceLocator -> getConfig ( ) ; $ config = $ config [ RouterInterface :: class ] ?? [ ] ; $ router = new Router ( ) ; foreach ( $ config [ 'routes' ] ?? [ ] as $ name => $ config ) { $ router -> addRoute ( $ this -> createRoute ( $ serviceLocator , $ config ) , $ name ) ; } return $ router ; }
Create router .
44,829
protected function createGroup ( ServiceLocatorInterface $ serviceLocator , RouteInterface $ route , array $ children , bool $ abstract = null ) : RouteInterface { $ group = $ serviceLocator -> getService ( GroupRoute :: class , [ 'route' => $ route , 'abstract' => $ abstract , ] ) ; foreach ( $ children as $ name => $ child ) { $ group -> addRoute ( $ this -> createRoute ( $ serviceLocator , $ child ) , $ name ) ; } return $ group ; }
Create group route .
44,830
public function addGroup ( $ str_alias , $ str_name = null ) { if ( ! isset ( self :: $ arr_group [ $ str_alias ] ) ) { $ grp = new \ stdClass ( ) ; $ grp -> name = ( strlen ( $ str_name ) ) ? $ str_name : null ; $ grp -> args = array ( ) ; self :: $ arr_group [ $ str_alias ] = $ grp ; } return $ this ; }
Adds a new group for options .
44,831
public static function add ( OptionItem $ opt , $ str_alias = null ) { if ( ! in_array ( $ opt -> getShort ( true ) , self :: $ arr_prohibited , true ) && ! in_array ( $ opt -> getLong ( true ) , self :: $ arr_prohibited , true ) ) { if ( is_string ( $ str_alias ) && isset ( self :: $ arr_group [ $ str_alias ] ) ) { self :: $ arr_group [ $ str_alias ] -> args [ $ opt -> getName ( ) ] = $ opt ; } else { self :: $ arr_opt [ $ opt -> getName ( ) ] = $ opt ; } } }
Adds one new option .
44,832
public function newSwitch ( $ name , $ group = null ) { $ arg = OptionItem :: createSwitch ( $ name ) ; if ( $ this -> obj_color -> opt ) { $ arg -> color ( $ this -> obj_color -> opt ) ; } if ( $ this -> obj_color -> bold ) { $ arg -> bold ( ) ; } self :: add ( $ arg , $ group ) ; return self :: getOpt ( $ name ) ; }
Adds a new option switch .
44,833
public function newValue ( $ name , $ group = null ) { $ arg = OptionItem :: createValue ( $ name ) ; if ( $ this -> obj_color -> opt ) { $ arg -> color ( $ this -> obj_color -> opt ) ; } if ( $ this -> obj_color -> bold ) { $ arg -> bold ( ) ; } self :: add ( $ arg , $ group ) ; return self :: getOpt ( $ name ) ; }
Adds a new option s value .
44,834
public function getDescription ( ) { if ( is_string ( $ this -> str_description ) ) { $ description = new S ( $ this -> str_description ) ; return $ description -> wrap ( OptionItem :: getWidth ( ) ) ; } else { return null ; } }
Getsthe description part .
44,835
public function displayHelp ( ) { printf ( "%s\n" , $ this -> getUsage ( ) ) ; printf ( "%s\n" , $ this -> getDescription ( ) ) ; if ( count ( self :: $ arr_opt ) ) { foreach ( self :: $ arr_opt as $ arg ) { printf ( "%s\n" , rtrim ( $ arg ) ) ; } } if ( count ( self :: $ arr_group ) ) { foreach ( self :: $ arr_group as $ group ) { if ( count ( $ group -> args ) ) { print ( "\n\n" ) ; if ( $ group -> name ) { $ name = $ group -> name ; if ( $ this -> obj_color -> label || $ this -> obj_color -> bold ) { $ name = new Ansi ( $ name ) ; if ( $ this -> obj_color -> label ) { $ name -> fg ( $ this -> obj_color -> label ) ; } if ( $ this -> obj_color -> bold ) { $ name -> bold ; } } printf ( "%s\n" , $ name ) ; } foreach ( $ group -> args as $ arg ) { printf ( "%s\n" , rtrim ( $ arg ) ) ; } } } } exit ( ) ; }
Displays full help message .
44,836
protected function refresh ( ) : bool { if ( ! $ this -> resource ) { return false ; } if ( ! $ this -> status ) { $ this -> status = new core \ Mask ( stream_is_local ( $ this -> resource ) ? interfaces \ Stream :: LOCAL : 0 ) ; } $ this -> getMetadata ( ) ; if ( isset ( self :: $ rwh [ 'read' ] [ $ this -> metadata [ 'mode' ] ] ) ) { $ this -> status -> set ( interfaces \ Stream :: READABLE ) ; } if ( isset ( self :: $ rwh [ 'write' ] [ $ this -> metadata [ 'mode' ] ] ) ) { $ this -> status -> set ( interfaces \ Stream :: WRITABLE ) ; } $ this -> status -> { ( ( isset ( $ this -> metadata [ 'seekable' ] ) && $ this -> metadata [ 'seekable' ] ) ? 'set' : 'remove' ) } ( interfaces \ Stream :: SEEKABLE ) ; $ this -> status -> { ( ( isset ( $ this -> metadata [ 'blocked' ] ) && $ this -> metadata [ 'blocked' ] ) ? 'set' : 'remove' ) } ( interfaces \ Stream :: BLOCKED ) ; return true ; }
Refreshes the status mask based on the current metadata of the stream .
44,837
public static function render ( $ textCode , $ other = null , $ domain = 'global' , $ description = null ) { $ response = new static ( ) ; $ response -> collectFrom ( $ textCode , $ other , $ domain , $ description ) ; return $ response ; }
Render the given data
44,838
public function generate ( $ suggestion = null ) { if ( null !== $ suggestion ) { $ this -> dataStore -> storeIdentity ( $ suggestion , $ this -> mob ) ; return $ suggestion ; } $ exceptions = array ( ) ; for ( $ i = 0 ; $ i <= $ this -> maxRetries ; $ i ++ ) { $ generatedIdentity = null ; try { $ generatedIdentity = $ this -> generator -> generateIdentity ( ) ; $ this -> dataStore -> storeIdentity ( $ generatedIdentity , $ this -> mob ) ; return $ generatedIdentity ; } catch ( NonUniqueIdentityException $ e ) { $ exceptions [ ] = $ e ; } catch ( \ Exception $ e ) { throw new GenerateException ( $ generatedIdentity , $ this -> mob , $ exceptions , $ e ) ; } } throw new GenerateException ( null , $ this -> mob , $ exceptions ) ; }
Generate an identity string
44,839
public function rollBack ( ) { return $ this -> inTransaction ? ( $ this -> in = $ this -> doRollBack ( $ this -> name ) ) : false ; }
Rolls back changes
44,840
public function do ( String $ app , $ key , String $ data = NULL ) : Bool { $ datas = [ ] ; $ createFile = $ this -> _langFile ( $ app ) ; if ( ! is_file ( $ createFile ) ) { file_put_contents ( $ createFile , json_encode ( [ ] ) ) ; } $ datas = json_decode ( file_get_contents ( $ createFile ) , true ) ; if ( ! empty ( $ datas ) ) { $ json = $ datas ; } if ( ! is_array ( $ key ) ) { $ json [ $ key ] = $ data ; } else { foreach ( $ key as $ k => $ v ) { $ json [ $ k ] = $ v ; } } if ( $ json !== $ datas ) { return file_put_contents ( $ createFile , json_encode ( $ json , JSON_UNESCAPED_UNICODE ) ) ; } else { return false ; } }
Insert language key
44,841
public function doNotEscape ( $ doNotEscape = [ ] ) : void { $ this -> doNotEscape = \ array_unique ( \ array_merge ( $ this -> doNotEscape , $ doNotEscape ) ) ; }
Adds no quotable expressions
44,842
public function escape ( $ value = null , array $ doNotEscape = [ ] ) { $ this -> doNotEscape = \ array_unique ( \ array_merge ( $ this -> doNotEscape , $ doNotEscape ) ) ; if ( \ is_null ( $ value ) ) { return 'NULL' ; } if ( \ is_int ( $ value ) || \ is_float ( $ value ) ) { return $ value ; } if ( \ is_array ( $ value ) || \ is_object ( $ value ) ) { return $ this -> dbClass -> escape ( \ serialize ( $ value ) ) ; } foreach ( $ this -> doNotEscape as $ doNotEscape ) { if ( \ preg_match ( '/^' . \ str_replace ( '*' , '\\*' , $ doNotEscape ) . '/i' , ( string ) $ value ) ) { return $ value ; } } return $ this -> dbClass -> escape ( $ value ) ; }
Escapes value using database specific method
44,843
public function getTriggerHtmlId ( ) { $ form = $ this -> getParentOfType ( '\\Zepi\\Web\\UserInterface\\Form\Form' ) ; if ( is_object ( $ form ) ) { $ part = $ form -> searchPartByKeyAndType ( $ this -> triggerKey ) ; return $ part -> getHtmlId ( ) ; } return '' ; }
Returns the html id of the trigger element
44,844
public function AndWhere ( $ condition , array $ values ) { $ this -> andWheres [ ] = $ condition ; $ this -> addBindValues ( $ values ) ; return $ this ; }
Add an And Where condition to the query .
44,845
public function Where ( $ condition , $ values ) { $ this -> setWhere ( $ condition ) ; $ this -> addBindValues ( $ values ) ; return $ this ; }
Set where condition of the query .
44,846
public function execute ( ) { $ statement = $ this -> buildStatement ( ) ; $ result = $ this -> getDataSource ( ) -> query ( $ statement , $ this -> getBindValues ( ) ) ; if ( $ result ) { $ collection = new Collection ( $ this -> getMapper ( ) -> getClass ( ) , $ result , $ this -> getMapper ( ) ) ; } else { $ collection = new Collection ( $ this -> getMapper ( ) -> getClass ( ) , array ( ) , $ this -> getMapper ( ) ) ; } return $ collection ; }
Execute query and return a collection .
44,847
protected function queryInternal ( $ method , $ fetchMode = null ) { if ( $ method !== '' ) { $ rawSql = $ this -> getRawSql ( ) ; $ requestLocalCacheKey = implode ( '' , [ __CLASS__ , $ method , $ fetchMode , $ this -> db -> dsn , $ this -> db -> username , preg_replace ( '/\s+/' , '' , $ rawSql ) ] ) ; mb_convert_encoding ( $ requestLocalCacheKey , 'UTF-8' , 'UTF-8' ) ; if ( ( $ result = static :: $ requestLocalCache -> get ( $ requestLocalCacheKey ) ) !== false ) { Yii :: info ( 'Query result served from request local cache' . PHP_EOL . 'Query: ' . VarDumper :: dumpAsString ( $ rawSql ) . PHP_EOL . 'Result: ' . VarDumper :: dumpAsString ( $ result ) , __METHOD__ ) ; return $ result ; } static :: $ requestLocalCache -> set ( 'rawSql' , $ rawSql ) ; } $ result = parent :: queryInternal ( $ method , $ fetchMode ) ; if ( $ method !== '' ) { static :: $ requestLocalCache -> set ( $ requestLocalCacheKey , $ result ) ; } return $ result ; }
Actual query with caching results in local for current request
44,848
public function isAbsolute ( $ path ) { $ firstChar = substr ( $ path , 0 , 1 ) ; if ( '/' === $ firstChar || '\\' === $ firstChar ) { return true ; } $ isLetter = ( ( $ firstChar >= 'A' && $ firstChar <= 'Z' ) || ( $ firstChar >= 'a' && $ firstChar <= 'z' ) ) ; $ path = substr ( $ path , 1 , 2 ) ; return $ isLetter && ( ':/' === $ path || ':\\' === $ path ) ; }
Tells if the given path is absolute .
44,849
public function hasProperty ( $ name ) { static $ vars = null ; if ( ! $ vars ) { $ vars = get_object_vars ( $ this ) ; } return array_key_exists ( $ name , $ vars ) ; }
has property ?
44,850
private static function dumpTree ( NodeInterface $ node , $ verbose , $ indent = 0 ) { list ( $ attributes , $ nodes ) = self :: extract ( $ node ) ; $ dump = get_class ( $ node ) ; if ( $ attributes ) { $ dump .= ' (' ; $ dump .= implode ( ', ' , array_map ( function ( $ key , $ value ) use ( $ verbose ) { return ( $ verbose ? sprintf ( '%s = ' , $ key ) : '' ) . self :: stringify ( $ value ) ; } , array_keys ( $ attributes ) , array_values ( $ attributes ) ) ) ; $ dump .= ')' ; } if ( $ nodes ) { $ dump .= ' {' . PHP_EOL ; foreach ( $ nodes as $ key => $ node ) { $ dump .= str_repeat ( ' ' , $ indent + 1 ) ; if ( $ verbose && is_string ( $ key ) ) { $ dump .= sprintf ( '%s = ' , $ key ) ; } if ( is_array ( $ node ) ) { $ dump .= '[' . PHP_EOL ; foreach ( $ node as $ item ) { $ dump .= str_repeat ( ' ' , $ indent + 2 ) . self :: dumpTree ( $ item , $ verbose , $ indent + 2 ) . PHP_EOL ; } $ dump .= str_repeat ( ' ' , $ indent + 1 ) . ']' . PHP_EOL ; } else { $ dump .= self :: dumpTree ( $ node , $ verbose , $ indent + 1 ) . PHP_EOL ; } } $ dump .= str_repeat ( ' ' , $ indent ) . '}' ; } return $ dump ; }
Dumps the node and its children as a pretty printed string representation .
44,851
private static function extract ( NodeInterface $ node ) { $ attributes = [ ] ; $ nodes = [ ] ; foreach ( self :: extractProperties ( $ node ) as $ name => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ item ) { if ( $ item instanceof NodeInterface ) { $ nodes [ $ name ] [ ] = $ item ; } else { $ attributes [ $ name ] [ ] = $ item ; } } } else { if ( $ value instanceof NodeInterface ) { $ nodes [ $ name ] = $ value ; } else { $ attributes [ $ name ] = $ value ; } } } return [ $ attributes , $ nodes ] ; }
Extracts the properties of the given node .
44,852
private static function extractProperties ( NodeInterface $ node ) { $ class = new \ ReflectionClass ( $ node ) ; foreach ( $ class -> getProperties ( ) as $ property ) { if ( ! $ property -> isPublic ( ) ) { $ property -> setAccessible ( true ) ; } $ name = $ property -> getName ( ) ; $ value = $ property -> getValue ( $ node ) ; yield $ name => $ value ; if ( ! $ property -> isPublic ( ) ) { $ property -> setAccessible ( false ) ; } } }
Provides a generator that share the properties of the given node .
44,853
private static function stringify ( $ value ) { if ( is_string ( $ value ) ) { return sprintf ( '"%s"' , preg_replace ( '/\n/' , '\n' , $ value ) ) ; } if ( is_bool ( $ value ) ) { return $ value ? 'true' : 'false' ; } if ( is_null ( $ value ) ) { return 'null' ; } if ( is_array ( $ value ) ) { return sprintf ( '[%s]' , implode ( ', ' , array_map ( function ( $ value ) { return self :: stringify ( $ value ) ; } , $ value ) ) ) ; } return ( string ) $ value ; }
Stringify the given value . It can handles strings booleans null values and arrays . The other types would be casted into string .
44,854
public static function removeAbandonedPosts ( ) { $ sub_posts = \ SubPost :: getWhere ( array ( 'post_parent' => 0 ) ) ; foreach ( $ sub_posts as $ sp ) { wp_delete_post ( $ sp -> ID , true ) ; } }
without hitting the publish or update button
44,855
public function retrieve ( $ name ) { $ this -> userRagnarok = Session :: get ( $ this -> getName ( ) ) ; if ( property_exists ( $ this -> userRagnarok , $ name ) ) { return $ this -> userRagnarok -> $ name ; } return null ; }
Get User Session Object attribute
44,856
public function make ( $ user ) { $ RagnarokUser = new SecUser ( ) ; $ this -> userRagnarok = $ RagnarokUser -> populate ( $ user ) ; Session :: put ( $ this -> getName ( ) , $ this -> userRagnarok ) ; return $ this -> userRagnarok ; }
Make User Session Object
44,857
public function instance ( $ data ) { $ RagnarokUser = new SecUser ( ) ; $ this -> userRagnarok = $ RagnarokUser -> populate ( $ data ) ; return $ this -> userRagnarok ; }
Get a new instance of the User
44,858
public function process ( ) { $ route = $ this -> findFirstMatchingRoute ( ) ; if ( ! $ route ) { $ route = $ this -> findFirstMatchingRoute ( true ) ; if ( $ route ) { $ r = $ this -> redirect ( $ route ) ; if ( $ r ) { return $ r ; } $ route = null ; } } return $ this -> processRoute ( $ route ) ; }
Process the request by finding a route and processing it
44,859
public function processRoute ( $ route ) { if ( ! $ route ) { throw new NotFoundException ( 'No route matches the current request ' . $ this ) ; } $ this -> setRoute ( $ route ) ; return $ this -> route -> run ( $ this ) ; }
Process the given route
44,860
public function setWidth ( $ width ) { $ this -> width = empty ( $ width ) ? null : ( int ) $ width ; return $ this ; }
Set width attribute
44,861
public function setHeight ( $ height ) { $ this -> height = empty ( $ height ) ? null : ( int ) $ height ; return $ this ; }
Set height attribute
44,862
protected function processValue ( callable $ func , CacheItem $ item ) { $ item -> setStrVal ( $ func ( $ item -> getStrVal ( ) ) ) ; return true ; }
Encrypt or decrypt
44,863
public function getExcelBook ( $ file_format = self :: FILE_FORMAT_XLSX , $ locale = 'UTF-8' ) { if ( ! extension_loaded ( 'excel' ) ) { throw new Exception \ RuntimeException ( __METHOD__ . ' LibXL requires excel extension (https://github.com/iliaal/php_excel) and http://libxl.com/.' ) ; } if ( ! $ this -> isSupportedFormat ( $ file_format ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . " Unsupported file format '$file_format'." ) ; } $ license = $ this -> getLicense ( ) ; $ license_name = $ license [ 'name' ] ; $ license_key = $ license [ 'key' ] ; $ excel2007 = true ; switch ( $ file_format ) { case self :: FILE_FORMAT_XLS : $ excel2007 = false ; break ; } $ book = new ExcelBook ( $ license_name , $ license_key , $ excel2007 ) ; if ( $ locale !== null ) { $ book -> setLocale ( $ locale ) ; } return $ book ; }
Return an empty ExcelBook instance
44,864
public static function isSupportedFormat ( $ format ) { if ( ! is_string ( $ format ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . " file_format must be a string" ) ; } return in_array ( ( string ) $ format , self :: $ supportedFormats ) ; }
Check whether the format is supported
44,865
public static function setDefaultLicense ( array $ license ) { if ( ! array_key_exists ( 'name' , $ license ) || ! array_key_exists ( 'key' , $ license ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . " In order to set a default libxl license you must provide an associative array with 'name' and 'key' set." ) ; } self :: $ default_license = $ license ; }
Set default license information
44,866
protected function getContainer ( $ name ) { if ( ! isset ( $ this -> containers [ $ name ] ) ) { $ this -> createContainer ( $ name ) ; } return $ this -> containers [ $ name ] ; }
Return a container wrapper based on its name saving to cache if necessary .
44,867
protected function createContainer ( $ name ) { $ this -> containers [ $ name ] = new Container ( $ this -> getView ( ) , $ this -> service , $ name ) ; }
Create a new container wrapper and save it to cache
44,868
public function rollbackWithoutThrow ( ) { if ( ! $ this -> isValid ( ) ) return ; foreach ( $ this -> getConnections ( ) as $ connection ) { $ connection -> rollback ( ) ; } $ this -> _depth = 0 ; }
rollback transaction without throw
44,869
public function createdAtDatetime ( ) { return $ this -> entity -> created_at -> setTimezone ( $ this -> config -> get ( 'config.timezone' ) ) -> format ( $ this -> config -> get ( 'config.date_format' ) . ' ' . $ this -> config -> get ( 'config.time_format' ) ) ; }
Return the datetime string for created at .
44,870
public function updatedAtDate ( ) { return $ this -> entity -> updated_at -> setTimezone ( $ this -> config -> get ( 'config.timezone' ) ) -> format ( $ this -> config -> get ( 'config.date_format' ) ) ; }
Return the date string for updated at .
44,871
public function updatedAtDatetime ( ) { return $ this -> entity -> updated_at -> setTimezone ( $ this -> config -> get ( 'config.timezone' ) ) -> format ( $ this -> config -> get ( 'config.date_format' ) . ' ' . $ this -> config -> get ( 'config.time_format' ) ) ; }
Return the datetime string for updated at .
44,872
public function where ( $ field , $ section = 'Reference' ) { if ( $ section === null ) { $ section = 'Reference' ; } return new FilterableList ( array_values ( array_filter ( $ this -> sections , function ( Section $ val ) use ( $ section ) { return $ val -> getHeading ( ) == $ section ; } ) ) , $ field ) ; }
Sets the field for the first filter .
44,873
public static function flatten ( array $ arr ) { $ flat = [ ] ; foreach ( $ arr as $ v ) { if ( is_array ( $ v ) ) { $ flat = array_merge ( $ flat , self :: flatten ( $ v ) ) ; } else { $ flat [ ] = $ v ; } } return $ flat ; }
Flattens an array .
44,874
public static function isIndexed ( array $ array ) { $ i = 0 ; foreach ( array_keys ( $ array ) as $ k ) { if ( $ k !== $ i ) { return false ; } $ i ++ ; } return true ; }
Checks if an array is indexed .
44,875
public function addRole ( $ role , $ parents = null ) { $ this -> getAcl ( ) -> addRole ( $ role , $ parents ) ; return $ this ; }
Add roles from storage
44,876
public function getClassMetadata ( $ class ) { $ class = ltrim ( $ class , '\\' ) ; $ metadataIndex = $ this -> getCacheId ( $ class ) ; if ( isset ( $ this -> loadedMetadata [ $ metadataIndex ] ) ) { return $ this -> loadedMetadata [ $ metadataIndex ] ; } if ( isset ( $ this -> cache ) ) { if ( false !== ( $ metadata = $ this -> cache -> fetch ( $ metadataIndex ) ) ) { return $ metadata ; } } $ metadata = new $ this -> metadataClassName ( $ class ) ; $ parentClasses = array_reverse ( class_parents ( $ class ) ) ; foreach ( $ parentClasses as $ parentClass ) { $ metadata -> setClassName ( $ parentClass ) ; $ this -> driver -> loadClassMetadata ( $ metadata ) ; } $ metadata -> setClassName ( $ class ) ; $ this -> driver -> loadClassMetadata ( $ metadata ) ; if ( isset ( $ this -> cache ) ) { $ this -> cache -> save ( $ metadataIndex , $ metadata ) ; } $ this -> loadedMetadata [ $ metadataIndex ] = $ metadata ; return $ metadata ; }
Returns class metadata read by the driver . This method calls itself recursively for each ancestor class
44,877
public function setInputStream ( $ stream ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::setStream() instead.' , __METHOD__ , StreamableInputInterface :: class ) , E_USER_DEPRECATED ) ; if ( ! is_resource ( $ stream ) ) { throw new InvalidArgumentException ( 'Input stream must be a valid resource.' ) ; } $ this -> inputStream = $ stream ; }
Sets the input stream to read from when interacting with the user .
44,878
public function getInputStream ( ) { if ( 0 === func_num_args ( ) || func_get_arg ( 0 ) ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::getStream() instead.' , __METHOD__ , StreamableInputInterface :: class ) , E_USER_DEPRECATED ) ; } return $ this -> inputStream ; }
Returns the helper s input stream .
44,879
private function getShell ( ) { if ( null !== self :: $ shell ) { return self :: $ shell ; } self :: $ shell = false ; if ( file_exists ( '/usr/bin/env' ) ) { $ test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null" ; foreach ( array ( 'bash' , 'zsh' , 'ksh' , 'csh' ) as $ sh ) { if ( 'OK' === rtrim ( shell_exec ( sprintf ( $ test , $ sh ) ) ) ) { self :: $ shell = $ sh ; break ; } } } return self :: $ shell ; }
Returns a valid unix shell .
44,880
public function onMessage ( MessageEvent $ e ) { $ formatter = $ this -> getFormatter ( ) ; $ adapterKey = $ e -> getAdapter ( ) -> getKey ( ) ; $ level = $ e -> getLevel ( ) ; $ message = $ e -> getMessage ( ) ; $ match = '/\r\n?/' ; if ( ! preg_match ( $ match , $ message ) ) { $ msg = sprintf ( "%s (%s): %s" , $ formatter -> formatBlock ( $ adapterKey , 'info' ) , $ formatter -> formatBlock ( $ level , 'comment' ) , $ message ) ; } else { $ msg = sprintf ( "%s (%s): %s" , $ adapterKey , $ level , preg_replace ( '/\r\n?/' , '' , $ message ) ) ; } $ this -> getOutput ( ) -> writeln ( $ msg ) ; }
Write any messages received by an adapter
44,881
public function onTranscodeStart ( TranscodeEvent $ e ) { $ inpath = $ e -> getInputPath ( ) ; $ presetKey = $ e -> getPreset ( ) ; $ formatter = $ this -> getFormatter ( ) ; $ msg = sprintf ( "Starting transcode of file %s with preset %s ..." , $ formatter -> formatBlock ( $ inpath , 'info' ) , $ formatter -> formatBlock ( $ presetKey , 'info' ) ) ; $ this -> getOutput ( ) -> writeln ( $ msg ) ; $ this -> startTime = microtime ( true ) ; }
Write to output that a process has started .
44,882
public function onTranscodeComplete ( TranscodeEvent $ e ) { $ outpath = $ e -> getOutputPath ( ) ; $ totalTime = microtime ( true ) - $ this -> startTime ; $ formatter = $ this -> getFormatter ( ) ; $ msg = sprintf ( "Transcode completed in %s seconds." , $ formatter -> formatBlock ( round ( $ totalTime , 4 ) , 'info' ) ) ; $ this -> getOutput ( ) -> writeln ( $ msg ) ; $ msg = sprintf ( "Created new file %s" , $ formatter -> formatBlock ( $ outpath , 'info' ) ) ; $ this -> getOutput ( ) -> writeln ( $ msg ) ; }
Write to output that a process has completed .
44,883
public function onTranscodeFailure ( TranscodeEvent $ e ) { $ inpath = $ e -> getInputPath ( ) ; $ errorMsg = $ e -> getException ( ) -> getMessage ( ) ; $ formatter = $ this -> getFormatter ( ) ; $ msg = sprintf ( "Transcode of %s failed! Message: %s" , $ formatter -> formatBlock ( $ inpath , 'info' ) , $ formatter -> formatBlock ( $ errorMsg , 'error' ) ) ; $ this -> getOutput ( ) -> writeln ( $ msg ) ; }
Write to output that a process has failed .
44,884
public function newMigration ( $ name ) { $ time = time ( ) ; $ date = date ( "n/j/Y" ) ; $ fileName = "{$time}_migration.php" ; if ( $ name ) $ fileName = "{$time}_{$name}.php" ; $ file = $ this -> storagePath . "/" . $ fileName ; $ class = 'Migration_' . ( ( int ) $ time ) ; $ contents = array ( '<?php' ) ; $ contents [ ] = '/*' ; $ contents [ ] = " * {$name} migration file" ; $ contents [ ] = ' *' ; $ contents [ ] = ' * @author ' ; $ contents [ ] = ' * @version 1.0' ; $ contents [ ] = " * @date $date" ; $ contents [ ] = ' */' ; $ contents [ ] = 'class ' . $ class . ' extends \Core\Migration' ; $ contents [ ] = '{' ; $ contents [ ] = '' ; $ contents [ ] = " public function up()" ; $ contents [ ] = " {" ; $ contents [ ] = "" ; $ contents [ ] = " }" ; $ contents [ ] = "" ; $ contents [ ] = " public function down()" ; $ contents [ ] = " {" ; $ contents [ ] = "" ; $ contents [ ] = " }" ; $ contents [ ] = '}' ; if ( file_put_contents ( $ file , implode ( "\n" , $ contents ) ) ) { echo 'Create ' . $ file . "\n\r" ; return $ file ; } return false ; }
Create new migration file
44,885
public function createTable ( $ name , $ data ) { $ q = "CREATE TABLE {$name} (" ; foreach ( $ data as $ key => $ v ) { $ q .= $ key ; if ( isset ( $ v [ 'type' ] ) ) { $ q .= " {$v['type']}" ; if ( isset ( $ v [ 'length' ] ) ) { $ q .= "({$v['length']})" ; } else { if ( $ v [ 'type' ] != 'int' && $ v [ 'type' ] != 'datetime' ) { die ( "Please set length for table: {$name} - column: {$key}" ) ; } } if ( isset ( $ v [ 'unsigned' ] ) && $ v [ 'unsigned' ] == true ) { $ q .= " UNSIGNED" ; } if ( ! isset ( $ v [ 'null' ] ) || $ v [ 'null' ] == false ) { $ q .= " NOT NULL" ; } if ( isset ( $ v [ 'default' ] ) ) { if ( is_string ( $ v [ 'default' ] ) ) { $ v [ 'default' ] = "'{$v['default']}'" ; } $ q .= " DEFAULT {$v['default']}" ; } if ( isset ( $ v [ 'ai' ] ) && $ v [ 'ai' ] == true ) { $ q .= " AUTO_INCREMENT" ; } if ( ( isset ( $ v [ 'unique' ] ) && $ v [ 'unique' ] == true ) && ( isset ( $ v [ 'primary' ] ) && $ v [ 'primary' ] == true ) ) { die ( "Unique or Primary?" ) ; } if ( isset ( $ v [ 'unique' ] ) && $ v [ 'unique' ] == true ) { $ q .= " UNIQUE" ; } if ( isset ( $ v [ 'primary' ] ) && $ v [ 'primary' ] == true ) { $ q .= " PRIMARY KEY" ; } if ( isset ( $ v [ 'foreign' ] ) && isset ( $ v [ 'foreign' ] [ 'table' ] ) && isset ( $ v [ 'foreign' ] [ 'column' ] ) ) { $ q .= " ,FOREIGN KEY ({$key}) REFERENCES {$v['foreign']['table']}({$v['foreign']['column']})" ; if ( isset ( $ v [ 'foreign' ] [ 'delete' ] ) && $ v [ 'foreign' ] [ 'delete' ] == true ) { $ q .= " ON DELETE CASCADE" ; } if ( isset ( $ v [ 'foreign' ] [ 'update' ] ) && $ v [ 'foreign' ] [ 'update' ] == true ) { $ q .= " ON UPDATE CASCADE" ; } } $ q .= ", " ; } else { die ( "Please set type of column " ) ; } } $ q = substr ( $ q , 0 , - 2 ) ; $ q .= ")" ; return $ this -> executeQuery ( $ q ) ; }
Create new table
44,886
public static function createEventConfig ( Event $ event ) { if ( $ event -> sender -> handler_class != Item :: className ( ) || $ event -> sender -> handler_method != Item :: HANDLER_METHOD ) { return false ; } $ model = new self ( [ 'title' => 'new config' , 'content' => 'new content' , 'subject' => 'new subject' , 'owner_name' => $ event -> sender -> trigger_class , 'owner_event' => $ event -> sender -> trigger_event , 'address' => 'test@test.com' ] ) ; $ model -> save ( ) ; }
For autocreate config from new event module items .
44,887
public function setData ( array $ data , $ replaceTemplateVariables = true ) : self { $ this -> assertDataIsWritable ( ) ; if ( $ replaceTemplateVariables ) { $ data = $ this -> replaceTemplateVariables ( $ data ) ; } $ this -> _data = $ data ; return $ this ; }
Setter method for field data .
44,888
public function replaceTemplateVariables ( $ data ) { $ this -> assertDataIsWritable ( ) ; if ( $ templateVariables = $ this -> getOption ( 'templateVariables' , [ ] ) ) { $ templateVariableKeys = array_keys ( $ templateVariables ) ; if ( is_string ( $ data ) ) { $ data = str_replace ( $ templateVariableKeys , $ templateVariables , $ data ) ; } else if ( is_array ( $ data ) ) { array_walk_recursive ( $ data , function ( & $ value , & $ key , & $ data ) { $ value = str_replace ( $ data [ 'keys' ] , $ data [ 'values' ] , $ value ) ; } , [ 'keys' => $ templateVariableKeys , 'values' => $ templateVariables ] ) ; } } return $ data ; }
Replaces the data with the template variables configured on this instance .
44,889
public function has ( string $ index , array $ options = [ ] ) : bool { $ separator = isset ( $ options [ 'separator' ] ) ? $ options [ 'separator' ] : $ this -> getOption ( 'separator' , '.' ) ; $ value = $ this -> getData ( ) ; $ keys = explode ( $ separator , $ index ) ; foreach ( $ keys as $ key ) { if ( ! is_array ( $ value ) || ! array_key_exists ( $ key , $ value ) ) { return false ; } $ value = $ value [ $ key ] ; } return true ; }
Returns true if the parameter exists or false otherwise .
44,890
public function load ( ) { $ menu = app ( 'menu' ) ; $ files = $ this -> getFiles ( ) ; foreach ( $ files as $ file ) { require_once $ file -> getPath ( ) . '/' . $ file -> getFilename ( ) ; } }
Load menus .
44,891
protected function getPath ( ) : string { $ directory = config ( 'menus.directory' ) ; if ( ! $ directory ) { throw new DirectoryNotFound ( 'Directory with menu files does not exist.' ) ; } $ path = $ this -> file -> exists ( base_path ( $ directory ) ) ? base_path ( $ directory ) : __DIR__ . '/../resources/menus' ; return $ path ; }
Get path to the directory with menus files .
44,892
protected function getFiles ( ) : array { $ path = $ this -> getPath ( ) ; $ files = $ this -> file -> allFiles ( $ path ) ; if ( ! $ files ) { throw new MenuFilesNotFound ( "Menu files have not been found in [{$path}]." ) ; } return $ files ; }
Get menu files from the specified directory .
44,893
public static function Tf2d ( $ s , $ ihour , $ imin , $ sec , & $ days ) { $ days = ( $ s == '-' ? - 1.0 : 1.0 ) * ( 60.0 * ( 60.0 * ( ( double ) abs ( $ ihour ) ) + ( ( double ) abs ( $ imin ) ) ) + abs ( $ sec ) ) / DAYSEC ; if ( $ ihour < 0 || $ ihour > 23 ) return 1 ; if ( $ imin < 0 || $ imin > 59 ) return 2 ; if ( $ sec < 0.0 || $ sec >= 60.0 ) return 3 ; return 0 ; }
- - - - - - - - i a u T f 2 d - - - - - - - -
44,894
public function charge ( InvoicePayment $ payment ) { try { $ charge = Charge :: create ( [ 'amount' => $ payment -> amount * 100 , 'currency' => 'gbp' , 'description' => 'Invoice payment' , 'metadata' => [ 'invoice_id' => $ payment -> invoice -> id ] , 'source' => $ payment -> getPreCommitMetadataArray ( ) [ 'STRIPE_TOKEN' ] , ] ) ; $ payment -> payment_id = $ charge -> id ; $ responseMeta = new InvoicePaymentMetadata ( ) ; $ responseMeta -> key = 'GATEWAY_RESPONSE' ; $ responseMeta -> value = $ charge -> status ; $ payment -> metadata ( ) -> save ( $ responseMeta ) ; $ payment -> save ( ) ; return true ; } catch ( Card $ cardError ) { $ payment -> payment_id = $ cardError -> getJsonBody ( ) [ 'error' ] [ 'charge' ] ; $ responseMeta = new InvoicePaymentMetadata ( ) ; $ responseMeta -> key = 'GATEWAY_RESPONSE' ; $ responseMeta -> value = $ cardError -> getMessage ( ) ; $ payment -> metadata ( ) -> save ( $ responseMeta ) ; $ payment -> save ( ) ; return false ; } }
Make a charge using Stripe .
44,895
protected function parse ( ) : void { switch ( $ this -> notation ) { case self :: NOTATION_DOT_DECIMAL : $ this -> fromDotDecimal ( $ this -> value ) ; break ; case self :: NOTATION_BINARY : $ this -> fromBinary ( $ this -> value ) ; break ; case self :: NOTATION_CIDR_SHORT : $ this -> fromCidrShort ( $ this -> value ) ; break ; case self :: NOTATION_CIDR_LONG : $ this -> fromCidrLong ( $ this -> value ) ; break ; case self :: NOTATION_CIDR_BINARY : $ this -> fromCidrBinary ( $ this -> value ) ; break ; default : $ this -> notation = self :: NOTATION_INVALID ; } }
Parses the given value into the desired format .
44,896
public function isValid ( ) : bool { $ segments = explode ( '.' , $ this -> value , self :: NUM_SEGMENTS ) ; if ( count ( $ segments ) !== self :: NUM_SEGMENTS ) { return false ; } for ( $ i = 0 ; $ i < self :: NUM_SEGMENTS ; $ i ++ ) { $ value = ( int ) $ segments [ $ i ] ; if ( $ value < self :: MIN_VALUE || $ value > self :: MAX_VALUE ) { return false ; } } return true ; }
Test each segment of the addess to be within the MIN_VALUE and MAX_VALUE .
44,897
public function toArray ( ) { return [ 'severity' => $ this -> severity , 'msg' => $ this -> msg , 'hint' => $ this -> hint , 'link' => ! empty ( $ this -> link ) ? $ this -> link : null , 'iconCls' => $ this -> iconClass , ] ; }
Return array represantation of this problem .
44,898
public function byPassCache ( EventInterface $ event ) { $ pool = $ event -> getTarget ( ) ; if ( $ this -> trigger === '' || isset ( $ _REQUEST [ $ this -> trigger ] ) ) { return $ pool -> setError ( Message :: get ( Message :: CACHE_EXT_BYPASS ) , Message :: CACHE_EXT_BYPASS ) ; } else { return true ; } }
Skip the cache
44,899
public function insert ( $ value , $ priority ) { if ( ! is_int ( $ priority ) ) { throw new Exception \ InvalidArgumentException ( 'The priority must be an integer' ) ; } $ this -> values [ $ priority ] [ ] = $ value ; if ( ! isset ( $ this -> priorities [ $ priority ] ) ) { $ this -> priorities [ $ priority ] = $ priority ; $ this -> maxPriority = max ( $ priority , $ this -> maxPriority ) ; } ++ $ this -> count ; }
Insert an element in the queue with a specified priority