idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
8,500
|
protected function _addFormArrayProvider ( ) { $ this -> addContextProvider ( 'array' , function ( $ request , $ data ) { if ( is_array ( $ data [ 'entity' ] ) && isset ( $ data [ 'entity' ] [ 'schema' ] ) ) { return new ArrayContext ( $ request , $ data [ 'entity' ] ) ; } } ) ; }
|
Add the array suite of context providers provided .
|
8,501
|
protected function _addFormContextProvider ( ) { $ this -> addContextProvider ( 'form' , function ( $ request , $ data ) { if ( $ data [ 'entity' ] instanceof Form ) { return new FormContext ( $ request , $ data ) ; } } ) ; }
|
Add the form suite of context providers provided .
|
8,502
|
public function defineTask ( $ name , $ object ) { $ options = static :: getOptions ( ) ; $ debug = @ $ options [ 'debug' ] === true ; if ( $ this -> started ) throw new \ Exception ( "Define tasks before start()ing the daemon not after" ) ; if ( ! $ object instanceof AbstractTask ) throw new \ Exception ( "Task must implement AbstractTask" ) ; $ object -> setDaemon ( $ this ) ; $ this -> tasks [ $ name ] = $ object ; if ( $ debug ) echo "==> Task defined: $name" . PHP_EOL ; return $ this ; }
|
Add task to the list of known tasks
|
8,503
|
public function runTask ( $ name , $ data = null , $ allowDuplicates = false ) { $ options = static :: getOptions ( ) ; $ debug = @ $ options [ 'debug' ] === true ; if ( $ debug ) echo "==> Trying to run task: $name" . PHP_EOL ; $ function = $ options [ 'namespace' ] . '-' . $ name ; $ data = json_encode ( $ data ) ; if ( $ allowDuplicates ) $ unique = self :: generateUnique ( ) ; else $ unique = md5 ( $ function . '-' . $ data ) ; $ gmClient = new GearmanClient ( ) ; $ gmClient -> addServer ( $ options [ 'gearman' ] [ 'host' ] , $ options [ 'gearman' ] [ 'port' ] ) ; $ gmClient -> doBackground ( $ function , $ data , $ unique ) ; $ code = $ gmClient -> returnCode ( ) ; if ( $ code != GEARMAN_SUCCESS ) throw new \ Exception ( "Could not run task: $name ($code)" ) ; return $ this ; }
|
Add known task to the run queue
|
8,504
|
public function ping ( ) { $ options = static :: getOptions ( ) ; $ debug = @ $ options [ 'debug' ] === true ; $ gmClient = new GearmanClient ( ) ; $ gmClient -> addServer ( $ options [ 'gearman' ] [ 'host' ] , $ options [ 'gearman' ] [ 'port' ] ) ; $ ping = $ gmClient -> ping ( self :: generateUnique ( ) ) ; if ( $ debug ) echo "==> Pinging job server: " . ( $ ping ? 'Success' : 'Failure' ) . PHP_EOL ; $ code = $ gmClient -> returnCode ( ) ; if ( $ code != GEARMAN_SUCCESS ) throw new \ Exception ( "Ping failed ($code)" ) ; return $ ping ; }
|
Ping job servers
|
8,505
|
public function getPid ( ) { $ options = static :: getOptions ( ) ; $ debug = @ $ options [ 'debug' ] === true ; $ pidFile = $ options [ 'pid_file' ] ; if ( ! $ pidFile ) throw new \ Exception ( "No pid_file in the config" ) ; $ fpPid = fopen ( $ pidFile , "c" ) ; if ( ! $ fpPid ) throw new \ Exception ( "Could not open " . $ pidFile ) ; if ( ! flock ( $ fpPid , LOCK_EX | LOCK_NB ) ) { fclose ( $ fpPid ) ; return ( int ) file_get_contents ( $ pidFile ) ; } flock ( $ fpPid , LOCK_UN ) ; fclose ( $ fpPid ) ; @ unlink ( $ pidFile ) ; return false ; }
|
Get daemon PID
|
8,506
|
public function stop ( ) { $ options = static :: getOptions ( ) ; $ debug = @ $ options [ 'debug' ] === true ; $ pidFile = $ options [ 'pid_file' ] ; if ( ! $ pidFile ) throw new \ Exception ( "No pid_file in the config" ) ; $ fpPid = fopen ( $ pidFile , "c" ) ; if ( ! $ fpPid ) throw new \ Exception ( "Could not open " . $ pidFile ) ; if ( flock ( $ fpPid , LOCK_EX | LOCK_NB ) ) { flock ( $ fpPid , LOCK_UN ) ; fclose ( $ fpPid ) ; if ( $ debug ) echo "==> Daemon not running" . PHP_EOL ; return ; } fclose ( $ fpPid ) ; $ pid = ( int ) file_get_contents ( $ pidFile ) ; if ( $ debug ) echo "==> Killing the daemon (PID $pid)..." . PHP_EOL ; posix_kill ( $ pid , SIGTERM ) ; pcntl_waitpid ( $ pid , $ status ) ; }
|
Stop the daemon
|
8,507
|
public function restart ( ) { if ( count ( $ this -> tasks ) == 0 ) throw new \ Exception ( "There are no tasks defined - can not restart" ) ; $ this -> stop ( ) ; do { sleep ( 1 ) ; } while ( $ this -> getPid ( ) !== false ) ; $ this -> start ( ) ; }
|
Restart the daemon
|
8,508
|
protected function setSetting ( $ name , $ value ) { $ args = $ this -> getArgument ( "settings" ) ; if ( is_null ( $ args ) ) { $ args = array ( ) ; } $ args [ $ name ] = $ value ; return $ this -> setArgument ( "settings" , $ args ) ; }
|
Set a campaign setting .
|
8,509
|
protected function getSearchQuery ( $ keywords ) { $ query = parent :: getSearchQuery ( $ keywords ) ; $ this -> extend ( 'updateSearchQuery' , $ query ) ; return $ query ; }
|
Builds a search query from a given search term .
|
8,510
|
protected function parseSearchResults ( $ results , $ suggestion , $ keywords ) { $ renderData = parent :: parseSearchResults ( $ results , $ suggestion , $ keywords ) ; $ this -> extend ( 'updateParseSearchResults' , $ renderData ) ; return $ renderData ; }
|
Overloading view method purely to provide a hook for others to add extra checks or pass additional data to the Search Results .
|
8,511
|
public function setApp ( PhrestAPI $ app ) { $ this -> app = $ app ; $ this -> app -> isInternalRequest = true ; return $ this ; }
|
Set the API instance
|
8,512
|
private function getHTTPResponse ( $ method , $ path , RequestOptions $ options = null ) { $ client = new Client ( ) ; $ body = new PostBody ( ) ; if ( $ options ) { foreach ( $ options -> getPostParams ( ) as $ name => $ value ) { $ body -> setField ( $ name , $ value ) ; } } $ request = new Request ( $ method , $ this -> url . $ path , [ ] , $ body , [ ] ) ; $ response = $ client -> send ( $ request ) ; $ body = json_decode ( $ response -> getBody ( ) ) ; if ( isset ( $ body -> data ) ) { return $ body -> data ; } else { throw new \ Exception ( 'Error calling ' . $ method . ' to: ' . $ path ) ; } }
|
Makes a cURL HTTP request to the API and returns the response todo this needs to also handle PUT POST DELETE
|
8,513
|
public function processNextJob ( $ workQueue , callable $ callback , int $ timeout = WorkServerAdapter :: DEFAULT_TIMEOUT ) : void { $ qe = $ this -> server -> getNextQueueEntry ( $ workQueue , $ timeout ) ; if ( ! $ qe ) { $ this -> onNoJobAvailable ( ( array ) $ workQueue ) ; return ; } $ job = $ qe -> getJob ( ) ; if ( $ job -> jobIsExpired ( ) ) { $ this -> handleExpiredJob ( $ qe ) ; return ; } $ this -> log ( LogLevel :: INFO , "got job" , $ qe ) ; $ this -> onJobAvailable ( $ qe ) ; $ ret = null ; try { $ ret = $ callback ( $ job ) ; } catch ( \ Throwable $ e ) { $ this -> handleFailedJob ( $ qe , $ e ) ; if ( $ this -> options [ self :: WP_RETHROW_EXCEPTIONS ] ) { throw $ e ; } else { return ; } } switch ( $ ret ?? JobResult :: DEFAULT ) { case JobResult :: SUCCESS : $ this -> handleFinishedJob ( $ qe ) ; break ; case JobResult :: FAILED : $ this -> handleFailedJob ( $ qe ) ; break ; default : $ this -> handleFinishedJob ( $ qe ) ; throw new \ UnexpectedValueException ( 'unexpected job handler return value, should be JobResult::... or null or void' ) ; } }
|
Executes the next job in the Work Queue by passing it to the callback function .
|
8,514
|
public function setOption ( int $ option , $ value ) : self { $ this -> options [ $ option ] = $ value ; return $ this ; }
|
Sets one of the configuration options .
|
8,515
|
public function keys ( ) { $ map = new Map ; foreach ( array_keys ( $ this -> array ) as $ hash ) { $ map [ ] = $ this -> hash_to_key ( $ hash ) ; } return $ map ; }
|
Get the keys of this map as a new map .
|
8,516
|
public function filter ( $ expression ) { $ new = new static ; $ this -> walk ( function ( $ v , $ k ) use ( $ expression , $ new ) { $ result = $ this -> call ( $ expression , $ v , $ k ) ; if ( $ this -> passes ( $ result ) ) { $ new [ $ k ] = $ v ; } } ) ; return $ new ; }
|
Apply the filter to every element creating a new map with only those elements from the original map that do not fail this filter .
|
8,517
|
public function first ( $ expression , $ n = 1 ) { if ( is_numeric ( $ n ) && intval ( $ n ) <= 0 ) { throw new \ InvalidArgumentException ( 'Argument $n must be whole number' ) ; } return $ this -> grep ( $ expression , intval ( $ n ) ) ; }
|
Return a new map containing the first N elements passing the expression .
|
8,518
|
public function last ( $ expression , $ n = 1 ) { if ( is_numeric ( $ n ) && intval ( $ n ) <= 0 ) { throw new \ InvalidArgumentException ( 'Argument $n must be whole number' ) ; } return $ this -> grep ( $ expression , - intval ( $ n ) ) ; }
|
Return a new map containing the last N elements passing the expression .
|
8,519
|
public function get ( $ key , $ default = null ) { $ hash = $ this -> key_to_hash ( $ key ) ; if ( array_key_exists ( $ hash , $ this -> array ) ) { return $ this -> array [ $ hash ] ; } else { return $ default ; } }
|
Get the value corresponding to the given key .
|
8,520
|
public function set ( $ key , $ value ) { $ hash = $ this -> key_to_hash ( $ key ) ; $ this -> array [ $ hash ] = $ value ; return $ this ; }
|
Set a key and its corresponding value into the map .
|
8,521
|
public function diff ( $ collection , $ comparison = Map :: LOOSE ) { $ func = ( $ comparison === Map :: LOOSE ? 'array_diff' : 'array_diff_assoc' ) ; return new static ( $ func ( $ this -> toArray ( ) , $ this -> collection_to_array ( $ collection ) ) ) ; }
|
Return a new map containing those keys and values that are not present in the given collection .
|
8,522
|
public function partition ( $ expression ) { $ outer = new MapOfCollections ; $ proto = new static ; $ this -> walk ( function ( $ v , $ k ) use ( $ expression , $ outer , $ proto ) { $ partition = $ this -> call ( $ expression , $ v , $ k ) ; $ inner = $ outer -> has ( $ partition ) ? $ outer -> get ( $ partition ) : clone $ proto ; $ inner -> set ( $ k , $ v ) ; $ outer -> set ( $ partition , $ inner ) ; } ) ; return $ outer ; }
|
Groups elements of this map based on the result of an expression .
|
8,523
|
public function map ( $ expression ) { $ new = new self ; $ this -> walk ( function ( $ v , $ k ) use ( $ expression , $ new ) { $ new [ $ k ] = $ this -> call ( $ expression , $ v , $ k ) ; } ) ; return $ new ; }
|
Walk the map applying the expression to every element transforming them into a new map .
|
8,524
|
public function reduce ( $ reducer , $ initial = null , $ finisher = null ) { $ reduced = $ initial ; $ this -> walk ( function ( $ value , $ key ) use ( $ reducer , & $ reduced ) { $ reduced = $ this -> call ( $ reducer , $ reduced , $ value , $ key ) ; } ) ; if ( null === $ finisher ) { return $ reduced ; } else { return $ this -> call ( $ finisher , $ reduced ) ; } }
|
Walk the map applying a reducing expression to every element so as to reduce the map to a single value .
|
8,525
|
public function rekey ( $ expression ) { $ new = new static ; $ this -> walk ( function ( $ v , $ k ) use ( $ expression , $ new ) { $ new_key = $ this -> call ( $ expression , $ v , $ k ) ; $ new [ $ new_key ] = $ v ; } ) ; return $ new ; }
|
Change the key for every element in the map using an expression to calculate the new key .
|
8,526
|
public function merge ( $ collection , callable $ merger , $ default = null ) { $ array = $ this -> collection_to_array ( $ collection ) ; foreach ( $ array as $ key => $ value ) { $ current = $ this -> get ( $ key , $ default ) ; $ this -> set ( $ key , $ merger ( $ current , $ value ) ) ; } return $ this ; }
|
Merge the given collection into this map .
|
8,527
|
public function transform ( callable $ transformer , callable $ creator = null , callable $ finisher = null ) { if ( null === $ creator ) { $ creator = function ( Map $ original ) { return new Map ( ) ; } ; } $ initial = $ creator ( $ this ) ; $ this -> walk ( function ( $ value , $ key ) use ( $ transformer , & $ initial ) { $ transformer ( $ initial , $ value , $ key ) ; } ) ; if ( null === $ finisher ) { return $ initial ; } else { return $ finisher ( $ initial ) ; } }
|
Flexibly and thoroughly change this map into another map .
|
8,528
|
public function into ( Map $ target ) { $ this -> walk ( function ( $ value , $ key ) use ( $ target ) { $ target -> set ( $ key , $ value ) ; } ) ; return $ target ; }
|
Put all of this map s elements into the target and return the target .
|
8,529
|
public function push ( $ element ) { $ this -> array [ ] = 'probe' ; end ( $ this -> array ) ; $ next = key ( $ this -> array ) ; unset ( $ this -> array [ $ next ] ) ; $ this -> set ( $ next , $ element ) ; return $ this ; }
|
Treat the map as a stack and push an element onto its end .
|
8,530
|
public function pop ( ) { if ( 0 === count ( $ this -> array ) ) { return null ; } end ( $ this -> array ) ; $ hash = key ( $ this -> array ) ; $ element = $ this -> array [ $ hash ] ; $ this -> forget ( $ this -> hash_to_key ( $ hash ) ) ; return $ element ; }
|
Treat the map as a stack and pop an element off its end .
|
8,531
|
public function toArray ( ) { $ array = [ ] ; foreach ( $ this -> array as $ hash => $ value ) { $ key = $ this -> hash_to_key ( $ hash ) ; if ( $ this -> is_collection_like ( $ value ) ) { $ array [ $ key ] = $ this -> collection_to_array ( $ value ) ; } else { $ array [ $ key ] = $ value ; } } return $ array ; }
|
Copy this map into an array recursing as necessary to convert contained collections into arrays .
|
8,532
|
public function offsetSet ( $ key , $ value ) { if ( null === $ key ) { $ this -> push ( $ value ) ; } else { $ this -> set ( $ key , $ value ) ; } }
|
Set the value at a given key .
|
8,533
|
public function getIterator ( ) { $ keys = $ this -> keys ( ) ; $ count = count ( $ keys ) ; $ index = 0 ; while ( $ index < $ count ) { $ key = $ keys [ $ index ] ; $ value = $ this -> get ( $ key ) ; yield $ key => $ value ; $ index ++ ; } }
|
Get an iterator for the map .
|
8,534
|
protected function is_collection_like ( $ value ) { if ( $ value instanceof self ) { return true ; } else if ( $ value instanceof \ Traversable ) { return true ; } else if ( $ value instanceof Arrayable ) { return true ; } else if ( $ value instanceof Jsonable ) { return true ; } else if ( is_object ( $ value ) || is_array ( $ value ) ) { return true ; } else { return false ; } }
|
Decide if the given value is considered collection - like .
|
8,535
|
protected function collection_to_array ( $ collection ) { if ( $ collection instanceof self ) { return $ collection -> toArray ( ) ; } else if ( $ collection instanceof \ Traversable ) { return iterator_to_array ( $ collection ) ; } else if ( $ collection instanceof Arrayable ) { return $ collection -> toArray ( ) ; } else if ( $ collection instanceof Jsonable ) { return json_decode ( $ collection -> toJson ( ) , true ) ; } else if ( is_object ( $ collection ) || is_array ( $ collection ) ) { return ( array ) $ collection ; } else { throw new \ InvalidArgumentException ( sprintf ( '$collection has type %s, which is not collection-like' , gettype ( $ collection ) ) ) ; } }
|
Give me a native PHP array regardless of what kind of collection - like structure is given .
|
8,536
|
protected function grep ( $ expression , $ limit = null ) { $ map = new static ; $ bnd = empty ( $ limit ) ? null : abs ( $ limit ) ; $ cnt = 0 ; $ helper = function ( $ value , $ key ) use ( $ expression , $ map , $ bnd , & $ cnt ) { if ( $ this -> passes ( $ this -> call ( $ expression , $ value , $ key ) ) ) { $ map -> set ( $ key , $ value ) ; if ( null !== $ bnd && $ bnd <= ++ $ cnt ) { return false ; } } } ; if ( 0 <= $ limit ) { $ this -> walk ( $ helper ) ; } else { $ this -> walk_backward ( $ helper ) ; } return $ map ; }
|
Finds elements for which the given code passes optionally limited to a maximum count .
|
8,537
|
protected function walk ( callable $ code ) { foreach ( $ this -> array as $ hash => & $ value ) { $ key = $ this -> hash_to_key ( $ hash ) ; if ( ! $ this -> passes ( $ this -> call ( $ code , $ value , $ key ) ) ) { break ; } } return $ this ; }
|
Execute the given code over each element of the map . The code receives the value by reference and then the key as formal parameters .
|
8,538
|
protected function walk_backward ( callable $ code ) { for ( end ( $ this -> array ) ; null !== ( $ hash = key ( $ this -> array ) ) ; prev ( $ this -> array ) ) { $ key = $ this -> hash_to_key ( $ hash ) ; $ current = current ( $ this -> array ) ; $ value = & $ current ; if ( ! $ this -> passes ( $ this -> call ( $ code , $ value , $ key ) ) ) { break ; } } return $ this ; }
|
Like walk except walk from the end toward the front .
|
8,539
|
private function key_to_hash ( $ key ) { if ( null === $ key ) { $ hash = 'null' ; } else if ( is_int ( $ key ) ) { $ hash = $ key ; } else if ( is_float ( $ key ) ) { $ hash = "f_$key" ; } else if ( is_bool ( $ key ) ) { $ hash = "b_$key" ; } else if ( is_string ( $ key ) ) { $ hash = "s_$key" ; } else if ( is_object ( $ key ) || is_callable ( $ key ) ) { $ hash = spl_object_hash ( $ key ) ; } else if ( is_array ( $ key ) ) { $ hash = 'a_' . md5 ( json_encode ( $ key ) ) ; } else if ( is_resource ( $ key ) ) { $ hash = "r_$key" ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Unsupported key type "%s"' , gettype ( $ key ) ) ) ; } $ this -> map_hash_to_key [ $ hash ] = $ key ; return $ hash ; }
|
Lookup the hash for the given key . If a hash does not yet exist one is created .
|
8,540
|
private function hash_to_key ( $ hash ) { if ( array_key_exists ( $ hash , $ this -> map_hash_to_key ) ) { return $ this -> map_hash_to_key [ $ hash ] ; } else { throw new \ OutOfBoundsException ( sprintf ( 'Hash "%s" has not been created' , $ hash ) ) ; } }
|
Lookup the key for the given hash .
|
8,541
|
public function setQuery ( Query $ query ) { $ this -> query = $ query ; $ this -> clonedQuery = clone $ query ; return $ this ; }
|
Set CakePHP query
|
8,542
|
protected function preparePaging ( Request $ request ) { self :: $ countBeforePaging = $ this -> query -> count ( ) ; $ this -> query -> limit ( $ request -> getLength ( ) ) ; $ this -> query -> offset ( $ request -> getStart ( ) ) ; }
|
Prepare CakePHP paging
|
8,543
|
protected function prepareSearch ( Request $ request ) { $ value = $ request -> getSearch ( ) -> getValue ( ) ; if ( ! empty ( $ value ) ) { $ where = [ ] ; foreach ( $ request -> getColumns ( ) as $ column ) { if ( $ column -> getSearchable ( ) === true ) { $ where [ $ column -> getData ( ) . ' LIKE' ] = '%' . $ value . '%' ; } } $ this -> query -> andWhere ( function ( QueryExpression $ exp ) use ( $ where ) { return $ exp -> or_ ( $ where ) ; } ) ; } }
|
Prepare CakePHP search
|
8,544
|
protected function prepareOrder ( Request $ request ) { foreach ( $ request -> getOrder ( ) as $ order ) { $ this -> query -> order ( [ $ this -> table -> getColumns ( ) [ $ order -> getColumn ( ) ] -> getData ( ) => strtoupper ( $ order -> getDir ( ) ) ] ) ; } }
|
Prepare CakePHP order
|
8,545
|
protected function getProperty ( $ dataName ) { $ dataName = explode ( '.' , trim ( $ dataName ) ) ; if ( count ( $ dataName ) != 2 ) { throw new Exception ( 'You are set invalid date.' ) ; } $ tableAlias = $ dataName [ 0 ] ; $ colName = $ dataName [ 1 ] ; if ( $ this -> query -> repository ( ) -> alias ( ) == $ tableAlias ) { return $ colName ; } elseif ( array_key_exists ( $ tableAlias , $ this -> query -> contain ( ) ) ) { return [ 'propertyPath' => $ this -> query -> eagerLoader ( ) -> normalized ( $ this -> query -> repository ( ) ) [ $ tableAlias ] [ 'propertyPath' ] , 'field' => $ colName ] ; } }
|
Get CakePHP property
|
8,546
|
public function _UpdateQueryBuilder ( Builder $ objBuilder ) { $ intLength = count ( $ this -> objNodeArray ) ; for ( $ intIndex = 0 ; $ intIndex < $ intLength ; $ intIndex ++ ) { $ objNode = $ this -> objNodeArray [ $ intIndex ] ; if ( $ objNode instanceof Node \ Virtual ) { if ( $ objNode -> hasSubquery ( ) ) { throw new Caller ( 'You cannot define a virtual node in an order by clause. You must use an Expand clause to define it.' ) ; } $ strOrderByCommand = '__' . $ objNode -> getAttributeName ( ) ; } elseif ( $ objNode instanceof Node \ Column ) { $ strOrderByCommand = $ objNode -> getColumnAlias ( $ objBuilder ) ; } elseif ( $ objNode instanceof iCondition ) { $ strOrderByCommand = $ objNode -> getWhereClause ( $ objBuilder ) ; } else { $ strOrderByCommand = '' ; } if ( ( ( $ intIndex + 1 ) < $ intLength ) && ! ( $ this -> objNodeArray [ $ intIndex + 1 ] instanceof Node \ NodeBase ) ) { if ( ( ! $ this -> objNodeArray [ $ intIndex + 1 ] ) || ( trim ( strtolower ( $ this -> objNodeArray [ $ intIndex + 1 ] ) ) == 'desc' ) ) { $ strOrderByCommand .= ' DESC' ; } else { $ strOrderByCommand .= ' ASC' ; } $ intIndex ++ ; } $ objBuilder -> addOrderByItem ( $ strOrderByCommand ) ; } }
|
Updates the query builder according to this clause . This is called by the query builder only .
|
8,547
|
public function renderOrbit ( ) { $ contents = $ list = array ( ) ; foreach ( $ this -> items as $ item ) { $ list [ ] = $ this -> renderItem ( $ item ) ; } if ( $ this -> showPreloader ) { $ contents [ ] = \ CHtml :: tag ( 'div' , array ( 'class' => Enum :: ORBIT_LOADER ) , ' ' ) ; } $ contents [ ] = \ CHtml :: tag ( 'ul' , array ( 'id' => $ this -> getId ( ) , 'data-orbit' => 'data-orbit' ) , implode ( "\n" , $ list ) ) ; return \ CHtml :: tag ( 'div' , $ this -> htmlOptions , implode ( "\n" , $ contents ) ) ; }
|
Renders the orbit plugin
|
8,548
|
public function renderItem ( $ item ) { $ content = ArrayHelper :: getValue ( $ item , 'content' , '' ) ; $ caption = ArrayHelper :: getValue ( $ item , 'caption' ) ; if ( $ caption !== null ) { $ caption = \ CHtml :: tag ( 'div' , array ( 'class' => Enum :: ORBIT_CAPTION ) , $ caption ) ; } return \ CHtml :: tag ( 'li' , array ( ) , $ content . $ caption ) ; }
|
Returns a generated LI tag item
|
8,549
|
public function registerClientScript ( ) { if ( ! empty ( $ this -> pluginOptions ) ) { $ options = \ CJavaScript :: encode ( $ this -> pluginOptions ) ; \ Yii :: app ( ) -> clientScript -> registerScript ( 'Orbit#' . $ this -> getId ( ) , "$(document).foundation('orbit', {$options});" ) ; } if ( ! empty ( $ this -> events ) ) { $ this -> registerEvents ( "#{$this->getId()}" , $ this -> events ) ; } }
|
Registers the plugin script
|
8,550
|
protected function runCleanTask ( $ outputDir ) { $ cleanTime = $ this -> runTimedTask ( function ( ) use ( $ outputDir ) { $ this -> builder -> clean ( $ outputDir ) ; } ) ; $ this -> output -> writeln ( "<comment>Cleaned <path>{$outputDir}</path> in <time>{$cleanTime}ms</time></comment>" , OutputInterface :: VERBOSITY_VERBOSE ) ; }
|
Clean the output build directory .
|
8,551
|
protected function runBuildTask ( $ sourceDir , $ outputDir ) { $ buildTime = $ this -> runTimedTask ( function ( ) use ( $ sourceDir , $ outputDir ) { $ this -> builder -> build ( $ sourceDir , $ outputDir ) ; } ) ; $ this -> output -> writeln ( "<comment>PHP built in <time>{$buildTime}ms</time></comment>" , OutputInterface :: VERBOSITY_VERBOSE ) ; }
|
Build the new site pages .
|
8,552
|
protected function runGulpTask ( ) { $ this -> output -> writeln ( "<comment>Starting gulp...</comment>" , OutputInterface :: VERBOSITY_VERY_VERBOSE ) ; $ process = $ this -> createGulpProcess ( 'steak:build' ) ; $ callback = $ this -> getProcessLogger ( $ this -> output ) ; $ timer = new Stopwatch ( ) ; $ timer -> start ( 'gulp' ) ; try { $ process -> mustRun ( $ callback ) ; $ this -> output -> writeln ( "<comment>gulp published in <time>{$timer->stop('gulp')->getDuration()}ms</time></comment>" , OutputInterface :: VERBOSITY_VERBOSE ) ; } catch ( ProcessFailedException $ exception ) { $ this -> output -> writeln ( "<error>gulp process failed after <time>{$timer->stop('gulp')->getDuration()}ms</time></error>" , OutputInterface :: VERBOSITY_VERBOSE ) ; if ( str_contains ( $ process -> getOutput ( ) , 'Local gulp not found' ) || str_contains ( $ process -> getErrorOutput ( ) , 'Cannot find module' ) ) { $ this -> output -> writeln ( "<comment>Missing npm dependencies, attempting install. This might take a minute...</comment>" ) ; $ this -> output -> writeln ( ' <comment>$</comment> npm install' , OutputInterface :: VERBOSITY_VERBOSE ) ; try { $ npmInstallTime = $ this -> runTimedTask ( function ( ) { ( new Process ( 'npm install' , $ this -> container [ 'config' ] [ 'source.directory' ] ) ) -> setTimeout ( 180 ) -> mustRun ( ) ; } ) ; $ this -> output -> writeln ( " <comment>npm installed in in <time>{$npmInstallTime}ms</time></comment>" , OutputInterface :: VERBOSITY_VERBOSE ) ; $ this -> output -> writeln ( '<comment>Retrying <b>steak:publish</b> task...</comment>' ) ; $ process -> mustRun ( $ callback ) ; } catch ( RuntimeException $ exception ) { $ this -> output -> writeln ( "We tried but <error>npm install</error> failed" ) ; } } } }
|
Trigger gulp to copy other assets to the build dir .
|
8,553
|
public static function create ( $ name , array $ properties = [ ] , $ serialize = true ) { try { $ class = get_called_class ( ) ; $ cookie = new $ class ( $ name ) ; CookieTools :: setCookieProperties ( $ cookie , $ properties , $ serialize ) ; } catch ( CookieException $ ce ) { throw $ ce ; } return $ cookie ; }
|
Static method to quickly create a cookie
|
8,554
|
public static function retrieve ( $ name ) { try { $ class = get_called_class ( ) ; $ cookie = new $ class ( $ name ) ; return $ cookie -> load ( ) ; } catch ( CookieException $ ce ) { throw $ ce ; } }
|
Static method to quickly get a cookie
|
8,555
|
public function getContent ( $ path ) { if ( ( '0' == $ path ) || ( int ) ( $ path ) > 0 ) { $ path = $ this -> findByIndex ( $ path ) ; } else { $ path = $ this -> basePath . '/' . $ path ; $ infos = pathinfo ( $ path ) ; if ( empty ( $ infos [ 'extension' ] ) ) { $ path .= '.md' ; } } if ( file_exists ( $ path ) ) { return file_get_contents ( $ path ) ; } return false ; }
|
getContent Retrieve a file content using the given path
|
8,556
|
public function getList ( ) { $ list = glob ( $ this -> basePath . "/*.md" ) ; foreach ( $ list as $ key => $ item ) { $ item = pathinfo ( $ item ) ; $ item = $ item [ 'filename' ] ; $ item = preg_split ( "/^[\d-]+/" , $ item , 2 , PREG_SPLIT_NO_EMPTY ) ; $ list [ $ key ] = ucfirst ( str_replace ( '-' , ' ' , $ item [ 0 ] ) ) ; } return $ list ; }
|
getList In the file list returned in array values - become spaces .
|
8,557
|
public function process ( ExprBuilder $ builder , $ field , $ expression , $ value ) { if ( ! Expr :: isValidExpression ( $ expression ) ) { throw new ParserException ( sprintf ( 'The expression "%s" is not allowed or not exists.' , $ expression ) ) ; } switch ( $ expression ) { case 'between' : set_error_handler ( function ( ) use ( $ value ) { throw new ParserException ( sprintf ( 'The value of "between" expression "%s" is not valid.' , $ value ) ) ; } ) ; list ( $ from , $ to ) = explode ( '-' , $ value ) ; restore_error_handler ( ) ; return $ builder -> between ( $ field , $ from , $ to ) ; case 'paginate' : set_error_handler ( function ( ) use ( $ value ) { throw new ParserException ( sprintf ( 'The value of "paginate" expression "%s" is not valid.' , $ value ) ) ; } ) ; list ( $ currentPageNumber , $ maxResultsPerPage ) = explode ( '-' , $ value ) ; restore_error_handler ( ) ; return $ builder -> paginate ( $ currentPageNumber , $ maxResultsPerPage ) ; case 'or' : return $ builder -> orx ( $ value ) ; default : return $ builder -> { $ expression } ( $ field , $ value ) ; } }
|
Process one expression an enqueue it using the ExprBuilder instance .
|
8,558
|
public function afterAction ( $ action , $ result ) { if ( Yii :: $ app -> user -> isGuest ) { return $ result ; } else { return $ this -> finishAuthorization ( ) ; } }
|
If user is logged on do oauth login immediatly continue authorization in the another case
|
8,559
|
public static function addScenarioFromYml ( $ key ) { $ cfg = Config :: inst ( ) -> get ( 'SimpleListField' , 'Scenarios' ) ; if ( isset ( $ cfg [ $ key ] ) ) { if ( ( isset ( $ cfg [ $ key ] [ 'preload' ] ) && ! $ cfg [ $ key ] [ 'preload' ] ) || ! isset ( $ cfg [ $ key ] [ 'preload' ] ) ) { self :: $ scenarios [ $ key ] = $ cfg [ $ key ] ; } } }
|
Add single scenario by using yml configuration
|
8,560
|
public function add_meta_boxes ( $ post_type ) { if ( in_array ( $ post_type , $ this -> settings [ 'post_types' ] ) ) { add_meta_box ( $ this -> settings [ 'id' ] , $ this -> settings [ 'title' ] , array ( $ this , 'render' ) , $ post_type , $ this -> settings [ 'context' ] , $ this -> settings [ 'priority' ] ) ; } }
|
Adds the meta box container .
|
8,561
|
public function save ( $ post_id ) { if ( ! isset ( $ _POST [ $ this -> nonce_name ( ) ] ) ) { return $ post_id ; } $ nonce = filter_input ( INPUT_POST , $ this -> nonce_name ( ) ) ; if ( ! wp_verify_nonce ( $ nonce , $ this -> action_name ( ) ) ) { return $ post_id ; } if ( defined ( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $ post_id ; } $ post_type = filter_input ( INPUT_POST , 'post_type' ) ; if ( in_array ( $ post_type , $ this -> settings [ 'post_types' ] ) ) { $ capability = 'edit_' . $ post_type ; if ( ! current_user_can ( $ capability , $ post_id ) ) { return $ post_id ; } } else { return $ post_id ; } $ old_instance = \ get_post_meta ( $ post_id , $ this -> settings [ 'id' ] , true ) ; $ new_instance = $ this -> form -> updater -> update ( $ old_instance === "" ? array ( ) : $ old_instance ) ; \ update_post_meta ( $ post_id , $ this -> settings [ 'id' ] , $ new_instance ) ; $ callable = $ this -> settings [ 'callback' ] ; if ( is_callable ( $ callable ) ) { $ callable ( $ post_id , $ new_instance ) ; } }
|
Save the meta when the post is saved .
|
8,562
|
public function render ( $ post ) { $ old_instance = \ get_post_meta ( $ post -> ID , $ this -> settings [ 'id' ] , true ) ; $ this -> form -> updater -> update ( $ old_instance === "" ? array ( ) : $ old_instance ) ; wp_nonce_field ( $ this -> action_name ( ) , $ this -> nonce_name ( ) ) ; $ this -> form -> render ( true ) ; }
|
Render Meta Box content .
|
8,563
|
static function get_meta_value ( $ post_id , $ metabox_id , $ field_name = null ) { $ meta = \ get_post_meta ( $ post_id , $ metabox_id , true ) ; if ( null == $ field_name ) { return $ meta ; } if ( isset ( $ meta [ $ field_name ] ) ) { return $ meta [ $ field_name ] ; } }
|
Get a meta box value for a given post id by specifying the metabox id and field name . If no field name is given an associative array with all the meta box values will be returned .
|
8,564
|
public function findAll ( ) { $ sheets = array ( ) ; foreach ( $ this -> readSelectedSheets ( ) as $ selectName => $ excelSheet ) { $ sheets [ $ selectName ] = new Sheet ( $ selectName , $ this -> readRows ( $ excelSheet ) ) ; } return $ sheets ; }
|
Returns all selected Sheets with all rows
|
8,565
|
public static function findFile ( $ file , $ loops = 3 ) { if ( ! file_exists ( $ file ) ) { for ( $ i = 0 ; $ i < $ loops ; $ i ++ ) { if ( ! file_exists ( $ file ) ) { $ file = '../' . $ file ; } } } return $ file ; }
|
Finds a file by default it will try up to 3 parent folders .
|
8,566
|
public static function findKey ( $ aKey , $ array ) { if ( is_array ( $ array ) ) { foreach ( $ array as $ key => $ item ) { if ( $ key == $ aKey ) { return $ item ; } else { $ result = self :: findKey ( $ aKey , $ item ) ; if ( $ result != false ) { return $ result ; } } } } return false ; }
|
in the array the key is just that it exists in there somewhere .
|
8,567
|
public static function getInstance ( $ configFile = 'config.yml' ) { static $ instance = null ; if ( null === $ instance ) { $ instance = new static ( ) ; } $ configuration = Yaml :: parse ( file_get_contents ( $ configFile ) ) ; $ instance -> setParams ( $ configuration ) ; return $ instance ; }
|
Config singleton .
|
8,568
|
protected function assertResult ( $ descriptor , $ result ) { $ errors = array ( 401 => "InvalidCredentials" , 402 => "PaymentRequired" , 403 => "Forbidden" , 404 => "NotFound" , 405 => "InvalidMethod" , 406 => "NotAcceptable" , 415 => "InvalidMedia" , 429 => "RateLimited" , 500 => "ServerError" , 400 => "ClientError" ) ; if ( isset ( $ errors [ $ result -> code ] ) ) { $ class = $ errors [ $ result -> code ] ; $ class = "PortaText\\Exception\\$class" ; throw new $ class ( $ descriptor , $ result ) ; } }
|
Will assert that the request finished successfuly .
|
8,569
|
public function createValidator ( Array $ simpleRules = array ( ) ) { $ validator = new Validator ( ) ; if ( count ( $ simpleRules ) > 0 ) { $ validator -> addSimpleRules ( $ simpleRules ) ; } return $ validator ; }
|
Erstellt einen Validator mit den SimpleRules
|
8,570
|
public function createComponentsValidator ( FormData $ requestData , EntityFormPanel $ panel , DCPackage $ dc , Array $ components = NULL ) { $ this -> validationEntity = $ entity = $ panel -> getEntityForm ( ) -> getEntity ( ) ; $ components = isset ( $ components ) ? Code :: castCollection ( $ components ) : $ panel -> getEntityForm ( ) -> getComponents ( ) ; return $ this -> componentsValidator = new ComponentsValidator ( $ this -> createFormDataSet ( $ requestData , $ panel , $ entity ) , $ components , $ this -> componentRuleMapper ) ; }
|
Erstellt einen ComponentsValidator anhand des EntityFormPanels
|
8,571
|
public function createFormDataSet ( FormData $ requestData , EntityFormPanel $ panel , Entity $ entity ) { $ meta = $ entity -> getSetMeta ( ) ; foreach ( $ panel -> getControlFields ( ) as $ field ) { $ meta -> setFieldType ( $ field , Type :: create ( 'String' ) ) ; } $ meta -> setFieldType ( 'disabled' , Type :: create ( 'Array' ) ) ; try { $ set = new Set ( ( array ) $ requestData , $ meta ) ; } catch ( \ Psc \ Data \ FieldNotDefinedException $ e ) { throw \ Psc \ Exception :: create ( "In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s)." , implode ( '.' , $ e -> field ) , implode ( ', ' , $ e -> avaibleFields ) ) ; } return $ set ; }
|
Erstellt aus dem Request und dem FormPanel ein Set mit allen FormularDaten
|
8,572
|
public function getDefaultCache ( ) : ? Repository { $ manager = Cache :: getFacadeRoot ( ) ; if ( isset ( $ manager ) ) { return $ cache = $ manager -> store ( ) ; } return $ manager ; }
|
Get a default cache value if any is available
|
8,573
|
public static function generate ( Event $ event ) { $ args = $ event -> getArguments ( ) ; if ( empty ( $ args ) ) { echo "Usage:\n\n" . " composer yasql-generate -- YASQL_FILE [INDENTATION]\n\n" . "By default, INDENTATION is 2\n" ; die ( 1 ) ; } echo Controller :: generate ( file_get_contents ( $ args [ 0 ] ) , null , $ args [ 1 ] ?? 2 ) ; }
|
Generates the SQL from a YASQL file
|
8,574
|
private function parseUseStatement ( ) { $ class = '' ; $ alias = '' ; $ statements = array ( ) ; $ explicitAlias = false ; while ( ( $ token = $ this -> next ( ) ) ) { $ isNameToken = $ token [ 0 ] === T_STRING || $ token [ 0 ] === T_NS_SEPARATOR ; if ( ! $ explicitAlias && $ isNameToken ) { $ class .= $ token [ 1 ] ; $ alias = $ token [ 1 ] ; } else if ( $ explicitAlias && $ isNameToken ) { $ alias .= $ token [ 1 ] ; } else if ( $ token [ 0 ] === T_AS ) { $ explicitAlias = true ; $ alias = '' ; } else if ( $ token === ',' ) { $ statements [ $ alias ] = $ class ; $ class = '' ; $ alias = '' ; $ explicitAlias = false ; } else if ( $ token === ';' ) { $ statements [ $ alias ] = $ class ; break ; } else { break ; } } return $ statements ; }
|
Parse a single use statement .
|
8,575
|
protected function getDefaultRouteName ( \ ReflectionClass $ class , \ ReflectionMethod $ method ) { $ routeName = parent :: getDefaultRouteName ( $ class , $ method ) ; return preg_replace ( array ( '/(module_|controller_?)/' , '/__/' ) , array ( '_' , '_' ) , $ routeName ) ; }
|
Makes the default route name more sane by removing common keywords .
|
8,576
|
private function resolveClient ( $ client ) { $ client = ! empty ( $ client ) ? $ client : new Client ( ) ; $ client -> setBaseUrl ( Properties :: baseUrl ( ) ) -> setUserAgent ( 'Double Opt-in php-api/' . self :: VERSION ) ; $ httpClientConfig = $ this -> config -> getHttpClientConfig ( ) ; if ( array_key_exists ( 'verify' , $ httpClientConfig ) && $ httpClientConfig [ 'verify' ] === false ) { $ client -> setSslVerification ( false , false ) ; } return $ client ; }
|
resolves a http client
|
8,577
|
private function setupOAuth2Plugin ( ) { $ oauth2AuthorizationClient = $ this -> resolveClient ( null ) ; $ oauth2AuthorizationClient -> setBaseUrl ( Properties :: authorizationUrl ( ) ) ; $ clientCredentials = new ClientCredentials ( $ oauth2AuthorizationClient , $ this -> config -> toArray ( ) ) ; $ oauth2Plugin = new OAuth2Plugin ( $ clientCredentials ) ; $ oauth2Plugin -> setCache ( $ this -> config -> getAccessTokenCacheFile ( ) ) ; $ this -> client -> addSubscriber ( $ oauth2Plugin ) ; }
|
setting up the oauth2 plugin for authorizing the requests
|
8,578
|
public function send ( ClientCommand $ command ) { $ request = $ this -> client -> createRequest ( $ command -> method ( ) , $ this -> client -> getBaseUrl ( ) . $ command -> uri ( $ this -> cryptographyEngine ) , $ this -> headers ( $ command -> apiVersion ( ) , $ command -> format ( ) , $ command -> headers ( ) ) , $ command -> body ( $ this -> cryptographyEngine ) , $ this -> config -> getHttpClientConfig ( ) ) ; try { $ response = $ request -> send ( ) ; } catch ( ClientErrorResponseException $ exception ) { $ response = $ exception -> getResponse ( ) ; } catch ( ServerErrorResponseException $ exception ) { $ response = $ exception -> getResponse ( ) ; } return $ command -> response ( $ response , $ this -> cryptographyEngine ) ; }
|
get all actions
|
8,579
|
public static function get_by_token ( $ token ) { $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ sql = "SELECT * FROM `login_tokens` WHERE `code` = '%s';" ; $ login = $ mysql :: select ( 'row' , $ sql , $ token ) ; if ( empty ( $ login ) ) { return false ; } return new static ( $ login [ 'id' ] ) ; }
|
checks whether the given token match one on file
|
8,580
|
public function is_valid ( $ mark_as_used = true ) { if ( ! empty ( $ this -> data [ 'used' ] ) ) { return false ; } if ( time ( ) > $ this -> data [ 'expire_at' ] ) { return false ; } if ( $ mark_as_used ) { $ this -> mark_as_used ( ) ; } return true ; }
|
check if the token is still valid also marks the token as used to prevent more people getting in
|
8,581
|
public static function create ( $ user_id ) { $ text = bootstrap :: get_library ( 'text' ) ; $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ new_token = $ text :: generate_token ( self :: TOKEN_LENGTH ) ; $ expiration = ( time ( ) + self :: EXPIRATION ) ; $ sql = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;" ; $ binds = [ $ new_token , $ user_id , $ expiration ] ; $ mysql :: query ( $ sql , $ binds ) ; return new static ( $ mysql :: $ insert_id ) ; }
|
create a new temporary login token
|
8,582
|
public static function registerIconFontSet ( $ fontName , $ forceCopyAssets = false ) { if ( ! in_array ( $ fontName , static :: getAvailableIconFontSets ( ) ) ) { return false ; } $ fontPath = \ Yii :: getPathOfAlias ( 'foundation.fonts.foundation_icons_' . $ fontName ) ; $ fontUrl = \ Yii :: app ( ) -> assetManager -> publish ( $ fontPath , true , - 1 , $ forceCopyAssets ) ; \ Yii :: app ( ) -> clientScript -> registerCssFile ( $ fontUrl . "/stylesheets/{$fontName}_foundicons.css" ) ; if ( strpos ( $ _SERVER [ 'HTTP_USER_AGENT' ] , 'MSIE 7.0' ) ) { \ Yii :: app ( ) -> clientScript -> registerCssFile ( $ fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css" ) ; } }
|
Registers a specific Icon Set . They are registered individually
|
8,583
|
public function setRootDir ( $ rootDir ) { $ dir = realpath ( $ rootDir ) ; if ( false === $ dir ) { throw new InvalidArgumentException ( Message :: get ( Message :: CONFIG_ROOT_INVALID , $ rootDir ) , Message :: CONFIG_ROOT_INVALID ) ; } $ this -> root_dir = $ dir . \ DIRECTORY_SEPARATOR ; return $ this ; }
|
Set config file root directory
|
8,584
|
protected function globFiles ( $ group , $ environment ) { $ files = [ ] ; $ group = '' === $ group ? '*' : $ group ; foreach ( $ this -> getSearchDirs ( $ environment ) as $ dir ) { $ file = $ dir . $ group . '.' . $ this -> file_type ; $ files = array_merge ( $ files , glob ( $ file ) ) ; } return $ files ; }
|
Returns an array of files to read from
|
8,585
|
protected function getSearchDirs ( $ env ) { if ( ! isset ( $ this -> sub_dirs [ $ env ] ) ) { $ this -> sub_dirs [ $ env ] = $ this -> buildSearchDirs ( $ env ) ; } return $ this -> sub_dirs [ $ env ] ; }
|
Get the search directories
|
8,586
|
protected function buildSearchDirs ( $ env ) { $ path = $ this -> root_dir ; $ part = preg_split ( '/[\/\\\]/' , trim ( $ env , '/\\' ) , 0 , \ PREG_SPLIT_NO_EMPTY ) ; $ subdirs = [ $ path ] ; foreach ( $ part as $ dir ) { $ path .= $ dir . \ DIRECTORY_SEPARATOR ; if ( false === file_exists ( $ path ) ) { trigger_error ( Message :: get ( Message :: CONFIG_ENV_UNKNOWN , $ env ) , \ E_USER_WARNING ) ; break ; } $ subdirs [ ] = $ path ; } return $ subdirs ; }
|
Build search directories
|
8,587
|
public function getServiceUrl ( $ serviceName , $ action ) { return sprintf ( '%s/api/%s/%s/%s' , $ this -> tulipUrl , $ this -> apiVersion , $ serviceName , $ action ) ; }
|
Returns the full Tulip API URL for the specified service and action .
|
8,588
|
public function callService ( $ serviceName , $ action , array $ parameters = array ( ) , array $ files = array ( ) ) { $ httpClient = $ this -> getHTTPClient ( ) ; $ url = $ this -> getServiceUrl ( $ serviceName , $ action ) ; $ request = new Request ( 'POST' , $ url , $ this -> getRequestHeaders ( $ url , $ parameters ) , $ this -> getRequestBody ( $ parameters , $ files ) ) ; try { $ response = $ httpClient -> send ( $ request ) ; } catch ( GuzzleRequestException $ exception ) { $ response = $ exception -> getResponse ( ) ; } $ this -> validateAPIResponseCode ( $ request , $ response ) ; return $ response ; }
|
Call a Tulip API service .
|
8,589
|
private function getHTTPClient ( ) { if ( $ this -> httpClient instanceof ClientInterface === false ) { $ this -> httpClient = new HTTPClient ( ) ; } return $ this -> httpClient ; }
|
Returns a ClientInterface instance .
|
8,590
|
private function getRequestHeaders ( $ url , array $ parameters ) { $ headers = array ( ) ; if ( isset ( $ this -> clientId ) && isset ( $ this -> sharedSecret ) ) { $ objectIdentifier = null ; if ( $ this -> apiVersion === '1.1' && isset ( $ parameters [ 'id' ] ) ) { $ objectIdentifier = $ parameters [ 'id' ] ; } elseif ( $ this -> apiVersion === '1.0' && isset ( $ parameters [ 'api_id' ] ) ) { $ objectIdentifier = $ parameters [ 'api_id' ] ; } $ headers [ 'X-Tulip-Client-ID' ] = $ this -> clientId ; $ headers [ 'X-Tulip-Client-Authentication' ] = hash_hmac ( 'sha256' , $ this -> clientId . $ url . $ objectIdentifier , $ this -> sharedSecret ) ; } return $ headers ; }
|
Returns the request authentication headers when a client ID and shared secret are provided .
|
8,591
|
private function getRequestBody ( array $ parameters , array $ files ) { $ body = array ( ) ; foreach ( $ parameters as $ parameterName => $ parameterValue ) { if ( is_scalar ( $ parameterValue ) || ( is_null ( $ parameterValue ) && $ parameterName !== 'id' ) ) { $ body [ ] = array ( 'name' => $ parameterName , 'contents' => strval ( $ parameterValue ) , ) ; } } foreach ( $ files as $ parameterName => $ fileResource ) { if ( is_resource ( $ fileResource ) ) { $ metaData = stream_get_meta_data ( $ fileResource ) ; $ body [ ] = array ( 'name' => $ parameterName , 'contents' => $ fileResource , 'filename' => basename ( $ metaData [ 'uri' ] ) , ) ; } } return new MultipartStream ( $ body ) ; }
|
Returns the multipart request body with the parameters and files .
|
8,592
|
private function validateAPIResponseCode ( RequestInterface $ request , ResponseInterface $ response ) { $ responseParser = new ResponseParser ( $ response ) ; switch ( $ responseParser -> getResponseCode ( ) ) { case ResponseCodes :: SUCCESS : break ; case ResponseCodes :: NOT_AUTHORIZED : throw new NotAuthorizedException ( $ responseParser -> getErrorMessage ( ) , $ request , $ response ) ; case ResponseCodes :: UNKNOWN_SERVICE : throw new UnknownServiceException ( $ responseParser -> getErrorMessage ( ) , $ request , $ response ) ; case ResponseCodes :: PARAMETERS_REQUIRED : throw new ParametersRequiredException ( $ responseParser -> getErrorMessage ( ) , $ request , $ response ) ; case ResponseCodes :: NON_EXISTING_OBJECT : throw new NonExistingObjectException ( $ responseParser -> getErrorMessage ( ) , $ request , $ response ) ; case ResponseCodes :: UNKNOWN_ERROR : default : throw new UnknownErrorException ( $ responseParser -> getErrorMessage ( ) , $ request , $ response ) ; } }
|
Validates the Tulip API response code .
|
8,593
|
public function setFieldsFromArray ( Array $ fields ) { foreach ( $ fields as $ field => $ value ) { $ this -> set ( $ field , $ value ) ; } return $ this ; }
|
Setzt mehrere Felder aus einem Array
|
8,594
|
public static function createFromStruct ( Array $ struct , SetMeta $ meta = NULL ) { if ( ! isset ( $ meta ) ) $ meta = new SetMeta ( ) ; $ set = new static ( array ( ) , $ meta ) ; foreach ( $ struct as $ field => $ list ) { list ( $ value , $ type ) = $ list ; $ set -> set ( $ field , $ value , $ type ) ; } return $ set ; }
|
Erstellt ein Set mit angegebenen Metadaten
|
8,595
|
public function init ( $ source ) { $ this -> source = $ source ; $ this -> scan ( $ source ) ; $ this -> reset ( ) ; }
|
Initialisiert den Lexer
|
8,596
|
public function save ( Entity $ entity ) { $ this -> _em -> persist ( $ entity ) ; $ this -> _em -> flush ( ) ; return $ this ; }
|
Persisted das Entity und flushed den EntityManager
|
8,597
|
public function hydrateRole ( $ role , $ identifier ) { return $ this -> _em -> getRepository ( $ this -> _class -> namespace . '\\' . ucfirst ( $ role ) ) -> hydrate ( $ identifier ) ; }
|
Returns an entity of the project which implements a specific Psc \ CMS \ Role
|
8,598
|
public function hydrateBy ( array $ criterias ) { $ entity = $ this -> findOneBy ( $ criterias ) ; if ( ! ( $ entity instanceof $ this -> _entityName ) ) { throw new EntityNotFoundException ( sprintf ( 'Entity %s nicht gefunden: criterias: %s' , $ this -> _entityName , Code :: varInfo ( $ criterias ) ) ) ; } return $ entity ; }
|
Sowie findOneBy aber mit exception
|
8,599
|
public function configureUniqueConstraintValidator ( UniqueConstraintValidator $ validator = NULL ) { $ uniqueConstraints = $ this -> getUniqueConstraints ( ) ; if ( ! isset ( $ validator ) ) { $ constraint = array_shift ( $ uniqueConstraints ) ; $ validator = new UniqueConstraintValidator ( $ constraint ) ; } foreach ( $ uniqueConstraints as $ constraint ) { $ validator -> addUniqueConstraint ( $ constraint ) ; } foreach ( $ validator -> getUniqueConstraints ( ) as $ constraint ) { $ validator -> updateIndex ( $ constraint , $ this -> getUniqueIndex ( $ constraint ) ) ; } return $ validator ; }
|
Setzt einen UniqueConstraintValidator mit den passenden UniqueConstraints des Entities
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.