idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
14,300
|
public function filter ( callable $ filter , callable $ controller ) { $ pattern = $ this -> getFrontController ( ) -> addController ( ':all' , $ controller ) -> getPattern ( ) ; $ pattern -> addFilter ( $ filter ) ; return new IRoutePatternSetterAdapter ( $ pattern ) ; }
|
Adds a controller with a special filter . This filter receive the current Request as first param .
|
14,301
|
public function mirror ( $ uriPattern , $ mirror ) { return $ this -> any ( $ uriPattern , function ( AppController $ appController , array $ args ) use ( $ mirror ) { return $ appController -> call ( $ mirror , $ args ) ; } ) ; }
|
Adds a mirror of a route .
|
14,302
|
public function pagination ( $ perPage = 15 ) { $ currentPageFinder = Paginator :: getCurrentPageFinder ( ) ; $ pathFinder = Paginator :: getRequestPathFinder ( ) ; $ pagination = new Paginator ( $ perPage , call_user_func ( $ currentPageFinder ) , [ 'pageName' => 'page' , 'path' => call_user_func ( $ pathFinder ) , ] ) ; $ pagination -> setMode ( Paginator :: MODE_STANDART ) ; $ count = $ this -> build ( ) -> rowCount ( ) ; $ pagination -> count ( $ count ) ; return $ pagination ; }
|
create a instance for standart pagination
|
14,303
|
public function simplePagination ( $ perPage = 15 ) { $ pegination = $ this -> pagination ( $ perPage ) ; $ pegination -> setMode ( Paginator :: MODE_SIMPLE ) ; return $ pegination ; }
|
create a paginaton instance and return it
|
14,304
|
public function guessFileType ( FileId $ fileId ) { $ extension = strtolower ( \ pathinfo ( $ fileId -> id ( ) , PATHINFO_EXTENSION ) ) ; foreach ( $ this -> fileTypeExtensions as $ fileType => $ extensions ) { if ( in_array ( $ extension , $ extensions ) ) { return $ fileType ; } } return 'file' ; }
|
Guess file type code
|
14,305
|
public function checkIpIsInRange ( $ ipGiven , $ ipStart , $ ipEnd ) { $ sReturn = 'out' ; $ startNo = $ this -> convertIpToNumber ( $ ipStart ) ; $ endNo = $ this -> convertIpToNumber ( $ ipEnd ) ; $ evaluatedNo = $ this -> convertIpToNumber ( $ ipGiven ) ; if ( $ sReturn == 'out' ) { if ( ( $ evaluatedNo >= $ startNo ) && ( $ evaluatedNo <= $ endNo ) ) { $ sReturn = 'in' ; } } return $ sReturn ; }
|
Determines if a given IP is with a defined range
|
14,306
|
public function checkIpIsPrivate ( $ ipGiven ) { if ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP ) ) { if ( ! filter_var ( $ ipGiven , FILTER_VALIDATE_IP , FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE ) ) { return 'private' ; } return 'public' ; } return 'invalid IP' ; }
|
Checks if given IP is a private or public one
|
14,307
|
public function checkIpIsV4OrV6 ( $ ipGiven ) { if ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP ) ) { if ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { return 'V4' ; } elseif ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { return 'V6' ; } } return 'invalid IP' ; }
|
Checks if given IP is a V4 or V6
|
14,308
|
public function convertIpToNumber ( $ ipGiven ) { if ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP ) ) { if ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { $ ips = explode ( '.' , $ ipGiven ) ; return $ ips [ 3 ] + $ ips [ 2 ] * 256 + $ ips [ 1 ] * 65536 + $ ips [ 0 ] * 16777216 ; } elseif ( filter_var ( $ ipGiven , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { return $ this -> convertIpV6ToNumber ( $ ipGiven ) ; } } return 'invalid IP' ; }
|
Converts IP to a number
|
14,309
|
public function bodyRequest ( $ forApi = false ) { $ json = file_get_contents ( 'php://input' ) ; $ data = json_decode ( $ json ) ; $ forApi ? $ requestWithBodyRequest = $ this -> getInteractionsRequestForApi ( ) : $ requestWithBodyRequest = $ this -> getInteractionsRequest ( ) ; foreach ( $ data as $ key => $ value ) $ requestWithBodyRequest -> $ key = $ value ; return $ requestWithBodyRequest ; }
|
Retorno del cuerpo de Request .
|
14,310
|
public function input ( $ input ) { if ( isset ( $ this -> inputs -> $ input ) ) return $ this -> inputs -> $ input ; return null ; }
|
Retorno de la variable enviada por el cliente .
|
14,311
|
public function header ( $ name ) { $ exists = isset ( $ this -> headers [ $ name ] ) ; return $ exists ? $ this -> headers [ $ name ] : array ( ) ; }
|
Returns a message header value by the given case - insensitive name .
|
14,312
|
public function getUrl ( string $ conversionName = '' ) : string { if ( $ this -> hasFile ( ) ) { return $ this -> getFile ( ) -> getUrl ( ) ; } return $ this -> getCollection ( ) -> getDefaultMediaUrl ( ) ; }
|
Get the url to a original media file .
|
14,313
|
public function createBootstrap ( $ secured = true ) { $ form = $ this -> create ( $ secured ) ; $ form -> setRenderer ( new Bootstrap3Renderer ( ) ) ; return $ form ; }
|
Create Form with Bootstrap styling
|
14,314
|
public function createBootstrapInline ( $ secured = true ) { $ form = $ this -> create ( $ secured ) ; $ form -> setRenderer ( new Bootstrap3InlineRenderer ( ) ) ; return $ form ; }
|
Create Form with inline Bootstrap styling
|
14,315
|
public function createBootstrapStacked ( $ secured = true ) { $ form = $ this -> create ( $ secured ) ; $ form -> setRenderer ( new Bootstrap3StackRenderer ( ) ) ; return $ form ; }
|
One column form where labels are placed to controls
|
14,316
|
public function oddKey ( array $ storage ) { return $ this -> filter ( $ storage , function ( $ value , $ key ) { return $ this -> helper -> math ( ) -> isOdd ( $ key ) ; } ) ; }
|
0 = > 2 = > ...
|
14,317
|
public function evenKey ( array $ storage ) { return $ this -> filter ( $ storage , function ( $ value , $ key ) { return $ this -> helper -> math ( ) -> isEven ( $ key ) ; } ) ; }
|
1 = > 3 = > ...
|
14,318
|
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ config = $ serviceLocator -> get ( 'Config' ) ; if ( ! isset ( $ config [ 'translator' ] ) ) { throw new Exception \ RuntimeException ( 'No translator config found.' ) ; } $ allOptions = $ config [ 'translator' ] ; foreach ( $ allOptions as $ module => $ options ) { if ( ! isset ( $ options [ 'content' ] ) && ! isset ( $ options [ 'data' ] ) ) { throw new Exception \ RuntimeException ( 'No translation source data provided.' ) ; } else if ( array_key_exists ( 'content' , $ options ) && array_key_exists ( 'data' , $ options ) ) { throw new Exception \ RuntimeException ( 'Conflict on translation source data: choose only one key between content and data.' ) ; } if ( empty ( $ options [ 'adapter' ] ) ) { $ options [ 'adapter' ] = Zend_Translate :: AN_ARRAY ; } if ( ! empty ( $ options [ 'data' ] ) ) { $ options [ 'content' ] = $ options [ 'data' ] ; unset ( $ options [ 'data' ] ) ; } if ( isset ( $ options [ 'options' ] ) ) { foreach ( $ options [ 'options' ] as $ key => $ value ) { $ options [ $ key ] = $ value ; } } if ( ! empty ( $ options [ 'cache' ] ) && is_string ( $ options [ 'cache' ] ) ) { $ cacheManager = $ serviceLocator -> get ( 'CacheManager' ) ; if ( $ cacheManager -> hasCache ( $ options [ 'cache' ] ) ) { $ options [ 'cache' ] = $ cacheManager -> getCache ( $ options [ 'cache' ] ) ; } } if ( $ this -> translator instanceof Zend_Translate_Adapter ) { $ this -> translator -> addTranslation ( $ options ) ; } else { $ translate = new Zend_Translate ( $ options ) ; $ this -> translator = $ translate -> getAdapter ( ) ; } } return $ this -> translator ; }
|
Create translator adapter
|
14,319
|
public static function isBeneathReal ( string $ child , string $ parent , string $ childDir = null , string $ parentDir = null ) { $ realChildPath = Filesystem :: resolveReal ( $ child , $ childDir ) ; $ realParentPath = Filesystem :: resolveReal ( $ parent , $ parentDir ) ; if ( $ realChildPath && $ realParentPath ) { return Directories :: isBeneath ( $ realChildPath , $ realParentPath ) ; } return false ; }
|
Determine if a real path is beneath another path .
|
14,320
|
protected function makeForm ( $ resource , $ class , $ model ) { $ form = $ this -> container -> make ( $ class ) ; if ( ! $ this -> formRules ( $ form ) && $ rules = $ this -> rules ( $ resource ) ) { $ form -> getValidator ( ) -> setRules ( $ rules ) ; } if ( $ model ) { $ form -> setModel ( $ model ) ; } $ this -> publish ( $ resource , 'form.created' , [ $ form ] ) ; return $ form ; }
|
Creates the form and fires an event
|
14,321
|
protected function makeSearchForm ( $ resource , $ class ) { $ form = $ this -> container -> make ( $ class ) ; $ this -> publish ( $ resource , 'search-form.created' , [ $ form ] ) ; $ form -> addCssClass ( 'search-form' ) ; return $ form ; }
|
Creates the search form and fires an event
|
14,322
|
protected function makeValidator ( $ resource , $ class ) { $ validator = $ this -> container -> make ( $ class ) ; if ( method_exists ( $ validator , 'setResourceName' ) ) { $ validator -> setResourceName ( $ resource ) ; } $ this -> publish ( $ resource , 'validator.created' , [ $ validator ] ) ; return $ validator ; }
|
Creates the validator and fires an event
|
14,323
|
protected function publish ( $ resource , $ event , array $ params = [ ] ) { $ eventName = $ this -> eventName ( "$resource.$event" ) ; $ this -> callOnListeners ( $ eventName , $ params ) ; }
|
Publishes an event on the event bus
|
14,324
|
public function add ( $ identifier , array $ configuration ) { $ presets = $ this -> loadPresets ( ) ; if ( ! empty ( $ presets [ $ identifier ] ) ) { throw new Exception ( 'Preset exists already' , 1410552459 ) ; } if ( empty ( $ configuration ) ) { throw new Exception ( 'Empty configuration is not allowed' , 1410595656 ) ; } $ presets [ $ identifier ] = $ configuration ; ksort ( $ presets ) ; $ this -> savePresets ( $ presets , 'Adds preset with identifier "' . $ identifier . '"' ) ; }
|
Adds a preset to this repository .
|
14,325
|
public function update ( $ identifier , array $ configuration ) { $ presets = $ this -> loadPresets ( ) ; if ( empty ( $ presets [ $ identifier ] ) ) { throw new Exception ( 'Could not find preset' , 1410552339 ) ; } if ( empty ( $ configuration ) ) { throw new Exception ( 'Empty configuration is not allowed' , 1410595612 ) ; } $ presets [ $ identifier ] = $ configuration ; $ this -> savePresets ( $ presets , 'Updates preset with identifier "' . $ identifier . '"' ) ; }
|
Updates a given preset .
|
14,326
|
public function remove ( $ identifier ) { $ presets = $ this -> loadPresets ( ) ; if ( empty ( $ presets [ $ identifier ] ) ) { throw new Exception ( 'Could not find preset' , 1410549993 ) ; } unset ( $ presets [ $ identifier ] ) ; $ this -> savePresets ( $ presets , 'Removes preset with identifier "' . $ identifier . '"' ) ; }
|
Removes a preset from this repository .
|
14,327
|
public function findByIdentifier ( $ identifier ) { $ presets = $ this -> loadPresets ( ) ; if ( empty ( $ presets [ $ identifier ] ) ) { throw new Exception ( 'Could not find preset' , 1410549868 ) ; } return $ presets [ $ identifier ] ; }
|
Finds a preset matching the given identifier .
|
14,328
|
public function findByRepositoryUrl ( $ repositoryUrl ) { $ presets = $ this -> loadPresets ( ) ; $ repositoryPresets = [ ] ; foreach ( $ presets as $ key => $ preset ) { foreach ( $ preset [ 'applications' ] as $ application ) { if ( ! empty ( $ application [ 'options' ] [ 'repositoryUrl' ] ) && $ repositoryUrl === $ application [ 'options' ] [ 'repositoryUrl' ] ) { $ repositoryPresets [ $ key ] = $ preset ; } } } return $ repositoryPresets ; }
|
Find presets matching the given repositoryUrl .
|
14,329
|
public function findGlobals ( ) { $ presets = $ this -> loadPresets ( ) ; $ globalPresets = [ ] ; foreach ( $ presets as $ key => $ preset ) { foreach ( $ preset [ 'applications' ] as $ application ) { if ( empty ( $ application [ 'options' ] [ 'repositoryUrl' ] ) ) { $ globalPresets [ $ key ] = $ preset ; } } } return $ globalPresets ; }
|
Finds all presets without a repositoryUrl .
|
14,330
|
public function getGroup ( ) { if ( $ this -> group === null ) { $ this -> setGroup ( $ this -> groupRepository -> getByClass ( $ this ) ) ; } return $ this -> group ; }
|
Get Group .
|
14,331
|
public static function get_active_route_name ( $ match , $ active = 'active' ) { $ route_name = Route :: currentRouteName ( ) ; return ( strcasecmp ( static :: get_base_route_name ( $ route_name ) , $ match ) == 0 ) ? $ active : '' ; }
|
Check if route name is the same as the current url and returns active state
|
14,332
|
public function encrypt ( $ data , $ key ) { $ this -> validateData ( $ data ) ; $ this -> validateKey ( $ key ) ; $ iv = openssl_random_pseudo_bytes ( openssl_cipher_iv_length ( self :: CIPHER_METHOD ) ) ; $ encrypted = openssl_encrypt ( $ data , self :: CIPHER_METHOD , $ key , 0 , $ iv ) ; $ encoded = base64_encode ( $ encrypted . self :: ENCRYPTED_IV_SEPERATOR . $ iv ) ; return new Encrypted ( $ encoded ) ; }
|
Encrypt data by key
|
14,333
|
public function decrypt ( $ data , $ key ) : string { $ this -> validateData ( $ data ) ; $ this -> validateKey ( $ key ) ; if ( empty ( $ data ) ) { return '' ; } list ( $ encrypted , $ iv ) = explode ( self :: ENCRYPTED_IV_SEPERATOR , base64_decode ( $ data ) , 2 ) ; return openssl_decrypt ( $ encrypted , self :: CIPHER_METHOD , $ key , 0 , $ iv ) ; }
|
Decrypt data by key
|
14,334
|
private function validateKey ( $ key ) : bool { if ( ! hash_equals ( $ this -> appKey , $ key ) ) { throw new \ Nuki \ Exceptions \ Base ( 'Used key does not equal the known application key' ) ; } return true ; }
|
Validate the crypter application key against the used key
|
14,335
|
public function getSignature ( $ domain , $ user ) { $ url = self :: BASE_URL . "{$domain}/{$user}/signature" ; $ request = new \ Google_Http_Request ( $ url , 'GET' , null , null ) ; $ httpRequest = $ this -> helper -> getClient ( ) -> getAuth ( ) -> authenticatedRequest ( $ request ) ; if ( $ httpRequest -> getResponseHttpCode ( ) == 200 ) { $ xmlResponse = new \ SimpleXMLElement ( $ httpRequest -> getResponseBody ( ) , 0 , false , 'apps' , true ) ; return ( string ) $ xmlResponse -> children ( 'apps' , true ) -> attributes ( ) -> value ; } else { return null ; } }
|
Get a Users email signature
|
14,336
|
public function setSignature ( $ domain , $ user , $ signature ) { $ url = self :: BASE_URL . "{$domain}/{$user}/signature" ; $ request = <<<XML<?xml version="1.0" encoding="utf-8"?><atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006"> <apps:property name="signature" value="{$signature}" /></atom:entry>XML ; $ request = new \ Google_Http_Request ( $ url , 'PUT' , array ( 'Content-Type' => 'application/atom+xml' ) , $ request ) ; $ httpRequest = $ this -> helper -> getClient ( ) -> getAuth ( ) -> authenticatedRequest ( $ request ) ; return ( $ httpRequest -> getResponseHttpCode ( ) == 200 ) ; }
|
Set a Users email signature
|
14,337
|
public function setSendAsAlias ( $ domain , $ user , $ name , $ address , $ replyTo = null , $ makeDefault = false ) { $ url = self :: BASE_URL . "{$domain}/{$user}/sendas" ; $ request = <<<XML<?xml version="1.0" encoding="utf-8"?><atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006"> <apps:property name="name" value="{$name}" /> <apps:property name="address" value="{$address}" />XML ; if ( $ replyTo !== null ) { $ request .= "<apps:property name=\"replyTo\" value=\"{$replyTo}\" />" ; } if ( $ makeDefault ) { $ request .= "<apps:property name=\"makeDefault\" value=\"true\" />" ; } $ request .= "</atom:entry>" ; $ request = new \ Google_Http_Request ( $ url , 'POST' , array ( 'Content-Type' => 'application/atom+xml' ) , $ request ) ; $ httpRequest = $ this -> helper -> getClient ( ) -> getAuth ( ) -> authenticatedRequest ( $ request ) ; return ( $ httpRequest -> getResponseHttpCode ( ) == 201 ) ; }
|
Add a Send - as Alias
|
14,338
|
public function setAdapter ( \ Desarrolla2 \ Cache \ Adapter \ AdapterInterface $ adapter ) { return $ this -> _instance -> setAdapter ( $ adapter ) ; }
|
Set Adapter interface
|
14,339
|
public static function getLog ( $ empty = false ) { $ log = self :: $ log ; if ( $ empty ) { self :: emptyLog ( ) ; } return $ log ; }
|
Returns all log entries and optionally removes them
|
14,340
|
protected function truncate ( $ table ) { if ( $ this -> db -> connection ( ) -> getConfig ( 'driver' ) === 'mysql' ) { $ this -> db -> statement ( 'SET FOREIGN_KEY_CHECKS=0;' ) ; $ this -> db -> table ( $ table ) -> truncate ( ) ; $ this -> db -> statement ( 'SET FOREIGN_KEY_CHECKS=1;' ) ; } }
|
Truncate the existing table of all records .
|
14,341
|
protected function getQueryItems ( ) { $ result = parent :: getQueryItems ( ) ; $ asAccCred = self :: AS_ACC_CREDIT ; $ asAccDeb = self :: AS_ACC_DEBIT ; $ asDwnlCred = self :: AS_DWNL_CRED ; $ asDwnlDeb = self :: AS_DWNL_DEB ; $ tbl = $ this -> resource -> getTableName ( self :: E_DWNL_CUST ) ; $ as = $ asDwnlDeb ; $ cols = [ self :: A_MLM_ID_DEBIT => EDownline :: A_MLM_ID ] ; $ cond = "$as." . EDownline :: A_CUSTOMER_REF . '=' . $ asAccDeb . '.' . EAccount :: A_CUST_ID ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; $ tbl = $ this -> resource -> getTableName ( self :: E_DWNL_CUST ) ; $ as = $ asDwnlCred ; $ cols = [ self :: A_MLM_ID_CREDIT => EDownline :: A_MLM_ID ] ; $ cond = "$as." . EDownline :: A_CUSTOMER_REF . '=' . $ asAccCred . '.' . EAccount :: A_CUST_ID ; $ result -> joinLeft ( [ $ as => $ tbl ] , $ cond , $ cols ) ; return $ result ; }
|
SELECT ... FROM prxgt_acc_transaction AS pat LEFT JOIN prxgt_acc_account AS paa_db ON paa_db . id = pat . debit_acc_id LEFT JOIN customer_entity AS ce_db ON ce_db . entity_id = paa_db . customer_id LEFT JOIN prxgt_acc_account AS paa_cr ON paa_cr . id = pat . credit_acc_id LEFT JOIN customer_entity AS ce_cr ON ce_cr . entity_id = paa_cr . customer_id LEFT JOIN prxgt_acc_type_asset AS pata ON pata . id = paa_db . asset_type_id LEFT JOIN prxgt_dwnl_customer AS dwnlDebit ON dwnlDebit . customer_ref = paa_db . customer_id LEFT JOIN prxgt_dwnl_customer AS dwnlCredit ON dwnlCredit . customer_ref = paa_cr . customer_id
|
14,342
|
protected function newSession ( Request $ request ) { $ factory = $ this -> sessionFactory ; $ cookie = $ request -> getCookieParams ( ) ; return $ factory -> newInstance ( $ cookie ) ; }
|
Create new session
|
14,343
|
public static function getLocalIP ( ) { $ s = & $ _SERVER ; $ ipAddress = $ s [ 'REMOTE_ADDR' ] ; if ( array_key_exists ( 'HTTP_X_FORWARDED_FOR' , $ s ) ) { $ temp = explode ( ',' , $ s [ 'HTTP_X_FORWARDED_FOR' ] ) ; $ ipAddress = array_pop ( $ temp ) ; } $ result = $ ipAddress == '::1' ? "127.0.0.1" : $ ipAddress ; return $ result ; }
|
Get local IP
|
14,344
|
public static function isSecure ( ) { $ s = & $ _SERVER ; $ ssl = ( ! empty ( $ s [ 'HTTPS' ] ) && $ s [ 'HTTPS' ] == 'on' ) ? true : false ; return $ ssl ; }
|
Evaluate the Safety Scope of Application .
|
14,345
|
public static function getBasicPath ( ) { $ s = & $ _SERVER ; $ ssl = ( ! empty ( $ s [ 'HTTPS' ] ) && $ s [ 'HTTPS' ] == 'on' ) ? true : false ; $ sp = strtolower ( $ s [ 'SERVER_PROTOCOL' ] ) ; $ protocol = substr ( $ sp , 0 , strpos ( $ sp , '/' ) ) . ( ( $ ssl ) ? 's' : '' ) ; $ port = $ s [ 'SERVER_PORT' ] ; $ port = ( ( ! $ ssl && $ port == '80' ) || ( $ ssl && $ port == '443' ) ) ? '' : ':' . $ port ; $ host = isset ( $ s [ 'HTTP_X_FORWARDED_HOST' ] ) ? $ s [ 'HTTP_X_FORWARDED_HOST' ] : ( isset ( $ s [ 'HTTP_HOST' ] ) ? $ s [ 'HTTP_HOST' ] : null ) ; $ host = isset ( $ host ) ? $ host : $ s [ 'SERVER_NAME' ] . $ port ; $ uri = $ protocol . '://' . $ host ; return $ uri ; }
|
Get basic path
|
14,346
|
public function killWww ( ) { $ host = $ _SERVER [ 'SERVER_NAME' ] ; if ( stripos ( $ host , 'www.' ) === 0 ) { $ host = substr_replace ( $ host , '' , 0 , 4 ) ; $ uri = $ _SERVER [ 'REQUEST_URI' ] ; header ( "HTTP/1.1 301 Moved Permanently" ) ; if ( '/' == $ uri [ 0 ] ) { header ( 'Location: http://' . $ host . $ uri ) ; } else { header ( 'Location: http://' . $ host . '/' . $ uri ) ; } die ; } return $ this ; }
|
Redirect from www . hostname to hostname
|
14,347
|
public static function resolve ( $ key ) { if ( strpos ( $ key , '\\' ) !== false ) return static :: resolveClass ( $ key ) ; $ key = explode ( '.' , $ key ) ; if ( $ resolver = static :: getResolver ( $ key [ 0 ] ) ) return $ resolver -> resolve ( $ key [ 0 ] , implode ( '.' , array_slice ( $ key , 1 ) ) ) ; return null ; }
|
Attempts to locate a instance or value from the registered resolvers .
|
14,348
|
public static function resolveClass ( $ class , $ buildOnFailure = false , $ parameters = [ ] ) { if ( ! is_string ( $ class ) ) throw new ResolverException ( "Class must be a string" ) ; if ( $ class == Framework :: class ) return Framework :: fw ( ) ; if ( $ class == Configuration :: class ) return Framework :: config ( ) ; if ( $ class == Logger :: class ) return Framework :: log ( ) ; foreach ( static :: $ resolvers as $ resolver ) if ( false !== ( $ result = $ resolver -> resolveClass ( $ class ) ) ) return $ result ; if ( $ buildOnFailure ) return static :: buildClass ( $ class , $ parameters ) ; return null ; }
|
Attempts to locate a class within the registered resolvers . Optionally will build the class on failure .
|
14,349
|
public static function buildClass ( $ class , array $ parameters = [ ] ) { if ( ! is_string ( $ class ) ) throw new BindingException ( "Class must be a string" ) ; if ( static :: building ( $ class ) ) throw new BindingException ( "The class [" . $ class . "] is already being built." ) ; static :: $ buildStack [ ] = $ class ; try { $ reflector = new \ ReflectionClass ( $ class ) ; if ( ! $ reflector -> isInstantiable ( ) ) throw new BindingException ( "Target [$class] is not instantiable." ) ; $ constructor = $ reflector -> getConstructor ( ) ; if ( is_null ( $ constructor ) ) return new $ class ; $ dependencies = $ constructor -> getParameters ( ) ; $ parameters = static :: keyParametersByArgument ( $ dependencies , $ parameters ) ; $ instances = static :: getDependencies ( $ dependencies , $ parameters , $ class ) ; array_pop ( static :: $ buildStack ) ; return $ reflector -> newInstanceArgs ( $ instances ) ; } catch ( \ ReflectionException $ e ) { array_pop ( static :: $ buildStack ) ; throw new BindingException ( "Failed to build [$class]: " . $ e -> getMessage ( ) . " in " . $ e -> getFile ( ) . " on line " . $ e -> getLine ( ) ) ; } }
|
Attempts to construct a class
|
14,350
|
protected function _normalizeMethodCallable ( $ callable ) { if ( is_object ( $ callable ) && is_callable ( $ callable ) ) { return array ( $ callable , '__invoke' ) ; } $ amtPartsRequired = 2 ; $ origCallable = $ callable ; try { $ callable = $ this -> _normalizeString ( $ callable ) ; $ callable = explode ( '::' , $ callable , $ amtPartsRequired ) ; } catch ( InvalidArgumentException $ e ) { } $ callable = $ this -> _normalizeArray ( $ callable ) ; $ callable = array_slice ( $ callable , 0 , $ amtPartsRequired ) ; if ( count ( $ callable ) !== $ amtPartsRequired ) { throw $ this -> _createOutOfRangeException ( $ this -> __ ( 'The callable must have at least %1$s parts' , array ( $ amtPartsRequired ) ) , null , null , $ origCallable ) ; } if ( ! is_string ( $ callable [ 0 ] ) && ! is_object ( $ callable [ 0 ] ) ) { throw $ this -> _createOutOfRangeException ( $ this -> __ ( 'The first part must be an object or a string' ) , null , null , $ origCallable ) ; } try { $ callable [ 1 ] = $ this -> _normalizeString ( $ callable [ 1 ] ) ; } catch ( InvalidArgumentException $ e ) { throw $ this -> _createOutOfRangeException ( $ this -> __ ( 'The second part must be a string or stringable' ) , null , $ e , $ origCallable ) ; } return $ callable ; }
|
Normalizes a method representation into a format recognizable by PHP as callable .
|
14,351
|
final public function open ( $ url = null , array $ paramaters = array ( ) , $ replace = false , $ name = '_blank' ) { $ specs = [ 'height' => 500 , 'width' => 500 , 'top' => 0 , 'left' => 0 , 'resizable' => 1 , 'titlebar' => 0 , 'menubar' => 0 , 'toolbar' => 0 , 'status' => 0 ] ; $ specs = array_merge ( $ specs , $ paramaters ) ; $ this -> response [ 'open' ] = [ 'url' => $ url , 'name' => $ name , 'specs' => $ specs , 'replace' => $ replace ] ; return $ this ; }
|
Open a popup using JavaScript
|
14,352
|
final public function animate ( $ sel , Array $ keyframes , Array $ opts ) { if ( ! array_key_exists ( 'animate' , $ this -> response ) ) { $ this -> response [ 'animate' ] = [ ] ; } $ this -> response [ 'animate' ] [ $ sel ] = [ 'keyframes' => $ keyframes , 'opts' => $ opts ] ; return $ this ; }
|
Add animations using Element . animate
|
14,353
|
final protected function consoleSetter ( $ method = 'log' , array $ value = array ( ) ) { if ( array_key_exists ( $ method , $ this -> response ) ) { if ( ! is_array ( $ this -> response [ $ method ] ) ) { $ this -> response [ $ method ] = [ $ this -> response [ $ method ] ] ; } $ this -> response [ $ method ] [ ] = count ( $ value ) === 1 ? current ( $ value ) : $ value ; } else { $ this -> response [ $ method ] = count ( $ value ) == 1 ? current ( $ value ) : $ value ; } return $ this ; }
|
Private method for setting console values which can contain one or more values . I . E . log could take a singe argument and then be called again later . For console methods set here to make it easier to call multiple times .
|
14,354
|
public static function withLanguage ( \ Closure $ callback , $ config = [ ] ) { if ( \ App :: runningUnitTests ( ) ) { $ locale = \ App :: getLocale ( ) ; } else { $ locale = request ( ) -> segment ( 1 ) ; } if ( strlen ( $ locale ) <= 2 ) { Route :: group ( [ 'prefix' => $ locale , 'middleware' => 'lang' ] , function ( ) use ( $ callback ) { $ callback ( ) ; } ) ; } }
|
Wraps routes with language prefix
|
14,355
|
protected function getIdentifier ( $ object ) { $ property = new ReflectionProperty ( get_class ( $ object ) , $ this -> getPrimaryKey ( ) ) ; $ property -> setAccessible ( true ) ; return $ property -> getValue ( $ object ) ; }
|
check if object has already an identifier
|
14,356
|
public function send ( MailMessage $ message ) { $ this -> headers -> add ( new Header ( 'From' , $ message -> getFrom ( ) ) ) ; $ this -> mailer -> send ( $ message , $ this -> headers ) ; }
|
Tries to deliver the mail
|
14,357
|
private function parseAttachments ( array $ files , string $ message , string $ contentType , string $ hash ) : string { $ result = [ ] ; $ result [ ] = '--body-mixed-' . $ hash ; $ result [ ] = new Header ( 'Content-Type' , $ contentType ) ; $ result [ ] = '' ; $ result [ ] = $ message ; foreach ( $ files as $ file ) { $ headers = new Headers ( ) ; $ headers -> add ( new Header ( 'Content-Transfer-Encoding' , 'base64' ) ) ; $ headers -> add ( new Header ( 'Content-Disposition' , 'attachment' ) ) ; $ headers -> add ( new Header ( 'Content-Type' , 'application/octet-stream' , [ 'filename' => $ file -> getFilename ( ) ] ) ) ; $ result [ ] = '--body-mixed-' . $ hash ; $ result [ ] = $ headers ; $ result [ ] = '' ; $ result [ ] = base64_encode ( $ file -> fread ( $ file -> getSize ( ) ) ) ; } return implode ( "\r\n" , $ result ) ; }
|
This will return a message body with the attachments in basecode64 encoding also the original message will be included
|
14,358
|
protected function addMixedTypeValidators ( $ targetClassName , GenericObjectValidator $ validator ) { foreach ( $ this -> reflectionService -> getClassPropertyNames ( $ targetClassName ) as $ property ) { if ( $ this -> propertyHasObjectValidator ( $ validator , $ property ) ) { continue ; } if ( $ this -> propertyIsMixedType ( $ targetClassName , $ property ) ) { $ objectValidator = $ this -> createValidator ( MixedTypeValidator :: class ) ; $ validator -> addPropertyValidator ( $ property , $ objectValidator ) ; } } }
|
This function will list the properties of the given class and filter on the ones that do not have a validator assigned yet .
|
14,359
|
protected function propertyIsMixedType ( $ className , $ property ) { $ mixedType = false ; $ propertySchema = $ this -> reflectionService -> getClassSchema ( $ className ) -> getProperty ( $ property ) ; if ( $ this -> classIsMixedType ( $ propertySchema [ 'type' ] ) ) { $ mixedType = true ; } else { if ( $ this -> reflectionService -> isPropertyTaggedWith ( $ className , $ property , MixedTypesService :: PROPERTY_ANNOTATION_MIXED_TYPE ) ) { $ tags = $ this -> reflectionService -> getPropertyTagValues ( $ className , $ property , MixedTypesService :: PROPERTY_ANNOTATION_MIXED_TYPE ) ; $ mixedTypeClassName = reset ( $ tags ) ; if ( $ this -> classIsMixedType ( $ mixedTypeClassName ) ) { $ mixedType = true ; } } } return $ mixedType ; }
|
Checks if the given property is a mixed type .
|
14,360
|
public function getHeaderContent ( ) { if ( ! $ this -> headerFileHandle ) { return null ; } fseek ( $ this -> headerFileHandle , 0 ) ; $ lines = array ( ) ; while ( $ line = trim ( fgets ( $ this -> headerFileHandle ) , "\n\r" ) ) { $ lines [ ] = $ line ; } return $ lines ; }
|
Get the content of the header output if enabled with enabledHeaderOutput .
|
14,361
|
public function getVerboseContent ( ) { if ( ! $ this -> verboseFileHandle ) { return null ; } fseek ( $ this -> verboseFileHandle , 0 ) ; $ lines = array ( ) ; while ( $ line = trim ( fgets ( $ this -> verboseFileHandle ) , "\n\r" ) ) { $ lines [ ] = $ line ; } return $ lines ; }
|
Get the content of the verbose output if enabled with enableVerboseOutput .
|
14,362
|
public function enableVerboseOutput ( ) { $ this -> verboseFileHandle = tmpfile ( ) ; $ this -> setOpt ( CURLOPT_VERBOSE , true ) ; $ this -> setOpt ( CURLOPT_STDERR , $ this -> verboseFileHandle ) ; }
|
Set all future requests of this instance to verbose mode .
|
14,363
|
public static function getSubject ( ) { $ logger = $ GLOBALS [ 'logger' ] ; $ app = $ GLOBALS [ 'app' ] ; $ subject = $ app -> getSubject ( ) ; $ logger -> debug ( 'Subject authentication status = ' . $ subject -> isAuthenticated ( ) ) ; if ( $ subject === null ) { $ subject = Subject :: createBuilder ( ) -> build ( ) ; $ app -> setSubject ( $ subject ) ; } return $ subject ; }
|
getSubject Convienience method to retrieve the subject . Subject is always retrieved from applicationContext . If no subject is found then a new subject is created with default properties .
|
14,364
|
public function table ( $ table , string $ alias = null ) : self { $ table = $ this -> checkStringValue ( 'Argument $table' , $ table ) ; $ this -> table = $ table ; $ this -> tableAlias = $ alias ; return $ this ; }
|
Sets the target table .
|
14,365
|
public function getTableIdentifier ( ) { if ( $ this -> tableAlias !== null ) { return $ this -> tableAlias ; } if ( is_string ( $ this -> table ) ) { return $ this -> table ; } return null ; }
|
Returns the identifier which the target table can be appealed to .
|
14,366
|
public function addUpdate ( array $ values ) : self { foreach ( $ values as $ column => $ value ) { if ( ! is_string ( $ column ) ) { return $ this -> handleException ( InvalidArgumentException :: create ( 'Argument $values indexes' , $ column , [ 'string' ] ) ) ; } $ value = $ this -> checkScalarOrNullValue ( 'Argument $values[' . $ column . ']' , $ value ) ; $ this -> update [ $ column ] = $ value ; } return $ this ; }
|
Adds values that should be updated
|
14,367
|
public function makeEmptyCopy ( ) : self { $ query = $ this -> constructEmptyCopy ( ) ; $ query -> setClosureResolver ( $ this -> closureResolver ) ; return $ query ; }
|
Makes an empty self copy with dependencies .
|
14,368
|
public function makeCopyForCriteriaGroup ( ) : self { $ query = $ this -> makeEmptyCopy ( ) ; $ query -> table = $ this -> table ; $ query -> tableAlias = $ this -> tableAlias ; return $ query ; }
|
Makes a self copy with dependencies for passing to a criteria group callback .
|
14,369
|
public function apply ( callable $ transform ) : self { $ result = $ transform ( $ this ) ?? $ this ; if ( $ result instanceof self ) { return $ result ; } return $ this -> handleException ( InvalidReturnValueException :: create ( 'The transform function return value' , $ result , [ 'null' , self :: class ] ) ) ; }
|
Modifies this query by passing it through a transform function .
|
14,370
|
protected function checkStringValue ( string $ name , $ value ) { if ( ! is_string ( $ value ) && ! ( $ value instanceof \ Closure ) && ! ( $ value instanceof self ) && ! ( $ value instanceof StatementInterface ) ) { return $ this -> handleException ( InvalidArgumentException :: create ( $ name , $ value , [ 'string' , \ Closure :: class , self :: class , StatementInterface :: class ] ) ) ; } if ( $ value instanceof \ Closure ) { return $ this -> resolveSubQueryClosure ( $ value ) ; } return $ value ; }
|
Check that value is suitable for being a string or subquery property of a query . Retrieves the closure subquery .
|
14,371
|
protected function checkIntOrNullValue ( string $ name , $ value ) { if ( $ value !== null && ! is_numeric ( $ value ) && ! ( $ value instanceof \ Closure ) && ! ( $ value instanceof self ) && ! ( $ value instanceof StatementInterface ) ) { return $ this -> handleException ( InvalidArgumentException :: create ( $ name , $ value , [ 'integer' , \ Closure :: class , self :: class , StatementInterface :: class , 'null' ] ) ) ; } if ( is_numeric ( $ value ) ) { $ value = ( int ) $ value ; } elseif ( $ value instanceof \ Closure ) { return $ this -> resolveSubQueryClosure ( $ value ) ; } return $ value ; }
|
Check that value is suitable for being a int or null or subquery property of a query . Retrieves the closure subquery .
|
14,372
|
protected function checkScalarOrNullValue ( string $ name , $ value ) { if ( $ value !== null && ! is_scalar ( $ value ) && ! ( $ value instanceof \ Closure ) && ! ( $ value instanceof self ) && ! ( $ value instanceof StatementInterface ) ) { return $ this -> handleException ( InvalidArgumentException :: create ( $ name , $ value , [ 'scalar' , \ Closure :: class , self :: class , StatementInterface :: class , 'null' ] ) ) ; } if ( $ value instanceof \ Closure ) { return $ this -> resolveSubQueryClosure ( $ value ) ; } return $ value ; }
|
Check that value is suitable for being a scalar or null or subquery property of a query . Retrieves the closure subquery .
|
14,373
|
protected function checkSubQueryValue ( string $ name , $ value ) { if ( ! ( $ value instanceof \ Closure ) && ! ( $ value instanceof self ) && ! ( $ value instanceof StatementInterface ) ) { return $ this -> handleException ( InvalidArgumentException :: create ( $ name , $ value , [ \ Closure :: class , self :: class , StatementInterface :: class ] ) ) ; } if ( $ value instanceof \ Closure ) { $ value = $ this -> resolveSubQueryClosure ( $ value ) ; } return $ value ; }
|
Check that value is suitable for being a subquery property of a query . Retrieves the closure subquery .
|
14,374
|
protected function _createReflectionForCallable ( $ callable ) { $ callable = $ this -> _normalizeCallable ( $ callable ) ; if ( is_string ( $ callable ) || ( $ callable instanceof Closure ) ) { return $ this -> _createReflectionFunction ( $ callable ) ; } $ object = $ callable [ 0 ] ; $ class = is_string ( $ object ) ? $ object : get_class ( $ object ) ; $ method = $ callable [ 1 ] ; return $ this -> _createReflectionMethod ( $ class , $ method ) ; }
|
Creates a reflection for the given callable .
|
14,375
|
public function addMultiple ( array $ items ) { foreach ( $ items as $ item ) { if ( $ item instanceof RequestException ) { $ this -> addException ( $ item ) ; } else { $ this -> addResponse ( $ item ) ; } } }
|
Add multiple items to the queue
|
14,376
|
private static function getParamsArray ( $ paramObj ) { $ parameters = array ( ) ; foreach ( $ paramObj as $ val ) { $ parameters [ $ val -> getName ( ) ] = $ val -> getValue ( ) ; } return $ parameters ; }
|
Get query params list
|
14,377
|
public static function getFullSQL ( $ query ) { $ sql = $ query -> getSql ( ) ; $ paramsList = self :: getListParamsByDql ( $ query -> getDql ( ) ) ; $ paramsArr = self :: getParamsArray ( $ query -> getParameters ( ) ) ; $ fullSql = '' ; for ( $ i = 0 ; $ i < strlen ( $ sql ) ; $ i ++ ) { if ( $ sql [ $ i ] == '?' ) { $ nameParam = array_shift ( $ paramsList ) ; if ( ! isset ( $ paramsArr [ $ nameParam ] ) ) { $ fullSql .= ':' . $ nameParam ; } elseif ( is_string ( $ paramsArr [ $ nameParam ] ) ) { $ fullSql .= '"' . addslashes ( $ paramsArr [ $ nameParam ] ) . '"' ; } elseif ( is_array ( $ paramsArr [ $ nameParam ] ) ) { $ sqlArr = '' ; foreach ( $ paramsArr [ $ nameParam ] as $ var ) { if ( ! empty ( $ sqlArr ) ) $ sqlArr .= ',' ; if ( is_string ( $ var ) ) { $ sqlArr .= '"' . addslashes ( $ var ) . '"' ; } else $ sqlArr .= $ var ; } $ fullSql .= $ sqlArr ; } elseif ( is_object ( $ paramsArr [ $ nameParam ] ) ) { switch ( get_class ( $ paramsArr [ $ nameParam ] ) ) { case 'DateTime' : $ fullSql .= '\'' . $ paramsArr [ $ nameParam ] -> format ( 'Y-m-d H:i:s' ) . '\'' ; break ; default : $ fullSql .= $ paramsArr [ $ nameParam ] -> getId ( ) ; } } else $ fullSql .= $ paramsArr [ $ nameParam ] ; } else { $ fullSql .= $ sql [ $ i ] ; } } return $ fullSql ; }
|
Get SQL from query
|
14,378
|
protected function loadSource ( \ SplFileInfo $ source , array $ params = [ ] ) { $ cfg = @ file_get_contents ( $ source -> getPathname ( ) ) ; if ( $ cfg === false ) { throw new \ RuntimeException ( sprintf ( 'Configuration source not found: "%s"' , $ source -> getPathname ( ) ) ) ; } $ replacements = [ ] ; foreach ( $ params as $ k => $ v ) { $ replacements [ '%' . $ k . '%' ] = trim ( $ v ) ; } return trim ( strtr ( $ cfg , $ replacements ) ) ; }
|
Loads the contents of the given file and replaces % - delimited placeholders with the given values .
|
14,379
|
private function resolveLanId ( ) : void { $ codes = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ?? null ) ; if ( empty ( $ codes ) ) $ this -> lanIdDefault ; $ map = Abc :: $ babel -> getInternalLanguageMap ( ) ; foreach ( $ codes as & $ code ) { $ code = strtolower ( str_replace ( '_' , '-' , strtok ( $ code , ';' ) ) ) ; if ( isset ( $ map [ $ code ] ) ) { $ this -> lanId = $ map [ $ code ] ; return ; } } foreach ( $ codes as $ code ) { $ code = substr ( $ code , 0 , 2 ) ; if ( isset ( $ map [ $ code ] ) ) { $ this -> lanId = $ map [ $ code ] ; return ; } } $ this -> lanId = $ this -> lanIdDefault ; }
|
Resolves the ID of the language in which the response must be drafted .
|
14,380
|
public function aroundGetCustomerGroupId ( \ Magento \ Quote \ Model \ Quote $ subject , \ Closure $ proceed ) { $ result = $ proceed ( ) ; if ( $ result == \ Magento \ Customer \ Model \ GroupManagement :: NOT_LOGGED_IN_ID ) { $ code = $ this -> hlpReferral -> getReferralCode ( ) ; if ( $ code ) { $ result = $ this -> hlpConfig -> getReferralsGroupReferrals ( ) ; } } return $ result ; }
|
Replace NOT_LOGGED_IN group for referral customers .
|
14,381
|
public function prePersist ( LifecycleEventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; if ( $ entity instanceof RoutableNodeInterface && $ entity -> hasAutoNodeRouteGeneration ( ) ) { $ routeManager = $ this -> container -> get ( 'mm_cmf_routing.node_route_manager' ) ; $ entity -> addRoute ( $ routeManager -> generateAutoNodeRoute ( $ entity ) ) ; } return ; }
|
prePersist Event whenever a new Node is created also create automatically a new NodeRoute
|
14,382
|
public function onFlush ( OnFlushEventArgs $ args ) { $ unit = $ args -> getEntityManager ( ) -> getUnitOfWork ( ) ; $ routeManager = $ this -> container -> get ( 'mm_cmf_routing.node_route_manager' ) ; foreach ( $ unit -> getScheduledEntityUpdates ( ) as $ entity ) { if ( $ entity instanceof RoutableNodeInterface && $ entity -> hasAutoNodeRouteGeneration ( ) ) { $ hasNodeRoute = false ; $ routeGenerated = false ; foreach ( $ entity -> getRoutes ( ) as $ route ) { if ( $ route instanceof AutoNodeRoute ) { $ hasNodeRoute = true ; break ; } } if ( ! $ hasNodeRoute ) { $ routeManager = $ this -> container -> get ( 'mm_cmf_routing.node_route_manager' ) ; $ entity -> addRoute ( $ routeManager -> generateAutoNodeRoute ( $ entity ) ) ; $ routeGenerated = true ; } $ changed = $ unit -> getEntityChangeSet ( $ entity ) ; if ( array_key_exists ( 'name' , $ changed ) || array_key_exists ( 'parent' , $ changed ) || $ routeGenerated ) { $ routeManager -> getAutoNodeRoutesRecursive ( $ entity ) ; $ unit -> computeChangeSets ( ) ; } } } }
|
onFlush Event for persisting all NodeRoutes that needs an update
|
14,383
|
public function block ( $ file , $ data = [ ] ) { $ block = clone ( $ this ) ; $ block -> layout_file = null ; return $ block -> doRender ( $ file , $ data ) ; }
|
render a block without default layout .
|
14,384
|
public function add ( $ string ) { $ this -> timestamp = $ this -> getTimestamp ( ) + $ this -> evaluateDateString ( $ string ) ; return $ this ; }
|
Add a specific period
|
14,385
|
public function sub ( $ string ) { $ this -> timestamp = $ this -> getTimestamp ( ) - $ this -> evaluateDateString ( $ string ) ; return $ this ; }
|
Subtract a specific period
|
14,386
|
protected function evaluateDateString ( $ string ) { $ seconds = 1 ; $ matches = [ ] ; preg_match ( '/^([0-9]*)([s|M|h|d|m|y])$/' , $ string , $ matches ) ; switch ( $ matches [ 2 ] ) { case 's' : $ seconds = $ matches [ 1 ] ; break ; case 'M' : $ seconds = $ this -> evaluateDateString ( 60 * $ matches [ 1 ] . 's' ) ; break ; case 'h' : $ seconds = $ this -> evaluateDateString ( 60 * $ matches [ 1 ] . 'M' ) ; break ; case 'd' : $ seconds = $ this -> evaluateDateString ( 24 * $ matches [ 1 ] . 'h' ) ; break ; case 'm' : $ seconds = $ this -> evaluateDateString ( 30 * $ matches [ 1 ] . 'd' ) ; break ; case 'y' : $ seconds = $ this -> evaluateDateString ( 12 * $ matches [ 1 ] . 'm' ) ; break ; } return $ seconds ; }
|
Convert string to seconds
|
14,387
|
public function get_plugin_rating ( $ slug , $ ratings = null ) { $ ratings = $ ratings ? : [ 1 => 0 , 2 => 0 , 3 => 0 , 4 => 0 , 5 => 1 , ] ; $ plugins_url = Component :: WP_Plugin_Rating ( ) -> getOption ( 'url' , 'wp-plugins' ) ; $ url = $ plugins_url . $ slug . '/reviews/#new-post' ; $ data [ 'plugin-url-review' ] = $ url ; if ( Plugin :: exists ( 'WP_Plugin_Info' ) ) { $ info = Plugin :: WP_Plugin_Info ( ) -> getControllerInstance ( 'Main' ) ; $ rating = $ info -> get ( 'ratings' , $ slug ) ; $ ratings = ( false !== $ rating ) ? $ rating : $ ratings ; } $ total = 0 ; $ voters = array_sum ( $ ratings ) ; foreach ( $ ratings as $ stars => $ votes ) { $ total += $ stars * $ votes ; } $ rating = $ total ? $ total / $ voters : 0 ; $ data [ 'stars' ] = $ this -> prepare_stars ( $ rating ) ; $ this -> render ( $ data ) ; }
|
Get plugin Rating .
|
14,388
|
protected function prepare_stars ( $ rating ) { $ stars = [ ] ; $ full_star = ( int ) floor ( $ rating ) ; $ half_star = ( ( $ rating - $ full_star ) > 0 ) ? true : false ; for ( $ i = 0 ; $ i < $ full_star ; $ i ++ ) { $ stars [ ] = 'filled' ; } if ( $ half_star ) { $ stars [ ] = 'half' ; } for ( $ i = 0 ; $ i < ( 5 - $ full_star ) ; $ i ++ ) { $ stars [ ] = 'empty' ; } return array_reverse ( $ stars ) ; }
|
Prepare states for each star .
|
14,389
|
protected function render ( $ data ) { $ template = Component :: WP_Plugin_Rating ( ) -> getOption ( 'path' , 'template' ) ; $ this -> view -> renderizate ( $ template , 'component' , $ data ) ; }
|
Renderizate admin page .
|
14,390
|
public function toArray ( ) : array { $ this -> internalDataListUpdate ( ) ; $ toArray = function ( $ object ) use ( & $ toArray ) { $ result = [ ] ; $ vars = get_object_vars ( $ object ) ; foreach ( $ vars as $ name => $ value ) { if ( $ name !== 'internalDataObjectData' ) { $ reflectionProperty = new \ ReflectionProperty ( $ object , $ name ) ; if ( $ reflectionProperty -> isPublic ( ) ) { $ result [ $ name ] = null ; } } } if ( isset ( $ object -> internalDataObjectData ) ) { foreach ( $ object -> internalDataObjectData as $ name => $ value ) { $ result [ substr ( $ name , 1 ) ] = null ; } } ksort ( $ result ) ; foreach ( $ result as $ name => $ null ) { $ value = $ object instanceof \ ArrayAccess ? $ object [ $ name ] : ( isset ( $ object -> $ name ) ? $ object -> $ name : null ) ; if ( is_object ( $ value ) ) { if ( method_exists ( $ value , 'toArray' ) ) { $ result [ $ name ] = $ value -> toArray ( ) ; } else { if ( $ value instanceof \ DateTime ) { $ result [ $ name ] = $ value -> format ( 'c' ) ; } else { $ propertyVars = $ toArray ( $ value ) ; foreach ( $ propertyVars as $ propertyVarName => $ propertyVarValue ) { if ( is_object ( $ propertyVarValue ) ) { $ propertyVars [ $ propertyVarName ] = $ toArray ( $ propertyVarValue ) ; } } $ result [ $ name ] = $ propertyVars ; } } } else { $ result [ $ name ] = $ value ; } } return $ result ; } ; $ result = [ ] ; foreach ( $ this -> internalDataListData as $ index => $ object ) { $ object = $ this -> internalDataListUpdateValueIfNeeded ( $ this -> internalDataListData , $ index ) ; if ( method_exists ( $ object , 'toArray' ) ) { $ result [ ] = $ object -> toArray ( ) ; } else { $ result [ ] = $ toArray ( $ object ) ; } } return $ result ; }
|
Returns the list data converted as an array .
|
14,391
|
public function link ( $ routes , $ url , $ value = '' , $ attributes = array ( 'class' => 'active' ) ) { if ( empty ( $ value ) ) { $ value = $ url ; } $ output = '<a href="' . $ url . '"' ; if ( $ this -> is ( $ routes ) ) { $ output .= $ this -> putAttributes ( $ attributes ) ; } $ output .= '>' . $ value . '</a>' ; return $ output ; }
|
Generate link with active state .
|
14,392
|
public function is ( ) { $ this -> routes = array ( ) ; foreach ( func_get_args ( ) as $ param ) { if ( ! is_array ( $ param ) ) { $ this -> routes [ ] = $ param ; continue ; } foreach ( $ param as $ p ) { $ this -> routes [ ] = $ p ; } } $ this -> request = Request :: path ( ) ; $ this -> parseRoutes ( ) ; foreach ( $ this -> routes as $ route ) { if ( ! Request :: is ( $ route ) ) { continue ; } foreach ( $ this -> bad_routes as $ bad_route ) { if ( str_is ( $ bad_route , $ this -> request ) ) { return false ; } } return true ; } return false ; }
|
Get current state .
|
14,393
|
private function parseRoutes ( ) { $ this -> bad_routes = array ( ) ; foreach ( $ this -> routes as $ r => $ route ) { if ( strpos ( $ route , 'not:' ) !== false ) { $ bad_route = substr ( $ route , strpos ( $ route , "not:" ) + 4 ) ; $ this -> bad_routes [ ] = $ bad_route ; unset ( $ this -> routes [ $ r ] ) ; } } }
|
Separate routes in clean routes and excluded routes .
|
14,394
|
private function putAttributes ( $ attributes ) { $ output = '' ; foreach ( $ attributes as $ attribute => $ value ) { $ output .= ' ' . $ attribute . '="' . $ value . '"' ; } return $ output ; }
|
Attributes to string .
|
14,395
|
public function getMimetype ( $ force = false ) { if ( ! isset ( $ this -> mimetype ) || $ force ) { $ this -> mimetype = MimeTypeGetter :: get ( $ this -> folder -> getPath ( ) . $ this -> filename ) ; } return $ this -> mimetype ; }
|
retrieve mime type requires MimeTypeGetter
|
14,396
|
public function move ( FilesystemFolder $ destination ) { if ( $ destination !== $ this -> folder ) { $ oldpath = $ this -> folder -> getPath ( ) . $ this -> filename ; $ newpath = $ destination -> getPath ( ) . $ this -> filename ; if ( @ rename ( $ oldpath , $ newpath ) ) { $ this -> clearCacheEntries ( ) ; $ this -> folder = $ destination ; $ this -> fileInfo = new \ SplFileInfo ( $ newpath ) ; self :: $ instances [ $ newpath ] = $ this ; unset ( self :: $ instances [ $ oldpath ] ) ; @ chmod ( $ newpath , 0666 & ~ umask ( ) ) ; } else { throw new FilesystemFileException ( "Moving from '$oldpath' to '$newpath' failed." , FilesystemFileException :: FILE_RENAME_FAILED ) ; } } return $ this ; }
|
move file into new folder orphaned cache entries are deleted new cache entries are not generated
|
14,397
|
protected function renameCacheEntries ( $ to ) { if ( ( $ cachePath = $ this -> folder -> getCachePath ( TRUE ) ) ) { $ di = new \ DirectoryIterator ( $ cachePath ) ; foreach ( $ di as $ fileinfo ) { $ filename = $ fileinfo -> getFilename ( ) ; if ( $ fileinfo -> isDot ( ) || ! $ fileinfo -> isFile ( ) || strpos ( $ filename , $ this -> filename ) !== 0 ) { continue ; } $ renamed = substr_replace ( $ filename , $ to , 0 , strlen ( $ this -> filename ) ) ; rename ( $ fileinfo -> getRealPath ( ) , $ fileinfo -> getPath ( ) . DIRECTORY_SEPARATOR . $ renamed ) ; } } }
|
updates names of cache entries
|
14,398
|
public function delete ( ) { if ( @ unlink ( $ this -> getPath ( ) ) ) { $ this -> deleteCacheEntries ( ) ; self :: unsetInstance ( $ this -> getPath ( ) ) ; } else { throw new FilesystemFileException ( "Delete of file '{$this->getPath()}' failed." , FilesystemFileException :: FILE_DELETE_FAILED ) ; } }
|
deletes file and removes instance from lookup array
|
14,399
|
protected function deleteCacheEntries ( ) { if ( ( $ cachePath = $ this -> folder -> getCachePath ( TRUE ) ) ) { $ di = new \ DirectoryIterator ( $ cachePath ) ; foreach ( $ di as $ fileinfo ) { if ( $ fileinfo -> isDot ( ) || ! $ fileinfo -> isFile ( ) || strpos ( $ fileinfo -> getFilename ( ) , $ this -> filename ) !== 0 ) { continue ; } unlink ( $ fileinfo -> getRealPath ( ) ) ; } } }
|
cleans up cache entries associated with original file
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.