idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
55,500
|
protected function createApiClientException ( $ statusCode , $ message , $ requestContents , $ responseContents ) : ApiClientException { return ExceptionFactory :: create ( $ statusCode , $ message , $ requestContents , $ responseContents ) ; }
|
Creates an API exception to throw .
|
55,501
|
protected function processApiClientException ( ApiClientException $ exception , RequestInterface $ request ) : ResponseInterface { if ( ! $ exception instanceof UnauthorizedException ) { throw $ exception ; } $ this -> clearAuthorizationToken ( ) ; $ promise = $ this -> createPromiseForRequest ( $ request , false ) ; return $ promise -> wait ( ) ; }
|
Processes an API client exception checking if authorization has to be renewed .
|
55,502
|
protected function castPropertiesMeta ( array $ meta ) : array { $ properties = [ ] ; foreach ( $ meta [ '@properties' ] ?? [ ] as $ name => $ data ) { $ properties [ $ name ] = new MetaProperty ( $ data ) ; } return $ properties ; }
|
Cast properties meta to MetaProperty class
|
55,503
|
public function getAllByPostType ( $ type , array $ queryVars = array ( ) ) { $ q = new WP_Query ( array_merge ( array ( 'post_type' => $ type , 'nopaging' => true ) , $ queryVars ) ) ; $ posts = array ( ) ; foreach ( $ q -> get_posts ( ) as $ p ) { $ posts [ ] = $ this -> postFactory -> create ( $ p ) ; } return $ posts ; }
|
Get all posts of the given type .
|
55,504
|
public function getYears ( ) { $ years = array ( ) ; foreach ( $ this -> getAllByPostType ( 'post' ) as $ post ) { $ year = ( int ) $ post -> getPublishedDate ( ) -> format ( 'Y' ) ; if ( ! in_array ( $ year , $ years ) ) { $ years [ ] = $ year ; } } rsort ( $ years ) ; return $ years ; }
|
Get array of post years in descending order .
|
55,505
|
private function setName ( $ name ) { $ this -> checkName ( $ name ) ; $ this -> name = $ name ; $ this -> singleValued = in_array ( $ name , $ this -> singles ) ; return $ this ; }
|
Set attribute name
|
55,506
|
private function setValues ( $ values ) { $ values = $ this -> checkContent ( $ values ) ; if ( $ this -> isSingleValued ( ) ) { return $ this -> addValue ( $ values [ 0 ] , true ) ; } return $ this -> addManyValues ( $ values ) ; }
|
Set attribute content
|
55,507
|
private function addValue ( $ value , $ erase = false ) { if ( $ erase ) { $ this -> values = [ ] ; } if ( ! in_array ( $ value , $ this -> values ) ) { $ this -> values [ ] = $ value ; } return $ this ; }
|
Add value to values property
|
55,508
|
public function forgetValue ( $ value ) { $ key = array_search ( $ value , $ this -> values ) ; if ( $ key !== false ) { unset ( $ this -> values [ $ key ] ) ; } return $ this ; }
|
Remove a value from attribute
|
55,509
|
private function checkName ( & $ name ) { if ( ! is_string ( $ name ) ) { throw new InvalidTypeException ( 'The name must be a string value, ' . gettype ( $ name ) . ' is given.' ) ; } $ name = strtolower ( trim ( $ name ) ) ; if ( empty ( $ name ) ) { throw new Exception ( 'The attribute name must not be empty.' ) ; } }
|
Check attribute name
|
55,510
|
private function checkContent ( $ content ) { if ( ! is_array ( $ content ) and ! is_string ( $ content ) ) { throw new InvalidTypeException ( 'The content must be an array or string value, ' . gettype ( $ content ) . ' is given.' ) ; } $ this -> checkSingleValuedContent ( $ content ) ; return is_array ( $ content ) ? $ content : [ $ content ] ; }
|
Check attribute content
|
55,511
|
private function checkSingleValuedContent ( & $ content ) { if ( is_string ( $ content ) and ! $ this -> isSingleValued ( ) ) { $ content = array_map ( 'trim' , explode ( ' ' , $ content ) ) ; } }
|
Check if content is single valued
|
55,512
|
public function token ( ) { if ( ! $ this -> session -> has ( 'token' ) ) { $ this -> session -> create ( 'token' , Str :: random ( 40 ) ) ; } return $ this -> session -> get ( 'token' ) ; }
|
To generate token
|
55,513
|
public function check ( ) { if ( $ this -> session -> get ( 'token' ) === $ this -> request -> input ( 'token' ) || $ this -> session -> get ( 'token' ) === $ this -> request -> header ( 'X-CSRF-TOKEN' ) ) { return true ; } return false ; }
|
To check token
|
55,514
|
private function processServerVariables ( array $ server ) { foreach ( $ server as $ key => $ value ) { $ this -> server [ $ key ] = $ value ; if ( strpos ( $ key , 'HTTP_' ) === 0 ) { $ key = str_replace ( '_' , '-' , substr ( $ key , 5 ) ) ; $ this -> headers [ $ key ] = $ value ; } } $ uri = $ server [ 'REQUEST_URI' ] ; $ uriPath = parse_url ( $ uri , PHP_URL_PATH ) ; $ this -> server [ 'REQUEST_URI' ] = $ uri ; $ this -> server [ 'REQUEST_URI_PATH' ] = $ uriPath ; $ this -> isEncrypted = ! ( empty ( $ server [ 'HTTPS' ] ) || strcasecmp ( $ server [ 'HTTPS' ] , 'off' ) === 0 ) ; $ this -> server [ 'SERVER_PROTOCOL' ] = substr ( $ server [ 'SERVER_PROTOCOL' ] , - 3 ) ; if ( isset ( $ server [ 'CONTENT_LENGTH' ] ) ) { $ this -> headers [ 'CONTENT-LENGTH' ] = $ server [ 'CONTENT_LENGTH' ] ; } if ( isset ( $ server [ 'CONTENT_TYPE' ] ) ) { $ this -> headers [ 'CONTENT-TYPE' ] = $ server [ 'CONTENT_TYPE' ] ; } }
|
Processes the server variables
|
55,515
|
public function server ( string $ key ) : string { if ( array_key_exists ( $ key , $ this -> server ) ) { return $ this -> server [ $ key ] ; } return '' ; }
|
Gets a server variable
|
55,516
|
public function header ( string $ key ) : string { if ( array_key_exists ( $ key , $ this -> headers ) ) { return $ this -> headers [ $ key ] ; } return '' ; }
|
Gets a header
|
55,517
|
public function get ( string $ key ) { if ( array_key_exists ( $ key , $ this -> get ) ) { return $ this -> get [ $ key ] ; } return '' ; }
|
Gets a get variable
|
55,518
|
public function post ( string $ key ) { if ( array_key_exists ( $ key , $ this -> post ) ) { return $ this -> post [ $ key ] ; } return '' ; }
|
Gets a post variable
|
55,519
|
public function files ( string $ key ) : array { if ( array_key_exists ( $ key , $ this -> files ) ) { return $ this -> files [ $ key ] ; } return [ ] ; }
|
Gets an item from the files
|
55,520
|
public function getBaseUrl ( ) : string { $ schemeAndHttpHost = 'http' ; if ( $ this -> isEncrypted ( ) ) { $ schemeAndHttpHost .= 's' ; } $ schemeAndHttpHost .= '://' . $ this -> server ( 'SERVER_NAME' ) ; if ( ( ! $ this -> isEncrypted ( ) && $ this -> server ( 'SERVER_PORT' ) !== '80' ) || ( $ this -> isEncrypted ( ) && $ this -> server ( 'SERVER_PORT' ) !== '443' ) ) { $ schemeAndHttpHost .= ':' . $ this -> server ( 'SERVER_PORT' ) ; } return $ schemeAndHttpHost ; }
|
Gets the base URL of the request
|
55,521
|
public function getFlaggedNice ( ) { $ obj = HTMLText :: create ( ) ; $ obj -> setValue ( ( $ this -> Flag ) ? '<span class="red">✱</span>' : '' ) ; $ this -> extend ( "updateFlaggedNice" , $ obj ) ; return $ obj ; }
|
Has this note been flagged? If so return a HTML Object that can be loaded into a gridfield .
|
55,522
|
public function formatException ( \ Exception $ ex ) { return sprintf ( $ this -> errorMessageFormat , $ ex -> getMessage ( ) , $ ex -> getCode ( ) , $ ex -> getFile ( ) , $ ex -> getLine ( ) , get_class ( $ ex ) ) ; }
|
Pass the given exception into the error message format string .
|
55,523
|
public function registerAssetFiles ( $ view ) { $ language = Yii :: $ app -> language ; if ( file_exists ( $ this -> sourcePath . "/$language.js" ) !== false ) { $ this -> js = [ "$language.js" ] ; } parent :: registerAssetFiles ( $ view ) ; }
|
This function extends default AssetBundle behavior - this will dynamically add needed file with js translation based on current requested language .
|
55,524
|
protected function setStream ( $ type , StreamInterface $ stream ) { $ this -> streams [ $ type ] = $ stream ; $ callback = array ( $ this , 'on' . ucfirst ( $ type ) . 'Message' ) ; $ stream -> addListener ( StreamInterface :: MESSAGE , $ this -> createEventListenerForStream ( $ callback ) ) ; return $ this ; }
|
Add the given stream and register it to the EventDispatcher .
|
55,525
|
private function createEventListenerForStream ( $ callback ) { $ logger = $ this -> getLogger ( ) ; $ function = function ( MessageEvent $ event ) use ( $ callback , $ logger ) { $ protocol = $ event -> getProtocolMessage ( ) ; if ( $ protocol === null ) { $ logger -> debug ( 'Incompatable message: ' . $ event -> getMessage ( ) ) ; return ; } $ routing = $ event -> getMessage ( ) -> getRoutingInformation ( ) ; call_user_func ( $ callback , $ protocol , $ routing ) ; return ; } ; return $ function ; }
|
Creates an event listener for a stream .
|
55,526
|
public function onClientMessage ( MessageInterface $ msg , $ routing ) { $ client = $ this -> client ( array_shift ( $ routing ) ) ; if ( $ msg instanceof ExecuteRequest ) { $ this -> clientRequest ( $ client , $ msg ) ; return ; } if ( $ msg instanceof FetchRequest ) { $ this -> clientFetch ( $ client , $ msg ) ; return ; } $ this -> getLogger ( ) -> info ( 'Invalid message type: ' . get_class ( $ msg ) . '.' ) ; }
|
Handle a message from a Client .
|
55,527
|
public function onWorkerHandlerMessage ( ClientHandlerJobResponse $ msg ) { $ this -> workerHandlerReady = true ; $ requestId = $ msg -> getRequestId ( ) ; if ( isset ( $ this -> workerHandlerQueue [ $ requestId ] ) ) { unset ( $ this -> workerHandlerQueue [ $ requestId ] ) ; } $ workerHandler = $ msg -> getWorkerHandlerId ( ) ; $ request = $ this -> getRequest ( $ requestId ) ; if ( $ request === null ) { $ this -> getLogger ( ) -> info ( sprintf ( 'WorkerHandler %s accepted request %s, but request is unknown.' , $ workerHandler , $ requestId ) ) ; return ; } $ this -> getLogger ( ) -> debug ( sprintf ( 'Worker-handler %s accepted request: %s.' , $ workerHandler , $ requestId ) ) ; $ request -> setWorkerHandlerId ( $ workerHandler ) ; }
|
Handle the result of a Job that a WorkerHandler processed .
|
55,528
|
public function onWorkerHandlerStatusMessage ( WorkerHandlerStatus $ msg ) { $ handlerId = $ msg -> getWorkerHandlerId ( ) ; if ( isset ( $ this -> workerHandlers [ $ handlerId ] ) ) { unset ( $ this -> workerHandlers [ $ handlerId ] ) ; } $ this -> workerHandlers [ $ handlerId ] = microtime ( true ) ; $ requestId = $ msg -> getRequestId ( ) ; if ( $ requestId === null ) { return ; } $ this -> getLogger ( ) -> debug ( 'Storage has a result available for: ' . $ requestId . '.' ) ; $ this -> sendResponseToClients ( $ requestId ) ; }
|
Handle a status message from the WorkerHandler .
|
55,529
|
public function handleWorkerHandlerQueue ( ) { if ( ! $ this -> workerHandlerReady || count ( $ this -> workerHandlerQueue ) == 0 ) { return ; } $ requestId = array_shift ( $ this -> workerHandlerQueue ) ; $ request = $ this -> getRequest ( $ requestId ) ; if ( $ request === null ) { return ; } $ this -> getLogger ( ) -> debug ( 'Sending request: ' . $ requestId . ' to worker-handler.' ) ; $ this -> workerHandlerReady = false ; $ this -> getStream ( 'workerHandler' ) -> send ( new ClientHandlerJobRequest ( $ requestId , $ request -> getActionName ( ) , $ request -> getParams ( ) ) ) ; }
|
Processes all new messages in the WorkerHandler queue .
|
55,530
|
public function hasExpiredWorkerHandler ( ) { $ hasExpired = false ; $ timeout = AlphaRPC :: WORKER_HANDLER_TIMEOUT ; $ validTime = microtime ( true ) - ( $ timeout / 1000 ) ; foreach ( $ this -> workerHandlers as $ handlerId => $ time ) { if ( $ time >= $ validTime ) { break ; } unset ( $ this -> workerHandlers [ $ handlerId ] ) ; $ hasExpired = true ; } return $ hasExpired ; }
|
Checks and removes all expired WorkerHandlers .
|
55,531
|
public function clientRequest ( Client $ client , ExecuteRequest $ msg ) { $ requestId = $ msg -> getRequestId ( ) ; if ( ! $ requestId ) { do { $ requestId = sha1 ( uniqid ( ) ) ; } while ( isset ( $ this -> request [ $ requestId ] ) ) ; } if ( $ this -> storage -> has ( $ requestId ) ) { $ this -> getLogger ( ) -> info ( sprintf ( 'Client %s wants to execute request %s. ' . 'Since there already is a result for that request, ' . 'it will be sent back immediately.' , bin2hex ( $ client -> getId ( ) ) , $ requestId ) ) ; $ this -> reply ( $ client , new ExecuteResponse ( $ requestId , $ this -> storage -> get ( $ requestId ) ) ) ; return ; } $ this -> reply ( $ client , new ExecuteResponse ( $ requestId ) ) ; $ request = $ this -> getRequest ( $ requestId ) ; if ( $ request ) { $ this -> getLogger ( ) -> info ( sprintf ( 'Client %s wants to execute already known request %s.' , bin2hex ( $ client -> getId ( ) ) , $ requestId ) ) ; return ; } $ action = $ msg -> getAction ( ) ; $ params = $ msg -> getParams ( ) ; $ this -> getLogger ( ) -> info ( sprintf ( 'New request %s from client %s for action %s' , $ requestId , bin2hex ( $ client -> getId ( ) ) , $ action ) ) ; $ this -> addRequest ( new Request ( $ requestId , $ action , $ params ) ) ; if ( ! $ this -> storage -> has ( $ requestId ) ) { $ this -> addWorkerQueue ( $ requestId ) ; } }
|
Handle a request form a Client .
|
55,532
|
protected function clientFetch ( Client $ client , FetchRequest $ msg ) { $ requestId = $ msg -> getRequestId ( ) ; $ waitForResult = $ msg -> getWaitForResult ( ) ; $ client -> setRequest ( $ requestId , $ waitForResult ) ; $ this -> getLogger ( ) -> debug ( sprintf ( 'Client %s is requesting the result of request %s.' , bin2hex ( $ client -> getId ( ) ) , $ requestId ) ) ; if ( $ this -> storage -> has ( $ requestId ) ) { $ this -> sendResponseToClients ( $ requestId ) ; return ; } $ this -> logger -> debug ( sprintf ( 'The result for request %s is not yet available, but ' . 'client %s is %s to wait for it.' , $ requestId , bin2hex ( $ client -> getId ( ) ) , ( $ waitForResult ) ? 'willing' : 'not willing' ) ) ; if ( ! $ waitForResult ) { $ this -> reply ( $ client , new TimeoutResponse ( $ requestId ) ) ; ; } }
|
Handle a Fetch Request from a Client .
|
55,533
|
public function handle ( ) { $ this -> getStream ( 'client' ) -> handle ( new TimeoutTimer ( $ this -> delay / 4 ) ) ; $ this -> getStream ( 'workerHandler' ) -> handle ( new TimeoutTimer ( $ this -> delay / 4 ) ) ; $ this -> handleWorkerHandlerQueue ( ) ; $ this -> getStream ( 'workerHandlerStatus' ) -> handle ( new TimeoutTimer ( $ this -> delay / 4 ) ) ; $ this -> handleExpired ( ) ; $ this -> handleExpiredWorkerHandlers ( ) ; }
|
Contains the main loop of the Client Handler .
|
55,534
|
public function handleExpired ( ) { $ expired = $ this -> clients -> getExpired ( AlphaRPC :: CLIENT_PING ) ; foreach ( $ expired as $ client ) { $ this -> reply ( $ client , new TimeoutResponse ( ) ) ; } }
|
Send a reply to expired clients .
|
55,535
|
public function handleExpiredWorkerHandlers ( ) { if ( ! $ this -> hasExpiredWorkerHandler ( ) ) { return ; } foreach ( $ this -> request as $ request ) { $ worker_handler_id = $ request -> getWorkerHandlerId ( ) ; if ( $ this -> hasWorkerHandler ( $ worker_handler_id ) ) { continue ; } $ this -> addWorkerQueue ( $ request -> getId ( ) ) ; $ this -> getLogger ( ) -> info ( sprintf ( 'WorkerHandler %s for request %s is expired. ' . 'Therefore, the request is queued again.' , $ worker_handler_id , $ request -> getId ( ) ) ) ; } }
|
Queue requests again for expired WorkerHandlers .
|
55,536
|
public function getRequest ( $ id ) { if ( ! isset ( $ this -> request [ $ id ] ) ) { return null ; } return $ this -> request [ $ id ] ; }
|
Returns the Request with the given ID .
|
55,537
|
public function removeRequest ( $ requestId ) { if ( isset ( $ this -> request [ $ requestId ] ) ) { unset ( $ this -> request [ $ requestId ] ) ; } return $ this ; }
|
Remove the given request .
|
55,538
|
public function reply ( Client $ client , MessageInterface $ msg ) { $ this -> getStream ( 'client' ) -> send ( $ msg , $ client -> getId ( ) ) ; $ this -> remove ( $ client ) ; }
|
Send the given message to the Client .
|
55,539
|
public function setLogger ( LoggerInterface $ logger ) { $ this -> logger = $ logger ; $ this -> getLogger ( ) -> info ( 'ClientHandler is started with pid ' . getmypid ( ) ) ; }
|
Set the Logger
|
55,540
|
public function getQuery ( ) { if ( ! $ this -> query instanceof Query ) { $ this -> query = $ this -> query === null ? new Query ( ) : Query :: fromString ( $ this -> query ) ; } return $ this -> query ; }
|
Get the query part of the URL as a Query object
|
55,541
|
public function setQuery ( $ query , $ rawString = false ) { if ( $ query instanceof Query ) { $ this -> query = $ query ; } elseif ( is_string ( $ query ) ) { if ( ! $ rawString ) { $ this -> query = Query :: fromString ( $ query ) ; } else { $ this -> query = preg_replace_callback ( self :: $ queryPattern , [ __CLASS__ , 'encodeMatch' ] , $ query ) ; } } elseif ( is_array ( $ query ) ) { $ this -> query = new Query ( $ query ) ; } else { throw new \ InvalidArgumentException ( 'Query must be a Query, ' . 'array, or string. Got ' . Core :: describeType ( $ query ) ) ; } }
|
Set the query part of the URL .
|
55,542
|
private function process ( ViewSource $ source , ContextInterface $ context ) : ViewSource { foreach ( $ this -> processors as $ processor ) { $ source = $ processor -> process ( $ source , $ context ) ; } return $ source ; }
|
Process given view source using set of associated processors .
|
55,543
|
public function getRequestUri ( ) { if ( isset ( $ this -> env [ 'REQUEST_URI' ] ) ) { $ uri = $ this -> env [ 'REQUEST_URI' ] ; } else { $ uri = "/" ; } if ( strstr ( $ uri , "?" ) ) { $ uri = strstr ( $ uri , "?" , true ) ; } return $ uri ; }
|
Retrieve the REQUEST_URI without and GET parameters
|
55,544
|
public function getHeader ( $ name , $ default = null ) { if ( empty ( $ name ) ) { return $ default ; } $ temp = 'HTTP_' . strtoupper ( str_replace ( '-' , '_' , $ name ) ) ; if ( isset ( $ this -> env [ $ temp ] ) ) { return $ this -> env [ $ temp ] ; } if ( function_exists ( 'apache_request_headers' ) ) { $ method = 'apache_request_headers' ; $ headers = $ method ( ) ; if ( isset ( $ headers [ $ name ] ) ) { return $ headers [ $ name ] ; } $ header = strtolower ( $ name ) ; foreach ( $ headers as $ key => $ value ) { if ( strtolower ( $ key ) == $ name ) { return $ value ; } } } return $ default ; }
|
Retrieve a header from the request header stack and optionally set a default value to use if key isn t found .
|
55,545
|
public function getBody ( ) { if ( $ this -> body == false ) { $ body = @ file_get_contents ( 'php://input' ) ; if ( $ body != false && strlen ( trim ( $ body ) ) > 0 ) { $ this -> body = $ body ; } else { $ this -> body = false ; } } if ( $ this -> body == false ) { return false ; } return $ body ; }
|
Get the raw body if any .
|
55,546
|
public function getIp ( ) { if ( isset ( $ this -> env [ 'HTTP_X_FORWARDED_FOR' ] ) ) { return $ this -> env [ 'HTTP_X_FORWARDED_FOR' ] ; } elseif ( isset ( $ this -> env [ 'HTTP_CLIENT_IP' ] ) ) { return $ this -> env [ 'HTTP_CLIENT_IP' ] ; } return $ this -> env [ 'REMOTE_ADDR' ] ; }
|
Return the users IP Address
|
55,547
|
protected function buildParams ( ) { if ( empty ( $ this -> get ) ) { foreach ( @ $ _GET as $ k => $ v ) { $ this -> get [ $ k ] = $ v ; $ this -> params [ $ k ] = $ v ; } } if ( empty ( $ this -> post ) ) { foreach ( @ $ _POST as $ k => $ v ) { $ this -> post [ $ k ] = $ v ; $ this -> params [ $ k ] = $ v ; } } foreach ( $ this -> userParams as $ k => $ v ) { $ this -> params [ $ k ] = $ v ; } }
|
Assign the GET POST and User Params to the main Params
|
55,548
|
public function collect ( $ callback ) { $ items = $ this -> crawler -> crawl ( ) ; $ articles = array ( ) ; foreach ( ( array ) $ items as $ item ) { $ article = $ this -> scraper -> scrape ( $ item ) ; $ articles [ ] = $ callback ( $ article , $ item ) ; } return $ articles ; }
|
Returns an array of article instances .
|
55,549
|
public static function getEventNames ( ) { $ names = [ ] ; $ reflection = new \ ReflectionClass ( self :: class ) ; foreach ( $ reflection -> getConstants ( ) as $ constant => $ value ) { if ( 'REPEATED_' === substr ( $ constant , 0 , 9 ) ) { $ names [ ] = $ value ; } } return $ names ; }
|
Get Event Names
|
55,550
|
public static function getDateInterval ( $ type ) { $ types = [ self :: REPEATED_EVERY_MINUTE => 'PT1M' , self :: REPEATED_TWO_MINUTES => 'PT2M' , self :: REPEATED_FIVE_MINUTES => 'PT5M' , self :: REPEATED_TEN_MINUTES => 'PT10M' , self :: REPEATED_TWENTY_MINUTES => 'PT20M' , self :: REPEATED_EVERY_HOUR => 'PT60M' , self :: REPEATED_DAILY_MORNING => 'P1D' , self :: REPEATED_DAILY_NIGHT => 'P1D' , self :: REPEATED_DAILY_NOON => 'P1D' , self :: REPEATED_FIRST_DAY_OF_MONTH => 'P1M' , ] ; return new DateInterval ( $ types [ $ type ] ) ; }
|
Get DateInterval Names
|
55,551
|
protected static function mimetypeInternalDetect ( $ path ) { $ pinfo = pathinfo ( $ path ) ; $ ext = isset ( $ pinfo [ 'extension' ] ) ? strtolower ( $ pinfo [ 'extension' ] ) : '' ; return isset ( elFinderVolumeDriver :: $ mimetypes [ $ ext ] ) ? elFinderVolumeDriver :: $ mimetypes [ $ ext ] : 'unknown' ; }
|
Detect file mimetype using internal method
|
55,552
|
public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( SmartyFilterI18nTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ SmartyFilter \ Model \ SmartyFilterI18n ) { $ criteria = $ values -> buildPkeyCriteria ( ) ; } else { $ criteria = new Criteria ( SmartyFilterI18nTableMap :: DATABASE_NAME ) ; if ( count ( $ values ) == count ( $ values , COUNT_RECURSIVE ) ) { $ values = array ( $ values ) ; } foreach ( $ values as $ value ) { $ criterion = $ criteria -> getNewCriterion ( SmartyFilterI18nTableMap :: ID , $ value [ 0 ] ) ; $ criterion -> addAnd ( $ criteria -> getNewCriterion ( SmartyFilterI18nTableMap :: LOCALE , $ value [ 1 ] ) ) ; $ criteria -> addOr ( $ criterion ) ; } } $ query = SmartyFilterI18nQuery :: create ( ) -> mergeWith ( $ criteria ) ; if ( $ values instanceof Criteria ) { SmartyFilterI18nTableMap :: clearInstancePool ( ) ; } elseif ( ! is_object ( $ values ) ) { foreach ( ( array ) $ values as $ singleval ) { SmartyFilterI18nTableMap :: removeInstanceFromPool ( $ singleval ) ; } } return $ query -> delete ( $ con ) ; }
|
Performs a DELETE on the database given a SmartyFilterI18n or Criteria object OR a primary key value .
|
55,553
|
private function getTblStructure ( ) { if ( strpos ( $ this -> tbl , '{db_prefix}' ) !== 0 || strpos ( $ this -> tbl , $ this -> prefix ) !== 0 ) { $ this -> tbl = $ this -> prefix . $ this -> tbl ; } else { $ this -> tbl = str_replace ( '{db_prefix}' , $ this -> prefix , $ this -> tbl ) ; } $ driver_class = '\Core\Data\Db\\' . ucfirst ( $ this -> db -> dbh -> getPrefix ( ) ) ; $ db_subs = new $ driver_class ( $ this , $ this -> tbl ) ; $ db_subs -> loadColumns ( $ this -> tbl ) ; $ this -> columns = $ db_subs -> getColumns ( ) ; $ db_subs -> loadIndexes ( $ this -> tbl ) ; $ this -> indexes = $ db_subs -> getIndexes ( ) ; }
|
Get complex table structure .
|
55,554
|
public function replaceHashableAttributes ( $ attributes ) { $ hash_id = $ this -> generateHashId ( $ attributes ) ; if ( $ hash_id ) { $ attributes [ 'hash_id' ] = $ hash_id ; foreach ( $ this -> hashableAttributes as $ value ) { unset ( $ attributes [ $ value ] ) ; } } return $ attributes ; }
|
Returns an array of attributes where the hashable attributes are replaced by the hash_id
|
55,555
|
public function generateHashId ( $ attributes ) { $ hashable_string = $ this -> getHashableString ( $ attributes ) ; if ( $ hashable_string ) return $ this -> hash ( $ hashable_string ) ; return null ; }
|
Get a hash id string from the set of hashable attributes .
|
55,556
|
public function getHashableString ( $ attributes ) { $ string = null ; if ( ! empty ( $ this -> hashableAttributes ) ) { foreach ( $ this -> hashableAttributes as $ value ) { if ( isset ( $ attributes [ $ value ] ) ) $ string .= $ attributes [ $ value ] ; else return null ; } } return $ string ; }
|
Get a hashable string from the hashable attributes .
|
55,557
|
public function resolve ( ) { $ this -> template = $ this -> createTemplate ( $ this -> templateClass ) ; $ this -> template -> setZones ( $ this -> zones ) ; $ this -> assertEntityIsValid ( $ this -> template , array ( 'Template' , 'creation' ) ) ; $ this -> eventDispatcher -> addListener ( TemplateEvents :: TEMPLATE_CREATED , $ handler = array ( $ this , 'onTemplateCreated' ) ) ; $ this -> fireEvent ( TemplateEvents :: TEMPLATE_CREATED , new TemplateEvent ( $ this -> template , $ this ) ) ; $ this -> eventDispatcher -> removeListener ( TemplateEvents :: TEMPLATE_CREATED , $ handler ) ; return $ this -> template ; }
|
Template creation method .
|
55,558
|
public function encode ( $ data ) { list ( $ data , $ consumed , $ error ) = $ this -> encodeTransform ( ) -> transform ( $ data , $ context , true ) ; if ( null !== $ error ) { throw $ error ; } return $ data ; }
|
Encode the supplied data .
|
55,559
|
public function decode ( $ data ) { list ( $ data , $ consumed , $ error ) = $ this -> decodeTransform ( ) -> transform ( $ data , $ context , true ) ; if ( null !== $ error ) { throw $ error ; } return $ data ; }
|
Decode the supplied data .
|
55,560
|
protected function createMySQLDatabase ( ) { $ this -> checkParameters ( ) ; $ this -> url = $ this -> obtainAPIURLEndpoint ( ) ; try { $ this -> http -> post ( $ this -> url , [ 'form_params' => $ data = $ this -> getData ( ) , 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' , 'Authorization' => 'Bearer ' . fp_env ( 'ACACHA_FORGE_ACCESS_TOKEN' ) ] ] ) ; if ( $ this -> option ( 'wait' ) ) { $ this -> info ( 'Waiting for database to be installed in Laravel Forge server...' ) ; $ this -> waitForMySQLDatabaseByName ( $ data [ 'name' ] ) ; $ this -> info ( 'Installed!' ) ; } } catch ( \ GuzzleHttp \ Exception \ ServerException $ se ) { if ( str_contains ( $ se -> getResponse ( ) -> getBody ( ) -> getContents ( ) , 'The given data failed to pass validation' ) ) { $ this -> error ( 'Skipping installation. Some of the data you provided already exists in server' ) ; } } catch ( \ Exception $ e ) { dump ( $ e -> getMessage ( ) ) ; } }
|
Create MySQL database .
|
55,561
|
protected function listMySQLDatabases ( ) { $ databases = $ this -> fetchMySQLDatabases ( ) ; if ( $ this -> option ( 'dump' ) ) { dump ( $ databases ) ; } if ( empty ( $ databases ) ) { $ this -> error ( 'No databases found.' ) ; die ( ) ; } $ headers = [ 'Id' , 'Server Id' , 'Name' , 'Status' , 'Created at' ] ; $ rows = [ ] ; foreach ( $ databases as $ database ) { $ rows [ ] = [ $ database [ 'id' ] , $ database [ 'serverId' ] , $ database [ 'name' ] , $ database [ 'status' ] , $ database [ 'createdAt' ] ] ; } $ this -> table ( $ headers , $ rows ) ; }
|
List MySQL databases .
|
55,562
|
public static function lowerCaseFirst ( $ str , $ encoding = null ) { return ( string ) Stringy :: create ( $ str , $ encoding ) -> lowerCaseFirst ( ) ; }
|
Converts the first character of the supplied string to lower case .
|
55,563
|
public static function upperCamelize ( $ str , $ encoding = null ) { return ( string ) Stringy :: create ( $ str , $ encoding ) -> upperCamelize ( ) ; }
|
Returns an UpperCamelCase version of the supplied string . It trims surrounding spaces capitalizes letters following digits spaces dashes and underscores and removes spaces dashes underscores .
|
55,564
|
public static function format_background ( $ value , $ post_id , $ field ) { if ( self :: BACKGROUND !== $ field [ 'key' ] ) { return $ value ; } $ new_value = [ ] ; foreach ( $ value as $ index => $ item ) { $ new_value [ $ index ] = [ 'type' => $ item [ 'type' ] , ] ; if ( 'images' === $ item [ 'type' ] ) { $ new_value [ $ index ] [ 'images' ] = $ item [ 'images' ] ; } if ( 'video' === $ item [ 'type' ] ) { $ new_value [ $ index ] [ 'video' ] = 'file' === $ field [ 'sub_fields' ] [ 2 ] [ 'type' ] ? $ item [ 'video' ] : Utils :: get_video_embed_url ( $ item [ 'video' ] ) ; $ new_value [ $ index ] [ 'fallback_image' ] = $ item [ 'fallback_image' ] ; } } return $ new_value ; }
|
Format the background field .
|
55,565
|
public function key ( $ type , $ columns , $ name ) { $ parameters = array ( 'name' => $ name , 'columns' => ( array ) $ columns ) ; return $ this -> command ( $ type , $ parameters ) ; }
|
Create a command for creating any index .
|
55,566
|
protected function command ( $ type , $ parameters = array ( ) ) { $ parameters = array_merge ( compact ( 'type' ) , $ parameters ) ; $ this -> commands [ ] = new Fluent ( $ parameters ) ; return end ( $ this -> commands ) ; }
|
Create a new fluent command instance .
|
55,567
|
protected function column ( $ type , $ parameters = array ( ) ) { $ parameters = array_merge ( compact ( 'type' ) , $ parameters ) ; $ this -> columns [ ] = new Fluent ( $ parameters ) ; return end ( $ this -> columns ) ; }
|
Create a new fluent column instance .
|
55,568
|
protected function sendRequest ( RequestInterface $ request , $ responseClass ) { if ( ! in_array ( ApiResponseInterface :: class , class_implements ( $ responseClass ) ) ) { throw new \ InvalidArgumentException ( 'The response class must implement "' . ApiResponseInterface :: class . '".' ) ; } $ body = $ this -> serializer -> serialize ( $ request , 'json' ) ; $ response = $ this -> transport -> sendRequest ( $ body ) ; $ apiResponse = $ this -> serializer -> deserialize ( $ response , $ responseClass , 'json' ) ; if ( $ apiResponse -> getResponse ( ) !== null && $ apiResponse -> getResponse ( ) -> hasErrors ( ) ) { throw new ApiResponseException ( sprintf ( 'Error calling "%s"' , $ request -> getService ( ) ) , $ apiResponse -> getResponse ( ) -> getErrors ( ) ) ; } return $ apiResponse ; }
|
Send a request to fastbill .
|
55,569
|
public function resolveClauses ( array & $ parameters ) { $ parameters = array_merge ( $ parameters , $ this -> parameters ) ; $ filter = function ( $ clause ) use ( $ parameters ) { $ is_exist = true ; if ( preg_match_all ( '/@(?P<type>.):(?P<name>.+?)@/' , $ clause , $ match ) > 0 ) { foreach ( $ match [ 'name' ] as $ name ) { if ( ! ( $ is_exist = isset ( $ parameters [ $ name ] ) ) ) { break ; } } } return $ is_exist ; } ; $ clauses = [ true => array_filter ( $ this -> clauses [ true ] , $ filter ) , false => array_filter ( $ this -> clauses [ false ] , $ filter ) ] ; if ( count ( $ clauses [ true ] ) > 0 ) { $ snippet = $ this -> prefix . implode ( $ this -> joiner , array_merge ( $ clauses [ false ] , [ ' ( ' . implode ( ' OR ' , $ clauses [ true ] ) . ' ) ' ] ) ) . $ this -> postfix ; } elseif ( count ( $ clauses [ false ] ) > 0 ) { $ snippet = $ this -> prefix . implode ( $ this -> joiner , $ clauses [ false ] ) . $ this -> postfix ; } else { $ snippet = '' ; } return $ snippet ; }
|
Resolve clauses .
|
55,570
|
public function addClause ( $ sql , array $ parameters , $ is_inclusive ) { $ this -> clauses [ $ is_inclusive ] [ ] = $ sql ; $ this -> parameters = array_merge ( $ this -> parameters , $ parameters ) ; }
|
Add a clause to the list of clauses .
|
55,571
|
public function at ( $ head , ... $ tail ) { if ( '@' == $ head [ 0 ] ) $ head = $ this -> marks [ $ head ] ; return $ head . self :: DS . join ( self :: DS , $ tail ) ; }
|
get the path .
|
55,572
|
public function copy ( $ source , $ target ) { if ( '@' == $ source [ 0 ] ) $ source = $ this -> as ( $ source ) ; if ( '@' == $ target [ 0 ] ) $ target = $ this -> as ( $ target ) ; if ( is_file ( $ source ) ) return copy ( $ source , $ target ) ; $ handle = opendir ( $ source ) ; while ( false !== ( $ name = readdir ( $ handle ) ) ) { if ( '.' == $ name or '..' == $ name ) continue ; $ subsource = $ source . self :: DS . $ name ; $ subtarget = $ target . self :: DS . $ name ; if ( ! $ this -> copy ( $ subsource , $ subtarget ) ) return false ; } closedir ( $ handle ) ; return true ; }
|
copy file or directory .
|
55,573
|
public function remove ( $ path ) { if ( '@' == $ path [ 0 ] ) $ path = $ this -> as ( $ path ) ; if ( is_file ( $ path ) ) return unlink ( $ path ) ; $ handle = opendir ( $ path ) ; while ( false !== ( $ name = readdir ( $ handle ) ) ) { if ( '.' == $ name or '..' == $ name ) continue ; if ( ! $ this -> remove ( $ path . self :: DS . $ name ) ) return false ; } closedir ( $ handle ) ; return rmdir ( $ path ) ; }
|
remove file or directory .
|
55,574
|
public function fill ( array $ values ) { foreach ( $ values as $ key => $ value ) { callback ( $ this , 'fill' . ucfirst ( $ key ) ) -> invoke ( $ value ) ; } return $ this ; }
|
Calls fill method for each item .
|
55,575
|
private function checkTagNameAndAttributes ( Element $ element , $ shortcutId , $ expectedTagName , $ expectedAttribs ) { $ actualTagName = $ element -> name ( ) ; if ( isset ( $ expectedTagName ) && $ actualTagName !== $ expectedTagName ) { throw new ViewStateException ( __METHOD__ . ": Element '$shortcutId' is expected to be a tag '{$expectedTagName}', but is '$actualTagName'." ) ; } if ( isset ( $ expectedAttribs ) && is_array ( $ expectedAttribs ) ) { foreach ( $ expectedAttribs as $ attribName => $ expectedValue ) { $ actualValue = $ element -> attribute ( $ attribName ) ; if ( $ actualValue !== $ expectedValue ) { throw new ViewStateException ( __METHOD__ . ": Expected value of '$attribName' is '$expectedValue' on element '$shortcutId', actual value is '$actualValue'." ) ; } } } }
|
Checks element name and attributes .
|
55,576
|
private function getNextPageFromList ( $ possibleReturnTypes , $ definingClass ) { foreach ( $ possibleReturnTypes as $ returnType ) { if ( $ returnType { 0 } !== '\\' ) { $ absolutizedReturnType = '\\' . ClassType :: from ( $ definingClass ) -> getNamespaceName ( ) . '\\' . $ returnType ; $ returnType = class_exists ( $ absolutizedReturnType ) ? $ absolutizedReturnType : '\\' . $ returnType ; } if ( $ this instanceof $ returnType ) { $ nextPage = $ this ; } else { if ( ! is_subclass_of ( $ returnType , 'Se34\IPageComponent' ) ) { $ backtrace = debug_backtrace ( ) ; $ className = get_class ( $ this ) ; if ( $ backtrace [ 1 ] [ 'object' ] === $ this && $ backtrace [ 1 ] [ 'function' ] === '__call' ) { $ method = "magic method $className::{$backtrace[2]['function']}()" ; } else { $ method = "method $className::{$backtrace[1]['function']}()" ; } throw new \ UnexpectedValueException ( __METHOD__ . ": Return type of $method - '$returnType' - " . ( class_exists ( $ returnType ) ? 'is not an instance of IPageComponent.' : " doesn't exist." ) ) ; } $ nextPage = new $ returnType ( $ this -> session ) ; } try { $ nextPage -> checkState ( ) ; return $ nextPage ; } catch ( \ Se34 \ ViewStateException $ viewStateException ) { ; } } throw $ viewStateException ; }
|
This method can find out on which of named page object types we are .
|
55,577
|
public function toArray ( ) { return array ( 'age' => $ this -> getAge ( ) , 'quarter' => $ this -> getQuarter ( ) , 'day' => $ this -> getDay ( ) , 'month' => $ this -> getMonth ( ) , 'year' => $ this -> getYear ( ) , 'hour' => $ this -> getHour ( ) , 'minute' => $ this -> getMinute ( ) , 'second' => $ this -> getSecond ( ) , 'microsecond' => $ this -> getMicrosecond ( ) , 'timezone' => $ this -> getTimezone ( ) , 'timestamp' => $ this -> getTimestamp ( ) , 'milliTimestamp' => $ this -> getMilliTimestamp ( ) , 'dayOfWeek' => $ this -> getDayOfWeek ( ) , 'dayOfYear' => $ this -> getDayOfYear ( ) , 'week' => $ this -> getWeek ( ) , ) ; }
|
Returns an array representation of the object
|
55,578
|
public function finish ( Request $ request ) : Response { if ( $ this -> finished ) { throw new \ LogicException ( 'The response has already finished.' ) ; } $ this -> request = $ request ; $ this -> headers -> set ( 'content-length' , strlen ( $ this -> body ) ) ; $ this -> setEmptyResponse ( ) ; $ this -> writeHeaders ( ) ; $ this -> writeBody ( ) ; $ this -> finished = true ; return $ this ; }
|
Finish the response and return the object .
|
55,579
|
public function setBody ( $ body ) : Response { if ( is_null ( $ body ) || is_scalar ( $ body ) ) { $ this -> body = ( string ) $ body ; return $ this ; } $ prefix = 'Body must be null or scalar, ' ; $ suffix = gettype ( $ body ) . ' given.' ; throw new \ InvalidArgumentException ( "{$prefix}{$suffix}" ) ; }
|
Set the response body .
|
55,580
|
public function setHeader ( string $ key , $ value ) : Response { $ this -> headers -> set ( $ key , $ value ) ; return $ this ; }
|
Set a response header .
|
55,581
|
protected function setEmptyResponse ( ) { $ empty = in_array ( $ this -> status , static :: NO_BODY_STATUSES ) ; if ( $ this -> request -> isHead ( ) || $ empty ) { $ this -> body = null ; } if ( $ empty ) { $ this -> headers -> delete ( 'content-length' ) ; $ this -> headers -> delete ( 'content-type' ) ; } }
|
Set the correct behaviour for empty and no - body responses .
|
55,582
|
protected function writeHeaders ( ) { if ( headers_sent ( ) === false ) { $ status = static :: RESPONSE_STATUSES [ $ this -> status ] ; header ( "{$this->request->protocol} {$status}" ) ; foreach ( $ this -> headers -> all ( ) as $ key => $ value ) { header ( "{$key}: {$value}" , false ) ; } } }
|
Send response headers .
|
55,583
|
public function getRSmartLoad ( ) { if ( $ this -> _rSmartLoad === null ) { $ smartLoadClassName = $ this -> smartLoadConfig [ 'class' ] ; $ config = base \ Helper :: filterByKeys ( $ this -> smartLoadConfig , null , [ 'class' , 'disableNativeScriptFilter' ] ) ; $ this -> _rSmartLoad = new $ smartLoadClassName ( $ this , $ config ) ; } return $ this -> _rSmartLoad ; }
|
Returns RSmartLoad instance
|
55,584
|
public static function rewindEntityBody ( RequestInterface $ redirectRequest ) { if ( $ body = $ redirectRequest -> getBody ( ) ) { if ( $ body -> tell ( ) && ! $ body -> seek ( 0 ) ) { throw new CouldNotRewindStreamException ( 'Unable to rewind the non-seekable request body after redirecting' , $ redirectRequest ) ; } } }
|
Rewind the entity body of the request if needed
|
55,585
|
public function getRoute ( ) { $ route = substr ( $ this -> route , strlen ( $ this -> prefix ) ) ; if ( strlen ( $ route ) > 1 && $ route [ strlen ( $ route ) - 1 ] == '/' ) { $ route = substr ( $ route , 0 , strlen ( $ route ) - 1 ) ; } return $ route ; }
|
Gets the current route without prefix .
|
55,586
|
protected function parsevars ( array $ s ) { $ this -> method = strtoupper ( $ this -> arrayGet ( 'REQUEST_METHOD' , $ s ) ) ; $ this -> host = $ this -> arrayGet ( 'HTTP_HOST' , $ s ) ; $ this -> user_agent = $ this -> arrayGet ( 'HTTP_USER_AGENT' , $ s , false , false ) ; $ this -> accept = $ this -> arrayGet ( 'HTTP_ACCEPT' , $ s , true ) ; $ this -> languages = $ this -> arrayGet ( 'HTTP_ACCEPT_LANGUAGE' , $ s , true ) ; $ this -> encodings = $ this -> arrayGet ( 'HTTP_ACCEPT_ENCODING' , $ s , true ) ; $ this -> connection = $ this -> arrayGet ( 'HTTP_CONNECTION' , $ s ) ; $ this -> referer = $ this -> arrayGet ( 'HTTP_REFERER' , $ s ) ; $ this -> path = $ this -> arrayGet ( 'PATH' , $ s ) ; $ this -> software = $ this -> arrayGet ( 'SERVER_SOFTWARE' , $ s ) ; $ this -> name = $ this -> arrayGet ( 'SERVER_NAME' , $ s ) ; $ this -> address = $ this -> arrayGet ( 'SERVER_ADDR' , $ s ) ; $ this -> port = $ this -> arrayGet ( 'SERVER_PORT' , $ s ) ; $ this -> remote_addr = $ this -> arrayGet ( 'REMOTE_ADDR' , $ s ) ; $ this -> remote_port = $ this -> arrayGet ( 'REMOTE_PORT' , $ s ) ; $ this -> admin = $ this -> arrayGet ( 'SERVER_ADMIN' , $ s ) ; $ this -> filename = $ this -> arrayGet ( 'SCRIPT_FILENAME' , $ s ) ; $ this -> scriptname = $ this -> arrayGet ( 'SCRIPT_NAME' , $ s ) ; $ this -> uri = $ this -> arrayGet ( 'REQUEST_URI' , $ s ) ; $ this -> time = $ this -> arrayGet ( 'REQUEST_TIME' , $ s ) ; if ( $ this -> arrayGet ( 'HTTPS' , $ s ) || strtolower ( $ this -> arrayGet ( 'HTTP_X_FORWARDED_PROTO' , $ s ) ) == 'https' ) { $ this -> protocol = 'https' ; } else { $ this -> protocol = 'http' ; } $ this -> route = $ this -> uri ; $ get_id = strpos ( $ this -> route , '?' ) ; if ( $ get_id !== false ) { $ this -> route = substr ( $ this -> route , 0 , $ get_id ) ; } $ anchor_id = strpos ( $ this -> route , '#' ) ; if ( $ anchor_id !== false ) { $ this -> route = substr ( $ this -> route , 0 , $ anchor_id ) ; } }
|
Parses server variables into this class .
|
55,587
|
protected function arrayGet ( $ key , array $ array , $ split = false , $ clean = true ) { if ( isset ( $ array [ $ key ] ) ) { if ( $ split ) { if ( $ clean ) { $ data = explode ( ',' , $ this -> clean ( $ array [ $ key ] ) ) ; } else { $ data = explode ( ',' , $ array [ $ key ] ) ; } $ data = array_map ( function ( $ item ) { return trim ( $ item ) ; } , $ data ) ; return $ data ; } else { if ( $ clean ) { return $ this -> clean ( $ array [ $ key ] ) ; } else { return $ array [ $ key ] ; } } } else { return false ; } }
|
Gets checks and cleans an array entry . Avoids warnings and simplifies use .
|
55,588
|
protected function clean ( $ serverstring ) { $ scol_id = strpos ( $ serverstring , ';' ) ; if ( $ scol_id !== false ) { return substr ( $ serverstring , 0 , $ scol_id ) ; } else { return $ serverstring ; } }
|
Cleans up server entries .
|
55,589
|
public function getFullUploadStorePath ( $ model ) { $ path = strtr ( $ this -> fullUploadStoreDirPattern , [ "{uploadDir}" => $ this -> getUploadStorePath ( ) . '/' , "{logicPath}" => $ model -> getLogicPath ( ) , "{filename}" => $ model -> getHashFileName ( ) , ] ) ; return $ path ; }
|
return file store path by EntityFile model
|
55,590
|
public function getUploadPath ( $ isAbs = false , $ createMode = 0775 ) { if ( $ isAbs && isset ( $ this -> _data [ 'ABS_UPLOAD_PATH' ] ) ) { return $ this -> _data [ 'ABS_UPLOAD_PATH' ] ; } elseif ( ! $ isAbs && isset ( $ this -> _data [ 'REV_UPLOAD_PATH' ] ) ) { return $ this -> _data [ 'REV_UPLOAD_PATH' ] ; } $ path = Yii :: getAlias ( '@webroot' ) . '/' . $ this -> uploadFolderName ; if ( ! @ file_exists ( $ path ) ) { if ( ! @ mkdir ( $ path , $ createMode , true ) ) { throw new Exception ( "Cannot create dir: {$path}" ) ; } } $ this -> _data [ 'ABS_UPLOAD_PATH' ] = $ path ; $ this -> _data [ 'REV_UPLOAD_PATH' ] = Url :: to ( '@web/' . basename ( $ path ) ) ; return $ isAbs ? $ this -> _data [ 'ABS_UPLOAD_PATH' ] : $ this -> _data [ 'REV_UPLOAD_PATH' ] ; }
|
Return upload path
|
55,591
|
public function getCmsUploadTempPath ( $ isAbs = false , $ createMode = 0775 , $ model = null ) { return $ this -> getScalableUploadPath ( 'CmsTemp' , 'ABS_CMS_TEMP' , 'REV_CMS_TEMP' , $ isAbs , $ createMode , $ model ) ; }
|
return cms upload temporary folder
|
55,592
|
protected function getScalableUploadPath ( $ defaultName , $ absKey , $ revKey , $ isAbs = false , $ createMode = 0775 , $ model = null ) { if ( $ isAbs && isset ( $ this -> _data [ $ absKey ] ) ) { return $ this -> _data [ $ absKey ] ; } elseif ( ! $ isAbs && isset ( $ this -> _data [ $ revKey ] ) ) { return $ this -> _data [ $ revKey ] ; } $ folderName = ! is_null ( $ model ) ? $ model -> className ( ) : $ defaultName ; $ path = $ this -> getUploadPath ( true ) . '/' . $ folderName ; if ( ! @ file_exists ( $ path ) ) { if ( ! @ mkdir ( $ path , $ createMode , true ) ) { throw new Exception ( "Cannot create dir: {$path}" ) ; } } $ this -> _data [ $ absKey ] = $ path ; $ this -> _data [ $ revKey ] = Url :: to ( $ this -> getUploadPath ( ) . '/' . $ folderName ) ; return $ isAbs ? $ this -> _data [ $ absKey ] : $ this -> _data [ $ revKey ] ; }
|
get scalable folder under upload
|
55,593
|
public function load ( $ config = array ( ) ) { $ openid = new LightOpenID ( ) ; if ( ! empty ( $ config ) ) { foreach ( $ config as $ key => $ val ) { $ openid -> $ key = $ val ; } } return $ openid ; }
|
Main extension loader
|
55,594
|
private function setFormName ( ) : void { $ this -> key = 'form_' . $ this -> name . '_' . bin2hex ( random_bytes ( 16 ) ) ; if ( isset ( $ _SESSION [ $ this -> key ] ) ) { $ this -> setFormName ( ) ; } $ prev_form_keys = preg_grep ( '/^form_' . preg_quote ( $ this -> name , '/' ) . '_[a-f0-9]+$/' , array_keys ( $ _SESSION ) ) ; array_map ( function ( $ key ) { unset ( $ _SESSION [ $ key ] ) ; } , $ prev_form_keys ) ; $ _SESSION [ $ this -> key ] = [ ] ; }
|
Set the form name to save in session
|
55,595
|
public function getFieldKey ( string $ name ) : string { $ name = trim ( $ name ) ; $ key = array_search ( $ name , $ _SESSION [ $ this -> key ] ) ; if ( $ key === false ) { throw new \ LogicException ( 'Field ' . $ name . ' does not exist' ) ; } return $ key ; }
|
Get a generated field key
|
55,596
|
public function parse ( $ query , $ secret = null ) { $ secret = $ secret ? Secret :: create ( $ secret ) : $ this -> secret ; if ( null === $ secret ) { throw new \ RuntimeException ( 'Secret not set on instance, be sure to pass it on parse.' ) ; } $ query = is_array ( $ query ) ? new QueryString ( $ query ) : QueryString :: fromString ( $ query ) ; if ( ! $ query -> isValid ( $ secret ) ) { throw new \ RuntimeException ( 'Bad signature for payload.' ) ; } $ data = QueryString :: fromString ( base64_decode ( $ query [ 'sso' ] ) ) ; return new Payload ( $ data -> all ( ) + [ 'sso_secret' => $ secret ] ) ; }
|
Converts query string parameters into a Payload .
|
55,597
|
protected function getModelTpl ( $ modelClassName , $ tableName ) { $ modelTpl = str_replace ( CodeTpl :: CLASS_NAME_TAG , $ modelClassName , CodeTpl :: MODEL_TPL ) ; $ statement = Connection :: component ( ) -> read_conn -> prepare ( 'desc ' . $ tableName ) ; if ( $ result = $ statement -> execute ( ) ) { $ fields = $ statement -> fetchAll ( ) ; if ( ! $ fields ) { throw new ParamException ( ErrorMsg :: INVALID_PARAM ) ; } $ primaryKeyAttr = '' ; $ attributes = '' ; $ primaryKeyLabel = '' ; $ labels = '' ; $ primaryKey = '' ; $ primaryKeyComment = '' ; $ propertyComments = '' ; $ setter = '' ; $ getter = '' ; foreach ( $ fields as $ field ) { $ attrName = $ field [ 'Field' ] ; $ defaultValue = $ this -> formatValue ( $ field [ 'Default' ] , $ field [ 'Type' ] ) ; $ label = $ this -> formatLabel ( $ attrName ) ; $ commentType = $ this -> getCommentType ( $ field [ 'Type' ] ) ; $ camelAttrName = $ this -> formatAttr ( $ attrName ) ; $ setter .= <<<EOF public function set{$camelAttrName}(\$value) { \$this->{$attrName} = \$value; return \$this; }EOF ; $ setter .= ( str_repeat ( PHP_EOL , 2 ) ) ; $ getter .= <<<EOF public function get{$camelAttrName}() { return \$this->{$attrName}; }EOF ; $ getter .= ( str_repeat ( PHP_EOL , 2 ) ) ; if ( $ field [ 'Key' ] == 'PRI' ) { $ primaryKey = $ attrName ; $ primaryKeyAttr = <<<EOF '{$attrName}' => {$defaultValue},EOF ; $ primaryKeyAttr .= PHP_EOL ; $ primaryKeyLabel = <<<EOF '{$attrName}' => '{$label}',EOF ; $ primaryKeyLabel .= PHP_EOL ; $ primaryKeyComment = <<<EOF * @property {$commentType} \${$attrName}EOF ; $ primaryKeyComment .= PHP_EOL ; } else { $ attributes .= <<<EOF '{$attrName}' => {$defaultValue},EOF ; $ attributes .= PHP_EOL ; $ labels .= <<<EOF '{$attrName}' => '{$label}',EOF ; $ labels .= PHP_EOL ; $ propertyComments .= <<<EOF * @property {$commentType} \${$attrName}EOF ; $ propertyComments .= PHP_EOL ; } } $ modelTpl = str_replace ( CodeTpl :: ATTRIBUTES_TAG , rtrim ( $ primaryKeyAttr . $ attributes , PHP_EOL ) , $ modelTpl ) ; $ modelTpl = str_replace ( CodeTpl :: LABELS_TAG , rtrim ( $ primaryKeyLabel . $ labels , PHP_EOL ) , $ modelTpl ) ; $ modelTpl = str_replace ( CodeTpl :: PROPERTY_COMMENTS_TAG , rtrim ( $ primaryKeyComment . $ propertyComments , PHP_EOL ) , $ modelTpl ) ; $ modelTpl = str_replace ( CodeTpl :: PRIMARY_KEY_TAG , $ primaryKey , $ modelTpl ) ; $ modelTpl = str_replace ( CodeTpl :: SETTER , $ setter , $ modelTpl ) ; $ modelTpl = str_replace ( CodeTpl :: GETTER , rtrim ( $ getter , PHP_EOL ) , $ modelTpl ) ; } return str_replace ( CodeTpl :: TABLE_NAME_TAG , $ tableName , $ modelTpl ) ; }
|
Get model template
|
55,598
|
protected function formatLabel ( $ attrName ) { if ( strpos ( $ attrName , '_' ) !== false ) { $ tempArr = explode ( '_' , $ attrName ) ; foreach ( $ tempArr as $ key => $ item ) { $ tempArr [ $ key ] = ucfirst ( strtolower ( $ item ) ) ; } $ attrName = implode ( ' ' , $ tempArr ) ; } else { $ capitals = [ ] ; for ( $ i = 0 ; $ i < mb_strlen ( $ attrName , 'UTF8' ) ; ++ $ i ) { if ( StringHelper :: isCapital ( $ attrName [ $ i ] ) ) { $ capitals [ ] = $ attrName [ $ i ] ; } } foreach ( $ capitals as $ capital ) { $ attrName = str_replace ( $ capital , ' ' . $ capital , $ attrName ) ; } $ attrName = trim ( $ attrName ) ; } return $ attrName ; }
|
Format attribute label
|
55,599
|
protected function getCommentType ( $ propertyType ) { $ commentType = 'string' ; if ( stripos ( $ propertyType , 'int' ) !== false ) { $ commentType = 'integer' ; } else if ( stripos ( $ propertyType , 'float' ) !== false ) { $ commentType = 'float' ; } else if ( stripos ( $ propertyType , 'decimal' ) !== false ) { $ commentType = 'double' ; } return $ commentType ; }
|
Get comment property variable type
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.