idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
23,500
public function withParameter ( $ name , $ value ) { $ query = clone $ this ; $ query -> setParameter ( $ name , $ value ) ; return $ query ; }
Get a new Query with a specified parameter
23,501
private function formatNormal ( \ DateInterval $ diff ) { $ str = '' ; $ first = null ; $ second = null ; $ val = 0 ; if ( $ diff -> y > 0 ) { $ str = "year" ; $ val = $ diff -> y ; } else if ( $ diff -> m > 0 ) { $ str = "month" ; $ val = $ diff -> m ; } else if ( $ diff -> d > 0 ) { $ str = "day" ; $ first = array ( 'after' => "tomorrow" , 'before' => "yesterday" ) ; $ val = $ diff -> d ; } else if ( $ diff -> h > 0 ) { $ str = "hour" ; $ val = $ diff -> h ; } else if ( $ diff -> i == 30 ) { var_dump ( $ diff -> invert ) ; return $ diff -> invert ? $ this -> translator -> trans ( "next half hour" ) : $ this -> translator -> trans ( "half hour ago" ) ; } else if ( $ diff -> i > 0 ) { $ str = "minute" ; $ val = $ diff -> i ; } else if ( $ diff -> s > 0 ) { $ str = "second" ; $ val = $ diff -> s ; } $ id = "%" . $ str . "s%" ; if ( $ diff -> invert ) { return $ this -> translator -> transChoice ( ( $ first && isset ( $ first [ 'after' ] ) ? $ first [ 'after' ] : "next " . $ str ) . "|" . ( $ second && isset ( $ second [ 'after' ] ) ? $ second [ 'after' ] : "next " . $ id . " " . $ str . "s" ) , $ val , array ( $ id => $ val ) ) ; } else { return $ this -> translator -> transChoice ( ( $ first && isset ( $ first [ 'before' ] ) ? $ first [ 'before' ] : ( $ str == "hour" ? 'an' : 'a' ) . ' ' . $ str . ' ago' ) . "|" . ( $ second && isset ( $ second [ 'before' ] ) ? $ second [ 'before' ] : $ id . " " . $ str . "s ago" ) , $ val , array ( $ id => $ val ) ) ; } }
Formating using default format .
23,502
private function formatSimple ( \ DateInterval $ diff ) { $ str = '' ; $ pre = '' ; if ( $ diff -> y > 0 || $ diff -> m > 0 || $ diff -> d == 1 || $ diff -> h == 1 ) { return $ this -> formatNormal ( $ diff ) ; } else if ( $ diff -> d > 0 ) { $ str = "few days" ; } else if ( $ diff -> h > 0 ) { $ str = "few hours" ; } else if ( $ diff -> i < 2 ) { $ str = "minute" ; $ pre = "a " ; } else if ( $ diff -> i < 20 ) { $ str = "15 minutes" ; } else if ( $ diff -> i < 40 ) { $ str = "half hour" ; } else if ( $ diff -> i < 60 ) { $ str = "hour" ; $ pre = "an " ; } return $ this -> translator -> trans ( $ diff -> invert ? "next " . $ str : $ pre . $ str . " ago" ) ; }
Formating using simple format .
23,503
private function convertFormat ( $ time , $ dateFormat ) { if ( ! ( $ time instanceof \ DateTime ) ) { if ( is_numeric ( $ time ) ) { $ transformer = new DateTimeToTimestampTransformer ( ) ; $ time = $ transformer -> reverseTransform ( $ time ) ; } else { $ transformer = new DateTimeToStringTransformer ( null , null , $ dateFormat ) ; $ time = $ transformer -> reverseTransform ( $ time ) ; } } return $ time ; }
Converting date format to expected by methods
23,504
public function cover ( $ entity , array $ options = [ ] ) { $ options += [ 'internal' => false ] ; $ result = [ 'type' => $ entity -> raw [ 'type' ] , 'title' => $ entity -> title ( ) ] ; if ( $ options [ 'internal' ] ) { return [ 'url' => 'instagram://' . $ entity -> id ( ) ] + $ result ; } if ( ! $ url = static :: _url ( $ entity -> raw ) ) { return false ; } return compact ( 'url' ) + $ result ; }
Chooses highest resolution possible .
23,505
public function hasMany ( $ sPrimaryKeyName , $ sEntityJoinName , $ sForeignKeyName , $ sNamespaceEntity , array $ aOptions = array ( ) ) { $ this -> _aJoins [ $ sEntityJoinName ] = function ( $ mParameters = null ) use ( $ sPrimaryKeyName , $ sEntityJoinName , $ sForeignKeyName , $ sNamespaceEntity ) { if ( ! isset ( $ this -> $ sEntityJoinName ) ) { $ oOrm = new Orm ; $ oOrm -> select ( array ( '*' ) ) -> from ( $ sEntityJoinName ) ; if ( $ mParameters ) { $ aWhere [ $ sForeignKeyName ] = $ mParameters ; } else { $ sMethodName = 'get_' . $ sPrimaryKeyName ; $ aWhere [ $ sForeignKeyName ] = $ this -> $ sMethodName ( ) ; } $ this -> $ sEntityJoinName = $ oOrm -> where ( $ aWhere ) -> load ( false , $ sNamespaceEntity . '\\' ) ; } return $ this -> $ sEntityJoinName ; } ; if ( isset ( $ aOptions [ 'foreignKey' ] ) && ! isset ( $ this -> _aForeignKey [ $ sEntityJoinName ] ) ) { $ this -> _aForeignKey [ $ sEntityJoinName ] = array ( 'primary_key' => $ sPrimaryKeyName , 'entity_join_name' => $ sEntityJoinName , 'foreign_key_name' => $ sForeignKeyName , 'foreign_key_options' => $ aOptions [ 'foreignKey' ] , 'has_one' => 0 ) ; } }
create a join in one to many
23,506
private function hasMethodDocBlockDescription ( File $ sniffedFile , $ index ) { $ indexOfOpeningDocBlock = $ sniffedFile -> findPrevious ( [ T_DOC_COMMENT_OPEN_TAG ] , $ index ) ; $ indexOfClosingDocBlock = $ sniffedFile -> findPrevious ( [ T_DOC_COMMENT_CLOSE_TAG ] , $ index ) ; $ hasDescription = false ; for ( $ i = $ indexOfOpeningDocBlock + 1 ; $ i < $ indexOfClosingDocBlock ; $ i ++ ) { if ( ! $ this -> isCommentWhitespaceToken ( $ sniffedFile , $ i ) && ! $ this -> isCommentStartToken ( $ sniffedFile , $ i ) ) { $ hasDescription = $ this -> isCommentTextToken ( $ sniffedFile , $ i ) ; break ; } } return $ hasDescription ; }
Checks if the methods docblock contains a description .
23,507
private function needsMethodDocBlockDescription ( File $ sniffedFile , $ index ) { $ methodName = $ sniffedFile -> getDeclarationName ( $ index ) ; $ isSpecialMethod = $ this -> methodIsAccessor ( $ methodName ) ; $ isDataProvider = $ this -> methodIsDataProvider ( $ methodName ) ; return ! $ isSpecialMethod && ! $ isDataProvider && ! $ this -> isTestMethod ( $ sniffedFile , $ index ) ; }
Checks if the method annotation is in need of a description .
23,508
public static function create ( $ config , $ simple = false ) { if ( request ( ) -> has ( '_itemRelSel' ) ) { list ( $ itemsRelSelCampo , $ itemsRelSelId ) = explode ( "|" , request ( ) -> _itemRelSel ) ; foreach ( $ config [ 'campos' ] as $ clave => $ relacion ) { if ( $ clave != $ itemsRelSelCampo ) { unset ( $ config [ 'campos' ] [ $ clave ] ) ; } } } if ( ! CrudGenerator :: checkPermission ( $ config ) ) { return View :: make ( 'sirgrimorum::crudgen.error' , [ 'message' => trans ( 'crudgenerator::admin.messages.permission' ) ] ) ; } $ modelo = strtolower ( class_basename ( $ config [ "modelo" ] ) ) ; $ config = CrudGenerator :: loadTodosFromConfig ( $ config ) ; if ( ! $ simple ) { $ js_section = config ( "sirgrimorum.crudgenerator.js_section" ) ; $ css_section = config ( "sirgrimorum.crudgenerator.css_section" ) ; } else { $ js_section = "" ; $ css_section = "" ; } if ( $ config [ 'url' ] == "Sirgrimorum_CrudAdministrator" ) { $ config [ 'url' ] = route ( "sirgrimorum_modelo::store" , [ "modelo" => $ modelo ] ) ; if ( \ Lang :: has ( 'crudgenerator::' . $ modelo . '.labels.create' ) ) { $ config [ 'botones' ] = trans ( "crudgenerator::$modelo.labels.create" ) ; } else { $ config [ 'botones' ] = trans ( "crudgenerator::admin.layout.crear" ) ; } } if ( request ( ) -> has ( '_itemRelSel' ) ) { $ view = View :: make ( 'sirgrimorum::crudgen.templates.relationshipssel_simple' , [ 'config' => $ config , 'datoId' => $ itemsRelSelId , 'columna' => $ itemsRelSelCampo , 'tabla' => ( new $ config [ 'campos' ] [ $ itemsRelSelCampo ] [ 'modelo' ] ) -> getTable ( ) , 'datos' => $ config [ 'campos' ] [ $ itemsRelSelCampo ] , 'js_section' => $ js_section , 'css_section' => $ css_section , 'modelo' => $ modelo ] ) ; } else { $ view = View :: make ( 'sirgrimorum::crudgen.create' , [ 'config' => $ config , 'tieneHtml' => CrudGenerator :: hasTipo ( $ config , [ 'html' , 'article' ] ) , 'tieneDate' => CrudGenerator :: hasTipo ( $ config , [ 'date' , 'datetime' , 'time' ] ) , 'tieneSlider' => CrudGenerator :: hasTipo ( $ config , 'slider' ) , 'tieneSelect' => CrudGenerator :: hasTipo ( $ config , [ 'select' , 'relationship' , 'relationships' ] ) , 'tieneSearch' => CrudGenerator :: hasTipo ( $ config , [ 'relationshipssel' ] ) , 'tieneFile' => CrudGenerator :: hasTipo ( $ config , [ 'file' , 'files' ] ) , 'tieneJson' => CrudGenerator :: hasTipo ( $ config , [ 'json' ] ) , 'js_section' => $ js_section , 'css_section' => $ css_section , 'modelo' => $ modelo ] ) ; } return $ view -> render ( ) ; }
Generate create view for a model
23,509
public static function show ( $ config , $ id = null , $ simple = false , $ registro = null ) { $ modelo = strtolower ( class_basename ( $ config [ "modelo" ] ) ) ; if ( $ registro == null ) { $ modeloM = ucfirst ( $ config [ 'modelo' ] ) ; if ( $ id == null ) { $ registro = $ modeloM :: first ( ) ; } elseif ( is_object ( $ id ) ) { $ registro = $ id ; $ id = $ registro -> getKey ( ) ; } else { $ registro = $ modeloM :: find ( $ id ) ; } } if ( ! CrudGenerator :: checkPermission ( $ config , $ registro -> getKey ( ) ) ) { return View :: make ( 'sirgrimorum::crudgen.error' , [ 'message' => trans ( 'crudgenerator::admin.messages.permission' ) ] ) ; } if ( ! $ simple ) { $ js_section = config ( "sirgrimorum.crudgenerator.js_section" ) ; $ css_section = config ( "sirgrimorum.crudgenerator.css_section" ) ; } else { $ js_section = "" ; $ css_section = "" ; } $ view = View :: make ( 'sirgrimorum::crudgen.show' , array ( 'config' => $ config , 'registro' => $ registro , 'js_section' => $ js_section , 'css_section' => $ css_section , 'modelo' => $ modelo ) ) ; return $ view -> render ( ) ; }
Generate view to show a model
23,510
public static function edit ( $ config , $ id = null , $ simple = false , $ registro = null ) { $ modelo = strtolower ( class_basename ( $ config [ "modelo" ] ) ) ; $ config = CrudGenerator :: loadTodosFromConfig ( $ config ) ; if ( $ registro == null ) { $ modeloM = ucfirst ( $ config [ 'modelo' ] ) ; if ( $ id == null ) { $ registro = $ modeloM :: first ( ) ; } elseif ( is_object ( $ id ) ) { $ registro = $ id ; $ id = $ registro -> getKey ( ) ; } else { $ registro = $ modeloM :: find ( $ id ) ; } } if ( ! CrudGenerator :: checkPermission ( $ config , $ registro -> getKey ( ) ) ) { return View :: make ( 'sirgrimorum::crudgen.error' , [ 'message' => trans ( 'crudgenerator::admin.messages.permission' ) ] ) ; } if ( $ config [ 'url' ] == "Sirgrimorum_CrudAdministrator" ) { $ config [ 'url' ] = route ( "sirgrimorum_modelo::update" , [ "modelo" => $ modelo , "registro" => $ registro -> id ] ) ; if ( \ Lang :: has ( 'crudgenerator::' . $ modelo . '.labels.edit' ) ) { $ config [ 'botones' ] = trans ( "crudgenerator::$modelo.labels.edit" ) ; } else { $ config [ 'botones' ] = trans ( "crudgenerator::admin.layout.editar" ) ; } } if ( ! $ simple ) { $ js_section = config ( "sirgrimorum.crudgenerator.js_section" ) ; $ css_section = config ( "sirgrimorum.crudgenerator.css_section" ) ; } else { $ js_section = "" ; $ css_section = "" ; } $ view = View :: make ( 'sirgrimorum::crudgen.edit' , [ 'config' => $ config , 'registro' => $ registro , 'tieneHtml' => CrudGenerator :: hasTipo ( $ config , [ 'html' , 'article' ] ) , 'tieneDate' => CrudGenerator :: hasTipo ( $ config , [ 'date' , 'datetime' , 'time' ] ) , 'tieneSlider' => CrudGenerator :: hasTipo ( $ config , 'slider' ) , 'tieneSelect' => CrudGenerator :: hasTipo ( $ config , [ 'select' , 'relationship' , 'relationships' ] ) , 'tieneSearch' => CrudGenerator :: hasTipo ( $ config , [ 'relationshipssel' ] ) , 'tieneFile' => CrudGenerator :: hasTipo ( $ config , [ 'file' , 'files' ] ) , 'tieneJson' => CrudGenerator :: hasTipo ( $ config , [ 'json' ] ) , 'js_section' => $ js_section , 'css_section' => $ css_section , 'modelo' => $ modelo ] ) ; return $ view -> render ( ) ; }
Generate de edit view of a model
23,511
public function addGroup ( $ group , $ action , $ priority = 0 ) { $ this -> assertNotFrozen ( ) ; if ( ! empty ( $ this -> initialData [ self :: GROUPS ] [ $ action ] ) ) { foreach ( $ this -> initialData [ self :: GROUPS ] [ $ action ] as $ existingGroup => $ existingPriority ) { if ( $ group !== $ existingGroup && $ priority === $ existingPriority ) { throw new \ InvalidArgumentException ( \ sprintf ( 'The priority %s cannot be used for the group "%s"' . ' because the group with this priority already exists.' . ' Existing group: "%s". Action: "%s".' , $ priority , $ group , $ existingGroup , $ action ) ) ; } } } $ this -> initialData [ self :: GROUPS ] [ $ action ] [ $ group ] = $ priority ; }
Registers a processing group .
23,512
public function addProcessor ( $ processorId , array $ attributes , $ action = null , $ group = null , $ priority = 0 ) { $ this -> assertNotFrozen ( ) ; if ( null === $ action ) { $ action = self :: NO_ACTION ; } if ( ! empty ( $ group ) ) { $ attributes [ self :: GROUP_ATTRIBUTE ] = $ group ; } $ this -> initialData [ self :: PROCESSORS ] [ $ action ] [ $ priority ] [ ] = [ $ processorId , $ attributes ] ; }
Registers a processor .
23,513
private function sortByPriorityAndFlatten ( array $ items ) { if ( ! empty ( $ items ) ) { \ krsort ( $ items ) ; $ items = \ array_merge ( ... $ items ) ; } return $ items ; }
Sorts the given groups of items by priority and returns flatten array of sorted items . The higher the priority the earlier item is added to the result array .
23,514
private static function calculatePriority ( $ processorPriority , $ groupPriority = null ) { if ( null === $ groupPriority ) { if ( $ processorPriority < 0 ) { $ processorPriority += self :: getIntervalPriority ( - 255 , - 255 ) + 1 ; } else { $ processorPriority += self :: getIntervalPriority ( 255 , 255 ) + 2 ; } } else { if ( $ groupPriority < - 255 || $ groupPriority > 255 ) { throw new \ RangeException ( \ sprintf ( 'The value %d is not valid priority of a group. It must be between -255 and 255.' , $ groupPriority ) ) ; } if ( $ processorPriority < - 255 || $ processorPriority > 255 ) { throw new \ RangeException ( \ sprintf ( 'The value %d is not valid priority of a processor. It must be between -255 and 255.' , $ processorPriority ) ) ; } } return self :: getIntervalPriority ( $ processorPriority , $ groupPriority ) ; }
Calculates an internal priority of a processor based on its priority and a priority of its group .
23,515
public function getTitle ( $ language = null ) { $ fallbackLanguage = key ( $ this -> titles ) ; if ( $ language === null ) { $ language = $ fallbackLanguage ; } if ( ! empty ( $ this -> titles [ $ language ] ) ) { return $ this -> titles [ $ language ] ; } if ( ! empty ( $ this -> titles [ $ fallbackLanguage ] ) ) { return $ this -> titles [ $ fallbackLanguage ] ; } $ title = false ; try { $ defaultUrl = $ this -> getDefaultUrl ( ) ; if ( $ defaultUrl ) { $ title = $ defaultUrl -> getHostname ( ) ; } } catch ( \ Exception $ e ) { } if ( ! $ title ) { return '(No title)' ; } return $ title ; }
Return siteroot title .
23,516
public function getSpecialTidsForLanguage ( $ language = null ) { $ specialTids = [ ] ; foreach ( $ this -> specialTids as $ specialTid ) { if ( $ specialTid [ 'language' ] === $ language || $ specialTid [ 'language' ] === null ) { $ specialTids [ $ specialTid [ 'name' ] ] = $ specialTid [ 'treeId' ] ; } } return $ specialTids ; }
Return special tids for a language .
23,517
public function getSpecialTid ( $ language , $ key ) { $ languageSpecialTids = $ this -> getSpecialTidsForLanguage ( $ language ) ; if ( ! empty ( $ languageSpecialTids [ $ key ] ) ) { return $ languageSpecialTids [ $ key ] ; } return null ; }
Return a special tid .
23,518
public function getDefaultUrl ( $ language = null ) { foreach ( $ this -> urls as $ url ) { if ( $ url -> isDefault ( ) ) { return $ url ; } } return null ; }
Return the default url .
23,519
private function makeOptions ( array $ result ) { $ options = ( null !== $ this -> options [ 'default_option' ] ) ? [ 0 => $ this -> options [ 'default_option' ] ] : [ ] ; foreach ( $ result as $ row ) { $ this -> makeOption ( $ row , $ options ) ; } return $ options ; }
Processes dataset rows as select options
23,520
private function makeOption ( $ row , & $ options ) { $ value = $ this -> propertyAccessor -> getValue ( $ row , "[{$this->options['value_column']}]" ) ; $ label = $ this -> propertyAccessor -> getValue ( $ row , "[{$this->options['label_column']}]" ) ; $ options [ $ value ] = $ label ; }
Processes single row
23,521
public function actionGetContextId ( ) { if ( false === Yii :: $ app -> request -> isAjax ) { throw new NotFoundHttpException ( Yii :: t ( 'dotplant.entity.structure' , 'Page not found' ) ) ; } Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; $ structureId = Yii :: $ app -> request -> post ( 'structure_id' ) ; return BaseStructure :: find ( ) -> select ( 'context_id' ) -> where ( [ 'id' => $ structureId ] ) -> scalar ( ) ; }
Returns context_id according to given Entity id
23,522
public function render ( AbstractContainer $ container ) { $ template = $ container -> getTemplateKey ( ) ; return $ this -> templatesManager -> renderTemplate ( $ template , array ( 'layoutRenderer' => $ this , 'container' => $ container ) ) ; }
Renders the given abstract container element and returns the html code for the given container .
23,523
public function prepare ( ) { if ( is_array ( $ this -> params [ 'items' ] ) ) { $ this -> items = array ( ) ; foreach ( $ this -> params [ 'items' ] as $ k => $ v ) { $ this -> items [ $ k ] = $ v ; } } }
Init control with start value
23,524
private static function extendTwig ( \ Twig_Environment $ twig_Environment ) { $ twig_Environment -> addFilter ( new \ Twig_SimpleFilter ( '__' , function ( $ text , $ domain = 'default' ) { return __ ( $ text , $ domain ) ; } ) ) ; $ twig_Environment -> addExtension ( new SlugifyExtension ( Slugify :: create ( ) ) ) ; }
Adds the WP - specific filters and functions to the twig environment
23,525
public function upload ( $ sourceFile , $ destinationFile ) { Service :: $ log -> msg ( 'Upload to S3 started: ' . $ sourceFile ) ; $ destinationFile = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/' . $ destinationFile ; $ this -> s3Instance -> multipartUpload ( $ this -> s3Config -> Bucket , $ destinationFile , $ sourceFile , 3 ) ; Service :: $ log -> msg ( 'Upload ended' ) ; return $ destinationFile ; }
Upload the give file to S3 .
23,526
public function moveOldBackup ( ) { Service :: $ log -> msg ( 'S3: moving old backups' ) ; $ destinationFile = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/backup-2days-old' ; if ( $ this -> s3Instance -> doesObjectExist ( $ this -> s3Config -> Bucket , $ destinationFile ) ) { $ this -> s3Instance -> deleteObject ( $ this -> s3Config -> Bucket , $ destinationFile ) ; } $ sourceFile = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/backup-1day-old' ; $ destinationFile = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/backup-2days-old' ; if ( $ this -> s3Instance -> doesObjectExist ( $ this -> s3Config -> Bucket , $ sourceFile ) ) { $ this -> s3Instance -> copyObject ( $ this -> s3Config -> Bucket , $ sourceFile , $ this -> s3Config -> Bucket , $ destinationFile ) ; } $ destinationFileTemp = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/backup-1day-old' ; if ( $ this -> s3Instance -> doesObjectExist ( $ this -> s3Config -> Bucket , $ destinationFileTemp ) ) { $ this -> s3Instance -> deleteObject ( $ this -> s3Config -> Bucket , $ destinationFileTemp ) ; } Service :: $ log -> msg ( 'S3: moving old backups done' ) ; return $ destinationFile ; }
Moves around the current backups on S3 and does some cleanup before new backups are created .
23,527
public function deleteBackup ( $ backupName ) { Service :: $ log -> msg ( 'S3: deleting backup ' . $ backupName ) ; $ destinationFile = rtrim ( $ this -> s3Config -> RemotePath , '/' ) . '/' . $ backupName ; if ( $ this -> s3Instance -> doesObjectExist ( $ this -> s3Config -> Bucket , $ destinationFile ) ) { $ this -> s3Instance -> deleteObject ( $ this -> s3Config -> Bucket , $ destinationFile ) ; } Service :: $ log -> msg ( 'S3: backup deleted ' . $ backupName ) ; }
Deletes a given backup from the S3 bucket .
23,528
public function findRoleNamesByUserId ( $ userId ) { $ query = $ this -> getSqlObject ( ) -> select ( ) -> join ( 'user_roles' , 'user_roles.id = pvt_roles_users.role_id' , [ 'name' ] ) -> where ( [ 'user_id' => $ userId ] ) ; $ results = $ this -> execute ( $ query ) -> toArray ( ) ; return Arr :: pluck ( $ results , 'name' ) ; }
Find roles for a user by user ID
23,529
public function addRoleForUser ( $ userId , $ roleName ) { $ roleIdExpression = new Expression ( '(SELECT `id` from `user_roles` WHERE `name` = ?)' , $ roleName ) ; $ query = $ this -> getSqlObject ( ) -> insert ( ) -> values ( [ 'user_id' => $ userId , 'role_id' => $ roleIdExpression , ] ) ; $ this -> execute ( $ query ) ; }
Add a given role to the given user id
23,530
public function setup ( Model $ model , $ config = [ ] ) { if ( ! isset ( $ this -> settings [ $ model -> alias ] ) ) { $ this -> settings [ $ model -> alias ] = [ 'pluginName' => null , 'checkPath' => null , 'configFile' => null , 'path' => null , ] ; } $ this -> settings [ $ model -> alias ] = array_merge ( $ this -> settings [ $ model -> alias ] , $ config ) ; extract ( $ this -> settings [ $ model -> alias ] ) ; $ this -> _initConfig = new InitConfig ( $ pluginName , $ checkPath , $ configFile ) ; if ( ! empty ( $ path ) ) { $ this -> _initConfig -> path = $ path ; } $ this -> _initConfig -> initConfig ( ) ; }
Setup this behavior with the specified configuration settings .
23,531
public function showCategory ( $ category , $ pagenumber = 1 ) { if ( ! $ this -> category -> exists ( $ category ) ) { return \ Response :: view ( $ this -> theme . '.404' , array ( 'global' => $ this -> global ) , 404 ) ; } $ categoryObject = $ this -> category -> getCategory ( $ category ) ; $ parent = $ this -> category -> getParentCategory ( $ category ) ; $ subCategories = $ this -> category -> getSubCategories ( $ category ) ; $ posts = $ this -> post -> getAll ( $ category ) ; $ viewParamaters = array ( 'global' => $ this -> global , 'category' => $ categoryObject , 'parent' => $ parent , 'subCategories' => $ subCategories , 'posts' => $ posts , 'pageNumber' => $ pagenumber ) ; return \ View :: make ( $ this -> theme . '.category' , $ viewParamaters ) ; }
Show a category .
23,532
public static function after ( $ subject , $ search ) { if ( $ search == '' ) { return $ subject ; } $ pos = strpos ( $ subject , $ search ) ; if ( $ pos === false ) { return $ subject ; } return substr ( $ subject , $ pos + strlen ( $ search ) ) ; }
Return the remainder of a string after a given value .
23,533
public static function flatten ( $ array ) { $ is_assoc = Arr :: isAssoc ( $ array ) ; $ flat = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ flat = array_merge ( $ flat , Arr :: flatten ( $ value ) ) ; } else { if ( $ is_assoc ) { $ flat [ $ key ] = $ value ; } else { $ flat [ ] = $ value ; } } } return $ flat ; }
Convert a multi - dimensional array into a single - dimensional array .
23,534
public function resolveName ( $ securityType , $ securityId ) { if ( $ securityType !== $ this -> userClass ) { return null ; } return $ this -> userManager -> find ( $ securityId ) -> getDisplayName ( ) ; }
Return security name .
23,535
public function getAll ( $ query , $ limit , $ offset ) { $ users = $ this -> userManager -> findBy ( array ( ) , array ( 'lastname' => 'ASC' ) , $ limit , $ offset ) ; $ data = array ( ) ; foreach ( $ users as $ user ) { $ data [ ] = array ( 'securityType' => get_class ( $ user ) , 'securityId' => $ user -> getId ( ) , 'securityName' => $ user -> getDisplayName ( ) , ) ; } return array ( 'total' => $ this -> userManager -> countAll ( ) , 'data' => $ data , ) ; }
Return users .
23,536
public function insertAfter ( $ value , $ afterKey ) { $ chunk = $ this -> splice ( $ afterKey + 1 ) ; return $ this -> items = $ this -> put ( $ afterKey + 1 , $ value ) -> merge ( $ chunk ) -> all ( ) ; }
Insert into a collection after the given key .
23,537
public function orderBy ( $ fields , $ direction = false ) { $ this -> orderBy -> addFields ( $ fields , $ direction ) ; return $ this ; }
Sets the order for the query .
23,538
public function restoreState ( ) { if ( $ activeCountry = $ this -> sessionState -> getByKey ( self :: ACTIVE_COUNTRY_KEY ) ) { $ this -> activeCountry = $ activeCountry ; } }
Uses the State service to retrieve the active country s identifier and sets the active country .
23,539
public function getCountry ( IdentifierInterface $ identifier ) { $ identifierFull = $ identifier -> getFull ( ) ; return isset ( $ this -> countries [ $ identifierFull ] ) ? $ this -> countries [ $ identifierFull ] : null ; }
Uses the identifier to retrieve the country object from the cache
23,540
protected function checkAttribute ( $ attribute ) { if ( ! defined ( $ attribute ) ) { throw new LogicException ( Message :: get ( Message :: DB_ATTRIBUTE_UNKNOWN , $ attribute ) , Message :: DB_ATTRIBUTE_UNKNOWN ) ; } }
Is attribute defined ?
23,541
public static function size ( string $ name , int $ size = 12 ) { $ instance = new static ( ) ; $ instance -> group [ 'name' ] = $ name ; $ instance -> group [ 'size' ] = $ size ; return $ instance ; }
Set the display column width of the group
23,542
public function repeater ( string $ key ) { $ this -> key ( $ key ) ; $ this -> group [ 'repeater' ] = true ; return $ this ; }
Defined a sub - group as a repeater group and assigns a key for saving
23,543
public function addField ( Field ... $ fields ) { collect ( $ fields ) -> map ( function ( $ field ) { $ this -> group [ 'fields' ] -> put ( $ field -> key ( ) , $ field -> get ( ) ) ; } ) ; return $ this ; }
Add fields to the current group . Accepts a comma separated list of Fields
23,544
public function addGroup ( Group ... $ groups ) { collect ( $ groups ) -> map ( function ( $ group ) { $ this -> group [ 'groups' ] [ ] = $ group -> get ( ) ; } ) ; return $ this ; }
Sub - groups are used to define collections of repeatable fields which can be inserted deleted and re - ordered by the user .
23,545
public function addClass ( $ className ) { if ( ! is_numeric ( array_search ( $ className , $ this -> classes ) ) ) { $ this -> classes [ ] = $ className ; return true ; } return false ; }
Applique une nouvelle classe CSS
23,546
public function addAttribute ( $ attributeName , $ attributeValue ) { if ( ! array_key_exists ( $ attributeName , $ this -> attributes ) ) { $ this -> attributes [ $ attributeName ] = $ attributeValue ; return true ; } return false ; }
Ajoute un nouvel attribut
23,547
public function replaceMagicFields ( $ html ) { $ html = str_replace ( '%id%' , $ this -> getId ( ) , $ html ) ; $ html = str_replace ( '%class%' , implode ( ' ' , $ this -> classes ) , $ html ) ; $ html = str_replace ( '%style%' , $ this -> getStyle ( ) , $ html ) ; $ strAttributes = '' ; foreach ( $ this -> attributes as $ key => $ value ) { $ strAttributes .= ' ' . $ key . '="' . $ value . '"' ; } $ html = str_replace ( '%attributes%' , $ strAttributes , $ html ) ; return $ html ; }
Remplace les champs magiques des assets - concernant uniquement les champs magiques des composants de type UI
23,548
public static function buildQueryString ( array $ data = null , $ urlEncode = true ) { if ( $ data === null ) { $ data = static :: $ get ; } $ query = [ ] ; foreach ( $ data as $ name => $ value ) { $ query [ ] = "{$name}=" . ( $ urlEncode ? urlencode ( $ value ) : $ value ) ; } if ( count ( $ query ) ) { return '?' . implode ( '&' , $ query ) ; } }
Builds a query string including the question mark .
23,549
protected function getAllHeaders ( ) { $ headers = [ ] ; foreach ( $ _SERVER as $ key => $ value ) { if ( substr ( $ key , 0 , 5 ) == 'HTTP_' ) { $ key = substr ( $ key , 5 ) ; $ key = str_replace ( '_' , ' ' , strtolower ( $ key ) ) ; $ key = str_replace ( ' ' , '-' , ucwords ( $ key ) ) ; $ headers [ $ key ] = $ value ; } } return $ headers ; }
Gets headers from _SERVER and formats the names nicely .
23,550
protected function migrationsToRun ( ) { $ path = APPDIR . '/src/' . str_replace ( '\\' , '/' , $ this -> migrationNamespace ) ; if ( ! is_dir ( $ path ) ) { return [ ] ; } $ dir = new DirectoryIterator ( $ path ) ; $ migrations = [ ] ; foreach ( $ dir as $ file ) { if ( ! $ file -> isFile ( ) or substr ( $ file -> getBasename ( ) , 0 , 1 ) === '.' ) { continue ; } $ class = $ this -> migrationNamespace . $ file -> getBasename ( '.php' ) ; $ migrations [ ] = new $ class ; } $ alreadyExecutedMigrations = $ this -> alreadyExecutedMigrations ( ) ; $ migrationsToRun = [ ] ; foreach ( $ migrations as $ migration ) { $ compare = new ArrayObject ( [ 'description' => $ migration -> getDescription ( ) , 'timestamp' => $ migration -> getTimestamp ( ) , ] ) ; if ( in_array ( $ compare , $ alreadyExecutedMigrations ) ) { continue ; } $ migrationsToRun [ ] = $ migration ; } return $ migrationsToRun ; }
Determine all migrations that have not yet been run on the database
23,551
protected function recordMigration ( AbstractMigration $ migration ) { $ query = 'INSERT INTO `app_migrations` (`timestamp`, `description`) VALUES ("%s", "%s")' ; $ query = sprintf ( $ query , $ migration -> getTimestamp ( ) , $ migration -> getDescription ( ) ) ; $ this -> db -> query ( $ query , DbAdapter :: QUERY_MODE_EXECUTE ) ; }
Insert a record into app_migrations to record that this migration was run
23,552
protected function alreadyExecutedMigrations ( ) { $ results = $ this -> db -> query ( 'SELECT * FROM `app_migrations`' , DbAdapter :: QUERY_MODE_EXECUTE ) ; return ( array ) iterator_to_array ( $ results , true ) ; }
Return array of already executed migrations .
23,553
public function getAdjoinMatrix ( ) : Matrix { $ matrix = new static ( ) ; for ( $ i = 0 ; $ i < static :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < static :: COLUMNS ; $ j ++ ) { $ subMatrix = MatrixMath :: getSubMatrix ( $ this -> toArray ( ) , $ i , $ j ) ; $ matrix [ $ i ] [ $ j ] = MatrixMath :: calculateDeterminant ( $ subMatrix ) ; } } return $ matrix ; }
Get the minors matrix of the matrix .
23,554
public function transpose ( ) { $ cpy = new static ( ) ; $ cpy -> copy ( $ this ) ; for ( $ i = 0 ; $ i < static :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < static :: COLUMNS ; $ j ++ ) { $ this [ $ i ] [ $ j ] = $ cpy [ $ j ] [ $ i ] ; } } }
Transpose the matrix .
23,555
public function inverse ( ) { $ determinant = $ this -> determinant ( ) ; if ( $ determinant == 0 ) { return ; } $ adj = $ this -> getAdjoinMatrix ( ) ; for ( $ i = 0 ; $ i < static :: ROWS ; $ i ++ ) { $ sign = ( $ i % 2 === 1 ) ? - 1 : 1 ; for ( $ j = 0 ; $ j < static :: COLUMNS ; $ j ++ ) { $ adj [ $ i ] [ $ j ] = $ sign * $ adj [ $ i ] [ $ j ] ; $ sign = - $ sign ; } } $ this -> copy ( $ adj ) ; $ this -> transpose ( ) ; $ div = 1 / $ determinant ; $ this -> mul ( $ div ) ; }
Inverse the matrix .
23,556
protected function copy ( Matrix $ matrix ) { for ( $ i = 0 ; $ i < static :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < static :: COLUMNS ; $ j ++ ) { $ this -> vectors [ $ i ] [ $ j ] = $ matrix [ $ i ] [ $ j ] ; } } }
Copy the matrix to another matrix .
23,557
public function template_fallback ( $ template , $ template_name , $ template_path ) { if ( ! file_exists ( $ template ) ) { $ fallback = self :: root_dir ( ) . '/templates/' . $ template_name ; if ( file_exists ( $ fallback ) ) { $ template = $ fallback ; } } return $ template ; }
Add hametwoo dir to template .
23,558
public function send_mail ( $ mail_id , $ arguments = [ ] ) { $ mailers = WC ( ) -> mailer ( ) -> get_emails ( ) ; foreach ( $ mailers as $ mailer ) { if ( $ mail_id == $ mailer -> id ) { if ( $ arguments ) { call_user_func_array ( [ $ mailer , 'trigger' ] , $ arguments ) ; } else { $ mailer -> trigger ( ) ; } } } }
Send email short hand .
23,559
public static function addressesGet ( $ addresses ) { $ return = array ( ) ; if ( ! is_array ( $ addresses ) ) { $ addresses = self :: addressParse ( $ addresses ) ; } foreach ( $ addresses as $ k => $ v ) { if ( is_array ( $ v ) ) { if ( ! empty ( $ v [ 'name' ] ) ) { $ return [ $ v [ 'email' ] ] = $ v [ 'name' ] ; } else { $ return [ ] = $ v [ 'email' ] ; } } elseif ( is_int ( $ k ) ) { $ v = self :: addressParse ( $ v ) ; $ v = array_shift ( $ v ) ; if ( ! empty ( $ v [ 'name' ] ) ) { $ return [ $ v [ 'email' ] ] = $ v [ 'name' ] ; } else { $ return [ ] = $ v [ 'email' ] ; } } else { $ return [ $ k ] = $ v ; } } return $ return ; }
Get address array from passed address string or addresses
23,560
public static function addressBuildString ( $ addresses ) { $ addresses = self :: addressesGet ( $ addresses ) ; $ addressesNew = array ( ) ; foreach ( $ addresses as $ k => $ v ) { $ name = null ; if ( is_int ( $ k ) ) { $ address = $ v ; } else { $ name = $ v ; $ address = $ k ; } if ( ! isset ( $ _SERVER [ 'WINDIR' ] ) && $ name ) { if ( strpos ( $ name , ',' ) ) { $ name = addcslashes ( $ name , '()' ) ; $ name = '"' . $ name . '"' ; } $ address = $ name . ' <' . $ address . '>' ; } $ addressesNew [ ] = $ address ; } return implode ( ', ' , $ addressesNew ) ; }
Returns email address string
23,561
public static function addressParse ( $ addressString ) { $ pattern = '/^(?:"?((?:[^"\\\\]|\\\\.)+)"?\s)?' . '<?([a-z0-9._%-]+@[a-z0-9.-]+\\.[a-z]{2,4})>?$/i' ; $ addresses = str_getcsv ( $ addressString ) ; $ result = array ( ) ; foreach ( $ addresses as $ address ) { $ address = trim ( $ address ) ; if ( preg_match ( $ pattern , $ address , $ matches ) ) { $ item = array ( ) ; if ( $ matches [ 1 ] != '' ) { $ item [ 'name' ] = stripcslashes ( $ matches [ 1 ] ) ; } $ item [ 'email' ] = $ matches [ 2 ] ; $ result [ ] = $ item ; } } return $ result ; }
parse address string
23,562
public static function addressValidate ( $ email ) { $ return = false ; $ regex = '/^' . '[a-z0-9_]+([_\.-][a-z0-9]+)*' . '@' . '([a-z0-9]+([\.-][a-z0-9]+)*)+' . '(\.[a-z]{2,})' . '$/i' ; $ email = trim ( $ email ) ; if ( preg_match ( $ regex , $ email , $ matches ) ) { $ hostname = strtolower ( $ matches [ 2 ] . $ matches [ 4 ] ) ; $ ipaddress = gethostbyname ( $ hostname ) ; $ return = $ email ; if ( $ ipaddress != $ hostname ) { } elseif ( $ mxrecord = getmxrr ( $ hostname , $ mxhosts ) ) { } elseif ( strpos ( $ _SERVER [ 'SERVER_NAME' ] , $ hostname ) ) { } else { $ return = false ; } } return $ return ; }
validate an email addrses
23,563
public function setDirectOnly ( $ value ) { if ( $ value !== null ) { if ( $ value == true ) { $ this -> _params [ 'directOnly' ] = 'true' ; } else { $ this -> _params [ 'directOnly' ] = 'false' ; } } else { unset ( $ this -> _params [ 'directOnly' ] ) ; } }
Sets the query parameter directOnly
23,564
public static function getReasonPhraseByCode ( $ code ) { if ( isset ( self :: $ codesDescription [ $ code ] ) ) { return self :: $ codesDescription [ $ code ] ; } $ group = self :: getGroupFromCode ( $ code ) ; return self :: getReasonPhraseByGroup ( $ group ) ; }
Provides description for IANA registered HTTP codes . If not registered code was specified respective group description is returned .
23,565
protected function fromBinaryString ( $ str ) { if ( ! ( \ is_string ( $ str ) && \ preg_match ( '/^[01]+$/' , $ str ) ) ) { throw new \ InvalidArgumentException ( '$str is not a binary string' ) ; } for ( $ i = 0 , $ l = \ strlen ( $ str ) ; $ i < $ l ; ++ $ i ) { $ this -> _List -> pushFront ( $ str [ $ i ] === '1' ? true : false ) ; } }
Sets bits from a binary string
23,566
public function flip ( $ pos = null ) { if ( \ is_int ( $ pos ) ) { $ this -> _List [ $ pos ] = ! $ this -> _List [ $ pos ] ; } else { $ this -> _List = $ this -> _List -> map ( function ( $ v ) { return ! $ v ; } ) ; } }
Flips all bits or one specific bit by position
23,567
public function logicalAnd ( self $ other ) { $ l = \ max ( array ( $ this -> count ( ) , $ other -> count ( ) ) ) ; $ new = new static ( ) ; for ( $ i = 0 ; $ i < $ l ; ++ $ i ) { $ new [ $ i ] = isset ( $ this [ $ i ] , $ other [ $ i ] ) ? ( $ this [ $ i ] && $ other [ $ i ] ) : false ; } return $ new ; }
Returns a new BitSet after ANDing this set with another
23,568
public function logicalOr ( self $ other ) { $ l = \ max ( array ( $ this -> count ( ) , $ other -> count ( ) ) ) ; $ new = new static ( ) ; for ( $ i = 0 ; $ i < $ l ; ++ $ i ) { if ( isset ( $ this [ $ i ] ) && $ other [ $ i ] ) { $ new [ $ i ] = true ; } else if ( isset ( $ other [ $ i ] ) && $ other [ $ i ] ) { $ new [ $ i ] = true ; } else { $ new [ $ i ] = false ; } } return $ new ; }
Returns a new BitSet after ORing this set with another
23,569
public function logicalXor ( self $ other ) { $ l = \ max ( array ( $ this -> count ( ) , $ other -> count ( ) ) ) ; $ new = new static ( ) ; for ( $ i = 0 ; $ i < $ l ; ++ $ i ) { if ( isset ( $ this [ $ i ] , $ other [ $ i ] ) ) { $ new [ $ i ] = ( bool ) ( $ this [ $ i ] ^ $ other [ $ i ] ) ; } else { $ new [ $ i ] = false ; } } return $ new ; }
Returns a new BitSet after XORing this set with another
23,570
public function reset ( $ pos = null ) { if ( \ is_int ( $ pos ) ) { $ this -> offsetSet ( $ pos , false ) ; } else { $ this -> _List = ArrayList :: repeat ( false , $ this -> count ( ) ) ; } }
Resets all bits or one specific bit by position
23,571
public function set ( $ pos , $ value ) { if ( ! \ is_bool ( $ value ) ) { throw new \ InvalidArgumentException ( '$value is not a bool' ) ; } $ this -> offsetSet ( $ pos , $ value ) ; }
Sets a specific bit
23,572
protected function minimizeResource ( string $ resource , ? string $ fullPathName ) : string { if ( isset ( $ fullPathName ) ) { $ css = $ this -> convertRelativePaths ( $ resource , $ fullPathName ) ; list ( $ std_out , $ std_err ) = $ this -> runProcess ( $ this -> minifyCommand , $ css ) ; if ( $ std_err ) $ this -> logInfo ( $ std_err ) ; $ ret = $ std_out ; } else { $ ret = $ resource ; } return $ ret ; }
Minimizes CSS code .
23,573
private function convertRelativePaths ( $ css , $ fullPathName ) { $ lines = explode ( "\n" , $ css ) ; $ lines = preg_replace_callback ( '/(url\([\'"]?)(([^()]|(?R))+)([\'"]?\))/i' , function ( $ matches ) use ( $ fullPathName ) { return $ matches [ 1 ] . Url :: combine ( $ this -> getPathInResources ( $ fullPathName ) , $ matches [ 2 ] ) . $ matches [ 4 ] ; } , $ lines ) ; if ( $ lines === null ) { $ this -> logError ( "Converting relative paths failed for '%s'" , $ fullPathName ) ; } return implode ( "\n" , $ lines ) ; }
In CSS code replace relative paths with absolute paths .
23,574
protected function find ( $ fileName ) { $ fileName = $ fileName . '.' . $ this -> fileExtension ; foreach ( $ this -> viewPaths as $ path ) { if ( file_exists ( $ path . $ fileName ) ) { return realpath ( $ path . $ fileName ) ; } } throw new \ Exception ( "View $fileName not found." ) ; }
Locates a view file and returns its full path .
23,575
protected function sign ( $ msg , $ key , $ method = 'HS256' ) { if ( empty ( self :: $ methods [ $ method ] ) ) { throw new \ DomainException ( 'Algorithm not supported' ) ; } list ( $ function , $ algo ) = self :: $ methods [ $ method ] ; switch ( $ function ) { case 'hash_hmac' : return hash_hmac ( $ algo , $ msg , $ key , true ) ; case 'openssl' : $ signature = '' ; $ success = openssl_sign ( $ msg , $ signature , $ key , $ algo ) ; if ( ! $ success ) { throw new \ DomainException ( "OpenSSL unable to sign data" ) ; } return $ signature ; } return '' ; }
Sign a string with a given key and algorithm .
23,576
protected function verifySignature ( $ msg , $ signature , $ key , $ method = 'HS256' ) { if ( empty ( self :: $ methods [ $ method ] ) ) { throw new \ DomainException ( 'Algorithm not supported' ) ; } list ( $ function , $ algo ) = self :: $ methods [ $ method ] ; switch ( $ function ) { case 'openssl' : $ success = openssl_verify ( $ msg , $ signature , $ key , $ algo ) ; if ( ! $ success ) { throw new \ DomainException ( "OpenSSL unable to verify data: " . openssl_error_string ( ) ) ; } return $ signature ; case 'hash_hmac' : default : return $ signature === hash_hmac ( $ algo , $ msg , $ key , true ) ; } }
Verify a signature with the mesage key and method . Not all methods are symmetric so we must have a separate verify and sign method .
23,577
public function findForSearchFilter ( ProductFilter $ filter , OrderCollection $ orderCollection = null ) { $ qb = $ this -> getEntityManager ( ) -> createQueryBuilder ( ) -> from ( 'HarvestCloudCoreBundle:Product' , 'p' ) -> select ( 'p' ) -> addSelect ( 'GEO(p.latitude = :latitude, p.longitude = :longitude) AS distance' ) -> setParameter ( 'latitude' , $ filter -> getLatitude ( ) ) -> setParameter ( 'longitude' , $ filter -> getLongitude ( ) ) -> orderBy ( 'distance' ) -> setMaxResults ( 20 ) ; if ( $ filter -> getRange ( ) ) { $ qb -> where ( 'GEO(p.latitude = :latitude, p.longitude = :longitude) <= :range' ) ; $ qb -> setParameter ( 'range' , $ filter -> getRange ( ) ) ; } if ( $ filter -> getCategory ( ) ) { $ qb -> join ( 'p.category' , 'c' ) ; $ qb -> andWhere ( 'c.lft >= :lft' ) ; $ qb -> andWhere ( 'c.rgt <= :rgt' ) ; $ qb -> setParameter ( 'lft' , $ filter -> getCategory ( ) -> getLft ( ) ) ; $ qb -> setParameter ( 'rgt' , $ filter -> getCategory ( ) -> getRgt ( ) ) ; } $ qb -> andWhere ( 'p.quantity_available > 0' ) ; $ q = $ qb -> getQuery ( ) ; $ products = $ q -> execute ( ) ; if ( $ orderCollection ) { $ lineItemQuantities = $ orderCollection -> getLineItemQuantitiesIndexedByProductId ( ) ; foreach ( $ products as $ product ) { $ id = $ product [ 0 ] -> getId ( ) ; if ( array_key_exists ( $ id , $ lineItemQuantities ) ) { $ product [ 0 ] -> setQuantityInCart ( $ lineItemQuantities [ $ id ] ) ; } } } return $ products ; }
Find Products for a given filter
23,578
public function BaseGeoProductQuery ( LatLng $ latLng ) { $ products = $ this -> getEntityManager ( ) -> createQueryBuilder ( ) -> from ( 'HarvestCloudCoreBundle:Product' , 'p' ) -> select ( 'p' ) -> addSelect ( 'GEO(p.latitude = :latitude, p.longitude = :longitude) AS distance' ) -> setParameter ( 'latitude' , $ latitude ) -> setParameter ( 'longitude' , $ longitude ) -> orderBy ( 'distance' ) -> where ( 'GEO(p.latitude = :latitude, p.longitude = :longitude) <= 50' ) -> getQuery ( ) -> execute ( ) ; return $ products ; }
Base Geographical Product Query
23,579
private function getDeploymentConfig ( ) { if ( ! $ this -> deploymentConfig instanceof \ Magento \ Framework \ App \ DeploymentConfig ) { $ this -> deploymentConfig = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) -> get ( 'Magento\Framework\App\DeploymentConfig' ) ; } return $ this -> deploymentConfig ; }
Get deployment config
23,580
protected function processApiRequest ( ) { $ inputParams = $ this -> getInputParamsResolver ( ) -> resolve ( ) ; $ route = $ this -> getInputParamsResolver ( ) -> getRoute ( ) ; $ serviceMethodName = $ route -> getServiceMethod ( ) ; $ serviceClassName = $ route -> getServiceClass ( ) ; $ service = $ this -> _objectManager -> get ( $ serviceClassName ) ; $ outputData = call_user_func_array ( [ $ service , $ serviceMethodName ] , $ inputParams ) ; $ outputData = $ this -> serviceOutputProcessor -> process ( $ outputData , $ serviceClassName , $ serviceMethodName ) ; $ filters = $ this -> getFilters ( ) ; if ( $ filters && is_array ( $ outputData ) ) { foreach ( $ filters as $ filterClassName ) { $ outputData = $ this -> applyFilter ( $ filterClassName , $ outputData ) ; } } $ header = $ this -> getDeploymentConfig ( ) -> get ( ConfigOptionsListConstants :: CONFIG_PATH_X_FRAME_OPT ) ; if ( $ header ) { $ this -> _response -> setHeader ( 'X-Frame-Options' , $ header ) ; } $ this -> _response -> prepareResponse ( $ outputData ) ; }
Execute API request
23,581
private function getInputParamsResolver ( ) { if ( $ this -> inputParamsResolver === null ) { $ this -> inputParamsResolver = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) -> get ( \ Magento \ Webapi \ Controller \ Rest \ InputParamsResolver :: class ) ; } return $ this -> inputParamsResolver ; }
The getter function to get InputParamsResolver object
23,582
public function php_error_handler ( $ errno , $ errstr , $ errfile , $ errline ) { $ e = new \ Exception ( $ errstr , $ errno ) ; call_user_func ( $ this -> error50x , $ e ) ; }
Wrapper that converts PHP errors to exceptions and passes them to the standard error50x handler .
23,583
public function setPrefix ( $ prefix ) { if ( $ prefix != "" ) { if ( $ prefix [ 0 ] != '/' ) { $ prefix = '/' . $ prefix ; } if ( $ prefix [ strlen ( $ prefix ) - 1 ] == '/' ) { $ prefix = substr ( $ prefix , 0 , strlen ( $ prefix ) - 1 ) ; } } $ this -> prefix = $ prefix ; return $ this ; }
Changes the URL prefix to work from .
23,584
function serve ( array $ urls ) { $ _SESSION [ 'toto' ] = 'prout' ; $ response = null ; set_error_handler ( array ( $ this , 'php_error_handler' ) , E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR ) ; try { $ handler = $ this -> route ( $ urls ) ; $ response = $ this -> process ( $ handler ) ; $ this -> display ( $ response ) ; } catch ( HttpRedirect $ r ) { $ response = Injector :: give ( 'Response' ) ; $ response -> setHeader ( 'Location' , $ r -> getUrl ( ) ) ; } catch ( HTTPClientError $ e ) { $ response = call_user_func ( $ this -> error40x , $ e ) ; } catch ( HTTPServerError $ e ) { $ response = call_user_func ( $ this -> error50x , $ e ) ; } catch ( HTTPStatus $ s ) { $ response = Injector :: give ( 'Response' , $ s -> getMessage ( ) , $ s -> getCode ( ) ) ; } catch ( \ Exception $ e ) { $ response = call_user_func ( $ this -> error50x , $ e ) ; } }
Serves the requests .
23,585
protected function display ( $ response ) { if ( $ response -> alteredSession ( ) ) { $ this -> request -> setAllSession ( $ response -> getAllSession ( ) ) ; } if ( $ response -> alteredCookies ( ) ) { $ this -> request -> setAllCookies ( $ response -> getAllCookies ( ) ) ; } $ this -> request -> commitSessionAndCookies ( ) ; if ( is_object ( $ response ) ) { $ response -> compile ( ) ; } else { echo $ response ; } }
Processes the returned object from a handler .
23,586
protected function route ( array $ urls ) { $ path = $ this -> server -> getRoute ( ) ; $ call = false ; $ matches = array ( ) ; $ method_routes = preg_grep ( '/^' . $ this -> server -> getMethod ( ) . ':/i' , array_keys ( $ urls ) ) ; foreach ( $ method_routes as $ route ) { $ method = $ this -> server -> getMethod ( ) . ':' ; $ clean_route = substr ( $ route , strlen ( $ method ) ) ; if ( preg_match ( '%^' . $ clean_route . '/?$%i' , $ this -> server -> getRoute ( ) , $ matches ) ) { $ call = $ urls [ $ route ] ; break ; } } if ( ! $ call ) { foreach ( $ urls as $ regex => $ proto ) { if ( preg_match ( '%^' . $ regex . '/?$%i' , $ this -> server -> getRoute ( ) , $ matches ) ) { $ call = $ proto ; break ; } } } if ( ! $ call ) { throw new NoRouteException ( "URL, " . $ this -> server -> getWholeRoute ( ) . ", not found." ) ; } return array ( 'call' => $ call , 'params' => $ matches ) ; }
Does the actual URL routing .
23,587
public static function parse ( string $ uri ) : Uri { preg_match ( static :: URI_PATTERN , $ uri , $ matches ) ; $ components = static :: componentsFromMatches ( $ matches ) ; $ scheme = $ components [ 'scheme' ] ; $ authority = $ components [ 'authority' ] ; $ path = $ components [ 'path' ] ; $ query = $ components [ 'query' ] ; $ fragment = $ components [ 'fragment' ] ; return new static ( $ path , $ scheme , $ authority , $ query , $ fragment ) ; }
Creates instance from a URI string
23,588
public static function resolve ( $ base , string $ reference , bool $ strict = true ) : Uri { if ( ! ( $ base instanceof self ) ) { $ base = static :: parse ( $ base ) ; } preg_match ( static :: URI_PATTERN , $ reference , $ matches ) ; $ ref = static :: componentsFromMatches ( $ matches ) ; if ( ! $ strict && ( $ ref [ 'scheme' ] !== null && $ base -> scheme ( ) === $ ref [ 'scheme' ] ) ) { $ ref [ 'scheme' ] = null ; } if ( $ ref [ 'scheme' ] !== null ) { $ scheme = $ ref [ 'scheme' ] ; $ authority = $ ref [ 'authority' ] ; $ path = static :: removeDotSegments ( $ ref [ 'path' ] ) ; $ query = $ ref [ 'query' ] ; } else { $ segments = explode ( '/' , trim ( $ ref [ 'path' ] , '/' ) ) ; if ( isset ( $ segments [ 0 ] ) && strpos ( $ segments [ 0 ] , ':' ) !== false ) { $ message = sprintf ( 'First segment in reference (%s) cannot contain a colon (":")' , $ reference ) ; throw new DomainException ( $ message ) ; } if ( $ ref [ 'authority' ] !== null ) { $ authority = $ ref [ 'authority' ] ; $ path = static :: removeDotSegments ( $ ref [ 'path' ] ) ; $ query = $ ref [ 'query' ] ; } else { if ( $ ref [ 'path' ] === '' ) { $ path = $ base -> path ( ) ; if ( $ ref [ 'query' ] !== null ) { $ query = $ ref [ 'query' ] ; } else { $ query = $ base -> query ( ) ; } } else { if ( $ ref [ 'path' ] [ 0 ] === '/' ) { $ path = static :: removeDotSegments ( $ ref [ 'path' ] ) ; } else { $ path = static :: mergePaths ( $ base , $ ref [ 'path' ] ) ; $ path = static :: removeDotSegments ( $ path ) ; } $ query = $ ref [ 'query' ] ; } $ authority = $ base -> authority ( ) ; } $ scheme = $ base -> scheme ( ) ; } $ fragment = $ ref [ 'fragment' ] ; return new static ( $ path , $ scheme , $ authority , $ query , $ fragment ) ; }
Creates instance from a base URI and relative reference
23,589
public static function fromArray ( array $ components ) : Uri { $ scheme = $ components [ 'scheme' ] ?? null ; $ authority = $ components [ 'authority' ] ?? null ; $ path = $ components [ 'path' ] ?? '' ; $ query = $ components [ 'query' ] ?? null ; $ fragment = $ components [ 'fragment' ] ?? null ; return new static ( $ path , $ scheme , $ authority , $ query , $ fragment ) ; }
Creates instance from components
23,590
public function display ( ) : string { $ output = sprintf ( '%s:' , $ this -> scheme ) ; if ( $ this -> authority !== null ) { $ output .= sprintf ( '//%s' , $ this -> host ) ; if ( $ this -> port !== null ) { $ output .= sprintf ( ':%d' , $ this -> port ) ; } } $ output .= $ this -> path ; if ( $ this -> query !== null ) { $ output .= sprintf ( '?%s' , $ this -> query ) ; } if ( $ this -> fragment !== null ) { $ output .= sprintf ( '#%s' , $ this -> fragment ) ; } return $ output ; }
Retrieves string representation without user info
23,591
protected static function componentsFromMatches ( array $ matches ) : array { if ( isset ( $ matches [ 2 ] ) && $ matches [ 2 ] ) { $ scheme = $ matches [ 1 ] ?? '' ; } else { $ scheme = null ; } if ( isset ( $ matches [ 3 ] ) && $ matches [ 3 ] ) { $ authority = $ matches [ 4 ] ?? '' ; } else { $ authority = null ; } $ path = $ matches [ 5 ] ?? '' ; if ( isset ( $ matches [ 6 ] ) && $ matches [ 6 ] ) { $ query = $ matches [ 7 ] ?? '' ; } else { $ query = null ; } if ( isset ( $ matches [ 8 ] ) && $ matches [ 8 ] ) { $ fragment = $ matches [ 9 ] ?? '' ; } else { $ fragment = null ; } return [ 'scheme' => $ scheme , 'authority' => $ authority , 'path' => $ path , 'query' => $ query , 'fragment' => $ fragment ] ; }
Exchanges URI_PATTERN matches for components
23,592
protected static function parseAuthority ( ? string $ authority ) : array { if ( $ authority === null ) { return [ 'userInfo' => null , 'host' => null , 'port' => null ] ; } preg_match ( static :: AUTHORITY_PATTERN , $ authority , $ matches ) ; $ userInfo = isset ( $ matches [ 1 ] ) && $ matches [ 1 ] ? $ matches [ 1 ] : null ; $ host = isset ( $ matches [ 2 ] ) && $ matches [ 2 ] ? $ matches [ 2 ] : '' ; $ port = isset ( $ matches [ 3 ] ) && $ matches [ 3 ] ? ( ( int ) $ matches [ 3 ] ) : null ; return [ 'userInfo' => $ userInfo , 'host' => $ host , 'port' => $ port ] ; }
Parses authority component into parts
23,593
protected static function buildAuthority ( ? string $ userInfo , ? string $ host , ? int $ port ) : ? string { if ( $ host === null ) { return null ; } $ authority = '' ; if ( $ userInfo !== null ) { $ authority .= sprintf ( '%s@' , $ userInfo ) ; } $ authority .= $ host ; if ( $ port !== null ) { $ authority .= sprintf ( ':%d' , $ port ) ; } return $ authority ; }
Builds authority from parts
23,594
protected static function normalizeScheme ( ? string $ scheme ) : string { if ( ! static :: isValidScheme ( $ scheme ) ) { $ message = sprintf ( 'Invalid URI scheme: %s' , VarPrinter :: toString ( $ scheme ) ) ; throw new DomainException ( $ message ) ; } return strtolower ( $ scheme ) ; }
Validates and normalizes the scheme
23,595
protected static function normalizePath ( string $ path ) : string { if ( ! static :: isValidPath ( $ path ) ) { $ message = sprintf ( 'Invalid URI path: %s' , $ path ) ; throw new DomainException ( $ message ) ; } $ path = static :: removeDotSegments ( $ path ) ; return static :: encodePath ( static :: decode ( $ path , static :: UNRESERVED_SET ) ) ; }
Validates and normalizes the path
23,596
protected static function normalizeQuery ( ? string $ query ) : ? string { if ( $ query === null ) { return null ; } if ( ! static :: isValidQuery ( $ query ) ) { $ message = sprintf ( 'Invalid URI query: %s' , $ query ) ; throw new DomainException ( $ message ) ; } return static :: encodeQuery ( static :: decode ( $ query , static :: UNRESERVED_SET ) ) ; }
Validates and normalizes the query
23,597
protected static function normalizeFragment ( ? string $ fragment ) : ? string { if ( $ fragment === null ) { return null ; } if ( ! static :: isValidFragment ( $ fragment ) ) { $ message = sprintf ( 'Invalid URI fragment: %s' , $ fragment ) ; throw new DomainException ( $ message ) ; } return static :: encodeFragment ( static :: decode ( $ fragment , static :: UNRESERVED_SET ) ) ; }
Validates and normalizes the fragment
23,598
protected static function normalizeUserInfo ( ? string $ userInfo ) : ? string { if ( $ userInfo === null ) { return null ; } if ( ! static :: isValidUserInfo ( $ userInfo ) ) { $ message = sprintf ( 'Invalid user info: %s' , $ userInfo ) ; throw new DomainException ( $ message ) ; } return static :: encodeUserInfo ( static :: decode ( $ userInfo , static :: UNRESERVED_SET ) ) ; }
Validates and normalizes the user info
23,599
protected static function normalizeHost ( ? string $ host ) : ? string { if ( $ host === null ) { return null ; } if ( $ host === '' ) { return '' ; } if ( ! static :: isValidHost ( $ host ) ) { $ message = sprintf ( 'Invalid host: %s' , $ host ) ; throw new DomainException ( $ message ) ; } $ host = mb_strtolower ( $ host , 'UTF-8' ) ; return static :: encodeHost ( static :: decode ( $ host , static :: UNRESERVED_SET ) ) ; }
Validates and normalizes the host