idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
10,500
|
public function search ( $ search = '' , $ criteria = SORTDATE , $ opt = SE_UID , $ dir = 1 ) { if ( '' === ( $ search = trim ( $ search ) ) ) { $ search = null ; } return imap_sort ( $ this -> stream , $ criteria , $ dir , $ opt , $ search ) ; }
|
Search mailbox for emails
|
10,501
|
public static function from ( DriverInterface $ driver , $ message = '' , $ code = 0 , \ Exception $ previous = null ) { $ self = $ message ? ( $ code ? new static ( $ message , $ code , $ previous ) : new static ( $ message ) ) : new static ( ) ; $ self -> setDriver ( $ driver ) ; return $ self ; }
|
Factory method to set the driver that created this exception .
|
10,502
|
protected function initStackSession ( ) { $ http = $ this -> getHttpDriver ( ) ; if ( ! $ http -> isSessionStarted ( ) ) { throw new DebugBarException ( 'Session must be started before using stack data in the songshenzong' ) ; } if ( ! $ http -> hasSessionValue ( $ this -> stackSessionNamespace ) ) { $ http -> setSessionValue ( $ this -> stackSessionNamespace , [ ] ) ; } return $ http ; }
|
Initializes the session for stacked data
|
10,503
|
private function addNamespaceFilter ( ProjectDescriptorBuilder $ builder , Filter $ filterManager ) { $ filter = new LegacyNamespaceFilter ( $ builder ) ; foreach ( $ this -> plugin -> getParameters ( ) as $ param ) { if ( $ param -> getKey ( ) == 'NamespacePrefix' ) { $ filter -> setNamespacePrefix ( $ param -> getValue ( ) ) ; } } $ filterManager -> attach ( 'phpDocumentor\Descriptor\ConstantDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\FunctionDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\InterfaceDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\TraitDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\PropertyDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\FileDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\ClassDescriptor' , $ filter ) ; }
|
Attaches the filter responsible for the conversion to all structural elements .
|
10,504
|
private function writeSession ( $ message , $ from = '' , $ is_error = false ) { if ( session_id ( ) ) { $ key = $ is_error ? $ this -> error_key : $ this -> message_key ; if ( ! isset ( $ _SESSION [ $ key ] ) || ! is_array ( $ _SESSION [ $ key ] ) ) { $ _SESSION [ $ key ] = [ ] ; } $ _SESSION [ $ key ] [ ] = ( empty ( $ from ) ? '' : sprintf ( '<strong>[%s]</strong> ' , $ from ) ) . $ message ; } }
|
Write message to session
|
10,505
|
public function flushMessage ( ) { if ( session_id ( ) ) { foreach ( [ $ this -> error_key => 'error' , $ this -> message_key => 'updated' ] as $ key => $ class_name ) { if ( isset ( $ _SESSION [ $ key ] ) && ! empty ( $ _SESSION [ $ key ] ) ) { $ markup = sprintf ( '<div class="%s"><p>%s</p></div>' , $ class_name , implode ( '<br />' , $ _SESSION [ $ key ] ) ) ; if ( is_admin ( ) ) { echo $ markup ; } else { echo apply_filters ( 'wpametu_prg_message_class' , $ markup , $ _SESSION [ $ key ] , $ class_name ) ; } $ _SESSION [ $ key ] = [ ] ; } } } }
|
Show message on screen
|
10,506
|
public static function prepare ( $ name , $ source , $ option ) { if ( is_string ( $ option ) ) { $ option = ( array ) Helper :: arrGet ( self :: $ multiples , $ option , array ( ) ) ; } $ lists = self :: find_multiple ( $ name , $ source , $ option ) ; $ found = self :: merge_multiple ( $ option , $ lists ) ; return $ found ; }
|
prepares for validation by creating a value from multiple value .
|
10,507
|
private static function find_multiple ( $ name , $ source , $ option ) { $ sep = Helper :: arrGet ( $ option , 'separator' , '_' ) ; $ suffix = explode ( ',' , $ option [ 'suffix' ] ) ; $ lists = [ ] ; foreach ( $ suffix as $ sfx ) { $ name_sfx = $ name . $ sep . $ sfx ; if ( array_key_exists ( $ name_sfx , $ source ) && trim ( $ source [ $ name_sfx ] ) ) { $ lists [ ] = trim ( $ source [ $ name_sfx ] ) ; } } return $ lists ; }
|
find multiples values from suffix list .
|
10,508
|
private static function merge_multiple ( $ option , $ lists ) { if ( empty ( $ lists ) ) { return null ; } if ( isset ( $ option [ 'format' ] ) ) { $ param = array_merge ( array ( $ option [ 'format' ] ) , $ lists ) ; $ found = call_user_func_array ( 'sprintf' , $ param ) ; } else { $ con = Helper :: arrGet ( $ option , 'connector' , '-' ) ; $ found = implode ( $ con , $ lists ) ; } return $ found ; }
|
merge the found list into one value .
|
10,509
|
public function to_path ( string $ id ) { if ( bbn \ str :: is_uid ( $ id ) ) { return $ this -> options -> to_path ( $ id , '' , $ this -> _get_public_root ( ) ) ; } return false ; }
|
Returns the path corresponding to an ID
|
10,510
|
public function add_shortcut ( string $ id ) : ? string { if ( ( $ bit = $ this -> pref -> get_bit ( $ id , false ) ) && ( $ id_option = $ this -> from_path ( 'shortcuts' ) ) && ( $ c = $ this -> pref -> get_class_cfg ( ) ) ) { if ( $ id_menu = $ this -> pref -> get_by_option ( $ id_option ) ) { $ id_menu = $ id_menu [ $ c [ 'arch' ] [ 'user_options' ] [ 'id' ] ] ; } else { $ id_menu = $ this -> pref -> add ( $ id_option , [ $ c [ 'arch' ] [ 'user_options' ] [ 'text' ] => _ ( 'Shortcuts' ) ] ) ; } if ( ! empty ( $ id_menu ) && ( $ arch = $ c [ 'arch' ] [ 'user_options_bits' ] ) ) { if ( ( $ bits = $ this -> pref -> get_bits ( $ id_menu , false , false ) ) && ( \ bbn \ x :: find ( $ bits , [ $ arch [ 'id_option' ] => $ bit [ $ arch [ 'id_option' ] ] ] ) !== false ) ) { return null ; } return $ this -> pref -> add_bit ( $ id_menu , [ $ arch [ 'id_option' ] => $ bit [ $ arch [ 'id_option' ] ] , $ arch [ 'text' ] => $ bit [ $ arch [ 'text' ] ] , $ arch [ 'cfg' ] => $ bit [ $ arch [ 'cfg' ] ] , $ arch [ 'num' ] => $ this -> pref -> next_bit_num ( $ id_menu ) ? : 1 ] ) ; } } return null ; }
|
Adds an user shortcut from a menu
|
10,511
|
public function remove_shortcut ( $ id ) : ? int { if ( \ bbn \ str :: is_uid ( $ id ) ) { return $ this -> pref -> delete_bit ( $ id ) ; } return null ; }
|
Removes an user shortcut
|
10,512
|
public function shortcuts ( ) : ? array { if ( ( $ id_option = $ this -> from_path ( 'shortcuts' ) ) && ( $ menu = $ this -> pref -> get_by_option ( $ id_option ) ) ) { $ links = $ this -> pref -> get_bits ( $ menu [ 'id' ] ) ; $ res = [ ] ; foreach ( $ links as $ link ) { if ( ( $ url = $ this -> to_path ( $ link [ 'id_option' ] ) ) ) { $ res [ ] = [ 'id' => $ link [ 'id' ] , 'id_option' => $ link [ 'id_option' ] , 'url' => $ url , 'text' => $ link [ 'text' ] , 'icon' => $ link [ 'icon' ] , 'num' => $ link [ 'num' ] ] ; } } return $ res ; } return null ; }
|
Gets the user shortcuts list
|
10,513
|
public function remove ( string $ id ) { if ( \ bbn \ str :: is_uid ( $ id ) ) { if ( $ id_menu = $ this -> get_id_menu ( $ id ) ) { if ( $ this -> pref -> delete_bit ( $ id ) ) { $ this -> delete_cache ( $ id_menu ) ; return true ; } } else if ( $ this -> pref -> delete ( $ id ) ) { $ this -> options -> delete_cache ( $ this -> from_path ( 'menus' ) ) ; return true ; } } return false ; }
|
Removes menu and deletes parent cache
|
10,514
|
public function add ( $ id_menu , array $ cfg = null ) : ? string { $ ids = [ ] ; if ( \ is_array ( $ id_menu ) ) { $ cfg = $ id_menu ; $ id_opt = $ this -> from_path ( 'menus' ) ; } if ( ! empty ( $ cfg ) ) { if ( \ bbn \ str :: is_uid ( $ id_menu ) ) { $ id = $ this -> pref -> add_bit ( $ id_menu , $ cfg ) ; } else { $ id = $ this -> pref -> add ( $ id_opt , $ cfg ) ; } } if ( ! empty ( $ id ) ) { if ( \ bbn \ str :: is_uid ( $ id_menu ) ) { $ this -> delete_cache ( $ id_menu ) ; } $ this -> options -> delete_cache ( $ id_opt ) ; return $ id ; } return null ; }
|
Add menu and delete the chache .
|
10,515
|
public function set ( string $ id , array $ cfg ) : bool { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ id_menu = $ this -> get_id_menu ( $ id ) ) && $ this -> pref -> update_bit ( $ id , $ cfg ) ) { $ this -> delete_cache ( $ id_menu ) ; return true ; } return false ; }
|
Updates a menu item and deletes the menu cache
|
10,516
|
public function set_text ( string $ id , string $ text ) : bool { if ( \ bbn \ str :: is_uid ( $ id ) && $ this -> pref -> set_text ( $ id , $ text ) ) { $ this -> delete_cache ( $ id ) ; return true ; } return false ; }
|
Sets the menu s text and deletes its chache
|
10,517
|
public function delete_cache ( $ id_menu ) { $ this -> options -> delete_cache ( $ this -> from_path ( 'menus' ) , true ) ; return $ this -> cache_delete ( $ id_menu ) ; }
|
Clears the menu cache
|
10,518
|
public function get_default ( ) : ? string { if ( ( $ id_opt = $ this -> from_path ( 'default' ) ) && ( $ all = $ this -> pref -> get_all ( $ id_opt ) ) ) { $ id = false ; foreach ( $ all as $ a ) { if ( ! empty ( $ a [ 'id_user' ] ) ) { $ id = $ a [ 'id_alias' ] ; break ; } else if ( ! empty ( $ a [ 'id_group' ] ) ) { $ id = $ a [ 'id_alias' ] ; break ; } else if ( ! empty ( $ a [ 'public' ] ) ) { $ id = $ a [ 'id_alias' ] ; break ; } } return $ id ; } return null ; }
|
Gets the user s default menu
|
10,519
|
public function clone ( string $ id , string $ name ) : ? string { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ id_menu = $ this -> add ( [ 'text' => $ name ] ) ) ) { if ( ( $ bits = $ this -> pref -> get_full_bits ( $ id ) ) && ! $ this -> _clone ( $ id_menu , $ bits ) ) { return null ; } return $ id_menu ; } return null ; }
|
Clones a menu
|
10,520
|
public function copy ( string $ id_menu , string $ id_menu_to , array $ cfg ) : ? string { if ( \ bbn \ str :: is_uid ( $ id_menu ) && \ bbn \ str :: is_uid ( $ id_menu_to ) && ( $ bits = $ this -> pref -> get_full_bits ( $ id_menu ) ) && ( $ id = $ this -> add ( $ id_menu_to , $ cfg ) ) && $ this -> _clone ( $ id_menu_to , $ bits , $ id ) ) { return $ id ; } return null ; }
|
Copies a menu into another one .
|
10,521
|
public function insert ( $ entity ) { $ values = $ this -> getInsertValues ( $ entity , $ this -> namingContention ) ; $ keyString = implode ( array_keys ( $ values ) , ', ' ) ; $ questionMarkString = count ( $ values ) === 0 ? '' : ( '?' . str_repeat ( ', ?' , count ( $ values ) - 1 ) ) ; $ sql = "INSERT INTO $this->tableName ($keyString) VALUES ($questionMarkString)" ; $ sth = $ this -> pdo -> prepare ( $ sql ) ; $ sth -> execute ( array_values ( $ values ) ) ; $ id = $ this -> pdo -> lastInsertId ( ) ; if ( $ this -> idProperty !== null ) { $ this -> idProperty -> setValue ( $ entity , $ id ) ; } return $ id ; }
|
Insert an entity into the database . You can optionally provide a property name . If you do the inserted id will be assigned to that property .
|
10,522
|
public function update ( $ entity ) { if ( $ this -> idProperty === null ) { throw new ConfigurationException ( 'No idProperty set' ) ; } $ id = $ this -> idProperty -> getValue ( $ entity ) ; if ( $ id === null ) { throw new ConfigurationException ( 'Value of ' . $ this -> idProperty -> getName ( ) . ' is null' ) ; } $ values = $ this -> getInsertValues ( $ entity , $ this -> namingContention ) ; $ keyString = implode ( array_keys ( $ values ) , ' = ?,' ) . ' = ?' ; $ idColumn = $ this -> namingContention -> propertyToColumnName ( $ this -> idProperty ) ; $ onlyValues = array_values ( $ values ) ; $ onlyValues [ ] = $ id ; $ sql = "UPDATE $this->tableName SET $keyString WHERE $idColumn = ?" ; $ sth = $ this -> pdo -> prepare ( $ sql ) ; $ sth -> execute ( $ onlyValues ) ; return $ id ; }
|
Update an existing entity in the database .
|
10,523
|
public function save ( $ entity ) { if ( $ this -> idProperty -> getValue ( $ entity ) === null ) { return $ this -> insert ( $ entity ) ; } else { return $ this -> update ( $ entity ) ; } }
|
Insert an entity into the database if it has no id yet . Otherwise update it by id .
|
10,524
|
public function get ( $ id ) { $ idName = ucfirst ( $ this -> idProperty -> getName ( ) ) ; return $ this -> __call ( "getBy$idName" , array ( $ id ) ) ; }
|
Get an entity by it s idProperty value .
|
10,525
|
public function delete ( $ id ) { $ idName = ucfirst ( $ this -> idProperty -> getName ( ) ) ; return $ this -> __call ( "deleteBy$idName" , array ( $ id ) ) ; }
|
Delete an entity by it s idProperty value .
|
10,526
|
private function addMethod ( $ method ) { $ tokens = $ this -> methodParser -> parse ( $ method ) ; $ query = $ this -> queryBuilder -> build ( $ tokens , $ this -> tableName , $ this -> namingContention , $ this -> entityClass ) ; if ( $ query -> getResultMode ( ) <= QueryBuilderResult :: RESULT_SELECT_MULTIPLE ) { $ this -> addSelectionMethod ( $ query , $ method ) ; } else { $ this -> addIntResultMethod ( $ query , $ method ) ; } }
|
Parse a dsl method and add it to this repository .
|
10,527
|
private function addSelectionMethod ( QueryBuilderResult $ query , $ methodName ) { $ findMethod = function ( ) use ( $ query , $ methodName ) { $ sth = $ this -> pdo -> prepare ( $ query -> getSql ( ) ) ; $ sth -> setFetchMode ( \ PDO :: FETCH_CLASS , $ this -> entityClass -> getName ( ) ) ; try { $ sth -> execute ( func_get_args ( ) ) ; } catch ( PDOException $ e ) { throw new DslSyntaxException ( 'Failed to run query [' . $ methodName . '] with parameters ' . print_r ( func_get_args ( ) , true ) ) ; } switch ( $ query -> getResultMode ( ) ) { case QueryBuilderResult :: RESULT_SELECT_SINGLE : return $ sth -> fetch ( ) ; case QueryBuilderResult :: RESULT_SELECT_MULTIPLE : return $ sth -> fetchAll ( ) ; } throw new DslSyntaxException ( 'Result Mode ' . $ query -> getResultMode ( ) . ' is not implemented' , DATADO_ILLEGAL_RESULT_MODE ) ; } ; $ this -> methods [ $ methodName ] = \ Closure :: bind ( $ findMethod , $ this , get_class ( ) ) ; }
|
Add a method that can either result in an entity or an array of entities .
|
10,528
|
private function addIntResultMethod ( QueryBuilderResult $ query , $ methodName ) { $ intResultMethod = function ( ) use ( $ query ) { $ sth = $ this -> pdo -> prepare ( $ query -> getSql ( ) ) ; $ sth -> execute ( func_get_args ( ) ) ; return $ sth -> rowCount ( ) ; } ; $ this -> methods [ $ methodName ] = \ Closure :: bind ( $ intResultMethod , $ this , get_class ( ) ) ; }
|
Add a new method that will result in an integer .
|
10,529
|
public function checkDatabase ( $ showAllData = true ) { switch ( $ this -> pdo -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ) { case 'mysql' : $ sth = $ this -> pdo -> prepare ( 'SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ?' ) ; $ sth -> execute ( array ( $ this -> tableName ) ) ; $ columnNameColumn = 'COLUMN_NAME' ; break ; case 'sqlite' : $ sth = $ this -> pdo -> prepare ( "PRAGMA table_info($this->tableName)" ) ; $ sth -> execute ( ) ; $ columnNameColumn = 'name' ; break ; default : echo '<p>SQL Driver: ' . $ this -> pdo -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) . ' is not supported by the checking tool... sorry</p>' . PHP_EOL ; return ; } $ tableProperties = $ sth -> fetchAll ( ) ; $ classProperties = $ this -> entityClass -> getProperties ( ) ; $ properties = [ ] ; foreach ( $ tableProperties as $ prop ) { $ newProp = new stdClass ( ) ; $ newProp -> actualColumnName = $ prop [ $ columnNameColumn ] ; $ properties [ $ newProp -> actualColumnName ] = $ newProp ; } foreach ( $ classProperties as $ prop ) { $ expectedColumnName = $ this -> namingContention -> propertyToColumnName ( $ prop ) ; if ( array_key_exists ( $ expectedColumnName , $ properties ) ) { $ newProp = $ properties [ $ expectedColumnName ] ; } else { $ newProp = new stdClass ( ) ; $ properties [ $ expectedColumnName ] = $ newProp ; } $ newProp -> propertyName = $ prop -> getName ( ) ; $ newProp -> expectedColumnName = $ expectedColumnName ; } $ issetOr = function ( & $ value , $ default = '' ) { return isset ( $ value ) ? $ value : $ default ; } ; $ pdoAtt = function ( $ att ) { try { return $ this -> pdo -> getAttribute ( $ att ) ; } catch ( PDOException $ e ) { return 'Not supported by driver' ; } } ; $ getClass = function ( stdClass $ prop ) use ( $ issetOr ) { $ classes = $ issetOr ( $ prop -> expectedColumnName ) === $ issetOr ( $ prop -> actualColumnName ) ? 'correct' : 'error' ; if ( $ issetOr ( $ prop -> propertyName ) === $ this -> idProperty -> getName ( ) ) { $ classes .= ' primary-key' ; } return $ classes ; } ; $ entitiesError = false ; $ entities = [ ] ; if ( $ showAllData ) { try { $ entities = $ this -> findAll ( ) ; } catch ( \ Exception $ e ) { $ entitiesError = $ e ; } } include 'Check/checkDatabaseTable.php' ; }
|
This method will run some analysis on the correctness of your configuration . It will be exported to the screen .
|
10,530
|
protected function getPDO ( ) { if ( null === $ this -> pdo ) { $ this -> pdo = new \ PDO ( $ this -> dsn , $ this -> user , $ this -> password , $ this -> options ) ; } return $ this -> pdo ; }
|
Get PDO object . Cache the result
|
10,531
|
public function register ( Application $ app ) { $ app [ 'parser.example.finder' ] = new Example \ Finder ( ) ; $ this -> addCache ( $ app ) ; $ this -> addAssemblers ( $ app ) ; $ this -> addFilters ( $ app ) ; $ this -> addValidators ( $ app ) ; $ this -> addBuilder ( $ app ) ; $ this -> attachFiltersToManager ( $ app [ 'descriptor.filter' ] , $ app ) ; $ app [ 'descriptor.analyzer' ] = function ( ) { return new ProjectAnalyzer ( ) ; } ; }
|
Adds the services needed to build the descriptors .
|
10,532
|
public function attachFiltersToManager ( Filter $ filterManager , Application $ app ) { $ stripOnVisibility = new StripOnVisibility ( $ app [ 'descriptor.builder' ] ) ; $ filtersOnAllDescriptors = array ( new StripInternal ( $ app [ 'descriptor.builder' ] ) , new StripIgnore ( $ app [ 'descriptor.builder' ] ) ) ; foreach ( $ filtersOnAllDescriptors as $ filter ) { $ filterManager -> attach ( 'phpDocumentor\Descriptor\ConstantDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\FunctionDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\InterfaceDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\TraitDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\PropertyDescriptor' , $ filter ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\MethodDescriptor' , $ filter ) ; } $ filterManager -> attach ( 'phpDocumentor\Descriptor\PropertyDescriptor' , $ stripOnVisibility ) ; $ filterManager -> attach ( 'phpDocumentor\Descriptor\MethodDescriptor' , $ stripOnVisibility ) ; return $ filterManager ; }
|
Attaches filters to the manager .
|
10,533
|
protected function addCache ( Application $ app ) { $ app [ 'descriptor.cache' ] = $ app -> share ( function ( ) { $ cache = new Filesystem ( ) ; $ cache -> setOptions ( array ( 'namespace' => 'phpdoc-cache' , 'cache_dir' => sys_get_temp_dir ( ) , ) ) ; $ plugin = new SerializerPlugin ( ) ; if ( extension_loaded ( 'igbinary' ) ) { $ options = new PluginOptions ( ) ; $ options -> setSerializer ( 'igbinary' ) ; $ plugin -> setOptions ( $ options ) ; } $ cache -> addPlugin ( $ plugin ) ; return $ cache ; } ) ; }
|
Adds the caching mechanism to the dependency injection container with key descriptor . cache .
|
10,534
|
protected function addBuilder ( Application $ app ) { if ( extension_loaded ( 'igbinary' ) ) { $ app [ 'descriptor.builder.serializer' ] = 'IgBinary' ; } else { $ app [ 'descriptor.builder.serializer' ] = 'PhpSerialize' ; } $ app [ 'descriptor.builder' ] = $ app -> share ( function ( $ container ) { $ builder = new ProjectDescriptorBuilder ( $ container [ 'descriptor.builder.assembler.factory' ] , $ container [ 'descriptor.filter' ] , $ container [ 'validator' ] ) ; $ builder -> setTranslator ( $ container [ 'translator' ] ) ; return $ builder ; } ) ; }
|
Adds the Building mechanism using the key descriptor . builder .
|
10,535
|
protected function addAssemblers ( Application $ app ) { $ app [ 'descriptor.builder.assembler.factory' ] = $ app -> share ( function ( ) { return new AssemblerFactory ( ) ; } ) ; $ provider = $ this ; $ app [ 'descriptor.builder.assembler.factory' ] = $ app -> share ( $ app -> extend ( 'descriptor.builder.assembler.factory' , function ( $ factory ) use ( $ provider , $ app ) { return $ provider -> attachAssemblersToFactory ( $ factory , $ app ) ; } ) ) ; }
|
Adds the assembler factory and attaches the basic assemblers with key descriptor . builder . assembler . factory .
|
10,536
|
protected function addValidators ( Application $ app ) { if ( ! isset ( $ app [ 'validator' ] ) ) { throw new Exception \ MissingDependencyException ( 'The validator manager is missing' ) ; } $ provider = $ this ; $ app [ 'validator' ] = $ app -> share ( $ app -> extend ( 'validator' , function ( $ validatorManager ) use ( $ provider ) { return $ provider -> attachValidators ( $ validatorManager ) ; } ) ) ; }
|
Adds validators for the descriptors to the validator manager .
|
10,537
|
public function parseUrl ( $ url , array $ data ) { return ( empty ( $ data ) ) ? $ url : $ url . '?' . $ this -> parseData ( $ data ) ; }
|
Build URL with query string
|
10,538
|
public function getChainFor ( $ fqcn ) { if ( ! isset ( $ this -> chains [ $ fqcn ] ) ) { $ this -> chains [ $ fqcn ] = new FilterChain ( ) ; } return $ this -> chains [ $ fqcn ] ; }
|
Retrieves the filters for a class with a given FQCN .
|
10,539
|
protected function getRateLimit ( array $ headers ) { $ rateLimit = array ( 'limit' => '?' , 'reset' => '?' , ) ; foreach ( $ headers as $ header ) { $ header = trim ( $ header ) ; if ( false === strpos ( $ header , 'X-RateLimit-' ) ) { continue ; } list ( $ type , $ value ) = explode ( ':' , $ header , 2 ) ; switch ( $ type ) { case 'X-RateLimit-Limit' : $ rateLimit [ 'limit' ] = ( int ) trim ( $ value ) ; break ; case 'X-RateLimit-Reset' : $ rateLimit [ 'reset' ] = date ( 'Y-m-d H:i:s' , ( int ) trim ( $ value ) ) ; break ; } } return $ rateLimit ; }
|
Extract ratelimit from response .
|
10,540
|
public function connect ( ) { if ( ! is_numeric ( $ this -> port ) ) { if ( substr ( $ this -> host , 0 , 3 ) == 'ssl' ) { $ this -> port = 5223 ; $ this -> log ( "Connecting with SSL" ) ; } else { $ this -> port = 5222 ; } } parent :: __construct ( $ this -> host . ':' . $ this -> port , $ this -> timeout ) ; $ this -> open ( ) ; $ this -> write ( "<stream:stream to='$this->host' xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en' version='1.0'>" ) ; $ this -> read ( ) ; $ this -> read ( ) ; $ this -> connected = true ; }
|
Connects to the XMPP server
|
10,541
|
public function login ( ) { if ( ! $ this -> connected ) { $ this -> reconnect ( ) ; } $ this -> jid = $ this -> uname . '@' . substr ( $ this -> host , strpos ( $ this -> host , '//' ) + 2 ) ; if ( $ this -> pass ) { $ this -> write ( "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>" . base64_encode ( "\x00" . $ this -> uname . "\x00" . $ this -> pass ) . "</auth>" ) ; } else { $ this -> write ( "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS' />" ) ; } $ buffer = $ this -> read ( ) ; if ( substr ( $ buffer , 0 , 5 ) == '<fail' ) { $ this -> onError ( 0 , 'Cound not log in' ) ; return false ; } $ this -> client_name = empty ( $ this -> client_name ) ? __CLASS__ : $ this -> client_name ; if ( ! $ this -> sendClientName ( ) ) { return false ; } $ this -> setStatus ( $ this -> status ) ; $ this -> onAfterLogin ( ) ; return true ; }
|
Login to the XMPP server as a user and set their precence to avaiable
|
10,542
|
public function sendPresence ( \ sb \ XMPP \ Presence $ presence ) { $ presence -> setFrom ( $ this -> jid ) ; return $ this -> write ( $ presence ) ; }
|
Converts a presense request instance to XML and sends it . It sets the from to the bots jid for you
|
10,543
|
public function setStatus ( $ status = null ) { $ presence = new \ sb \ XMPP \ Presence ( ) ; $ presence -> setStatus ( is_string ( $ status ) ? $ status : $ this -> status ) ; $ this -> sendPresence ( $ presence ) ; }
|
Sets status message
|
10,544
|
public function sendSimpleMessage ( $ to , $ body ) { $ message = new \ sb \ XMPP \ Message ( ) ; $ message -> setTo ( $ to ) ; $ message -> setBody ( $ body ) ; $ this -> sendMessage ( $ message ) ; }
|
Sends simple string based text message
|
10,545
|
public function sendAcceptSubscriptionRequest ( $ to ) { $ presence = new \ sb \ XMPP \ Presence ( ) ; $ presence -> setType ( 'subscribed' ) ; $ presence -> setTo ( $ to ) ; return $ this -> sendPresence ( $ presence ) ; }
|
Send a presence message accepting subscription request to a jid
|
10,546
|
public function sendSubscriptionRequest ( $ to ) { $ presence = new \ sb \ XMPP \ Presence ( ) ; $ presence -> setTo ( $ to ) ; $ presence -> setType ( 'subscribe' ) ; $ presence -> setFrom ( $ this -> jid ) ; return $ this -> sendPresence ( $ presence ) ; }
|
Sends a subscription request to a jid
|
10,547
|
public function sleep ( $ secs ) { $ str = 'Going to sleep for ' . $ secs . 'secs' ; $ this -> log ( 'NOTICE: ' . $ str ) ; $ this -> setStatus ( $ str ) ; sleep ( $ secs ) ; $ this -> setStatus ( $ this -> status ? $ this -> status : 'awake' ) ; }
|
Puts the bot to sleep for a while
|
10,548
|
public function composingStart ( $ to ) { $ message = new \ sb \ XMPP \ Message ( ) ; $ message -> setTo ( $ to ) ; $ message -> setFrom ( $ this -> jid ) ; $ message -> setType ( 'chat' ) ; $ node = $ message -> createElement ( 'composing' ) ; $ attr = $ message -> createAttribute ( 'xmlns' ) ; $ node -> appendChild ( $ attr ) ; $ attr -> appendChild ( $ message -> createTextNode ( 'http://jabber.org/protocol/chatstates' ) ) ; $ message -> doc -> appendChild ( $ node ) ; $ this -> sendMessage ( $ message ) ; }
|
Send an indication that the bot is composing text .
|
10,549
|
final public function read ( $ byte_count = null ) { $ buffer = '' ; $ read = array ( $ this -> socket ) ; $ updated = @ stream_select ( $ read , $ write , $ except , 1 ) ; if ( $ updated > 0 ) { $ data = fread ( $ this -> socket , 4096 ) ; if ( $ data ) { $ buffer = $ data ; } } if ( ! empty ( $ buffer ) ) { $ this -> log ( 'RECEIVED: ' . $ buffer ) ; } return $ buffer ; }
|
Reads from the socket should be protected but can t because this is inherited as public
|
10,550
|
final public function listen ( ) { $ this -> log ( "Listening..." ) ; $ x = 1 ; while ( $ x ) { $ x ++ ; $ xml = $ this -> read ( 1024 ) ; if ( ! empty ( $ xml ) ) { if ( $ this -> onRead ( $ xml ) === false ) { return false ; } } if ( substr ( $ xml , 0 , 8 ) == '<message' ) { $ message = new \ sb \ XMPP \ Message ( $ xml ) ; $ message -> client = $ this ; $ this -> onMessage ( $ message ) ; } elseif ( substr ( $ xml , 0 , 9 ) == '<presence' ) { $ presence = new \ sb \ XMPP \ Presence ( $ xml ) ; $ from = $ presence -> getFrom ( ) ; $ type = $ presence -> getType ( ) ; if ( is_array ( $ this -> buddies_online ) ) { $ status = $ presence -> getStatus ( ) ; if ( $ from && $ type == 'unavailable' ) { unset ( $ this -> buddies_online [ $ from ] ) ; $ this -> log ( 'NOTICE: ' . $ from . ' is unavailable' ) ; } elseif ( $ from ) { $ this -> buddies_online [ $ from ] = $ status ; $ this -> log ( 'NOTICE: ' . $ from . ' is ' . $ status ) ; } } if ( strstr ( $ type , 'subscribe' ) && $ this -> onSubscriptionRequest ( $ presence ) ) { $ this -> sendAcceptSubscriptionRequest ( $ from ) ; $ this -> log ( 'NOTICE: Auto accepting subscription request from ' . $ from ) ; } $ this -> onPresence ( $ presence ) ; } if ( $ x % 100 == 0 ) { $ presence = new \ sb \ XMPP \ Presence ( ) ; $ presence -> setStatus ( $ this -> status ) ; $ this -> sendPresence ( $ presence ) ; $ x = 1 ; } usleep ( 100000 ) ; } }
|
Listens for incoming chat on the socket
|
10,551
|
final public function write ( $ xml ) { if ( $ xml instanceof \ SimpleXMLElement ) { $ xml = $ xml -> asXML ( ) ; } elseif ( $ xml instanceof \ DOMDocument ) { $ xml = $ xml -> saveXML ( ) ; } $ this -> log ( "SENT: " . $ xml ) ; return parent :: write ( $ xml ) ; }
|
Writes XML to the socket client
|
10,552
|
final public function close ( ) { $ this -> onCloseConnection ( ) ; if ( $ this -> socket ) { $ this -> write ( "</stream:stream>" ) ; parent :: close ( ) ; $ this -> connected = false ; } }
|
Ends the stream and closes the connection
|
10,553
|
public function indexTree ( $ id = null ) { $ this -> authorize ( 'readList' , Content :: class ) ; $ input = $ this -> validator -> validate ( 'tree' ) ; $ params = $ this -> processor -> process ( $ input ) -> getProcessedFields ( ) ; $ this -> getSerializer ( ) -> parseIncludes ( 'children' ) ; if ( $ id ) { $ content = $ this -> repository -> getById ( $ id ) ; if ( ! empty ( $ content ) ) { return $ this -> respondWithSuccess ( $ this -> repository -> getTree ( $ content , $ params [ 'filter' ] , $ params [ 'orderBy' ] ) , new ContentTransformer ) ; } else { return $ this -> respondNotFound ( ) ; } } $ nodes = $ this -> repository -> getContentsByLevel ( $ params [ 'filter' ] , $ params [ 'orderBy' ] , null ) ; $ trees = $ this -> repository -> buildTree ( $ nodes ) ; if ( ! empty ( $ trees ) && ! $ trees instanceof LaravelCollection ) { $ trees = new LaravelCollection ( [ $ trees ] ) ; } return $ this -> respondWithSuccess ( $ trees , new ContentTransformer ) ; }
|
Display a listing of the resource as nested tree .
|
10,554
|
protected function buildSyncData ( array $ input ) { $ syncData = [ ] ; foreach ( $ input [ 'data' ] as $ item ) { $ syncData [ $ item [ 'id' ] ] = [ 'weight' => isset ( $ item [ 'weight' ] ) ? $ item [ 'weight' ] : 0 ] ; } return $ syncData ; }
|
It builds syncData
|
10,555
|
public function getRemainingLifetime ( $ id , $ attributes = array ( ) ) { if ( count ( $ found = $ this -> search ( $ id , $ attributes ) ) > 0 ) { $ identifier = $ found [ 0 ] [ 2 ] ; return $ this -> calcLifetime ( $ identifier ) ; } return 0 ; }
|
Returns the time in seconds which remains for a cache object before it gets outdated . In case the cache object is already outdated or does not exists this method returns 0 .
|
10,556
|
public function generateIdentifier ( $ id , $ attributes = null ) { $ identifier = strtolower ( $ this -> backendName ) . $ this -> properties [ 'location' ] . $ id . ( ( $ attributes !== null && ! empty ( $ attributes ) ) ? md5 ( serialize ( $ attributes ) ) : '' ) ; return urlencode ( $ identifier ) ; }
|
Generates the storage internal identifier from ID and attributes .
|
10,557
|
public function purge ( $ limit = null ) { $ this -> fetchSearchRegistry ( true ) ; $ purgedIds = array ( ) ; $ ttl = $ this -> properties [ 'options' ] -> ttl ; foreach ( $ this -> searchRegistry [ $ this -> properties [ 'location' ] ] as $ id => $ identifiers ) { $ deleted = false ; foreach ( $ identifiers as $ identifier => $ data ) { if ( $ ttl !== false && $ this -> calcLifetime ( $ identifier ) == 0 ) { $ this -> backend -> delete ( $ identifier ) ; $ this -> unRegisterIdentifier ( null , null , $ identifiers , true ) ; $ deleted = true ; } } if ( $ deleted === true ) { $ purgedIds [ ] = $ id ; } if ( $ limit !== null && count ( $ purgedIds ) >= $ limit ) { break ; } } $ this -> storeSearchRegistry ( ) ; return $ purgedIds ; }
|
Purge outdated data from the storage .
|
10,558
|
public function reset ( ) { $ this -> backend -> reset ( ) ; $ this -> registry = array ( ) ; $ this -> searchRegistry = array ( $ this -> properties [ 'location' ] => null ) ; $ this -> storeSearchRegistry ( ) ; }
|
Reset the complete storage .
|
10,559
|
protected function registerIdentifier ( $ id = null , $ attributes = array ( ) , $ identifier = null ) { $ identifier = ( $ identifier !== null ) ? $ identifier : $ this -> generateIdentifier ( $ id , $ attributes ) ; $ location = $ this -> properties [ 'location' ] ; $ this -> fetchSearchRegistry ( ) ; if ( ! isset ( $ this -> searchRegistry [ $ location ] [ $ id ] [ $ identifier ] ) ) { if ( ! isset ( $ this -> searchRegistry [ $ location ] [ $ id ] ) || ! is_array ( $ this -> searchRegistry [ $ location ] [ $ id ] ) ) { $ this -> searchRegistry [ $ location ] [ $ id ] = array ( ) ; } $ this -> searchRegistry [ $ location ] [ $ id ] [ $ identifier ] = new ezcCacheStorageMemoryRegisterStruct ( $ id , $ attributes , $ identifier , $ location ) ; $ this -> storeSearchRegistry ( ) ; } }
|
Registers an identifier to facilitate searching .
|
10,560
|
protected function unRegisterIdentifier ( $ id = null , $ attributes = array ( ) , $ identifier = null , $ delayStore = false ) { $ identifier = ( $ identifier !== null ) ? $ identifier : $ this -> generateIdentifier ( $ id , $ attributes ) ; $ location = $ this -> properties [ 'location' ] ; $ this -> fetchSearchRegistry ( ! $ delayStore ) ; if ( $ this -> searchRegistry === false ) { $ this -> searchRegistry = array ( ) ; } if ( isset ( $ this -> searchRegistry [ $ location ] [ $ id ] [ $ identifier ] ) ) { unset ( $ this -> searchRegistry [ $ location ] [ $ id ] [ $ identifier ] , $ this -> registry [ $ location ] [ $ id ] [ $ identifier ] ) ; if ( $ delayStore === false ) { $ this -> storeSearchRegistry ( ) ; } } }
|
Un - registers a previously registered identifier .
|
10,561
|
protected function fetchSearchRegistry ( $ requireFresh = false ) { $ location = $ this -> properties [ 'location' ] ; if ( ! is_array ( $ this -> searchRegistry ) ) { $ this -> searchRegistry = array ( ) ; } if ( ! isset ( $ this -> searchRegistry [ $ location ] ) || ! is_array ( $ this -> searchRegistry [ $ location ] ) ) { $ this -> searchRegistry [ $ location ] = array ( ) ; } if ( empty ( $ this -> searchRegistry [ $ location ] ) || $ requireFresh === true ) { $ this -> searchRegistry [ $ location ] = $ this -> backend -> fetch ( $ this -> registryName . '_' . urlencode ( $ location ) ) ; } }
|
Fetches the search registry from the backend or creates it if empty .
|
10,562
|
protected function storeSearchRegistry ( ) { $ location = $ this -> properties [ 'location' ] ; $ this -> backend -> store ( $ this -> registryName . '_' . urlencode ( $ location ) , $ this -> searchRegistry [ $ location ] ) ; $ this -> searchRegistry [ $ location ] = null ; $ this -> fetchSearchRegistry ( true ) ; }
|
Stores the search registry in the backend .
|
10,563
|
public function apiStore ( ) { DB :: beginTransaction ( ) ; try { $ record = $ this -> __apiStore ( ) ; } catch ( \ Exception $ e ) { DB :: rollback ( ) ; return HCLog :: error ( 'CORE-0002' . $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; } DB :: commit ( ) ; return response ( $ record ) ; }
|
Function which will store new record
|
10,564
|
public function apiUpdate ( string $ id ) { DB :: beginTransaction ( ) ; try { $ record = $ this -> __apiUpdate ( $ id ) ; } catch ( \ Exception $ e ) { DB :: rollback ( ) ; return HCLog :: error ( 'CORE-0003' . $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; } DB :: commit ( ) ; return $ record ; }
|
Function which will update record
|
10,565
|
public function apiUpdateStrict ( string $ id ) { DB :: beginTransaction ( ) ; try { $ record = $ this -> __apiUpdateStrict ( $ id ) ; } catch ( \ Exception $ e ) { DB :: rollback ( ) ; return HCLog :: error ( 'CORE-0003' . $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; } DB :: commit ( ) ; return $ record ; }
|
Function which will update specific values of the record
|
10,566
|
private function initializeDelete ( string $ id = null , bool $ soft ) { if ( $ id ) $ list = [ $ id ] ; else $ list = request ( ) -> input ( 'list' ) ; if ( sizeOf ( $ list ) <= 0 ) return HCLog :: info ( 'CORE-0004' , trans ( 'HCTranslations::core.nothing_to_delete' ) ) ; DB :: beginTransaction ( ) ; try { if ( $ soft ) $ response = $ this -> __apiDestroy ( $ list ) ; else $ response = $ this -> __apiForceDelete ( $ list ) ; } catch ( \ Exception $ e ) { DB :: rollback ( ) ; return HCLog :: error ( 'CORE-0005' . $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; } DB :: commit ( ) ; if ( isset ( $ response ) ) return $ response ; return [ 'success' => true , 'list' => $ list ] ; }
|
Function which will actually call deletion function
|
10,567
|
public function apiRestore ( ) { $ toRestore = request ( ) -> input ( 'list' ) ; if ( sizeOf ( $ toRestore ) <= 0 ) return HCLog :: info ( 'CORE-0006' , trans ( 'HCTranslations::core.nothing_to_restore' ) ) ; $ response = $ this -> __apiRestore ( $ toRestore ) ; if ( isset ( $ response ) ) return $ response ; return [ 'success' => true , 'list' => $ toRestore ] ; }
|
Recovers items from database by given id s Just need to set wanted Model name with list parameter
|
10,568
|
public function apiMerge ( ) { DB :: beginTransaction ( ) ; try { $ record = $ this -> __apiMerge ( ) ; } catch ( \ Exception $ e ) { DB :: rollback ( ) ; return HCLog :: error ( 'CORE-0007' . $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; } DB :: commit ( ) ; return $ record ; }
|
Function will can be used to merge multiple records into one
|
10,569
|
protected function downloadExchangeRatesTable ( ) { try { $ this -> table [ $ this -> baseCurrency ] = 1 ; $ xml = simplexml_load_file ( $ this -> url , 'SimpleXMLElement' , LIBXML_NOWARNING ) ; if ( $ xml instanceof \ SimpleXMLElement ) { $ data = $ xml -> xpath ( '//gesmes:Envelope/*[3]/*' ) ; foreach ( $ data [ 0 ] -> children ( ) as $ child ) { $ currency = ( string ) $ child -> attributes ( ) -> currency ; $ exchangeRate = ( string ) $ child -> attributes ( ) -> rate ; $ this -> table [ $ currency ] = $ exchangeRate ; } } } catch ( \ Exception $ e ) { throw new \ RuntimeException ( 'Cannot download rates from ECB.' ) ; } }
|
Downloads exchange rates table from ECB
|
10,570
|
protected function updateCurrencyRates ( Currency $ currency ) { $ baseExchangeRate = $ this -> table [ $ currency -> getCode ( ) ] ; foreach ( $ this -> table as $ currencySymbol => $ exchangeRate ) { $ rate = $ this -> calculateExchangeRate ( $ baseExchangeRate , $ currencySymbol ) ; $ this -> addUpdateExchangeRate ( $ currency -> getCode ( ) , $ currencySymbol , $ rate ) ; } $ this -> helper -> getEntityManager ( ) -> flush ( ) ; }
|
Updates managed currency with exchange rates
|
10,571
|
protected function point ( ) { if ( ! $ this -> point -> isLoaded ( ) ) { $ url = str_replace ( "{point}" , $ this -> point -> getLat ( ) . "," . $ this -> point -> getLon ( ) , self :: POINT ) ; $ res = $ this -> load ( $ url , Point :: TTL ) ; $ this -> point -> setProperties ( $ res ) ; } return $ this -> point ; }
|
ensure point has data loaded
|
10,572
|
public function getGroup ( ) { $ request = $ this -> container -> get ( 'request' ) ; $ groupInfo = $ request -> getSession ( ) -> get ( CustomerGroup :: getModuleCode ( ) ) ; return $ groupInfo ; }
|
Get CustomerGroup of the current customer
|
10,573
|
public function checkGroup ( $ groupCode ) { $ securityContext = $ this -> container -> get ( 'thelia.securityContext' ) ; return $ securityContext -> hasCustomerUser ( ) && $ this -> getGroupCode ( ) === $ groupCode ; }
|
Check if the current customer is in the asked group
|
10,574
|
public function checkCustomerHasGroup ( Customer $ customer , $ groupCode ) { $ group = CustomerCustomerGroupQuery :: create ( ) -> filterByCustomer ( $ customer ) -> useCustomerGroupQuery ( ) -> filterByCode ( $ groupCode ) -> endUse ( ) -> findOne ( ) ; return $ group !== null ; }
|
Check that a customer belongs to a group .
|
10,575
|
protected function init ( ) { $ this -> container -> set ( 'logger' , function ( $ c ) { $ configuration = $ c -> get ( 'configuration' ) ; $ logger = new Logger ( $ configuration [ 'logger' ] ) ; return $ logger ; } ) ; $ this -> container -> set ( MiddlewareFactory :: class , function ( $ c ) { return new MiddlewareFactory ( ) ; } ) ; $ this -> container -> set ( 'request' , function ( $ c ) { $ psr17Factory = new Psr17Factory ( ) ; $ creator = new ServerRequestCreator ( $ psr17Factory , $ psr17Factory , $ psr17Factory , $ psr17Factory ) ; return $ creator -> fromGlobals ( ) ; } ) ; $ this -> container -> set ( 'router' , function ( $ c ) { return new Router ( ) ; } ) ; $ this -> container -> set ( 'response' , function ( $ c ) { return new Response ( ) ; } ) ; $ this -> container -> set ( 'view' , function ( $ c ) { $ configuration = $ c -> get ( 'configuration' ) [ 'view' ] ; $ viewFunctions = isset ( $ configuration [ 'viewFunctions' ] ) ? $ configuration [ 'viewFunctions' ] : [ ] ; return new Plates ( $ configuration [ 'viewPath' ] , $ viewFunctions ) ; } ) ; $ this -> registerErrorHandler ( ) ; }
|
Initializes application s components
|
10,576
|
public function registerErrorHandler ( ) { $ whoops = new \ Whoops \ Run ( ) ; $ configuration = $ this -> getConfiguration ( ) ; if ( isset ( $ configuration [ 'debug' ] ) && $ configuration [ 'debug' ] ) { $ whoops -> pushHandler ( new \ Whoops \ Handler \ PrettyPageHandler ( ) ) ; } else { $ whoops -> pushHandler ( new \ Whoops \ Handler \ CallbackHandler ( function ( $ exception ) { $ this -> logger -> error ( $ exception -> getMessage ( ) , compact ( 'exception' ) ) ; $ request = $ this -> container -> get ( 'request' ) ; $ response = $ this -> container -> get ( 'response' ) ; $ view = $ this -> container -> get ( 'view' ) ; $ errorInfo = [ 'message' => $ exception -> getMessage ( ) ] ; if ( is_a ( $ exception , HttpException :: class ) ) { $ errorInfo [ 'code' ] = $ exception -> getCode ( ) ; } else { $ errorInfo [ 'code' ] = 500 ; } $ headerAccept = $ request -> getHeader ( 'Accept' ) ; if ( in_array ( 'application/json' , $ headerAccept ) ) { $ response = $ response -> withStatus ( $ errorInfo [ 'code' ] ) ; $ response -> getBody ( ) -> write ( json_encode ( $ errorInfo ) ) ; $ response = $ response -> withHeader ( 'Content-Type' , 'application/json' ) ; } else { $ response = $ view -> render ( $ response , 'error' , $ errorInfo ) ; } $ this -> emitResponse ( $ response ) ; return \ Whoops \ Handler \ Handler :: DONE ; } ) ) ; } $ whoops -> register ( ) ; }
|
Registers error handler for this application
|
10,577
|
public function run ( ) { $ request = $ this -> request ; $ response = $ this -> response ; $ config = $ this -> configuration ; $ httpMethod = $ request -> getMethod ( ) ; $ pathInfo = $ request -> getUri ( ) -> getPath ( ) ; if ( empty ( $ pathInfo ) ) { $ pathInfo = '/' ; } $ routeObject = $ this -> router -> resolve ( $ pathInfo , $ httpMethod ) ; if ( $ routeObject ) { $ middlewareList = [ ] ; if ( isset ( $ routeObject [ 'middleware' ] ) ) { $ middlewareConfig = $ config -> get ( 'middlewares' ) ; $ middlewareCount = count ( $ routeObject [ 'middleware' ] ) ; $ middlewareNext = null ; $ middlewareFactory = $ this -> container -> get ( MiddlewareFactory :: class ) ; for ( $ i = $ middlewareCount - 1 ; $ i >= 0 ; $ i -- ) { $ middlewareName = $ routeObject [ 'middleware' ] [ $ i ] ; $ middlewareClass = $ middlewareConfig [ $ middlewareName ] ; $ middlewareList [ $ i ] = $ middlewareFactory -> createObject ( $ middlewareClass , [ 'response' => $ response , 'next' => $ middlewareNext , ] ) ; $ middlewareNext = $ middlewareList [ $ i ] ; } } $ baseNamespace = $ config -> get ( 'controllersNamespace' ) ; $ handler = $ this -> convertCallbackToClosure ( $ routeObject [ 'handler' ] , $ baseNamespace ) ; $ params = isset ( $ routeObject [ 'params' ] ) ? $ routeObject [ 'params' ] : [ ] ; $ requestHandler = new ServerRequestHandler ( $ response , $ handler , $ routeObject [ 'params' ] ) ; if ( isset ( $ middlewareList [ 0 ] ) ) { $ response = $ middlewareList [ 0 ] -> process ( $ request , $ requestHandler ) ; } else { $ response = $ requestHandler -> handle ( $ request ) ; } } else { throw new HttpException ( 404 , "Route '{$pathInfo}' not found" ) ; } $ this -> emitResponse ( $ response ) ; }
|
Runs application to handle request .
|
10,578
|
protected function emitResponse ( ResponseInterface $ response ) { $ this -> logger -> flush ( ) ; ( new \ Zend \ HttpHandlerRunner \ Emitter \ SapiEmitter ( ) ) -> emit ( $ response ) ; }
|
Emits response to client
|
10,579
|
protected function convertCallbackToClosure ( $ callback , $ namespace ) { if ( $ callback instanceof Closure || is_callable ( $ callback ) ) { return $ callback ; } elseif ( is_string ( $ callback ) ) { $ namespace = rtrim ( $ namespace , '\\' ) . '\\' ; $ arrCallback = explode ( '::' , $ callback ) ; $ isStaticCall = count ( $ arrCallback ) == 2 ; if ( $ isStaticCall ) { $ className = $ namespace . $ arrCallback [ 0 ] ; return [ $ className , $ arrCallback [ 1 ] ] ; } else { $ arrCallback = explode ( ':' , $ callback ) ; $ className = $ namespace . $ arrCallback [ 0 ] ; $ obj = $ this -> container -> get ( $ className ) ; return [ $ obj , $ arrCallback [ 1 ] ] ; } } }
|
Converts callback to Closure .
|
10,580
|
public function arretsToHide ( $ newsletter_id = null ) { $ campagnes = $ this -> campagne -> getAll ( $ newsletter_id ) -> where ( 'status' , 'brouillon' ) ; return $ campagnes -> flatMap ( function ( $ campagne ) { return $ campagne -> content ; } ) -> map ( function ( $ content , $ key ) { if ( $ content -> arret_id ) return $ content -> arret_id ; if ( $ content -> groupe_id > 0 ) return $ content -> groupe -> arrets -> pluck ( 'id' ) -> all ( ) ; } ) -> filter ( function ( $ value , $ key ) { return ! empty ( $ value ) ; } ) -> flatten ( ) -> toArray ( ) ; }
|
Interaction with site controllers List of arrets in non sent campagne to hide on frontend
|
10,581
|
public function siteCampagnes ( $ site_id ) { if ( config ( 'newsletter.multi' ) ) { $ newsletters = $ this -> newsletter -> getSite ( $ site_id ) ; return $ newsletters -> map ( function ( $ newsletter , $ key ) { return $ newsletter -> campagnes ; } ) -> flatten ( 1 ) ; } return null ; }
|
All campagnes for site
|
10,582
|
public function html ( $ id ) { libxml_use_internal_errors ( true ) ; $ htmldoc = new InlineStyle ( file_get_contents ( url ( 'campagne/' . $ id ) ) ) ; $ htmldoc -> applyStylesheet ( $ htmldoc -> extractStylesheets ( ) ) ; $ html = $ htmldoc -> getHTML ( ) ; $ html = preg_replace ( '#<script(.*?)>(.*?)</script>#is' , '' , $ html ) ; return $ html ; }
|
Put styles inline for campagne Used when sending cammpagne or test
|
10,583
|
public function save_config ( array $ cfg , $ description , $ class = 'grid' ) { if ( isset ( $ cfg [ 'elements' ] ) ) { $ copy = $ cfg ; unset ( $ copy [ 'elements' ] ) ; $ obj_param = [ 'id_project' => 1 , 'class' => $ class , 'description' => $ description , 'configuration' => json_encode ( $ copy ) ] ; if ( isset ( $ cfg [ 'table' ] ) ) { $ obj_param [ 'table' ] = $ cfg [ 'table' ] ; } $ this -> db -> insert ( $ this -> admin_db . '.' . $ this -> prefix . 'objects' , $ obj_param ) ; $ id = $ this -> db -> last_id ( ) ; $ i = 1 ; foreach ( $ cfg [ 'elements' ] as $ name => $ ele ) { $ table = $ column = false ; if ( ! empty ( $ ele [ 'appui' ] [ 'table' ] ) ) { $ table = $ ele [ 'appui' ] [ 'table' ] ; } else if ( ! empty ( $ ele [ 'table' ] ) ) { $ table = $ ele [ 'table' ] ; } else if ( ! empty ( $ cfg [ 'table' ] ) ) { $ table = $ cfg [ 'table' ] ; } if ( $ table && isset ( $ ele [ 'attr' ] [ 'name' ] ) ) { $ column = $ this -> db -> tfn ( $ table ) . '.' . $ this -> db -> csn ( $ ele [ 'attr' ] [ 'name' ] ) ; } $ this -> db -> insert ( $ this -> admin_db . '.' . $ this -> prefix . 'fields' , [ 'id_obj' => $ id , 'column' => ( $ column ? : null ) , 'title' => isset ( $ ele [ 'label' ] ) ? $ ele [ 'label' ] : null , 'position' => $ i , 'configuration' => json_encode ( $ ele ) ] ) ; $ i ++ ; } return $ id ; } }
|
Saves the given configuration in the database and returns the new ID
|
10,584
|
public function getSubscriptionById ( $ subscriptionId ) { $ subscriptions = $ this -> getSubscriptions ( null , null , null , $ subscriptionId ) -> getResponse ( ) -> getSubscriptions ( ) ; return count ( $ subscriptions ) ? reset ( $ subscriptions ) : null ; }
|
Get one subscription by using the Monsum subscription ID .
|
10,585
|
public function getSubscriptions ( $ customerId = null , $ externalCustomerId = null , $ subscriptionExternalId = null , $ subscriptionId = null ) { $ requestData = new Get \ RequestData ( ) ; $ requestData -> setCustomerId ( $ customerId ) ; $ requestData -> setExternalCustomerId ( $ externalCustomerId ) ; $ requestData -> setSubscriptionExternalId ( $ subscriptionExternalId ) ; $ requestData -> setSubscriptionId ( $ subscriptionId ) ; $ request = new Get \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Get \ ApiResponse :: class ) ; }
|
Get the subscriptions .
|
10,586
|
public function getAllSubscriptions ( ) { $ limit = RequestInterface :: MAX_LIST_LIMIT ; $ offset = 0 ; $ subscriptions = [ [ ] ] ; while ( true ) { $ subscriptionBatch = $ this -> getSubscriptionsResponse ( $ offset ) ; $ subscriptions [ ] = $ subscriptionBatch ; $ offset += $ limit ; if ( \ count ( $ subscriptionBatch ) < $ limit ) { break ; } } return \ array_merge ( ... $ subscriptions ) ; }
|
Get all subscriptions .
|
10,587
|
public function createSubscription ( Create \ RequestData $ requestData ) { $ request = new Create \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Create \ ApiResponse :: class ) ; }
|
Create a subscription .
|
10,588
|
public function updateSubscription ( $ subscriptionId , $ nextEvent = null , $ subscriptionExternalId = null , $ status = null , array $ xAttributes = [ ] , array $ features = [ ] ) { $ requestData = new Update \ RequestData ( $ subscriptionId ) ; $ requestData -> setSubscriptionId ( $ subscriptionId ) ; $ requestData -> setNextEvent ( $ nextEvent ) ; $ requestData -> setSubscriptionExternalId ( $ subscriptionExternalId ) ; $ requestData -> setStatus ( $ status ) ; $ requestData -> setXAttributes ( $ xAttributes ) ; $ requestData -> setFeatures ( $ features ) ; $ request = new Update \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Update \ ApiResponse :: class ) ; }
|
Update a subscription .
|
10,589
|
public function changeSubscriptionArticle ( ChangeArticle \ RequestData $ requestData ) { $ request = new ChangeArticle \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , ChangeArticle \ ApiResponse :: class ) ; }
|
Change article of a subscription .
|
10,590
|
public function setSubscriptionAddon ( SetAddon \ RequestData $ requestData ) { $ request = new SetAddon \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , SetAddon \ ApiResponse :: class ) ; }
|
Set the addon for a subscription .
|
10,591
|
public function setSubscriptionUsageData ( SetUsageData \ RequestData $ requestData ) { $ request = new SetUsageData \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , SetUsageData \ ApiResponse :: class ) ; }
|
Set the usage data of a subscription .
|
10,592
|
public function getUpcomingAmount ( GetUpcomingAmount \ RequestData $ requestData = null ) { if ( $ requestData === null ) { $ requestData = new GetUpcomingAmount \ RequestData ( ) ; } $ request = new GetUpcomingAmount \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , GetUpcomingAmount \ ApiResponse :: class ) ; }
|
Get the upcoming amount .
|
10,593
|
public function postponeSubscription ( $ subscriptionId , $ month ) { $ requestData = new Postpone \ RequestData ( $ subscriptionId , $ month ) ; $ request = new Postpone \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Postpone \ ApiResponse :: class ) ; }
|
Postpone a subscription shipping .
|
10,594
|
public function renewSubscription ( $ subscriptionId ) { $ requestData = new Renew \ RequestData ( $ subscriptionId ) ; $ request = new Renew \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Renew \ ApiResponse :: class ) ; }
|
Renew a subscription .
|
10,595
|
public function createSecureLink ( $ subscriptionId ) { $ requestData = new CreateSecureLink \ RequestData ( $ subscriptionId ) ; $ request = new CreateSecureLink \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , CreateSecureLink \ ApiResponse :: class ) ; }
|
Create a secure link for a subscription .
|
10,596
|
public function cancelSubscription ( $ subscriptionId , \ DateTime $ cancellationDate = null , $ cancellationNote = null ) { $ requestData = new Cancel \ RequestData ( $ subscriptionId ) ; $ requestData -> setCancellationDate ( $ cancellationDate ) ; $ requestData -> setCancellationNote ( $ cancellationNote ) ; $ request = new Cancel \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Cancel \ ApiResponse :: class ) ; }
|
Cancel a subscription .
|
10,597
|
public function reactivateSubscription ( $ subscriptionId ) { $ requestData = new Reactivate \ RequestData ( $ subscriptionId ) ; $ request = new Reactivate \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Reactivate \ ApiResponse :: class ) ; }
|
Reactivate a subscription .
|
10,598
|
public static function stripBase ( $ path , $ base = null ) { if ( $ base === null ) $ base = getcwd ( ) ; if ( substr ( $ path , 0 , strlen ( $ base ) ) === $ base ) return ltrim ( substr ( $ path , strlen ( $ base ) + 1 ) , "/" ) ; else throw new PathException ( "\"$path\" does not contain base path \"$base\"" ) ; }
|
Strips a base from a file or directory path . If no base is supplied the working directory is used .
|
10,599
|
public static function rootPath ( $ directory ) { $ num = count ( explode ( "/" , $ directory ) ) ; $ path = "" ; for ( $ i = 0 ; $ i < $ num ; $ i ++ ) $ path = self :: join ( ".." , $ path ) ; return $ path ; }
|
Builds a path referring to the root directory from a relative path .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.