idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
51,100
public function formatTaxRate ( $ rate ) { return $ rate != intval ( $ rate ) ? self :: formatAsDecimal ( $ rate , 1 ) : self :: formatAsDecimal ( $ rate , 0 ) ; }
shows decimals only if necessary
51,101
public function getNetPriceAfterTaxUpdate ( $ productId , $ oldNetPrice , $ oldTaxRate ) { if ( is_null ( $ oldTaxRate ) ) { $ oldTaxRate = 0 ; } $ sql = 'SELECT ROUND(:oldNetPrice / ((100 + t.rate) / 100) * (1 + :oldTaxRate / 100), 6) as new_net_price ' ; $ sql .= $ this -> getTaxJoins ( ) ; $ params = [ 'oldNetPrice' => $ oldNetPrice , 'oldTaxRate' => $ oldTaxRate , 'productId' => $ productId ] ; $ statement = $ this -> getConnection ( ) -> prepare ( $ sql ) ; $ statement -> execute ( $ params ) ; $ rate = $ statement -> fetchAll ( 'assoc' ) ; if ( empty ( $ rate ) ) { $ newNetPrice = $ oldNetPrice * ( 1 + $ oldTaxRate / 100 ) ; } else { $ newNetPrice = $ rate [ 0 ] [ 'new_net_price' ] ; } return $ newNetPrice ; }
needs to be called AFTER taxId of product was updated
51,102
public function findNeighbors ( Query $ query , array $ options ) { $ previous = $ this -> find ( ) -> orderAsc ( $ this -> getAlias ( ) . '.modified' ) -> where ( $ this -> getAlias ( ) . '.modified > \'' . $ options [ 'modified' ] . '\'' ) ; $ next = $ this -> find ( ) -> orderDesc ( $ this -> getAlias ( ) . '.modified' ) -> where ( $ this -> getAlias ( ) . '.modified < \'' . $ options [ 'modified' ] . '\'' ) ; return [ 'prev' => $ previous , 'next' => $ next ] ; }
Find neighbors method
51,103
public function initInstantOrder ( $ customerId ) { if ( ! $ customerId ) { throw new RecordNotFoundException ( 'customerId not passed' ) ; } $ this -> Customer = TableRegistry :: getTableLocator ( ) -> get ( 'Customers' ) ; $ instantOrderCustomer = $ this -> Customer -> find ( 'all' , [ 'conditions' => [ 'Customers.id_customer' => $ customerId ] , 'contain' => [ 'AddressCustomers' ] ] ) -> first ( ) ; if ( ! empty ( $ instantOrderCustomer ) ) { $ this -> getRequest ( ) -> getSession ( ) -> write ( 'Auth.instantOrderCustomer' , $ instantOrderCustomer ) ; } else { $ this -> Flash -> error ( __d ( 'admin' , 'No_member_found_with_id_{0}.' , [ $ customerId ] ) ) ; } $ this -> redirect ( '/' ) ; }
this url is called if instant order is initialized saves the desired user in session
51,104
public function middleware ( $ middlewareQueue ) { $ middlewareQueue -> add ( ErrorHandlerMiddleware :: class ) -> add ( AssetMiddleware :: class ) -> add ( new RoutingMiddleware ( $ this ) ) ; return $ middlewareQueue ; }
Setup the middleware queue your application will use .
51,105
private function getFile ( $ filenameWithPath ) { $ explodedString = explode ( '\\' , $ filenameWithPath ) ; header ( 'Content-Type: application/pdf' ) ; header ( 'Content-Disposition: inline; filename="' . $ explodedString [ count ( $ explodedString ) - 1 ] . '"' ) ; readfile ( ROOT . $ filenameWithPath ) ; exit ; }
invoices and order lists are not stored in webroot
51,106
private function markProductsAsSynced ( $ products , $ syncDomainsCount ) { $ syncProducts = $ this -> SyncProduct -> findAllSyncProducts ( $ this -> AppAuth -> getManufacturerId ( ) ) ; foreach ( $ products as $ product ) { $ syncCount = 0 ; $ preparedSyncProducts = [ ] ; foreach ( $ syncProducts as $ syncProduct ) { if ( $ syncProduct -> dash_separated_local_product_id === $ product -> id_product ) { $ syncCount ++ ; $ preparedSyncProducts [ ] = [ 'domain' => $ syncProduct -> sync_domain -> domain , 'name' => 'Name wird nach Login angezeigt...' , 'remoteProductId' => $ syncProduct -> dash_separated_remote_product_id ] ; } } if ( $ syncCount > 0 ) { $ product -> prepared_sync_products = $ preparedSyncProducts ; } } return $ products ; }
check if already synced with local products
51,107
public function getManufacturerRecord ( $ customer ) { $ mm = TableRegistry :: getTableLocator ( ) -> get ( 'Manufacturers' ) ; $ manufacturer = $ mm -> find ( 'all' , [ 'conditions' => [ 'AddressManufacturers.email' => $ customer -> email ] , 'contain' => [ 'AddressManufacturers' ] ] ) -> first ( ) ; return $ manufacturer ; }
bindings with email as foreign key was tricky ...
51,108
private function validateAuthentication ( ) { if ( $ this -> AppAuth -> user ( ) ) { $ this -> Customer = TableRegistry :: getTableLocator ( ) -> get ( 'Customers' ) ; $ query = $ this -> Customer -> find ( 'all' , [ 'conditions' => [ 'Customers.email' => $ this -> AppAuth -> getEmail ( ) ] ] ) ; $ query = $ this -> Customer -> findAuth ( $ query , [ ] ) ; if ( empty ( $ query -> first ( ) ) ) { $ this -> Flash -> error ( __ ( 'You_have_been_signed_out.' ) ) ; $ this -> AppAuth -> logout ( ) ; $ this -> redirect ( Configure :: read ( 'app.slugHelper' ) -> getHome ( ) ) ; } } }
check valid login on each request logged in user should be logged out if deleted or deactivated by admin
51,109
private static function paddingString ( int $ inputsize , int $ blocksize ) : string { $ pad = $ blocksize - ( $ inputsize % $ blocksize ) ; return \ str_repeat ( \ chr ( $ pad ) , $ pad ) ; }
Create the padding string that will be appended to the input .
51,110
protected static function initializeState ( string $ key ) : array { $ s = \ range ( 0 , 255 ) ; $ j = 0 ; foreach ( \ range ( 0 , 255 ) as $ i ) { $ j = ( $ j + $ s [ $ i ] + \ ord ( $ key [ $ i % Str :: strlen ( $ key ) ] ) ) % 256 ; $ x = $ s [ $ i ] ; $ s [ $ i ] = $ s [ $ j ] ; $ s [ $ j ] = $ x ; } return $ s ; }
Create the initial byte matrix that will be used for swaps . This code is identical between RC4 and Spritz .
51,111
public static function equal ( string $ known , string $ given ) : bool { $ nonce = \ random_bytes ( 32 ) ; $ known = \ hash_hmac ( 'sha256' , $ known , $ nonce , true ) ; $ given = \ hash_hmac ( 'sha256' , $ given , $ nonce , true ) ; return \ hash_equals ( $ known , $ given ) ; }
Compares two strings in constant time . Strings are hashed before comparison so information is not leaked when strings are not of equal length .
51,112
public static function tagRequired ( string $ cipher ) : bool { $ cipher = strtolower ( $ cipher ) ; $ needle_tips = [ '-gcm' , '-ccm' , ] ; foreach ( $ needle_tips as $ needle ) { if ( strpos ( $ cipher , $ needle ) ) { return true ; } } return false ; }
Determines if the provided cipher requires a tag
51,113
public static function crypt ( string $ input , string $ password , string $ algo = 'sha512' ) : string { $ chunks = \ str_split ( $ input , Str :: hashSize ( $ algo ) ) ; $ length = Str :: strlen ( $ input ) ; foreach ( $ chunks as $ i => & $ chunk ) { $ chunk = $ chunk ^ \ hash_hmac ( $ algo , $ password . $ length , $ i , true ) ; } return \ implode ( $ chunks ) ; }
Encrypt or decrypt a binary input string .
51,114
private static function build ( string $ data , string $ pass , int $ cost , string $ salt = null ) : string { $ salt = $ salt ?? \ random_bytes ( 16 ) ; $ pkey = \ hash_pbkdf2 ( self :: ALGO , $ pass , $ salt , $ cost , 0 , true ) ; $ hash = \ hash_hmac ( self :: ALGO , $ data , $ pkey , true ) ; $ cost = self :: costEncrypt ( $ cost , $ salt , $ pass ) ; $ chsh = self :: costHash ( $ cost , $ pass ) ; return $ salt . $ chsh . $ cost . $ hash ; }
Internal function used to build the actual hash .
51,115
private static function costEncrypt ( int $ cost , string $ salt , string $ pass ) : string { $ packed = pack ( 'N' , $ cost ) ; return Otp :: crypt ( $ packed , ( $ pass . $ salt ) , self :: ALGO ) ; }
Encrypts the cost value so that it can be added to the output hash discretely
51,116
private static function costDecrypt ( string $ pack , string $ salt , string $ pass ) : int { $ pack = Otp :: crypt ( $ pack , ( $ pass . $ salt ) , self :: ALGO ) ; return unpack ( 'N' , $ pack ) [ 1 ] ; }
Decrypts the cost string back into an int
51,117
public static function make ( string $ data , string $ pass , int $ cost = 250000 ) : string { return self :: build ( $ data , $ pass , $ cost , null ) ; }
Hash an input string into a salted 52 bit hash .
51,118
public static function verify ( string $ data , string $ hash , string $ pass ) : bool { $ salt = Str :: substr ( $ hash , 0 , 16 ) ; $ chsh = Str :: substr ( $ hash , 16 , 8 ) ; $ cost = Str :: substr ( $ hash , 24 , 4 ) ; if ( $ chsh !== self :: costHash ( $ cost , $ pass ) ) { return false ; } $ cost = self :: costDecrypt ( $ cost , $ salt , $ pass ) ; $ calc = self :: build ( $ data , $ pass , $ cost , $ salt ) ; return Str :: equal ( $ hash , $ calc ) ; }
Check the validity of a hash .
51,119
private static function costHash ( string $ cost , string $ pass ) : string { return Str :: substr ( \ hash_hmac ( self :: ALGO , $ cost , $ pass , true ) , 0 , 8 ) ; }
Returns the correct hash for an encrypted cost value .
51,120
public static function encrypt ( string $ input , string $ method , string $ key , string $ iv , string & $ tag ) : string { if ( OpensslStatic :: tagRequired ( $ method ) ) { $ ret = \ openssl_encrypt ( $ input , $ method , $ key , OPENSSL_RAW_DATA , $ iv , $ tag , '' , 4 ) ; } else { $ ret = \ openssl_encrypt ( $ input , $ method , $ key , OPENSSL_RAW_DATA , $ iv ) ; } return self :: returnOrException ( $ ret ) ; }
OpenSSL encrypt wrapper function
51,121
public static function decrypt ( string $ input , string $ method , string $ key , string $ iv , string $ tag ) : string { if ( OpensslStatic :: tagRequired ( $ method ) ) { $ ret = \ openssl_decrypt ( $ input , $ method , $ key , OPENSSL_RAW_DATA , $ iv , $ tag , '' ) ; } else { $ ret = \ openssl_decrypt ( $ input , $ method , $ key , OPENSSL_RAW_DATA , $ iv ) ; } return self :: returnOrException ( $ ret ) ; }
OpenSSL decrypt wrapper function
51,122
public static function ivsize ( string $ cipher ) : int { $ ret = \ openssl_cipher_iv_length ( $ cipher ) ; if ( $ ret === false ) { throw new \ Exception ( "Failed to determine correct IV size." ) ; } return $ ret ; }
Get IV size for specified CIPHER .
51,123
protected function formatDateTime ( DateTimeInterface $ date ) : string { return ( new DateTime ) -> setTimestamp ( $ date -> getTimestamp ( ) ) -> setTimezone ( new DateTimeZone ( 'UTC' ) ) -> format ( 'Y-m-d\TH:i:s\Z' ) ; }
Use UTC time zone and return ISO - 8601 format .
51,124
protected function toDateTime ( string $ representation ) : DateTimeImmutable { if ( is_numeric ( $ representation ) ) { $ representation = '@' . substr ( $ representation , 0 , 10 ) ; } return new DateTimeImmutable ( $ representation ) ; }
Convert an ISO - 8601 formatted string to DateTimeImmutable .
51,125
private static function processUriParams ( & $ path , & $ params ) { if ( preg_match_all ( static :: REGEX_PATH_PARAMS , $ path , $ matches , PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ) { $ previousMatchEnd = 0 ; $ regexParts = [ ] ; foreach ( $ matches as $ match ) { $ matchStart = $ match [ 0 ] [ 1 ] ; $ matchEnd = $ matchStart + strlen ( $ match [ 0 ] [ 0 ] ) ; $ regexParts [ ] = static :: regexEscape ( substr ( $ path , $ previousMatchEnd , $ matchStart - $ previousMatchEnd ) ) ; $ params [ ] = $ match [ 1 ] [ 0 ] ; $ regexParts [ ] = static :: REGEX_PATH_SEGMENT ; $ previousMatchEnd = $ matchEnd ; } $ regexParts [ ] = static :: regexEscape ( substr ( $ path , $ previousMatchEnd ) ) ; $ path = implode ( '' , $ regexParts ) ; } else { $ path = static :: regexEscape ( $ path ) ; } }
Extracts parameters from a path
51,126
public function normalize ( ) { $ this -> str = ltrim ( $ this -> str ) ; $ this -> str = '/' . ltrim ( $ this -> str , '/' ) ; $ this -> str = rtrim ( $ this -> str ) ; return $ this ; }
Normalizes the path
51,127
public function index ( ) { $ test = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'uri' ) ) ; $ model = $ this -> getServiceManager ( ) -> get ( TestModel :: SERVICE_ID ) ; $ itemSequence = array ( ) ; $ itemUris = array ( ) ; $ counter = 1 ; foreach ( $ model -> getItems ( $ test ) as $ item ) { $ itemUris [ ] = $ item -> getUri ( ) ; $ itemSequence [ $ counter ] = array ( 'uri' => tao_helpers_Uri :: encode ( $ item -> getUri ( ) ) , 'label' => $ item -> getLabel ( ) ) ; $ counter ++ ; } $ allItems = array ( ) ; foreach ( \ taoTests_models_classes_TestsService :: singleton ( ) -> getAllItems ( ) as $ itemUri => $ itemLabel ) { $ allItems [ 'item_' . tao_helpers_Uri :: encode ( $ itemUri ) ] = $ itemLabel ; } $ config = $ model -> getConfig ( $ test ) ; $ checked = ( isset ( $ config [ 'previous' ] ) ) ? $ config [ 'previous' ] : false ; $ testConfig [ 'previous' ] = array ( 'label' => __ ( 'Allow test-taker to go back in test' ) , 'checked' => $ checked ) ; $ this -> setData ( 'uri' , $ test -> getUri ( ) ) ; $ this -> setData ( 'allItems' , json_encode ( $ allItems ) ) ; $ this -> setData ( 'itemSequence' , $ itemSequence ) ; $ this -> setData ( 'testConfig' , $ testConfig ) ; $ this -> setData ( 'relatedItems' , json_encode ( tao_helpers_Uri :: encodeArray ( $ itemUris ) ) ) ; $ openNodes = TreeHelper :: getNodesToOpen ( $ itemUris , new core_kernel_classes_Class ( TaoOntology :: ITEM_CLASS_URI ) ) ; $ this -> setData ( 'itemRootNode' , TaoOntology :: ITEM_CLASS_URI ) ; $ this -> setData ( 'itemOpenNodes' , $ openNodes ) ; $ this -> setData ( 'saveUrl' , _url ( 'saveItems' , 'Authoring' , 'taoTestLinear' ) ) ; $ this -> setView ( 'Authoring/index.tpl' ) ; }
Renders the auhtoring for simple tests
51,128
public function saveItems ( ) { $ test = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'uri' ) ) ; if ( ! tao_helpers_Request :: isAjax ( ) ) { throw new common_exception_BadRequest ( 'wrong request mode' ) ; } $ itemUris = tao_helpers_form_GenerisTreeForm :: getSelectedInstancesFromPost ( ) ; foreach ( $ this -> getRequestParameters ( ) as $ key => $ value ) { if ( preg_match ( "/^instance_/" , $ key ) ) { $ itemUris [ ] = tao_helpers_Uri :: decode ( $ value ) ; } } $ config = array ( 'previous' => ( $ this -> getRequestParameter ( 'previous' ) === "true" ) ) ; $ testContent = array ( 'itemUris' => $ itemUris , 'config' => $ config ) ; $ model = $ this -> getServiceManager ( ) -> get ( TestModel :: SERVICE_ID ) ; $ saved = $ model -> save ( $ test , $ testContent ) ; $ this -> returnJson ( array ( 'saved' => $ saved ) ) ; }
save the related items from the checkbox tree or from the sequence box
51,129
protected function getMergedConfigurationForSitePackage ( $ sitePackageKey ) { if ( array_key_exists ( $ sitePackageKey , $ this -> mergedConfigurationCache ) ) { return $ this -> mergedConfigurationCache [ $ sitePackageKey ] ; } $ configuration = $ this -> configuration ; $ siteConfiguration = Arrays :: getValueByPath ( $ configuration , [ 'packages' , $ sitePackageKey ] ) ; if ( $ siteConfiguration ) { $ result = Arrays :: arrayMergeRecursiveOverrule ( $ configuration , $ siteConfiguration ) ; } else { $ result = $ configuration ; } $ this -> mergedConfigurationCache [ $ sitePackageKey ] = $ result ; return $ result ; }
Get the merged configuration for a specific site - package
51,130
public function configurationAction ( $ sitePackageKey = null ) { $ sitePackageKey = $ sitePackageKey ? : $ this -> getDefaultSitePackageKey ( ) ; $ value = [ ] ; $ value [ 'sitePackage' ] = $ sitePackageKey ; $ value [ 'ui' ] = [ 'sitePackages' => $ this -> getSitePackages ( ) , 'viewportPresets' => $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , 'ui.viewportPresets' ) , 'localePresets' => $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , 'ui.localePresets' ) , 'hotkeys' => $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , 'ui.hotkeys' ) , 'preview' => $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , 'preview' ) ] ; $ value [ 'styleguideObjects' ] = $ this -> getStyleguideObjects ( $ sitePackageKey ) ; $ this -> view -> assign ( 'value' , $ value ) ; }
Get all configurations for this site package
51,131
public function prototypeDetailsAction ( $ sitePackageKey , $ prototypeName ) { $ sitePackageKey = $ sitePackageKey ? : $ this -> getDefaultSitePackageKey ( ) ; $ prototypePreviewRenderPath = FusionService :: RENDERPATH_DISCRIMINATOR . str_replace ( [ '.' , ':' ] , [ '_' , '__' ] , $ prototypeName ) ; $ fusionView = new FusionView ( ) ; $ fusionView -> setControllerContext ( $ this -> getControllerContext ( ) ) ; $ fusionView -> setFusionPath ( $ prototypePreviewRenderPath ) ; $ fusionView -> setPackageKey ( $ sitePackageKey ) ; $ fusionObjectTree = $ this -> fusionService -> getMergedFusionObjectTreeForSitePackage ( $ sitePackageKey ) ; $ fusionAst = $ fusionObjectTree [ '__prototypes' ] [ $ prototypeName ] ; $ fusionCode = ReverseFusionParser :: restorePrototypeCode ( $ prototypeName , $ fusionAst ) ; $ result = [ 'prototypeName' => $ prototypeName , 'renderedCode' => $ fusionCode , 'parsedCode' => Yaml :: dump ( $ fusionAst , 99 ) , 'fusionAst' => $ fusionAst , 'anatomy' => $ this -> fusionService -> getAnatomicalPrototypeTreeFromAstExcerpt ( $ fusionAst ) ] ; $ this -> view -> assign ( 'value' , $ result ) ; }
Render informations about the given prototype
51,132
protected function getStructureForPrototypeName ( $ prototypeStructures , $ prototypeName ) { foreach ( $ prototypeStructures as $ structure ) { if ( preg_match ( sprintf ( '!%s!' , $ structure [ 'match' ] ) , $ prototypeName ) ) { return $ structure ; } } return [ 'label' => 'Other' , 'icon' => 'icon-question' , 'color' => 'white' ] ; }
Find the matching structure for a prototype
51,133
public function getMergedFusionObjectTreeForSitePackage ( $ siteResourcesPackageKey ) { $ siteRootFusionPathAndFilename = sprintf ( $ this -> siteRootFusionPattern , $ siteResourcesPackageKey ) ; $ mergedFusionCode = '' ; $ mergedFusionCode .= $ this -> generateNodeTypeDefinitions ( ) ; $ mergedFusionCode .= $ this -> getFusionIncludes ( $ this -> prepareAutoIncludeFusion ( ) ) ; $ mergedFusionCode .= $ this -> getFusionIncludes ( $ this -> prependFusionIncludes ) ; $ mergedFusionCode .= $ this -> readExternalFusionFile ( $ siteRootFusionPathAndFilename ) ; $ mergedFusionCode .= $ this -> getFusionIncludes ( $ this -> appendFusionIncludes ) ; return $ this -> fusionParser -> parse ( $ mergedFusionCode , $ siteRootFusionPathAndFilename ) ; }
Returns a merged fusion object tree in the context of the given site - package
51,134
public function getStyleguideObjectsFromFusionAst ( $ fusionAst ) { $ styleguideObjects = [ ] ; if ( $ fusionAst && $ fusionAst [ '__prototypes' ] ) { foreach ( $ fusionAst [ '__prototypes' ] as $ prototypeFullName => $ prototypeObject ) { if ( array_key_exists ( '__meta' , $ prototypeObject ) && is_array ( $ prototypeObject [ '__meta' ] ) && array_key_exists ( 'styleguide' , $ prototypeObject [ '__meta' ] ) ) { list ( $ prototypeVendor , $ prototypeName ) = explode ( ':' , $ prototypeFullName , 2 ) ; $ styleguideConfiguration = $ prototypeObject [ '__meta' ] [ 'styleguide' ] ; $ styleguideObjects [ $ prototypeFullName ] = [ 'title' => ( isset ( $ styleguideConfiguration [ 'title' ] ) ) ? $ styleguideConfiguration [ 'title' ] : implode ( ' ' , array_reverse ( explode ( '.' , $ prototypeName ) ) ) , 'path' => ( isset ( $ styleguideConfiguration [ 'path' ] ) ) ? $ styleguideConfiguration [ 'path' ] : $ prototypeName , 'description' => ( isset ( $ styleguideConfiguration [ 'description' ] ) ) ? $ styleguideConfiguration [ 'description' ] : '' , 'options' => ( isset ( $ styleguideConfiguration [ 'options' ] ) ) ? $ styleguideConfiguration [ 'options' ] : null , ] ; } } } return $ styleguideObjects ; }
Get all styleguide objects for the given fusion - ast
51,135
public function getAnatomicalPrototypeTreeFromAstExcerpt ( $ fusionAstExcerpt ) { $ result = [ ] ; if ( ! is_array ( $ fusionAstExcerpt ) ) { return $ result ; } foreach ( $ fusionAstExcerpt as $ key => $ value ) { if ( substr ( $ key , 0 , 2 ) === '__' ) { continue ; } $ anatomy = $ this -> getAnatomicalPrototypeTreeFromAstExcerpt ( $ value ) ; if ( array_key_exists ( 'prototypeName' , $ anatomy ) ) { if ( $ anatomy [ 'prototypeName' ] !== null ) { $ result [ ] = $ anatomy ; } } else { $ result = array_merge ( $ result , $ anatomy ) ; } } if ( ! array_key_exists ( '__objectType' , $ fusionAstExcerpt ) ) { return $ result ; } else { return [ 'prototypeName' => $ fusionAstExcerpt [ '__objectType' ] , 'children' => $ result ] ; } }
Get anatomical prototype tree from fusion AST excerpt
51,136
public function viewportsCommand ( $ format = 'json' , $ packageKey = null ) { $ sitePackageKey = $ packageKey ? : $ this -> getDefaultSitePackageKey ( ) ; $ viewportPresets = $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , 'ui.viewportPresets' ) ; $ this -> outputData ( $ viewportPresets , $ format ) ; }
Get a list of all configured default styleguide viewports
51,137
public function itemsCommand ( $ format = 'json' , $ packageKey = null ) { $ sitePackageKey = $ packageKey ? : $ this -> getDefaultSitePackageKey ( ) ; $ fusionAst = $ this -> fusionService -> getMergedFusionObjectTreeForSitePackage ( $ sitePackageKey ) ; $ styleguideObjects = $ this -> fusionService -> getStyleguideObjectsFromFusionAst ( $ fusionAst ) ; $ this -> outputData ( $ styleguideObjects , $ format ) ; }
Get all styleguide items currently available
51,138
public function renderCommand ( $ prototypeName , $ packageKey = null , $ propSet = '__default' , $ props = '' , $ locales = '' ) { $ sitePackageKey = $ packageKey ? : $ this -> getDefaultSitePackageKey ( ) ; $ convertedProps = json_decode ( $ props , true ) ?? [ ] ; $ convertedLocales = json_decode ( $ locales , true ) ?? [ ] ; $ controllerContext = $ this -> createDummyControllerContext ( ) ; $ fusionView = new FusionView ( ) ; $ fusionView -> setControllerContext ( $ controllerContext ) ; $ fusionView -> setPackageKey ( $ sitePackageKey ) ; $ fusionRootPath = $ this -> configurationService -> getSiteConfiguration ( $ sitePackageKey , [ 'cli' , 'fusionRootPath' ] ) ; $ fusionView -> setPackageKey ( $ sitePackageKey ) ; $ fusionView -> setFusionPath ( $ fusionRootPath ) ; $ fusionView -> assignMultiple ( [ 'sitePackageKey' => $ packageKey , 'prototypeName' => $ prototypeName , 'propSet' => $ propSet , 'props' => $ convertedProps , 'locales' => $ convertedLocales ] ) ; $ this -> output ( $ fusionView -> render ( ) ) ; }
Render a given fusion component to HTML
51,139
public function staticAction ( $ key ) { if ( $ key && is_array ( $ this -> staticUriMocks ) && array_key_exists ( $ key , $ this -> staticUriMocks ) ) { $ config = $ this -> staticUriMocks [ $ key ] ; $ this -> response -> setHeader ( 'Content-Type' , $ config [ 'contentType' ] ) ; return file_get_contents ( $ config [ 'path' ] ) ; } throw new TargetNotFoundException ( ) ; }
Return the given static content as defined in the configuration
51,140
public static function restorePrototypeCode ( $ prototypeName , $ abstractSyntaxTree , $ indentation = '' ) { $ result = '' ; if ( array_key_exists ( '__prototypeObjectName' , $ abstractSyntaxTree ) ) { $ result .= sprintf ( 'prototype(%s) < prototype(%s) {' , $ prototypeName , $ abstractSyntaxTree [ '__prototypeObjectName' ] ) . chr ( 10 ) ; } else { $ result .= sprintf ( 'prototype(%s) {' , $ prototypeName ) . chr ( 10 ) ; } if ( array_key_exists ( '__meta' , $ abstractSyntaxTree ) ) { foreach ( array_keys ( $ abstractSyntaxTree [ '__meta' ] ) as $ key ) { if ( in_array ( $ key , self :: $ TOP_META_KEYS , true ) === false ) { continue ; } $ result .= self :: restoreValueCode ( '@' . $ key , $ abstractSyntaxTree [ '__meta' ] [ $ key ] , $ indentation . self :: INDENTATION ) ; } } if ( array_key_exists ( '__prototypes' , $ abstractSyntaxTree ) ) { foreach ( array_keys ( $ abstractSyntaxTree [ '__prototypes' ] ) as $ key ) { $ result .= self :: restorePrototypeCode ( $ key , $ abstractSyntaxTree [ '__prototypes' ] [ $ key ] , $ indentation . self :: INDENTATION ) ; } } foreach ( array_keys ( $ abstractSyntaxTree ) as $ key ) { if ( in_array ( $ key , self :: $ RESERVED_KEYS , true ) ) { continue ; } $ result .= self :: restoreValueCode ( $ key , $ abstractSyntaxTree [ $ key ] , $ indentation . self :: INDENTATION ) ; } if ( array_key_exists ( '__meta' , $ abstractSyntaxTree ) ) { foreach ( array_keys ( $ abstractSyntaxTree [ '__meta' ] ) as $ key ) { if ( in_array ( $ key , self :: $ TOP_META_KEYS , true ) === true ) { continue ; } $ result .= self :: restoreValueCode ( '@' . $ key , $ abstractSyntaxTree [ '__meta' ] [ $ key ] , $ indentation . self :: INDENTATION ) ; } } $ result .= $ indentation . '}' . chr ( 10 ) ; return $ result ; }
Get PrototypeName and AST and restore the original Code representation
51,141
protected function getActiveSitePackageKeys ( ) { $ sitePackages = $ this -> packageManager -> getFilteredPackages ( 'available' , null , 'neos-site' ) ; $ result = [ ] ; foreach ( $ sitePackages as $ sitePackage ) { $ packageKey = $ sitePackage -> getPackageKey ( ) ; $ result [ ] = $ packageKey ; } return $ result ; }
Get a list of all active site package keys
51,142
public function evaluate ( ) { $ type = $ this -> getType ( ) ; $ content = $ this -> getContent ( ) ; if ( $ type && $ content ) { return 'data:' . $ type . ';base64,' . base64_encode ( $ content ) ; } }
Render a prototype
51,143
protected function createDummyControllerContext ( ) { $ httpRequest = Request :: create ( new Uri ( 'http://neos.io' ) ) ; $ request = new ActionRequest ( $ httpRequest ) ; $ response = new Response ( ) ; $ arguments = new Arguments ( [ ] ) ; $ uriBuilder = new UriBuilder ( ) ; $ uriBuilder -> setRequest ( $ request ) ; return new ControllerContext ( $ request , $ response , $ arguments , $ uriBuilder ) ; }
Create a dummy controller context
51,144
private function minifyHTML ( $ html ) { $ search = array ( '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/' , '/\n/' , '/\>[^\S ]+/s' , '/[^\S ]+\</s' , '/(\s)+/s' , '/<!--.*? ) ; $ replace = array ( ' ' , ' ' , '>' , '<' , '\\1' , '' ) ; $ squeezedHTML = preg_replace ( $ search , $ replace , $ html ) ; return $ squeezedHTML ; }
minify html content
51,145
public function attempt ( $ password ) { if ( ! Hash :: check ( $ password , Auth :: user ( ) -> getAuthPassword ( ) ) ) { return false ; } $ this -> request -> session ( ) -> put ( $ this -> key . '.life' , Carbon :: now ( ) -> timestamp ) ; $ this -> request -> session ( ) -> put ( $ this -> key . '.authenticated' , true ) ; return true ; }
Attempt to Reauthenticate the user .
51,146
public function check ( ) { $ session = $ this -> request -> session ( ) ; $ validationTime = Carbon :: createFromTimestamp ( $ session -> get ( $ this -> key . '.life' , 0 ) ) ; return $ session -> get ( $ this -> key . '.authenticated' , false ) && ( $ validationTime -> diffInMinutes ( ) <= $ this -> reauthTime ) ; }
Validate a reauthenticated Session data .
51,147
public function createConnection ( string $ dsn , string $ driverClass = 'com.mysql.jdbc.Driver' ) : Interfaces \ JavaObject { if ( ! is_string ( $ dsn ) || trim ( $ dsn ) == '' ) { $ message = 'DSN param must be a valid (on-empty) string' ; throw new Exception \ InvalidArgumentException ( __METHOD__ . ' ' . $ message ) ; } $ class = $ this -> ba -> javaClass ( 'java.lang.Class' ) ; try { $ class -> forName ( $ driverClass ) ; } catch ( Exception \ JavaException $ e ) { throw $ e ; } try { $ conn = $ this -> getDriverManager ( ) -> getConnection ( $ dsn ) ; } catch ( Exception \ JavaExceptionInterface $ e ) { throw $ e ; } return $ conn ; }
Create an sql connection to database .
51,148
public function getDriverManager ( ) : Interfaces \ JavaObject { if ( $ this -> driverManager === null ) { $ this -> driverManager = $ this -> ba -> javaClass ( 'java.sql.DriverManager' ) ; } return $ this -> driverManager ; }
Return underlying java driver manager .
51,149
public static function getJdbcDsn ( string $ driver , string $ db , string $ host , string $ user , string $ password , array $ options = [ ] ) : string { $ extras = '' ; if ( count ( $ options ) > 0 ) { $ tmp = [ ] ; foreach ( $ options as $ key => $ value ) { $ tmp [ ] = urlencode ( $ key ) . '=' . urlencode ( $ value ) ; } $ extras = '&' . implode ( '&' , $ tmp ) ; } return "jdbc:$driver://$host/$db?user=$user&password=$password" . $ extras ; }
Return a JDBC DSN formatted string from options .
51,150
protected function loadClient ( ) : void { if ( self :: $ client === null ) { $ options = $ this -> options ; if ( ! isset ( $ options [ 'servlet_address' ] ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . ' Missing required parameter servlet_address' ) ; } $ connection = static :: parseServletUrl ( $ options [ 'servlet_address' ] ) ; $ params = new ArrayObject ( [ Client :: PARAM_JAVA_HOSTS => $ connection [ 'servlet_host' ] , Client :: PARAM_JAVA_SERVLET => $ connection [ 'servlet_uri' ] , Client :: PARAM_JAVA_AUTH_USER => $ connection [ 'auth_user' ] , Client :: PARAM_JAVA_AUTH_PASSWORD => $ connection [ 'auth_password' ] , Client :: PARAM_JAVA_DISABLE_AUTOLOAD => $ options [ 'java_disable_autoload' ] , Client :: PARAM_JAVA_PREFER_VALUES => $ options [ 'java_prefer_values' ] , Client :: PARAM_JAVA_SEND_SIZE => $ options [ 'java_send_size' ] , Client :: PARAM_JAVA_RECV_SIZE => $ options [ 'java_recv_size' ] , Client :: PARAM_JAVA_LOG_LEVEL => $ options [ 'java_log_level' ] , Client :: PARAM_XML_PARSER_FORCE_SIMPLE_PARSER => $ options [ 'force_simple_xml_parser' ] , Client :: PARAM_USE_PERSISTENT_CONNECTION => $ options [ 'use_persistent_connection' ] ] ) ; self :: $ client = new Client ( $ params , $ this -> logger ) ; self :: getClient ( ) -> throwExceptionProxyFactory = new Proxy \ DefaultThrowExceptionProxyFactory ( self :: $ client , $ this -> logger ) ; $ this -> bootstrap ( ) ; } }
Load pjb client with options .
51,151
public function getJavaClass ( $ name ) : Interfaces \ JavaClass { if ( ! array_key_exists ( $ name , $ this -> classMapCache ) ) { $ this -> classMapCache [ $ name ] = new JavaClass ( $ name ) ; } return $ this -> classMapCache [ $ name ] ; }
Return a Java class .
51,152
public function invokeMethod ( ? Interfaces \ JavaType $ object = null , string $ method , array $ args = [ ] ) { $ id = ( $ object === null ) ? 0 : $ object -> __getJavaInternalObjectId ( ) ; return self :: getClient ( ) -> invokeMethod ( $ id , $ method , $ args ) ; }
Invoke a method dynamically .
51,153
public function isInstanceOf ( Interfaces \ JavaObject $ object , $ class ) : bool { if ( is_string ( $ class ) ) { $ name = $ class ; $ class = $ this -> getJavaClass ( $ name ) ; } elseif ( ! $ class instanceof Interfaces \ JavaObject ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . 'Class $class parameter must be of Interfaces\JavaClass, Interfaces\JavaObject or string' ) ; } return self :: getClient ( ) -> invokeMethod ( 0 , 'instanceOf' , [ $ object , $ class ] ) ; }
Test whether an object is an instance of java class or interface .
51,154
public function getOption ( string $ name ) { if ( ! $ this -> options -> offsetExists ( $ name ) ) { throw new Exception \ InvalidArgumentException ( "Option '$name' does not exists'" ) ; } return $ this -> options [ $ name ] ; }
Return specific option .
51,155
public static function unregisterInstance ( ) : void { if ( ! self :: $ unregistering && self :: $ client !== null ) { self :: $ unregistering = true ; if ( ( self :: $ client -> preparedToSendBuffer ? : '' ) !== '' ) { self :: $ client -> sendBuffer .= self :: $ client -> preparedToSendBuffer ; } try { self :: $ client -> sendBuffer .= self :: $ client -> protocol -> getKeepAlive ( ) ; self :: $ client -> protocol -> flush ( ) ; } catch ( \ Throwable $ e ) { } if ( isset ( self :: $ client -> protocol -> handler -> channel ) && false === strpos ( get_class ( self :: getClient ( ) -> protocol -> handler -> channel ) , '/EmptyChannel/' ) ) { try { self :: $ client -> protocol -> keepAlive ( ) ; } catch ( \ Throwable $ e ) { } } self :: $ client = null ; self :: $ instance = null ; self :: $ instanceOptionsKey = null ; self :: $ unregistering = false ; } }
Clean up PjbProxyClient instance .
51,156
public function invokeMethod ( int $ object_id , string $ method , array $ args = [ ] ) { $ this -> protocol -> invokeBegin ( $ object_id , $ method ) ; $ this -> writeArgs ( $ args ) ; $ this -> protocol -> invokeEnd ( ) ; $ val = $ this -> getResult ( ) ; return $ val ; }
Invoke a method on java object .
51,157
public function setExitCode ( int $ code ) : void { if ( isset ( $ this -> protocol ) ) { $ this -> protocol -> writeExitCode ( $ code ) ; } }
Write exit code .
51,158
public function cast ( JavaProxy $ object , $ type ) { $ code = strtoupper ( $ type [ 0 ] ) ; switch ( $ code ) { case 'S' : return $ this -> invokeMethod ( 0 , 'castToString' , [ $ object ] ) ; case 'B' : return $ this -> invokeMethod ( 0 , 'castToBoolean' , [ $ object ] ) ; case 'L' : case 'I' : return $ this -> invokeMethod ( 0 , 'castToExact' , [ $ object ] ) ; case 'D' : case 'F' : return $ this -> invokeMethod ( 0 , 'castToInExact' , [ $ object ] ) ; case 'N' : return null ; case 'A' : return $ this -> invokeMethod ( 0 , 'castToArray' , [ $ object ] ) ; case 'O' : return $ object ; default : throw new Exception \ RuntimeException ( "Illegal type '$code' for casting" ) ; } }
Cast an object to a certain type .
51,159
public function getAvailableIDs ( ) : array { if ( $ this -> availableTz === null ) { $ this -> availableTz = [ ] ; $ available = $ this -> timeZoneClass -> getAvailableIDs ( ) ; foreach ( $ available as $ id ) { $ this -> availableTz [ ] = $ id ; } } return $ this -> availableTz ; }
Return java available timezone ids .
51,160
public function getDefault ( $ enableTzCache = true ) : Interfaces \ JavaObject { $ enableCache = $ enableTzCache && self :: $ enableTzCache ; if ( ! $ enableCache || self :: $ defaultTz === null ) { self :: $ defaultTz = $ this -> timeZoneClass -> getDefault ( ) ; } return self :: $ defaultTz ; }
Return default jvm TimeZone .
51,161
public function isInstanceOf ( Interfaces \ JavaObject $ javaObject , $ className ) : bool { return $ this -> driver -> isInstanceOf ( $ javaObject , $ className ) ; }
Checks whether object is an instance of a class or interface .
51,162
public function isNull ( Interfaces \ JavaObject $ javaObject = null ) : bool { return $ this -> driver -> isNull ( $ javaObject ) ; }
Whether a java internal value is null .
51,163
public function getSystem ( ) : Adapter \ System { if ( $ this -> system === null ) { $ this -> system = new Adapter \ System ( $ this ) ; } return $ this -> system ; }
Return system properties .
51,164
public static function getJavaBridgeHeader ( string $ name , array $ array ) : string { if ( array_key_exists ( $ name , $ array ) ) { return $ array [ $ name ] ; } $ name = "HTTP_$name" ; if ( array_key_exists ( $ name , $ array ) ) { return $ array [ $ name ] ; } return '' ; }
Return java bridge header or empty string if nothing .
51,165
public static function castPjbInternal ( $ javaObject , string $ cast_type ) { if ( $ javaObject instanceof JavaType ) { return $ javaObject -> __cast ( $ cast_type ) ; } $ first_char = strtoupper ( $ cast_type [ 0 ] ) ; switch ( $ first_char ) { case 'S' : return ( string ) $ javaObject ; case 'B' : return ( bool ) $ javaObject ; case 'L' : case 'I' : return ( int ) $ javaObject ; case 'D' : case 'F' : return ( float ) $ javaObject ; case 'N' : return null ; case 'A' : return ( array ) $ javaObject ; case 'O' : return ( object ) $ javaObject ; } }
Cast internal objects to a new type .
51,166
public function getClassName ( Interfaces \ JavaObject $ javaObject ) : string { $ inspect = $ this -> inspect ( $ javaObject ) ; $ matches = [ ] ; preg_match ( '/^\[class (.+)\:/' , $ inspect , $ matches ) ; if ( ! isset ( $ matches [ 1 ] ) || $ matches [ 1 ] == '' ) { throw new Exception \ UnexpectedException ( __METHOD__ . ' Cannot determine class name' ) ; } return $ matches [ 1 ] ; }
Return object java class name .
51,167
public static function all ( $ routes ) { foreach ( self :: $ beforeFuncs as $ beforeFunc ) { if ( $ beforeFunc [ 1 ] ) { call_user_func_array ( $ beforeFunc [ 0 ] , $ beforeFunc [ 1 ] ) ; } else { call_user_func ( $ beforeFunc [ 0 ] ) ; } } self :: $ routes = $ routes ; $ method = strtolower ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; $ path = '/' ; $ handler = null ; $ matched = array ( ) ; if ( ! empty ( $ _SERVER [ 'PATH_INFO' ] ) ) { $ path = $ _SERVER [ 'PATH_INFO' ] ; } else if ( ! empty ( $ _SERVER [ 'REQUEST_URI' ] ) ) { $ path = parse_url ( $ _SERVER [ 'REQUEST_URI' ] , PHP_URL_PATH ) ; } if ( isset ( $ routes [ $ path ] ) ) { if ( is_array ( $ routes [ $ path ] ) ) { $ handler = $ routes [ $ path ] [ 0 ] ; } else { $ handler = $ routes [ $ path ] ; } } else if ( $ routes ) { $ regex = array ( '/{i}/' , '/{s}/' , '/{a}/' ) ; $ replacements = array ( '([\d]+)' , '([a-zA-Z]+)' , '([\w-]+)' ) ; foreach ( $ routes as $ routePath => $ routeDesc ) { $ routePath = preg_replace ( $ regex , $ replacements , $ routePath ) ; if ( preg_match ( '#^/?' . $ routePath . '/?$#' , $ path , $ matches ) ) { if ( is_array ( $ routeDesc ) ) { $ handler = $ routeDesc [ 0 ] ; if ( isset ( $ routeDesc [ 2 ] ) ) { $ middleware = $ routeDesc [ 2 ] ; } } else $ handler = $ routeDesc ; $ matched = $ matches ; break ; } } } unset ( $ matched [ 0 ] ) ; if ( isset ( $ middleware ) ) { $ newMatched = self :: callFunction ( $ middleware , $ matched , $ method ) ; if ( $ newMatched ) { self :: callFunction ( $ handler , $ newMatched , $ method ) ; } else { self :: callFunction ( $ handler , $ matched , $ method ) ; } } else { self :: callFunction ( $ handler , $ matched , $ method ) ; } foreach ( self :: $ afterFuncs as $ afterFunc ) if ( $ afterFunc [ 1 ] ) { call_user_func_array ( $ afterFunc [ 0 ] , $ afterFunc [ 1 ] ) ; } else { call_user_func ( $ afterFunc [ 0 ] ) ; } }
Static function of the class Link that deploys the route according to the passed handler and path
51,168
public static function route ( $ name , $ params = array ( ) ) { $ href = null ; foreach ( self :: $ routes as $ routePath => $ routeDesc ) { if ( is_array ( $ routeDesc ) ) { if ( $ name == $ routeDesc [ 1 ] ) { $ href = $ routePath ; for ( $ i = 0 ; $ i < count ( $ params ) ; $ i ++ ) { $ href = preg_replace ( '#{(.*?)}#' , $ params [ $ i ] , $ href , 1 ) ; } } } } return $ href ; }
Static function that helps you generate links effortlessly and pass parameters to them thus enabling to generate dynamic links
51,169
public static function callFunction ( $ handler , $ matched , $ method ) { if ( $ handler ) { if ( is_callable ( $ handler ) ) { $ newParams = call_user_func_array ( $ handler , $ matched ) ; } else { if ( class_exists ( $ handler ) ) { $ instanceOfHandler = new $ handler ( ) ; } else { print_r ( 'Class or function ' . $ handler . ' not found' ) ; header ( $ _SERVER [ 'SERVER_PROTOCOL' ] . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } } } else { self :: handle404 ( ) ; } if ( isset ( $ instanceOfHandler ) ) { if ( method_exists ( $ instanceOfHandler , $ method ) ) { try { $ newParams = call_user_func_array ( array ( $ instanceOfHandler , $ method ) , $ matched ) ; } catch ( Exception $ exception ) { $ string = str_replace ( "\n" , ' ' , var_export ( $ exception , TRUE ) ) ; error_log ( $ string ) ; header ( $ _SERVER [ 'SERVER_PROTOCOL' ] . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } } } if ( isset ( $ newParams ) && $ newParams ) { return $ newParams ; } }
Static function to handle both middlewares call and main handler s call .
51,170
protected function determineLineEnding ( ) { if ( isset ( $ this -> content [ 0 ] ) && strpos ( $ this -> content [ 0 ] , "\r\n" ) !== false ) { $ this -> lineEnding = "\r\n" ; } return $ this ; }
Default line ending is set to LF .
51,171
protected static function useCustomGrammar ( $ connection ) { if ( get_class ( $ connection ) === 'Illuminate\Database\MySqlConnection' ) { $ MySqlGrammar = $ connection -> withTablePrefix ( new MySqlGrammar ) ; $ connection -> setSchemaGrammar ( $ MySqlGrammar ) ; } return $ connection -> getSchemaBuilder ( ) ; }
lead the system to load custom Grammar
51,172
public function enter ( RequestInterface $ request = null ) { $ this -> starts = [ 'wt' => microtime ( true ) , 'mu' => memory_get_usage ( ) , 'pmu' => memory_get_peak_usage ( ) , ] ; if ( $ request ) { $ this -> request = [ 'method' => $ request -> getMethod ( ) , 'url' => ( string ) $ request -> getUri ( ) , 'headers' => $ request -> getHeaders ( ) , 'body' => ( string ) $ request -> getBody ( ) ] ; } }
Starts the profiling .
51,173
protected function findOrCreateMember ( AccessToken $ token , AbstractProvider $ provider ) { $ user = $ provider -> getResourceOwner ( $ token ) ; $ passport = Passport :: get ( ) -> filter ( [ 'Identifier' => $ user -> getId ( ) ] ) -> first ( ) ; if ( ! $ passport ) { $ member = $ this -> createMember ( $ token , $ provider ) ; $ passport = Passport :: create ( ) -> update ( [ 'Identifier' => $ user -> getId ( ) , 'MemberID' => $ member -> ID ] ) ; $ passport -> write ( ) ; } return $ passport -> Member ( ) ; }
Find or create a member from the given access token
51,174
protected function createMember ( AccessToken $ token , AbstractProvider $ provider ) { $ session = $ this -> getSession ( ) ; $ providerName = $ session -> get ( 'oauth2.provider' ) ; $ user = $ provider -> getResourceOwner ( $ token ) ; $ member = Member :: create ( ) ; $ member = $ this -> getMapper ( $ providerName ) -> map ( $ member , $ user ) ; $ member -> OAuthSource = $ providerName ; $ member -> write ( ) ; return $ member ; }
Create a member from the given token
51,175
public function link ( $ action = null ) { if ( $ action ) { return Controller :: join_links ( $ this -> link , $ action ) ; } return $ this -> link ; }
Return a link to this request handler . The link returned is supplied in the constructor
51,176
public function handleProvider ( $ name ) { $ this -> extend ( 'onBeforeHandleProvider' , $ name ) ; $ providers = Config :: inst ( ) -> get ( $ this -> authenticator_class , 'providers' ) ; $ config = $ providers [ $ name ] ; $ scope = isset ( $ config [ 'scopes' ] ) ? $ config [ 'scopes' ] : [ 'email' ] ; $ url = Helper :: buildAuthorisationUrl ( $ name , 'login' , $ scope ) ; return $ this -> getController ( ) -> redirect ( $ url ) ; }
Handle a submission for a given provider - build redirection
51,177
public function pushDecorator ( Decorator $ decorator ) { $ decorator -> setInnerBus ( $ this -> bus ) ; $ this -> bus = $ decorator ; }
Push a new Decorator on to the stack
51,178
public function resolve ( Command $ command ) { $ commandName = get_class ( $ command ) ; foreach ( $ this -> handlers as $ handlerCommand => $ handler ) { if ( $ handlerCommand == $ commandName ) { return $ handler ; } } if ( $ command instanceof CommandHandler ) { return $ command ; } $ class = $ commandName . 'Handler' ; if ( class_exists ( $ class ) ) { return $ this -> container -> make ( $ class ) ; } $ classParts = explode ( '\\' , $ commandName ) ; $ commandNameWithoutNamespace = array_pop ( $ classParts ) ; $ class = implode ( '\\' , $ classParts ) . '\\Handlers\\' . $ commandNameWithoutNamespace . 'Handler' ; if ( class_exists ( $ class ) ) { return $ this -> container -> make ( $ class ) ; } throw new UnresolvableCommandHandlerException ( 'Could not resolve a handler for [' . get_class ( $ command ) . ']' ) ; }
Retrieve a CommandHandler for a given Command
51,179
public function bindHandler ( $ commandName , $ handler ) { if ( $ handler instanceof CommandHandler ) { $ this -> handlers [ $ commandName ] = $ handler ; return ; } if ( is_callable ( $ handler ) ) { return $ this -> bindHandler ( $ commandName , new CallableCommandHandler ( $ handler ) ) ; } if ( is_string ( $ handler ) ) { return $ this -> bindHandler ( $ commandName , new LazyLoadingCommandHandler ( $ handler , $ this -> container ) ) ; } throw new \ InvalidArgumentException ( 'Could not push handler. Command Handlers should be an instance of Chief\CommandHandler, a callable, or a string representing a CommandHandler class' ) ; }
Bind a handler to a command . These bindings should overrule the default resolution behaviour for this resolver
51,180
public function handle ( Command $ command ) { $ handler = $ this -> container -> make ( $ this -> handlerName ) ; return $ handler -> handle ( $ command ) ; }
Handle a command execution
51,181
public function execute ( Command $ command ) { if ( ! $ this -> innerCommandBus ) { throw new Exception ( 'No inner bus defined for this decorator. Set an inner bus with setInnerBus()' ) ; } $ response = $ this -> innerCommandBus -> execute ( $ command ) ; $ eventName = $ this -> getEventName ( $ command ) ; $ this -> dispatcher -> dispatch ( $ eventName , [ $ command ] ) ; return $ response ; }
Execute a command and dispatch and event
51,182
private function createCacheItem ( CacheableCommand $ command , $ value ) { return $ this -> cache -> getItem ( $ this -> getCacheKey ( $ command ) ) -> expiresAfter ( $ this -> getCacheExpiry ( $ command ) ) -> set ( $ value ) ; }
Create a new cache item to be persisted .
51,183
private function getCacheKey ( CacheableCommand $ command ) { if ( $ command instanceof HasCacheOptions && $ command -> getCacheKey ( ) ) { return $ command -> getCacheKey ( ) ; } return md5 ( serialize ( $ command ) ) ; }
Create the key to be used when saving this item to the cache pool .
51,184
private function getCacheExpiry ( CacheableCommand $ command ) { if ( $ command instanceof HasCacheOptions && $ command -> getCacheExpiry ( ) > 0 ) { return $ command -> getCacheExpiry ( ) ; } return $ this -> expiresAfter ; }
Determine when this CachableCommand should expire in terms of seconds from now .
51,185
public function addTags ( array $ tags , Taggable $ resource ) { foreach ( $ tags as $ tag ) { if ( $ tag instanceof Tag ) { $ this -> addTag ( $ tag , $ resource ) ; } } }
Adds multiple tags on the given taggable resource
51,186
public function replaceTags ( array $ tags , Taggable $ resource ) { $ resource -> getTags ( ) -> clear ( ) ; $ this -> addTags ( $ tags , $ resource ) ; }
Replaces all current tags on the given taggable resource
51,187
public function loadOrCreateTags ( array $ names ) { if ( empty ( $ names ) ) { return array ( ) ; } $ names = array_unique ( $ names ) ; $ builder = $ this -> em -> createQueryBuilder ( ) ; $ tags = $ builder -> select ( 't' ) -> from ( $ this -> tagClass , 't' ) -> where ( $ builder -> expr ( ) -> in ( 't.name' , $ names ) ) -> getQuery ( ) -> getResult ( ) ; $ loadedNames = array ( ) ; foreach ( $ tags as $ tag ) { $ loadedNames [ ] = $ tag -> getName ( ) ; } $ missingNames = array_udiff ( $ names , $ loadedNames , 'strcasecmp' ) ; if ( sizeof ( $ missingNames ) ) { foreach ( $ missingNames as $ name ) { $ tag = $ this -> createTag ( $ name ) ; $ this -> em -> persist ( $ tag ) ; $ tags [ ] = $ tag ; } $ this -> em -> flush ( ) ; } return $ tags ; }
Loads or creates multiples tags from a list of tag names
51,188
public function saveTagging ( Taggable $ resource ) { $ oldTags = $ this -> getTagging ( $ resource ) ; $ newTags = $ resource -> getTags ( ) ; $ tagsToAdd = $ newTags ; if ( $ oldTags !== null and is_array ( $ oldTags ) and ! empty ( $ oldTags ) ) { $ tagsToRemove = array ( ) ; foreach ( $ oldTags as $ oldTag ) { if ( $ newTags -> exists ( function ( $ index , $ newTag ) use ( $ oldTag ) { return $ newTag -> getName ( ) == $ oldTag -> getName ( ) ; } ) ) { $ tagsToAdd -> removeElement ( $ oldTag ) ; } else { $ tagsToRemove [ ] = $ oldTag -> getId ( ) ; } } if ( sizeof ( $ tagsToRemove ) ) { $ builder = $ this -> em -> createQueryBuilder ( ) ; $ builder -> delete ( $ this -> taggingClass , 't' ) -> where ( 't.tag_id' ) -> where ( $ builder -> expr ( ) -> in ( 't.tag' , $ tagsToRemove ) ) -> andWhere ( 't.resourceType = :resourceType' ) -> setParameter ( 'resourceType' , $ resource -> getTaggableType ( ) ) -> andWhere ( 't.resourceId = :resourceId' ) -> setParameter ( 'resourceId' , $ resource -> getTaggableId ( ) ) -> getQuery ( ) -> getResult ( ) ; } } foreach ( $ tagsToAdd as $ tag ) { $ this -> em -> persist ( $ tag ) ; $ this -> em -> persist ( $ this -> createTagging ( $ tag , $ resource ) ) ; } if ( count ( $ tagsToAdd ) ) { $ this -> em -> flush ( ) ; } }
Saves tags for the given taggable resource
51,189
public function loadTagging ( Taggable $ resource ) { $ tags = $ this -> getTagging ( $ resource ) ; $ this -> replaceTags ( $ tags , $ resource ) ; }
Loads all tags for the given taggable resource
51,190
public function deleteTagging ( Taggable $ resource ) { $ taggingList = $ this -> em -> createQueryBuilder ( ) -> select ( 't' ) -> from ( $ this -> taggingClass , 't' ) -> where ( 't.resourceType = :type' ) -> setParameter ( 'type' , $ resource -> getTaggableType ( ) ) -> andWhere ( 't.resourceId = :id' ) -> setParameter ( 'id' , $ resource -> getTaggableId ( ) ) -> getQuery ( ) -> getResult ( ) ; foreach ( $ taggingList as $ tagging ) { $ this -> em -> remove ( $ tagging ) ; } }
Deletes all tagging records for the given taggable resource
51,191
public function splitTagNames ( $ names , $ separator = ',' ) { $ tags = explode ( $ separator , $ names ) ; $ tags = array_map ( 'trim' , $ tags ) ; $ tags = array_filter ( $ tags , function ( $ value ) { return ! empty ( $ value ) ; } ) ; return array_values ( $ tags ) ; }
Splits an string into an array of valid tag names
51,192
public function getTagNames ( Taggable $ resource ) { $ names = array ( ) ; if ( sizeof ( $ resource -> getTags ( ) ) > 0 ) { foreach ( $ resource -> getTags ( ) as $ tag ) { $ names [ ] = $ tag -> getName ( ) ; } } return $ names ; }
Returns an array of tag names for the given Taggable resource .
51,193
public function get ( $ class , $ connexion , array $ exchangeOptions , array $ queueOptions , $ lazy = false , array $ qosOptions = [ ] ) { if ( ! class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( sprintf ( "Consumer class '%s' doesn't exist" , $ class ) ) ; } if ( $ lazy ) { if ( ! $ connexion -> isConnected ( ) ) { $ connexion -> connect ( ) ; } } $ channel = new $ this -> channelClass ( $ connexion ) ; if ( isset ( $ qosOptions [ 'prefetch_size' ] ) ) { $ channel -> setPrefetchSize ( $ qosOptions [ 'prefetch_size' ] ) ; } if ( isset ( $ qosOptions [ 'prefetch_count' ] ) ) { $ channel -> setPrefetchCount ( $ qosOptions [ 'prefetch_count' ] ) ; } $ this -> createExchange ( $ this -> exchangeClass , $ channel , $ exchangeOptions ) ; $ queue = new $ this -> queueClass ( $ channel ) ; if ( ! empty ( $ queueOptions [ 'name' ] ) ) { $ queue -> setName ( $ queueOptions [ 'name' ] ) ; } $ queue -> setArguments ( $ queueOptions [ 'arguments' ] ) ; $ queue -> setFlags ( ( $ queueOptions [ 'passive' ] ? AMQP_PASSIVE : AMQP_NOPARAM ) | ( $ queueOptions [ 'durable' ] ? AMQP_DURABLE : AMQP_NOPARAM ) | ( $ queueOptions [ 'exclusive' ] ? AMQP_EXCLUSIVE : AMQP_NOPARAM ) | ( $ queueOptions [ 'auto_delete' ] ? AMQP_AUTODELETE : AMQP_NOPARAM ) ) ; $ queue -> declareQueue ( ) ; if ( count ( $ queueOptions [ 'routing_keys' ] ) ) { foreach ( $ queueOptions [ 'routing_keys' ] as $ routingKey ) { $ queue -> bind ( $ exchangeOptions [ 'name' ] , $ routingKey ) ; } } else { $ queue -> bind ( $ exchangeOptions [ 'name' ] ) ; } return new $ class ( $ queue , $ queueOptions ) ; }
build the consumer class .
51,194
public function setResource ( Taggable $ resource ) { $ this -> resourceType = $ resource -> getTaggableType ( ) ; $ this -> resourceId = $ resource -> getTaggableId ( ) ; }
Sets the resource
51,195
public function purge ( ) { if ( $ this -> eventDispatcher ) { $ purgeEvent = new PurgeEvent ( $ this -> queue ) ; $ this -> eventDispatcher -> dispatch ( PurgeEvent :: NAME , $ purgeEvent ) ; } return $ this -> call ( $ this -> queue , 'purge' ) ; }
Purge the contents of the queue .
51,196
public function getCurrentMessageCount ( ) { $ flags = $ this -> queue -> getFlags ( ) ; $ this -> queue -> setFlags ( $ flags | AMQP_PASSIVE ) ; $ messagesCount = $ this -> queue -> declareQueue ( ) ; $ this -> queue -> setFlags ( $ flags ) ; return $ messagesCount ; }
Get the current message count .
51,197
public function getTagsWithCountArray ( $ taggableType , $ limit = null ) { $ qb = $ this -> getTagsWithCountArrayQueryBuilder ( $ taggableType ) ; if ( null !== $ limit ) { $ qb -> setMaxResults ( $ limit ) ; } $ tags = $ qb -> getQuery ( ) -> getResult ( AbstractQuery :: HYDRATE_SCALAR ) ; $ arr = array ( ) ; foreach ( $ tags as $ tag ) { $ count = $ tag [ 'tag_count' ] ; if ( $ count > 0 ) { $ tagName = $ tag [ $ this -> tagQueryField ] ; $ arr [ $ tagName ] = $ count ; } } return $ arr ; }
For a specific taggable type this returns an array where they key is the tag and the value is the number of times that tag is used
51,198
public function getTagsWithCountArrayQueryBuilder ( $ taggableType ) { $ qb = $ this -> getTagsQueryBuilder ( $ taggableType ) -> groupBy ( 'tagging.tag' ) -> select ( 'tag.' . $ this -> tagQueryField . ', COUNT(tagging.tag) as tag_count' ) -> orderBy ( 'tag_count' , 'DESC' ) ; return $ qb ; }
Returns a query builder built to return tag counts for a given type
51,199
public function onCommand ( $ event ) { $ this -> data [ 'commands' ] [ ] = array ( 'command' => $ event -> getCommand ( ) , 'arguments' => $ event -> getArguments ( ) , 'executiontime' => $ event -> getExecutionTime ( ) , ) ; }
Listen for command event .