idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
53,700
public function getLevelName ( ) { switch ( $ this -> getLevel ( ) ) { case self :: LEVEL_INFO : return 'Info' ; case self :: LEVEL_WARNING : return 'Warning' ; case self :: LEVEL_ERROR : return 'Error' ; default : throw new \ UnexpectedValueException ( 'Level was set to ' . $ this -> getLevel ( ) ) ; } }
Gets the Issues level as a string .
53,701
public function getColour ( ) { switch ( $ this -> level ) { case self :: LEVEL_INFO : return 'cyan' ; case self :: LEVEL_WARNING : return 'brown' ; case self :: LEVEL_ERROR : return 'red' ; default : throw new \ UnexpectedValueException ( 'Could not get a colour. Level was set to ' . $ this -> getLevel ( ) ) ; } }
Gets the colour to use when echoing to the console .
53,702
public function forLevel ( $ option ) { $ filter = function ( $ issue ) use ( $ option ) { if ( $ issue -> matches ( $ option ) ) { return true ; } return false ; } ; return $ this -> select ( $ filter ) ; }
Returns a new IssueCollection filtered by the given level option .
53,703
public function getStagedFiles ( ) { $ base = $ this -> getProjectBase ( ) ; $ files = new FileCollection ( ) ; foreach ( $ this -> getFiles ( ) as $ file ) { $ fileData = explode ( "\t" , $ file ) ; $ status = reset ( $ fileData ) ; $ relativePath = end ( $ fileData ) ; $ fullPath = rtrim ( $ base . DIRECTORY_SEPARATOR . $ relativePath ) ; $ file = new File ( $ status , $ fullPath , $ base ) ; $ this -> saveFileToCache ( $ file ) ; $ files -> append ( $ file ) ; } return $ files ; }
Gets a list of the files currently staged under git .
53,704
public function getCommitMessage ( $ file = null ) { if ( $ file ) { $ hash = null ; $ message = file_get_contents ( $ file ) ; } else { list ( $ hash , $ message ) = explode ( PHP_EOL , $ this -> getLastCommitMessage ( ) , 2 ) ; } return new CommitMessage ( $ message , $ hash ) ; }
Get a commit message by file or log .
53,705
private function getFiles ( ) { $ process = new Process ( 'git diff --cached --name-status --diff-filter=ACMR' ) ; $ process -> run ( ) ; if ( $ process -> isSuccessful ( ) ) { return array_filter ( explode ( "\n" , $ process -> getOutput ( ) ) ) ; } return [ ] ; }
Gets the list of files from the index .
53,706
private function saveFileToCache ( FileInterface $ file ) { $ cachedPath = sys_get_temp_dir ( ) . self :: CACHE_DIR . $ file -> getRelativePath ( ) ; if ( ! is_dir ( dirname ( $ cachedPath ) ) ) { mkdir ( dirname ( $ cachedPath ) , 0700 , true ) ; } $ cmd = sprintf ( 'git show :%s > %s' , $ file -> getRelativePath ( ) , $ cachedPath ) ; $ process = new Process ( $ cmd ) ; $ process -> run ( ) ; $ file -> setCachedPath ( $ cachedPath ) ; return $ file ; }
Saves a copy of the cached version of the given file to a temp directory .
53,707
public function loadViews ( $ viewNames = array ( ) , $ data = array ( ) , $ mergeData = array ( ) ) { $ this -> children = array ( ) ; foreach ( $ viewNames as $ key => $ viewName ) { $ className = get_class ( ) ; $ item = new $ className ( $ this -> cmd , $ this -> folder ) ; $ item -> loadView ( $ viewName , $ data , $ mergeData ) ; $ this -> children [ ] = $ item ; } return $ this ; }
Mass version of the loadView function .
53,708
public function loadHTMLs ( $ htmls ) { $ this -> children = array ( ) ; foreach ( $ htmls as $ key => $ html ) { $ className = get_class ( ) ; $ item = new $ className ( $ this -> cmd , $ this -> folder ) ; $ item -> loadHTML ( $ html ) ; $ this -> children [ ] = $ item ; } return $ this ; }
Mass loads HTML Content .
53,709
protected function getInputSource ( ) { if ( empty ( $ this -> children ) ) { return parent :: getInputSource ( ) ; } $ childPaths = [ ] ; foreach ( $ this -> children as $ child ) { $ childPaths [ ] = $ child -> getInputSource ( ) ; } return implode ( " " , $ childPaths ) ; }
Updated version which can handle multiple source files .
53,710
public function review ( ReporterInterface $ reporter , ReviewableInterface $ file ) { $ cmd = sprintf ( 'file %s | grep --fixed-strings --quiet "CRLF"' , $ file -> getFullPath ( ) ) ; $ process = $ this -> getProcess ( $ cmd ) ; $ process -> run ( ) ; if ( $ process -> isSuccessful ( ) ) { $ message = 'File contains CRLF line endings' ; $ reporter -> error ( $ message , $ this , $ file ) ; } }
Checks if the set file contains any CRLF line endings .
53,711
public function getContext ( ) { $ context = [ 'log_cmd_insert' => [ $ this , 'onInsert' ] , 'log_cmd_delete' => [ $ this , 'onDelete' ] , 'log_cmd_update' => [ $ this , 'onUpdate' ] , 'log_insert' => [ $ this , 'onInsert' ] , 'log_delete' => [ $ this , 'onDelete' ] , 'log_update' => [ $ this , 'onUpdate' ] , 'log_batchinsert' => [ $ this , 'onBatchInsert' ] , 'log_write_batch' => [ $ this , 'onBatchInsert' ] , 'log_query' => [ $ this , 'onQuery' ] ] ; return $ context ; }
Returns the context array for being converted into a stream context by the MongoConnection class .
53,712
public function addReviews ( ReviewCollection $ reviews ) { foreach ( $ reviews as $ review ) { $ this -> reviews -> append ( $ review ) ; } return $ this ; }
Appends a ReviewCollection to the current list of reviews .
53,713
public function files ( FileCollection $ files ) { foreach ( $ files as $ key => $ file ) { $ this -> getReporter ( ) -> progress ( $ key + 1 , count ( $ files ) ) ; foreach ( $ this -> getReviews ( ) -> forFile ( $ file ) as $ review ) { $ review -> review ( $ this -> getReporter ( ) , $ file ) ; } } return $ this ; }
Runs through each review on each file collecting any errors .
53,714
public function message ( CommitMessageInterface $ message ) { foreach ( $ this -> getReviews ( ) -> forMessage ( $ message ) as $ review ) { $ review -> review ( $ this -> getReporter ( ) , $ message ) ; } return $ this ; }
Runs through each review on the commit collecting any errors .
53,715
public function getMongoCollectionName ( ) { $ class = get_class ( $ this ) ; $ split_array = explode ( '\\' , $ class ) ; $ final = $ split_array [ count ( $ split_array ) - 1 ] ; return Inflector :: tableize ( substr ( $ final , 0 , - 10 ) ) ; }
Infers the name of the Mongo collection inside of the database based on the namespace of the current class .
53,716
public function setMongaCollection ( $ collection_name ) { $ this -> collection = $ this -> database -> collection ( $ collection_name ) ; return $ this -> collection ; }
Sets a new collection property based on the lowercase tableized collection name passed in as the first arg .
53,717
public function canReview ( ReviewableInterface $ subject ) { if ( $ subject instanceof FileInterface ) { return $ this -> canReviewFile ( $ subject ) ; } if ( $ subject instanceof CommitMessageInterface ) { return $ this -> canReviewMessage ( $ subject ) ; } return false ; }
Determine if the subject can be reviewed .
53,718
private function getRootDirectory ( ) { static $ root ; if ( ! $ root ) { $ working = getcwd ( ) ; $ myself = __DIR__ ; if ( 0 === strpos ( $ myself , $ working ) ) { $ root = $ working ; } else { $ root = realpath ( $ myself . '/../../../../../' ) ; } } return $ root ; }
Get the root directory for a process command .
53,719
public function review ( ReporterInterface $ reporter , ReviewableInterface $ file ) { $ cmd = sprintf ( 'php --syntax-check %s' , $ file -> getFullPath ( ) ) ; $ process = $ this -> getProcess ( $ cmd ) ; $ process -> run ( ) ; $ output = array_filter ( explode ( PHP_EOL , $ process -> getOutput ( ) ) ) ; $ needle = 'Parse error: syntax error, ' ; if ( ! $ process -> isSuccessful ( ) ) { foreach ( array_slice ( $ output , 0 , count ( $ output ) - 1 ) as $ error ) { $ raw = ucfirst ( substr ( $ error , strlen ( $ needle ) ) ) ; $ message = str_replace ( ' in ' . $ file -> getFullPath ( ) , '' , $ raw ) ; $ reporter -> error ( $ message , $ this , $ file ) ; } } }
Checks PHP files using the builtin PHP linter php - l .
53,720
public function connect ( ) { if ( $ this -> _mongo ) { return $ this -> _mongo ; } if ( $ this -> logger ( ) && $ this -> logQueries ( ) ) { $ logger = $ this -> buildStreamContext ( ) ; } else { $ logger = [ ] ; } $ this -> _mongo = Monga :: connection ( $ this -> dns ( ) , $ this -> getMongoConfig ( ) , $ logger ) ; $ this -> _connected = true ; return $ this -> _mongo ; }
Connects to our MongoDB instance and returns the connection object . If we have connected previously returns the old connection object that s already been established .
53,721
public function config ( $ config = null ) { if ( $ this -> _config ) { return $ this -> _config ; } $ this -> _config = $ config ; return $ this -> _config ; }
Gets and Sets our configuration array for our connection class .
53,722
public function dns ( $ dns = null ) { if ( $ dns ) { $ this -> _config [ 'dns' ] = $ dns ; return $ dns ; } if ( isset ( $ this -> _config [ 'dns' ] ) ) { return $ this -> _config [ 'dns' ] ; } return 'mongodb://localhost:27017' ; }
Gets or Sets the DNS string for our connection in our configuration array . If no DNS string is provided the default localhost DNS is returned .
53,723
protected function buildStreamContext ( ) { $ opts = [ ] ; if ( $ this -> logQueries ( ) && $ logger = $ this -> logger ( ) ) { $ opts [ 'mongodb' ] = $ logger -> getContext ( ) ; } $ context = stream_context_create ( $ opts ) ; return [ 'context' => $ context ] ; }
Builds our context object for passing in query logging options as well as the SSL context for HTTPS
53,724
public function getOptionsForConsole ( ) { $ builder = '' ; foreach ( $ this -> options as $ option => $ value ) { $ builder .= '--' . $ option ; if ( $ value ) { $ builder .= '=' . $ value ; } $ builder .= ' ' ; } return $ builder ; }
Gets a string of the set options to pass to the command line .
53,725
public function setOption ( $ option , $ value ) { if ( $ option === 'report' ) { throw new \ RuntimeException ( '"report" is not a valid option name.' ) ; } $ this -> options [ $ option ] = $ value ; return $ this ; }
Adds an option to be included when running PHP_CodeSniffer . Overwrites the values of options with the same name .
53,726
public function review ( ReporterInterface $ reporter , ReviewableInterface $ file ) { $ bin = str_replace ( [ '/' , '\\' ] , DIRECTORY_SEPARATOR , 'vendor/bin/phpcs' ) ; $ cmd = $ bin . ' --report=json ' ; if ( $ this -> getOptionsForConsole ( ) ) { $ cmd .= $ this -> getOptionsForConsole ( ) ; } $ cmd .= $ file -> getFullPath ( ) ; $ process = $ this -> getProcess ( $ cmd ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { $ output = json_decode ( $ process -> getOutput ( ) , true ) ; $ filter = function ( $ acc , $ file ) { if ( $ file [ 'errors' ] > 0 || $ file [ 'warnings' ] > 0 ) { return $ acc + $ file [ 'messages' ] ; } } ; foreach ( array_reduce ( $ output [ 'files' ] , $ filter , [ ] ) as $ error ) { $ message = $ error [ 'message' ] . ' on line ' . $ error [ 'line' ] ; $ reporter -> warning ( $ message , $ this , $ file ) ; } } }
Checks PHP files using PHP_CodeSniffer .
53,727
public static function cssClassProvider ( $ name , $ value ) { switch ( $ name ) { case 'table_condensed' : return $ value ? 'table-condensed' : '' ; break ; case 'collapsed_sidebar' : return $ value ? 'sidebar-collapse' : '' ; break ; default : return parent :: cssClassProvider ( $ name , $ value ) ; } }
Provides css class by given attribute name and value .
53,728
public function report ( $ level , $ message , ReviewInterface $ review , ReviewableInterface $ subject ) { $ issue = new Issue ( $ level , $ message , $ review , $ subject ) ; $ this -> issues -> append ( $ issue ) ; return $ this ; }
Reports an Issue raised by a Review .
53,729
public function info ( $ message , ReviewInterface $ review , ReviewableInterface $ subject ) { $ this -> report ( Issue :: LEVEL_INFO , $ message , $ review , $ subject ) ; return $ this ; }
Reports an Info Issue raised by a Review .
53,730
public function warning ( $ message , ReviewInterface $ review , ReviewableInterface $ subject ) { $ this -> report ( Issue :: LEVEL_WARNING , $ message , $ review , $ subject ) ; return $ this ; }
Reports an Warning Issue raised by a Review .
53,731
public function error ( $ message , ReviewInterface $ review , ReviewableInterface $ subject ) { $ this -> report ( Issue :: LEVEL_ERROR , $ message , $ review , $ subject ) ; return $ this ; }
Reports an Error Issue raised by a Review .
53,732
protected function parseMultiRecordResult ( $ objectName , $ data ) { $ this -> resultCount = ( int ) $ data [ 'result' ] [ 'total_results' ] ; if ( 0 === $ this -> resultCount ) { $ this -> result = array ( ) ; } else { if ( array_key_exists ( $ objectName , $ data [ 'result' ] ) ) { if ( $ this -> resultHasOnlyOneRecord ( $ objectName , $ data ) ) { $ this -> result = array ( $ data [ 'result' ] [ $ objectName ] ) ; } else { $ this -> result = $ data [ 'result' ] [ $ objectName ] ; } } else { $ msg = sprintf ( 'The response does not contain the expected object key \'%s\'' , $ objectName ) ; throw new InvalidArgumentException ( $ msg ) ; } } }
Parse response document containing multiple records
53,733
public function openTunnel ( array $ config ) : Process { $ process = new Process ( $ this -> createSshCommand ( $ config ) ) ; $ process -> setTimeout ( 60 ) ; $ process -> start ( ) ; while ( $ process -> isRunning ( ) ) { sleep ( 1 ) ; } if ( $ process -> getExitCode ( ) !== 0 ) { throw new SSHException ( sprintf ( "Unable to create ssh tunnel. Output: %s ErrorOutput: %s" , $ process -> getOutput ( ) , $ process -> getErrorOutput ( ) ) ) ; } return $ process ; }
Open SSH tunnel defined by config
53,734
public function authenticate ( ) { $ object = 'login' ; $ url = sprintf ( '/api/%s/version/%s' , $ object , $ this -> version ) ; $ parameters = array ( 'email' => $ this -> email , 'password' => $ this -> password , 'user_key' => $ this -> userKey , 'format' => $ this -> format ) ; $ this -> apiKey = $ this -> doPost ( $ object , $ url , $ parameters ) ; return $ this -> apiKey ; }
Make a call to the login endpoint and obtain an API key
53,735
public function post ( $ object , $ operation , $ parameters ) { if ( null === $ this -> apiKey ) { $ this -> authenticate ( ) ; } $ url = sprintf ( '/api/%s/version/%s/do/%s' , $ object , $ this -> version , $ operation ) ; $ parameters = array_merge ( array ( 'api_key' => $ this -> apiKey , 'user_key' => $ this -> userKey , 'format' => $ this -> format , 'output' => $ this -> output ) , $ parameters ) ; try { return $ this -> doPost ( $ object , $ url , $ parameters ) ; } catch ( AuthenticationErrorException $ e ) { $ this -> authenticate ( ) ; $ parameters [ 'api_key' ] = $ this -> apiKey ; return $ this -> doPost ( $ object , $ url , $ parameters ) ; } }
Makes necessary preparations for a POST request to the Pardot API handles authentication retries
53,736
protected function getClient ( ) { $ retries = 5 ; $ httpCodes = null ; $ curlCodes = null ; $ plugin = BackoffPlugin :: getExponentialBackoff ( $ retries , $ httpCodes , $ curlCodes ) ; $ client = new Client ( $ this -> baseUrl ) ; $ client -> addSubscriber ( $ plugin ) ; return $ client ; }
Construct the Guzzle Http Client with the exponential retry plugin
53,737
protected function doPost ( $ object , $ url , $ parameters ) { $ httpResponse = null ; $ headers = null ; $ postBody = null ; $ options = $ this -> httpClientOptions ; try { $ httpResponse = $ this -> client -> post ( $ url , $ headers , $ postBody , $ options ) -> setHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) -> setBody ( http_build_query ( $ parameters ) ) -> send ( ) ; } catch ( HttpException $ e ) { $ msg = sprintf ( '%s. Http status code [%s]' , $ e -> getMessage ( ) , $ e -> getResponse ( ) -> getStatusCode ( ) ) ; throw new RequestException ( $ msg , 0 , $ e , $ url , $ parameters ) ; } catch ( \ Exception $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) , 0 , $ e , $ url , $ parameters ) ; } if ( 204 == $ httpResponse -> getStatusCode ( ) ) { return array ( ) ; } try { $ handler = $ this -> getHandler ( $ httpResponse , $ object ) ; $ result = $ handler -> parse ( ) -> getResult ( ) ; $ this -> totalResults = $ handler -> getResultCount ( ) ; return $ result ; } catch ( ExceptionInterface $ e ) { $ e -> setUrl ( $ url ) ; $ e -> setParameters ( $ parameters ) ; throw $ e ; } catch ( \ Exception $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) , 0 , $ e , $ url , $ parameters ) ; } }
Makes the actual HTTP POST call to the API parses the response and returns the data if there is any . Throws exceptions in case of error .
53,738
protected function getHandler ( $ response , $ object ) { $ handler = null ; switch ( $ this -> format ) { case 'json' : $ this -> rawResponse = $ response -> json ( ) ; $ handler = new JsonResponseHandler ( $ this -> rawResponse , $ object ) ; break ; case 'xml' : $ this -> rawResponse = $ response -> xml ( ) ; $ handler = new XmlResponseHandler ( $ this -> rawResponse , $ object ) ; break ; } return $ handler ; }
Instantiate the appropriate Response document handler based on the format
53,739
public static function decode ( $ data ) { $ decoded = \ base64_decode ( $ data , true ) ; if ( $ decoded === false ) { throw new DecodingError ( ) ; } return $ decoded ; }
Decodes the supplied data from Base64
53,740
public static function encodeUrlSafe ( $ data ) { $ encoded = self :: encode ( $ data ) ; return \ strtr ( $ encoded , self :: LAST_THREE_STANDARD , self :: LAST_THREE_URL_SAFE ) ; }
Encodes the supplied data to a URL - safe variant of Base64
53,741
public static function decodeUrlSafe ( $ data ) { $ data = \ strtr ( $ data , self :: LAST_THREE_URL_SAFE , self :: LAST_THREE_STANDARD ) ; return self :: decode ( $ data ) ; }
Decodes the supplied data from a URL - safe variant of Base64
53,742
public static function encodeUrlSafeWithoutPadding ( $ data ) { $ encoded = self :: encode ( $ data ) ; $ encoded = \ rtrim ( $ encoded , \ substr ( self :: LAST_THREE_STANDARD , - 1 ) ) ; return \ strtr ( $ encoded , \ substr ( self :: LAST_THREE_STANDARD , 0 , - 1 ) , \ substr ( self :: LAST_THREE_URL_SAFE , 0 , - 1 ) ) ; }
Encodes the supplied data to a URL - safe variant of Base64 without padding
53,743
protected function loadStoreId ( ) { $ query = Drupal :: entityQuery ( 'commerce_store' ) ; $ result = $ query -> execute ( ) ; $ storeId = NULL ; if ( count ( $ result ) > 0 ) { $ storeId = reset ( $ result ) ; } return $ storeId ; }
Loads the main store .
53,744
public function workCommand ( $ queue , $ exitAfter = null , $ limit = null , $ verbose = false ) { if ( $ verbose ) { $ this -> output ( 'Watching queue <b>"%s"</b>' , [ $ queue ] ) ; if ( $ exitAfter !== null ) { $ this -> output ( ' for <b>%d</b> seconds' , [ $ exitAfter ] ) ; } $ this -> outputLine ( '...' ) ; } $ startTime = time ( ) ; $ timeout = null ; $ numberOfJobExecutions = 0 ; do { $ message = null ; if ( $ exitAfter !== null ) { $ timeout = max ( 1 , $ exitAfter - ( time ( ) - $ startTime ) ) ; } try { $ message = $ this -> jobManager -> waitAndExecute ( $ queue , $ timeout ) ; } catch ( JobQueueException $ exception ) { $ numberOfJobExecutions ++ ; $ this -> outputLine ( '<error>%s</error>' , [ $ exception -> getMessage ( ) ] ) ; if ( $ verbose && $ exception -> getPrevious ( ) instanceof \ Exception ) { $ this -> outputLine ( ' Reason: %s' , [ $ exception -> getPrevious ( ) -> getMessage ( ) ] ) ; } } catch ( \ Exception $ exception ) { $ this -> outputLine ( '<error>Unexpected exception during job execution: %s, aborting...</error>' , [ $ exception -> getMessage ( ) ] ) ; $ this -> quit ( 1 ) ; } if ( $ message !== null ) { $ numberOfJobExecutions ++ ; if ( $ verbose ) { $ messagePayload = strlen ( $ message -> getPayload ( ) ) <= 50 ? $ message -> getPayload ( ) : substr ( $ message -> getPayload ( ) , 0 , 50 ) . '...' ; $ this -> outputLine ( '<success>Successfully executed job "%s" (%s)</success>' , [ $ message -> getIdentifier ( ) , $ messagePayload ] ) ; } } if ( $ exitAfter !== null && ( time ( ) - $ startTime ) >= $ exitAfter ) { if ( $ verbose ) { $ this -> outputLine ( 'Quitting after %d seconds due to <i>--exit-after</i> flag' , [ time ( ) - $ startTime ] ) ; } $ this -> quit ( ) ; } if ( $ limit !== null && $ numberOfJobExecutions >= $ limit ) { if ( $ verbose ) { $ this -> outputLine ( 'Quitting after %d executed job%s due to <i>--limit</i> flag' , [ $ numberOfJobExecutions , $ numberOfJobExecutions > 1 ? 's' : '' ] ) ; } $ this -> quit ( ) ; } } while ( true ) ; }
Work on a queue and execute jobs
53,745
public function listCommand ( $ queue , $ limit = 1 ) { $ jobs = $ this -> jobManager -> peek ( $ queue , $ limit ) ; $ totalCount = $ this -> queueManager -> getQueue ( $ queue ) -> countReady ( ) ; foreach ( $ jobs as $ job ) { $ this -> outputLine ( '<b>%s</b>' , [ $ job -> getLabel ( ) ] ) ; } if ( $ totalCount > count ( $ jobs ) ) { $ this -> outputLine ( '(%d omitted) ...' , [ $ totalCount - count ( $ jobs ) ] ) ; } $ this -> outputLine ( '(<b>%d total</b>)' , [ $ totalCount ] ) ; }
List queued jobs
53,746
public function executeCommand ( $ queue , $ messageCacheIdentifier ) { if ( ! $ this -> messageCache -> has ( $ messageCacheIdentifier ) ) { throw new JobQueueException ( sprintf ( 'No message with identifier %s was found in the message cache.' , $ messageCacheIdentifier ) , 1517868903 ) ; } $ message = $ this -> messageCache -> get ( $ messageCacheIdentifier ) ; $ queue = $ this -> queueManager -> getQueue ( $ queue ) ; $ this -> jobManager -> executeJobForMessage ( $ queue , $ message ) ; }
Execute one job
53,747
public function sendRequest ( $ req ) { $ response = $ this -> send ( $ req -> getJSON ( ) ) ; if ( $ response -> id != $ req -> id ) { throw new Clientside \ Exception ( "Mismatched request id" ) ; } if ( isset ( $ response -> error_code ) ) { throw new Clientside \ Exception ( "{$response->error_code} {$response->error_message}" , $ response -> error_code ) ; } return $ response -> result ; }
send a single request object
53,748
public function sendNotify ( $ req ) { if ( property_exists ( $ req , 'id' ) && $ req -> id != null ) { throw new Clientside \ Exception ( "Notify requests must not have ID set" ) ; } $ this -> send ( $ req -> getJSON ( ) , true ) ; return true ; }
send a single notify request object
53,749
public function sendBatch ( $ reqs ) { $ arr = array ( ) ; $ ids = array ( ) ; $ all_notify = true ; foreach ( $ reqs as $ req ) { if ( $ req -> id ) { $ all_notify = false ; $ ids [ ] = $ req -> id ; } $ arr [ ] = $ req -> getArray ( ) ; } $ response = $ this -> send ( json_encode ( $ arr ) , $ all_notify ) ; if ( $ all_notify ) { return true ; } $ ordered_response = array ( ) ; foreach ( $ ids as $ id ) { if ( array_key_exists ( $ id , $ response ) ) { $ ordered_response [ ] = $ response [ $ id ] ; unset ( $ response [ $ id ] ) ; } else { throw new Clientside \ Exception ( "Missing id in response" ) ; } } if ( count ( $ response ) > 0 ) { throw new Clientside \ Exception ( "Extra id(s) in response" ) ; } return $ ordered_response ; }
send an array of request objects as a batch
53,750
public function send ( $ json , $ notify = false ) { $ header = "Content-Type: application/json\r\n" ; if ( $ this -> authHeader ) { $ header .= $ this -> authHeader ; } $ opts = array ( 'http' => array ( 'method' => 'POST' , 'header' => $ header , 'content' => $ json ) ) ; $ context = stream_context_create ( $ opts ) ; try { $ response = file_get_contents ( $ this -> uri , false , $ context ) ; } catch ( \ Exception $ e ) { $ message = "Unable to connect to {$this->uri}" ; $ message .= PHP_EOL . $ e -> getMessage ( ) ; throw new Clientside \ Exception ( $ message ) ; } if ( $ response === false ) { throw new Clientside \ Exception ( "Unable to connect to {$this->uri}" ) ; } if ( $ notify ) { return true ; } $ json_response = $ this -> decodeJSON ( $ response ) ; return $ this -> handleResponse ( $ json_response ) ; }
send raw json to the server
53,751
function decodeJSON ( $ json ) { $ json_response = json_decode ( $ json ) ; if ( $ json_response === null ) { throw new Clientside \ Exception ( "Unable to decode JSON response from: {$json}" ) ; } return $ json_response ; }
decode json throwing exception if unable
53,752
public function handleResponse ( $ response ) { if ( is_array ( $ response ) ) { $ response_arr = array ( ) ; foreach ( $ response as $ res ) { $ response_arr [ $ res -> id ] = $ this -> handleResponse ( $ res ) ; } return $ response_arr ; } if ( property_exists ( $ response , 'error' ) ) { return new Response ( null , $ response -> id , $ response -> error -> code , $ response -> error -> message ) ; } return new Response ( $ response -> result , $ response -> id ) ; }
handle the response and return a result or an error
53,753
public function queue ( string $ queueName , JobInterface $ job , array $ options = [ ] ) : void { $ queue = $ this -> queueManager -> getQueue ( $ queueName ) ; $ payload = serialize ( $ job ) ; $ messageId = $ queue -> submit ( $ payload , $ options ) ; $ this -> emitMessageSubmitted ( $ queue , $ messageId , $ payload , $ options ) ; }
Put a job in the queue
53,754
public function waitAndExecute ( string $ queueName , $ timeout = null ) : ? Message { $ messageCacheIdentifier = null ; $ queue = $ this -> queueManager -> getQueue ( $ queueName ) ; $ message = $ queue -> waitAndReserve ( $ timeout ) ; if ( $ message === null ) { $ this -> emitMessageTimeout ( $ queue ) ; return null ; } $ this -> emitMessageReserved ( $ queue , $ message ) ; $ queueSettings = $ this -> queueManager -> getQueueSettings ( $ queueName ) ; try { if ( isset ( $ queueSettings [ 'executeIsolated' ] ) && $ queueSettings [ 'executeIsolated' ] === true ) { $ messageCacheIdentifier = sha1 ( serialize ( $ message ) ) ; $ this -> messageCache -> set ( $ messageCacheIdentifier , $ message ) ; Scripts :: executeCommand ( 'flowpack.jobqueue.common:job:execute' , $ this -> flowSettings , false , [ 'queue' => $ queue -> getName ( ) , 'messageCacheIdentifier' => $ messageCacheIdentifier ] ) ; } else { $ this -> executeJobForMessage ( $ queue , $ message ) ; } } catch ( \ Exception $ exception ) { $ maximumNumberOfReleases = isset ( $ queueSettings [ 'maximumNumberOfReleases' ] ) ? ( integer ) $ queueSettings [ 'maximumNumberOfReleases' ] : 0 ; if ( $ message -> getNumberOfReleases ( ) < $ maximumNumberOfReleases ) { $ releaseOptions = isset ( $ queueSettings [ 'releaseOptions' ] ) ? $ queueSettings [ 'releaseOptions' ] : [ ] ; $ queue -> release ( $ message -> getIdentifier ( ) , $ releaseOptions ) ; $ this -> emitMessageReleased ( $ queue , $ message , $ releaseOptions , $ exception ) ; throw new JobQueueException ( sprintf ( 'Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - RELEASE' , $ message -> getIdentifier ( ) , $ queue -> getName ( ) , $ message -> getNumberOfReleases ( ) + 1 , $ maximumNumberOfReleases + 1 ) , 1334056583 , $ exception ) ; } else { $ queue -> abort ( $ message -> getIdentifier ( ) ) ; $ this -> emitMessageFailed ( $ queue , $ message , $ exception ) ; throw new JobQueueException ( sprintf ( 'Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - ABORTING' , $ message -> getIdentifier ( ) , $ queue -> getName ( ) , $ message -> getNumberOfReleases ( ) + 1 , $ maximumNumberOfReleases + 1 ) , 1334056584 , $ exception ) ; } } finally { if ( $ messageCacheIdentifier !== null ) { $ this -> messageCache -> remove ( $ messageCacheIdentifier ) ; } } $ queue -> finish ( $ message -> getIdentifier ( ) ) ; $ this -> emitMessageFinished ( $ queue , $ message ) ; return $ message ; }
Wait for a job in the given queue and execute it A worker using this method should catch exceptions
53,755
protected function emitMessageReleased ( QueueInterface $ queue , Message $ message , array $ releaseOptions , \ Exception $ jobExecutionException = null ) : void { }
Signal that is triggered when a message has been re - released to the queue
53,756
public function listCommand ( ) { $ rows = [ ] ; foreach ( $ this -> queueConfigurations as $ queueName => $ queueConfiguration ) { $ queue = $ this -> queueManager -> getQueue ( $ queueName ) ; try { $ numberOfMessages = $ queue -> countReady ( ) ; } catch ( \ Exception $ e ) { $ numberOfMessages = '-' ; } $ rows [ ] = [ $ queue -> getName ( ) , TypeHandling :: getTypeForValue ( $ queue ) , $ numberOfMessages ] ; } $ this -> output -> outputTable ( $ rows , [ 'Queue' , 'Type' , '# messages' ] ) ; }
List configured queues
53,757
public function describeCommand ( $ queue ) { $ queueSettings = $ this -> queueManager -> getQueueSettings ( $ queue ) ; $ this -> outputLine ( 'Configuration options for Queue <b>%s</b>:' , [ $ queue ] ) ; $ rows = [ ] ; foreach ( $ queueSettings as $ name => $ value ) { $ rows [ ] = [ $ name , is_array ( $ value ) ? json_encode ( $ value , JSON_PRETTY_PRINT ) : $ value ] ; } $ this -> output -> outputTable ( $ rows , [ 'Option' , 'Value' ] ) ; }
Describe a single queue
53,758
public function setupCommand ( $ queue ) { $ queue = $ this -> queueManager -> getQueue ( $ queue ) ; try { $ queue -> setUp ( ) ; } catch ( \ Exception $ exception ) { $ this -> outputLine ( '<error>An error occurred while trying to setup queue "%s":</error>' , [ $ queue -> getName ( ) ] ) ; $ this -> outputLine ( '%s (#%s)' , [ $ exception -> getMessage ( ) , $ exception -> getCode ( ) ] ) ; $ this -> quit ( 1 ) ; } $ this -> outputLine ( '<success>Queue "%s" has been initialized successfully.</success>' , [ $ queue -> getName ( ) ] ) ; }
Initialize a queue
53,759
public function flushCommand ( $ queue , $ force = false ) { $ queue = $ this -> queueManager -> getQueue ( $ queue ) ; if ( ! $ force ) { $ this -> outputLine ( 'Use the --force flag if you really want to flush queue "%s"' , [ $ queue -> getName ( ) ] ) ; $ this -> outputLine ( '<error>Warning: This will delete all messages from the queue!</error>' ) ; $ this -> quit ( 1 ) ; } $ queue -> flush ( ) ; $ this -> outputLine ( '<success>Flushed queue "%s".</success>' , [ $ queue -> getName ( ) ] ) ; }
Remove all messages from a queue!
53,760
public function submitCommand ( $ queue , $ payload , $ options = null ) { $ queue = $ this -> queueManager -> getQueue ( $ queue ) ; if ( $ options !== null ) { $ options = json_decode ( $ options , true ) ; } $ messageId = $ queue -> submit ( $ payload , $ options !== null ? $ options : [ ] ) ; $ this -> outputLine ( '<success>Submitted payload to queue "%s" with ID "%s".</success>' , [ $ queue -> getName ( ) , $ messageId ] ) ; }
Submit a message to a given queue
53,761
public function getUrl ( DataTable $ data , $ width , $ height , $ title = null , $ params = array ( ) , $ rawParams = array ( ) ) { $ title = isset ( $ title ) ? $ title : null ; $ titleSize = isset ( $ params [ 'titleSize' ] ) ? $ params [ 'titleSize' ] : null ; $ titleColor = isset ( $ params [ 'titleColor' ] ) ? $ params [ 'titleColor' ] : $ this -> options [ 'titleColor' ] ; $ withLabels = isset ( $ params [ 'withLabels' ] ) ? $ params [ 'withLabels' ] : $ this -> options [ 'withLabels' ] ; $ withLegend = isset ( $ params [ 'withLegend' ] ) ? $ params [ 'withLegend' ] : $ this -> options [ 'withLegend' ] ; $ transparent = isset ( $ params [ 'transparent' ] ) ? $ params [ 'transparent' ] : $ this -> options [ 'transparent' ] ; $ backgroundFillColor = isset ( $ params [ 'backgroundFillColor' ] ) ? $ params [ 'backgroundFillColor' ] : null ; $ color = isset ( $ params [ 'color' ] ) ? $ params [ 'color' ] : null ; if ( is_array ( $ color ) ) { $ color = implode ( '|' , $ color ) ; } else { $ color = $ color ? $ color : null ; } $ labels = null ; if ( $ withLabels ) { $ labels = implode ( '|' , $ data -> getLabels ( ) ) ; } $ legendString = $ this -> getLegendParamValue ( $ data ) ; $ dataString = $ this -> getValueParamValue ( $ data ) ; if ( ! is_null ( $ backgroundFillColor ) ) { $ chf = 'bg' ; if ( $ transparent ) { $ chf = 'a' ; } $ chf = $ chf . ',s,' . $ backgroundFillColor ; } $ params = array ( 'chd' => $ dataString , 'cht' => static :: CHART_TYPE , 'chs' => $ width . 'x' . $ height , 'chco' => $ color , 'chtt' => $ title , 'chts' => $ titleColor . ',' . $ titleSize , 'chl' => isset ( $ labels ) ? $ labels : null , 'chdl' => isset ( $ legendString ) ? $ legendString : null , 'chf' => isset ( $ chf ) ? $ chf : null , ) ; $ params = array_merge ( $ params , $ rawParams ) ; return self :: BuildUrl ( $ params ) ; }
Returns a URL for the Google Image Chart
53,762
public static function createBlocks ( ) { $ block = Block :: create ( [ 'id' => 'presto_theme_views_block__presto_product_listing_listing_block' , 'status' => TRUE , 'plugin' => 'views_block:presto_product_listing-listing_block' , 'weight' => 10 , 'theme' => 'presto_theme' , 'region' => 'content' , 'visibility' => [ 'request_path' => [ 'id' => 'request_path' , 'pages' => '/products' , 'negate' => FALSE , 'context_mapping' => [ ] , ] , ] , ] ) ; $ block -> save ( ) ; $ block = Block :: create ( [ 'id' => 'presto_theme_cart' , 'status' => TRUE , 'plugin' => 'commerce_cart' , 'weight' => 30 , 'theme' => 'presto_theme' , 'region' => 'navigation_collapsible' , 'visibility' => [ ] , 'settings' => [ 'id' => 'commerce_cart' , 'label' => 'Cart' , 'provider' => 'commerce_cart' , 'label_display' => '0' , 'dropdown' => 'false' , ] , ] ) ; $ block -> save ( ) ; }
Create block .
53,763
public function field ( $ name ) { if ( ! isset ( $ this -> fieldList [ $ name ] ) ) { $ this -> addField ( $ name ) ; } return $ this -> fieldList [ $ name ] ; }
Get or Create a field with a name
53,764
public function addField ( $ name , $ dataType = "varchar(255)" ) { if ( $ name == "" ) { throw new Exception ( "Field name cannot be empty." ) ; } if ( ctype_upper ( $ name [ 0 ] ) ) { throw new Exception ( "Field name cannot start with upper-case." ) ; } $ this -> fieldList [ $ name ] = new Field ( $ this , $ name , $ dataType ) ; }
Create a field with a name
53,765
public function hideFields ( $ fieldNameList ) { if ( is_array ( $ fieldNameList ) ) { foreach ( $ fieldNameList as $ name ) { $ this -> field ( $ name ) -> hide ( ) ; } } else { $ numargs = func_num_args ( ) ; $ fieldNames = func_get_args ( ) ; for ( $ i = 0 ; $ i < $ numargs ; $ i ++ ) { $ this -> field ( $ fieldNames [ $ i ] ) -> hide ( ) ; } } }
Hide fields useful if you want to keep the field in the database but not show on the curd page .
53,766
protected function countTotalListViewData ( $ keyword = null ) { $ count = 0 ; if ( $ this -> listViewDataClosure != null ) { if ( $ this -> countListViewDataClosure != null ) { $ c = $ this -> countListViewDataClosure ; return $ c ( $ keyword ) ; } else { return 100000 ; } } elseif ( $ this -> searchResultCountClosure != null ) { $ c = $ this -> searchResultCountClosure ; return $ c ( $ keyword ) ; } else { $ this -> beforeGetListViewData ( function ( $ tableName , $ findClause , $ limit , $ bindingData ) use ( & $ count ) { $ count = R :: getCell ( "SELECT COUNT(*) FROM `$tableName` WHERE $findClause $limit" , $ bindingData ) ; } , function ( $ sql , $ limit , $ bindingData ) use ( & $ count ) { $ count = R :: getRow ( "SELECT COUNT(*) AS `count` FROM (" . $ sql . $ limit . ") AS user_defined_query" , $ bindingData ) [ "count" ] ; } , null , null , $ keyword ) ; } return $ count ; }
Count Total List view data
53,767
protected function getListViewData ( $ start = null , $ rowPerPage = null , $ keyword = null , $ sortField = null , $ sortOrder = null ) { $ list = [ ] ; if ( $ this -> listViewDataClosure != null ) { $ c = $ this -> listViewDataClosure ; $ list = $ c ( $ start , $ rowPerPage , $ keyword , $ sortField , $ sortOrder ) ; } elseif ( $ keyword != null && trim ( $ keyword ) != "" && $ this -> searchClosure != null ) { $ c = $ this -> searchClosure ; $ list = $ c ( $ start , $ rowPerPage , $ keyword , $ sortField , $ sortOrder ) ; } else { $ this -> beforeGetListViewData ( function ( $ tableName , $ findClause , $ limit , $ bindingData ) use ( & $ list ) { $ list = R :: find ( $ tableName , $ findClause . $ limit , $ bindingData ) ; } , function ( $ sql , $ limit , $ bindingData ) use ( & $ list ) { $ list = R :: getAll ( $ sql . $ limit , $ bindingData ) ; try { $ list = R :: convertToBeans ( $ this -> tableName , $ list ) ; } catch ( \ Exception $ ex ) { } } , $ start , $ rowPerPage , $ keyword , $ sortField , $ sortOrder ) ; } return $ list ; }
Get List view data
53,768
protected function beforeGetListViewData ( $ callbackRedBean , $ callbackSQL , $ start = null , $ rowPerPage = null , $ keyword = null , $ sortField = null , $ sortOrder = null ) { try { if ( $ start != null && $ rowPerPage != null ) { $ limit = " LIMIT $start,$rowPerPage" ; } else { $ limit = "" ; } if ( $ this -> sql != null ) { $ list = [ ] ; $ callbackSQL ( $ this -> sql , $ limit , $ this -> bindingData ) ; } else { $ bindingData = $ this -> bindingData ; if ( $ this -> findAllClause != null ) { $ findClause = " 1 = 1 " . $ this -> findAllClause ; } else if ( $ this -> findClause != null ) { $ findClause = $ this -> findClause ; } else { $ findClause = " 1 = 1 " ; } if ( $ keyword != null ) { $ searchClause = $ this -> buildSearchingClause ( ) ; $ searchData = $ this -> buildSearchingData ( $ keyword ) ; $ findClause = $ searchClause . $ findClause ; $ bindingData = array_merge ( $ searchData , $ bindingData ) ; } if ( $ sortField != null ) { $ fakeSelect = "SELECT * FROM louislamcrud_fake_table WHERE " ; $ parser = new PHPSQLParser ( $ fakeSelect . $ findClause ) ; $ sqlArray = $ parser -> parsed ; $ sqlArray [ "ORDER" ] [ 0 ] [ "expr_type" ] = "colref" ; $ sqlArray [ "ORDER" ] [ 0 ] [ "base_expr" ] = $ sortField ; $ sqlArray [ "ORDER" ] [ 0 ] [ "sub_tree" ] = null ; $ sqlArray [ "ORDER" ] [ 0 ] [ "direction" ] = $ sortOrder ; $ findClause = str_replace ( $ fakeSelect , "" , ( new PHPSQLCreator ( $ sqlArray ) ) -> created ) ; } $ callbackRedBean ( $ this -> tableName , $ findClause , $ limit , $ bindingData ) ; } } catch ( \ RedBeanPHP \ RedException \ SQL $ ex ) { throw $ ex ; } catch ( \ Exception $ ex ) { $ this -> createTable ( ) ; $ this -> beforeGetListViewData ( $ callbackRedBean , $ callbackSQL , $ start , $ rowPerPage , $ keyword , $ sortField , $ sortOrder ) ; } }
Prepare the SQL or parameter for RedBean
53,769
public function loadBean ( $ id ) { if ( $ this -> currentBean != null ) { throw new BeanNotNullException ( ) ; } $ this -> currentBean = R :: load ( $ this -> tableName , $ id ) ; }
Load a bean . For Edit and Create only . Before rendering the edit or Create page you have to load a bean first .
53,770
public function insertBean ( $ data ) { $ bean = R :: xdispense ( $ this -> tableName ) ; $ result = $ this -> saveBean ( $ bean , $ data ) ; if ( empty ( $ result -> msg ) ) { $ result -> msg = "The record has been created successfully." ; $ result -> class = "callout-info" ; $ result -> ok = true ; } else { $ result -> ok = false ; $ result -> class = "callout-danger" ; } if ( $ this -> afterInsertBean != null ) { $ callable = $ this -> afterInsertBean ; $ callable ( $ bean , $ result ) ; } return $ result ; }
Store Data into Database
53,771
public function updateBean ( $ data ) { if ( $ this -> currentBean == null ) { throw new NoBeanException ( ) ; } $ result = $ this -> saveBean ( $ this -> currentBean , $ data ) ; if ( empty ( $ result -> msg ) ) { $ result -> msg = "Saved." ; $ result -> class = "callout-info" ; } else { $ result -> class = "callout-danger" ; } if ( $ this -> afterUpdateBean != null ) { $ callable = $ this -> afterUpdateBean ; $ callable ( $ this -> currentBean , $ result ) ; } return $ result ; }
Update a bean .
53,772
private function getLayoutName ( ) { if ( $ this -> layout != null ) { return $ this -> layout ; } try { return $ this -> template -> exists ( "backend_layout" ) ? "backend_layout" : $ this -> theme . "::layout" ; } catch ( \ LogicException $ ex ) { return $ this -> theme . "::layout" ; } }
Get Current Layout Name in Plates Template Engine style If user have created a layout . php in the default folder use their layout . php . Or else use the default layout .
53,773
public function checkValid ( ) { if ( $ this -> error_code && $ this -> error_message ) { return false ; } if ( ! $ this -> json_rpc || ! $ this -> method ) { $ this -> error_code = self :: ERROR_INVALID_REQUEST ; $ this -> error_message = "Invalid Request." ; return false ; } if ( substr ( $ this -> method , 0 , 4 ) == 'rpc.' ) { $ this -> error_code = self :: ERROR_RESERVED_PREFIX ; $ this -> error_message = "Illegal method name; Method cannot start with 'rpc.'" ; return false ; } if ( ! preg_match ( self :: VALID_FUNCTION_NAME , $ this -> method ) ) { $ this -> error_code = self :: ERROR_INVALID_REQUEST ; $ this -> error_message = "Invalid Request." ; return false ; } if ( $ this -> json_rpc != "2.0" ) { $ this -> error_code = self :: ERROR_MISMATCHED_VERSION ; $ this -> error_message = "Client/Server JSON-RPC version mismatch; Expected '2.0'" ; return false ; } return true ; }
returns true if request is valid or returns false assigns error
53,774
public function toResponseJSON ( ) { $ arr = array ( 'jsonrpc' => self :: JSON_RPC_VERSION ) ; if ( $ this -> result !== null ) { $ arr [ 'result' ] = $ this -> result ; $ arr [ 'id' ] = $ this -> id ; return json_encode ( $ arr ) ; } else { $ arr [ 'error' ] = array ( 'code' => $ this -> error_code , 'message' => $ this -> error_message ) ; $ arr [ 'id' ] = $ this -> id ; return json_encode ( $ arr ) ; } }
return raw JSON response
53,775
public function toMatchingArray ( $ colsArr ) { $ arr = array ( ) ; foreach ( $ colsArr as $ key => $ col ) { $ arr [ ] = $ this -> getCellArrayForPosition ( $ col -> getId ( ) ) ; } return $ arr ; }
returns an array representation of the instance by matching column ids with Row cell key
53,776
public function getValueForPosition ( $ pos ) { return ( isset ( $ this -> cells [ $ pos ] ) ) ? $ this -> cells [ $ pos ] -> getValue ( ) : null ; }
Returns a value in the row at a specific position
53,777
public function symbols ( $ currencies = null ) { if ( func_num_args ( ) and ! is_array ( func_get_args ( ) [ 0 ] ) ) { $ currencies = func_get_args ( ) ; } $ this -> symbols = $ currencies ; return $ this ; }
Sets the currencies to return . Expects either a list of arguments or a single argument as array
53,778
public function get ( ) { $ url = $ this -> buildUrl ( $ this -> url ) ; try { $ response = $ this -> makeRequest ( $ url ) ; return $ this -> prepareResponse ( $ response ) ; } catch ( TransferException $ e ) { throw new ConnectionException ( $ e -> getMessage ( ) ) ; } }
Makes the request and returns the response with the rates .
53,779
public function getResult ( ) { $ url = $ this -> buildUrl ( $ this -> url ) ; try { $ response = $ this -> makeRequest ( $ url ) ; return $ this -> prepareResponseResult ( $ response ) ; } catch ( TransferException $ e ) { throw new ConnectionException ( $ e -> getMessage ( ) ) ; } }
Makes the request and returns the response with the rates as a Result object
53,780
private function buildUrl ( $ url ) { $ url = $ this -> protocol . '://' . $ url . '/' ; if ( $ this -> date ) { $ url .= $ this -> date ; } else { $ url .= 'latest' ; } $ url .= '?base=' . $ this -> base ; if ( $ this -> key ) { $ url .= '&access_key=' . $ this -> key ; } if ( $ symbols = $ this -> symbols ) { $ url .= '&symbols=' . implode ( ',' , $ symbols ) ; } return $ url ; }
Forms the correct url from the different parts
53,781
public function validateModuleID ( ) { if ( ! empty ( $ this -> moduleID ) ) { $ module = Yii :: $ app -> getModule ( $ this -> moduleID ) ; if ( $ module === null ) { $ this -> addError ( 'moduleID' , "Module '{$this->moduleID}' does not exist." ) ; } } }
Checks if model ID is valid
53,782
public function generateActionParamComments ( ) { $ class = $ this -> modelClass ; $ pks = $ class :: primaryKey ( ) ; if ( ( $ table = $ this -> getTableSchema ( ) ) === false ) { $ params = [ ] ; foreach ( $ pks as $ pk ) { $ params [ ] = '@param ' . ( substr ( strtolower ( $ pk ) , - 2 ) == 'id' ? 'integer' : 'string' ) . ' $' . $ pk ; } return $ params ; } if ( count ( $ pks ) === 1 ) { return [ '@param ' . $ table -> columns [ $ pks [ 0 ] ] -> phpType . ' $id' ] ; } else { $ params = [ ] ; foreach ( $ pks as $ pk ) { $ params [ ] = '@param ' . $ table -> columns [ $ pk ] -> phpType . ' $' . $ pk ; } return $ params ; } }
Generates parameter tags for phpdoc
53,783
public function getQueueSettings ( string $ queueName ) : array { if ( isset ( $ this -> queueSettingsRuntimeCache [ $ queueName ] ) ) { return $ this -> queueSettingsRuntimeCache [ $ queueName ] ; } if ( ! isset ( $ this -> settings [ 'queues' ] [ $ queueName ] ) ) { throw new JobQueueException ( sprintf ( 'Queue "%s" is not configured' , $ queueName ) , 1334054137 ) ; } $ queueSettings = $ this -> settings [ 'queues' ] [ $ queueName ] ; if ( isset ( $ queueSettings [ 'preset' ] ) ) { $ presetName = $ queueSettings [ 'preset' ] ; if ( ! isset ( $ this -> settings [ 'presets' ] [ $ presetName ] ) ) { throw new JobQueueException ( sprintf ( 'Preset "%s", referred to in settings for queue "%s" is not configured' , $ presetName , $ queueName ) , 1466677893 ) ; } $ queueSettings = Arrays :: arrayMergeRecursiveOverrule ( $ this -> settings [ 'presets' ] [ $ presetName ] , $ queueSettings ) ; } $ this -> queueSettingsRuntimeCache [ $ queueName ] = $ queueSettings ; return $ this -> queueSettingsRuntimeCache [ $ queueName ] ; }
Returns the settings for the requested queue merged with the preset defaults if any
53,784
public function getStoreValue ( $ data = null ) { if ( isset ( $ this -> value ) && $ this -> overwriteValue ) { return $ this -> value ; } if ( $ data != null && isset ( $ data [ $ this -> getName ( ) ] ) ) { return $ this -> fieldType -> beforeStoreValue ( $ data [ $ this -> getName ( ) ] ) ; } return $ this -> value ; }
Get the value that will be inserted into the database
53,785
public function getRenderValue ( ) { $ name = $ this -> getName ( ) ; $ defaultValue = $ this -> getDefaultValue ( ) ; $ bean = $ this -> getBean ( ) ; $ value = "" ; if ( $ this -> isCreate ( ) ) { if ( $ this -> value !== null ) { $ value = $ this -> value ; } else if ( $ defaultValue !== null ) { $ value = $ defaultValue ; } } else { if ( $ this -> getFieldRelation ( ) == Field :: MANY_TO_MANY ) { $ keyName = "shared" . ucfirst ( $ name ) . "List" ; $ relatedBeans = $ bean -> { $ keyName } ; $ value = [ ] ; foreach ( $ relatedBeans as $ relatedBean ) { $ value [ $ relatedBean -> id ] = $ relatedBean -> id ; } } else { if ( $ this -> isOverwriteValue ( ) && $ this -> value !== null ) { $ value = $ this -> value ; } else { $ value = $ this -> getFieldType ( ) -> beforeRenderValue ( $ bean -> { $ name } ) ; $ value = htmlspecialchars ( $ value ) ; } } } return $ value ; }
GEt the value that will be rendered on HTML page
53,786
public function isStorable ( ) { return ! $ this -> isReadOnly ( ) && ! $ this -> isHidden ( ) && $ this -> getFieldRelation ( ) == Field :: NORMAL && $ this -> isStorable ; }
Is the field storable to the current table .
53,787
public function getRate ( $ code ) { if ( $ code == $ this -> getBase ( ) ) { return 1.0 ; } if ( isset ( $ this -> rates [ $ code ] ) ) { return $ this -> rates [ $ code ] ; } return null ; }
Get an individual rate by Currency code Will return null if currency is not found in the result
53,788
public function getArray ( ) { $ arr = array ( 'jsonrpc' => self :: JSON_RPC_VERSION , 'method' => $ this -> method ) ; if ( $ this -> params ) { $ arr [ 'params' ] = $ this -> params ; } if ( $ this -> id !== null ) { $ arr [ 'id' ] = $ this -> id ; } return $ arr ; }
return an associated array for this object
53,789
private function recursiveUTF8Decode ( $ result ) { if ( is_array ( $ result ) ) { foreach ( $ result as & $ value ) { $ value = $ this -> recursiveUTF8Decode ( $ value ) ; } return $ result ; } else { return utf8_decode ( $ result ) ; } }
recursively decode utf8
53,790
public function getFilteredDefinitions ( $ type ) { $ all = $ this -> getDefinitions ( ) ; return array_filter ( $ all , function ( $ definition ) use ( $ type ) { return $ definition [ 'type' ] === $ type ; } ) ; }
Filters plugin definitions by a type .
53,791
public function invokeMethod ( $ method , $ params ) { if ( is_object ( $ params ) ) { $ array = array ( ) ; foreach ( $ params as $ key => $ val ) { $ array [ $ key ] = $ val ; } $ params = array ( $ array ) ; } if ( $ params === null ) { $ params = array ( ) ; } $ reflection = new \ ReflectionMethod ( $ this -> exposed_instance , $ method ) ; if ( ! $ reflection -> isPublic ( ) ) { throw new Serverside \ Exception ( "Called method is not publically accessible." ) ; } $ num_required_params = $ reflection -> getNumberOfRequiredParameters ( ) ; if ( $ num_required_params > count ( $ params ) ) { throw new Serverside \ Exception ( "Too few parameters passed." ) ; } return $ reflection -> invokeArgs ( $ this -> exposed_instance , $ params ) ; }
attempt to invoke the method with params
53,792
public function process ( ) { try { $ json = file_get_contents ( $ this -> input ) ; } catch ( \ Exception $ e ) { $ message = "Server unable to read request body." ; $ message .= PHP_EOL . $ e -> getMessage ( ) ; throw new Serverside \ Exception ( $ message ) ; } if ( $ json === false ) { throw new Serverside \ Exception ( "Server unable to read request body." ) ; } $ request = $ this -> makeRequest ( $ json ) ; if ( ! ( defined ( 'ENV' ) && ENV == 'TEST' ) ) { header ( 'Content-type: application/json' ) ; } if ( $ request -> error_code && $ request -> error_message ) { echo $ request -> toResponseJSON ( ) ; return ; } echo $ this -> handleRequest ( $ request ) ; }
process json - rpc request
53,793
public static function createCurrency ( ) { $ default_country = \ Drupal :: config ( 'system.date' ) -> get ( 'country.default' ) ; if ( $ default_country !== 'AU' ) { $ currency_importer = \ Drupal :: service ( 'commerce_price.currency_importer' ) ; $ currency_importer -> importByCountry ( 'AU' ) ; } }
Create currency .
53,794
protected function sortByWeight ( array $ definitions ) { uasort ( $ definitions , function ( $ first , $ second ) { if ( $ first [ 'weight' ] === $ second [ 'weight' ] ) { return 0 ; } return ( $ first [ 'weight' ] < $ second [ 'weight' ] ) ? - 1 : 1 ; } ) ; return $ definitions ; }
Sorts plugins by weight .
53,795
private function shouldInstallDemoContent ( ) { if ( ! array_key_exists ( 'presto_ecommerce_install_demo_content' , $ this -> installState ) ) { return FALSE ; } $ create = ( bool ) $ this -> installState [ 'presto_ecommerce_install_demo_content' ] ; return $ this -> shouldInstallModules ( ) && $ create ; }
Check if we should create demo content too .
53,796
private function addDependencyOperations ( ) { $ operations = [ ] ; foreach ( $ this -> dependencies as $ module => $ type ) { $ operations [ ] = [ [ static :: class , 'installDependency' ] , [ $ module , $ type , ] , ] ; } return $ operations ; }
Crates a set of batch operations to install all required dependencies .
53,797
private function addDemoContentOperations ( ) { $ operations = [ ] ; $ contentDefs = $ this -> demoContentManager -> getFilteredDefinitions ( DemoContentTypes :: ECOMMERCE ) ; $ operations [ ] = [ [ static :: class , 'installDependency' ] , [ 'presto_commerce' , DependencyTypes :: MODULE , ] , ] ; foreach ( $ contentDefs as $ def ) { $ operations [ ] = [ [ static :: class , 'createDemoContent' ] , [ $ def [ 'id' ] ] , ] ; } return $ operations ; }
Crates a set of batch operations to create demo content .
53,798
public static function createDemoContent ( $ pluginId , array & $ context ) { drupal_set_time_limit ( 0 ) ; $ demoContentManager = Drupal :: service ( 'plugin.manager.presto.demo_content' ) ; $ definition = $ demoContentManager -> getDefinition ( $ pluginId ) ; $ label = $ definition [ 'label' ] ; $ instance = $ demoContentManager -> createInstance ( $ pluginId ) ; $ instance -> createContent ( ) ; $ context [ 'results' ] [ ] = $ pluginId ; $ context [ 'message' ] = t ( 'Running %task_name' , [ '%task_name' => lcfirst ( $ label -> render ( ) ) , ] ) ; }
Creates a demo content item .
53,799
public function renderExcel ( ) { $ this -> beforeRender ( ) ; $ list = $ this -> getListViewData ( ) ; $ helper = new ExcelHelper ( ) ; $ helper -> setHeaderClosure ( function ( $ key , $ value ) { $ this -> getSlim ( ) -> response ( ) -> header ( $ key , $ value ) ; } ) ; $ helper -> genExcel ( $ this , $ list , $ this -> getExportFilename ( ) ) ; }
Override render Excel function