idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
2,900
|
public function saveToEntities ( ) { $ data = $ this -> transformFromFormData ( $ this -> data ) ; foreach ( $ this -> entities as $ entity ) { if ( $ entity [ 'entity' ] instanceof EntityInterface ) { $ entity [ 'entity' ] -> setFormData ( $ data , $ entity [ 'fields' ] ) ; } else { $ this -> entityProcessor -> saveToEntity ( $ entity [ 'entity' ] , $ data , $ entity [ 'fields' ] ) ; } } }
|
Save the current form data to the assigned entities
|
2,901
|
public function saveToAndGetClonedEntities ( ) { $ data = $ this -> transformFromFormData ( $ this -> data ) ; $ cloned_entities = array ( ) ; foreach ( $ this -> entities as $ entity ) { $ entity [ 'entity' ] = clone $ entity [ 'entity' ] ; $ cloned_entities [ ] = $ entity ; if ( $ entity [ 'entity' ] instanceof EntityInterface ) { $ entity [ 'entity' ] -> setFormData ( $ data , $ entity [ 'fields' ] ) ; } else { $ this -> entityProcessor -> saveToEntity ( $ entity [ 'entity' ] , $ data , $ entity [ 'fields' ] ) ; } } return $ cloned_entities ; }
|
Save the form data to cloned entities and retrieve them .
|
2,902
|
public function getProcessedFields ( ) { $ fields = array ( ) ; foreach ( $ this -> fields as $ fieldName => $ field ) { $ fields [ $ fieldName ] = $ this -> getProcessedField ( $ fieldName ) ; } return $ fields ; }
|
Process all fields and return them
|
2,903
|
public function getProcessedField ( $ fieldName ) { if ( ! isset ( $ this -> fields [ $ fieldName ] ) ) { return false ; } $ field = $ this -> fields [ $ fieldName ] ; $ field [ 'has_error' ] = $ this -> fieldHasError ( $ fieldName ) ; return $ this -> typeHandler -> makeView ( $ field , $ this -> data , $ this ) ; }
|
Process a field and return it
|
2,904
|
public function fieldHasError ( $ fieldName ) { foreach ( $ this -> errors as $ error ) { if ( $ error -> getParam ( ) == $ fieldName ) { return true ; } } if ( ! $ this -> isSubmitted ( ) ) { return false ; } if ( isset ( $ this -> validator ) && $ this -> validator -> fieldHasError ( $ fieldName ) ) { return true ; } }
|
Check if a field has an error
|
2,905
|
public function hasFieldOfType ( $ fieldType ) { foreach ( $ this -> fields as $ field ) { if ( $ field [ 'type' ] == $ fieldType ) { return true ; } } return false ; }
|
Check if the form contains any fields of a certain type like select or textarea
|
2,906
|
public function getData ( $ name = null , $ transform = true ) { $ data = $ this -> data ; if ( $ transform === true ) { $ data = $ this -> transformFromFormData ( $ this -> data ) ; } if ( $ name === null ) { return $ data ; } else { if ( isset ( $ data [ $ name ] ) ) { return $ data [ $ name ] ; } else { return null ; } } }
|
Get the values of all the form fields or a single form field
|
2,907
|
public function createView ( ) { if ( ! $ this -> formView ) { $ this -> formView = new FormView ( ) ; } $ this -> formView -> setFormBlueprint ( $ this -> form ) ; $ this -> formView -> setFields ( $ this -> getProcessedFields ( ) ) ; $ this -> formView -> setSections ( $ this -> form -> getSections ( ) ) ; $ this -> formView -> setMethod ( $ this -> getMethod ( ) ) ; $ this -> formView -> setName ( $ this -> getName ( ) ) ; $ this -> formView -> setEncoding ( $ this -> getEncoding ( ) ) ; $ this -> formView -> setAction ( $ this -> getAction ( ) ) ; $ this -> formView -> setSubmitted ( $ this -> isSubmitted ( ) ) ; $ this -> formView -> setValid ( $ this -> isValid ( ) ) ; $ this -> formView -> setErrors ( $ this -> getValidationErrors ( ) ) ; $ this -> formView -> setShouldShowSuccessMessage ( $ this -> shouldShowSuccessMessage ( ) ) ; $ this -> formView -> setSubmitButtonLabel ( $ this -> form -> getSubmitButtonLabel ( ) ) ; if ( isset ( $ this -> restoreDataHandler ) ) { $ this -> restoreDataHandler -> cancelRestore ( $ this ) ; } return $ this -> formView ; }
|
Assign the form data to the view
|
2,908
|
public function setValidator ( ValidatorExtensionInterface $ validator ) { $ this -> validator = $ validator ; $ this -> validator -> setFormHandler ( $ this ) ; }
|
Set a validator wrapped in a ValidatorExtension class
|
2,909
|
public function isValid ( $ scope = null , $ options = null ) { if ( ! $ this -> isSubmitted ( ) ) { return false ; } if ( ( isset ( $ this -> validator ) && $ this -> validator -> isValid ( $ scope , $ options ) && empty ( $ this -> errors ) ) || ( ! isset ( $ this -> validator ) && empty ( $ this -> errors ) ) ) { if ( isset ( $ this -> restoreDataHandler ) ) { $ this -> restoreDataHandler -> setValid ( $ this ) ; } return true ; } else { if ( isset ( $ this -> restoreDataHandler ) ) { $ this -> restoreDataHandler -> setRestorableErrors ( $ this , $ this -> getValidationErrors ( ) ) ; } if ( isset ( $ this -> restoreDataHandler ) ) { $ this -> restoreDataHandler -> setInvalid ( $ this ) ; } return false ; } }
|
Check if the form is valid using the validator if it is set and checking for any custom errors . Will save data to entities .
|
2,910
|
protected function setRequiredFieldErrors ( $ fields = null , $ data = null ) { if ( $ fields === null ) { $ fields = & $ this -> fields ; } if ( $ data === null ) { $ data = & $ this -> data ; } foreach ( $ fields as $ field ) { if ( isset ( $ field [ 'options' ] [ 'required' ] ) && $ field [ 'options' ] [ 'required' ] === true ) { if ( ! isset ( $ data [ $ field [ 'name' ] ] ) || $ data [ $ field [ 'name' ] ] == null ) { if ( isset ( $ field [ 'options' ] [ 'label' ] ) ) { $ label = $ field [ 'options' ] [ 'label' ] ; } else { $ label = $ field [ 'name' ] ; } $ this -> errors [ ] = new FormError ( $ field [ 'name' ] , "Field '{field_label}' must be set" , true , array ( 'field_label' => $ label ) ) ; } } if ( isset ( $ field [ 'fields' ] ) ) { $ this -> setRequiredFieldErrors ( $ field [ 'fields' ] , $ data [ $ field [ 'name' ] ] ) ; } } }
|
Check each field to see if they re required . If they have no data set assign the error
|
2,911
|
public function setError ( $ param , $ message , $ translate = false , $ translationParams = array ( ) ) { $ this -> errors [ ] = new FormError ( $ param , $ message , $ translate , $ translationParams ) ; $ this -> isValid ( ) ; }
|
Set a custom error on the form
|
2,912
|
public function addCustomErrors ( $ errors ) { if ( $ errors ) { foreach ( $ errors as $ error ) { if ( ! is_a ( $ error , 'AV\Form\FormError' ) ) { throw new InvalidArgumentException ( 'Custom errors must be AV\Form\FormError objects' ) ; } else { $ this -> errors [ ] = $ error ; } } } $ this -> isValid ( ) ; }
|
Add custom errors to the form . Must be an array of FormError objects
|
2,913
|
public function getValidationErrors ( ) { $ errors = $ this -> errors ; if ( isset ( $ this -> validator ) ) { $ validator_errors = $ this -> validator -> getErrors ( ) ; $ errors = array_merge ( $ errors , $ validator_errors ) ; } return $ errors ; }
|
Get the errors from the validator
|
2,914
|
public function setType ( $ type ) { if ( is_string ( $ type ) ) { if ( in_array ( $ type , [ self :: TYPE_ALL , self :: TYPE_PRINT , self :: TYPE_SCREEN , self :: TYPE_SPEECH , self :: TYPE_AURAL , self :: TYPE_BRAILLE , self :: TYPE_EMBOSSED , self :: TYPE_HANDHELD , self :: TYPE_PROJECTION , self :: TYPE_TTY , self :: TYPE_TV ] ) ) { $ this -> type = $ type ; return $ this ; } else { $ this -> type = self :: TYPE_ALL ; $ this -> setIsNot ( true ) ; $ this -> setIsOnly ( false ) ; } } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ type ) . "' for argument 'type' given." ) ; } }
|
Sets the media type .
|
2,915
|
public function addCondition ( ConditionAbstract $ condition ) { if ( $ condition instanceof MediaCondition ) { $ this -> conditions [ ] = $ condition ; } else { throw new \ InvalidArgumentException ( "Invalid condition instance. Instance of 'MediaCondition' expected." ) ; } return $ this ; }
|
Adds a media rule condition .
|
2,916
|
final public static function byName ( $ name ) { $ instances = & static :: getInstances ( ) ; if ( ! array_key_exists ( $ name , $ instances ) ) { $ instances [ $ name ] = new static ( $ name ) ; } return $ instances [ $ name ] ; }
|
Attempts to instantiate an Enum from a label name .
|
2,917
|
public static function getAllInstances ( ) { try { $ instances = array ( ) ; foreach ( static :: getAllNames ( ) as $ name ) { $ instances [ ] = static :: byName ( $ name ) ; } return $ instances ; } catch ( Enum \ Exception \ InvalidInstance $ e ) { throw new LogicException ( "All valid names should produce valid instances?" ) ; } }
|
Gets an array of all possible instances .
|
2,918
|
public static function getAllNames ( ) { $ className = get_called_class ( ) ; if ( ! array_key_exists ( $ className , self :: $ constantsArray ) ) { try { $ class = new ReflectionClass ( $ className ) ; } catch ( ReflectionException $ e ) { throw new RuntimeException ( $ e -> getMessage ( ) , ( int ) $ e -> getCode ( ) , $ e ) ; } self :: $ constantsArray [ $ className ] = array_keys ( $ class -> getConstants ( ) ) ; } return self :: $ constantsArray [ $ className ] ; }
|
Gets an array of all possible instances label names .
|
2,919
|
final public function equals ( Enum $ b ) { $ aClass = get_class ( $ this ) ; $ bClass = get_class ( $ b ) ; if ( $ aClass !== $ bClass ) { throw new InvalidArgumentException ( "Unexpected type {$bClass} is not of type {$aClass}." ) ; } return $ b -> getName ( ) === $ this -> getName ( ) ; }
|
Only two Enums of the same type can be compared . They are equal if their label is the same .
|
2,920
|
public function resourceWith ( $ entity , $ transformer , $ key = null ) : TransformationFactory { if ( ( is_array ( $ entity ) && isset ( $ entity [ 0 ] ) && is_array ( $ entity [ 0 ] ) ) || $ entity instanceof LaravelCollection || $ entity instanceof LengthAwarePaginator ) { return $ this -> collectionWith ( $ entity , $ transformer , $ key ) ; } return $ this -> itemWith ( $ entity , $ transformer , $ key ) ; }
|
Adds data and transformer and chooses whether to use the Item or Collection Resource based on what s most suitable for the data passed in .
|
2,921
|
public function collectionWith ( $ entity , $ transformer , $ key = null ) : TransformationFactory { $ this -> entity = $ entity ; $ this -> transformer = $ transformer ; $ this -> resource = new Collection ( $ entity , $ transformer , $ key ) ; return $ this ; }
|
Uses a Collection resource on the data and transformer passed in .
|
2,922
|
public function itemWith ( $ entity , $ transformer , $ key = null ) : TransformationFactory { $ this -> entity = $ entity ; $ this -> transformer = $ transformer ; $ this -> resource = new Item ( $ entity , $ transformer , $ key ) ; return $ this ; }
|
Uses an Item resource on the data and transformer passed in .
|
2,923
|
public function serialize ( $ serializer = ApiDataSerializer :: class ) : array { if ( ! is_a ( $ serializer , SerializerAbstract :: class , true ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The serializer must either be an instance, or string representation of %s. The passed value %s is neither.' , SerializerAbstract :: class , $ serializer ) ) ; } $ this -> serializer = is_string ( $ serializer ) ? new $ serializer : $ serializer ; $ this -> manager -> setSerializer ( $ this -> serializer ) ; return $ this -> manager -> createData ( $ this -> resource ) -> toArray ( ) ; }
|
Completes the the transformation and serialization flow returning the data .
|
2,924
|
public function usingPaginator ( $ paginator = null ) : TransformationFactory { if ( ! ( $ this -> resource instanceof Collection ) || ! ( $ this -> entity instanceof LengthAwarePaginator ) ) { throw new \ InvalidArgumentException ( 'Bad Request Issued' ) ; } $ this -> resource -> setPaginator ( new IlluminatePaginatorAdapter ( $ this -> entity ) ) ; return $ this ; }
|
Applies a LengthAwarePaginator for paged resources .
|
2,925
|
protected function parseFieldOptionsJson ( ) { foreach ( $ this -> data -> rawData [ 'fields' ] as $ fieldId => & $ fieldData ) { $ optionsJson = trim ( $ fieldData [ 'options' ] ) ; if ( empty ( $ optionsJson ) ) continue ; $ fieldData [ 'options' ] = json_decode ( $ optionsJson , true ) ; } unset ( $ fieldData ) ; }
|
Parses json to array for fields with options set
|
2,926
|
public static function renderItem ( SQL \ Columns $ item ) { return Compiler :: braced ( Arr :: join ( ', ' , Arr :: map ( __NAMESPACE__ . '\Compiler::name' , $ item -> all ( ) ) ) ) ; }
|
Render Columns object
|
2,927
|
public static function render ( Query \ Select $ query ) { return Compiler :: withDb ( $ query -> getDb ( ) , function ( ) use ( $ query ) { return Compiler :: expression ( array ( 'SELECT' , $ query -> getType ( ) , Aliased :: combine ( $ query -> getColumns ( ) ) ? : '*' , Compiler :: word ( 'FROM' , Aliased :: combine ( $ query -> getFrom ( ) ) ) , Join :: combine ( $ query -> getJoin ( ) ) , Compiler :: word ( 'WHERE' , Condition :: combine ( $ query -> getWhere ( ) ) ) , Compiler :: word ( 'GROUP BY' , Direction :: combine ( $ query -> getGroup ( ) ) ) , Compiler :: word ( 'HAVING' , Condition :: combine ( $ query -> getHaving ( ) ) ) , Compiler :: word ( 'ORDER BY' , Direction :: combine ( $ query -> getOrder ( ) ) ) , Compiler :: word ( 'LIMIT' , $ query -> getLimit ( ) ) , Compiler :: word ( 'OFFSET' , $ query -> getOffset ( ) ) , ) ) ; } ) ; }
|
Render a Select object
|
2,928
|
public function with ( $ options ) { $ clone = clone $ this ; foreach ( $ options as $ name => $ value ) { $ clone -> setOption ( $ name , $ value ) ; } return $ clone ; }
|
Clones the instance and applies new set of options
|
2,929
|
public function getCastedQuery ( ) { $ newQuery = $ this -> castArray ( $ this -> query , $ this -> initialMetadata ) ; ArrayModifier :: aggregate ( $ newQuery , self :: $ mongoDbQueryOperators ) ; return $ newQuery ; }
|
Get the caster query
|
2,930
|
protected function execute ( Input \ InputInterface $ input , Output \ OutputInterface $ output ) { $ this -> generatorService -> process ( $ input -> getOption ( 'force' ) ) ; $ output -> writeln ( 'Completed' ) ; }
|
Generate the container
|
2,931
|
public function has ( string ... $ props ) : bool { foreach ( $ props as $ prop ) { if ( ! array_key_exists ( strtolower ( $ prop ) , $ this -> props ) ) { return false ; } } return true ; }
|
Checks if 1 or all the keys exist in Bag
|
2,932
|
public function setModelDefaults ( $ attr , $ value = null ) { if ( is_array ( $ attr ) ) $ this -> modelDefaults = array_merge ( $ this -> modelDefaults , $ attr ) ; else $ this -> modelDefaults [ $ attr ] = $ value ; return $ this ; }
|
Sets the Model default values .
|
2,933
|
protected function orderFixturesByNumber ( ) { $ this -> orderedFixtures = $ this -> fixtures ; usort ( $ this -> orderedFixtures , function ( $ a , $ b ) { if ( $ a instanceof OrderedFixtureInterface && $ b instanceof OrderedFixtureInterface ) { if ( $ a -> getOrder ( ) === $ b -> getOrder ( ) ) { return 0 ; } return $ a -> getOrder ( ) < $ b -> getOrder ( ) ? - 1 : 1 ; } elseif ( $ a instanceof OrderedFixtureInterface ) { return $ a -> getOrder ( ) === 0 ? 0 : 1 ; } elseif ( $ b instanceof OrderedFixtureInterface ) { return $ b -> getOrder ( ) === 0 ? 0 : - 1 ; } return 0 ; } ) ; }
|
Order fixtures by priority
|
2,934
|
protected function getLastJsonError ( ) { $ error = json_last_error ( ) ; return array_key_exists ( $ error , self :: $ errors ) ? self :: $ errors [ $ error ] : "Unknown error ({$error})" ; }
|
Get the last error
|
2,935
|
protected function isTypeWithinArray ( $ type , array $ haystackTypes ) { $ iterator = new \ ArrayIterator ( $ haystackTypes ) ; while ( $ iterator -> valid ( ) ) { $ seenValue = $ iterator -> current ( ) ; if ( $ seenValue === $ type ) { return true ; } $ parts = explode ( '.' , $ seenValue ) ; if ( count ( $ parts ) > 1 ) { array_shift ( $ parts ) ; $ newKey = implode ( '.' , $ parts ) ; $ iterator -> append ( $ newKey ) ; } $ iterator -> next ( ) ; } return false ; }
|
Checks if the given type exists within the array of types .
|
2,936
|
protected function reviveRequest ( ServerRequestInterface $ request ) { $ isStale = interface_exists ( 'Jasny\HttpMessage\GlobalEnvironmentInterface' ) && $ request instanceof GlobalEnvironmentInterface && $ request -> isStale ( ) ; return $ isStale ? $ request -> revive ( ) : $ request ; }
|
Revive a stale request
|
2,937
|
protected function getErrorRoute ( ServerRequestInterface $ request , ResponseInterface $ response ) { if ( interface_exists ( 'Jasny\HttpMessage\GlobalEnvironmentInterface' ) && $ request instanceof GlobalEnvironmentInterface ) { $ request = $ request -> withoutGlobalEnvironment ( ) ; } $ status = $ response -> getStatusCode ( ) ; $ errorUri = $ request -> getUri ( ) -> withPath ( $ status ) -> withQuery ( null ) -> withFragment ( null ) ; return $ this -> router -> getRoutes ( ) -> getRoute ( $ request -> withUri ( $ errorUri ) ) ; }
|
Get the route to the error page
|
2,938
|
protected function routeToErrorPage ( ServerRequestInterface $ request , ResponseInterface $ response ) { $ errorRoute = $ this -> getErrorRoute ( $ request , $ response ) ; if ( ! isset ( $ errorRoute ) ) { return $ response ; } $ runner = $ this -> router -> getRunner ( ) ; return $ runner ( $ request -> withAttribute ( 'route' , $ errorRoute ) , $ response ) ; }
|
Route to the error page
|
2,939
|
protected function processNext ( ) { foreach ( $ this -> _status as $ i => $ status ) { if ( $ status === false && ( $ request = array_shift ( $ this -> _queue ) ) !== null ) { $ this -> _status [ $ i ] = $ request ; $ this -> _retries [ $ i ] = 0 ; $ this -> add ( $ request ) ; } } }
|
Execute free threads
|
2,940
|
public function addHeader ( $ add , $ dca ) { $ catId = $ add [ 'id' ] ; unset ( $ add [ 'id' ] ) ; $ sql = 'SELECT CAST(`banner_published` AS UNSIGNED INTEGER) AS published ,count(id) AS numbers FROM `tl_banner` WHERE `pid`=? GROUP BY 1' ; $ objNumbers = \ Database :: getInstance ( ) -> prepare ( $ sql ) -> execute ( $ catId ) ; if ( $ objNumbers -> numRows == 0 ) { return $ add ; } $ published = 0 ; $ not_published = 0 ; while ( $ objNumbers -> next ( ) ) { if ( $ objNumbers -> published == 0 ) { $ not_published = $ objNumbers -> numbers ; } if ( $ objNumbers -> published == 1 ) { $ published = $ objNumbers -> numbers ; } } $ add [ $ GLOBALS [ 'TL_LANG' ] [ 'tl_banner' ] [ 'banner_number_of' ] ] = $ published . " " . $ GLOBALS [ 'TL_LANG' ] [ 'tl_banner' ] [ 'banner_active' ] . " / " . $ not_published . " " . $ GLOBALS [ 'TL_LANG' ] [ 'tl_banner' ] [ 'banner_inactive' ] ; return $ add ; }
|
Add Header Rows call from header_callback
|
2,941
|
public function listBanner ( $ row ) { switch ( $ row [ 'banner_type' ] ) { case self :: BANNER_TYPE_INTERN : return $ this -> listBannerInternal ( $ row ) ; break ; case self :: BANNER_TYPE_EXTERN : return $ this -> listBannerExternal ( $ row ) ; break ; case self :: BANNER_TYPE_TEXT : return $ this -> listBannerText ( $ row ) ; break ; default : return false ; break ; } }
|
List banner record
|
2,942
|
public function getBannerImageSizes ( ) { $ sizes = array ( ) ; $ imageSize = $ this -> Database -> prepare ( "SELECT id, name, width, height FROM tl_image_size ORDER BY pid, name" ) -> execute ( \ Input :: get ( 'id' ) ) ; while ( $ imageSize -> next ( ) ) { $ sizes [ $ imageSize -> id ] = $ imageSize -> name ; $ sizes [ $ imageSize -> id ] .= ' (' . $ imageSize -> width . 'x' . $ imageSize -> height . ')' ; } return array_merge ( array ( 'image_sizes' => $ sizes ) , $ GLOBALS [ 'TL_CROP' ] ) ; }
|
Return all image sizes as array
|
2,943
|
public function group ( $ prefix , callable $ group ) { $ group = new RouteGroup ( $ prefix , $ group , $ this ) ; $ this -> groups [ ] = $ group ; return $ group ; }
|
Add a group of routes to the collection .
|
2,944
|
protected function discoverClasses ( array $ namespaces ) : array { $ classes = [ ] ; foreach ( $ namespaces as $ namespace => $ namespace_directories ) { $ namespace_directories = array_filter ( $ namespace_directories , function ( $ dir ) { return is_dir ( $ dir ) ; } ) ; foreach ( $ namespace_directories as $ namespace_directory ) { $ finder = $ this -> createFinder ( ) -> files ( ) -> name ( '*.php' ) -> in ( $ namespace_directory ) -> path ( $ this -> subdir ) ; foreach ( $ finder as $ file ) { $ sub_path = substr ( $ file -> getPath ( ) , strlen ( $ namespace_directory ) ) ; if ( ! empty ( $ sub_path ) ) { $ sub_path = substr ( $ sub_path , 1 ) ; $ sub_path = str_replace ( '/' , '\\' , $ sub_path ) ; $ sub_path .= '\\' ; $ classes [ ] = $ namespace . $ sub_path . $ file -> getBasename ( '.php' ) ; } } } } return $ classes ; }
|
Discover files that look like avatar service classes .
|
2,945
|
protected function discoverAnnotations ( array $ classes ) : array { AnnotationRegistry :: reset ( ) ; AnnotationRegistry :: registerLoader ( 'class_exists' ) ; $ reader = $ this -> createReader ( ) ; $ annotations = [ ] ; foreach ( $ classes as $ class ) { $ reflection = new \ ReflectionClass ( $ class ) ; if ( ! $ reflection -> isSubclassOf ( $ this -> serviceInterface ) ) { continue ; } $ annotation = $ reader -> getClassAnnotation ( $ reflection , $ this -> annotationClass ) ; if ( $ annotation ) { $ annotations [ $ class ] = $ annotation ; } } AnnotationRegistry :: reset ( ) ; return $ annotations ; }
|
Discovers and caches annotations .
|
2,946
|
protected function registerResources ( ContainerBuilder $ container ) { $ templatingEngines = $ container -> getParameter ( 'templating.engines' ) ; if ( in_array ( 'twig' , $ templatingEngines ) ) { $ container -> setParameter ( 'twig.form.resources' , array_merge ( array ( 'FenrizbesColorPickerTypeBundle:Form:fields.html.twig' ) , $ container -> getParameter ( 'twig.form.resources' ) ) ) ; } }
|
Registers form templates
|
2,947
|
protected function getClientInitializer ( Application $ app , $ prefix ) { return $ app -> protect ( function ( $ args ) use ( $ app , $ prefix ) { $ extract = function ( $ bag , $ key ) use ( $ app , $ prefix ) { $ default = "default_$key" ; if ( $ bag instanceof Application ) { $ key = "$prefix.$key" ; var_dump ( $ key ) ; } if ( ! isset ( $ bag [ $ key ] ) ) { return $ app [ "$prefix.$default" ] ; } if ( is_array ( $ bag [ $ key ] ) ) { return array_merge ( $ app [ "$prefix.$default" ] , $ bag [ $ key ] ) ; } return $ bag [ $ key ] ; } ; if ( isset ( $ args [ 'parameters' ] ) && is_string ( $ args [ 'parameters' ] ) ) { $ args [ 'parameters' ] = $ app [ "$prefix.uri_parser" ] ( $ args [ 'parameters' ] ) ; } $ parameters = $ extract ( $ args , 'parameters' ) ; $ options = $ extract ( $ args , 'options' ) ; return $ app [ "$prefix.client_constructor" ] ( $ parameters , $ options ) ; } ) ; }
|
Returns an anonymous function used by the service provider initialize lazily new instances of Redis \ Client .
|
2,948
|
public static function fromJson ( string $ json ) : self { $ input = json_decode ( $ json , true ) ; $ data = reset ( $ input ) ; $ locale = key ( $ input ) ; return new self ( $ locale , $ data ) ; }
|
Factory method to create a translation resource from a JSON string
|
2,949
|
private function setLocale ( string $ locale ) { $ arr = \ Locale :: parseLocale ( $ locale ) ; if ( $ arr === false ) { throw new \ InvalidArgumentException ( 'Invalid locale' ) ; } $ this -> locale = $ arr ; }
|
Sets the locale of the resource
|
2,950
|
public function addData ( array $ data , bool $ overwrite = true ) : void { if ( $ overwrite ) { $ this -> data = array_merge ( $ this -> data , $ data ) ; } else { $ this -> data = array_merge ( $ data , $ this -> data ) ; } }
|
Adds translation values to the resource
|
2,951
|
public function merge ( self $ resource , bool $ overwrite = true ) : void { if ( $ this -> getLocale ( ) !== $ resource -> getLocale ( ) ) { trigger_error ( 'Attempting to merge resources of different locale' , \ E_USER_NOTICE ) ; } $ this -> addData ( $ resource -> data , ( bool ) $ overwrite ) ; }
|
Merges a resource into the current resource
|
2,952
|
public function jsonSerialize ( ) : string { $ output = array ( $ this -> getLocale ( ) => $ this -> data ) ; return json_encode ( $ output , JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG ) ; }
|
Serializes the resource into a JSON object
|
2,953
|
public function dump ( $ data , $ ttl = null ) { return $ this -> getCache ( ) -> setNamespace ( self :: CACHE_NAMESPACE ) -> set ( self :: CACHE_NAME , $ data , $ ttl === null ? self :: DEFAULTTTL : intval ( $ ttl ) ) ; }
|
Store the routing table in cache
|
2,954
|
public function evaluate ( $ value , $ filters ) { if ( false === is_array ( $ filters ) ) { $ filters = [ $ filters ] ; } foreach ( $ filters as $ filter ) { $ value = $ this -> evaluateFilter ( $ value , $ filter ) ; } return $ value ; }
|
Evaluates the given value with the given filters .
|
2,955
|
public function controllers ( array $ controllers ) { $ group = new Group ; foreach ( $ controllers as $ controller ) $ group -> set ( $ this -> controller ( $ controller ) ) ; return $ group ; }
|
Maps several controllers at same time .
|
2,956
|
public function appendToStructureSql ( $ statement , $ comment = '' ) { if ( $ structure_sql_path = $ this -> getStructureSqlPath ( ) ) { $ current_content = file_get_contents ( $ structure_sql_path ) ; if ( $ current_content ) { $ current_content .= "\n\n\n\n" ; } if ( $ comment ) { $ current_content .= "# $comment\n" ; } file_put_contents ( $ structure_sql_path , $ current_content . $ statement ) ; } }
|
Append statement to SQL file .
|
2,957
|
public function match ( array $ methods , $ pattern , $ action ) { $ group = new Group ; foreach ( $ methods as $ method ) $ group -> set ( $ this -> set ( $ method , $ pattern , $ action ) ) ; return $ group ; }
|
Insert a route into several http methods .
|
2,958
|
public function any ( $ pattern , $ action ) { return $ this -> match ( explode ( " " , self :: HTTP_METHODS ) , $ pattern , $ action ) ; }
|
Insert a route into every http method supported .
|
2,959
|
public function except ( $ methods , $ pattern , $ action ) { return $ this -> match ( array_diff ( explode ( " " , self :: HTTP_METHODS ) , ( array ) $ methods ) , $ pattern , $ action ) ; }
|
Insert a route into every http method supported but the given ones .
|
2,960
|
public function group ( array $ routes ) { $ group = new Group ; foreach ( $ routes as $ route ) $ group -> set ( $ route ) ; return $ group ; }
|
Group all given routes .
|
2,961
|
public function forget ( $ method , $ pattern ) { if ( strpos ( $ pattern , "{" ) === false ) { unset ( $ this -> statics [ $ method ] [ $ pattern ] ) ; } else unset ( $ this -> dynamics [ $ this -> getDynamicIndex ( $ method , $ pattern ) ] [ $ pattern ] ) ; }
|
Remove a route from collector .
|
2,962
|
protected function getValidMethod ( $ method ) { $ method = strtolower ( $ method ) ; if ( strpos ( self :: HTTP_METHODS , $ method ) === false ) { throw new MethodNotSupportedException ( $ method ) ; } return $ method ; }
|
Determine if the http method is valid .
|
2,963
|
final public function traverse ( array & $ arr ) { if ( ! $ this -> isReady ( ) ) { throw new \ RuntimeException ( "The traverser is not ready, no valid item callback has been set." ) ; } return static :: run ( $ arr , $ this -> itemCallback , $ this -> resultCallback ) ; }
|
Runs the given array through the Traverser s callbacks .
|
2,964
|
public static function run ( array & $ arr , callable $ itemCallback , callable $ resultCallback = null ) { $ result = [ ] ; foreach ( $ arr as $ key => & $ value ) { $ r = $ itemCallback ( $ value , $ key , $ arr ) ; $ result [ $ key ] = $ r ; } if ( ! is_null ( $ resultCallback ) ) { return $ resultCallback ( $ result , $ arr ) ; } return $ result ; }
|
Runs the traverser across the given array and executes the item callback into every item of the array .
|
2,965
|
private function getValidProductPriceForItem ( $ item , $ currency ) { $ product = $ item -> getCalcProduct ( ) ; $ specialPriceValue = null ; $ bulkPriceValue = null ; $ specialPrice = $ this -> priceManager -> getSpecialPriceForCurrency ( $ product , $ currency ) ; if ( $ specialPrice ) { $ specialPriceValue = $ specialPrice -> getPrice ( ) ; } $ bulkPrice = $ this -> priceManager -> getBulkPriceForCurrency ( $ product , $ item -> getCalcQuantity ( ) , $ currency ) ; if ( $ bulkPrice ) { $ bulkPriceValue = $ bulkPrice -> getPrice ( ) ; } if ( ! empty ( $ specialPriceValue ) && ! empty ( $ bulkPriceValue ) ) { $ priceValue = $ specialPriceValue ; if ( $ specialPriceValue > $ bulkPriceValue ) { $ priceValue = $ bulkPriceValue ; } } elseif ( ! empty ( $ specialPriceValue ) ) { $ priceValue = $ specialPriceValue ; } else { $ priceValue = $ bulkPriceValue ; } if ( empty ( $ priceValue ) ) { return 0 ; } return $ priceValue ; }
|
Returns the valid product price for item
|
2,966
|
public function calculate ( $ item , $ currency = null , $ useProductsPrice = true ) { $ currency = $ this -> getCurrency ( $ currency ) ; $ this -> validateItem ( $ item ) ; if ( $ useProductsPrice ) { $ priceValue = $ this -> getValidProductPriceForItem ( $ item , $ currency ) ; } else { $ priceValue = $ item -> getPrice ( ) ; } $ this -> validateNotNull ( 'price' , $ priceValue ) ; if ( $ item -> getPrice ( ) && $ item -> getPrice ( ) !== $ priceValue ) { $ item -> setPriceChange ( $ item -> getPrice ( ) , $ priceValue ) ; } $ itemPrice = $ priceValue * $ item -> getCalcQuantity ( ) ; $ discount = ( $ itemPrice / 100 ) * $ item -> getCalcDiscount ( ) ; $ totalPrice = $ itemPrice - $ discount ; return $ totalPrice ; }
|
Calculates the overall total price of an item
|
2,967
|
protected function validateItem ( $ item ) { $ this -> validateNotNull ( 'quantity' , $ item -> getCalcQuantity ( ) ) ; $ discountPercent = $ item -> getCalcDiscount ( ) ; if ( $ discountPercent < 0 || $ discountPercent > 100 ) { throw new PriceCalculationException ( 'Discount must be within 0 and 100 percent' ) ; } }
|
Validate item values
|
2,968
|
private function duration ( $ time ) { if ( is_numeric ( $ time ) ) { return $ time ; } return ( new \ DateTime ( $ time ) ) -> getTimestamp ( ) - ( new \ DateTime ( 'now' ) ) -> getTimestamp ( ) ; }
|
Convert a potential string date like + 30 days to seconds .
|
2,969
|
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ message = $ this -> getContainer ( ) -> get ( $ this -> serviceAlias ) ; if ( get_class ( $ message ) !== $ this -> serviceClass ) { throw new InvalidArgumentException ( sprintf ( 'The specified service alias (%s) and class (%s) do not correspond to each other.' , $ this -> serviceAlias , $ this -> serviceClass ) ) ; } $ message -> setCliCommand ( $ this ) ; $ message -> setInput ( $ input ) ; $ message -> setOutput ( $ output ) ; $ this -> getCommandBus ( ) -> handle ( $ message ) ; }
|
Executes the current command by retrieving its associated Message from the Container setting the Input and Output according to what was received as parameters and finally passing that Message to the CommandBus for handling .
|
2,970
|
public function getBoolean ( string $ optionName ) : bool { return in_array ( $ this -> get ( $ optionName ) , self :: TRUE_VALUES , true ) ; }
|
Cast an option value into boolean .
|
2,971
|
protected function convert ( $ num ) { if ( $ num instanceof NumericTypeInterface ) { return $ num ; } if ( is_numeric ( $ num ) ) { return $ this -> calcEngine -> convertNumeric ( $ num ) ; } $ type = ( is_object ( $ num ) ? get_class ( $ num ) : gettype ( $ num ) ) ; throw new \ BadMethodCallException ( 'No solution for unknown type: ' . $ type ) ; }
|
Convert into Strong Numeric Type
|
2,972
|
public function getCard ( $ userId , $ cardId ) { $ card = $ this -> client -> get ( $ this -> getResourceEndpoint ( $ userId ) . '/' . ( int ) $ cardId ) ; return $ card [ 'Response' ] [ 0 ] ; }
|
Gets a user its card information .
|
2,973
|
public function beforeEntityDelete ( $ entity , & $ idx ) { $ this -> undeleteReasons = [ ] ; $ entityMetadata = $ this -> em -> getClassMetadata ( get_class ( $ entity ) ) ; $ associations = $ entityMetadata -> getAssociationMappings ( ) ; foreach ( $ associations as $ association ) { if ( in_array ( 'remove' , $ association [ 'cascade' ] ) ) { continue ; } if ( ! in_array ( $ association [ 'type' ] , [ ClassMetadata :: ONE_TO_MANY ] ) ) { continue ; } $ propertyAccessor = new PropertyAccessor ( ) ; $ associationData = $ propertyAccessor -> getValue ( $ entity , $ association [ 'fieldName' ] ) ; if ( $ associationData instanceof Collection ) { if ( $ associationData -> count ( ) > 0 ) { $ this -> removeFromIdsArray ( $ entityMetadata -> getIdentifierValues ( $ entity ) , $ idx , $ association ) ; } } elseif ( $ associationData !== null ) { $ this -> removeFromIdsArray ( $ entityMetadata -> getIdentifierValues ( $ entity ) , $ idx , $ association ) ; } } return $ this -> undeleteReasons ; }
|
Hande entity relations before trying to remove it .
|
2,974
|
protected function getSupportedParams ( $ method ) { $ columns = [ ] ; if ( $ this -> isEloquentBuilder ( ) ) { $ model = $ this -> getHandler ( ) -> getModel ( ) ; $ columns = in_array ( ApiHelper :: class , class_uses ( $ model ) ) ? $ model -> $ method ( ) : $ model -> getFillable ( ) ; } return $ columns ; }
|
Get supported params .
|
2,975
|
protected function parse ( ) { $ this -> parseParam ( 'sort' ) ; $ this -> parseParam ( 'fields' ) ; $ this -> parseParam ( 'limit' ) ; if ( $ this -> isEloquentBuilder ( ) ) { $ this -> parseParam ( 'with' ) ; } $ this -> parseFilter ( ) ; }
|
Parse the data from the request .
|
2,976
|
protected function parseParam ( $ param ) { $ method = 'parse' . ucfirst ( $ param ) ; if ( method_exists ( $ this , $ method ) ) { if ( $ params = $ this -> input ( $ param ) ) { return $ this -> $ method ( $ params ) ; } } }
|
Parse the special param .
|
2,977
|
protected function parseSort ( $ params ) { foreach ( explode ( ',' , $ params ) as $ sort ) { if ( preg_match ( '/^-.+/' , $ sort ) ) { $ direction = 'desc' ; } else { $ direction = 'asc' ; } $ sort = preg_replace ( '/^-/' , '' , $ sort ) ; if ( ! $ this -> canSort ( $ sort ) ) { return ; } if ( ! Str :: contains ( $ sort , '.' ) ) { $ this -> getHandler ( ) -> orderBy ( $ sort , $ direction ) ; } else { $ this -> additionalSorts [ $ sort ] = $ direction ; } } }
|
Parse the sort parameter .
|
2,978
|
protected function parseFields ( $ params ) { foreach ( explode ( ',' , $ params ) as $ field ) { if ( ! Str :: contains ( $ field , '.' ) ) { $ this -> fields [ ] = trim ( $ field ) ; } else { $ this -> additionalFields [ ] = trim ( $ field ) ; } } }
|
Parse the fields parameter .
|
2,979
|
protected function parseWith ( $ params ) { $ with = explode ( ',' , $ params ) ; $ withable = $ this -> getSupportedParams ( 'getApiWithable' ) ; $ with = in_array ( '*' , $ withable ) ? $ with : array_only ( $ with , $ withable ) ; foreach ( $ this -> additionalSorts as $ sort => $ direction ) { $ parts = explode ( '.' , $ sort ) ; $ realKey = array_pop ( $ parts ) ; $ relation = implode ( '.' , $ parts ) ; if ( in_array ( $ relation , $ with ) ) { $ this -> builder -> with ( [ $ relation => function ( $ query ) use ( $ realKey , $ direction ) { $ query -> orderBy ( $ realKey , $ direction ) ; } ] ) ; if ( ( $ key = array_search ( $ relation , $ with ) ) !== false ) { unset ( $ with [ $ key ] ) ; } } } if ( ! empty ( $ with ) ) { $ this -> builder -> with ( $ with ) ; } $ this -> with = $ this -> builder -> getEagerLoads ( ) ; }
|
Parse the with parameter .
|
2,980
|
protected function parseFilter ( ) { if ( ! $ params = $ this -> getParams ( ) ) { return ; } foreach ( $ params as $ key => $ value ) { if ( $ this -> isEloquentBuilder ( ) && Str :: contains ( $ key , '~' ) ) { $ this -> filterRelation ( $ key , $ value ) ; } else { $ this -> filter ( $ key , $ value ) ; } } }
|
Parse all the paramenters for query builder .
|
2,981
|
protected function formatParam ( $ key , $ value ) { $ supportedFixes = [ 'lt' => '<' , 'gt' => '>' , 'lte' => '<=' , 'gte' => '>=' , 'lk' => 'LIKE' , 'not-lk' => 'NOT LIKE' , 'in' => 'IN' , 'not-in' => 'NOT IN' , 'not' => '!=' , ] ; $ prefixes = implode ( '|' , $ supportedFixes ) ; $ suffixes = implode ( '|' , array_keys ( $ supportedFixes ) ) ; $ matches = [ ] ; $ regex = '/^(?:(' . $ prefixes . ')-)?(.*?)(?:-(' . $ suffixes . ')|$)/' ; preg_match ( $ regex , $ key , $ matches ) ; if ( ! isset ( $ matches [ 3 ] ) ) { if ( Str :: lower ( trim ( $ value ) ) == 'null' ) { $ comparator = 'NULL' ; } else { $ comparator = '=' ; } } else { if ( Str :: lower ( trim ( $ value ) ) == 'null' ) { $ comparator = 'NOT NULL' ; } else { $ comparator = $ supportedFixes [ $ matches [ 3 ] ] ; } } $ column = isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : null ; return compact ( 'comparator' , 'column' , 'matches' ) ; }
|
Format the paramenter for query builder .
|
2,982
|
protected function filter ( $ key , $ value ) { extract ( $ this -> formatParam ( $ key , $ value ) ) ; if ( ! $ this -> canFilter ( $ column ) ) { return ; } if ( $ comparator == 'IN' ) { $ values = explode ( ',' , $ value ) ; $ this -> getHandler ( ) -> whereIn ( $ column , $ values ) ; } elseif ( $ comparator == 'NOT IN' ) { $ values = explode ( ',' , $ value ) ; $ this -> getHandler ( ) -> whereNotIn ( $ column , $ values ) ; } else { $ values = explode ( '|' , $ value ) ; if ( count ( $ values ) > 1 ) { $ this -> getHandler ( ) -> where ( function ( $ query ) use ( $ column , $ comparator , $ values ) { foreach ( $ values as $ value ) { if ( $ comparator == 'LIKE' || $ comparator == 'NOT LIKE' ) { $ value = preg_replace ( '/(^\*|\*$)/' , '%' , $ value ) ; } if ( $ comparator == '!=' || $ comparator == 'NOT LIKE' ) { $ query -> where ( $ column , $ comparator , $ value ) ; } else { $ query -> orWhere ( $ column , $ comparator , $ value ) ; } } } ) ; } else { $ value = $ values [ 0 ] ; if ( $ comparator == 'LIKE' || $ comparator == 'NOT LIKE' ) { $ value = preg_replace ( '/(^\*|\*$)/' , '%' , $ value ) ; } if ( $ comparator == 'NULL' || $ comparator == 'NOT NULL' ) { $ this -> getHandler ( ) -> whereNull ( $ column , 'and' , $ comparator == 'NOT NULL' ) ; } else { $ this -> getHandler ( ) -> where ( $ column , $ comparator , $ value ) ; } } } }
|
Apply the filter to query builder .
|
2,983
|
protected function filterRelation ( $ key , $ value ) { $ key = str_replace ( '~' , '.' , $ key ) ; $ parts = explode ( '.' , $ key ) ; $ realKey = array_pop ( $ parts ) ; $ relation = implode ( '.' , $ parts ) ; if ( ! in_array ( $ relation , array_keys ( $ this -> with ) ) ) { return ; } extract ( $ this -> formatParam ( $ realKey , $ value ) ) ; if ( ! $ this -> canFilter ( $ column ) ) { return ; } $ this -> builder -> whereHas ( $ relation , function ( $ q ) use ( $ column , $ comparator , $ value ) { if ( $ comparator == 'IN' ) { $ values = explode ( ',' , $ value ) ; $ q -> whereIn ( $ column , $ values ) ; } elseif ( $ comparator == 'NOT IN' ) { $ values = explode ( ',' , $ value ) ; $ q -> whereNotIn ( $ column , $ values ) ; } else { $ values = explode ( '|' , $ value ) ; if ( count ( $ values ) > 1 ) { $ q -> where ( function ( $ query ) use ( $ column , $ comparator , $ values ) { foreach ( $ values as $ value ) { if ( $ comparator == 'LIKE' || $ comparator == 'NOT LIKE' ) { $ value = preg_replace ( '/(^\*|\*$)/' , '%' , $ value ) ; } if ( $ comparator == '!=' || $ comparator == 'NOT LIKE' ) { $ query -> where ( $ column , $ comparator , $ value ) ; } else { $ query -> orWhere ( $ column , $ comparator , $ value ) ; } } } ) ; } else { $ value = $ values [ 0 ] ; if ( $ comparator == 'LIKE' || $ comparator == 'NOT LIKE' ) { $ value = preg_replace ( '/(^\*|\*$)/' , '%' , $ value ) ; } if ( $ comparator == 'NULL' || $ comparator == 'NOT NULL' ) { $ q -> whereNull ( $ column , 'and' , $ comparator == 'NOT NULL' ) ; } else { $ q -> where ( $ column , $ comparator , $ value ) ; } } } } ) ; }
|
Apply the filter to relationship query builder .
|
2,984
|
protected function getParams ( ) { $ reserved = [ $ this -> config ( 'prefix' , '' ) . 'sort' , $ this -> config ( 'prefix' , '' ) . 'fields' , $ this -> config ( 'prefix' , '' ) . 'limit' , $ this -> config ( 'prefix' , '' ) . 'with' , $ this -> config ( 'prefix' , '' ) . 'page' , ] ; return $ this -> params ? : $ this -> request -> except ( $ reserved ) ; }
|
Get the params from the request .
|
2,985
|
protected function getHandler ( ) { if ( $ this -> builder ) { return $ this -> builder ; } if ( $ this -> query ) { return $ this -> query ; } throw new InvalidArgumentException ( 'Missing query builder' ) ; }
|
Get the handler .
|
2,986
|
protected function liberatorPropertyReflector ( $ property ) { $ classReflector = $ this -> liberatorReflector ( ) ; while ( $ classReflector ) { if ( $ classReflector -> hasProperty ( $ property ) ) { $ propertyReflector = $ classReflector -> getProperty ( $ property ) ; $ propertyReflector -> setAccessible ( true ) ; return $ propertyReflector ; } $ classReflector = $ classReflector -> getParentClass ( ) ; } return null ; }
|
Get a property reflector .
|
2,987
|
public function interceptMethodCall ( ProceedingJoinPointInterface $ jointPoint ) { try { return $ jointPoint -> proceed ( ) ; } catch ( Exception $ e ) { $ methodName = $ jointPoint -> getMethodName ( ) ; $ partialTrace = array ( ) ; $ trace = $ e -> getTrace ( ) ; $ depth = 0 ; foreach ( $ trace as $ entry ) { if ( $ depth > $ this -> maxTraceDepth ) { $ partialTrace [ ] = "... trace truncated" ; break ; } $ file = isset ( $ entry [ 'file' ] ) ? $ entry [ 'file' ] : "" ; $ function = isset ( $ entry [ 'function' ] ) ? $ entry [ 'function' ] : "" ; $ line = isset ( $ entry [ 'line' ] ) ? $ entry [ 'line' ] : "" ; $ partialTrace [ ] = sprintf ( "%s:%s:%s" , $ file , $ function , $ line ) ; $ depth ++ ; } $ msg = sprintf ( "Exception in %s:%s:%s (%d) %s" , $ e -> getFile ( ) , $ e -> getLine ( ) , $ methodName , $ e -> getCode ( ) , $ e -> getMessage ( ) ) ; $ this -> logger -> logWarning ( $ msg , implode ( "\n" , $ partialTrace ) ) ; throw $ e ; } }
|
In this implementation we log each exception and rethrow .
|
2,988
|
function Services_JSON ( $ use = 0 ) { $ this -> use = $ use ; $ this -> _mb_strlen = function_exists ( 'mb_strlen' ) ; $ this -> _mb_convert_encoding = function_exists ( 'mb_convert_encoding' ) ; $ this -> _mb_substr = function_exists ( 'mb_substr' ) ; }
|
constructs a new JSON instance
|
2,989
|
function encodeUnsafe ( $ var ) { $ lc = setlocale ( LC_NUMERIC , 0 ) ; setlocale ( LC_NUMERIC , 'C' ) ; $ ret = $ this -> _encode ( $ var ) ; setlocale ( LC_NUMERIC , $ lc ) ; return $ ret ; }
|
encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!! )
|
2,990
|
public function setKeyframes ( $ keyframes ) { $ this -> keyframes = [ ] ; if ( ! is_array ( $ keyframes ) ) { $ keyframes = [ $ keyframes ] ; } foreach ( $ keyframes as $ keyframe ) { $ this -> addKeyframe ( $ keyframe ) ; } return $ this ; }
|
Sets the keyframes .
|
2,991
|
public function addDeclaration ( DeclarationAbstract $ declaration ) { if ( $ declaration instanceof KeyframesDeclaration ) { $ this -> declarations [ ] = $ declaration ; } else { throw new \ InvalidArgumentException ( "Invalid declaration instance. Instance of 'KeyframesDeclaration' expected." ) ; } return $ this ; }
|
Adds a keyframes declaration .
|
2,992
|
protected function parseKeyframeList ( $ keyframeList ) { foreach ( explode ( "," , $ keyframeList ) as $ keyframe ) { $ keyframe = trim ( $ keyframe , " \r\n\t\f" ) ; $ this -> addKeyframe ( new KeyframesKeyframe ( $ keyframe , $ this -> getStyleSheet ( ) ) ) ; } }
|
Parses a string of keyframes .
|
2,993
|
public function addMenu ( ) { add_submenu_page ( 'tools.php' , __ ( 'StaticWP' , $ this -> plugin ) , __ ( 'StaticWP' , $ this -> plugin ) , 'manage_options' , $ this -> plugin , array ( $ this , 'viewPage' ) ) ; }
|
Creates menu for StaticWP admin pages .
|
2,994
|
public function deactivate ( ) { $ muPluginFile = WP_CONTENT_DIR . '/mu-plugins/' . $ this -> plugin . '-mu.php' ; if ( is_file ( $ muPluginFile ) ) { unlink ( $ muPluginFile ) ; } if ( is_dir ( $ this -> destination ) ) { $ this -> rrmdir ( dirname ( $ this -> destination ) ) ; } delete_option ( $ this -> plugin . 'version' ) ; delete_option ( 'staticwp_deferred_admin_notices' ) ; }
|
Cleans up after itself on deactivation .
|
2,995
|
public static function displayNotices ( ) { if ( $ notices = get_option ( 'staticwp_deferred_admin_notices' ) ) { foreach ( $ notices as $ notice ) { $ message = $ notice ; $ type = 'updated' ; if ( is_array ( $ notice ) ) { $ message = isset ( $ notice [ 'message' ] ) ? $ notice [ 'message' ] : '' ; $ type = isset ( $ notice [ 'type' ] ) ? $ notice [ 'type' ] : $ type ; } echo '<div class="' . $ type . '"><p>' . $ message . '</p></div>' ; } delete_option ( 'staticwp_deferred_admin_notices' ) ; } }
|
Displays admin notices .
|
2,996
|
public static function errorToException ( $ num , $ mes , $ file = null , $ line = null , $ context = null ) { throw new Exception ( $ mes , $ num ) ; }
|
Error handler to convert errors to exceptions to make it easier to catch them .
|
2,997
|
public function handlePost ( ) { if ( ! isset ( $ _POST [ 'staticwp-action' ] ) ) { return ; } if ( ! check_admin_referer ( 'staticwp' ) ) { return ; } switch ( $ _POST [ 'staticwp-action' ] ) { case 'preload' : set_error_handler ( array ( __CLASS__ , 'errorToException' ) , E_ALL ) ; try { $ types = apply_filters ( 'staticwp_preload_post_types' , array ( 'post' , 'page' ) ) ; foreach ( $ types as $ type ) { $ this -> preload ( $ type ) ; } $ this -> addNotice ( View :: notice ( 'admin/preload-success' ) ) ; } catch ( Exception $ e ) { $ this -> addNotice ( View :: notice ( 'admin/preload-error' , 'error' ) ) ; } restore_error_handler ( ) ; wp_reset_postdata ( ) ; wp_safe_redirect ( self :: url ( 'preload' ) ) ; exit ( ) ; break ; default : break ; } }
|
Handles form submission on StaticWP admin pages .
|
2,998
|
public function update ( ) { $ version = get_option ( $ this -> plugin . 'version' ) ; if ( $ version != STATICWP_VERSION ) { update_option ( $ this -> plugin . 'version' , STATICWP_VERSION ) ; } }
|
Handles plugin updates .
|
2,999
|
public function viewPage ( ) { $ page = isset ( $ _GET [ 'sub' ] ) ? ( string ) $ _GET [ 'sub' ] : self :: DEFAULT_SUB_PAGE ; View :: page ( 'admin/' . $ page ) ; }
|
Displays a page .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.