idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
14,700
|
public function mapDeviceName ( ? string $ deviceName ) : ? string { if ( null === $ deviceName ) { return null ; } $ brandName = null ; switch ( mb_strtolower ( $ deviceName ) ) { case '' : case 'unknown' : case 'other' : case 'various' : case 'android 1.6' : case 'android 2.0' : case 'android 2.1' : case 'android 2.2' : case 'android 2.3' : case 'android 3.0' : case 'android 3.1' : case 'android 3.2' : case 'android 4.0' : case 'android 4.1' : case 'android 4.2' : case 'android 4.3' : case 'android 4.4' : case 'android 5.0' : case 'android 2.2 tablet' : case 'android 4 tablet' : case 'android 4.1 tablet' : case 'android 4.2 tablet' : case 'android 4.3 tablet' : case 'android 4.4 tablet' : case 'android 5.0 tablet' : case 'disguised as macintosh' : case 'mini 1' : case 'mini 4' : case 'mini 5' : case 'windows mobile 6.5' : case 'windows mobile 7' : case 'windows mobile 7.5' : case 'windows phone 7' : case 'windows phone 8' : case 'fennec tablet' : case 'tablet on android' : case 'fennec' : case 'opera for series 60' : case 'opera mini for s60' : case 'windows mobile (opera)' : case 'nokia unrecognized ovi browser' : $ brandName = null ; break ; case 'p9514' : case 'lifetab p9514' : case 'lifetab s9512' : $ brandName = 'Medion' ; break ; case 'htc desire sv' : $ brandName = 'HTC' ; break ; case 'ipad' : case 'iphone' : $ brandName = 'Apple' ; break ; default : break ; } return $ brandName ; }
|
maps the brand name of a device from the device name
|
14,701
|
public static function mostSimilar ( $ needle , $ wordPool ) { $ distancePool = [ ] ; $ needle = mb_strtolower ( $ needle ) ; foreach ( $ wordPool as $ word ) { $ distance = similar_text ( $ needle , mb_strtolower ( $ word ) ) ; if ( ! isset ( $ distancePool [ $ distance ] ) ) { $ distancePool [ $ distance ] = [ ] ; } $ distancePool [ $ distance ] [ ] = $ word ; } $ min = max ( array_keys ( $ distancePool ) ) ; return $ distancePool [ $ min ] [ 0 ] ; }
|
Finds a string in a pool of strings which is most similar to the given needle .
|
14,702
|
public static function translit ( $ string , $ substChar = '?' , $ trim = true , $ removeDuplicates = true ) { if ( ! is_string ( $ string ) ) { if ( is_scalar ( $ string ) ) { $ string = ( string ) $ string ; } else { $ type = gettype ( $ string ) ; throw new \ InvalidArgumentException ( __METHOD__ . "() expects parameter 1 to be string, $type given" ) ; } } $ string = strtr ( $ string , CharacterMap :: get ( ) ) ; $ string = preg_replace ( "/[^\\w]/" , $ substChar , $ string ) ; if ( $ trim ) { $ string = trim ( $ string , $ substChar ) ; } if ( $ removeDuplicates ) { $ string = preg_replace ( "/\\{$substChar}+/" , $ substChar , $ string ) ; } return $ string ; }
|
Transliterates an UTF8 string to printable ASCII characters .
|
14,703
|
public static function slugify ( $ string ) { if ( ! is_string ( $ string ) ) { $ type = gettype ( $ string ) ; throw new \ InvalidArgumentException ( "Given argument is a $type, expected string." ) ; } if ( empty ( $ string ) ) { throw new \ InvalidArgumentException ( "Cannot slugify an empty string." ) ; } $ string = strtr ( $ string , CharacterMap :: get ( ) ) ; $ string = preg_replace ( '/[^\\p{L}\\d]+/u' , '-' , $ string ) ; $ string = trim ( $ string , '-' ) ; $ string = iconv ( 'utf-8' , 'ASCII//TRANSLIT' , $ string ) ; $ string = strtolower ( $ string ) ; $ string = preg_replace ( '/[^-\w]+/' , '' , $ string ) ; return $ string ; }
|
Returns a slugified version of the string .
|
14,704
|
public function readJson ( $ check_header = true , $ override = false ) { if ( ! is_null ( $ this -> from_json ) && ! $ override ) { return $ this -> from_json ; } $ this -> from_json = false ; if ( $ check_header ) { $ type = $ this -> server -> getIs ( "CONTENT_TYPE" ) ? $ this -> server -> get ( "CONTENT_TYPE" ) : $ this -> server -> getOr ( "HTTP_ACCEPT" , '' ) ; if ( ! preg_match ( '/(?:application|text)\/json(?:$|;| )/' , $ type ) ) { return false ; } } $ body = $ this -> body ( ) ; if ( strlen ( $ body ) && ( $ body [ 0 ] === "{" || $ body [ 0 ] === "[" ) ) { $ this -> params_post = new Collection ( Json :: parse ( $ body , true ) ) ; $ this -> body = '' ; $ this -> from_json = true ; } return $ this -> from_json ; }
|
Load json content from body data
|
14,705
|
public function ip ( ) { if ( is_null ( $ this -> ip_address ) ) { $ remote = isset ( $ this -> server [ "REMOTE_ADDR" ] ) ; if ( $ remote && isset ( $ this -> server [ "HTTP_CLIENT_IP" ] ) ) { $ this -> ip_address = $ this -> server [ "HTTP_CLIENT_IP" ] ; } else if ( $ remote ) { $ this -> ip_address = $ _SERVER [ "REMOTE_ADDR" ] ; } else if ( isset ( $ this -> server [ "HTTP_CLIENT_IP" ] ) ) { $ this -> ip_address = $ this -> server [ "HTTP_CLIENT_IP" ] ; } else if ( isset ( $ this -> server [ "HTTP_X_FORWARDED_FOR" ] ) ) { $ this -> ip_address = $ this -> server [ "HTTP_X_FORWARDED_FOR" ] ; } else { $ this -> ip_address = "0.0.0.0" ; } if ( strpos ( $ this -> ip_address , ',' ) !== false ) { $ this -> ip_address = end ( explode ( ',' , $ this -> ip_address ) ) ; } if ( ! $ this -> ip_address ) { $ this -> ip_address = "0.0.0.0" ; } } return $ this -> ip_address ; }
|
Gets the request IP address
|
14,706
|
public function referer ( $ valid_host = false , $ valid_string = '' ) { $ ref = $ this -> server -> getOr ( 'HTTP_REFERER' , '' ) ; if ( $ ref ) { if ( $ valid_host ) { $ host = BASE_PROTOCOL . "://" . APP_HOST ; $ len = strlen ( $ host ) ; if ( substr ( $ ref , 0 , $ len ) !== $ host ) { return '' ; } if ( strlen ( $ ref ) > $ len ) { $ end = $ ref [ $ len ] ; if ( $ end !== "/" && $ end !== ":" ) { return '' ; } } } if ( $ valid_string && strpos ( $ ref , $ valid_string ) === false ) { return '' ; } } return $ ref ; }
|
Gets the request referer
|
14,707
|
public function getRelation ( $ type ) { if ( ! isset ( $ this -> relations [ $ type ] ) ) { throw new RelationNotFoundException ( $ type ) ; } return $ this -> relations [ $ type ] ; }
|
Get a relation link .
|
14,708
|
public function hydrate ( Model $ model , \ Tapestry \ Entities \ File $ file , \ TapestryCloud \ Database \ Entities \ ContentType $ contentType = null ) { $ model -> setUid ( $ file -> getUid ( ) ) ; $ model -> setLastModified ( $ file -> getLastModified ( ) ) ; $ model -> setFilename ( $ file -> getFilename ( ) ) ; $ model -> setExt ( $ file -> getExt ( ) ) ; $ model -> setPath ( $ file -> getPath ( ) ) ; $ model -> setToCopy ( $ file -> isToCopy ( ) ) ; $ model -> setDate ( $ file -> getData ( 'date' ) -> getTimestamp ( ) ) ; $ model -> setIsDraft ( $ file -> getData ( 'draft' , false ) ) ; if ( ! $ file -> isToCopy ( ) ) { $ frontMatter = new TapestryFrontMatter ( $ file -> getFileContent ( ) ) ; $ model -> setContent ( $ frontMatter -> getContent ( ) ) ; $ inFile = [ ] ; foreach ( array_keys ( $ frontMatter -> getData ( ) ) as $ inFileKey ) { $ inFile [ $ inFileKey ] = 1 ; } $ inDatabase = [ ] ; foreach ( $ model -> getFrontMatterKeys ( ) as $ inDatabaseKey ) { if ( isset ( $ inFile [ $ inDatabaseKey ] ) ) { $ inDatabase [ $ inDatabaseKey ] = 1 ; } else { $ inDatabase [ $ inDatabaseKey ] = - 1 ; } } foreach ( $ frontMatter -> getData ( ) as $ key => $ value ) { $ fmRecord = new FrontMatter ( ) ; $ fmRecord -> setName ( $ key ) ; if ( isset ( $ inDatabase [ $ key ] ) ) { $ fmRecord = $ model -> getFrontMatterByKey ( $ key , $ fmRecord ) ; } $ fmRecord -> setValue ( json_encode ( $ value ) ) ; $ model -> addFrontMatter ( $ fmRecord ) ; $ this -> entityManager -> persist ( $ fmRecord ) ; } } if ( ! is_null ( $ contentType ) ) { $ model -> setContentType ( $ contentType ) ; } }
|
File Hydration .
|
14,709
|
protected function copyMigrations ( ) : void { $ this -> stdout ( "\nCopy the migration files in a temp directory\n" , Console :: FG_YELLOW ) ; FileHelper :: removeDirectory ( $ this -> migrationPath ) ; FileHelper :: createDirectory ( $ this -> migrationPath ) ; if ( ! is_dir ( $ this -> migrationPath ) ) { $ this -> stdout ( "Could not create a temporary directory migration\n" , Console :: FG_RED ) ; exit ( ) ; } $ this -> stdout ( "\tCreated a directory migration\n" , Console :: FG_GREEN ) ; if ( $ dirs = $ this -> findMigrationDirs ( ) ) { foreach ( $ dirs as $ dir ) { FileHelper :: copyDirectory ( $ dir , $ this -> migrationPath ) ; } } $ this -> stdout ( "\tThe copied files components migrations\n" , Console :: FG_GREEN ) ; $ appMigrateDir = \ Yii :: getAlias ( "@app/commands" ) ; if ( is_dir ( $ appMigrateDir ) ) { FileHelper :: copyDirectory ( $ appMigrateDir , $ this -> migrationPath ) ; } $ this -> stdout ( "\tThe copied files app migrations\n\n" , Console :: FG_GREEN ) ; }
|
Copy migrations to temp directory .
|
14,710
|
protected function clearNamespace ( string $ class ) { if ( file_exists ( $ class ) ) { $ content = file_get_contents ( $ class ) ; $ content = preg_replace ( '#^namespace\s+(.+?);$#sm' , ' ' , $ content ) ; file_put_contents ( $ class , $ content ) ; } }
|
Clear namespace to php class file .
|
14,711
|
public function update ( $ new_instance , $ old_instance ) { $ menus = get_terms ( 'nav_menu' , array ( 'hide_empty' => true ) ) ; $ selected_menu = isset ( $ _REQUEST [ $ this -> get_menu_field_id ( ) ] ) ? sanitize_text_field ( wp_unslash ( $ _REQUEST [ $ this -> get_menu_field_id ( ) ] ) ) : false ; foreach ( $ menus as $ menu ) { if ( $ selected_menu === $ menu -> slug ) { $ new_instance [ 'menu' ] = $ selected_menu ; break ; } } return $ new_instance ; }
|
Save the menu slug
|
14,712
|
public function get_sub_menu_items ( $ menu_items , $ parent_id ) { $ items = [ ] ; foreach ( $ menu_items as $ menu_item ) { if ( intval ( $ parent_id ) === intval ( $ menu_item -> menu_item_parent ) ) { $ items [ ] = [ 'title' => $ menu_item -> title , 'link' => str_replace ( site_url ( ) , '' , $ menu_item -> url ) , 'items' => self :: get_sub_menu_items ( $ menu_items , $ menu_item -> ID ) , ] ; } } return $ items ; }
|
Recursively get all sub menu items .
|
14,713
|
protected function buildClass ( $ name ) { $ className = $ this -> formatClassName ( $ name ) ; if ( ! class_exists ( $ className ) ) { throw new RuntimeException ( 'Enum ' . $ className . ' is not exists' ) ; } $ enum = new $ className ( ) ; if ( ! $ enum instanceof Enumable ) { throw new RuntimeException ( 'Enum ' . $ className . ' is not instance of ' . Enumable :: class ) ; } return $ enum ; }
|
Build a Enum class .
|
14,714
|
public function Initialize ( ) { $ this -> Head = new HeadModule ( $ this ) ; $ this -> AddCssFile ( 'setup.css' ) ; $ this -> AddJsFile ( 'jquery.js' ) ; SaveToConfig ( 'Garden.Errors.MasterView' , 'deverror.master.php' , array ( 'Save' => FALSE ) ) ; }
|
Add CSS & module set error master view . Automatically run on every use .
|
14,715
|
public function Index ( ) { $ this -> AddJsFile ( 'setup.js' ) ; $ this -> ApplicationFolder = 'dashboard' ; $ this -> MasterView = 'setup' ; $ Installed = C ( 'Garden.Installed' ) ; if ( $ Installed ) { $ this -> View = "AlreadyInstalled" ; $ this -> Render ( ) ; return ; } if ( ! $ this -> _CheckPrerequisites ( ) ) { $ this -> View = 'prerequisites' ; } else { $ this -> View = 'configure' ; if ( ! file_exists ( PATH_ROOT . '/.htaccess' ) && ! $ this -> Form -> GetFormValue ( 'SkipHtaccess' ) ) { $ this -> SetData ( 'NoHtaccess' , TRUE ) ; $ this -> Form -> AddError ( T ( 'You are missing Vanilla\'s .htaccess file.' , 'You are missing Vanilla\'s <b>.htaccess</b> file. Sometimes this file isn\'t copied if you are using ftp to upload your files because this file is hidden. Make sure you\'ve copied the <b>.htaccess</b> file before continuing.' ) ) ; } $ ApplicationManager = new Gdn_ApplicationManager ( ) ; if ( $ this -> Configure ( ) && $ this -> Form -> IsPostBack ( ) ) { $ AppNames = C ( 'Garden.Install.Applications' , array ( 'Conversations' , 'Vanilla' ) ) ; try { foreach ( $ AppNames as $ AppName ) { $ Validation = new Gdn_Validation ( ) ; $ ApplicationManager -> RegisterPermissions ( $ AppName , $ Validation ) ; $ ApplicationManager -> EnableApplication ( $ AppName , $ Validation ) ; } } catch ( Exception $ ex ) { $ this -> Form -> AddError ( $ ex ) ; } if ( $ this -> Form -> ErrorCount ( ) == 0 ) { $ Config = array ( 'Garden.Installed' => TRUE ) ; SaveToConfig ( $ Config ) ; Redirect ( '/settings/gettingstarted' ) ; } } } $ this -> Render ( ) ; }
|
The summary of all settings available .
|
14,716
|
private function _CheckPrerequisites ( ) { if ( version_compare ( phpversion ( ) , ENVIRONMENT_PHP_VERSION ) < 0 ) $ this -> Form -> AddError ( sprintf ( T ( 'You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.' ) , phpversion ( ) , ENVIRONMENT_PHP_VERSION ) ) ; if ( ! class_exists ( 'PDO' ) ) $ this -> Form -> AddError ( T ( 'You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.' ) ) ; if ( ! defined ( 'PDO::MYSQL_ATTR_USE_BUFFERED_QUERY' ) ) $ this -> Form -> AddError ( T ( 'You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.' ) ) ; $ PermissionProblem = FALSE ; $ ProblemDirectories = array ( ) ; if ( ! is_readable ( PATH_CONF ) || ! IsWritable ( PATH_CONF ) ) $ ProblemDirectories [ ] = PATH_CONF ; if ( ! is_readable ( PATH_UPLOADS ) || ! IsWritable ( PATH_UPLOADS ) ) $ ProblemDirectories [ ] = PATH_UPLOADS ; if ( ! is_readable ( PATH_CACHE ) || ! IsWritable ( PATH_CACHE ) ) $ ProblemDirectories [ ] = PATH_CACHE ; if ( count ( $ ProblemDirectories ) > 0 ) { $ PermissionProblem = TRUE ; $ PermissionError = T ( 'Some folders don\'t have correct permissions.' , '<p>Some of your folders do not have the correct permissions.</p><p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p>' ) ; $ PermissionHelp = '<pre>chmod -R 777 ' . implode ( "\nchmod -R 777 " , $ ProblemDirectories ) . '</pre>' ; $ this -> Form -> AddError ( $ PermissionError . $ PermissionHelp ) ; } if ( ! $ PermissionProblem ) { $ ConfigFile = PATH_CONF . '/config.php' ; if ( ! file_exists ( $ ConfigFile ) ) file_put_contents ( $ ConfigFile , '' ) ; if ( ! is_readable ( $ ConfigFile ) || ! IsWritable ( $ ConfigFile ) ) { $ this -> Form -> AddError ( sprintf ( T ( 'Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>' ) , $ ConfigFile ) ) ; $ PermissionProblem = TRUE ; } } if ( ! $ PermissionProblem ) { if ( ! file_exists ( PATH_CACHE . '/Smarty' ) ) mkdir ( PATH_CACHE . '/Smarty' ) ; if ( ! file_exists ( PATH_CACHE . '/Smarty/cache' ) ) mkdir ( PATH_CACHE . '/Smarty/cache' ) ; if ( ! file_exists ( PATH_CACHE . '/Smarty/compile' ) ) mkdir ( PATH_CACHE . '/Smarty/compile' ) ; } return $ this -> Form -> ErrorCount ( ) == 0 ? TRUE : FALSE ; }
|
Check minimum requirements for Garden .
|
14,717
|
public static function flatten ( array $ array , $ separator = '.' , $ prefix = '' ) { $ result = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ newPrefix = empty ( $ prefix ) ? $ key : "$prefix.$key" ; $ result = array_merge ( $ result , self :: flatten ( $ value , $ separator , $ newPrefix ) ) ; } else { $ newKey = empty ( $ prefix ) ? $ key : "$prefix.$key" ; $ result [ $ newKey ] = $ value ; } } return $ result ; }
|
Flattens a deep array to a single dimension .
|
14,718
|
private static function processReindexPath ( $ path ) { if ( is_string ( $ path ) || is_integer ( $ path ) ) { $ path = array ( array ( $ path ) ) ; } elseif ( is_array ( $ path ) && ! empty ( $ path ) && ! is_array ( $ path [ 0 ] ) ) { foreach ( $ path as $ key ) { if ( ! ( is_string ( $ key ) || is_integer ( $ key ) ) ) { throw new InvalidArgumentException ( 'Invalid reindex path.' ) ; } } $ path = array ( $ path ) ; } elseif ( is_array ( $ path ) && ! empty ( $ path ) && is_array ( $ path [ 0 ] ) ) { foreach ( $ path as $ subpath ) { if ( ! is_array ( $ subpath ) || empty ( $ subpath ) ) { throw new InvalidArgumentException ( 'Invalid reindex path.' ) ; } foreach ( $ subpath as $ key ) { if ( ! ( is_string ( $ key ) || is_integer ( $ key ) ) ) { throw new InvalidArgumentException ( 'Invalid reindex path.' ) ; } } } } else { throw new InvalidArgumentException ( 'Invalid reindex path.' ) ; } return $ path ; }
|
Processes and validates the given index path .
|
14,719
|
public function setExpectedAndReceived ( $ expected , $ received ) { $ this -> expected = is_string ( $ expected ) ? $ expected : get_class ( $ expected ) ; $ this -> received = TypeHound :: fetch ( $ received ) ; $ this -> message = vsprintf ( 'An instance of a %s was expected but got %s' , [ $ this -> expected , $ this -> received ] ) ; }
|
Set the expected class and the received value .
|
14,720
|
private function tryLogMessage ( $ message ) { $ messageId = null ; if ( $ message instanceof RemoteMessage ) $ messageId = $ message -> header ( ) -> uuid ( ) ; elseif ( $ message instanceof ProcessingMessage ) $ messageId = $ message -> uuid ( ) ; if ( ! $ messageId ) return ; $ entry = $ this -> messageLogger -> getEntryForMessageId ( $ messageId ) ; if ( $ entry ) return ; $ this -> messageLogger -> logIncomingMessage ( $ message ) ; }
|
Message is only logged if it is has a valid type and is not logged already otherwise it is ignored .
|
14,721
|
public function addChild ( RecursiveLeafInterface $ leaf ) { $ leaf -> setDepth ( $ this -> depth + 1 ) ; $ this -> children [ ] = $ leaf ; }
|
Adds the child leaf .
|
14,722
|
public function setUniqueKey ( $ uniqueKey ) { if ( ! is_null ( $ this -> uniqueKey ) ) { throw new RuntimeException ( 'The unique key was already set.' ) ; } if ( ! is_int ( $ uniqueKey ) && ! is_string ( $ uniqueKey ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid type of specified unique key; must be an integer or ' . 'an string, "%s" received.' , gettype ( $ uniqueKey ) ) ) ; } $ this -> uniqueKey = $ uniqueKey ; }
|
Sets the unique key of leaf .
|
14,723
|
public function setDepth ( $ depth ) { if ( ! is_null ( $ this -> depth ) ) { throw new RuntimeException ( 'The depth was already set.' ) ; } if ( ! is_int ( $ depth ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid type of specified depth; must be an integer, ' . '"%s" received.' , gettype ( $ depth ) ) ) ; } $ this -> depth = $ depth ; }
|
Sets the depth of leaf in the tree .
|
14,724
|
protected static function getEndPointFromRequest ( Request $ request , array $ config ) { $ class = self :: getClassFromRequest ( $ request ) ; if ( class_exists ( $ class ) && $ request -> match ( $ class :: getPatterns ( ) ) ) { return [ 'endPoint' => $ class :: getEndpoint ( ) , 'params' => $ class :: getParams ( $ request ) , ] ; } if ( ! empty ( $ config [ 'embedlyKey' ] ) && $ request -> match ( OEmbed \ Embedly :: getPatterns ( ) ) ) { return [ 'endPoint' => OEmbed \ Embedly :: getEndpoint ( ) , 'params' => OEmbed \ Embedly :: getParams ( $ request ) + [ 'key' => $ config [ 'embedlyKey' ] ] , ] ; } }
|
Returns the oembed link from the request
|
14,725
|
public static function generateHash ( $ password ) { $ cost = 10 ; $ salt = strtr ( base64_encode ( mcrypt_create_iv ( 16 , MCRYPT_DEV_URANDOM ) ) , '+' , '.' ) ; $ salt = sprintf ( "$2a$%02d$" , $ cost ) . $ salt ; $ hash = crypt ( $ password , $ salt ) ; return $ hash ; }
|
generates the hash
|
14,726
|
private function AddOptionsField ( ) { $ name = 'Options' ; $ field = new Textarea ( $ name , $ this -> OptionsString ( ) ) ; $ this -> AddField ( $ field ) ; $ this -> SetTransAttribute ( $ name , 'placeholder' ) ; $ this -> SetRequired ( $ name ) ; }
|
Adds the options textarea
|
14,727
|
protected function SaveElement ( ) { $ this -> radio -> SetLabel ( $ this -> Value ( 'Label' ) ) ; $ this -> radio -> SetName ( $ this -> Value ( 'Name' ) ) ; $ this -> radio -> SetValue ( $ this -> Value ( 'Value' ) ) ; $ this -> radio -> SetRequired ( ( bool ) $ this -> Value ( 'Required' ) ) ; $ this -> radio -> SetDisableFrontendValidation ( ( bool ) $ this -> Value ( 'DisableFrontendValidation' ) ) ; return $ this -> radio ; }
|
Stores the radio content s base properties
|
14,728
|
private function FetchOptions ( ) { $ strOptions = $ this -> Value ( 'Options' ) ; $ lines = Str :: SplitLines ( $ strOptions ) ; $ result = array ( ) ; foreach ( $ lines as $ line ) { $ dpPos = strpos ( $ line , ':' ) ; if ( $ dpPos !== false ) { $ value = trim ( substr ( $ line , 0 , $ dpPos ) ) ; $ text = trim ( substr ( $ line , $ dpPos + 1 ) ) ; } else { $ value = $ line ; $ text = '' ; } $ result [ $ value ] = $ text ; } return $ result ; }
|
Fetches submitted options as array
|
14,729
|
public function group ( $ fields , $ rollup = false ) { $ this -> parts [ 'group' ] [ 'fields' ] = $ fields ; $ this -> parts [ 'group' ] [ 'rollup' ] = $ rollup ; return $ this ; }
|
Sets the group paramater for the query
|
14,730
|
protected function parseCols ( ) { if ( ! isset ( $ this -> parts [ 'cols' ] ) || ! is_array ( $ this -> parts [ 'cols' ] ) || count ( $ this -> parts [ 'cols' ] ) < 1 ) { return '*' ; } else { $ selectParts = [ ] ; foreach ( $ this -> parts [ 'cols' ] as $ itemSelect ) { if ( is_array ( $ itemSelect ) ) { $ field = isset ( $ itemSelect [ 0 ] ) ? $ itemSelect [ 0 ] : false ; $ alias = isset ( $ itemSelect [ 1 ] ) ? $ itemSelect [ 1 ] : false ; $ protected = isset ( $ itemSelect [ 2 ] ) ? $ itemSelect [ 2 ] : true ; $ selectParts [ ] = ( $ protected ? $ this -> protect ( $ field ) : $ field ) . ( ! empty ( $ alias ) ? ' AS ' . $ this -> protect ( $ alias ) : '' ) ; } else { $ selectParts [ ] = $ itemSelect ; } } return implode ( ', ' , $ selectParts ) ; } }
|
Parses SELECT entries
|
14,731
|
private function parseFrom ( ) { if ( ! empty ( $ this -> parts [ 'from' ] ) ) { $ parts = [ ] ; foreach ( $ this -> parts [ 'from' ] as $ key => $ item ) { if ( is_array ( $ item ) ) { $ table = isset ( $ item [ 0 ] ) ? $ item [ 0 ] : false ; $ alias = isset ( $ item [ 1 ] ) ? $ item [ 1 ] : false ; if ( is_object ( $ table ) ) { if ( ! $ alias ) { trigger_error ( 'Select statements in for need aliases defined' , E_USER_ERROR ) ; } $ parts [ $ key ] = '(' . $ table . ') AS ' . $ this -> protect ( $ alias ) . $ this -> parseJoin ( $ alias ) ; } else { $ parts [ $ key ] = $ this -> protect ( $ table ) . ' AS ' . $ this -> protect ( ( ! empty ( $ alias ) ? $ alias : $ table ) ) . $ this -> parseJoin ( $ alias ) ; } } elseif ( ! strpos ( $ item , ' ' ) ) { $ parts [ ] = $ this -> protect ( $ item ) . $ this -> parseJoin ( $ item ) ; } else { $ parts [ ] = $ item ; } } return implode ( ", " , array_unique ( $ parts ) ) ; } return null ; }
|
Parses FROM entries
|
14,732
|
private function parseGroup ( ) { $ group = '' ; if ( isset ( $ this -> parts [ 'group' ] [ 'fields' ] ) ) { if ( is_array ( $ this -> parts [ 'group' ] [ 'fields' ] ) ) { $ groupFields = [ ] ; foreach ( $ this -> parts [ 'group' ] [ 'fields' ] as $ field ) { $ field = is_array ( $ field ) ? $ field : [ $ field ] ; $ column = isset ( $ field [ 0 ] ) ? $ field [ 0 ] : false ; $ type = isset ( $ field [ 1 ] ) ? $ field [ 1 ] : '' ; $ groupFields [ ] = $ this -> protect ( $ column ) . ( $ type ? ' ' . strtoupper ( $ type ) : '' ) ; } $ group .= implode ( ', ' , $ groupFields ) ; } else { $ group .= $ this -> parts [ 'group' ] [ 'fields' ] ; } } if ( isset ( $ this -> parts [ 'group' ] [ 'rollup' ] ) && $ this -> parts [ 'group' ] [ 'rollup' ] !== false ) { $ group .= ' WITH ROLLUP' ; } return $ group ; }
|
Parses GROUP entries
|
14,733
|
public function addServiceListener ( string $ eventName , array $ listener , $ priority = 0 ) : ContainerMediatorInterface { $ this -> checkEventName ( $ eventName ) ; $ this -> checkAllowedServiceListener ( $ listener ) ; $ priority = $ this -> getActualPriority ( $ eventName , $ priority ) ; if ( \ array_key_exists ( $ eventName , $ this -> serviceListeners ) && \ array_key_exists ( $ priority , $ this -> serviceListeners [ $ eventName ] ) && \ in_array ( $ listener , $ this -> serviceListeners [ $ eventName ] [ $ priority ] , \ true ) ) { return $ this ; } $ this -> serviceListeners [ $ eventName ] [ $ priority ] [ ] = $ listener ; return $ this ; }
|
Add a service as an event listener .
|
14,734
|
public function getServiceListeners ( string $ eventName = '' ) : array { $ this -> sortServiceListeners ( $ eventName ) ; if ( '' !== $ eventName ) { return \ array_key_exists ( $ eventName , $ this -> serviceListeners ) ? $ this -> serviceListeners [ $ eventName ] : [ ] ; } return $ this -> serviceListeners ; }
|
Get a list of service listeners for an event .
|
14,735
|
public function removeServiceListener ( string $ eventName , array $ listener , $ priority = 0 ) : ContainerMediatorInterface { $ this -> checkEventName ( $ eventName ) ; if ( ! \ array_key_exists ( $ eventName , $ this -> serviceListeners ) ) { return $ this ; } $ this -> checkAllowedServiceListener ( $ listener ) ; if ( \ in_array ( $ eventName , $ this -> loadedServices , \ true ) ) { $ this -> removeListener ( $ eventName , [ $ this -> getServiceByName ( $ listener [ 0 ] ) , $ listener [ 1 ] ] , $ priority ) ; } if ( 'last' !== $ priority ) { $ priorities = $ this -> serviceListeners [ $ eventName ] ; } else { $ priorities = \ array_reverse ( $ this -> serviceListeners [ $ eventName ] , \ true ) ; $ priority = 'first' ; } $ isIntPriority = \ is_int ( $ priority ) ; foreach ( $ priorities as $ atPriority => $ listeners ) { if ( $ isIntPriority && $ priority !== $ atPriority ) { continue ; } $ key = \ array_search ( $ listener , $ listeners , \ true ) ; if ( \ false !== $ key ) { $ this -> bubbleUpUnsetServiceListener ( $ eventName , $ atPriority , $ key ) ; if ( 'first' === $ priority ) { break ; } } } return $ this ; }
|
Remove a service as an event listener .
|
14,736
|
public function configureAsseticBundle ( ContainerBuilder $ container , array $ config ) { foreach ( array_keys ( $ container -> getExtensions ( ) ) as $ name ) { switch ( $ name ) { case 'assetic' : $ this -> addJqueryInAssetic ( $ container , $ config [ 'assets' ] [ 'jquery' ] ) ; $ this -> addTwbsInAssetic ( $ container , $ config [ 'assets' ] [ 'twbs' ] ) ; if ( isset ( $ config [ 'assets' ] [ 'jqueryui' ] ) ) { $ this -> addJqueryUIInAssetic ( $ container , $ config [ 'assets' ] [ 'jqueryui' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'select2' ] ) ) { $ this -> addSelect2InAssetic ( $ container , $ config [ 'assets' ] [ 'select2' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'bazinga_js_translation' ] ) ) { $ this -> addBazingaJsTranslationInAssetic ( $ container , $ config [ 'assets' ] [ 'bazinga_js_translation' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'speakingurl' ] ) ) { $ this -> addSpeakingURLInAssetic ( $ container , $ config [ 'assets' ] [ 'speakingurl' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'tinymce' ] ) ) { $ this -> addTinyMCEInAssetic ( $ container , $ config [ 'assets' ] [ 'tinymce' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'jquery_tags_input' ] ) ) { $ this -> addJqueryTagsInputInAssetic ( $ container , $ config [ 'assets' ] [ 'jquery_tags_input' ] ) ; } if ( isset ( $ config [ 'assets' ] [ 'prism_js' ] ) ) { $ this -> addPrismJSInAssetic ( $ container , $ config [ 'assets' ] [ 'prism_js' ] ) ; } break ; } } }
|
Add assets to Assetic Bundle .
|
14,737
|
protected function addJqueryUIInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'js' ] !== false && $ config [ 'css' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'jqueryui_js' => $ config [ 'js' ] , 'jqueryui_css' => $ config [ 'css' ] , ) , ) ) ; } elseif ( $ config [ 'js' ] === false && $ config [ 'css' ] !== false ) { throw new InvalidConfigurationException ( 'You have enabled jQuery UI supports but js parameter is missing.' ) ; } elseif ( $ config [ 'js' ] !== false && $ config [ 'css' ] === false ) { throw new InvalidConfigurationException ( 'You have enabled jQuery UI supports but css parameter is missing.' ) ; } }
|
Adding jQuery UI in Assetic .
|
14,738
|
protected function addTwbsInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'twbs_dir' ] !== false && ! is_null ( $ config [ 'twbs_dir' ] ) ) { $ inputs = array ( ) ; foreach ( $ config [ 'js' ] as $ file ) { $ inputs [ ] = $ config [ 'twbs_dir' ] . '/' . $ file ; } $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'twbs_js' => array ( 'inputs' => $ inputs , ) , ) , ) ) ; if ( count ( $ config [ 'less' ] ) > 0 && count ( $ config [ 'css' ] ) > 0 ) { throw new InvalidConfigurationException ( 'You can\'t have less files and css files in your Twitter Bootstrap Configuration, choose one.' ) ; } elseif ( count ( $ config [ 'less' ] ) > 0 ) { $ inputs = array ( ) ; foreach ( $ config [ 'less' ] as $ file ) { $ inputs [ ] = $ config [ 'twbs_dir' ] . '/' . $ file ; } $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'twbs_css' => array ( 'inputs' => $ inputs , ) , ) , ) ) ; } elseif ( count ( $ config [ 'css' ] ) > 0 ) { $ inputs = array ( ) ; foreach ( $ config [ 'css' ] as $ file ) { $ inputs [ ] = $ config [ 'twbs_dir' ] . '/' . $ file ; } $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'twbs_css' => array ( 'inputs' => $ inputs , ) , ) , ) ) ; } } }
|
Adding Twitter Bootstrap in Assetic .
|
14,739
|
protected function addSelect2InAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'js' ] !== false && $ config [ 'css' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'select2_js' => $ config [ 'js' ] , 'select2_css' => $ config [ 'css' ] , ) , ) ) ; } elseif ( $ config [ 'js' ] === false && $ config [ 'css' ] !== false ) { throw new InvalidConfigurationException ( 'You have enabled select2 supports but js parameter is missing.' ) ; } elseif ( $ config [ 'js' ] !== false && $ config [ 'css' ] === false ) { throw new InvalidConfigurationException ( 'You have enabled select2 supports but css parameter is missing.' ) ; } }
|
Adding Select2 in Assetic .
|
14,740
|
protected function addBazingaJsTranslationInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'bz_translator_js' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'bz_translator_js' => $ config [ 'bz_translator_js' ] , 'bz_translator_config' => $ config [ 'bz_translator_config' ] , 'bz_translations_files' => $ config [ 'bz_translations_files' ] , ) , ) ) ; } }
|
Adding Bazinga Js Translation in Assetic .
|
14,741
|
protected function addTinyMCEInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'tinymce_dir' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'tinymce_js' => $ config [ 'tinymce_dir' ] . '/' . $ config [ 'js' ] , 'config' => $ config [ 'config' ] , ) , ) ) ; } }
|
Adding TinyMCE In Assetic .
|
14,742
|
protected function addJqueryTagsInputInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'js' ] !== false && $ config [ 'css' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'jquerytagsinput_js' => $ config [ 'js' ] , 'jquerytagsinput_css' => $ config [ 'css' ] , ) , ) ) ; } elseif ( $ config [ 'js' ] === false && $ config [ 'css' ] !== false ) { throw new InvalidConfigurationException ( 'You have enabled jQuery Tags Input supports but js parameter is missing.' ) ; } elseif ( $ config [ 'js' ] !== false && $ config [ 'css' ] === false ) { throw new InvalidConfigurationException ( 'You have enabled jQuery Tags Input supports but css parameter is missing.' ) ; } }
|
Adding jQuery Tags Input Plugin in Assetic .
|
14,743
|
protected function addPrismJSInAssetic ( ContainerBuilder $ container , array $ config ) { if ( $ config [ 'js' ] !== false && $ config [ 'css' ] !== false ) { $ container -> prependExtensionConfig ( 'assetic' , array ( 'assets' => array ( 'prismjs_js' => $ config [ 'js' ] , 'prismjs_css' => $ config [ 'css' ] , ) , ) ) ; } elseif ( $ config [ 'js' ] === false && $ config [ 'css' ] !== false ) { throw new InvalidConfigurationException ( 'You have enabled PrismJS supports but js parameter is missing.' ) ; } elseif ( $ config [ 'js' ] !== false && $ config [ 'css' ] === false ) { throw new InvalidConfigurationException ( 'You have enabled PrismJS supports but css parameter is missing.' ) ; } }
|
Adding PrismJS in Assetic .
|
14,744
|
private function getRuleFactory ( string $ name ) : callable { if ( array_key_exists ( $ name , $ this -> factories ) ) { return $ this -> factories [ $ name ] ; } throw new RuleFactoryNotDefinedException ( $ name ) ; }
|
Return the rule factory associated to the given name .
|
14,745
|
public function parseRulesDefinition ( $ definition ) : RulesCollection { if ( is_callable ( $ definition ) ) { $ definition = [ $ definition ] ; } if ( is_string ( $ definition ) ) { $ definition = array_map ( 'trim' , explode ( '|' , $ definition ) ) ; } if ( is_array ( $ definition ) ) { $ keys = array_keys ( $ definition ) ; return array_reduce ( $ keys , function ( $ rules , $ key ) use ( $ definition ) { $ definition = $ definition [ $ key ] ; $ rule = $ this -> parseRuleDefinition ( $ key , $ definition ) ; return $ rules -> withRule ( $ rule ) ; } , new RulesCollection ) ; } throw new InvalidRuleFormatException ( $ definition ) ; }
|
Return a rules collection from a rule definition . It can be either a callable an array of callables an array of factory names or a string of rule factory names .
|
14,746
|
private function parseRuleDefinition ( $ key , $ definition ) : Rule { if ( is_string ( $ definition ) ) { $ parts = preg_split ( '/:/' , $ definition , 2 ) ; $ factory_name = $ parts [ 0 ] ; $ parameters = $ parts [ 1 ] ?? null ; $ parameters = ! is_null ( $ parameters ) ? explode ( ',' , $ parameters ) : [ ] ; $ factory_name = trim ( $ factory_name ) ; $ parameters = array_map ( 'trim' , $ parameters ) ; $ factory = $ this -> getRuleFactory ( $ factory_name ) ; $ name = is_string ( $ key ) ? $ key : $ factory_name ; $ validate = $ factory ( $ parameters ) ; return new Rule ( $ name , $ validate ) ; } if ( is_callable ( $ definition ) ) { return new Rule ( ( string ) $ key , $ definition ) ; } throw new InvalidRuleFormatException ( $ definition ) ; }
|
Return a rule from a rule key and the associated definition . It can be either a callable or a rule factory name with optional parameters .
|
14,747
|
public static function table ( $ data ) { $ in = new self ( ) ; $ in -> setData ( $ data ) ; $ in -> setOutput ( new Table ( ) ) ; return $ in ; }
|
Show the data in a html table .
|
14,748
|
public static function print_r ( $ data ) { $ in = new self ( ) ; $ in -> setData ( $ data ) ; $ in -> setOutput ( new PrintR ( ) ) ; return $ in ; }
|
Show the data in print_r form html .
|
14,749
|
public static function proxy ( $ request ) { if ( ! $ request instanceof Request ) { $ url = $ request ; $ request = new Request ( ) ; $ request -> setUrl ( $ url ) ; $ request -> setMethod ( Request :: METHOD_GET ) ; } return Client :: getInstance ( ) -> process ( $ request ) ; }
|
Proxy a request .
|
14,750
|
public function setRedirect ( $ url ) { $ this -> setHeader ( 'Location' , $ url ) ; $ this -> setStatus ( 302 ) ; $ this -> setData ( array ( 'message' => 'Redirecting to ' . $ url ) ) ; return $ this ; }
|
Set a response to be a redirect .
|
14,751
|
public function match ( $ methods , $ pattern , $ fn ) { $ pattern = $ this -> baseroute . '/' . trim ( $ pattern , '/' ) ; $ pattern = $ this -> baseroute ? rtrim ( $ pattern , '/' ) : $ pattern ; $ route = new Route ( $ pattern ) ; $ route -> setFunction ( $ fn ) ; $ route -> setModule ( $ this -> module ) ; foreach ( explode ( '|' , $ methods ) as $ method ) { $ this -> routes [ $ method ] [ ] = $ route ; } return $ route ; }
|
Store a route and a handling function to be executed when accessed using one of the specified methods
|
14,752
|
public static function toSnakeCase ( $ name ) { $ temp_array = array ( ) ; for ( $ i = 0 ; $ i < strlen ( $ name ) ; $ i ++ ) { $ ascii_code = ord ( $ name [ $ i ] ) ; if ( $ ascii_code >= 65 && $ ascii_code <= 90 ) { if ( $ i == 0 ) { $ temp_array [ ] = chr ( $ ascii_code + 32 ) ; } else { $ temp_array [ ] = '_' . chr ( $ ascii_code + 32 ) ; } } else { $ temp_array [ ] = $ name [ $ i ] ; } } return implode ( '' , $ temp_array ) ; }
|
userName - > user_name
|
14,753
|
public function showAction ( Parameter $ entity ) { $ deleteForm = $ this -> createDeleteForm ( $ entity ) ; return array ( 'entity' => $ entity , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
|
Finds and displays a parameter entity .
|
14,754
|
private function createDeleteForm ( Parameter $ entity ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'core_parameter_delete' , array ( 'id' => $ entity -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; }
|
Creates a form to delete a parameter entity .
|
14,755
|
public function passes ( $ action = null ) { $ this -> data = $ this -> sanitize ( $ this -> data ) ; $ rules = $ this -> getRules ( $ action ) ; $ validator = $ this -> validator -> make ( $ this -> data , $ rules ) ; if ( $ validator -> fails ( ) ) { $ this -> errors = $ validator -> messages ( ) ; return false ; } return true ; }
|
Pass the data and the rules to the validator .
|
14,756
|
public function exchangeArray ( $ dataSet ) { if ( is_object ( $ dataSet ) ) { switch ( true ) { case is_callable ( array ( $ dataSet , 'getArrayCopy' ) , false ) : $ dataSet = $ dataSet -> getArrayCopy ( ) ; break ; case is_callable ( array ( $ dataSet , 'toArray' ) , false ) : $ dataSet = $ dataSet -> toArray ( ) ; break ; case is_callable ( array ( $ dataSet , '__toArray' ) , false ) : $ dataSet = $ dataSet -> __toArray ( ) ; break ; case ( $ dataSet instanceof \ stdClass ) : $ dataSet = ( array ) $ dataSet ; break ; default : throw new \ InvalidArgumentException ( vsprintf ( '%s - Unable to exchange data with object of class "%s".' , array ( get_class ( $ this ) , get_class ( $ dataSet ) ) ) ) ; } } if ( is_array ( $ dataSet ) ) { $ prevStorage = $ this -> _storage ; $ this -> _storage = $ dataSet ; $ this -> _modified = true ; return $ prevStorage ; } throw new \ InvalidArgumentException ( vsprintf ( '%s::exchangeArray expects parameter 1 to be array or object, "%s" seen.' , array ( get_class ( $ this ) , gettype ( $ dataSet ) ) ) ) ; }
|
This method was inspired by Zend Framework 2 . 2 . x PhpReferenceCompatibility class
|
14,757
|
public function exists ( $ func ) { if ( ! is_callable ( $ func , false , $ callable_name ) ) throw new \ InvalidArgumentException ( get_class ( $ this ) . '::exists - Un-callable "$func" value seen!' ) ; foreach ( $ this -> _storage as $ key => $ value ) { if ( call_user_func ( $ func , $ key , $ value ) ) return true ; } return false ; }
|
Custom contains method
|
14,758
|
public function remove ( $ index ) { if ( isset ( $ this -> _storage [ $ index ] ) || array_key_exists ( $ index , $ this -> _storage ) ) { $ this -> _modified = true ; $ removed = $ this -> _storage [ $ index ] ; unset ( $ this -> _storage [ $ index ] ) ; return $ removed ; } return null ; }
|
Remove and return an element
|
14,759
|
public function map ( $ func ) { if ( is_callable ( $ func , false ) ) return $ this -> initNew ( array_map ( $ func , $ this -> _storage ) ) ; throw new \ InvalidArgumentException ( vsprintf ( '%s::map - Un-callable "$func" value seen!' , array ( get_class ( $ this ) ) ) ) ; }
|
Applies array_map to this collection and returns a new object .
|
14,760
|
public function filter ( $ func = null ) { if ( null === $ func ) return $ this -> initNew ( array_filter ( $ this -> _storage ) ) ; if ( is_callable ( $ func , false ) ) return $ this -> initNew ( array_filter ( $ this -> _storage , $ func ) ) ; throw new \ InvalidArgumentException ( vsprintf ( '%s::filter - Un-callable "$func" value seen!' , array ( get_class ( $ this ) ) ) ) ; }
|
Applies array_filter to internal collection returns new instance with resulting values .
|
14,761
|
public function sort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return sort ( $ this -> _storage , $ flags ) ; }
|
Sort values by standard PHP sort method
|
14,762
|
public function rsort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return rsort ( $ this -> _storage , $ flags ) ; }
|
Reverse sort values
|
14,763
|
public function ksort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return ksort ( $ this -> _storage , $ flags ) ; }
|
Sort by keys
|
14,764
|
public function krsort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return krsort ( $ this -> _storage , $ flags ) ; }
|
Reverse sort by keys
|
14,765
|
public function asort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return asort ( $ this -> _storage , $ flags ) ; }
|
Sort values while retaining indices .
|
14,766
|
public function arsort ( $ flags = SORT_REGULAR ) { $ this -> _modified = true ; return arsort ( $ this -> _storage , $ flags ) ; }
|
Reverse sort values while retaining indices
|
14,767
|
private function _updateFirstLastKeys ( ) { end ( $ this -> _storage ) ; $ this -> _lastKey = key ( $ this -> _storage ) ; reset ( $ this -> _storage ) ; $ this -> _firstKey = key ( $ this -> _storage ) ; $ this -> _modified = false ; }
|
Update internal references to first and last keys in collection
|
14,768
|
public function notify ( $ type = 'default' ) { if ( isset ( $ this -> observers [ $ type ] ) ) { foreach ( $ this -> observers [ $ type ] as $ obs ) { $ obs -> update ( $ this ) ; } } return $ this ; }
|
Notify observers by type
|
14,769
|
public function mark_ready_for_dispatchAction ( Order $ order ) { $ order -> markReadyForDispatchBySeller ( ) ; $ em = $ this -> getDoctrine ( ) -> getEntityManager ( ) ; $ em -> persist ( $ order ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'Order_show' , array ( 'id' => $ order -> getNumberForPath ( ) ) ) ) ; }
|
mark ready for dispatch
|
14,770
|
public function mark_as_ready_to_pickupAction ( Order $ order ) { $ order -> markReadyForPickupFromHub ( ) ; $ message = \ Swift_Message :: newInstance ( ) -> setSubject ( 'Your order is ready to be picked up' ) -> setFrom ( array ( 'no-reply@harvestcloud.com' => 'Harvest Cloud' ) ) -> setTo ( array ( 'tom@templestreetmedia.com' => 'Tom Haskins-Vaughan' ) ) -> setBody ( $ this -> renderView ( 'HarvestCloudEmailBundle:Buyer:order_ready_to_pickup.txt.twig' , array ( 'order' => $ order ) ) ) ; $ this -> get ( 'mailer' ) -> send ( $ message ) ; $ em = $ this -> getDoctrine ( ) -> getEntityManager ( ) ; $ em -> persist ( $ order ) ; $ em -> flush ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'Order_show' , array ( 'id' => $ order -> getNumberForPath ( ) ) ) ) ; }
|
mark as ready to pickup
|
14,771
|
public static function Atciqz ( $ rc , $ dc , iauASTROM & $ astrom , & $ ri , & $ di ) { $ pco = [ ] ; $ pnat = [ ] ; $ ppr = [ ] ; $ pi = [ ] ; $ w ; IAU :: S2c ( $ rc , $ dc , $ pco ) ; IAU :: Ldsun ( $ pco , $ astrom -> eh , $ astrom -> em , $ pnat ) ; IAU :: Ab ( $ pnat , $ astrom -> v , $ astrom -> em , $ astrom -> bm1 , $ ppr ) ; IAU :: Rxp ( $ astrom -> bpn , $ ppr , $ pi ) ; IAU :: C2s ( $ pi , $ w , $ di ) ; $ ri = IAU :: Anp ( $ w ) ; }
|
- - - - - - - - - - i a u A t c i q z - - - - - - - - - -
|
14,772
|
public function addOption ( OptionInterface $ option ) : void { $ option -> setSelected ( $ option -> getValue ( ) === $ this -> value ) ; if ( $ option -> getValue ( ) === '' ) { $ this -> hasEmptyOption = true ; } $ this -> options [ ] = $ option ; }
|
Adds on option .
|
14,773
|
public static function sanitizeUrl ( $ url ) { $ url = trim ( $ url ) ; if ( ! $ url ) { return null ; } if ( ! preg_match ( "/^https?:\/\//i" , $ url ) ) { $ url = "http://" . $ url ; } return self :: sanitizeString ( $ url ) ; }
|
Prefixes the url with a protocol if it has none to prevent local lookups .
|
14,774
|
public static function sanitizeText ( $ text ) { if ( ! $ text ) { return null ; } $ allowedTagNames = [ "b" , "strong" , "i" , "em" , "br" ] ; $ marker = "\&8slkc7\\" ; $ allowedTagConversion = [ ] ; foreach ( $ allowedTagNames as $ allowedTagName ) { $ allowedTagConversion [ "<{$allowedTagName}>" ] = "{$marker}{$allowedTagName}{$marker}" ; $ allowedTagConversion [ "<{$allowedTagName}/>" ] = "{$marker}{$allowedTagName}/{$marker}" ; $ allowedTagConversion [ "<{$allowedTagName} />" ] = "{$marker}{$allowedTagName} /{$marker}" ; $ allowedTagConversion [ "</{$allowedTagName}>" ] = "{$marker}/{$allowedTagName}{$marker}" ; } $ text = str_ireplace ( array_keys ( $ allowedTagConversion ) , array_values ( $ allowedTagConversion ) , $ text ) ; $ text = self :: sanitizeString ( $ text ) ; if ( ! $ text ) { return null ; } return str_ireplace ( array_values ( $ allowedTagConversion ) , array_keys ( $ allowedTagConversion ) , $ text ) ; }
|
Same as sanitizeString but allows linebreaks and strong and italic text .
|
14,775
|
public static function sanitizeString ( $ string ) { if ( ! $ string ) { return null ; } $ string = str_ireplace ( [ "\r\n" , "\n" , "\r" ] , " " , $ string ) ; $ string = html_entity_decode ( $ string , ENT_NOQUOTES , "UTF-8" ) ; $ string = trim ( strip_tags ( $ string ) ) ; if ( ! $ string ) { return null ; } return ( string ) $ string ; }
|
Trims string removes tags and linebreaks . Returns null if string equals false before or after conversion .
|
14,776
|
public static function sanitizeUrlParts ( $ urlPartOrUrlParts , ... $ additionalUrlParts ) { if ( is_array ( $ urlPartOrUrlParts ) ) { $ urlParts = $ urlPartOrUrlParts ; } else { $ urlParts = array_merge ( [ $ urlPartOrUrlParts ] , $ additionalUrlParts ) ; } $ sanitizedUrlParts = [ ] ; foreach ( $ urlParts as $ urlPart ) { $ urlPart = self :: sanitizeString ( $ urlPart ) ; $ urlPart = str_replace ( array_keys ( self :: ACCENTED_CHARACTERS ) , array_values ( self :: ACCENTED_CHARACTERS ) , $ urlPart ) ; $ urlPart = preg_replace ( "/[\s-_]+/" , "-" , $ urlPart ) ; $ urlPart = strtolower ( $ urlPart ) ; $ urlPart = preg_replace ( "/[^a-z0-9\\-\\.]/" , "" , $ urlPart ) ; $ urlPart = trim ( $ urlPart , "-" ) ; $ sanitizedUrlParts [ ] = $ urlPart ; } return implode ( "/" , $ sanitizedUrlParts ) ; }
|
Sanitize or SEOify url part . Will result in a string with only dashes dots and alphanumeric characters . Arguments are joined by slashes . If an array of parts is given as the first argument each one will be processed and returned as one string with slashes between parts .
|
14,777
|
public static function explode ( $ string , $ characters = ";>|/\\<" ) { $ string = self :: sanitizeString ( $ string ) ; if ( $ string === null ) { return [ ] ; } $ splitRegex = "" ; for ( $ i = 0 ; $ i < strlen ( $ characters ) ; $ i ++ ) { $ splitRegex .= "\\" . $ characters [ $ i ] ; } $ splitRegex = "/[" . $ splitRegex . "]/" ; $ rawElements = preg_split ( $ splitRegex , $ string ) ; $ elements = [ ] ; foreach ( $ rawElements as $ rawElement ) { $ element = self :: sanitizeString ( $ rawElement ) ; if ( $ element !== null ) { $ elements [ ] = $ element ; } } return $ elements ; }
|
Explodes a string into an array after performing sanitization on each element .
|
14,778
|
public static function implode ( $ array , $ separator = " > " ) { if ( $ array === null ) { return "" ; } $ elements = [ ] ; foreach ( $ array as $ rawElement ) { $ element = self :: sanitizeString ( $ rawElement ) ; if ( $ element !== null ) { $ elements [ ] = $ element ; } } return implode ( $ separator , $ elements ) ; }
|
Implodes an array into a string after performing sanitization on each element .
|
14,779
|
public static function startsWith ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , false , false , false ) ; }
|
Returns whether the value of the given strings start with any of the supplied options .
|
14,780
|
public static function endsWith ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , true , false , false ) ; }
|
Returns whether the value of the given strings end with any of the supplied options .
|
14,781
|
public static function startsWithInsensitive ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , false , false , true ) ; }
|
Returns whether the case insensitive value of the given strings start with any of the supplied options .
|
14,782
|
public static function endsWithInsensitive ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , true , false , true ) ; }
|
Returns whether the case insensitive value of the given string ends with any of the supplied options .
|
14,783
|
public static function startsWithAlphanumeric ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , false , true , false ) ; }
|
Returns whether the alphanumeric value of the given strings start with any of the supplied options .
|
14,784
|
public static function endsWithAlphanumeric ( $ stringOrStrings , $ optionOrOptions ) { return self :: startsWithInternal ( $ stringOrStrings , $ optionOrOptions , true , true , false ) ; }
|
Returns whether the alphanumeric value of the given strings end with any of the supplied options .
|
14,785
|
private static function startsWithInternal ( $ stringOrStrings , $ optionOrOptions , $ matchEnd , $ alphanumeric , $ caseInsensitive ) { $ strings = is_array ( $ stringOrStrings ) ? $ stringOrStrings : [ $ stringOrStrings ] ; $ options = is_array ( $ optionOrOptions ) ? $ optionOrOptions : [ $ optionOrOptions ] ; foreach ( $ strings as $ string ) { $ stringMatched = false ; if ( $ alphanumeric ) { $ string = self :: sanitizeAlphanumeric ( $ string ) ; } foreach ( $ options as $ option ) { if ( $ alphanumeric ) { $ option = self :: sanitizeAlphanumeric ( $ option ) ; } if ( strlen ( $ option ) <= strlen ( $ string ) && substr_compare ( $ string , $ option , $ matchEnd ? - strlen ( $ option ) : 0 , strlen ( $ option ) , $ caseInsensitive ) === 0 ) { $ stringMatched = true ; break ; } } if ( ! $ stringMatched ) { return false ; } } return true ; }
|
Internal method used by all startsWith and endsWith methods to keep code in one place .
|
14,786
|
public static function encodeUri ( $ uri ) { $ uri = self :: removeSchemeFromUri ( $ uri , $ scheme ) ; $ uri = rawurlencode ( $ uri ) ; $ uri = str_replace ( "%2F" , "/" , $ uri ) ; return $ scheme . $ uri ; }
|
Encodes a full URI leaving the slashes and scheme intact .
|
14,787
|
public static function formatPath ( $ pathOrPaths , ... $ additionalPaths ) { $ path = rawurldecode ( self :: mergePaths ( $ pathOrPaths , ... $ additionalPaths ) ) ; $ path = self :: removeSchemeFromUri ( $ path , $ scheme ) ; $ replacements = 0 ; do { $ path = str_replace ( [ "/./" , "//" ] , "/" , $ path , $ replacements ) ; } while ( $ replacements > 0 ) ; $ pathParts = explode ( "/" , $ path ) ; $ ignoredParts = 0 ; do { $ parentKey = array_search ( ".." , array_slice ( $ pathParts , $ ignoredParts , null , true ) ) ; if ( $ parentKey > 0 ) { switch ( $ pathParts [ $ parentKey - 1 ] ) { case "" : unset ( $ pathParts [ $ parentKey ] ) ; break ; case ".." : $ ignoredParts ++ ; break ; default : unset ( $ pathParts [ $ parentKey - 1 ] ) ; unset ( $ pathParts [ $ parentKey ] ) ; break ; } $ pathParts = array_values ( $ pathParts ) ; } else { $ ignoredParts ++ ; } } while ( $ parentKey !== false ) ; $ path = implode ( "/" , $ pathParts ) ; return $ scheme . $ path ; }
|
Formats a file path to a uniform representation . Multiple paths can be given and will be concatenated .
|
14,788
|
public static function formatAndResolvePath ( $ pathOrPaths , ... $ additionalPaths ) { $ path = rawurldecode ( self :: mergePaths ( $ pathOrPaths , ... $ additionalPaths ) ) ; $ path = realpath ( $ path ) ; if ( ! $ path ) { throw new DataHandlingException ( "Given path does not exist." ) ; } return self :: formatPath ( $ path ) ; }
|
Resolves and formats a path .
|
14,789
|
public static function mergePaths ( $ pathOrPaths , ... $ additionalPaths ) { if ( is_array ( $ pathOrPaths ) ) { $ paths = $ pathOrPaths ; } else { $ paths = array_merge ( [ $ pathOrPaths ] , $ additionalPaths ) ; } $ paths = array_values ( $ paths ) ; $ prefix = "" ; $ suffix = "" ; if ( count ( $ paths ) > 0 ) { if ( self :: startsWith ( $ paths [ 0 ] , [ "/" , "\\" ] ) ) { $ prefix = "/" ; } if ( self :: endsWith ( $ paths [ count ( $ paths ) - 1 ] , [ "/" , "\\" ] ) ) { $ suffix = "/" ; } } array_walk ( $ paths , function ( & $ path ) { $ path = str_replace ( "\\" , "/" , $ path ) ; $ path = trim ( $ path , "/" ) ; } ) ; $ paths = array_filter ( $ paths ) ; $ path = implode ( "/" , $ paths ) ; if ( $ path ) { $ path .= $ suffix ; } return $ prefix . $ path ; }
|
Merges path parts into one path . Only the first argument can cause the path to become absolute .
|
14,790
|
public static function makePathRelative ( $ path , $ rootDirectory ) { $ rootDirectory = self :: formatDirectory ( $ rootDirectory ) ; $ path = self :: formatPath ( $ path ) ; if ( ! self :: startsWith ( self :: formatDirectory ( $ path ) , $ rootDirectory ) ) { throw new DataHandlingException ( "Path is not part of the given root directory." ) ; } return substr_replace ( $ path , "" , 0 , strlen ( $ rootDirectory ) ) ; }
|
Makes given path relative to the given root directory .
|
14,791
|
public static function formatDirectory ( $ pathOrPaths , ... $ additionalPaths ) { $ directory = self :: formatPath ( $ pathOrPaths , ... $ additionalPaths ) ; if ( $ directory ) { $ directory = rtrim ( $ directory , "/" ) . "/" ; } return $ directory ; }
|
Formats a directory path to a uniform representation . Basically formatPath but with a trailing slash .
|
14,792
|
public static function formatAndResolveDirectory ( $ pathOrPaths , ... $ additionalPaths ) { $ directory = self :: formatAndResolvePath ( $ pathOrPaths , ... $ additionalPaths ) ; if ( $ directory ) { $ directory = rtrim ( $ directory , "/" ) . "/" ; } return $ directory ; }
|
Resolves and formats a directory .
|
14,793
|
public static function formatBytesize ( $ size ) { $ suffixes = [ "B" , "KiB" , "MiB" , "GiB" , "TiB" ] ; $ level = 1 ; for ( $ exponent = 0 ; $ exponent < count ( $ suffixes ) ; $ exponent ++ ) { $ nextLevel = pow ( 1024 , $ exponent + 1 ) ; if ( $ nextLevel > $ size ) { $ smallSize = $ size / $ level ; if ( $ smallSize < 10 ) { $ decimals = 2 ; } elseif ( $ smallSize < 100 ) { $ decimals = 1 ; } else { $ decimals = 0 ; } return round ( $ smallSize , $ decimals ) . " " . $ suffixes [ $ exponent ] ; } $ level = $ nextLevel ; } return "Large." ; }
|
Returns a suffixed and shortened indication of an amount of bytes .
|
14,794
|
public function authenticateSocial ( $ authResponse ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ return = false ; $ providerkey = $ authResponse [ 'auth' ] [ 'uid' ] ; $ query = 'SELECT * FROM `user_social` WHERE `providerkey` = ' . $ this -> db -> quoteValue ( $ providerkey ) ; $ users = $ this -> db -> query ( $ query ) [ 0 ] ; $ this -> debug -> table ( $ users , 'users' ) ; if ( $ users ) { $ userid = $ users [ 0 ] [ 'userid' ] ; $ this -> log ( 'login' , $ userid , array ( 'provider' => $ authResponse [ 'auth' ] [ 'provider' ] ) ) ; $ return = $ userid ; } $ this -> debug -> groupEnd ( ) ; return $ return ; }
|
check if auth response user exists in auth_social table does not load any user info
|
14,795
|
public function create ( $ vals ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ return = array ( 'success' => true , 'errorDesc' => '' , 'userid' => null , ) ; $ noQuoteCols = array ( 'createdon' , 'lastactivity' , ) ; $ vals = array_change_key_case ( $ vals ) ; $ vals [ 'createdon' ] = 'NOW()' ; $ vals [ 'lastactivity' ] = 'NOW()' ; $ valsOther = array ( ) ; $ cols = $ this -> db -> getColProperties ( 'user' ) ; $ this -> debug -> table ( $ cols , 'cols' ) ; $ col_names = array_keys ( $ cols ) ; foreach ( $ vals as $ k => $ v ) { if ( isset ( $ this -> cfg [ 'userForeignKeys' ] [ $ k ] ) ) { $ fka = $ this -> cfg [ 'userForeignKeys' ] [ $ k ] ; $ k_new = $ fka [ 'userCol' ] ; $ v_new = Str :: quickTemp ( '(' . $ fka [ 'getValQuery' ] . ')' , array ( 'value' => $ this -> db -> quoteValue ( $ v ) ) ) ; unset ( $ vals [ $ k ] ) ; $ vals [ $ k_new ] = $ v_new ; $ noQuoteCols [ ] = $ k_new ; } elseif ( ! in_array ( $ k , $ col_names ) ) { $ valsOther [ $ k ] = $ v ; unset ( $ vals [ $ k ] ) ; } } $ result = $ this -> db -> rowMan ( 'user' , $ vals , null , $ noQuoteCols ) ; $ this -> debug -> log ( 'result' , $ result ) ; if ( $ result ) { $ this -> debug -> info ( 'user created' ) ; $ userid = $ result ; $ this -> log ( 'userCreate' , $ userid ) ; if ( ! empty ( $ valsOther ) ) { $ return = $ this -> update ( $ valsOther , $ userid ) ; } $ return [ 'userid' ] = $ userid ; } else { $ return [ 'success' ] = false ; $ return [ 'errorDesc' ] = $ this -> db -> error ; } $ this -> debug -> log ( 'return' , $ return ) ; $ this -> debug -> groupEnd ( ) ; return $ return ; }
|
Creates user in DB Does NOT load user into current session
|
14,796
|
public function logout ( ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; if ( $ this -> auth ) { $ this -> setPersistToken ( false ) ; $ this -> log ( 'logout' ) ; } ArrayUtil :: path ( $ _SESSION , $ this -> cfg [ 'sessionPath' ] , array ( ) ) ; $ this -> userid = null ; $ this -> auth = 0 ; $ this -> debug -> groupEnd ( ) ; return ; }
|
Log user out
|
14,797
|
public function search ( $ vals ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ this -> debug -> log ( 'vals' , $ vals ) ; $ return = array ( ) ; if ( $ vals ) { $ where = array ( ) ; $ where_or = array ( ) ; if ( ! empty ( $ vals [ 'username' ] ) ) { $ where_or [ ] = '`username` = ' . $ this -> db -> quoteValue ( $ vals [ 'username' ] ) ; unset ( $ vals [ 'username' ] ) ; } if ( ! empty ( $ vals [ 'email' ] ) ) { $ where_or [ ] = '`email` = ' . $ this -> db -> quoteValue ( $ vals [ 'email' ] ) ; unset ( $ vals [ 'email' ] ) ; } if ( $ where_or ) { $ where [ ] = '( ' . implode ( ' OR ' , $ where_or ) . ' )' ; } foreach ( $ vals as $ k => $ v ) { $ col = '`' . $ k . '`' ; if ( $ k == 'userid' ) { $ col = '`user`.' . $ col ; } $ where [ ] = $ col . ' = ' . $ this -> db -> quoteValue ( $ v ) ; } $ where = ! empty ( $ where ) ? ' WHERE ' . implode ( ' AND ' , $ where ) : '' ; $ query = 'SELECT * FROM `user`' . ' LEFT JOIN `user_auth` USING (`userid`)' . $ where ; $ return = $ this -> db -> query ( $ query ) [ 0 ] ; } $ this -> debug -> table ( $ return , 'return' ) ; $ this -> debug -> groupEnd ( ) ; return $ return ; }
|
search for user by username email or userid
|
14,798
|
public function setCurrent ( $ userid ) { $ this -> debug -> groupCollapsed ( __METHOD__ , $ userid ) ; Session :: start ( ) ; $ user = $ this -> get ( $ userid ) ; ArrayUtil :: path ( $ _SESSION , $ this -> cfg [ 'sessionPath' ] , array ( ) ) ; $ path = $ this -> cfg [ 'sessionPath' ] ; if ( ! \ is_array ( $ path ) ) { $ path = \ array_filter ( \ preg_split ( '#[\./]#' , $ path ) , 'strlen' ) ; } $ this -> user = & $ _SESSION ; foreach ( $ path as $ k ) { if ( ! isset ( $ this -> user [ $ k ] ) ) { $ this -> user [ $ k ] = array ( ) ; } $ this -> user = & $ this -> user [ $ k ] ; } $ this -> user = $ user ; $ this -> user [ '_ts_cur' ] = time ( ) ; $ this -> userid = $ this -> user [ 'userid' ] ; $ this -> update ( array ( 'lastactivity' => 'NOW()' ) ) ; $ this -> debug -> groupEnd ( ) ; return ; }
|
Set current user by userid
|
14,799
|
public function setPersistToken ( $ set = true ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ cookieParams = $ this -> cfg [ 'persistCookie' ] ; $ return = null ; if ( $ set ) { $ token = $ this -> genToken ( ) ; $ cookieParams [ 'value' ] = array ( 'username' => $ this -> user [ 'username' ] , 'token' => $ token , ) ; Cookie :: set ( $ cookieParams ) ; $ values = array ( 'userid' => $ this -> userid , 'token_hash' => sha1 ( $ token ) , ) ; $ this -> db -> rowMan ( 'persist_tokens' , $ values ) ; $ return = $ cookieParams [ 'value' ] ; } elseif ( isset ( $ _COOKIE [ $ cookieParams [ 'name' ] ] ) ) { $ vals = Cookie :: get ( $ cookieParams [ 'name' ] ) ; if ( is_array ( $ vals ) && isset ( $ vals [ 'username' ] ) && isset ( $ vals [ 'token' ] ) ) { $ userid = null ; if ( isset ( $ this -> user [ 'username' ] ) && $ this -> user [ 'username' ] === $ vals [ 'username' ] ) { $ userid = $ this -> userid ; } else { $ users = $ this -> search ( array ( 'username' => $ vals [ 'username' ] ) ) ; if ( $ users ) { $ userid = $ users [ 0 ] [ 'userid' ] ; } } if ( $ userid ) { $ where = array ( 'userid' => $ userid , 'token_hash' => sha1 ( $ vals [ 'token' ] ) , ) ; $ this -> db -> rowMan ( 'persist_tokens' , null , $ where ) ; } $ cookieParams [ 'value' ] = null ; Cookie :: set ( $ cookieParams ) ; } } $ this -> debug -> groupEnd ( ) ; return $ return ; }
|
sets cookie stores unsalted SHA1 hash in db
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.