idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
1,700
|
protected function createPaginatedQueryBuilder ( array $ criteria = [ ] , $ indexBy = null , array $ orderBy = null ) { $ qb = new PaginatedQueryBuilder ( $ this -> _em ) ; $ qb -> from ( $ this -> _entityName , $ this -> getEntityAlias ( ) , $ indexBy ) ; $ this -> processCriteria ( $ qb , $ criteria ) ; return $ qb ; }
|
Creates a query builder for pagination
|
1,701
|
protected function reduce ( ) { $ gcd = $ this -> gcd ( $ this -> value [ 'num' ] -> get ( ) , $ this -> value [ 'den' ] -> get ( ) ) ; if ( $ gcd > 1 ) { $ this -> value [ 'num' ] -> set ( $ this -> value [ 'num' ] -> get ( ) / $ gcd ) ; $ this -> value [ 'den' ] -> set ( $ this -> value [ 'den' ] -> get ( ) / $ gcd ) ; } }
|
Reduce this number to it s lowest form
|
1,702
|
public function get ( $ key , $ default = null , $ save = false ) { $ this -> load ( ) ; if ( $ this -> has ( $ key ) ) { return Arr :: get ( $ this -> settings , $ key , $ default ) ; } if ( $ save ) { $ this -> set ( $ key , $ default ) ; } if ( $ this -> config -> has ( $ key ) ) { return $ this -> config -> get ( $ key ) ; } return $ default ; }
|
Get setting by key
|
1,703
|
public function connect ( ) { if ( ! $ this -> connection ) { $ errNum = $ errStr = null ; $ this -> connection = @ fsockopen ( $ this -> host , $ this -> port , $ errNum , $ errStr , $ this -> options [ 'timeout' ] ) ; if ( ! $ this -> connection or $ errNum > 0 ) { $ message = sprintf ( 'Could not connect to beanstalkd "%s:%d": %s (%d)' , $ this -> host , $ this -> port , $ errStr , $ errNum ) ; throw new Exception \ SocketException ( $ message ) ; } stream_set_timeout ( $ this -> connection , - 1 , 0 ) ; } return $ this ; }
|
Connect the socket to the beanstalk server .
|
1,704
|
public function isAllowed ( $ spec , $ pattern ) { if ( ! array_key_exists ( $ spec , $ this -> catalogue ) ) { return false ; } $ features = $ this -> catalogue [ $ spec ] ; if ( ! is_array ( $ pattern ) ) { $ pattern = [ $ pattern ] ; } $ needle = 0 ; foreach ( $ pattern as $ term ) { $ needle |= $ term ; } return $ needle === ( $ features & $ needle ) ; }
|
Returns true if and only if the file specification is allowed for a given pattern .
|
1,705
|
protected function findByType ( $ pattern , $ part ) { if ( ! is_array ( $ pattern ) ) { $ pattern = [ $ pattern ] ; } $ needle = 0 ; foreach ( $ pattern as $ term ) { $ needle |= $ term ; } $ matches = [ ] ; foreach ( $ this -> catalogue as $ spec => $ features ) { if ( $ needle === ( $ features & $ needle ) ) { $ props = explode ( ':' , $ spec ) ; $ matches [ ] = $ props [ $ part ] ; } } return array_unique ( $ matches ) ; }
|
Each new term does not extend the search results but makes them more specific .
|
1,706
|
public function createNullDriver ( array $ config ) { return $ this -> adapt ( $ this -> createFlysystem ( new \ League \ Flysystem \ Adapter \ NullAdapter , $ config ) ) ; }
|
Create an instance of the null driver .
|
1,707
|
public function defineStyleCommands ( ) { if ( $ this -> css === null ) { throw new Exception ( 'LaTeX formatter has not been set a theme' ) ; } $ cmds = array ( ) ; $ round = function ( $ n ) { return round ( $ n , 2 ) ; } ; foreach ( $ this -> css -> rules ( ) as $ name => $ properties ) { if ( ! preg_match ( '/^\w+$/' , $ name ) ) { continue ; } $ cmd = "{#1}" ; if ( $ this -> css -> value ( $ name , 'bold' , false ) === true ) { $ cmd = "{\\textbf$cmd}" ; } if ( $ this -> css -> value ( $ name , 'italic' , false ) === true ) { $ cmd = "{\\emph$cmd}" ; } if ( ( $ col = $ this -> css -> value ( $ name , 'color' , null ) ) !== null ) { if ( preg_match ( '/^#[a-f0-9]{6}$/i' , $ col ) ) { $ rgb = ColorUtils :: normalizeRgb ( ColorUtils :: hex2rgb ( $ col ) , true ) ; $ rgb = array_map ( $ round , $ rgb ) ; $ colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]" ; $ cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}" ; } } $ name = str_replace ( '_' , '' , $ name ) ; $ name = strtoupper ( $ name ) ; $ cmds [ ] = "\\newcommand{\\lms{$name}}[1]$cmd" ; } if ( $ this -> lineNumbers && ( $ col = $ this -> css -> value ( 'code' , 'color' , null ) ) !== null ) { if ( preg_match ( '/^#[a-f0-9]{6}$/i' , $ col ) ) { $ rgb = ColorUtils :: normalizeRgb ( ColorUtils :: hex2rgb ( $ col ) , true ) ; $ rgb = array_map ( $ round , $ rgb ) ; $ colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]" ; $ cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}" ; $ cmds [ ] = $ cmd ; } } return implode ( "\n" , $ cmds ) ; }
|
Defines all the styling commands these are obtained from the css parser
|
1,708
|
private function getFullNameBit ( $ bit ) { if ( empty ( $ this -> full_name_bits ) ) { $ full_name = $ this -> getFullName ( ) ; if ( empty ( $ full_name ) ) { list ( $ first_name , $ last_name ) = $ this -> getFirstAndLastNameFromEmail ( ) ; if ( $ first_name && $ last_name ) { $ this -> full_name_bits = ( new HumanNameParser ( "$first_name $last_name" ) ) -> getArray ( ) ; } else { $ this -> full_name_bits = [ 'first' => $ first_name ] ; } } else { $ this -> full_name_bits = ( new HumanNameParser ( $ full_name ) ) -> getArray ( ) ; } } return empty ( $ this -> full_name_bits [ $ bit ] ) ? '' : $ this -> full_name_bits [ $ bit ] ; }
|
Return first name bit .
|
1,709
|
public function onMoveContent ( EventInterface $ event ) { $ translator = $ this -> getTranslator ( ) ; $ mapper = $ this -> getLayoutMapper ( ) ; if ( is_null ( $ event -> getParam ( 'tid' ) ) ) { throw new InvalidArgumentException ( $ translator -> translate ( "Unknown transaction identifier. Missing event param 'tid'." ) ) ; } if ( is_null ( $ event -> getParam ( 'content' ) ) ) { throw new InvalidArgumentException ( sprintf ( $ translator -> translate ( "Missing event param '%s'." ) , 'content' ) ) ; } $ mapper -> unregisterContent ( $ event -> getParam ( 'content' ) , false , $ event -> getParam ( 'tid' ) ) ; }
|
If the content has been moved all the rules of widget visibility are cleared .
|
1,710
|
protected function replaceInText ( $ text ) { $ text = str_replace ( "##YEAR##" , date ( 'Y' ) , $ text ) ; $ text = str_replace ( "##DATE##" , date ( 'Y-m-d' ) , $ text ) ; return $ text ; }
|
Replaces placeholders in the copyright header Todo separate and make configurable and extensible
|
1,711
|
protected function addHeader ( \ SplFileInfo $ file , $ text ) { $ content = file_get_contents ( $ file -> getRealPath ( ) ) ; $ lines = explode ( PHP_EOL , $ content ) ; $ text = explode ( "\n" , $ text ) ; foreach ( $ lines as $ i => $ l ) { $ l = trim ( $ l ) ; if ( strpos ( $ l , "<?php" ) === 0 ) { continue ; } array_splice ( $ lines , $ i , 0 , $ text ) ; break ; } file_put_contents ( $ file -> getRealPath ( ) , implode ( PHP_EOL , $ lines ) ) ; }
|
Adds copyright headers in file
|
1,712
|
public function whenStarted ( ) { $ milliseconds = $ this -> event -> getOrigin ( ) ; $ seconds = $ milliseconds / 1000 ; return is_float ( $ seconds ) ? date ( 'Y-m-d H:i:s' , $ seconds ) : null ; }
|
Convert start time to datetime from milliseconds .
|
1,713
|
private function parseData ( array $ data ) { $ field = $ data [ 'field' ] ; foreach ( $ data [ 'policies' ] as $ rule => $ policy ) { $ passes = call_user_func_array ( [ new Rule ( ) , $ rule ] , [ $ field , $ data [ 'value' ] , $ policy ] ) ; if ( ! $ passes ) { ErrorHandler :: set ( str_replace ( [ ':attribute' , ':policy' , '_' ] , [ $ field , $ policy , ' ' ] , $ this -> messages [ $ rule ] ) , $ field ) ; } } }
|
Perform validation for the data provider and set error messages .
|
1,714
|
protected function parseContent ( $ content , TokenList $ tokenList = null , $ independent = false ) { $ parser = new Parser ( ) ; $ lexer = new Lexer ( ) ; $ this -> set -> init ( $ parser , $ lexer ) ; $ parser -> setStartRule ( $ this ) ; $ tokenList = $ parser -> parse ( $ content , $ tokenList , ! $ independent ) ; return $ tokenList ; }
|
Parse token match content
|
1,715
|
static public function display ( ) { Sorter :: sort ( Listing :: $ files ) ; $ content = '<!DOCTYPE html>' ; $ content .= sprintf ( '<html xmlns="http://www.w3.org/1999/xhtml" lang="%s">' , Translation :: getCanonicalLocale ( ) ) ; $ content .= ' <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>' . sprintf ( Translation :: trans ( 'index_of' ) , Main :: getDir ( ) ) . '</title>' ; $ content .= static :: getStyle ( ) ; $ content .= ' </head> <body>' ; $ content .= static :: getTitle ( ) ; $ content .= ' <table align="center">' ; $ content .= static :: getHeader ( ) ; foreach ( Listing :: $ files as $ file ) { $ content .= static :: getRow ( $ file ) ; } $ content .= static :: getFooter ( ) ; $ content .= ' </table>' ; $ content .= ' </body></html>' ; die ( $ content ) ; }
|
Display directory listing
|
1,716
|
public static function dataTypeSelectOptions ( ) { return [ Property :: DATA_TYPE_STRING => Module :: t ( 'app' , 'String' ) , Property :: DATA_TYPE_TEXT => Module :: t ( 'app' , 'Text' ) , Property :: DATA_TYPE_INTEGER => Module :: t ( 'app' , 'Integer' ) , Property :: DATA_TYPE_FLOAT => Module :: t ( 'app' , 'Float' ) , Property :: DATA_TYPE_BOOLEAN => Module :: t ( 'app' , 'Boolean' ) , Property :: DATA_TYPE_PACKED_JSON => Module :: t ( 'app' , 'Packed JSON' ) , Property :: DATA_TYPE_INVARIANT_STRING => Module :: t ( 'app' , 'Untranslatable String' ) , ] ; }
|
Returns array of data types for select inputs
|
1,717
|
public function setMagicFile ( $ file ) { if ( $ file === false ) { $ this -> options [ 'magicFile' ] = false ; } elseif ( empty ( $ file ) ) { $ this -> options [ 'magicFile' ] = null ; } elseif ( ! ( class_exists ( 'finfo' , false ) ) ) { $ this -> options [ 'magicFile' ] = null ; throw new Exception \ RuntimeException ( 'Magicfile can not be set; there is no finfo extension installed' ) ; } elseif ( ! is_file ( $ file ) || ! is_readable ( $ file ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'The given magicfile ("%s") could not be read' , $ file ) ) ; } else { ErrorHandler :: start ( E_NOTICE | E_WARNING ) ; $ this -> finfo = finfo_open ( FILEINFO_MIME_TYPE , $ file ) ; $ error = ErrorHandler :: stop ( ) ; if ( empty ( $ this -> finfo ) ) { $ this -> finfo = null ; throw new Exception \ InvalidArgumentException ( sprintf ( 'The given magicfile ("%s") could not be used by ext/finfo' , $ file ) , 0 , $ error ) ; } $ this -> options [ 'magicFile' ] = $ file ; } return $ this ; }
|
Sets the magicfile to use if null the MAGIC constant from php is used if the MAGIC file is erroneous no file will be set if false the default MAGIC file from PHP will be used
|
1,718
|
public function retrieveByCredentials ( array $ credentials ) { $ u = $ credentials [ 'username' ] ; $ p = $ credentials [ 'password' ] ; $ m = $ this -> modelName ; try { $ user = $ m :: where ( $ this -> username , $ u ) -> first ( ) ; if ( empty ( $ user ) ) { return null ; } if ( ! $ this -> allow_no_pass ) { $ pw_attr = $ this -> password ; if ( ! Hash :: check ( $ p , $ user -> $ pw_attr ) ) { return null ; } } return $ user ; } catch ( Exception $ e ) { throw $ e ; } }
|
Retrieves the user with the specified credentials from the database . Returns null if the model instance could not be found .
|
1,719
|
public function retrieveByToken ( $ identifier , $ token ) { $ m = $ this -> modelName ; return $ m :: findForAuthToken ( $ identifier , $ token ) ; }
|
Returns the user with the specified identifier and Remember Me token .
|
1,720
|
public function updateRememberToken ( AuthenticatableContract $ user , $ token ) { if ( ! empty ( $ user ) ) { if ( $ user -> canHaveRememberToken ( ) ) { $ user -> remember_token = $ token ; $ user -> save ( ) ; } } }
|
Updates the Remember Me token for the specified identifier .
|
1,721
|
public static function load ( $ arg ) { if ( is_object ( $ arg ) && $ arg instanceof Entity ) { $ class = get_class ( $ arg ) ; } elseif ( is_object ( $ arg ) && $ arg instanceof Collection ) { $ class = $ arg -> getEntityClass ( ) ; } elseif ( is_object ( $ arg ) && $ arg instanceof Reflection ) { $ class = $ arg -> getClassName ( ) ; if ( ! isset ( self :: $ registered [ $ class ] ) ) { return self :: $ registered [ $ class ] = $ arg ; } return $ arg ; } elseif ( is_string ( $ arg ) ) { $ class = $ arg ; } else { throw new Exception \ InvalidArgumentException ( "Entity identifier must be object, collection, class or name!" , $ arg ) ; } if ( ! is_subclass_of ( $ class , "UniMapper\Entity" ) ) { $ class = Convention :: nameToClass ( $ arg , Convention :: ENTITY_MASK ) ; } if ( ! class_exists ( $ class ) ) { throw new Exception \ InvalidArgumentException ( "Entity class " . $ class . " not found!" ) ; } if ( isset ( self :: $ registered [ $ class ] ) ) { return self :: $ registered [ $ class ] ; } return self :: $ registered [ $ class ] = new Reflection ( $ class ) ; }
|
Load and register reflection
|
1,722
|
private function _parseProperties ( $ docComment , \ ReflectionClass $ reflectionClass ) { $ properties = [ ] ; foreach ( Reflection \ Annotation :: parseProperties ( $ docComment ) as $ definition ) { try { $ property = new Reflection \ Property ( $ definition [ 2 ] , $ definition [ 3 ] , $ this , ! $ definition [ 1 ] , $ definition [ 4 ] ) ; } catch ( Exception \ PropertyException $ e ) { throw new Exception \ ReflectionException ( $ e -> getMessage ( ) , $ this -> className , $ definition [ 0 ] ) ; } if ( isset ( $ properties [ $ property -> getName ( ) ] ) ) { throw new Exception \ ReflectionException ( "Duplicate property with name '" . $ property -> getName ( ) . "'!" , $ this -> className , $ definition [ 0 ] ) ; } if ( $ reflectionClass -> hasProperty ( $ property -> getName ( ) ) ) { throw new Exception \ ReflectionException ( "Property '" . $ property -> getName ( ) . "' already defined as" . " public property!" , $ this -> className , $ definition [ 0 ] ) ; } $ this -> properties [ $ property -> getName ( ) ] = $ property ; } }
|
Parse properties from annotations
|
1,723
|
public function getProperty ( $ name ) { if ( ! $ this -> hasProperty ( $ name ) ) { throw new Exception \ InvalidArgumentException ( "Unknown property " . $ name . "!" ) ; } return $ this -> properties [ $ name ] ; }
|
Get property reflection object
|
1,724
|
public function getRelatedFiles ( array $ files = [ ] ) { if ( in_array ( $ this -> fileName , $ files ) ) { return $ files ; } $ files [ ] = $ this -> fileName ; foreach ( $ this -> properties as $ property ) { if ( in_array ( $ property -> getType ( ) , [ Reflection \ Property :: TYPE_COLLECTION , Reflection \ Property :: TYPE_ENTITY ] ) ) { $ files += self :: load ( $ property -> getTypeOption ( ) ) -> getRelatedFiles ( $ files ) ; } } return $ files ; }
|
Get arg s related files
|
1,725
|
public function getPrimaryProperty ( ) { foreach ( $ this -> properties as $ property ) { if ( $ property -> hasOption ( Entity \ Reflection \ Property \ Option \ Primary :: KEY ) ) { return $ property ; } } throw new \ Exception ( "Primary property not defined in " . $ this -> className . "!" ) ; }
|
Get primary property reflection
|
1,726
|
public function saveImage ( \ Illuminate \ Http \ UploadedFile $ imageFile , $ path , $ name = null , Array $ sizes = [ ] , $ callback = null ) { $ extension = $ imageFile -> extension ( ) ; if ( ! in_array ( $ extension , [ 'png' , 'jpeg' , 'jpg' , 'gif' ] ) ) throw new NotSupportedImageFormatException ( $ extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' ) ; $ image = ( new Image ( $ imageFile -> getPathname ( ) , $ extension ) ) -> setOutputFormat ( $ extension , 100 , PNG_NO_FILTER ) ; $ name = $ name ? : str_random ( 10 ) . time ( ) ; if ( empty ( $ sizes ) ) { $ save_name = $ image -> setSaveOptions ( $ name , $ path ) -> export ( ) ; } else { $ main_size = array_shift ( $ sizes ) ; $ main = self :: getSize ( $ main_size ) ; $ save_name = $ image -> createThumbnail ( $ main [ 'w' ] , $ main [ 'h' ] , true ) -> setSaveOptions ( $ name , $ path ) -> export ( true ) ; foreach ( $ sizes as $ size ) { $ size = self :: getSize ( $ size ) ; $ image -> createThumbnail ( $ size [ 'w' ] , $ size [ 'h' ] , true ) -> setSaveOptions ( join ( 'x' , $ size ) . '_' . $ save_name , $ path . 'thumb' ) -> export ( true ) ; } $ image -> destroy ( ) ; } if ( is_callable ( $ callback ) ) call_user_func ( $ callback , $ this , $ save_name , $ extension ) ; return $ save_name ; }
|
Save Uploaded File Image
|
1,727
|
public function saveImages ( Array $ images , $ path , $ name = null , Array $ sizes = [ ] , $ callback = null ) { $ array = [ ] ; foreach ( $ images as $ file ) { $ array [ ] = $ this -> saveImage ( $ file , $ path ) ; } if ( is_callable ( $ callback ) ) call_user_func ( $ callback , $ this , $ array ) ; return $ array ; }
|
Save Array Of Uploaded Files Image
|
1,728
|
public static function getSize ( $ size ) { $ dim = [ ] ; if ( is_array ( $ size ) ) { $ dim [ 'w' ] = $ size [ 0 ] ; $ dim [ 'h' ] = isset ( $ size [ 1 ] ) ? $ size [ 1 ] : $ size [ 0 ] ; } else { $ dim [ 'w' ] = $ size ; $ dim [ 'h' ] = null ; } return $ dim ; }
|
Get Width Height values
|
1,729
|
public function saveLocalImage ( $ imageFile , $ path , $ name = null , Array $ sizes = [ ] , $ callback = null ) { $ arr = explode ( '.' , $ imageFile ) ; $ extension = end ( $ arr ) ; if ( ! in_array ( $ extension , [ 'png' , 'jpeg' , 'jpg' , 'gif' ] ) ) throw new NotSupportedImageFormatException ( $ extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' ) ; $ image = ( new Image ( $ imageFile , $ extension ) ) -> setOutputFormat ( $ extension , 100 , PNG_NO_FILTER ) ; $ name = $ name ? : str_random ( 10 ) . time ( ) ; if ( empty ( $ sizes ) ) { $ save_name = $ image -> setSaveOptions ( $ name , $ path ) -> export ( ) ; } else { $ main_size = array_shift ( $ sizes ) ; $ main = self :: getSize ( $ main_size ) ; $ save_name = $ image -> createThumbnail ( $ main [ 'w' ] , $ main [ 'h' ] , true ) -> setSaveOptions ( $ name , $ path ) -> export ( true ) ; foreach ( $ sizes as $ size ) { $ size = self :: getSize ( $ size ) ; $ image -> createThumbnail ( $ size [ 'w' ] , $ size [ 'h' ] , true ) -> setSaveOptions ( join ( 'x' , $ size ) . '_' . $ save_name , $ path . 'thumb' ) -> export ( true ) ; } $ image -> destroy ( ) ; } if ( is_callable ( $ callback ) ) call_user_func ( $ callback , $ this , $ save_name , $ extension ) ; return $ save_name ; }
|
Save Locale Images
|
1,730
|
public function to_avro ( ) { $ avro = array ( "protocol" => $ this -> name , "namespace" => $ this -> namespace ) ; if ( ! is_null ( $ this -> doc ) ) $ avro [ "doc" ] = $ this -> doc ; $ types = array ( ) ; $ avro [ "types" ] = $ this -> schemata -> to_avro ( ) ; $ messages = array ( ) ; foreach ( $ this -> messages as $ name => $ msg ) $ messages [ $ name ] = $ msg -> to_avro ( ) ; $ avro [ "messages" ] = $ messages ; return $ avro ; }
|
Internal represention of this Avro Protocol .
|
1,731
|
protected function flushForModel ( $ index , $ modelId ) { $ query = [ 'index' => $ index , 'body' => [ 'query' => [ 'bool' => [ 'filter' => [ 'bool' => [ 'must' => [ 'term' => [ 'model_id' => $ modelId ] ] ] ] , ] ] ] ] ; $ pks = IndexHelper :: primaryKeysByCondition ( $ this -> client , $ query ) ; if ( count ( $ pks ) > 0 ) { $ params = [ 'body' => [ ] ] ; foreach ( $ pks as $ id => $ types ) { foreach ( $ types as $ type ) { $ params [ 'body' ] [ ] = [ 'delete' => [ '_index' => $ index , '_type' => $ type , '_id' => $ id ] ] ; } } $ this -> client -> bulk ( $ params ) ; } }
|
Flushes all elasticsearch indices for given model id
|
1,732
|
protected function fillForModel ( $ index , $ model ) { if ( false === empty ( $ model -> propertiesIds ) && false === empty ( $ model -> propertiesValues ) ) { $ workingProps = array_filter ( $ model -> propertiesValues , function ( $ e ) { if ( true === is_array ( $ e ) ) { foreach ( $ e as $ val ) { return ( count ( $ val ) > 0 && false === empty ( $ val [ 0 ] ) ) ; } } else { return false === empty ( $ e ) ; } } ) ; $ storage = ( new Query ( ) ) -> from ( PropertyStorage :: tableName ( ) ) -> select ( 'id' ) -> indexBy ( 'class_name' ) -> column ( ) ; $ rawProps = ( new Query ( ) ) -> from ( Property :: tableName ( ) ) -> select ( [ 'id' , 'key' , 'storage_id' , 'data_type' ] ) -> where ( [ 'id' => array_keys ( $ workingProps ) , 'in_search' => 1 ] ) -> all ( ) ; $ props = ArrayHelper :: map ( $ rawProps , 'id' , 'key' , 'storage_id' ) ; foreach ( $ storage as $ className => $ id ) { if ( false === isset ( $ props [ $ id ] ) || true === empty ( $ props [ $ id ] ) ) { continue ; } $ indexData = self :: prepareIndexData ( $ className , $ props [ $ id ] , $ workingProps , $ index , $ model ) ; if ( false === empty ( $ indexData ) ) { $ this -> client -> bulk ( $ indexData ) ; } } } }
|
Performs model index filling
|
1,733
|
private static function prepareStatic ( $ props , $ modelId , $ workingProps , $ index , $ type , $ languages ) { $ res = $ valIds = [ ] ; $ workingProps = array_intersect_key ( $ workingProps , $ props ) ; $ workingProps = array_flip ( $ workingProps ) ; $ values = ( new Query ( ) ) -> from ( StaticValueTranslation :: tableName ( ) ) -> select ( [ 'model_id' , 'language_id' , 'name' , 'slug' ] ) -> where ( [ 'model_id' => array_keys ( $ workingProps ) ] ) -> all ( ) ; $ propertyValues = [ ] ; foreach ( $ values as $ value ) { if ( false === isset ( $ propertyValues [ $ value [ 'model_id' ] ] ) ) { $ propId = isset ( $ workingProps [ $ value [ 'model_id' ] ] ) ? $ workingProps [ $ value [ 'model_id' ] ] : null ; $ propKey = isset ( $ props [ $ propId ] ) ? $ props [ $ propId ] : null ; $ propertyValues [ $ value [ 'model_id' ] ] = [ 'static_value_id' => $ value [ 'model_id' ] , 'prop_id' => $ propId , 'prop_key' => $ propKey , 'value_' . $ languages [ $ value [ 'language_id' ] ] => $ value [ 'name' ] , 'slug_' . $ languages [ $ value [ 'language_id' ] ] => $ value [ 'slug' ] , ] ; } else { $ propertyValues [ $ value [ 'model_id' ] ] [ 'value_' . $ languages [ $ value [ 'language_id' ] ] ] = $ value [ 'name' ] ; $ propertyValues [ $ value [ 'model_id' ] ] [ 'slug_' . $ languages [ $ value [ 'language_id' ] ] ] = $ value [ 'slug' ] ; } } if ( false === empty ( $ propertyValues ) ) { $ res [ 'body' ] [ ] = [ 'index' => [ '_id' => $ modelId , '_index' => $ index , '_type' => $ type , ] ] ; $ res [ 'body' ] [ ] = [ 'model_id' => $ modelId , Search :: STATIC_VALUES_FILED => array_values ( $ propertyValues ) , ] ; } return $ res ; }
|
Prepares bulk data to store in elasticsearch index for model properties static values
|
1,734
|
private static function prepareEav ( $ model , $ props , $ index , $ type , $ languages ) { $ eavTable = $ model -> eavTable ( ) ; $ values = ( new Query ( ) ) -> from ( $ eavTable ) -> where ( [ 'model_id' => $ model -> id , 'property_id' => array_keys ( $ props ) ] ) -> select ( [ 'id' , 'property_id' , 'value_integer' , 'value_float' , 'value_string' , 'value_text' , 'language_id' ] ) -> all ( ) ; $ rows = $ data = [ ] ; foreach ( $ values as $ val ) { $ propKey = isset ( $ props [ $ val [ 'property_id' ] ] ) ? $ props [ $ val [ 'property_id' ] ] : null ; $ row = [ 'eav_value_id' => $ val [ 'id' ] , 'prop_id' => $ val [ 'property_id' ] , 'prop_key' => $ propKey , 'value_integer' => $ val [ 'value_integer' ] , 'value_float' => $ val [ 'value_float' ] , ] ; if ( $ val [ 'language_id' ] == 0 ) { $ row [ 'utr_text' ] = $ val [ 'value_text' ] ; } else { if ( false === isset ( $ languages [ $ val [ 'language_id' ] ] ) ) { continue ; } $ row [ 'str_value_' . $ languages [ $ val [ 'language_id' ] ] ] = $ val [ 'value_string' ] ; $ row [ 'txt_value_' . $ languages [ $ val [ 'language_id' ] ] ] = $ val [ 'value_text' ] ; } $ rows [ ] = $ row ; } if ( false === empty ( $ rows ) ) { $ data [ 'body' ] [ ] = [ 'index' => [ '_id' => $ model -> id , '_index' => $ index , '_type' => $ type , ] ] ; $ data [ 'body' ] [ ] = [ 'model_id' => $ model -> id , Search :: EAV_FIELD => $ rows , ] ; } return $ data ; }
|
Prepares bulk data to store in elasticsearch index for model properties eav values
|
1,735
|
public function convert ( $ source , $ adapter = 'hpricot' , $ base_url = null , $ line_length = 65 , $ link_query_string = null , $ preserve_styles = true , $ remove_ids = true , $ remove_classes = true , $ remove_comments = true ) { $ params = array ( 'adapter' => $ adapter , 'base_url' => $ base_url , 'line_length' => $ line_length , 'link_query_string' => $ link_query_string , 'preserve_styles' => $ preserve_styles , 'remove_ids' => $ remove_ids , 'remove_classes' => $ remove_classes , 'remove_comments' => $ remove_comments , ) ; if ( filter_var ( $ source , FILTER_VALIDATE_URL ) ) { $ params [ 'url' ] = $ source ; } else { $ params [ 'html' ] = $ source ; } return $ this -> request ( $ params ) ; }
|
Convert an email using Premailer
|
1,736
|
private function request ( array $ params = array ( ) ) { $ request = $ this -> client -> createRequest ( 'POST' , $ this -> url ) ; $ body = $ request -> getBody ( ) ; foreach ( $ params as $ key => $ value ) { $ body -> setField ( $ key , $ value ) ; } try { $ response = $ this -> client -> send ( $ request ) ; } catch ( \ Exception $ e ) { throw new \ ScottRobertson \ Premailer \ Exception \ Request ( $ e -> getMessage ( ) ) ; } return new Response ( $ response -> json ( ) , $ this -> client ) ; }
|
Make the request to Premailer
|
1,737
|
public function addPattern ( $ pattern , $ childRuleName = null ) { preg_match_all ( '/\\\\.|' . '\(\?|[()]|' . '\[\^?\]?(?:\\\\.|\[:[^]]*:\]|[^]\\\\])*\]|' . '[^[()\\\\]+/' , $ pattern , $ matches ) ; $ groupDeep = 0 ; $ pattern = '(' ; foreach ( $ matches [ 0 ] as $ match ) { switch ( $ match ) { case '(' : $ pattern .= '\\(' ; break ; case ')' : if ( $ groupDeep > 0 ) { $ groupDeep -- ; } else { $ pattern .= '\\' ; } $ pattern .= ')' ; break ; case '(?' : $ groupDeep ++ ; $ pattern .= '(?' ; break ; default : $ pattern .= substr ( $ match , 0 , 1 ) == '\\' ? $ match : str_replace ( '/' , '\\/' , $ match ) ; break ; } } $ pattern .= ')' ; $ this -> patterns [ ] = [ 'pattern' => $ pattern , 'childRuleName' => $ childRuleName , ] ; }
|
Add pattern to rule pattern
|
1,738
|
public function split ( $ text ) { if ( count ( $ this -> patterns ) === 0 ) { return false ; } if ( $ this -> concatenatedPatterns === null ) { $ this -> concatenatedPatterns = '/' . implode ( '|' , array_map ( function ( $ pattern ) { return $ pattern [ 'pattern' ] ; } , $ this -> patterns ) ) . '/msSi' ; } if ( ! preg_match ( $ this -> concatenatedPatterns , $ text , $ matches ) ) { return false ; } $ match = array_shift ( $ matches ) ; $ patternNo = count ( $ matches ) - 1 ; $ childRuleName = $ this -> patterns [ $ patternNo ] [ 'childRuleName' ] ; list ( $ first , $ end ) = preg_split ( $ this -> patterns [ $ patternNo ] [ 'pattern' ] . 'msSi' , $ text , 2 ) ; return [ $ first , $ match , $ end , $ childRuleName ] ; }
|
Split subject into pieces
|
1,739
|
public function addCondition ( $ validation ) { if ( ! $ this -> property ) { throw new Exception \ InvalidArgumentException ( "Condition can be called only on properties!" ) ; } $ condition = new Validator \ Condition ( $ this -> _getValidation ( $ validation ) , $ this ) ; $ this -> rules [ ] = $ condition ; return $ condition -> getValidator ( ) ; }
|
Add validation condition
|
1,740
|
public function addError ( $ message , $ severity = Validator \ Rule :: ERROR , array $ indexes = [ ] ) { $ rule = new Validator \ Rule ( $ this -> entity , function ( ) { return false ; } , $ message , $ this -> property , $ severity , $ this -> child ) ; $ rule -> setChildFailed ( $ indexes ) ; $ this -> rules [ ] = $ rule ; return $ this ; }
|
Add permanent error manually
|
1,741
|
public function on ( $ name , $ child = null ) { $ reflection = $ this -> entity -> getReflection ( ) ; if ( ! $ reflection -> hasProperty ( $ name ) ) { throw new Exception \ InvalidArgumentException ( "Unknown property '" . $ name . "'!" ) ; } $ this -> property = $ reflection -> getProperty ( $ name ) ; if ( $ this -> property -> hasOption ( Computed :: KEY ) ) { throw new Exception \ InvalidArgumentException ( "Validation can not be used on computed property!" ) ; } if ( $ child && ( ! $ this -> property -> getType ( ) === Entity \ Reflection \ Property :: TYPE_ENTITY && ! $ this -> property -> getType ( ) === Entity \ Reflection \ Property :: TYPE_COLLECTION ) ) { throw new Exception \ InvalidArgumentException ( "Child validation can be used only on entities and collections!" ) ; } $ this -> child = $ child ; return $ this -> endCondition ( ) ; }
|
Set property which is validation configured on
|
1,742
|
public function addRule ( $ validation , $ message , $ severity = Validator \ Rule :: ERROR ) { $ this -> rules [ ] = new Validator \ Rule ( $ this -> entity , $ this -> _getValidation ( $ validation ) , $ message , $ this -> property , $ severity , $ this -> child ) ; return $ this ; }
|
Addd validation rule
|
1,743
|
public function validate ( $ failOn = Validator \ Rule :: ERROR ) { $ this -> warnings = [ ] ; $ this -> errors = [ ] ; foreach ( $ this -> rules as $ rule ) { if ( $ rule instanceof Validator \ Condition ) { $ condition = $ rule ; if ( $ condition -> validate ( ) ) { if ( ! $ condition -> getValidator ( ) -> validate ( $ failOn ) ) { $ this -> errors = array_merge ( $ this -> errors , $ rule -> getValidator ( ) -> getErrors ( ) ) ; } $ this -> warnings = array_merge ( $ this -> warnings , $ rule -> getValidator ( ) -> getWarnings ( ) ) ; } } else { if ( ! $ rule -> validate ( ) ) { if ( $ rule -> getSeverity ( ) <= $ failOn ) { $ this -> errors [ ] = $ rule ; } else { $ this -> warnings [ ] = $ rule ; } } } } foreach ( $ this -> entity -> getData ( ) as $ propertyName => $ value ) { if ( $ value instanceof Entity ) { $ validator = $ value -> getValidator ( ) ; if ( ! $ validator -> validate ( $ failOn ) ) { foreach ( $ validator -> getErrors ( ) as $ error ) { $ rule = clone $ error ; $ rule -> setPath ( array_merge ( [ $ propertyName ] , $ rule -> getPath ( ) ) ) ; $ this -> errors [ ] = $ rule ; } } foreach ( $ validator -> getWarnings ( ) as $ warning ) { $ rule = clone $ warning ; $ rule -> setPath ( array_merge ( [ $ propertyName ] , $ rule -> getPath ( ) ) ) ; $ this -> warnings [ ] = $ rule ; } } } return count ( $ this -> errors ) === 0 ; }
|
Run all validations
|
1,744
|
public function html ( ) { if ( ! $ this -> getPublicKey ( ) ) { throw new Exception ( 'You must set public key provided by reCaptcha' ) ; } $ error = ( $ this -> getError ( ) ? '&error=' . $ this -> getError ( ) : null ) ; $ theme = null ; if ( $ this -> theme ) { $ theme = '<script> var RecaptchaOptions = {theme: "' . $ this -> theme . '"};</script>' ; } return $ theme . '<script type="text/javascript" src="' . self :: SERVER . '/challenge?k=' . $ this -> getPublicKey ( ) . $ error . '"></script> <noscript> <iframe src="' . self :: SERVER . '/noscript?k=' . $ this -> getPublicKey ( ) . $ error . '" height="300" width="500" frameborder="0"></iframe><br/> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> </noscript>' ; }
|
Generates reCaptcha form to output to your end user
|
1,745
|
public function check ( $ captcha_challenge = false , $ captcha_response = false ) { if ( ! $ this -> getPrivateKey ( ) ) { throw new Exception ( 'You must set private key provided by reCaptcha' ) ; } if ( ! $ captcha_challenge && ! $ captcha_response ) { if ( isset ( $ _POST [ 'recaptcha_challenge_field' ] ) && isset ( $ _POST [ 'recaptcha_response_field' ] ) ) { $ captcha_challenge = $ _POST [ 'recaptcha_challenge_field' ] ; $ captcha_response = $ _POST [ 'recaptcha_response_field' ] ; } } $ response = new Response ( ) ; if ( strlen ( $ captcha_challenge ) == 0 || strlen ( $ captcha_response ) == 0 ) { $ response -> setValid ( false ) ; $ response -> setError ( 'Incorrect-captcha-sol' ) ; return $ response ; } $ process = $ this -> process ( array ( 'privatekey' => $ this -> getPrivateKey ( ) , 'remoteip' => $ this -> getRemoteIp ( ) , 'challenge' => $ captcha_challenge , 'response' => $ captcha_response ) ) ; $ answers = explode ( "\n" , $ process [ 1 ] ) ; if ( trim ( $ answers [ 0 ] ) == 'true' ) { $ response -> setValid ( true ) ; } else { $ response -> setValid ( false ) ; $ response -> setError ( $ answers [ 1 ] ) ; } return $ response ; }
|
Checks and validates user s response
|
1,746
|
protected function process ( $ parameters ) { $ parameters = $ this -> encode ( $ parameters ) ; $ request = "POST /recaptcha/api/verify HTTP/1.0\r\n" ; $ request .= "Host: " . self :: VERIFY_SERVER . "\r\n" ; $ request .= "Content-Type: application/x-www-form-urlencoded;\r\n" ; $ request .= "Content-Length: " . strlen ( $ parameters ) . "\r\n" ; $ request .= "User-Agent: reCAPTCHA/PHP5\r\n" ; $ request .= "\r\n" ; $ request .= $ parameters ; if ( false == ( $ socket = @ fsockopen ( self :: VERIFY_SERVER , 80 ) ) ) { throw new Exception ( 'Could not open socket to: ' . self :: VERIFY_SERVER ) ; } fwrite ( $ socket , $ request ) ; $ response = '' ; while ( ! feof ( $ socket ) ) { $ response .= fgets ( $ socket , 1160 ) ; } fclose ( $ socket ) ; return explode ( "\r\n\r\n" , $ response , 2 ) ; }
|
Make a signed validation request to reCaptcha s servers
|
1,747
|
protected function encode ( array $ parameters ) { $ uri = '' ; if ( $ parameters ) { foreach ( $ parameters as $ parameter => $ value ) { $ uri .= $ parameter . '=' . urlencode ( stripslashes ( $ value ) ) . '&' ; } } $ uri = substr ( $ uri , 0 , strlen ( $ uri ) - 1 ) ; return $ uri ; }
|
Construct encoded URI string from an array
|
1,748
|
public function setTheme ( $ theme ) { if ( ! self :: isValidTheme ( $ theme ) ) { throw new Exception ( 'Theme ' . $ theme . ' is not valid. Please use one of [' . join ( ', ' , self :: $ themes ) . ']' ) ; } $ this -> theme = $ theme ; }
|
Set a reCaptcha theme
|
1,749
|
public function invoke ( $ callable , array $ namedParams = [ ] , array $ classParams = [ ] ) { $ classParams = $ this -> reindexclassParams ( $ classParams ) ; if ( $ callable instanceof \ Closure ) { return $ this -> invokeFunction ( $ callable , $ namedParams , $ classParams ) ; } if ( is_string ( $ callable ) ) { if ( strpos ( $ callable , '::' ) !== false ) { list ( $ class , $ method ) = explode ( '::' , $ callable ) ; return $ this -> invokeClassMethod ( $ class , $ method , $ namedParams , $ classParams ) ; } else { return $ this -> invokeFunction ( $ callable , $ namedParams , $ classParams ) ; } } if ( is_array ( $ callable ) && count ( $ callable ) == 2 && is_string ( $ callable [ 1 ] ) ) { if ( is_object ( $ callable [ 0 ] ) ) { return $ this -> invokeObjectMethod ( $ callable [ 0 ] , $ callable [ 1 ] , $ namedParams , $ classParams ) ; } if ( is_string ( $ callable [ 0 ] ) ) { return $ this -> invokeClassMethod ( $ callable [ 0 ] , $ callable [ 1 ] , $ namedParams , $ classParams ) ; } } throw new \ InvalidArgumentException ( "Given argument is not callable." ) ; }
|
Invokes a method or anonymous function and returns the result .
|
1,750
|
private function invokeClassMethod ( $ class , $ method , $ namedParams , $ classParams ) { if ( ! class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( "Class $class does not exist." ) ; } $ object = new $ class ( ) ; return $ this -> invokeObjectMethod ( $ object , $ method , $ namedParams , $ classParams ) ; }
|
Invokes a method on a class by creating an instance of the class and then invoking the method .
|
1,751
|
private function invokeObjectMethod ( $ object , $ method , $ namedParams , $ classParams ) { if ( ! method_exists ( $ object , $ method ) ) { $ class = get_class ( $ object ) ; throw new \ InvalidArgumentException ( "Method $class::$method does not exist." ) ; } $ reflection = new \ ReflectionMethod ( $ object , $ method ) ; $ params = $ reflection -> getParameters ( ) ; $ invokeParams = $ this -> mapParameters ( $ params , $ namedParams , $ classParams ) ; return call_user_func_array ( [ $ object , $ method ] , $ invokeParams ) ; }
|
Invokes a method on an object .
|
1,752
|
private function invokeFunction ( $ function , $ namedParams , $ classParams ) { $ reflection = new \ ReflectionFunction ( $ function ) ; $ params = $ reflection -> getParameters ( ) ; $ invokeParams = $ this -> mapParameters ( $ params , $ namedParams , $ classParams ) ; return call_user_func_array ( $ function , $ invokeParams ) ; }
|
Invokes an anonymous function .
|
1,753
|
private function reindexClassParams ( array $ classParams ) { $ reindexed = [ ] ; foreach ( $ classParams as $ param ) { if ( ! is_object ( $ param ) ) { throw new \ InvalidArgumentException ( "\$classParams entries must be objects." ) ; } for ( $ class = get_class ( $ param ) ; $ class !== false ; $ class = get_parent_class ( $ class ) ) { if ( isset ( $ reindexed [ $ class ] ) ) { throw new \ InvalidArgumentException ( "\$classParams contains multiple objects of the same class [$class]." ) ; } $ reindexed [ $ class ] = $ param ; } } return $ reindexed ; }
|
Reindexes an array of objects by class name .
|
1,754
|
public function toJson ( ) { $ json = array ( ) ; $ json [ 'id' ] = $ this -> id ; $ json [ 'from' ] = $ this -> from ; $ json [ 'color' ] = $ this -> color ; $ json [ 'message' ] = $ this -> message ; $ json [ 'notify' ] = $ this -> notify ; $ json [ 'message_format' ] = $ this -> messageFormat ; $ json [ 'date' ] = $ this -> date ; return $ json ; }
|
Serializes Message object
|
1,755
|
public function scanChild ( $ lang ) { assert ( isset ( $ this -> childScanners [ $ lang ] ) ) ; $ scanner = $ this -> childScanners [ $ lang ] ; $ scanner -> pos ( $ this -> pos ( ) ) ; $ substr = $ scanner -> main ( ) ; $ this -> record ( $ scanner -> tagged ( ) , 'XML' , true ) ; $ this -> pos ( $ scanner -> pos ( ) ) ; if ( $ scanner -> interrupt ) { $ this -> childState = array ( $ lang , $ this -> pos ( ) ) ; } else { $ this -> childState = null ; } }
|
c + p from HTML scanner
|
1,756
|
public function getValidator ( ) { if ( ! $ this -> validator ) { $ this -> validator = new Validator ( $ this ) ; } return $ this -> validator -> onEntity ( ) ; }
|
Get entity validator
|
1,757
|
public function toArray ( $ nesting = false ) { $ output = [ ] ; foreach ( $ this :: getReflection ( ) -> getProperties ( ) as $ propertyName => $ property ) { $ value = $ this -> { $ propertyName } ; if ( ( $ value instanceof Entity \ Collection || $ value instanceof Entity ) && $ nesting ) { $ output [ $ propertyName ] = $ value -> toArray ( $ nesting ) ; } else { $ output [ $ propertyName ] = $ value ; } } return $ output ; }
|
Get entity values as array
|
1,758
|
public function jsonSerialize ( ) { $ output = [ ] ; foreach ( $ this :: getReflection ( ) -> getProperties ( ) as $ propertyName => $ property ) { $ value = $ this -> { $ propertyName } ; if ( $ value instanceof Entity \ Collection || $ value instanceof Entity ) { $ output [ $ propertyName ] = $ value -> jsonSerialize ( ) ; } elseif ( $ value instanceof \ DateTime && $ property -> getType ( ) === Entity \ Reflection \ Property :: TYPE_DATE ) { $ output [ $ propertyName ] = ( array ) $ value ; $ output [ $ propertyName ] [ "date" ] = $ value -> format ( self :: $ dateFormat ) ; } else { $ output [ $ propertyName ] = $ value ; } } return $ output ; }
|
Gets data which should be serialized to JSON
|
1,759
|
public function menu_tree_all_data ( $ menu_name , $ link = NULL , $ max_depth = NULL ) { return menu_tree_all_data ( $ menu_name , $ link , $ max_depth ) ; }
|
Get the data structure representing a named menu tree .
|
1,760
|
public function menu_tree_page_data ( $ menu_name , $ max_depth = NULL , $ only_active_trail = FALSE ) { return menu_tree_page_data ( $ menu_name , $ max_depth , $ only_active_trail ) ; }
|
Get the data structure representing a named menu tree based on the current page .
|
1,761
|
public function menu_link_maintain ( $ module , $ op , $ link_path , $ link_title ) { return menu_link_maintain ( $ module , $ op , $ link_path , $ link_title ) ; }
|
Insert update or delete an uncustomized menu link related to a module .
|
1,762
|
public function build ( $ basePath , $ production = false ) { $ minifine = new Minifine ( $ basePath , $ production ) ; $ minifine -> appendJsMinifier ( new MatthiasMullieJs ( new JS ( ) ) ) ; $ minifine -> appendCssMinifier ( new MatthiasMullieCss ( new Css ( ) ) ) ; return $ minifine ; }
|
Builds a new minifine instance
|
1,763
|
public function getEntityLine ( ) { if ( $ this -> definition ) { foreach ( file ( $ this -> getEntityPath ( ) , FILE_IGNORE_NEW_LINES ) as $ lineNumber => $ line ) { if ( strpos ( $ line , $ this -> definition ) !== false ) { return $ lineNumber + 1 ; } } } return 0 ; }
|
Get problematic entity line number
|
1,764
|
public function runFileGeneratorCommand ( $ path , $ argument ) { if ( $ this -> filesystem -> exists ( $ path ) ) { return 'File with the name ' . $ argument . ' already exist' ; } $ folder_name = explode ( '/' , $ argument ) ; $ folder = '' ; if ( count ( $ folder_name ) > 1 ) { $ folder_path = array_slice ( $ folder_name , 0 , - 1 ) ; foreach ( $ folder_path as $ f ) { $ folder .= "$f/" ; } $ filename = end ( $ folder_name ) ; } else { $ filename = $ argument ; } $ folder ? $ location = "$this->basePath/$folder/$filename.php" : $ location = "$this->basePath/$filename.php" ; $ template = $ this -> findTemplateAndReplacePlaceHolders ( 'PlaceHolder' , $ filename , file_get_contents ( $ this -> getTemplate ( $ this -> type ) ) ) ; $ this -> filesystem -> dumpFile ( $ location , $ template ) ; return true ; }
|
Generate and move file to specified path .
|
1,765
|
public function getMatchingRoute ( $ routes , Request $ request ) { foreach ( $ routes as $ matchingRoute ) { if ( $ matchingRoute -> matches ( $ request ) ) { return $ matchingRoute ; } } return null ; }
|
Check which of the given routes matches the given request .
|
1,766
|
public function getByMethod ( $ method = null ) { if ( is_null ( $ method ) ) { return $ this -> getRoutes ( ) ; } return ArrayHelper :: get ( $ this -> routes , $ method , [ ] ) ; }
|
Get all matched routes according to the given request method .
|
1,767
|
public function compare ( MatchedPreferenceInterface $ lValue , MatchedPreferenceInterface $ rValue ) { $ result = $ this -> compareQualityFactorPair ( $ lValue , $ rValue ) ; if ( 0 === $ result ) { $ result = $ this -> comparePrecedence ( $ lValue , $ rValue ) ; } if ( 0 === $ result ) { $ result = $ this -> compareVariant ( $ lValue , $ rValue ) ; } return $ result ; }
|
Comparison function used for ordering matched preferences .
|
1,768
|
private function compareQualityFactorPair ( MatchedPreferenceInterface $ lValue , MatchedPreferenceInterface $ rValue ) { $ compareList = array ( array ( 'left' => $ lValue , 'right' => $ rValue ) , array ( 'left' => $ lValue -> getClientPreference ( ) , 'right' => $ rValue -> getClientPreference ( ) ) , array ( 'left' => $ lValue -> getServerPreference ( ) , 'right' => $ rValue -> getServerPreference ( ) ) ) ; $ result = 0 ; foreach ( $ compareList as $ compare ) { $ result = $ this -> compareQualityFactor ( $ compare [ 'left' ] , $ compare [ 'right' ] ) ; if ( 0 !== $ result ) { break ; } } return $ result ; }
|
Comparison function for quality factors of matched preferences .
|
1,769
|
private function compareQualityFactor ( PreferenceInterface $ lValue , PreferenceInterface $ rValue ) { if ( $ rValue -> getQualityFactor ( ) < $ lValue -> getQualityFactor ( ) ) { return - 1 ; } elseif ( $ rValue -> getQualityFactor ( ) > $ lValue -> getQualityFactor ( ) ) { return 1 ; } else { return 0 ; } }
|
Compare quality factors of preferences .
|
1,770
|
private function comparePrecedence ( PreferenceInterface $ lValue , PreferenceInterface $ rValue ) { if ( $ rValue -> getPrecedence ( ) < $ lValue -> getPrecedence ( ) ) { return - 1 ; } elseif ( $ rValue -> getPrecedence ( ) > $ lValue -> getPrecedence ( ) ) { return 1 ; } else { return 0 ; } }
|
Compare precedences of preferences .
|
1,771
|
private function compareVariant ( MatchedPreferenceInterface $ lValue , MatchedPreferenceInterface $ rValue ) { return strcasecmp ( $ lValue -> getVariant ( ) , $ rValue -> getVariant ( ) ) ; }
|
Compare preferences alphabetically
|
1,772
|
function post ( $ payload ) { $ this -> requestDecorator -> setPayload ( $ payload ) ; $ result = $ this -> client -> post ( $ this -> requestDecorator -> makeResource ( ) , $ this -> requestDecorator -> makePayload ( ) , $ this -> requestDecorator -> makeHeaders ( ) ) ; $ this -> refresh ( ) ; return $ result ; }
|
Make a post request .
|
1,773
|
function put ( $ id , $ payload ) { $ this -> requestDecorator -> setId ( $ id ) ; $ this -> requestDecorator -> setPayload ( $ payload ) ; if ( ( is_array ( $ payload ) ) && ( ! empty ( $ payload [ 'sys' ] [ 'version' ] ) ) ) { $ this -> requestDecorator -> addHeader ( 'X-Contentful-Version' , $ payload [ 'sys' ] [ 'version' ] ) ; } $ result = $ this -> client -> put ( $ this -> requestDecorator -> makeResource ( ) , $ this -> requestDecorator -> makePayload ( ) , $ this -> requestDecorator -> makeHeaders ( ) ) ; $ this -> refresh ( ) ; return $ result ; }
|
Make a put request .
|
1,774
|
function delete ( $ id ) { $ this -> requestDecorator -> setId ( $ id ) ; $ result = $ this -> client -> delete ( $ this -> requestDecorator -> makeResource ( ) , $ this -> requestDecorator -> makeHeaders ( ) ) ; $ this -> refresh ( ) ; return $ result ; }
|
Make a delete request .
|
1,775
|
public function push ( AbstractJob $ job ) { if ( $ job -> getRunAt ( ) > time ( ) ) { return $ this -> addJobToRetrySet ( $ job , $ job -> getRunAt ( ) ) ; } return ( bool ) $ this -> client -> rpush ( $ this -> getQueueNameWithPrefix ( $ job -> getQueue ( ) ) , serialize ( $ job ) ) ; }
|
push a job to the queue
|
1,776
|
public function pop ( $ queue ) { $ this -> migrateRetryJobs ( $ queue ) ; $ data = $ this -> client -> lpop ( $ this -> getQueueNameWithPrefix ( $ queue ) ) ; if ( ! empty ( $ data ) ) { $ job = @ unserialize ( $ data ) ; if ( $ job instanceof AbstractJob ) { return $ job ; } } return null ; }
|
get a job from the queue
|
1,777
|
public function retry ( AbstractJob $ job ) { if ( $ job -> shouldRetry ( ) ) { return $ this -> addJobToRetrySet ( $ job , $ job -> getRetryTime ( ) ) ; } return false ; }
|
retry a job
|
1,778
|
protected function migrateRetryJobs ( $ queue ) { $ luaScript = <<<LUA-- Get all of the jobs with an expired "score"...local val = redis.call('zrangebyscore', KEYS[1], '-inf', ARGV[1])-- If we have values in the array, we will remove them from the first queue-- and add them onto the destination queue in chunks of 100, which moves-- all of the appropriate jobs onto the destination queue very safely.if(next(val) ~= nil) then redis.call('zremrangebyrank', KEYS[1], 0, #val - 1) for i = 1, #val, 100 do redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val))) endendreturn valLUA ; return $ this -> client -> eval ( $ luaScript , 2 , $ this -> getRetryZsetNameWithPrefix ( $ queue ) , $ this -> getQueueNameWithPrefix ( $ queue ) , time ( ) ) ; }
|
migrate the retry jobs of a queue
|
1,779
|
protected function addJobToRetrySet ( $ job , $ retryAt ) { return ( bool ) $ this -> client -> zadd ( $ this -> getRetryZsetNameWithPrefix ( $ job -> getQueue ( ) ) , $ retryAt , serialize ( $ job ) ) ; }
|
add job to the retry set
|
1,780
|
public static function SSHA ( $ password , $ salt = null ) { if ( empty ( $ salt ) ) { if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ salt = bin2hex ( openssl_random_pseudo_bytes ( 4 ) ) ; } else { throw new Exception ( "You must have the openssl extension installed and enabled to use a random salt" ) ; } } return "{SSHA}" . base64_encode ( sha1 ( $ password . $ salt , true ) . $ salt ) ; }
|
Generates and returns a new password as a SSHA hash for use in LDAP . If the salt is not specified one will be generated using the openssl extension and have a length of four bytes .
|
1,781
|
public function editAction ( ) { $ id = $ this -> params ( ) -> fromRoute ( 'id' ) ; if ( ! is_numeric ( $ id ) ) { $ this -> flashMessenger ( ) -> addMessage ( $ this -> scTranslate ( 'The article identifier was not specified.' ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/content-manager' ) -> setStatusCode ( 303 ) ; } try { $ article = $ this -> getArticleService ( ) -> getArticle ( $ id ) ; } catch ( RuntimeException $ e ) { $ this -> flashMessenger ( ) -> addMessage ( $ e -> getMessage ( ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/content-manager' ) -> setStatusCode ( 303 ) ; } $ form = $ this -> getArticleForm ( ) ; $ form -> setAttribute ( 'action' , $ this -> url ( ) -> fromRoute ( 'sc-admin/article/edit' , [ 'id' => $ id ] ) ) ; $ form -> bind ( $ article ) ; if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ form -> setData ( $ this -> getRequest ( ) -> getPost ( ) ) ; if ( $ form -> isValid ( ) ) { $ this -> getArticleService ( ) -> saveContent ( $ form -> getData ( ) ) ; } } return new ViewModel ( [ 'content' => $ article , 'form' => $ form , ] ) ; }
|
Edit File .
|
1,782
|
public function generateRoutes ( $ name , array $ localesWithPaths , Route $ baseRoute ) { $ this -> assertLocalesAreSupported ( array_keys ( $ localesWithPaths ) ) ; return $ this -> routeGenerator -> generateRoutes ( $ name , $ localesWithPaths , $ baseRoute ) ; }
|
Generate localized versions of the given route .
|
1,783
|
protected static function buildTableName ( $ suffix = '' ) { if ( true === empty ( static :: $ tablePrefix ) ) { if ( strpos ( static :: tableName ( ) , '}}' ) !== false ) { $ name = str_replace ( '}}' , $ suffix . '}}' , static :: tableName ( ) ) ; } else { $ name = static :: tableName ( ) . $ suffix ; } } else { $ name = static :: $ tablePrefix . $ suffix ; } return $ name ; }
|
Build a valid table name with suffix
|
1,784
|
public function propertiesRules ( ) { $ rules = [ ] ; $ this -> ensurePropertiesAttributes ( ) ; if ( empty ( $ this -> propertiesIds ) === false ) { foreach ( $ this -> propertiesIds as $ propertyId ) { $ property = Property :: findById ( $ propertyId ) ; $ handler = $ property -> handler ( ) ; $ rules = ArrayHelper :: merge ( $ rules , $ handler -> getValidationRules ( $ property ) ) ; if ( $ property -> isRequired ( ) ) { $ rules = ArrayHelper :: merge ( $ rules , [ [ $ property -> key , 'required' ] ] ) ; } } } return $ rules ; }
|
Array of validation rules for properties
|
1,785
|
public function drupal_set_message ( $ message = null , $ type = 'status' , $ repeat = true ) { return drupal_set_message ( $ message , $ type , $ repeat ) ; }
|
Sets a message to display to the user .
|
1,786
|
public function & drupal_static ( $ name , $ default_value = null , $ reset = false ) { return drupal_static ( $ name , $ default_value , $ reset ) ; }
|
Provides central static variable storage .
|
1,787
|
public function getModel ( $ model ) { $ ns = $ this -> getAppNamespace ( ) ; if ( $ ns ) { $ qm = $ ns . $ model ; if ( class_exists ( $ qm ) ) { return new $ qm ; } $ qm = $ ns . 'Models' . '\\' . $ model ; if ( class_exists ( $ qm ) ) { return new $ qm ; } } return false ; }
|
Attempt to get an apps model from namespace .
|
1,788
|
public function apply_filters ( ) { $ args = func_get_args ( ) ; $ tag = current ( array_splice ( $ args , 1 , 1 ) ) ; return apply_filters_ref_array ( $ tag , $ args ) ; }
|
Call WordPress filter .
|
1,789
|
public function onRunnerStart ( ) { $ rootSuite = Context :: getInstance ( ) -> getCurrentSuite ( ) ; $ rootSuite -> getScope ( ) -> peridotAddChildScope ( $ this -> scope ) ; }
|
When the runner starts we will mix in the http kernel scope into the root suite thereby making it available EVERYWHERE .
|
1,790
|
public function actionDelete ( ) { $ rr = new RequestResponse ( ) ; if ( $ rr -> isRequestAjaxPost ( ) ) { try { $ model = $ this -> model ; $ id = $ model -> name ; $ model = $ this -> findModel ( $ id ) ; if ( ! in_array ( $ model -> item -> name , CmsManager :: protectedPermissions ( ) ) ) { if ( \ Yii :: $ app -> getAuthManager ( ) -> remove ( $ model -> item ) ) { $ rr -> message = \ Yii :: t ( 'app' , 'Record deleted successfully' ) ; $ rr -> success = true ; } else { $ rr -> message = \ Yii :: t ( 'app' , 'Record deleted unsuccessfully' ) ; $ rr -> success = false ; } } else { $ rr -> message = \ Yii :: t ( 'app' , 'This entry can not be deleted!' ) ; $ rr -> success = false ; } } catch ( \ Exception $ e ) { $ rr -> message = $ e -> getMessage ( ) ; $ rr -> success = false ; } return ( array ) $ rr ; } }
|
Deletes an existing Game model . If deletion is successful the browser will be redirected to the index page .
|
1,791
|
public function down ( ) { try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Content' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Search' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Garbage' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Layout' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Widgets' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Users' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.Roles' ) -> down ( ) ; } catch ( Exception $ e ) { } try { $ this -> buildMapper ( 'ScContent.Migration.MapperBase.RolesLinker' ) -> down ( ) ; } catch ( Exception $ e ) { } }
|
Remove migration from the database .
|
1,792
|
public function get ( $ name = '' ) { if ( ! $ this -> _app -> name ) return [ ] ; if ( ! $ this -> _config ) $ this -> getConfig ( ) ; return $ name ? ( isset ( $ this -> _config [ '_' . $ name ] ) ? $ this -> _config [ '_' . $ name ] : [ ] ) : $ this -> _config ; }
|
Gets a specific mod config array .
|
1,793
|
public function matches ( $ url ) { $ pattern = $ this -> getRegexPattern ( ) ; if ( preg_match ( $ pattern , $ url , $ matches ) ) { foreach ( $ matches as $ key => $ value ) { if ( is_int ( $ key ) ) { unset ( $ matches [ $ key ] ) ; } } return $ matches ; } return false ; }
|
Checks whether this route matches the given url .
|
1,794
|
public function run ( Application $ app , Request $ request , array $ arguments = [ ] ) { return $ this -> processRequest ( $ app , $ request , $ this -> callback , $ arguments ) ; }
|
Processes the Request and returns a Response .
|
1,795
|
public function method ( $ method ) { if ( ! in_array ( $ method , $ this -> methods ) ) { throw new \ InvalidArgumentException ( "Unknown HTTP method: $method" ) ; } $ this -> method = $ method ; return $ this ; }
|
Sets the route s HTTP method .
|
1,796
|
private function compileRegex ( ) { $ path = $ this -> prefix . $ this -> path ; $ asserts = $ this -> asserts ; $ callback = function ( $ matches ) use ( $ asserts ) { $ name = $ matches [ 1 ] ; $ pattern = isset ( $ asserts [ $ name ] ) ? $ asserts [ $ name ] : ".+" ; return "(?<$name>$pattern)" ; } ; $ pattern = preg_replace_callback ( '/{([^}]+)}/' , $ callback , $ path ) ; $ pattern = preg_replace ( '/\/+/' , '/' , $ pattern ) ; $ pattern = str_replace ( '/' , '\\/' , $ pattern ) ; return "/^$pattern$/" ; }
|
Compiles a regex pattern which matches this route .
|
1,797
|
protected function fixUrl ( $ url , $ encode ) { if ( strpos ( $ url , "http" ) !== 0 ) { $ url = "http://" . $ url ; } if ( $ encode ) { $ url = urlencode ( $ url ) ; } return $ url ; }
|
Returns a corrected URL
|
1,798
|
protected function exec ( $ url ) { $ client = $ this -> getRequest ( ) ; $ response = $ client -> request ( 'GET' , $ url ) ; return $ this -> handleResponse ( $ response -> getBody ( ) ) ; }
|
Executes a CURL request to the Bitly API
|
1,799
|
public function search ( $ filter , $ fields ) { $ param = array ( 'filter' => json_encode ( $ filter ) , 'fields' => json_encode ( $ fields ) ) ; return $ this -> get ( 'inventory/resources/' , $ param ) ; }
|
Search a service
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.