idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
3,500
|
public function validateRedirectHeader ( string $ headerName ) : ValueValidator { if ( $ this -> headers -> contain ( 'REDIRECT_' . $ headerName ) ) { return $ this -> validateHeader ( 'REDIRECT_' . $ headerName ) ; } return $ this -> validateHeader ( $ headerName ) ; }
|
checks whether a request value from redirect headers is valid or not
|
3,501
|
public function readCookie ( string $ cookieName ) : ValueReader { return new ValueReader ( $ this -> cookies -> errors ( ) , $ cookieName , $ this -> cookies -> value ( $ cookieName ) ) ; }
|
returns request value from cookies for filtering or validation
|
3,502
|
public function calculateItemTotalNetPrice ( $ item , $ currency = null , $ useProductsPrice = true , $ isGrossPrice = false ) { $ priceValue = $ this -> calculateItemNetPrice ( $ item , $ currency , $ useProductsPrice , $ isGrossPrice ) ; if ( $ priceValue === null ) { $ priceValue = 0 ; } 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 .
|
3,503
|
public function calculateItemNetPrice ( $ item , $ currency = null , $ useProductsPrice = null , $ isGrossPrice = false ) { $ currency = $ this -> getCurrency ( $ currency ) ; if ( $ useProductsPrice === null ) { $ useProductsPrice = $ item -> getUseProductsPrice ( ) ; } $ this -> validateItem ( $ item ) ; $ priceValue = $ item -> getPrice ( ) ; if ( $ useProductsPrice && ( $ item -> getCalcProduct ( ) || $ item -> getAddon ( ) ) ) { $ priceValue = $ this -> getValidProductNetPriceForItem ( $ item , $ currency ) ; } elseif ( $ isGrossPrice ) { $ tax = $ item -> getTax ( ) ; if ( $ tax > 0 ) { $ priceValue = ( $ priceValue / ( 100 + $ tax ) ) * 100 ; } } return $ priceValue ; }
|
Returns price of a single item based on it s quantity .
|
3,504
|
public function formatPrice ( $ price , $ currency , $ locale = null ) { return $ this -> priceManager -> getFormattedPrice ( $ price , $ currency , $ locale ) ; }
|
Format price .
|
3,505
|
private function getValidProductNetPriceForItem ( CalculableBulkPriceItemInterface $ item , $ currency ) { $ product = $ item -> getCalcProduct ( ) ; $ areGrossPrices = false ; $ addon = $ item -> getAddon ( ) ; if ( $ addon ) { $ addonPrice = $ this -> priceManager -> getAddonPriceForCurrency ( $ item -> getAddon ( ) , $ currency ) ; if ( $ addonPrice ) { $ priceValue = $ addonPrice -> getPrice ( ) ; } else { $ priceValue = $ this -> getPriceOfProduct ( $ addon -> getAddon ( ) , $ item -> getCalcQuantity ( ) , $ currency ) ; } $ areGrossPrices = $ addon -> getAddon ( ) -> getAreGrossPrices ( ) ; } elseif ( $ product ) { $ priceValue = $ this -> getPriceOfProduct ( $ item -> getCalcProduct ( ) , $ item -> getCalcQuantity ( ) , $ currency ) ; $ areGrossPrices = $ product -> getAreGrossPrices ( ) ; if ( $ product -> getParent ( ) ) { $ areGrossPrices = $ product -> getParent ( ) -> getAreGrossPrices ( ) ; } } if ( empty ( $ priceValue ) ) { return 0 ; } if ( $ areGrossPrices ) { $ tax = $ item -> getTax ( ) ; if ( $ tax > 0 ) { $ priceValue = ( $ priceValue / ( 100 + $ tax ) ) * 100 ; } } return $ priceValue ; }
|
Returns the valid product net price for item .
|
3,506
|
private function retrieveProductTypeIdByKey ( $ key ) { if ( ! isset ( $ this -> productTypesMap [ $ key ] ) ) { return null ; } return intval ( $ this -> productTypesMap [ $ key ] ) ; }
|
Returns product type id by key .
|
3,507
|
public function getAll ( $ identity , $ page = 1 , $ perPage = 25 ) { $ params = array ( 'page' => $ page , 'per_page' => $ perPage ) ; return $ this -> _user -> get ( 'account/identity/' . $ identity . '/token' , $ params ) ; }
|
Get all the tokens for an identity
|
3,508
|
public function create ( $ identity , $ service , $ token ) { $ params = array ( 'service' => $ service , 'token' => $ token , ) ; return $ this -> _user -> post ( 'account/identity/' . $ identity . '/token' , $ params ) ; }
|
Creates a token for a service
|
3,509
|
public function update ( $ identity , $ service , $ token ) { $ params = array ( 'token' => $ token , ) ; return $ this -> _user -> put ( 'account/identity/' . $ identity . '/token/' . $ service , $ params ) ; }
|
Updates the token for a service
|
3,510
|
public function delete ( $ identity , $ service ) { $ successCode = array ( DataSift_ApiClient :: HTTP_NO_CONTENT ) ; return $ this -> _user -> delete ( 'account/identity/' . $ identity . '/token/' . $ service ) ; }
|
Deletes a token for a service
|
3,511
|
public function & possibilities ( ... $ possibilities ) { if ( $ this -> getDefaultValue ( ) !== null && ! in_array ( $ this -> getDefaultValue ( ) , $ possibilities ) ) { throw new InvalidArgumentException ( 'Default value ' . var_export ( $ this -> getDefaultValue ( ) , true ) . ' needs to be in the list of possibilities' ) ; } $ this -> possibilities = $ possibilities ; return $ this ; }
|
Set a list of possible values .
|
3,512
|
public static function getDateTime ( ) { $ dt = \ DateTime :: createFromFormat ( 'U.u' , microtime ( true ) ) ; $ dt -> setTimezone ( new \ DateTimeZone ( date ( 'e' ) ) ) ; return $ dt ; }
|
Returns DateTime object .
|
3,513
|
public function getConnectionTableName ( ) { $ type_names = [ $ this -> getSourceTypeName ( ) , $ this -> getTargetTypeName ( ) ] ; sort ( $ type_names ) ; return implode ( '_' , $ type_names ) ; }
|
Return connection table name .
|
3,514
|
public static function extractUrl ( $ url ) { if ( is_string ( $ url ) ) { $ url = Placeholder :: replaceStringPlaceholders ( $ url ) ; $ url = preg_replace ( '/^url\(|\)$/' , '' , $ url ) ; $ url = str_replace ( [ "\\(" , "\\)" , "\\ " , "\\'" , "\\\"" ] , [ "(" , ")" , " " , "'" , "\"" ] , $ url ) ; $ url = preg_replace ( '/^(["\'])(.*)\g{1}$/' , '\\2' , $ url ) ; $ url = urldecode ( $ url ) ; return $ url ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ url ) . "' for argument 'url' given." ) ; } }
|
Extracts the URL from a CSS URL value .
|
3,515
|
function range ( $ min = null , $ max = null ) { $ this -> min ( $ min ) ; $ this -> max ( $ max ) ; return $ this ; }
|
Set the minimum and maximum
|
3,516
|
function exclusiveRange ( $ min = null , $ max = null ) { $ this -> exclusiveMin ( $ min ) ; $ this -> exclusiveMax ( $ max ) ; return $ this ; }
|
Set the exclusive minimum and maximum
|
3,517
|
public function add ( $ tag ) { if ( ! $ tag instanceof TagInterface ) { throw new \ InvalidArgumentException ( 'This tag is not allowed' ) ; } if ( $ this -> isUniqueTag ( $ tag -> getName ( ) ) ) { $ this -> removeByName ( $ tag -> getName ( ) ) ; } return parent :: add ( $ tag ) ; }
|
Adds a new Tag on Dockblock .
|
3,518
|
public function sortAsc ( ) { $ cmp = function ( TagInterface $ a , TagInterface $ b ) { if ( $ a -> getName ( ) == $ b -> getName ( ) ) { return 0 ; } return ( $ a -> getName ( ) < $ b -> getName ( ) ) ? - 1 : 1 ; } ; usort ( $ this -> elements , $ cmp ) ; }
|
Sort the list by elements .
|
3,519
|
protected function initialize ( ) { $ xmlConfig = simplexml_load_file ( $ this -> configFilePath ) ; $ this -> wurflFile = $ this -> wurflFile ( $ xmlConfig -> xpath ( '/wurfl-config/wurfl/main-file' ) ) ; $ this -> wurflPatches = $ this -> wurflPatches ( $ xmlConfig -> xpath ( '/wurfl-config/wurfl/patches/patch' ) ) ; $ this -> allowReload = $ this -> allowReload ( $ xmlConfig -> xpath ( '/wurfl-config/allow-reload' ) ) ; $ this -> capabilityFilter = $ this -> capabilityFilter ( $ xmlConfig -> xpath ( '/wurfl-config/capability-filter/capability' ) ) ; $ this -> persistence = $ this -> persistence ( $ xmlConfig -> xpath ( '/wurfl-config/persistence' ) ) ; $ this -> cache = $ this -> persistence ( $ xmlConfig -> xpath ( '/wurfl-config/cache' ) ) ; $ this -> logDir = $ this -> logDir ( $ xmlConfig -> xpath ( '/wurfl-config/logDir' ) ) ; $ this -> matchMode = $ this -> matchMode ( $ xmlConfig -> xpath ( '/wurfl-config/match-mode' ) ) ; }
|
Initialize XML Configuration
|
3,520
|
private function wurflPatches ( $ patchElements ) { $ patches = array ( ) ; if ( $ patchElements ) { foreach ( $ patchElements as $ patchElement ) { $ patches [ ] = parent :: getFullPath ( ( string ) $ patchElement ) ; } } return $ patches ; }
|
Returns an array of full path WURFL patches
|
3,521
|
private function capabilityFilter ( $ capabilityFilter ) { $ filter = array ( ) ; if ( $ capabilityFilter ) { foreach ( $ capabilityFilter as $ filterElement ) { $ filter [ ] = ( string ) $ filterElement ; } } return $ filter ; }
|
Returns an array of WURFL Capabilities
|
3,522
|
private function matchMode ( $ modeElement ) { if ( ! empty ( $ modeElement ) ) { $ mode = $ modeElement [ 0 ] ; if ( ! $ mode ) { return $ this -> matchMode ; } if ( ! self :: validMatchMode ( $ mode ) ) { throw new WURFL_WURFLException ( 'Invalid Match Mode: ' . $ mode ) ; } $ this -> matchMode = $ mode ; } return $ this -> matchMode ; }
|
Returns the mode of operation if set otherwise null
|
3,523
|
private function persistence ( $ persistenceElement ) { $ persistence = array ( ) ; if ( $ persistenceElement ) { $ persistence [ 'provider' ] = ( string ) $ persistenceElement [ 0 ] -> provider ; $ persistence [ 'params' ] = $ this -> _toArray ( ( string ) $ persistenceElement [ 0 ] -> params ) ; } return $ persistence ; }
|
Returns persistence provider info from XML config
|
3,524
|
protected function registerPlugin ( ) { if ( ! isset ( $ this -> options [ 'id' ] ) ) { $ this -> options [ 'id' ] = $ this -> hasModel ( ) ? Html :: getInputId ( $ this -> model , $ this -> attribute ) : $ this -> getId ( ) ; } else { $ this -> setId ( $ this -> options [ 'id' ] ) ; } $ clientOptions = [ ] ; $ this -> clientOptions = ArrayHelper :: merge ( $ clientOptions , $ this -> clientOptions ) ; if ( $ this -> hasModel ( ) ) { $ this -> querySelector = '#' . $ this -> options [ 'id' ] ; } elseif ( empty ( $ this -> querySelector ) ) { $ this -> querySelector = ArrayHelper :: remove ( $ this -> clientOptions , 'querySelector' , '#' . $ this -> options [ 'id' ] ) ; } }
|
Registers switchery plugin
|
3,525
|
public function getSharedTempStoreFactory ( ) { if ( empty ( $ this -> sharedTempStoreFactory ) ) { $ this -> sharedTempStoreFactory = \ Drupal :: service ( 'user.shared_tempstore' ) ; } return $ this -> sharedTempStoreFactory ; }
|
Gets shared tempstore factory .
|
3,526
|
protected function getLines ( ) { $ ret = file ( $ this -> fileName ) ; if ( $ ret === false ) { throw new Exception ( 'Unable to read file' ) ; } $ lines = array ( ) ; foreach ( $ ret as $ line ) { $ lines [ ] = rtrim ( $ line ) ; } return $ lines ; }
|
get an array of all lines in this file
|
3,527
|
public static function collection ( $ records = [ ] , Fields $ fields = null , $ flags = Resource :: PARSE_DEFAULT ) { return Resource :: parseFromRecords ( $ records , static :: class , $ fields , $ flags ) ; }
|
Prepare a collection of resources
|
3,528
|
public static function resource ( $ record , Fields $ fields = null , $ flags = Resource :: PARSE_DEFAULT ) { return Resource :: parseFromRecord ( $ record , static :: class , $ fields , $ flags ) ; }
|
Prepare an individual resource
|
3,529
|
public static function post ( $ attributes , $ return = \ Phramework \ Database \ Operations \ Create :: RETURN_ID ) { return \ Phramework \ Database \ Operations \ Create :: create ( $ attributes , static :: getTable ( ) , static :: getSchema ( ) , $ return ) ; }
|
Create a record in database
|
3,530
|
public static function patch ( $ id , $ attributes ) { static :: invalidateCache ( $ id ) ; return \ Phramework \ Database \ Operations \ Update :: update ( $ id , ( array ) $ attributes , ( static :: getSchema ( ) === null ? static :: getTable ( ) : [ 'table' => static :: getTable ( ) , 'schema' => static :: getSchema ( ) ] ) , static :: getIdAttribute ( ) ) ; }
|
Update selected attributes of a database record
|
3,531
|
public static function delete ( $ id , $ additionalAttributes = null ) { static :: invalidateCache ( $ id ) ; return \ Phramework \ Database \ Operations \ Delete :: delete ( $ id , ( $ additionalAttributes !== null ? ( array ) $ additionalAttributes : [ ] ) , ( static :: getSchema ( ) === null ? static :: getTable ( ) : [ 'table' => static :: getTable ( ) , 'schema' => static :: getSchema ( ) ] ) , static :: getIdAttribute ( ) ) ; }
|
Delete a database record
|
3,532
|
public static function convertDateRepetitionToString ( DateRepetition $ dateRepetition ) { $ dateString = '' ; if ( $ dateRepetition instanceof HourlyDateRepetition ) { $ prefix = 'hourly' ; $ timeString = ' at minute ' . $ dateRepetition -> getMinute ( ) ; } if ( $ dateRepetition instanceof DailyDateRepetition ) { $ prefix = 'daily' ; $ timeString = ' at ' . $ dateRepetition -> getHour ( ) . ':' . $ dateRepetition -> getMinute ( ) ; } if ( $ dateRepetition instanceof WeeklyDateRepetition ) { $ prefix = 'weekly' ; $ dateString = ' on ' . $ dateRepetition -> getDay ( ) ; } return $ prefix . $ dateString . $ timeString ; }
|
converts DateRepetition to a string accepted by newDateRepetitionFromString
|
3,533
|
public function toHArray ( $ delim = '' , $ limit = null ) { if ( empty ( $ this -> str ) ) { return new HArray ( ) ; } $ arr = new StringToArray ( $ this -> str , $ delim ) ; return new HArray ( $ arr -> stringToArray ( $ limit ) ) ; }
|
Alias to PHP function explode
|
3,534
|
private function getMigrationFileContents ( $ class_name ) { $ namespace = $ this -> getNamespace ( ) ; $ contents = [ '<?php' , '' , ] ; if ( $ header_comment = $ this -> getHeaderComment ( ) ) { $ contents [ ] = '/*' ; $ contents = array_merge ( $ contents , array_map ( function ( $ line ) { if ( $ line ) { return ' * ' . $ line ; } else { return ' *' ; } } , explode ( "\n" , $ header_comment ) ) ) ; $ contents [ ] = ' */' ; $ contents [ ] = '' ; } if ( $ namespace ) { $ contents [ ] = 'namespace ' . $ namespace . ';' ; $ contents [ ] = '' ; } $ contents [ ] = 'use ActiveCollab\DatabaseMigrations\Migration\Migration;' ; $ contents [ ] = '' ; if ( $ namespace ) { $ contents [ ] = '/**' ; $ contents [ ] = ' * @package ' . $ namespace ; $ contents [ ] = ' */' ; } $ contents [ ] = 'class ' . $ class_name . ' extends Migration' ; $ contents [ ] = '{' ; $ contents [ ] = ' /**' ; $ contents [ ] = ' * {@inheritdoc}' ; $ contents [ ] = ' */' ; $ contents [ ] = ' public function up()' ; $ contents [ ] = ' {' ; $ contents [ ] = ' }' ; $ contents [ ] = '}' ; $ contents [ ] = '' ; return implode ( "\n" , $ contents ) ; }
|
Generate migration class contents .
|
3,535
|
public function setSettings ( array $ settings ) { $ this -> settings = $ settings ; $ hosts = \ ECL \ Util :: get ( $ settings , 'hosts' , [ ] ) ; $ index_hosts = \ ECL \ Util :: get ( $ settings , 'index_hosts' , [ ] ) ; $ ssl_cert = \ ECL \ Util :: get ( $ settings , 'ssl_cert' , null ) ; $ ssl_client_key = \ ECL \ Util :: get ( $ settings , 'ssl_client_key' , null ) ; $ ssl_client_cert = \ ECL \ Util :: get ( $ settings , 'ssl_client_cert' , null ) ; if ( count ( $ index_hosts ) == 0 ) { $ index_hosts = $ hosts ; } $ cb = \ Elasticsearch \ ClientBuilder :: create ( ) ; if ( count ( $ hosts ) ) { $ cb -> setHosts ( $ hosts ) ; } $ icb = \ Elasticsearch \ ClientBuilder :: create ( ) ; if ( count ( $ index_hosts ) ) { $ icb -> setHosts ( $ index_hosts ) ; } if ( $ ssl_cert !== null ) { $ cb -> setSSLVerification ( $ ssl_cert ) ; $ icb -> setSSLVerification ( $ ssl_cert ) ; } if ( $ ssl_client_key !== null && $ ssl_client_cert !== null ) { $ cb -> setSSLKey ( $ ssl_client_key ) ; $ cb -> setSSLCert ( $ ssl_client_cert ) ; $ icb -> setSSLKey ( $ ssl_client_key ) ; $ icb -> setSSLCert ( $ ssl_client_cert ) ; } $ this -> client = $ cb -> build ( ) ; $ this -> index_client = $ icb -> build ( ) ; }
|
Set the current list of settings .
|
3,536
|
private function constructQueryBody ( \ ECL \ SymbolTable $ table , array $ filters , \ ECL \ Command \ Elasticsearch \ Agg $ agg = null , $ fields = null , $ sort = null , $ size = null , $ date_field = null , $ from = null , $ to = null ) { $ query_body = [ 'size' => 100 , 'query' => [ 'bool' => [ 'filter' => $ this -> constructFilter ( $ table , $ filters , $ date_field , $ from , $ to ) ] ] ] ; if ( ! is_null ( $ size ) ) { $ query_body [ 'size' ] = $ size ; } if ( ! is_null ( $ agg ) ) { $ query_body [ 'aggs' ] = $ agg -> constructQuery ( $ table ) ; $ query_body [ 'size' ] = 0 ; } if ( ! is_null ( $ fields ) ) { $ query_body [ '_source' ] = [ 'include' => $ fields ] ; } if ( ! is_null ( $ sort ) ) { $ query_body [ 'sort' ] = array_map ( function ( $ x ) { return [ $ x [ 0 ] => [ 'order' => $ x [ 1 ] ? 'asc' : 'desc' ] ] ; } , $ sort ) ; } return $ query_body ; }
|
Construct the query body .
|
3,537
|
public function matchMode ( $ mode ) { if ( ! self :: validMatchMode ( $ mode ) ) { throw new WURFL_WURFLException ( 'Invalid Match Mode: ' . $ mode ) ; } $ this -> matchMode = $ mode ; return $ this ; }
|
Sets the API match mode
|
3,538
|
protected function buildStored ( ) { return $ this -> files -> exists ( $ file_path = $ this -> config [ 'build_metadata_path' ] ) ? $ this -> files -> get ( $ file_path , $ this -> use_locking ) : null ; }
|
Get build value from metadata file .
|
3,539
|
protected function forgetFormatted ( ) { if ( $ this -> files -> exists ( $ compiled_path = $ this -> config [ 'compiled_path' ] ) ) { return $ this -> files -> delete ( $ compiled_path ) ; } return false ; }
|
Forget stored formatted value .
|
3,540
|
private function _checkPermission ( $ name , $ attribute ) { if ( $ name == 'store' ) { return $ this -> permissionStore ( $ attribute ) ; } if ( $ name == 'update' ) { return $ this -> permissionUpdate ( $ attribute ) ; } if ( $ name == 'delete' ) { return $ this -> permissionDelete ( $ attribute ) ; } if ( $ name == 'order' ) { return $ this -> permissionOrder ( $ attribute ) ; } if ( $ name == 'export' ) { return $ this -> permissionExport ( $ attribute ) ; } return $ this -> permissionView ( $ attribute ) ; }
|
Check permission by name
|
3,541
|
private function _checkOption ( $ name ) { if ( $ name == 'list' ) return true ; $ names = [ 'store' => 'add' , 'update' => 'edit' , 'delete' => 'delete' , 'order' => 'order' , 'export' => 'export' ] ; return $ this -> crudeSetup -> haveOption ( $ names [ $ name ] ) ; }
|
Check option by name
|
3,542
|
protected function validateCommon ( $ value , $ validateResult ) { if ( $ validateResult -> status === true && $ this -> enum ) { $ validateResult = $ this -> validateEnum ( $ value , $ validateResult -> value ) ; if ( $ validateResult -> status !== true ) { return $ validateResult ; } } if ( $ validateResult -> status === true && $ this -> not ) { $ validateResult = $ this -> validateNot ( $ value , $ validateResult -> value ) ; if ( $ validateResult -> status !== true ) { return $ validateResult ; } } return $ this -> runValidateCallback ( $ validateResult ) ; }
|
Common helper method to validate against all common keywords
|
3,543
|
protected function validateEnum ( $ value , $ parsedValue ) { $ return = new ValidateResult ( $ parsedValue , false ) ; if ( $ this -> enum !== null ) { if ( is_object ( $ value ) ) { throw new \ Exception ( 'Objects are not supported' ) ; } foreach ( $ this -> enum as $ v ) { if ( is_object ( $ v ) ) { throw new \ Exception ( 'Objects are not supported' ) ; } if ( $ value == $ v ) { if ( $ this -> validateType && ( $ valueType = gettype ( $ value ) ) !== ( $ vType = gettype ( $ v ) ) ) { continue ; } $ return -> value = $ v ; $ return -> status = true ; return $ return ; } elseif ( is_array ( $ value ) && is_array ( $ v ) && ArrayValidator :: equals ( $ value , $ v ) ) { $ return -> value = $ v ; $ return -> status = true ; return $ return ; } } $ return -> status = false ; $ return -> errorObject = new IncorrectParametersException ( [ [ 'type' => static :: getType ( ) , 'failure' => 'enum' ] ] ) ; } return $ return ; }
|
Common helper method to validate against enum keyword
|
3,544
|
protected function validateNot ( $ value , $ parsedValue ) { $ return = new ValidateResult ( $ parsedValue , true ) ; if ( $ this -> not && $ this -> not !== null ) { if ( ! is_subclass_of ( $ this -> not , BaseValidator :: class , true ) ) { throw new \ Exception ( sprintf ( 'Property "not" MUST extend "%s"' , BaseValidator :: class ) ) ; } $ validateNot = $ this -> not -> validate ( $ value ) ; if ( $ validateNot -> status === true ) { $ return -> status = false ; $ return -> errorObject = new IncorrectParametersException ( [ [ 'type' => static :: getType ( ) , 'failure' => 'not' ] ] ) ; return $ return ; } } return $ return ; }
|
Common helper method to validate against not keyword
|
3,545
|
public static function registerValidator ( $ type , $ className ) { if ( ! is_string ( $ type ) ) { throw new \ Exception ( '"type" MUST be string' ) ; } if ( ! is_string ( $ className ) ) { throw new \ Exception ( '"className" MUST be string' ) ; } if ( ! is_subclass_of ( $ className , BaseValidator :: class , true ) ) { throw new \ Exception ( sprintf ( '"className" MUST extend "%s"' , BaseValidator :: class ) ) ; } self :: $ validatorRegistry [ $ type ] = $ className ; }
|
Register a custom validator for a type
|
3,546
|
protected static function createFromObjectForAdditional ( $ object ) { $ indexProperty = null ; $ class = null ; if ( property_exists ( $ object , 'anyOf' ) ) { $ indexProperty = 'anyOf' ; $ class = AnyOf :: class ; } elseif ( property_exists ( $ object , 'allOf' ) ) { $ indexProperty = 'allOf' ; $ class = AllOf :: class ; } elseif ( property_exists ( $ object , 'oneOf' ) ) { $ indexProperty = 'oneOf' ; $ class = OneOf :: class ; } else { return null ; } foreach ( $ object -> { $ indexProperty } as & $ property ) { $ property = BaseValidator :: createFromObject ( $ property ) ; } $ validator = new $ class ( $ object -> { $ indexProperty } ) ; return $ validator ; }
|
Helper method . Used to create anyOf allOf and oneOf validators from objects
|
3,547
|
public static function createFromObject ( $ object ) { $ isFromBase = ( static :: class === self :: class ) ; if ( ! is_object ( $ object ) ) { throw new \ Exception ( 'Expecting an object' ) ; } if ( property_exists ( $ object , 'type' ) && ! empty ( $ object -> type ) ) { if ( array_key_exists ( $ object -> type , self :: $ validatorRegistry ) ) { if ( is_object ( $ object -> type ) || is_array ( $ object -> type ) || $ object -> type === null ) { throw new \ Exception ( 'Expecting string for type' ) ; } $ className = self :: $ validatorRegistry [ $ object -> type ] ; $ validator = new $ className ( ) ; } else { $ className = $ object -> type . 'Validator' ; try { new \ ReflectionClass ( $ className ) ; $ validator = new $ className ( ) ; } catch ( \ Exception $ e ) { throw new \ Exception ( sprintf ( 'Incorrect type "%s" from "%s"' , $ object -> type , static :: class ) ) ; } } } elseif ( ( $ validator = static :: createFromObjectForAdditional ( $ object ) ) !== null ) { return $ validator ; } elseif ( ! $ isFromBase || ( isset ( $ object -> type ) && ! empty ( $ object -> type ) && $ object -> type == static :: $ type ) ) { $ validator = new static ( ) ; } else { throw new \ Exception ( sprintf ( 'Type is required when creating from "%s"' , self :: class ) ) ; } foreach ( array_merge ( $ validator :: getTypeAttributes ( ) , $ validator :: $ commonAttributes ) as $ attribute ) { if ( property_exists ( $ object , $ attribute ) ) { if ( $ attribute == 'properties' ) { $ properties = $ object -> { $ attribute } ; $ createdProperties = new \ stdClass ( ) ; foreach ( $ properties as $ key => $ property ) { $ createdProperties -> { $ key } = BaseValidator :: createFromObject ( $ property ) ; } $ validator -> { $ attribute } = $ createdProperties ; } elseif ( $ attribute == 'items' || $ attribute == 'not' ) { $ validator -> { $ attribute } = BaseValidator :: createFromObject ( $ object -> { $ attribute } ) ; } else { $ validator -> { $ attribute } = $ object -> { $ attribute } ; } } } return $ validator ; }
|
Create validator from validation object
|
3,548
|
public static function createFromJSON ( $ json ) { $ object = json_decode ( $ json ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new \ Exception ( 'JSON parse had errors - ' . json_last_error_msg ( ) ) ; } return static :: createFromObject ( $ object ) ; }
|
Create validator from validation object encoded as json object
|
3,549
|
public function toJSON ( $ JSON_PRETTY_PRINT = false ) { $ object = $ this -> toObject ( ) ; return json_encode ( $ object , ( $ JSON_PRETTY_PRINT ? JSON_PRETTY_PRINT : 0 ) ) ; }
|
Export validator to json encoded string
|
3,550
|
public function toObject ( ) { $ object = $ this -> toArray ( ) ; if ( isset ( $ object [ 'properties' ] ) ) { $ object [ 'properties' ] = ( object ) $ object [ 'properties' ] ; } foreach ( [ 'anyOf' , 'allOf' , 'oneOf' , 'not' ] as $ property ) { if ( isset ( $ object [ $ property ] ) ) { foreach ( $ object [ $ property ] as & $ propertyItem ) { $ propertyItem = ( object ) $ propertyItem ; } } } return ( object ) $ object ; }
|
Export validator to object
|
3,551
|
public function toArray ( ) { $ object = [ ] ; if ( static :: $ type ) { $ object [ 'type' ] = static :: $ type ; } $ attributes = array_merge ( static :: getTypeAttributes ( ) , static :: $ commonAttributes ) ; foreach ( $ attributes as $ attribute ) { $ value = $ this -> { $ attribute } ; if ( $ value !== null ) { $ toCopy = $ value ; if ( is_object ( $ value ) ) { $ toCopy = clone $ value ; } $ object [ $ attribute ] = $ toCopy ; } if ( static :: $ type == 'object' && $ attribute == 'properties' ) { foreach ( $ object [ $ attribute ] as $ key => $ property ) { if ( $ property instanceof BaseValidator ) { $ object [ $ attribute ] -> { $ key } = $ property -> toArray ( ) ; } } $ object [ $ attribute ] = ( array ) $ object [ $ attribute ] ; } elseif ( in_array ( $ attribute , [ 'allOf' , 'anyOf' , 'oneOf' ] ) ) { if ( isset ( $ object [ $ attribute ] ) && $ object [ $ attribute ] !== null ) { foreach ( $ object [ $ attribute ] as $ key => $ property ) { if ( $ property instanceof BaseValidator ) { $ object [ $ attribute ] [ $ key ] = $ property -> toArray ( ) ; } } } } elseif ( in_array ( $ attribute , [ 'items' , 'not' ] ) ) { if ( isset ( $ object [ $ attribute ] ) && $ object [ $ attribute ] && $ object [ $ attribute ] instanceof BaseValidator ) { $ object [ $ attribute ] = $ object [ $ attribute ] -> toArray ( ) ; } } } return $ object ; }
|
Export validator to array
|
3,552
|
public function sendVerificationLink ( CanVerifyEmailContract $ user , Closure $ callback = null ) { $ token = $ this -> tokens -> create ( $ user ) ; $ this -> emailVerificationLink ( $ user , $ token , $ callback ) ; return VerifyEmailBrokerContract :: VERIFY_LINK_SENT ; }
|
Send an email verification link to a user .
|
3,553
|
public function verify ( CanVerifyEmailContract $ user , $ token ) { $ user = $ this -> validateVerification ( $ user , $ token ) ; if ( ! $ user instanceof CanVerifyEmailContract ) { return $ user ; } $ this -> tokens -> delete ( $ token ) ; $ user -> setVerified ( true ) ; $ user -> save ( ) ; return VerifyEmailBrokerContract :: EMAIL_VERIFIED ; }
|
Verify the email address for the given token .
|
3,554
|
protected function validateVerification ( CanVerifyEmailContract $ user , $ token ) { if ( ! $ this -> tokens -> exists ( $ user , $ token ) ) { return VerifyEmailBrokerContract :: INVALID_TOKEN ; } return $ user ; }
|
Validate a verification for the given credentials .
|
3,555
|
protected function runSeeder ( $ module = null , $ database = null ) { $ this -> call ( 'pluggables:seed' , [ 'pluggable' => $ this -> argument ( 'pluggable' ) , '--database' => $ database , ] ) ; }
|
Run the module seeder command .
|
3,556
|
public function verifyEmailAction ( ) { $ userId = $ this -> params ( ) -> fromRoute ( 'userId' , null ) ; $ token = $ this -> params ( ) -> fromRoute ( 'token' , null ) ; if ( $ userId === null || $ token === null ) { return $ this -> notFoundAction ( ) ; } $ user = $ this -> getUserMapper ( ) -> findById ( $ userId ) ; if ( ! $ user ) { return $ this -> notFoundAction ( ) ; } if ( $ this -> userRegistrationService -> verifyEmail ( $ user , $ token ) ) { return $ this -> redirectToPostVerificationRoute ( ) ; } $ vm = new ViewModel ( ) ; $ vm -> setTemplate ( 'ht-user-registration/user-registration/verify-email-error.phtml' ) ; return $ vm ; }
|
Verifies user s email address and redirects to login route
|
3,557
|
public function setPasswordAction ( ) { $ userId = $ this -> params ( ) -> fromRoute ( 'userId' , null ) ; $ token = $ this -> params ( ) -> fromRoute ( 'token' , null ) ; if ( $ userId === null || $ token === null ) { return $ this -> notFoundAction ( ) ; } $ user = $ this -> getUserMapper ( ) -> findById ( $ userId ) ; if ( ! $ user ) { return $ this -> notFoundAction ( ) ; } $ record = $ this -> getUserRegistrationMapper ( ) -> findByUser ( $ user ) ; if ( ! $ record || ! $ this -> userRegistrationService -> isTokenValid ( $ user , $ token , $ record ) ) { return $ this -> notFoundAction ( ) ; } if ( $ record -> isResponded ( ) ) { return $ this -> redirectToPostVerificationRoute ( ) ; } $ form = $ this -> getServiceLocator ( ) -> get ( 'HtUserRegistration\SetPasswordForm' ) ; if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ form -> setData ( $ this -> getRequest ( ) -> getPost ( ) ) ; if ( $ form -> isValid ( ) ) { $ this -> userRegistrationService -> setPassword ( $ form -> getData ( ) , $ record ) ; return $ this -> redirectToPostVerificationRoute ( ) ; } } return array ( 'user' => $ user , 'form' => $ form ) ; }
|
Allows users to set their account password
|
3,558
|
public function buildLoader ( ContainerBuilder $ container ) { return new YamlFileLoader ( $ container , new FileLocator ( $ this -> dir . $ this -> prefix ) ) ; }
|
the buildLoader returns the required FileLoader .
|
3,559
|
protected function writeClass ( ClassGenerator $ class , Filesystem $ filesystem , $ destinationDir ) { $ className = $ class -> getName ( ) ; $ file = new FileGenerator ( [ 'fileName' => $ className . '.php' , 'classes' => [ $ class ] , ] ) ; $ contents = $ file -> generate ( ) ; $ relativePath = $ destinationDir . DIRECTORY_SEPARATOR . $ file -> getFilename ( ) ; if ( $ filesystem -> has ( $ relativePath ) ) { throw new CliException ( sprintf ( 'Could not generate migration. File already exists: %s' , $ relativePath ) ) ; } $ result = $ filesystem -> write ( $ relativePath , $ contents ) ; return $ result ? $ relativePath : false ; }
|
Function writeClass .
|
3,560
|
protected function validateFileContents ( ) { if ( ! $ this -> fileName ) { throw new \ LogicException ( "Missing file's path. Looks like severe internal error." ) ; } $ this -> validateFilePath ( $ this -> fileName ) ; if ( ! $ this -> sha1hash ) { throw new \ LogicException ( "Missing file's SHA1 hash. Looks like severe internal error." ) ; } if ( $ this -> sha1hash !== sha1_file ( $ this -> fileName ) ) { throw new IOException ( "The file on disk has changed and this " . get_class ( $ this ) . " class instance is no longer valid for use. Please create fresh instance." ) ; } return true ; }
|
Uses SHA1 hash to determine if file contents has changed since analysis .
|
3,561
|
protected function validateFilePath ( $ fileName ) { if ( ! file_exists ( $ fileName ) ) { throw new IOException ( "File $fileName does not exists" ) ; } if ( ! is_file ( $ fileName ) ) { throw new IOException ( "$fileName must be a file" ) ; } if ( ! is_readable ( $ fileName ) ) { throw new IOException ( "File $fileName is not readable" ) ; } return true ; }
|
Checks if file exists and is readable .
|
3,562
|
private function computeNestingParentTokens ( $ debug = false ) { $ nesting = 0 ; $ parents = array ( ) ; $ lastParent = null ; foreach ( $ this -> tokens as $ key => $ token ) { if ( is_array ( $ token ) ) { $ parent = $ parents ? $ parents [ count ( $ parents ) - 1 ] : null ; $ this -> tokens [ $ key ] [ 3 ] = $ parent ; $ this -> tokens [ $ key ] [ 4 ] = $ nesting ; if ( $ this -> isEqualToAnyToken ( array ( T_CLASS , T_INTERFACE , T_FUNCTION ) , $ key ) ) { $ lastParent = $ key + 2 ; } elseif ( $ this -> isEqualToAnyToken ( array ( T_CURLY_OPEN , T_DOLLAR_OPEN_CURLY_BRACES ) , $ key ) ) { $ nesting ++ ; array_push ( $ parents , '' ) ; if ( $ debug ) { echo "$nesting\{\$\n" ; } } } else { if ( $ token == '{' ) { $ nesting ++ ; if ( $ debug ) { echo "$nesting{\n" ; } array_push ( $ parents , $ lastParent ) ; } elseif ( $ token == '}' ) { if ( $ debug ) { echo "$nesting}\n" ; } $ nesting -- ; array_pop ( $ parents ) ; } } } }
|
Compute parents of the tokens to easily determine containing methods and classes .
|
3,563
|
public function getView ( $ name , $ data = [ ] ) { $ view = 'missing-page' ; if ( view ( ) -> exists ( 'page::' . $ name ) ) { $ view = $ name ; } return view ( 'page::' . $ view , $ data ) ; }
|
Search and Load the view or fallbacks to specific view
|
3,564
|
public function validate ( $ cpf ) { $ raw_cpf = $ cpf ; $ cpf = $ this -> clean ( $ cpf ) ; $ has_mask = preg_match ( "/^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}$/" , $ raw_cpf ) ; if ( ! $ has_mask && ! is_numeric ( $ raw_cpf ) ) { return false ; } if ( ! $ this -> isLengthValid ( $ cpf ) ) { return false ; } elseif ( $ this -> isDummyValue ( $ cpf ) ) { return false ; } return $ this -> validateDigits ( $ cpf ) ; }
|
Validate a given Brazilian CPF number
|
3,565
|
public function isDummyValue ( $ cpf ) { return ( $ cpf == '00000000000' || $ cpf == '11111111111' || $ cpf == '22222222222' || $ cpf == '33333333333' || $ cpf == '44444444444' || $ cpf == '55555555555' || $ cpf == '66666666666' || $ cpf == '77777777777' || $ cpf == '88888888888' || $ cpf == '99999999999' ) ; }
|
Check if a given CPF value is a dummy sequence
|
3,566
|
public function addElement ( \ FrenchFrogs \ Form \ Element \ Element $ element , FrenchFrogs \ Renderer \ Renderer $ renderer = null ) { $ element -> setForm ( $ this ) ; $ this -> elements [ $ element -> getName ( ) ] = $ element ; return $ this ; }
|
Add a single element to the elements container
|
3,567
|
public function addDateRange ( $ name , $ label = '' , $ from = '' , $ to = '' , $ is_mandatory = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ DateRange ( $ name , $ label , $ from , $ to ) ; $ this -> addElement ( $ e ) ; if ( $ is_mandatory ) { $ e -> addRule ( 'required' ) ; } else { $ e -> addFilter ( 'nullable' ) ; } return $ e ; }
|
Add 2 input for a date range element
|
3,568
|
public function addTextarea ( $ name , $ label = '' , $ is_mandatory = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ Textarea ( $ name , $ label ) ; $ this -> addElement ( $ e ) ; if ( $ is_mandatory ) { $ e -> addRule ( 'required' ) ; } else { $ e -> addFilter ( 'nullable' ) ; } return $ e ; }
|
Add textarea element
|
3,569
|
public function addSubmit ( $ name , $ attr = [ ] ) { $ e = new \ FrenchFrogs \ Form \ Element \ Submit ( $ name , $ attr ) ; $ e -> setValue ( $ name ) ; $ e -> setOptionAsPrimary ( ) ; $ this -> addAction ( $ e ) ; return $ e ; }
|
Add action button
|
3,570
|
public function addCheckbox ( $ name , $ label = '' , $ multi = [ ] , $ attr = [ ] ) { $ e = new \ FrenchFrogs \ Form \ Element \ Checkbox ( $ name , $ label , $ multi , $ attr ) ; $ this -> addElement ( $ e ) ; return $ e ; }
|
Add input checkbox element
|
3,571
|
public function addBoolean ( $ name , $ label = '' , $ attr = [ ] ) { $ e = new \ FrenchFrogs \ Form \ Element \ Boolean ( $ name , $ label , $ attr ) ; $ this -> addElement ( $ e ) ; return $ e ; }
|
Add Boolean Element
|
3,572
|
public function addButton ( $ name , $ label , $ attr = [ ] ) { $ e = new \ FrenchFrogs \ Form \ Element \ Button ( $ name , $ label , $ attr ) ; $ this -> addElement ( $ e ) ; return $ e ; }
|
Add button element
|
3,573
|
public function addTitle ( $ name , $ attr = [ ] ) { $ e = new \ FrenchFrogs \ Form \ Element \ Title ( $ name , $ attr ) ; $ this -> addElement ( $ e ) ; return $ e ; }
|
Add a Title element
|
3,574
|
public function addContent ( $ label , $ value = '' , $ fullwidth = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ Content ( $ label , $ value , $ fullwidth ) ; $ this -> addElement ( $ e ) ; return $ e ; }
|
Add format content
|
3,575
|
public function addSelect ( $ name , $ label , $ multi = [ ] , $ is_mandatory = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ Select ( $ name , $ label , $ multi ) ; $ this -> addElement ( $ e ) ; if ( $ is_mandatory ) { $ e -> addRule ( 'required' ) ; } else { $ e -> addFilter ( 'nullable' ) ; } return $ e ; }
|
Add select element
|
3,576
|
public function addDataList ( $ name , $ label , $ options = [ ] , $ is_mandatory = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ DataList ( $ name , $ label , $ options ) ; $ this -> addElement ( $ e ) ; if ( $ is_mandatory ) { $ e -> addRule ( 'required' ) ; } else { $ e -> addFilter ( 'nullable' ) ; } return $ e ; }
|
Add list element
|
3,577
|
public function addFile ( $ name , $ label = '' , $ is_mandatory = true ) { $ e = new \ FrenchFrogs \ Form \ Element \ File ( $ name , $ label ) ; $ this -> addElement ( $ e ) ; if ( $ is_mandatory ) { $ e -> addRule ( 'required' ) ; } else { $ e -> addFilter ( 'nullable' ) ; } return $ e ; }
|
Add file element
|
3,578
|
public function getArgbHexString ( Color $ color ) { $ alpha = dechex ( 255 * $ color -> alpha ) ; return '#' . $ alpha . $ color -> hex ; }
|
Given a Color object returns a formatted argb hex string
|
3,579
|
public function getRgbaHexString ( Color $ color ) { $ alpha = dechex ( 255 * $ color -> alpha ) ; return '#' . $ color -> hex . $ alpha ; }
|
Given a Color object returns a formatted rgba hex string
|
3,580
|
public function getRgbaString ( Color $ color ) { return 'rgba(' . $ color -> red . ', ' . $ color -> green . ', ' . $ color -> blue . ', ' . $ color -> alpha . ')' ; }
|
Given a Color object returns a formatted rgba string
|
3,581
|
public function getHslString ( Color $ color ) { return 'hsl(' . round ( $ color -> hue ) . ', ' . round ( $ color -> saturation * 100 ) . '%, ' . round ( $ color -> lightness * 100 ) . '%)' ; }
|
Given a Color object returns a formatted hsl string
|
3,582
|
public function getHslaString ( Color $ color ) { return 'hsla(' . round ( $ color -> hue ) . ', ' . round ( $ color -> saturation * 100 ) . '%, ' . round ( $ color -> lightness * 100 ) . '%, ' . $ color -> alpha . ')' ; }
|
Given a Color object returns a formatted hsla string
|
3,583
|
public function load ( Color $ color , $ value ) { $ value = strtolower ( trim ( $ value ) ) ; $ format = $ this -> guess ( $ value ) ; if ( is_callable ( __CLASS__ . '::' . $ format ) ) { $ this -> $ format ( $ color , $ value ) ; } return $ color ; }
|
Pass a var in subject param and this method will attempt to parse it into a color object and return it
|
3,584
|
private function guess ( $ value ) { if ( is_string ( $ value ) ) { $ len = strlen ( $ value ) ; if ( strpos ( $ value , ' ' ) === false && strpos ( $ value , ',' ) === false ) { if ( substr ( $ value , 0 , 1 ) === '#' && ( $ len === 7 || $ len === 4 ) ) { return 'loadHexString' ; } elseif ( $ len === 6 || $ len === 3 ) { return 'loadHexString' ; } } elseif ( substr ( $ value , 0 , 3 ) === 'rgb' ) { return 'loadRgbString' ; } elseif ( substr ( $ value , 0 , 4 ) === 'rgba' ) { return 'loadRgbString' ; } elseif ( substr ( $ value , 0 , 3 ) === 'hsl' ) { return 'loadHslString' ; } elseif ( substr ( $ value , 0 , 4 ) === 'hsla' ) { return 'loadHslString' ; } } return false ; }
|
Given a subject tries to discover the format then return the appropriate method name
|
3,585
|
public function loadHexString ( Color $ color , $ subject ) { $ subject = trim ( $ subject ) ; $ subject = str_replace ( array ( '#' , ';' , ' ' ) , '' , $ subject ) ; if ( strlen ( $ subject ) !== 3 && strlen ( $ subject ) !== 6 ) { return false ; } elseif ( strlen ( $ subject ) === 3 ) { $ subject = $ subject [ 0 ] . $ subject [ 0 ] . $ subject [ 1 ] . $ subject [ 1 ] . $ subject [ 2 ] . $ subject [ 2 ] ; } $ color -> hex = $ subject ; return $ color ; }
|
Loads a color object from a hex string
|
3,586
|
public function loadRgbString ( Color $ color , $ subject ) { $ subject = trim ( $ subject ) ; $ subject = str_replace ( array ( 'rgba' , 'rgb' , '(' , ')' , ';' , ' ' ) , '' , $ subject ) ; $ rgbnum = explode ( ',' , $ subject ) ; if ( count ( $ rgbnum ) !== 3 && count ( $ rgbnum ) !== 4 ) { return false ; } foreach ( $ rgbnum as & $ val ) { $ val = floatval ( trim ( $ val ) ) ; } $ rgb = array ( 'red' => $ rgbnum [ 0 ] , 'green' => $ rgbnum [ 1 ] , 'blue' => $ rgbnum [ 2 ] ) ; if ( isset ( $ rgbnum [ 3 ] ) ) { $ rgb [ 'alpha' ] = $ rgbnum [ 3 ] ; } $ color -> bulkUpdate ( $ rgb ) ; return $ color ; }
|
Loads a color object from an rgb or rgba string
|
3,587
|
public function loadHslString ( Color $ color , $ subject ) { $ subject = trim ( $ subject ) ; $ subject = str_replace ( array ( 'hsla' , 'hsl' , '(' , ')' , ';' , ' ' ) , '' , $ subject ) ; $ hslnum = explode ( ',' , $ subject ) ; if ( count ( $ hslnum ) !== 3 && count ( $ hslnum ) !== 4 ) { return false ; } foreach ( $ hslnum as & $ val ) { $ val = floatval ( trim ( $ val ) ) ; } $ hsl = array ( 'hue' => $ hslnum [ 0 ] , 'saturation' => $ hslnum [ 1 ] , 'lightness' => $ hslnum [ 2 ] ) ; if ( isset ( $ hslnum [ 3 ] ) ) { $ hsl [ 'alpha' ] = $ hslnum [ 3 ] ; } $ color -> bulkUpdate ( $ hsl ) ; return $ color ; }
|
Loads a color object from a hsl or hsla string
|
3,588
|
public function has ( $ key ) { try { $ ttlColumn = $ this -> columns [ 'ttl' ] ; return ( bool ) $ this -> db -> from ( $ this -> table ) -> where ( $ this -> columns [ 'key' ] ) -> eq ( $ this -> prefix . $ key ) -> andWhere ( function ( $ group ) use ( $ ttlColumn ) { $ group -> where ( $ ttlColumn ) -> eq ( 0 ) -> orWhere ( $ ttlColumn ) -> gt ( time ( ) ) ; } ) -> count ( ) ; } catch ( PDOException $ e ) { return false ; } }
|
Returns TRUE if the cache key exists and FALSE if not .
|
3,589
|
public function delete ( $ key ) { try { return ( bool ) $ this -> db -> from ( $ this -> table ) -> where ( $ this -> columns [ 'key' ] ) -> eq ( $ this -> prefix . $ key ) -> delete ( ) ; } catch ( PDOException $ e ) { return false ; } }
|
Delete a variable from the cache .
|
3,590
|
public function clear ( ) { try { $ this -> db -> from ( $ this -> table ) -> delete ( ) ; } catch ( PDOException $ e ) { return false ; } return true ; }
|
Clears the user cache .
|
3,591
|
public function children ( ) { if ( $ this -> collection === null ) { $ this -> initializeCollection ( $ this -> defaultChildren ( ) ) ; } return $ this -> collection ; }
|
Returns collection of child nodes .
|
3,592
|
public function getChildrenRecursive ( ) { $ res = new ObjectCollection ( ) ; foreach ( $ this -> children ( ) as $ child ) { $ res -> add ( $ child ) ; if ( $ child instanceof ParentNodeInterface ) { $ res -> addMany ( $ child -> getChildrenRecursive ( ) ) ; } } return $ res ; }
|
Returns collection containing all descendant nodes .
|
3,593
|
public static function isXhtmlRequester ( $ request ) { if ( ! isset ( $ request [ "accept" ] ) ) { return false ; } $ accept = $ request [ "accept" ] ; if ( isset ( $ accept ) ) { if ( ( strpos ( $ accept , WURFL_Constants :: ACCEPT_HEADER_VND_WAP_XHTML_XML ) !== 0 ) || ( strpos ( $ accept , WURFL_Constants :: ACCEPT_HEADER_XHTML_XML ) !== 0 ) || ( strpos ( $ accept , WURFL_Constants :: ACCEPT_HEADER_TEXT_HTML ) !== 0 ) ) { return true ; } } return false ; }
|
Checks if the requester device is xhtml enabled
|
3,594
|
public function prepareHasOneConstraintStatement ( TypeInterface $ type , HasOneAssociation $ association ) { $ result = [ ] ; $ result [ ] = 'ALTER TABLE ' . $ this -> getConnection ( ) -> escapeTableName ( $ type -> getName ( ) ) ; $ result [ ] = ' ADD CONSTRAINT ' . $ this -> getConnection ( ) -> escapeFieldName ( $ association -> getConstraintName ( ) ) ; $ result [ ] = ' FOREIGN KEY (' . $ this -> getConnection ( ) -> escapeFieldName ( $ association -> getFieldName ( ) ) . ') REFERENCES ' . $ this -> getConnection ( ) -> escapeTableName ( $ association -> getTargetTypeName ( ) ) . '(`id`)' ; if ( $ association -> isRequired ( ) ) { $ result [ ] = ' ON UPDATE CASCADE ON DELETE CASCADE;' ; } else { $ result [ ] = ' ON UPDATE SET NULL ON DELETE SET NULL;' ; } return implode ( "\n" , $ result ) ; }
|
Prepare has one constraint statement .
|
3,595
|
public function prepareHasAndBelongsToManyConstraintStatement ( $ type_name , $ connection_table , $ constraint_name , $ field_name ) { $ result = [ ] ; $ result [ ] = 'ALTER TABLE ' . $ this -> getConnection ( ) -> escapeTableName ( $ connection_table ) ; $ result [ ] = ' ADD CONSTRAINT ' . $ this -> getConnection ( ) -> escapeFieldName ( $ constraint_name ) ; $ result [ ] = ' FOREIGN KEY (' . $ field_name . ') REFERENCES ' . $ this -> getConnection ( ) -> escapeTableName ( $ type_name ) . '(`id`)' ; $ result [ ] = ' ON UPDATE CASCADE ON DELETE CASCADE;' ; return implode ( "\n" , $ result ) ; }
|
Prepare has and belongs to many constraint statement .
|
3,596
|
private final function setReadableWritable ( string $ mode ) { if ( self :: MODE_R === $ mode ) { $ this -> meta [ "readable" ] = true ; $ this -> meta [ "writable" ] = false ; } else if ( self :: MODE_W === $ mode || self :: MODE_A === $ mode || self :: MODE_C === $ mode || self :: MODE_X === $ mode ) { $ this -> meta [ "readable" ] = false ; $ this -> meta [ "writable" ] = true ; } else if ( self :: MODE_R_MORE === $ mode || self :: MODE_W_MORE === $ mode || self :: MODE_A_MORE === $ mode || self :: MODE_C_MORE === $ mode || self :: MODE_X_MORE === $ mode ) { $ this -> meta [ "readable" ] = true ; $ this -> meta [ "writable" ] = true ; } }
|
Set stream readable and writable status
|
3,597
|
public final function getMetadata ( $ key = null ) { return isset ( $ key ) ? ( array_key_exists ( $ key , $ this -> meta ) ? $ this -> meta [ $ key ] : null ) : $ this -> meta ; }
|
Get stream metadata
|
3,598
|
public function sync ( Color $ firstcolor , Color $ secondcolor ) { foreach ( $ this -> colorprops as $ name ) { $ firstcolor -> $ name = $ secondcolor -> $ name ; } return $ firstcolor ; }
|
Sync first color with second color
|
3,599
|
public function getCssGradient ( Color $ color , $ amount = null ) { if ( self :: isLight ( $ color ) ) { $ lightColor = $ color -> hex ; $ darkColor = self :: darken ( $ color -> copy ( ) , $ amount ) -> hex ; } else { $ lightColor = self :: lighten ( $ color -> copy ( ) , $ amount ) -> hex ; $ darkColor = $ color -> hex ; } $ css = "background-color: #" . $ color -> hex . ";" ; $ css .= "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . $ lightColor . "', endColorstr='#" . $ darkColor . "');" ; $ css .= "background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#" . $ lightColor . "), to(#" . $ darkColor . "));" ; $ css .= "background-image: -webkit-linear-gradient(top, #" . $ lightColor . ", #" . $ darkColor . ");" ; $ css .= "background-image: -moz-linear-gradient(top, #" . $ lightColor . ", #" . $ darkColor . ");" ; $ css .= "background-image: -ms-linear-gradient(top, #" . $ lightColor . ", #" . $ darkColor . ");" ; $ css .= "background-image: -o-linear-gradient(top, #" . $ lightColor . ", #" . $ darkColor . ");" ; return $ css ; }
|
Returns the cross browser CSS3 gradient
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.