idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
20,900 | public static function applyNamingConvention ( string $ namespace , string $ path , ? string $ node , string $ name , ? string $ suffix = null ) { if ( null === $ node ) { return sprintf ( '%s\%s\%s%s' , $ namespace , $ path , ucfirst ( $ name ) , $ suffix ) ; } return sprintf ( '%s\%s\%s\%s%s' , $ namespace , $ path , $ node , ucfirst ( $ name ) , $ suffix ) ; } | Apply a naming convention based on namespace and path for given node |
20,901 | public static function insertTemplatePF ( $ parser , $ template , $ spot = '' ) { $ params = array ( ) ; $ template = preg_replace ( '/[^A-Za-z0-9_\-]/' , '_' , $ template ) ; return '<p>ADDTEMPLATE(' . $ spot . '):' . $ template . ':ETALPMETDDA</p>' ; } | render a template from a skin template file ... |
20,902 | public static function getSkin ( $ context , & $ skin ) { if ( ! isset ( $ _GET [ 'useskin' ] ) ) { $ key = $ GLOBALS [ 'wgDefaultSkin' ] ; if ( self :: $ pageSkin ) { $ key = new self :: $ pageSkin ; } $ key = \ Skin :: normalizeKey ( $ key ) ; $ skinNames = \ Skin :: getSkinNames ( ) ; $ skinName = $ skinNames [ $ key ] ; $ className = "\Skin{$skinName}" ; if ( class_exists ( $ className ) ) { $ skin = new $ className ( ) ; if ( isset ( self :: $ skinLayout ) && method_exists ( $ skin , 'setLayout' ) ) { $ skin -> setLayout ( self :: $ skinLayout ) ; } } } self :: $ skin = $ skin ; return true ; } | hook for RequestContextCreateSkin |
20,903 | public function table ( $ model ) { return $ this -> table -> of ( 'control.roles' , function ( TableGrid $ table ) use ( $ model ) { $ table -> with ( $ model ) -> paginate ( true ) ; $ table -> sortable ( ) ; $ table -> searchable ( [ 'name' ] ) ; $ table -> layout ( 'orchestra/foundation::components.table' ) ; $ table -> column ( trans ( 'orchestra/foundation::label.name' ) , 'name' ) ; } ) ; } | View table generator for Orchestra \ Model \ Role . |
20,904 | protected function addEditButton ( Eloquent $ role ) { $ link = handles ( "orchestra::control/roles/{$role->id}/edit" ) ; $ text = trans ( 'orchestra/foundation::label.edit' ) ; $ attributes = [ 'class' => 'btn btn-xs btn-label btn-warning' ] ; return app ( 'html' ) -> link ( $ link , $ text , $ attributes ) ; } | Add edit button . |
20,905 | public function form ( Eloquent $ model ) { return $ this -> form -> of ( 'control.roles' , function ( FormGrid $ form ) use ( $ model ) { $ form -> resource ( $ this , 'orchestra::control/roles' , $ model ) ; $ form -> hidden ( 'id' ) ; $ form -> fieldset ( function ( Fieldset $ fieldset ) { $ fieldset -> control ( 'input:text' , 'name' ) -> label ( trans ( 'orchestra/control::label.name' ) ) ; } ) ; } ) ; } | View form generator for Orchestra \ Model \ Role . |
20,906 | public function SaveFile ( $ Key , $ Index = 0 , $ TargetPath = '' ) { if ( ! isset ( $ this -> Data [ $ Key ] ) ) { return false ; } if ( ! isset ( $ this -> Data [ $ Key ] [ $ Index ] ) ) { return false ; } if ( stripos ( $ this -> Data [ $ Key ] [ $ Index ] [ 'Value' ] , 'uri:' ) === 0 ) { return false ; } if ( is_writable ( $ TargetPath ) || ( ! file_exists ( $ TargetPath ) && is_writable ( dirname ( $ TargetPath ) ) ) ) { $ RawContent = $ this -> Data [ $ Key ] [ $ Index ] [ 'Value' ] ; if ( isset ( $ this -> Data [ $ Key ] [ $ Index ] [ 'Encoding' ] ) && $ this -> Data [ $ Key ] [ $ Index ] [ 'Encoding' ] == 'b' ) { $ RawContent = base64_decode ( $ RawContent ) ; } $ Status = file_put_contents ( $ TargetPath , $ RawContent ) ; return ( bool ) $ Status ; } else { throw new Exception ( 'vCard: Cannot save file (' . $ Key . '), target path not writable (' . $ TargetPath . ')' ) ; } return false ; } | Saves an embedded file |
20,907 | private static function ParseStructuredValue ( $ Text , $ Key ) { $ Text = array_map ( 'trim' , explode ( ';' , $ Text ) ) ; $ Result = array ( ) ; $ Ctr = 0 ; foreach ( self :: $ Spec_StructuredElements [ $ Key ] as $ Index => $ StructurePart ) { $ Result [ $ StructurePart ] = isset ( $ Text [ $ Index ] ) ? $ Text [ $ Index ] : null ; } return $ Result ; } | Separates the various parts of a structured value according to the spec . |
20,908 | public static function prepareReport ( Report $ report ) { $ contents = Report :: getReportFileContents ( $ report -> getFullPath ( ) ) ; $ report -> content = $ contents ; return $ report ; } | no need to instantiate a report object just return the source |
20,909 | public function call ( string $ method , array $ arguments ) : ResponseInterface { try { return $ this -> __soapCall ( $ method , $ arguments , null , $ this -> getHeader ( ) ) ; } catch ( \ Exception $ e ) { $ exception = new ClientException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; if ( $ this -> debug ) { $ exception -> request = ClientException :: formatXml ( $ this -> __getLastRequest ( ) ) ; $ exception -> response = ClientException :: formatXml ( $ this -> __getLastResponse ( ) ) ; } throw $ exception ; } } | Performs the soap call . |
20,910 | protected function getHeader ( ) : \ SoapHeader { if ( $ this -> header ) { return $ this -> header ; } return $ this -> header = new \ SoapHeader ( static :: NAMESPACE , 'UserCredentials' , [ 'userid' => $ this -> login , 'password' => $ this -> password , ] ) ; } | Returns the header . |
20,911 | public function read ( ) : ? TimePoint { try { $ datetime = new DateTime ( $ this -> current , $ this -> timezone ) ; } catch ( BaseException $ e ) { return null ; } return $ this -> fromDateTime ( $ datetime ) ; } | Get the current TimePoint |
20,912 | public function fromString ( $ input , $ format = null ) : ? TimePoint { if ( $ format === null ) { $ formats = [ 'Y-m-d\TH:i:sP' , 'Y-m-d\TH:i:s.uP' , 'Y-m-d\TH:i:sO' , 'Y-m-d\TH:i:s.uO' , 'Y-m-d\TH:i:s,uO' , 'Y-m-d\TH:iO' , ] ; do { $ datetime = DateTime :: createFromFormat ( array_shift ( $ formats ) , $ input , $ this -> timezone ) ; } while ( ! $ datetime instanceof DateTime && count ( $ formats ) > 0 ) ; } else { $ datetime = DateTime :: createFromFormat ( $ format , $ input , $ this -> timezone ) ; } return ( $ datetime instanceof DateTime ) ? $ this -> fromDateTime ( $ datetime ) : null ; } | Get a TimePoint from a formatted string |
20,913 | public function inRange ( TimePoint $ expiration , TimePoint $ creation = null , $ skew = null ) : bool { $ now = $ this -> read ( ) ; if ( $ skew !== null ) { if ( $ creation instanceof TimePoint ) { $ creation = $ creation -> modify ( sprintf ( '-%s' , $ skew ) ) ; } $ expiration = $ expiration -> modify ( sprintf ( '+%s' , $ skew ) ) ; } return $ now -> compare ( $ expiration ) !== 1 && ( ! $ creation instanceof TimePoint || $ now -> compare ( $ creation ) !== - 1 ) ; } | Check that the current time is within a specified range |
20,914 | public function validateActivationKey ( $ email , $ activationKey ) { $ query = $ this -> findByEmailAndActivationKey ( $ email , $ activationKey ) ; if ( $ query -> Count ( ) > 0 ) { return true ; } return false ; } | Checks if an user is allowed to do an action with a required activation - key |
20,915 | public function activateUser ( $ email , $ activationKey ) { if ( $ this -> validateActivationKey ( $ email , $ activationKey ) ) { $ user = $ this -> findByEmailAndActivationKey ( $ email , $ activationKey ) -> first ( ) ; if ( $ user -> active == 0 ) { $ user -> active = 1 ; $ user -> activation_key = null ; if ( $ this -> save ( $ user ) ) { return true ; } } } return false ; } | Activates an user |
20,916 | public final function lookup ( $ funcName ) { if ( isset ( self :: $ functions [ $ funcName ] ) ) { return self :: $ functions [ $ funcName ] ; } return ( self :: $ functions [ $ funcName ] = $ this -> create ( $ funcName ) ) ; } | Returns the instance of the Function class that handles the requested function . If it was not loaded yet tries to instanciate by calling the overriden create method . Returns null if the factory could not produce an instance . |
20,917 | public static function create ( $ code , $ message = null , $ category = null ) { return new class ( $ message , $ code , $ category ) extends ControlledError { protected $ category ; public function __construct ( $ message , $ code , $ category = null ) { if ( $ category ) { $ this -> category = $ category ; } parent :: __construct ( $ message , $ code ) ; } public function getCategory ( ) : string { return $ this -> category ?? parent :: getCategory ( ) ; } } ; } | Throw a controlled error dynamically |
20,918 | protected function parseAttributes ( $ figNamespace , array $ attributes ) { if ( ! $ this -> figCall ) { foreach ( $ attributes as $ name => $ value ) { if ( strpos ( $ name , $ figNamespace ) === 0 ) { continue ; } if ( preg_match ( '/\|(.+)\|(.+)\|$/' , $ value , $ matches ) ) { $ attributes [ $ name ] = new InlineCondAttr ( $ matches [ 1 ] , $ matches [ 2 ] ) ; $ this -> isDirective = true ; continue ; } if ( preg_match_all ( '/\{([^\{]+)\}/' , $ value , $ matches , PREG_OFFSET_CAPTURE ) ) { $ parts = [ ] ; $ previousPosition = 0 ; $ nMatches = count ( $ matches [ 0 ] ) ; for ( $ i = 0 ; $ i < $ nMatches ; ++ $ i ) { $ expression = $ matches [ 1 ] [ $ i ] [ 0 ] ; $ position = $ matches [ 1 ] [ $ i ] [ 1 ] ; if ( $ position > $ previousPosition + 1 ) { $ parts [ ] = substr ( $ value , $ previousPosition , $ position - 1 - $ previousPosition ) ; } $ parts [ ] = new AdHoc ( $ expression ) ; $ this -> isDirective = true ; $ previousPosition = $ position + strlen ( $ expression ) + 1 ; } if ( $ previousPosition < strlen ( $ value ) ) { $ parts [ ] = substr ( $ value , $ previousPosition ) ; } if ( count ( $ parts ) == 1 ) { $ parts = $ parts [ 0 ] ; } $ attributes [ $ name ] = $ parts ; } } } $ this -> attributes = $ attributes ; } | Split attributes by adhoc parts and store the resulting array in the object member . |
20,919 | private function buildXMLAttributesString ( Context $ context ) { $ result = '' ; $ matches = null ; $ attributes = $ this -> attributes ; $ runtimeAttributes = $ context -> getRuntimeAttributes ( ) ; foreach ( $ runtimeAttributes as $ attributeName => $ runtimeAttr ) { $ attributes [ $ attributeName ] = $ runtimeAttr ; } foreach ( $ attributes as $ attribute => $ value ) { if ( ! $ context -> view -> isFigPrefix ( $ attribute ) ) { if ( $ value instanceof Flag ) { $ result .= " $attribute" ; } else { if ( $ value instanceof InlineCondAttr ) { $ inlineCondAttr = $ value ; if ( $ this -> evaluate ( $ context , $ inlineCondAttr -> cond ) ) { $ value = $ this -> evaluate ( $ context , $ inlineCondAttr -> val ) ; } else { continue ; } } if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } $ combined = '' ; foreach ( $ value as $ part ) { if ( $ part instanceof AdHoc ) { $ evaluatedValue = $ this -> evaluate ( $ context , $ part -> string ) ; if ( $ evaluatedValue instanceof ViewElement ) { $ evaluatedValue = $ evaluatedValue -> render ( $ context ) ; } if ( is_array ( $ evaluatedValue ) ) { if ( empty ( $ evaluatedValue ) ) { $ evaluatedValue = '' ; } else { $ message = 'Adhoc {' . $ part -> string . '} of attribute ' . $ attribute . ' in tag "' . $ this -> name . '" evaluated to array.' ; throw new TagRenderingException ( $ this -> getTagName ( ) , $ this -> getLineNumber ( ) , $ message ) ; } } else if ( is_object ( $ evaluatedValue ) && ( $ evaluatedValue instanceof \ DOMNode ) ) { $ evaluatedValue = $ evaluatedValue -> nodeValue ; } if ( is_object ( $ evaluatedValue ) ) { $ evaluatedValue = '### Object of class: ' . get_class ( $ evaluatedValue ) . ' ###' ; } else { $ evaluatedValue = htmlspecialchars ( $ evaluatedValue ) ; } $ part = $ evaluatedValue ; } $ combined .= $ part ; } $ value = $ combined ; $ result .= " $attribute=\"$value\"" ; } } } return $ result ; } | Returns a string containing the space - separated list of XML attributes of an element . |
20,920 | protected function evalAttribute ( Context $ context , $ name ) { $ expression = $ this -> getAttribute ( $ name , false ) ; if ( $ expression ) { return $ this -> evaluate ( $ context , $ expression ) ; } return false ; } | Evaluates the expression written in specified attribute . If attribute does not exist returns false . |
20,921 | private function applyOutputFilter ( Context $ context , $ buffer ) { if ( $ this -> figFilter ) { $ filterClass = $ this -> figFilter ; $ filter = $ this -> instantiateFilter ( $ context , $ filterClass ) ; $ buffer = $ filter -> transform ( $ buffer ) ; } return $ buffer ; } | Applies a filter to the inner contents of an element . Returns the filtered output . |
20,922 | private function replaceLastChild_cdata ( ViewElementCData $ cdata ) { $ n = count ( $ this -> children ) ; if ( ( $ n > 1 ) && ( $ this -> children [ $ n - 2 ] instanceof ViewElementCData ) ) { $ this -> children [ $ n - 2 ] -> outputBuffer .= $ cdata -> outputBuffer ; array_pop ( $ this -> children ) ; } else { $ cdata -> parent = $ this ; $ this -> children [ $ n - 1 ] = $ cdata ; } } | If the last but one child is already a CData squash them together . |
20,923 | private function inspectApplication ( ) { $ this -> commands = [ ] ; $ this -> namespaces = [ ] ; $ all = $ this -> application -> getAllCommands ( $ this -> namespace ? $ this -> application -> findNamespace ( $ this -> namespace ) : '' ) ; foreach ( $ this -> sortCommands ( $ all ) as $ namespace => $ commands ) { $ names = [ ] ; foreach ( $ commands as $ name => $ command ) { if ( ! $ command -> getName ( ) || ( ! $ this -> showHidden && $ command -> isHidden ( ) ) ) { continue ; } if ( $ command -> getName ( ) === $ name ) { $ this -> commands [ $ name ] = $ command ; } else { $ this -> aliases [ $ name ] = $ command ; } $ names [ ] = $ name ; } $ this -> namespaces [ $ namespace ] = [ 'id' => $ namespace , 'commands' => $ names ] ; } } | Inspects the application . |
20,924 | private function sortCommands ( array $ commands ) : array { $ namespacedCommands = [ ] ; $ globalCommands = [ ] ; foreach ( $ commands as $ name => $ command ) { $ key = $ this -> extractNamespace ( $ name , 1 ) ; if ( ! $ key ) { $ globalCommands [ self :: GLOBAL_NAMESPACE ] [ $ name ] = $ command ; } else { $ namespacedCommands [ $ key ] [ $ name ] = $ command ; } } ksort ( $ namespacedCommands ) ; $ namespacedCommands = array_merge ( $ globalCommands , $ namespacedCommands ) ; foreach ( $ namespacedCommands as & $ commandsSet ) { ksort ( $ commandsSet ) ; } unset ( $ commandsSet ) ; return $ namespacedCommands ; } | Sort a set of commands . |
20,925 | public function getConfig ( ) : array { $ ref = new \ ReflectionClass ( get_class ( $ this ) ) ; $ properties = $ ref -> getProperties ( ) ; $ config = [ ] ; foreach ( $ properties as $ property ) { $ value = $ property -> getValue ( $ this ) ; if ( null !== $ value ) { $ config [ Inflector :: tableize ( $ property -> getName ( ) ) ] = $ property -> getValue ( $ this ) ; } } return $ config ; } | Must return the array with plugin config |
20,926 | public function getTrackingUrl ( ) { if ( ! isset ( $ this -> parcelnumber ) ) { throw new RuntimeException ( "Shipment has no parcel number." ) ; } return sprintf ( Api :: TRACKING_URL , $ this -> parcelnumber ) ; } | Returns the tracking url . |
20,927 | public function addFilter ( $ query , $ value = null ) { if ( $ value ) { $ query = "$query:$value" ; } $ this -> filters [ $ query ] = $ query ; return $ this ; } | Add a filter query clause . |
20,928 | public function removeFilter ( $ query , $ value = null ) { if ( $ value ) { $ query = "$query:$value" ; } unset ( $ this -> filters [ $ query ] ) ; return $ this ; } | Remove a filter in place on this query |
20,929 | public function restrictNearPoint ( $ point , $ field , $ radius ) { $ this -> addFilter ( "{!geofilt}" ) ; $ this -> params [ 'sfield' ] = $ field ; $ this -> params [ 'pt' ] = $ point ; $ this -> params [ 'd' ] = $ radius ; return $ this ; } | Apply a geo field restriction around a particular point |
20,930 | public function toRoute ( $ name , array $ args = [ ] , $ code = 307 ) { $ to = $ this -> getRoute ( $ name , $ args ) ; header ( "location: {$to}" , true , $ code ) ; exit ; } | Redirect to a route |
20,931 | public function crud ( $ pattern , $ callback , array $ params = [ ] ) { if ( ! is_string ( $ callback ) ) { throw new \ Exception ( 'Crud callbacks must be a string to a controller class' ) ; } if ( ! empty ( $ params [ 'name' ] ) ) { $ name = $ params [ 'name' ] ; } $ pattern = rtrim ( $ pattern , '/' ) ; $ params [ 'name' ] = $ name ? $ name . '.create' : null ; $ this -> post ( "{$pattern}" , "{$callback}@create" , $ params ) ; $ params [ 'name' ] = $ name ? $ name . '.one' : null ; $ this -> get ( "{$pattern}/(:any)" , "{$callback}@one" , $ params ) ; $ params [ 'name' ] = $ name ? $ name . '.many' : null ; $ this -> get ( "{$pattern}" , "{$callback}@many" , $ params ) ; $ params [ 'name' ] = $ name ? $ name . '.update' : null ; $ this -> put ( "{$pattern}/(:any)" , "{$callback}@update" , $ params ) ; $ params [ 'name' ] = $ name ? $ name . '.delete' : null ; $ this -> delete ( "{$pattern}/(:any)" , "{$callback}@delete" , $ params ) ; return $ this ; } | Add crud routes for a controller |
20,932 | public function group ( array $ params , $ callback ) { $ prefix = trim ( $ this -> getParam ( $ params , 'prefix' ) , '/' ) ; $ before = $ this -> getParam ( $ params , 'before' ) ; $ after = $ this -> getParam ( $ params , 'after' ) ; if ( $ prefix ) { $ this -> prefixes [ ] = $ prefix ; $ this -> prefix = '/' . trim ( implode ( '/' , $ this -> prefixes ) , '/' ) ; } if ( $ before ) { $ this -> befores [ ] = $ before ; $ this -> before = explode ( '|' , implode ( '|' , $ this -> befores ) ) ; } if ( $ after ) { $ this -> afters [ ] = $ after ; $ this -> after = explode ( '|' , implode ( '|' , $ this -> afters ) ) ; } call_user_func_array ( $ callback , [ $ this ] ) ; if ( $ prefix ) { array_pop ( $ this -> prefixes ) ; $ this -> prefix = $ this -> prefixes ? '/' . trim ( implode ( '/' , $ this -> prefixes ) , '/' ) : null ; } if ( $ before ) { array_pop ( $ this -> befores ) ; $ this -> before = explode ( '|' , implode ( '|' , $ this -> befores ) ) ; } if ( $ after ) { array_pop ( $ this -> afters ) ; $ this -> after = explode ( '|' , implode ( '|' , $ this -> afters ) ) ; } return $ this ; } | Create a new route group |
20,933 | public function getMatch ( $ method = null , $ path = null ) { $ method = $ method ? : $ this -> getRequestMethod ( ) ; $ path = $ path ? : $ this -> getRequestPath ( ) ; $ method = strtoupper ( $ method ) ; $ methodNotAllowed = null ; foreach ( $ this -> routes as $ pattern => $ methods ) { preg_match ( $ this -> regexifyPattern ( $ pattern ) , $ path , $ matches ) ; if ( $ matches ) { $ r = $ this -> getRouteObject ( $ pattern , $ method ) ; if ( ! $ r ) { $ methodNotAllowed = true ; continue ; } $ r -> method = strtoupper ( $ method ) ; $ r -> args = $ this -> getMatchArgs ( $ matches ) ; return $ r ; } } if ( $ methodNotAllowed ) { if ( $ this -> methodNotAllowed ) { return ( object ) [ 'before' => [ ] , 'after' => [ ] , 'args' => [ ] , 'callback' => & $ this -> methodNotAllowed , ] ; } throw new MethodNotAllowedException ; } if ( $ this -> notFound ) { return ( object ) [ 'before' => [ ] , 'after' => [ ] , 'args' => [ ] , 'callback' => & $ this -> notFound , ] ; } throw new NotFoundException ; } | Get matching route |
20,934 | public function dispatch ( $ method = null , $ path = null ) { $ match = $ this -> getMatch ( $ method , $ path ) ; foreach ( $ match -> before as $ filter ) { if ( empty ( $ filter ) ) { continue ; } $ response = $ this -> executeCallback ( $ this -> getFilterCallback ( $ filter ) , $ match -> args , true ) ; if ( ! is_null ( $ response ) ) { return $ response ; } } $ routeResponse = $ this -> executeCallback ( $ match -> callback , $ match -> args ) ; foreach ( $ match -> after as $ filter ) { if ( empty ( $ filter ) ) { continue ; } array_unshift ( $ match -> args , $ routeResponse ) ; $ response = $ this -> executeCallback ( $ this -> getFilterCallback ( $ filter ) , $ match -> args , true ) ; if ( ! is_null ( $ response ) ) { return $ response ; } } return $ routeResponse ; } | Get matching route and dispatch all filters and callbacks |
20,935 | public function executeCallback ( $ cb , array $ args = [ ] , $ filter = false ) { if ( $ cb instanceof Closure ) { return call_user_func_array ( $ cb , $ args ) ; } if ( is_string ( $ cb ) && strpos ( $ cb , "@" ) !== false ) { $ cb = explode ( '@' , $ cb ) ; } if ( is_array ( $ cb ) && count ( $ cb ) == 2 ) { if ( ! is_object ( $ cb [ 0 ] ) ) { $ cb = $ this -> resolveCallback ( $ cb ) ; } if ( isset ( $ cb [ 0 ] , $ cb [ 1 ] ) && is_object ( $ cb [ 0 ] ) && ! method_exists ( $ cb [ 0 ] , $ cb [ 1 ] ) ) { $ name = get_class ( $ cb [ 0 ] ) ; throw new ControllerNotFoundException ( "Controller '{$name}->{$cb[1]}' not found" ) ; } return call_user_func_array ( $ cb , $ args ) ; } if ( is_string ( $ cb ) && strpos ( $ cb , "::" ) !== false ) { return call_user_func_array ( $ cb , $ args ) ; } throw new Exception ( 'Invalid callback' ) ; } | Execute a callback |
20,936 | public function getRoute ( $ name , array $ args = [ ] ) { if ( ! isset ( $ this -> names [ $ name ] ) ) { return null ; } $ route = $ this -> callbacks [ $ this -> names [ $ name ] ] ; if ( strpos ( $ route -> pattern , '(' ) === false ) { return $ route -> pattern ; } $ from = [ '/(\([^\/]+[\)]+[\?])/' , '/(\([^\/]+\))/' ] ; $ to = [ '%o' , '%r' ] ; $ pattern = preg_replace ( $ from , $ to , $ route -> pattern ) ; $ frags = explode ( '/' , trim ( $ pattern , '/' ) ) ; $ url = [ ] ; foreach ( $ frags as $ frag ) { if ( $ frag == '%r' ) { if ( ! $ args ) { throw new Exception ( 'Missing route parameters' ) ; } $ url [ ] = array_shift ( $ args ) ; continue ; } if ( $ frag == "%o" ) { if ( ! $ args ) { continue ; } $ url [ ] = array_shift ( $ args ) ; continue ; } $ url [ ] = $ frag ; } return '/' . implode ( '/' , $ url ) ; } | Get the URL of a named route |
20,937 | protected function regexifyPattern ( $ pattern ) { preg_match_all ( '/(\/?)\(:([^)]*)\)(\??)/' , $ pattern , $ regExPatterns , PREG_SET_ORDER , 0 ) ; $ pattern = preg_quote ( $ pattern , '/' ) ; foreach ( $ regExPatterns as $ regExPattern ) { if ( ! empty ( $ regExPattern [ 2 ] ) && key_exists ( $ regExPattern [ 2 ] , $ this -> patterns ) ) { $ replacement = sprintf ( '(%s%s)%s' , empty ( $ regExPattern [ 1 ] ) ? '' : '\/' , $ this -> patterns [ $ regExPattern [ 2 ] ] , $ regExPattern [ 3 ] ) ; $ pattern = str_replace ( preg_quote ( $ regExPattern [ 0 ] , '/' ) , $ replacement , $ pattern ) ; } } return "/^$pattern$/" ; } | Replace placeholders to regular expressions |
20,938 | protected function getRouteObject ( $ pattern , $ method ) { foreach ( [ 'REDIRECT' , $ method , 'ANY' ] as $ verb ) { if ( array_key_exists ( $ verb , $ this -> routes [ $ pattern ] ) ) { $ index = $ this -> routes [ $ pattern ] [ $ verb ] ; return $ this -> callbacks [ $ index ] ; } } return false ; } | Get matched route from pattern and method |
20,939 | protected function getMatchArgs ( array $ match ) { array_shift ( $ match ) ; foreach ( $ match as & $ arg ) { $ arg = trim ( $ arg , '/' ) ; } return $ match ; } | Get and clean route arguments |
20,940 | protected function storeRoute ( array $ methods , array $ route ) { $ this -> callbacks [ ] = ( object ) $ route ; $ index = count ( $ this -> callbacks ) - 1 ; if ( ! isset ( $ this -> routes [ $ route [ 'pattern' ] ] ) ) { $ this -> routes [ $ route [ 'pattern' ] ] = [ ] ; } if ( $ route [ 'name' ] ) { $ this -> names [ $ route [ 'name' ] ] = $ index ; } foreach ( $ methods as $ method ) { $ this -> routes [ $ route [ 'pattern' ] ] [ strtoupper ( $ method ) ] = $ index ; } } | Store a route in the route collection |
20,941 | protected function interpolate ( $ message , $ context = array ( ) ) { $ replace = array ( ) ; foreach ( $ context as $ key => $ value ) { $ replace [ '{' . $ key . '}' ] = $ value ; } return strtr ( $ message , $ replace ) ; } | Interpolate log message |
20,942 | protected function resolveInterfaceExtension ( InterfaceDefinition $ definition , Endpoint $ endpoint ) : void { $ bundleNamespace = ClassUtils :: relatedBundleNamespace ( $ definition -> getClass ( ) ) ; $ extensionClass = ClassUtils :: applyNamingConvention ( $ bundleNamespace , 'Extension' , null , $ definition -> getName ( ) . 'Extension' ) ; if ( class_exists ( $ extensionClass ) ) { foreach ( $ definition -> getImplementors ( ) as $ implementor ) { $ definition -> addExtension ( $ extensionClass ) ; $ object = $ endpoint -> getType ( $ implementor ) ; if ( $ object instanceof HasExtensionsInterface ) { $ object -> addExtension ( $ extensionClass ) ; } } } } | Using naming convention resolve CRUD extension for given interface definition and automatically register this extension for all interface implementors |
20,943 | protected function resolveObjectRealInterfaceExtensions ( ClassAwareDefinitionInterface $ definition ) : void { $ class = $ definition -> getClass ( ) ; if ( class_exists ( $ class ) ) { $ refClass = new \ ReflectionClass ( $ definition -> getClass ( ) ) ; if ( $ interfaces = $ refClass -> getInterfaceNames ( ) ) { foreach ( $ interfaces as $ interface ) { $ bundleNamespace = ClassUtils :: relatedBundleNamespace ( $ interface ) ; if ( preg_match ( '/(\w+)Interface?$/' , $ interface , $ matches ) ) { $ extensionClass = ClassUtils :: applyNamingConvention ( $ bundleNamespace , 'Extension' , null , $ matches [ 1 ] . 'Extension' ) ; if ( class_exists ( $ extensionClass ) ) { if ( $ definition instanceof HasExtensionsInterface ) { $ definition -> addExtension ( $ extensionClass ) ; } } } } } } } | Using naming convention resolve all extensions for given object based on implemented interfaces . |
20,944 | public function getHttpTransport ( ) { if ( $ this -> _httpTransport === false ) { require_once ( dirname ( __FILE__ ) . '/HttpTransport/FileGetContents.php' ) ; $ this -> _httpTransport = new Apache_Solr_HttpTransport_FileGetContents ( ) ; } return $ this -> _httpTransport ; } | Get the current configured HTTP Transport |
20,945 | public function add ( TranslatorInterface $ translator ) { $ hash = spl_object_hash ( $ translator ) ; $ this -> translators [ $ hash ] = $ translator ; return $ this ; } | Add a translator to the chain . |
20,946 | public function remove ( TranslatorInterface $ translator ) { $ hash = spl_object_hash ( $ translator ) ; unset ( $ this -> translators [ $ hash ] ) ; return $ this ; } | Remove a translator from the chain . |
20,947 | public function loadFile ( $ filename ) { $ this -> filename = $ filename ; if ( $ this -> cachePath ) { if ( ! $ this -> templatesRoot ) { $ this -> templatesRoot = dirname ( $ filename ) ; } $ cacheFile = $ this -> makeCacheFilename ( $ this -> cachePath , $ this -> templatesRoot , $ this -> filename ) ; if ( file_exists ( $ cacheFile ) && ( ! file_exists ( $ this -> filename ) || ( filemtime ( $ this -> filename ) < filemtime ( $ cacheFile ) ) ) ) { $ this -> loadFromSerialized ( file_get_contents ( $ cacheFile ) ) ; return ; } } if ( file_exists ( $ filename ) ) { $ this -> source = file_get_contents ( $ filename ) ; } else { $ message = "File not found: $filename" ; throw new FileNotFoundException ( $ message , $ filename ) ; } } | Load from source file . |
20,948 | public function parse ( ) { if ( $ this -> bParsed ) { return ; } if ( $ this -> replacements ) { $ this -> source = XMLEntityTransformer :: replace ( $ this -> source ) ; } $ this -> xmlParser = xml_parser_create ( 'UTF-8' ) ; xml_parser_set_option ( $ this -> xmlParser , XML_OPTION_CASE_FOLDING , false ) ; xml_set_object ( $ this -> xmlParser , $ this ) ; xml_set_element_handler ( $ this -> xmlParser , 'openTagHandler' , 'closeTagHandler' ) ; xml_set_character_data_handler ( $ this -> xmlParser , 'cdataHandler' ) ; $ this -> firstOpening = true ; try { $ bSuccess = xml_parse ( $ this -> xmlParser , $ this -> source ) ; } catch ( RequiredAttributeException $ ex ) { throw $ ex -> setFile ( $ this -> filename ) ; } if ( $ bSuccess ) { $ errMsg = '' ; $ lineNumber = 0 ; } else { $ errMsg = xml_error_string ( xml_get_error_code ( $ this -> xmlParser ) ) ; $ lineNumber = xml_get_current_line_number ( $ this -> xmlParser ) ; if ( count ( $ this -> stack ) ) { $ lastElement = $ this -> stack [ count ( $ this -> stack ) - 1 ] ; if ( $ lastElement instanceof ViewElementTag ) { $ errMsg .= '. Last element: ' . $ lastElement -> getTagName ( ) . '(' . $ lineNumber . ')' ; } } } xml_parser_free ( $ this -> xmlParser ) ; $ this -> bParsed = $ bSuccess ; if ( ! $ bSuccess ) { throw new XMLParsingException ( $ errMsg , $ lineNumber ) ; } if ( ( $ this -> cachePath ) && ( $ this -> filename !== null ) && ( ! $ this -> unserialized ) ) { $ cacheFile = $ this -> makeCacheFilename ( $ this -> cachePath , $ this -> templatesRoot , $ this -> filename , true ) ; file_put_contents ( $ cacheFile , serialize ( $ this ) ) ; } } | Parse source . |
20,949 | private function makeCacheFilename ( $ cachePath , $ templatesRoot , $ filename , $ mkdir = false ) { if ( ( substr ( $ filename , 0 , 1 ) != '/' ) && ! parse_url ( $ filename , PHP_URL_SCHEME ) ) { $ filename = getcwd ( ) . '/' . $ filename ; } $ cacheFile = str_replace ( $ templatesRoot , $ cachePath . '/figs' , $ filename ) . '.fig' ; if ( $ mkdir ) { $ intermed = dirname ( $ cacheFile ) ; if ( ! file_exists ( $ intermed ) ) { mkdir ( $ intermed , 0700 , true ) ; } } return $ cacheFile ; } | The compiled file is at the same subfolder location as the source file relative to the templatesRoot directory but under the tempPath directory . In other words tempPath and templatesRoot correspond together . |
20,950 | public function render ( ) { if ( ! $ this -> bParsed ) { $ this -> parse ( ) ; } if ( ! $ this -> rootNode ) { throw new XMLParsingException ( 'No template file loaded' , 0 ) ; } $ context = new Context ( $ this ) ; if ( $ this -> rootNode instanceof ViewElementTag ) { $ context -> setDoctype ( $ this -> rootNode -> getAttribute ( $ this -> figNamespace . 'doctype' ) ) ; } try { $ result = $ this -> rootNode -> render ( $ context ) ; } catch ( RequiredAttributeException $ ex ) { throw $ ex -> setFile ( $ context -> getFilename ( ) ) ; } catch ( TagRenderingException $ ex ) { throw new RenderingException ( $ ex -> getTag ( ) , $ context -> getFilename ( ) , $ ex -> getLine ( ) , $ ex -> getMessage ( ) , $ ex ) ; } catch ( FeedClassNotFoundException $ ex ) { throw $ ex -> setFile ( $ context -> getFilename ( ) ) ; } $ result = $ this -> plugIntoSlots ( $ context , $ result ) ; if ( $ context -> getDoctype ( ) ) { $ result = '<!doctype ' . $ context -> getDoctype ( ) . '>' . "\n" . $ result ; } return $ result ; } | Process parsed source and render view using the data universe . |
20,951 | public function setCachePath ( $ path , $ templatesRoot = null ) { $ this -> cachePath = preg_replace ( '#/+$#' , '' , $ path ) ; $ this -> templatesRoot = preg_replace ( '#/+$#' , '' , $ templatesRoot ) ; } | Specifies the folder in which the engine will be able to produce temporary files for JIT - compilation and caching purposes . The engine will not attempt to use cache - based optimization features if you leave this property blank . |
20,952 | private function cdataHandler ( $ xmlParser , $ cdata ) { $ currentElement = $ this -> stack [ count ( $ this -> stack ) - 1 ] ; $ currentElement -> appendCDataChild ( $ cdata ) ; $ this -> previousCData .= $ cdata ; } | XML parser handler for CDATA |
20,953 | public function getParameter ( $ paramName ) { if ( isset ( $ this -> params [ $ paramName ] ) ) { return $ this -> params [ $ paramName ] ; } return null ; } | Returns a Feed parameter leaving it untyped . Can be used to retrieve arrays in particular . |
20,954 | protected function getState ( $ key ) { if ( ! Yii :: $ app -> has ( 'session' ) ) { return null ; } $ session = Yii :: $ app -> get ( 'session' ) ; $ key = $ this -> getStateKeyPrefix ( ) . $ key ; $ value = $ session -> get ( $ key ) ; return $ value ; } | Returns persistent state value . |
20,955 | protected function removeState ( $ key ) { if ( ! Yii :: $ app -> has ( 'session' ) ) { return true ; } $ session = Yii :: $ app -> get ( 'session' ) ; $ key = $ this -> getStateKeyPrefix ( ) . $ key ; $ session -> remove ( $ key ) ; return true ; } | Removes persistent state value . |
20,956 | public static function pubKeyHashFromKey ( $ prefix , $ publicKey ) { $ length = strlen ( $ publicKey ) ; if ( $ length === 33 ) { if ( $ publicKey [ 0 ] !== "\x02" && $ publicKey [ 0 ] !== "\x03" ) { throw new CashAddressException ( "Invalid public key" ) ; } } else if ( $ length === 65 ) { if ( $ publicKey [ 0 ] !== "\x04" ) { throw new CashAddressException ( "Invalid public key" ) ; } } else { throw new CashAddressException ( "Invalid public key" ) ; } return self :: pubKeyHash ( $ prefix , hash ( 'ripemd160' , hash ( 'sha256' , $ publicKey , true ) , true ) ) ; } | This function does not validate public keys beyond their size and prefix . It will hash the data and produce the address even if it s invalid . You MUST validate them elsewhere . |
20,957 | static function replaceParameters ( array $ paramsInfo , array $ params ) : array { if ( \ count ( $ params ) !== \ count ( $ paramsInfo ) ) { throw new \ Plasma \ Exception ( 'Insufficient amount of parameters passed, expected ' . \ count ( $ paramsInfo ) . ', got ' . \ count ( $ params ) ) ; } $ realParams = array ( ) ; $ pos = ( \ array_key_exists ( 0 , $ params ) ? 0 : 1 ) ; foreach ( $ paramsInfo as $ param ) { $ key = ( $ param [ 0 ] === ':' ? $ param : ( $ pos ++ ) ) ; if ( ! \ array_key_exists ( $ key , $ params ) ) { throw new \ Plasma \ Exception ( 'Missing parameter with key "' . $ key . '"' ) ; } $ realParams [ ] = $ params [ $ key ] ; } return $ realParams ; } | Replaces the user parameters keys with the correct parameters for the DBMS . |
20,958 | public function storeRequest ( $ request = null , $ expiration = '+ 10 minutes' ) : string { if ( $ request === null ) { $ request = $ this -> getRequest ( ) ; } elseif ( ! $ request instanceof Request ) { $ expiration = $ request ; $ request = $ this -> getRequest ( ) ; } assert ( $ request instanceof Request ) ; $ request = clone $ request ; $ this -> unloader -> filterOut ( $ request ) ; $ session = $ this -> getSession ( 'Arachne.Application/requests' ) ; do { $ key = Random :: generate ( 5 ) ; } while ( isset ( $ session [ $ key ] ) ) ; $ session [ $ key ] = [ $ this -> user !== null ? $ this -> user -> getId ( ) : null , $ request ] ; $ session -> setExpiration ( $ expiration , $ key ) ; return $ key ; } | Stores request to session . |
20,959 | public function restoreRequest ( $ key ) : void { $ session = $ this -> getSession ( 'Arachne.Application/requests' ) ; if ( ! isset ( $ session [ $ key ] ) || ( $ this -> user !== null && $ session [ $ key ] [ 0 ] !== null && $ session [ $ key ] [ 0 ] !== $ this -> user -> getId ( ) ) ) { return ; } $ request = clone $ session [ $ key ] [ 1 ] ; unset ( $ session [ $ key ] ) ; try { $ this -> loader -> filterIn ( $ request ) ; } catch ( BadRequestException $ e ) { return ; } $ request -> setFlag ( Request :: RESTORED , true ) ; $ parameters = $ request -> getParameters ( ) ; $ parameters [ self :: FLASH_KEY ] = $ this -> getParameter ( self :: FLASH_KEY ) ; $ request -> setParameters ( $ parameters ) ; $ this -> sendResponse ( new ForwardResponse ( $ request ) ) ; } | Restores request from session . |
20,960 | public function build ( ) { $ client = $ this -> buildClient ( ) ; $ requestHandler = $ this -> getRequestHandler ( ) ; $ configuration = [ self :: CONF_EXPECT_JS_COOKIE => $ this -> expectJsCookie ] ; return new ThisData ( $ client , $ requestHandler , $ configuration ) ; } | Create an instance of the ThisData API client abstraction after configuration has been provided . |
20,961 | public function translate ( $ key , $ dictionaryName = null ) { if ( null !== $ dictionaryName ) { $ dictionary = $ this -> getDictionary ( $ dictionaryName ) ; if ( null == $ dictionary ) { throw new DictionaryNotFoundException ( $ dictionaryName , $ this -> getFilename ( ) , $ this -> tag -> getLineNumber ( ) ) ; } try { return $ dictionary -> translate ( $ key ) ; } catch ( DictionaryEntryNotFoundException $ ex ) { $ ex -> setDictionaryName ( $ dictionaryName ) ; $ ex -> setTemplateFile ( $ this -> getFilename ( ) , $ this -> tag -> getLineNumber ( ) ) ; throw $ ex ; } } foreach ( $ this -> dictionaries [ count ( $ this -> dictionaries ) - 1 ] as $ dictionary ) { try { return $ dictionary -> translate ( $ key ) ; } catch ( DictionaryEntryNotFoundException $ ex ) { } } throw new DictionaryEntryNotFoundException ( $ key , $ this -> getFilename ( ) , $ this -> tag -> getLineNumber ( ) ) ; } | If a dictionary name is specified performs the lookup only in this one . If the dictionary name is not in the perimeter of the current file bubbles up the translation request if a parent file exists . Finally throws DictionaryNotFoundException if the dictionary name is not found anywhere in the hierarchy . |
20,962 | protected static function getMailTransport ( ) { if ( ! isset ( PhpReports :: $ config [ 'mail_settings' ] ) ) PhpReports :: $ config [ 'mail_settings' ] = array ( ) ; if ( ! isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'method' ] ) ) PhpReports :: $ config [ 'mail_settings' ] [ 'method' ] = 'mail' ; switch ( PhpReports :: $ config [ 'mail_settings' ] [ 'method' ] ) { case 'mail' : return Swift_MailTransport :: newInstance ( ) ; case 'sendmail' : return Swift_MailTransport :: newInstance ( isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'command' ] ) ? PhpReports :: $ config [ 'mail_settings' ] [ 'command' ] : '/usr/sbin/sendmail -bs' ) ; case 'smtp' : if ( ! isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'server' ] ) ) throw new Exception ( "SMTP server must be configured" ) ; $ transport = Swift_SmtpTransport :: newInstance ( PhpReports :: $ config [ 'mail_settings' ] [ 'server' ] , isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'port' ] ) ? PhpReports :: $ config [ 'mail_settings' ] [ 'port' ] : 25 ) ; if ( isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'username' ] ) ) { $ transport -> setUsername ( PhpReports :: $ config [ 'mail_settings' ] [ 'username' ] ) ; $ transport -> setPassword ( PhpReports :: $ config [ 'mail_settings' ] [ 'password' ] ) ; } if ( isset ( PhpReports :: $ config [ 'mail_settings' ] [ 'encryption' ] ) ) { $ transport -> setEncryption ( PhpReports :: $ config [ 'mail_settings' ] [ 'encryption' ] ) ; } return $ transport ; default : throw new Exception ( "Mail method must be either 'mail', 'sendmail', or 'smtp'" ) ; } } | Determines the email transport to use based on the configuration settings |
20,963 | protected function findValue ( $ key , $ pool , $ default = null ) { if ( is_null ( $ pool ) ) { return $ default ; } else { return array_key_exists ( $ key , $ pool ) ? $ pool [ $ key ] : $ default ; } } | Utility method to retrieve a value from an array or a default if not found . |
20,964 | protected function synchronousExecute ( $ method , $ verb , array $ data = [ ] ) { $ request = new Request ( $ method , $ verb , [ ] , $ this -> serialize ( $ data ) ) ; $ response = $ this -> client -> send ( $ request ) ; return $ response ; } | Returns the response for a synchronous request |
20,965 | public static function resolveObjectType ( Endpoint $ endpoint , $ object ) : ? string { if ( $ object instanceof PolymorphicObjectInterface && $ object -> getConcreteType ( ) ) { return $ object -> getConcreteType ( ) ; } $ class = DoctrineClassUtils :: getClass ( $ object ) ; if ( ! $ endpoint -> hasTypeForClass ( $ class ) ) { return null ; } $ types = $ endpoint -> getTypesForClass ( $ class ) ; if ( count ( $ types ) === 1 ) { return $ types [ 0 ] ; } foreach ( $ types as $ type ) { $ definition = $ endpoint -> getType ( $ type ) ; if ( $ definition instanceof PolymorphicDefinitionInterface ) { return self :: resolveConcreteType ( $ endpoint , $ definition , $ object ) ; } } return $ types [ 0 ] ; } | Resolve the object type for given object instance |
20,966 | public static function resolveConcreteType ( Endpoint $ endpoint , PolymorphicDefinitionInterface $ definition , $ object ) { if ( $ map = $ definition -> getDiscriminatorMap ( ) ) { if ( $ definition -> getDiscriminatorProperty ( ) ) { $ property = $ definition -> getDiscriminatorProperty ( ) ; $ accessor = new PropertyAccessor ( ) ; $ propValue = $ accessor -> getValue ( $ object , $ property ) ; $ resolvedType = $ map [ $ propValue ] ?? null ; } if ( ! $ resolvedType ) { $ class = DoctrineClassUtils :: getClass ( $ object ) ; $ resolvedType = $ map [ $ class ] ?? null ; } } if ( ! $ resolvedType && $ definition instanceof InterfaceDefinition ) { foreach ( $ definition -> getImplementors ( ) as $ implementor ) { $ implementorDef = $ endpoint -> getType ( $ implementor ) ; if ( $ implementorDef instanceof ClassAwareDefinitionInterface && $ implementorDef -> getClass ( ) === DoctrineClassUtils :: getClass ( $ object ) ) { $ resolvedType = $ implementorDef -> getName ( ) ; } } } if ( $ endpoint -> hasType ( $ resolvedType ) ) { $ resolvedTypeDefinition = $ endpoint -> getType ( $ resolvedType ) ; if ( $ resolvedTypeDefinition instanceof PolymorphicDefinitionInterface ) { $ resolvedType = self :: resolveConcreteType ( $ endpoint , $ resolvedTypeDefinition , $ object ) ; } } return $ resolvedType ; } | Resolve the object type for given object instance when object use polymorphic definitions |
20,967 | public function showByType ( Selector $ listener , string $ type ) { if ( ! in_array ( $ type , $ this -> type ) ) { return $ listener -> themeFailedVerification ( ) ; } $ current = $ this -> memory -> get ( "site.theme.{$type}" ) ; $ themes = $ this -> getAvailableTheme ( $ type ) ; return $ listener -> showThemeSelection ( compact ( 'current' , 'themes' , 'type' ) ) ; } | List available theme . |
20,968 | public function activate ( Selector $ listener , string $ type , string $ id ) { $ theme = $ this -> getAvailableTheme ( $ type ) -> get ( $ id ) ; if ( ! in_array ( $ type , $ this -> type ) || is_null ( $ theme ) ) { return $ listener -> themeFailedVerification ( ) ; } $ this -> memory -> put ( "site.theme.{$type}" , $ id ) ; return $ listener -> themeHasActivated ( $ type , $ id ) ; } | Activate a theme . |
20,969 | protected function getAvailableTheme ( string $ type ) : Collection { $ themes = $ this -> foundation -> make ( 'orchestra.theme.finder' ) -> detect ( ) ; return $ themes -> filter ( function ( $ manifest ) use ( $ type ) { if ( ! empty ( $ manifest -> type ) && ! in_array ( $ type , $ manifest -> type ) ) { return null ; } return $ manifest ; } ) ; } | Get all available theme . |
20,970 | public static function object ( \ Closure $ callback ) { $ obj = new Object ; $ callback -> __invoke ( $ obj ) ; return json_encode ( $ obj ) ; } | Builds a JSON object by invoking a callback function . |
20,971 | protected function applyFilters ( QueryBuilder $ qb , array $ filters ) { $ definition = $ this -> objectDefinition ; foreach ( $ filters as $ field => $ value ) { if ( ! $ definition -> hasField ( $ field ) || ! $ prop = $ definition -> getField ( $ field ) -> getOriginName ( ) ) { continue ; } $ entityField = sprintf ( '%s.%s' , $ this -> queryAlias , $ prop ) ; switch ( gettype ( $ value ) ) { case 'string' : $ qb -> andWhere ( $ qb -> expr ( ) -> eq ( $ entityField , $ qb -> expr ( ) -> literal ( $ value ) ) ) ; break ; case 'integer' : case 'double' : $ qb -> andWhere ( $ qb -> expr ( ) -> eq ( $ entityField , $ value ) ) ; break ; case 'boolean' : $ qb -> andWhere ( $ qb -> expr ( ) -> eq ( $ entityField , ( int ) $ value ) ) ; break ; case 'array' : if ( empty ( $ value ) ) { $ qb -> andWhere ( $ qb -> expr ( ) -> isNull ( $ entityField ) ) ; } else { $ qb -> andWhere ( $ qb -> expr ( ) -> in ( $ entityField , $ value ) ) ; } break ; case 'NULL' : $ qb -> andWhere ( $ qb -> expr ( ) -> isNull ( $ entityField ) ) ; break ; } } } | Apply advanced filters |
20,972 | protected function isMetaField ( $ strField ) { $ strField = \ trim ( $ strField ) ; if ( \ in_array ( $ strField , $ this -> getMetaModelsSystemColumns ( ) ) ) { return true ; } return false ; } | Check if we have a meta field from metamodels . |
20,973 | public function save ( Request $ request , FileUploader $ fileUploader ) { $ data = $ request -> except ( '_token' ) ; if ( $ request -> hasFile ( 'image' ) ) { $ file = $ fileUploader -> handle ( $ request -> file ( 'image' ) , 'settings' ) ; $ this -> deleteImage ( ) ; $ data [ 'image' ] = $ file [ 'filename' ] ; } foreach ( $ data as $ group_name => $ array ) { if ( ! is_array ( $ array ) ) { $ array = [ $ group_name => $ array ] ; $ group_name = 'config' ; } foreach ( $ array as $ key_name => $ value ) { $ model = Setting :: firstOrCreate ( [ 'key_name' => $ key_name , 'group_name' => $ group_name ] ) ; $ model -> value = $ value ; $ model -> save ( ) ; $ this -> repository -> forgetCache ( ) ; } } return redirect ( ) -> route ( 'admin::index-settings' ) ; } | Save settings . |
20,974 | public function deleteImage ( ) { if ( $ filename = Setting :: where ( 'key_name' , 'image' ) -> value ( 'value' ) ) { try { Croppa :: delete ( 'storage/settings/' . $ filename ) ; } catch ( Exception $ e ) { Log :: info ( $ e -> getMessage ( ) ) ; } } Setting :: where ( 'key_name' , 'image' ) -> delete ( ) ; $ this -> repository -> forgetCache ( ) ; } | Delete image . |
20,975 | protected function doExecute ( InputInterface $ input , OutputInterface $ output ) : int { $ descriptor = new DescriptorHelper ; $ this -> getHelperSet ( ) -> set ( $ descriptor ) ; $ descriptor -> describe ( $ output , $ this -> getApplication ( ) , [ 'namespace' => $ input -> getArgument ( 'namespace' ) , ] ) ; return 0 ; } | Internal function to execute the command . |
20,976 | public function isVisible ( ) : bool { if ( ! empty ( $ this -> item [ 'permission' ] ) ) { return $ this -> vault -> getGuard ( ) -> allows ( $ this -> item [ 'permission' ] ) ; } $ target = current ( explode ( ':' , $ this -> getTarget ( ) ) ) ; return $ this -> vault -> getGuard ( ) -> allows ( "{$this->vault->getConfig()->guardNamespace()}.{$target}" ) ; } | Check if item is visible . |
20,977 | function runQuery ( \ Plasma \ QueryBuilderInterface $ query ) : \ React \ Promise \ PromiseInterface { if ( $ this -> driver === null ) { throw new \ Plasma \ TransactionException ( 'Transaction has been committed or rolled back' ) ; } return $ this -> driver -> runQuery ( $ this -> client , $ query ) ; } | Runs the given querybuilder on the underlying driver instance . The driver CAN throw an exception if the given querybuilder is not supported . An example would be a SQL querybuilder and a Cassandra driver . |
20,978 | function commit ( ) : \ React \ Promise \ PromiseInterface { return $ this -> query ( 'COMMIT' ) -> then ( function ( ) { $ this -> driver -> endTransaction ( ) ; $ this -> client -> checkinConnection ( $ this -> driver ) ; $ this -> driver = null ; } ) ; } | Commits the changes . |
20,979 | function createSavepoint ( string $ identifier ) : \ React \ Promise \ PromiseInterface { return $ this -> query ( 'SAVEPOINT ' . $ this -> quote ( $ identifier ) ) ; } | Creates a savepoint with the given identifier . |
20,980 | public function getExitCode ( ) : int { return $ this -> exitCode ? : ( \ is_int ( $ this -> error -> getCode ( ) ) && $ this -> error -> getCode ( ) !== 0 ? $ this -> error -> getCode ( ) : 1 ) ; } | Gets the exit code . |
20,981 | public function shouldExistInTableARecordMatching ( $ table , YamlStringNode $ criteria ) { $ count = $ this -> countRecordsInTableMatching ( $ table , $ criteria -> toArray ( ) ) ; Assert :: assertEquals ( 1 , $ count , sprintf ( 'Does not exist any record in the database "%s" matching given conditions' , $ table ) ) ; } | Use a YAML syntax to create a criteria to match a record in given table |
20,982 | public function shouldExistInTableRecordsMatching ( $ table , YamlStringNode $ criteria ) { foreach ( $ criteria -> toArray ( ) as $ row ) { $ count = $ this -> countRecordsInTableMatching ( $ table , $ row ) ; Assert :: assertEquals ( 1 , $ count , sprintf ( 'Does not exist any record in the database "%s" matching given conditions' , $ table ) ) ; } } | Use a YAML syntax to create a criteria to match many records in given table |
20,983 | public function countRecordsInTableMatching ( $ table , $ criteria = [ ] ) : int { $ where = '' ; foreach ( $ criteria as $ field => $ vale ) { if ( $ where ) { $ where .= ' AND ' ; } if ( $ vale === null ) { $ where .= sprintf ( '%s IS NULL' , $ field ) ; } else { $ where .= sprintf ( '%s = :%s' , $ field , $ field ) ; } } $ query = sprintf ( 'SELECT count(*) AS records FROM %s WHERE %s' , $ table , $ where ) ; $ manager = $ this -> client -> getContainer ( ) -> get ( 'doctrine' ) -> getManager ( ) ; $ rsm = new ResultSetMapping ( ) ; $ rsm -> addScalarResult ( 'records' , 'records' , 'integer' ) ; $ query = $ manager -> createNativeQuery ( $ query , $ rsm ) ; $ query -> setParameters ( $ criteria ) ; return ( int ) $ query -> getSingleScalarResult ( ) ; } | Count records in table matching criteria |
20,984 | private function loadLanguageFile ( $ name ) { $ system = $ this -> framework -> getAdapter ( System :: class ) ; $ system -> loadLanguageFile ( $ name ) ; } | Loads a Contao framework language file . |
20,985 | protected function loadDomain ( $ domain , $ locale ) { $ event = new LoadLanguageFileEvent ( $ domain , $ locale ) ; $ this -> eventDispatcher -> dispatch ( ContaoEvents :: SYSTEM_LOAD_LANGUAGE_FILE , $ event ) ; } | Load the language strings for the given domain in the passed locale . |
20,986 | public function getLoadedEntity ( NodeInterface $ entity ) : NodeInterface { $ class = ClassUtils :: getClass ( $ entity ) ; if ( isset ( self :: $ deferred [ $ class ] [ $ entity -> getId ( ) ] ) && self :: $ deferred [ $ class ] [ $ entity -> getId ( ) ] instanceof NodeInterface ) { return self :: $ deferred [ $ class ] [ $ entity -> getId ( ) ] ; } return $ entity ; } | Return the loaded entity for given not initialized entity |
20,987 | public function loadBuffer ( ) : void { if ( self :: $ loaded ) { return ; } self :: $ loaded = true ; foreach ( self :: $ deferred as $ class => $ ids ) { $ repo = $ this -> registry -> getRepository ( $ class ) ; $ qb = $ repo -> createQueryBuilder ( 'o' , 'o.id' ) ; $ entities = $ qb -> where ( $ qb -> expr ( ) -> in ( 'o.id' , array_values ( $ ids ) ) ) -> getQuery ( ) -> getResult ( ) ; foreach ( $ entities as $ entity ) { if ( $ entity instanceof NodeInterface ) { self :: $ deferred [ $ class ] [ $ entity -> getId ( ) ] = $ entity ; } } } } | Load buffer of entities |
20,988 | public function uri ( string $ target , $ parameters = [ ] ) : UriInterface { if ( strpos ( $ target , ':' ) !== false ) { list ( $ controller , $ action ) = explode ( ':' , $ target ) ; } else { $ controller = $ target ; $ action = $ parameters [ 'action' ] ?? null ; } if ( ! $ this -> config -> hasController ( $ controller ) ) { throw new VaultException ( "Unable to generate uri, undefined controller '{$controller}'" ) ; } return $ this -> route -> withDefaults ( compact ( 'controller' , 'action' ) ) -> uri ( $ parameters ) ; } | Get vault specific uri . |
20,989 | private function buildPipeline ( ) { $ nextCallable = function ( $ item ) { } ; foreach ( $ this -> getStepsSortedDescByPriority ( ) as $ step ) { $ nextCallable = function ( $ item ) use ( $ step , $ nextCallable ) { return $ step -> process ( $ item , $ nextCallable ) ; } ; } return $ nextCallable ; } | Builds the pipeline |
20,990 | private function getStepsSortedDescByPriority ( ) { $ steps = $ this -> steps ; $ steps [ - 255 ] [ ] = new Step \ ArrayCheckStep ; foreach ( $ this -> writers as $ writer ) { $ steps [ - 256 ] [ ] = new Step \ WriterStep ( $ writer ) ; } krsort ( $ steps ) ; $ sortedStep = [ ] ; foreach ( $ steps as $ stepsAtSamePriority ) { foreach ( $ stepsAtSamePriority as $ step ) { $ sortedStep [ ] = $ step ; } } return array_reverse ( $ sortedStep ) ; } | Sorts the internal list of steps and writers by priority in reverse order . |
20,991 | public function close ( ) { $ userId = 0 ; $ userName = 'guest' ; $ userEmail = '' ; if ( $ this -> authenticationService ) { if ( $ this -> authenticationService -> getIdentity ( ) instanceof OAuth2AuthenticatedIdentity ) { $ user = $ this -> authenticationService -> getIdentity ( ) -> getUser ( ) ; if ( method_exists ( $ user , 'getId' ) ) { $ userId = $ user -> getId ( ) ; } if ( method_exists ( $ user , 'getDisplayName' ) ) { $ userName = $ user -> getDisplayName ( ) ; } if ( method_exists ( $ user , 'getEmail' ) ) { $ userEmail = $ user -> getEmail ( ) ; } } elseif ( $ this -> authenticationService -> getIdentity ( ) instanceof AuthenticatedIdentity ) { $ userId = $ this -> authenticationService -> getIdentity ( ) -> getAuthenticationIdentity ( ) [ 'user_id' ] ; $ userName = $ this -> authenticationService -> getIdentity ( ) -> getName ( ) ; } elseif ( $ this -> authenticationService -> getIdentity ( ) instanceof GuestIdentity ) { } else { } } $ query = $ this -> getObjectManager ( ) -> createNativeQuery ( " SELECT close_revision_audit(:userId, :userName, :userEmail, :comment) " , new ResultSetMapping ( ) ) -> setParameter ( 'userId' , $ userId ) -> setParameter ( 'userName' , $ userName ) -> setParameter ( 'userEmail' , $ userEmail ) -> setParameter ( 'comment' , $ this -> revisionComment -> getComment ( ) ) ; ; $ query -> getResult ( ) ; $ this -> revisionComment -> setComment ( '' ) ; } | Close a revision - can be done manually or automatically via postFlush |
20,992 | public function getSections ( ) : \ Generator { foreach ( $ this -> vault -> getConfig ( ) -> navigationSections ( ) as $ section ) { yield new Section ( $ this -> vault , $ section ) ; } } | Get all navigation sections . This is generator . |
20,993 | public static function createFromData ( $ data , $ upper = false ) : string { if ( \ is_array ( $ data ) || \ is_object ( $ data ) ) { $ data = serialize ( $ data ) ; } $ hash = $ upper ? strtoupper ( md5 ( $ data ) ) : strtolower ( md5 ( $ data ) ) ; return implode ( '-' , [ substr ( $ hash , 0 , 8 ) , substr ( $ hash , 8 , 4 ) , substr ( $ hash , 12 , 4 ) , substr ( $ hash , 16 , 4 ) , substr ( $ hash , 20 , 8 ) , ] ) ; } | Create universal identifier for given data . Helpful to create unique across then system but the same when use the same data |
20,994 | public function getMapping ( Request $ request ) : array { return $ this -> cache -> load ( $ this -> getCacheKey ( $ request ) , function ( & $ dependencies ) use ( $ request ) { return $ this -> loadMapping ( $ request -> getPresenterName ( ) , $ request -> getParameters ( ) , $ dependencies ) ; } ) ; } | Returns parameters information based on the request . |
20,995 | public function additionalSolrValues ( ) { if ( ( $ this -> owner -> CanViewType === 'Inherit' ) && $ this -> owner -> ParentID ) { return $ this -> owner -> Parent ( ) -> additionalSolrValues ( ) ; } else if ( $ this -> owner -> CanViewType === 'OnlyTheseUsers' ) { $ groups = array ( ) ; foreach ( $ this -> owner -> ViewerGroups ( ) as $ group ) { $ groups [ ] = ( string ) $ group -> ID ; } return array ( $ this -> index => $ groups ) ; } else if ( $ this -> owner -> CanViewType === 'LoggedInUsers' ) { return array ( $ this -> index => array ( 'logged-in' ) ) ; } else { return array ( $ this -> index => array ( 'anyone' ) ) ; } } | Retrieve the custom search index value for the current site tree element returning the listing of groups that have access . |
20,996 | public function getGeoSelectableFields ( ) { $ all = $ this -> owner -> getSelectableFields ( null , false ) ; $ listTypes = $ this -> owner -> searchableTypes ( 'Page' ) ; $ geoFields = array ( ) ; foreach ( $ listTypes as $ classType ) { $ db = Config :: inst ( ) -> get ( $ classType , 'db' ) ; foreach ( $ db as $ name => $ type ) { if ( is_subclass_of ( $ type , 'SolrGeoPoint' ) || $ type == 'SolrGeoPoint' ) { $ geoFields [ $ name ] = $ name ; } } } ksort ( $ geoFields ) ; return $ geoFields ; } | Get a list of geopoint fields that are selectable |
20,997 | public function image ( $ file , $ caption = null ) { $ this -> messages [ ] = $ this -> media -> compile ( $ file , $ caption , 'image' ) ; } | Send image message |
20,998 | public function location ( $ longitude , $ latitude , $ caption = null , $ url = null ) { $ location = new stdClass ( ) ; $ location -> type = 'location' ; $ location -> longitude = $ longitude ; $ location -> latitude = $ latitude ; $ location -> caption = $ caption ; $ location -> url = $ url ; $ this -> messages [ ] = $ location ; } | Send location message |
20,999 | public function vcard ( $ name , VCard $ vcard ) { $ card = new stdClass ( ) ; $ card -> type = 'vcard' ; $ card -> name = $ name ; $ card -> vcard = $ vcard ; $ this -> messages [ ] = $ card ; } | Send Virtual Cards |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.