idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
13,500
|
public static function lastIndexOf ( $ string , $ needle , $ strict = true , $ offset = 0 ) { if ( $ strict ) { return mb_strrpos ( $ string , $ needle , $ offset ) ; } return mb_strripos ( $ string , $ needle , $ offset ) ; }
|
Grab the index of the last matched character .
|
13,501
|
public static function listing ( $ items , $ glue = ' & ' , $ sep = ', ' ) { if ( is_array ( $ items ) ) { $ lastItem = array_pop ( $ items ) ; if ( count ( $ items ) === 0 ) { return $ lastItem ; } $ items = implode ( $ sep , $ items ) ; $ items = $ items . $ glue . $ lastItem ; } return $ items ; }
|
Creates a comma separated list with the last item having an ampersand prefixing it .
|
13,502
|
public static function shorten ( $ string , $ limit = 25 , $ glue = ' … ' ) { if ( mb_strlen ( $ string ) > $ limit ) { $ width = round ( $ limit / 2 ) ; $ pre = mb_substr ( $ string , 0 , $ width ) ; if ( mb_substr ( $ pre , - 1 ) !== ' ' && ( $ i = static :: lastIndexOf ( $ pre , ' ' ) ) ) { $ pre = mb_substr ( $ pre , 0 , $ i ) ; } $ suf = mb_substr ( $ string , - $ width ) ; if ( mb_substr ( $ suf , 0 , 1 ) !== ' ' && ( $ i = static :: indexOf ( $ suf , ' ' ) ) ) { $ suf = mb_substr ( $ suf , $ i ) ; } return trim ( $ pre ) . $ glue . trim ( $ suf ) ; } return $ string ; }
|
If a string is too long shorten it in the middle while also respecting whitespace and preserving words .
|
13,503
|
public static function startsWith ( $ string , $ needle , $ strict = true ) { $ start = static :: extract ( $ string , 0 , mb_strlen ( $ needle ) ) ; if ( $ strict ) { return ( $ start === $ needle ) ; } return ( mb_strtolower ( $ start ) === mb_strtolower ( $ needle ) ) ; }
|
Checks to see if the string starts with a specific value .
|
13,504
|
protected function AddRichTextField ( $ name , $ value = '' ) { $ renderer = new CKEditorRenderer ( PathUtil :: BackendRTEPath ( ) , PathUtil :: BackendRTEUrl ( ) , PathUtil :: UploadPath ( ) , PathUtil :: UploadUrl ( ) , self :: Guard ( ) ) ; $ field = new Custom ( $ renderer ) ; $ field -> SetName ( $ name ) ; $ field -> SetValue ( $ value ) ; $ this -> AddField ( $ field ) ; return $ field ; }
|
Adds a field with the default rich text editor
|
13,505
|
function addpath ( $ name , $ fspath , $ overwrite = false ) { if ( ! $ overwrite && isset ( $ this -> registeredpaths [ $ name ] ) ) { throw new Panic ( "A path is already registered for $name." ) ; } else { $ this -> registeredpaths [ $ name ] = $ fspath ; } }
|
Registers a path under a specified name .
|
13,506
|
function path ( $ name , $ null_on_failure = false ) { if ( ! isset ( $ this -> registeredpaths [ $ name ] ) ) { if ( $ null_on_failure ) { return null ; } else { throw new Panic ( "There is no path registered for $name." ) ; } } else { return $ this -> registeredpaths [ $ name ] ; } }
|
Retrieves the specified path . If the path is not registered the method will Panic unless the second parameter is set in which case it will just return null .
|
13,507
|
public function addListener ( DBListener $ listener , $ name = null ) { if ( $ name !== null ) $ this -> listeners -> offsetSet ( $ name , $ listener ) ; else $ this -> listeners -> append ( $ listener ) ; }
|
Adds a DBListener to listen on some events of the DB class
|
13,508
|
protected function triggerListeners ( $ method , array $ params = array ( ) ) { if ( $ this -> muteListeners === true ) return ; $ this -> muteListeners = true ; foreach ( $ this -> listeners as $ l ) { call_user_func_array ( array ( $ l , $ method ) , $ params ) ; } $ this -> muteListeners = false ; }
|
Triggers a call of a specific method from all registered listener classes if the listeners are not set to mute
|
13,509
|
public function read ( $ chat , $ route , $ nameReader = 'random' ) { $ queue = new \ AMQPQueue ( $ this -> channel ) ; $ queue -> setName ( $ nameReader ) ; $ queue -> declare ( ) ; $ queue -> bind ( $ chat , $ route ) ; $ envelop = $ queue -> get ( ) ; if ( $ envelop ) { $ queue -> ack ( $ envelop -> getDeliveryTag ( ) ) ; return $ envelop ; } return false ; }
|
Read current message
|
13,510
|
public function readAll ( $ chat , $ route , $ nameReader ) { $ queue = new \ AMQPQueue ( $ this -> channel ) ; $ queue -> setName ( $ nameReader ) ; $ queue -> declare ( ) ; $ queue -> bind ( $ chat , $ route ) ; $ result = [ ] ; while ( $ envelop = $ queue -> get ( ) ) { $ queue -> ack ( $ envelop -> getDeliveryTag ( ) ) ; $ result [ ] = $ envelop ; } return $ result ; }
|
Read all messages
|
13,511
|
final public function resizeImage ( $ width = null , $ height = null ) { if ( is_int ( $ width ) and is_int ( $ height ) ) { $ new_image = imagecreatetruecolor ( $ width , $ height ) ; imagecopyresampled ( $ new_image , $ this -> _image_handle , 0 , 0 , 0 , 0 , $ width , $ height , $ this -> imageWidth ( ) , $ this -> imageHeight ( ) ) ; if ( is_resource ( $ new_image ) ) { $ this -> _image_handle = $ new_image ; } } return $ this ; }
|
Resize an image to an exact width and height
|
13,512
|
final public function rotateImage ( $ angle = 0 , array $ bgd_color = array ( 0 , 0 , 0 , 127 ) , $ ignore_transparent = false ) { $ this -> _image_handle = imagerotate ( $ this -> _image_handle , $ angle , $ this -> _createImageColorAlpha ( $ bgd_color ) , $ ignore_transparent ? 1 : 0 ) ; }
|
Rotate an image with a given angle
|
13,513
|
final protected function _createImageColorAlpha ( array $ rgba = array ( ) ) { $ keys = array ( 'r' , 'g' , 'b' , 'a' ) ; $ rgba = array_filter ( $ rgba , 'is_int' ) ; $ rgba = array_map ( 'abs' , $ rgba ) ; $ rgba = array_pad ( $ rgba , count ( $ keys ) , 0 ) ; $ rgba = array_slice ( $ rgba , 0 , count ( $ keys ) ) ; $ rgba = array_combine ( $ keys , $ rgba ) ; extract ( $ rgba ) ; return imagecolorallocatealpha ( $ this -> _image_handle , min ( $ r , 255 ) , min ( $ g , 255 ) , min ( $ b , 255 ) , min ( $ a , 127 ) ) ; }
|
Allocate a color for an image
|
13,514
|
final public function imagePNG ( $ filename = null , $ quality = - 1 , $ filters = PNG_NO_FILTER ) { return imagepng ( $ this -> _image_handle , $ filename , $ quality , $ filters ) ; }
|
Output a PNG image to either the browser or a file
|
13,515
|
final public function saveImage ( $ filename ) { $ extension = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( ! is_string ( $ extension ) ) { $ extension = image_type_to_extension ( $ this -> _image_type ) ; $ filename .= ".{$extension}" ; } switch ( strtolower ( $ extension ) ) { case 'jpeg' : case 'jpg' : return $ this -> imageJPEG ( $ filename ) ; break ; case 'png' : return $ this -> imagePNG ( $ filename ) ; break ; case 'gif' : return $ this -> imageGIF ( $ filename ) ; default : trigger_error ( 'Invalid extension or not an image' , E_USER_WARNING ) ; return false ; } }
|
Generic save funciton which converts image according to extension
|
13,516
|
final public function imageAsDOMElement ( $ as = null ) { $ dom = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ image = $ dom -> appendChild ( $ dom -> createElement ( 'img' ) ) ; $ image -> setAttribute ( 'height' , $ this -> imageHeight ( ) ) ; $ image -> setAttribute ( 'width' , $ this -> imageWidth ( ) ) ; $ image -> setAttribute ( 'alt' , $ this -> alt_text ) ; $ image -> setAttribute ( 'src' , $ this -> dataURI ( $ as ) ) ; return $ image ; }
|
Create a DOMElement containing attributes of the image
|
13,517
|
final public function imageAsString ( $ as = null ) { $ image = $ this -> imageAsDOMElement ( $ as ) ; return $ image -> ownerDocument -> saveHTML ( $ image ) ; }
|
Uses imageAsDOMElement and returns it as an HTML string
|
13,518
|
final public function dataURI ( $ as = null ) { $ mime = is_int ( $ as ) ? image_type_to_mime_type ( $ as ) : $ this -> _image_mime ; return 'data:' . $ mime . ';base64,' . base64_encode ( $ this -> imageAsBinary ( $ as ) ) ; }
|
Converts image to a base64 encoded string
|
13,519
|
protected static function makeStatement ( $ statement ) { $ self = self :: getInstance ( ) ; $ optionWhere = ( ! empty ( $ self -> optionWhere ) ) ? " WHERE " . substr ( implode ( "" , $ self -> optionWhere ) , 4 ) : null ; $ optionJoin = implode ( "" , $ self -> optionJoin ) ; $ optionOrder = $ self -> optionOrder ; $ optionLimit = $ self -> optionLimit ; return $ statement . $ optionJoin . $ optionWhere . $ optionOrder . $ optionLimit ; }
|
Make Query Statement
|
13,520
|
protected static function makeMultipleInsert ( $ table , $ data ) { $ insert_values = array ( ) ; foreach ( $ data as $ d ) { $ insert_values = array_merge ( $ insert_values , array_values ( $ d ) ) ; $ count = count ( $ d ) ; $ array = array_fill ( 0 , $ count , '?' ) ; $ placeholder [ ] = '(' . implode ( ',' , $ array ) . ')' ; } $ column = implode ( ',' , array_keys ( $ data [ 0 ] ) ) ; $ values = implode ( ',' , $ placeholder ) ; $ query = "INSERT INTO {$table} ({$column}) VALUES {$values}" ; return [ $ query , $ insert_values ] ; }
|
Make Multiple Insert Parameter
|
13,521
|
protected static function makeUpdateParameter ( $ data ) { foreach ( $ data as $ field => $ value ) { $ newData [ ] = "{$field}=:{$field}" ; } $ newData = implode ( "," , $ newData ) ; return $ newData ; }
|
Make Update Parameter
|
13,522
|
protected static function makeSelect ( ) { $ self = self :: getInstance ( ) ; $ select = ( ! empty ( $ self -> optionSelect ) ) ? $ self -> optionSelect : "*" ; return "SELECT {$select} FROM {$self->table_name} " ; }
|
Make Select Query
|
13,523
|
protected static function makeEmpty ( ) { $ self = self :: getInstance ( ) ; $ self -> optionWhere = [ ] ; $ self -> optionWhereData = [ ] ; $ self -> optionJoin = [ ] ; $ self -> optionLimit = null ; $ self -> optionSelect = null ; $ self -> table_name = null ; return $ self ; }
|
Empty All Option
|
13,524
|
protected function makeArrayOfWhere ( $ array , $ type ) { $ self = self :: getInstance ( ) ; if ( array_key_exists ( 0 , $ array ) ) : foreach ( $ array as $ a ) : $ make = [ 'parameter' => str_replace ( "." , "_" , $ a [ 0 ] ) , 'column' => $ a [ 0 ] , 'operator' => $ a [ 1 ] , 'value' => ( isset ( $ a [ 2 ] ) ) ? $ a [ 2 ] : null , ] ; $ where = $ self -> makeWhere ( $ make [ 'parameter' ] , $ make [ 'column' ] , $ make [ 'operator' ] , $ make [ 'value' ] ) ; $ whereData = $ self -> makeOptionWhere ( $ make [ 'parameter' ] , $ make [ 'column' ] , $ make [ 'operator' ] , $ make [ 'value' ] ) ; array_push ( $ self -> optionWhere , $ type . $ where ) ; $ self -> optionWhereData = array_merge ( $ self -> optionWhereData , [ ":where_{$make['parameter']}" => $ whereData ] ) ; endforeach ; else : foreach ( $ array as $ a => $ v ) : $ param = str_replace ( "." , "_" , $ a ) ; $ where = $ self -> makeWhere ( $ param , $ a , '=' , $ v ) ; $ whereData = $ self -> makeOptionWhere ( $ param , $ a , '=' , $ v ) ; array_push ( $ self -> optionWhere , $ type . $ where ) ; $ self -> optionWhereData = array_merge ( $ self -> optionWhereData , [ ":where_{$param}" => $ whereData ] ) ; endforeach ; endif ; return $ self ; }
|
Make Where Array
|
13,525
|
protected function makeStringOfWhere ( $ column , $ operator = null , $ value = null , $ type ) { $ self = self :: getInstance ( ) ; $ param = str_replace ( "." , "_" , $ column ) ; $ where = $ self -> makeWhere ( $ param , $ column , $ operator , $ value ) ; $ whereData = $ self -> makeOptionWhere ( $ param , $ column , $ operator , $ value ) ; array_push ( $ self -> optionWhere , $ type . $ where ) ; $ self -> optionWhereData = array_merge ( $ self -> optionWhereData , [ ":where_{$param}" => $ whereData ] ) ; return $ self ; }
|
Make String Where
|
13,526
|
public static function insert ( $ data ) { $ self = self :: getInstance ( ) ; $ table = $ self -> table_name ; if ( isset ( $ data [ 0 ] ) ) { $ make = $ self -> makeMultipleInsert ( $ table , $ data ) ; $ statement = $ make [ 0 ] ; $ value = $ make [ 1 ] ; } else { $ newData = $ self -> makeInsertParameter ( $ data ) ; $ column = implode ( "," , array_keys ( $ data ) ) ; $ paramValue = implode ( "," , array_keys ( $ newData ) ) ; $ statement = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});" ; $ value = $ newData ; } $ execute = $ self -> exec ( $ statement , $ value ) ; return $ execute ; }
|
Insert & Multiple Insert
|
13,527
|
public function increment ( $ column , $ value = null , $ where = [ ] , $ operator = "+" ) { return self :: getInstance ( ) -> makeIncreDecrement ( $ column , $ value , $ where , $ operator ) ; }
|
Increment & Decrement
|
13,528
|
public static function get ( ) { $ self = self :: getInstance ( ) ; $ statement = $ self -> makeSelect ( ) ; $ execute = $ self -> exec ( $ statement , [ ] ) ; return $ execute -> fetchAll ( \ PDO :: FETCH_CLASS ) ; }
|
Get All Record
|
13,529
|
public static function first ( ) { $ self = self :: getInstance ( ) ; $ statement = $ self -> makeSelect ( ) ; $ execute = $ self -> exec ( $ statement , [ ] ) ; return $ execute -> fetchObject ( ) ; }
|
Get First Record
|
13,530
|
public function write ( & $ result ) { $ entity = $ this -> accessor -> getPropertyValue ( $ result , $ this -> definition -> container ( ) ) ; if ( empty ( $ entity ) ) { $ conditions = [ ] ; foreach ( $ this -> definition -> keys ( ) as $ local => $ foreign ) { $ conditions [ $ foreign ] [ ] = $ this -> accessor -> getPropertyValue ( $ result , $ local ) ; } $ this -> cleanup ( $ this -> definition -> entity ( ) , [ ] , $ conditions ) ; return $ result ; } $ this -> assertInstance ( $ entity ) ; foreach ( $ this -> definition -> keys ( ) as $ local => $ foreign ) { $ this -> accessor -> setPropertyValue ( $ entity , $ foreign , $ this -> accessor -> getPropertyValue ( $ result , $ local ) ) ; } $ this -> storage -> write ( $ entity , $ this -> definition -> entity ( ) ) -> execute ( ) ; $ this -> accessor -> setPropertyValue ( $ result , $ this -> definition -> container ( ) , $ entity ) ; return $ result ; }
|
Executes write fro one - to - one relation
|
13,531
|
protected function encrypt ( $ string ) { if ( $ this -> config [ 'cookie' ] [ 'encrypt_cookie' ] ) { if ( ! function_exists ( 'mcrypt_encrypt' ) ) { throw new \ BadMethodCallException ( 'The Session Cookie driver requires the PHP mcrypt extension to be installed.' ) ; } $ key = hash ( 'SHA256' , $ this -> config [ 'cookie' ] [ 'crypt_key' ] , true ) ; $ iv = mcrypt_create_iv ( mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_128 , MCRYPT_MODE_CBC ) , MCRYPT_RAND ) ; if ( strlen ( $ iv_base64 = rtrim ( base64_encode ( $ iv ) , '=' ) ) != 22 ) { return false ; } $ string = $ iv_base64 . base64_encode ( mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $ key , $ string . md5 ( $ string ) , MCRYPT_MODE_CBC , $ iv ) ) ; } return $ string ; }
|
Encrypts a string using the crypt_key configured in the config
|
13,532
|
protected function decrypt ( $ string ) { if ( $ this -> config [ 'cookie' ] [ 'encrypt_cookie' ] ) { if ( ! function_exists ( 'mcrypt_decrypt' ) ) { throw new \ BadMethodCallException ( 'The Session Cookie driver requires the PHP mcrypt extension to be installed.' ) ; } $ key = hash ( 'SHA256' , $ this -> config [ 'cookie' ] [ 'crypt_key' ] , true ) ; $ iv = base64_decode ( substr ( $ string , 0 , 22 ) . '==' ) ; $ string = substr ( $ string , 22 ) ; $ string = rtrim ( mcrypt_decrypt ( MCRYPT_RIJNDAEL_128 , $ key , base64_decode ( $ string ) , MCRYPT_MODE_CBC , $ iv ) , "\0\4" ) ; $ hash = substr ( $ string , - 32 ) ; $ string = substr ( $ string , 0 , - 32 ) ; if ( md5 ( $ string ) != $ hash ) { return false ; } } return $ string ; }
|
Decrypts a string using the crypt_key configured in the config
|
13,533
|
public function getAdapter ( ) { if ( $ this -> _adapter === null ) { $ this -> _adapter = Zend_Db_Table_Abstract :: getDefaultAdapter ( ) ; if ( null === $ this -> _adapter ) { throw new Zend_Validate_Exception ( 'No database adapter present' ) ; } } return $ this -> _adapter ; }
|
Returns the set adapter
|
13,534
|
public function getRequest ( $ autoInit = false ) { $ this -> setAutoInitRequest ( $ autoInit ) ; if ( $ this -> request == null && $ this -> isAutoInitRequest ( ) ) { $ this -> initRequest ( ) ; } return $ this -> request ; }
|
Get the Request .
|
13,535
|
public function addScheduleMenuItem ( UserMenuCollectionEvent $ event ) : void { $ menu = $ event -> getMenu ( ) ; $ separator = $ this -> factory -> createItem ( 'schedule_separator' , [ 'extras' => [ 'separator' => true , 'translation_domain' => false , ] , ] ) ; $ menu -> addChild ( $ separator ) ; $ schedule = $ this -> factory -> createItem ( 'menu_item.my_schedule' , [ 'route' => 'bkstg_calendar_personal' , 'extras' => [ 'icon' => 'calendar' , 'translation_domain' => BkstgScheduleBundle :: TRANSLATION_DOMAIN , ] , ] ) ; $ menu -> addChild ( $ schedule ) ; }
|
Add the schedule items to the user menu .
|
13,536
|
public function addInvitationsMenuItem ( UserMenuCollectionEvent $ event ) : void { $ menu = $ event -> getMenu ( ) ; $ repo = $ this -> em -> getRepository ( Invitation :: class ) ; $ user = $ this -> token_storage -> getToken ( ) -> getUser ( ) ; $ invitations = $ repo -> findPendingInvitations ( $ user ) ; $ invitations = $ this -> factory -> createItem ( 'menu_item.pending_invitations' , [ 'route' => 'bkstg_invitation_index' , 'extras' => [ 'badge_count' => count ( $ invitations ) , 'translation_domain' => BkstgScheduleBundle :: TRANSLATION_DOMAIN , ] , ] ) ; $ menu -> addChild ( $ invitations ) ; }
|
Add invitations menu item .
|
13,537
|
public function sanitize ( callable $ sanitizeCallback ) { foreach ( $ this -> val as $ lang => $ val ) { $ this -> val [ $ lang ] = call_user_func ( $ sanitizeCallback , $ val ) ; } return $ this ; }
|
Sanitize each language s string with a callback function .
|
13,538
|
public static function weekdays ( ) : array { $ days = self :: getAll ( ) ; $ weekDays = [ ] ; foreach ( $ days as $ key => $ day ) { if ( $ day -> isWeekDay ( ) ) { $ weekDays [ ] = $ day ; } } return $ weekDays ; }
|
Gets the weekdays .
|
13,539
|
public static function weekends ( ) : array { $ days = self :: getAll ( ) ; $ weekEndDays = [ ] ; foreach ( $ days as $ key => $ day ) { if ( $ day -> isWeekEnd ( ) ) { $ weekEndDays [ ] = $ day ; } } return $ weekEndDays ; }
|
Gets the weekend days .
|
13,540
|
public function getResponse ( ) : ResponseInterface { if ( ! $ this -> response ) { $ this -> response = ( new Client ( ) ) -> request ( 'GET' , $ this -> remoteUrl ) ; } return $ this -> response ; }
|
Returns the HTTP response .
|
13,541
|
public function getResponseHeaders ( ) : array { $ headers = [ ] ; foreach ( $ this -> getResponse ( ) -> getHeaders ( ) as $ header => $ values ) { if ( preg_grep ( '/^' . preg_quote ( $ header , '$/' ) . '/ui' , $ this -> acceptableProxyHeaders ) ) { $ headers [ $ header ] = $ values ; } } return $ headers ; }
|
Returns all the imported headers from the HTTP response .
|
13,542
|
protected static function typeof ( $ v ) : string { if ( is_bool ( $ v ) ) { return 'bool' ; } elseif ( is_int ( $ v ) ) { return 'int' ; } elseif ( is_float ( $ v ) ) { return 'float' ; } elseif ( is_string ( $ v ) ) { return 'string' ; } elseif ( is_array ( $ v ) ) { return 'array' ; } elseif ( is_resource ( $ v ) ) { return 'resource' ; } return get_class ( $ v ) ; }
|
More predictable results than gettype .
|
13,543
|
public function scopeProtectAdmins ( Builder $ query ) { $ user = auth ( ) -> user ( ) ; return ( $ user && $ user -> is_admin ) ? $ query : $ query -> where ( 'is_admin' , false ) ; }
|
Protect admins .
|
13,544
|
public function getDefaultValues ( ) { preg_match ( '/([0-9.]+)([A-Z]{3})/' , $ this -> config [ 'price' ] , $ matches ) ; $ this -> defaults [ 'price' ] = array ( 'currency' => ( ! empty ( $ this -> defaults [ 'price' ] [ 'currency' ] ) ? $ this -> defaults [ 'price' ] [ 'currency' ] : $ matches [ 2 ] ) , 'amount' => ( ! empty ( $ this -> defaults [ 'price' ] [ 'amount' ] ) ? $ this -> defaults [ 'price' ] [ 'amount' ] : $ matches [ 1 ] ) , 'vat' => ( ! empty ( $ this -> defaults [ 'price' ] [ 'vat' ] ) ? $ this -> defaults [ 'price' ] [ 'vat' ] : null ) , ) ; return $ this -> defaults ; }
|
Return default values .
|
13,545
|
protected function getSmsc ( $ number ) { $ adapter = $ this -> getAdapter ( ) ; $ adapter -> setEndpoint ( self :: SMSC_ENDPOINT ) ; $ adapter -> setParameters ( array ( 'user' => $ this -> config [ 'user' ] , 'password' => $ this -> config [ 'password' ] , 'msisdn' => $ number ) ) ; $ response = $ adapter -> get ( ) ; return $ response -> getBody ( ) ; }
|
Get smsc for a given mobile number .
|
13,546
|
public function getIpInfo ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ ipInfo = [ ] ; $ ipInfo [ 'country' ] = $ request -> server -> get ( 'GEOIP_COUNTRY_CODE' , null ) ; $ ipInfo [ 'city' ] = $ request -> server -> get ( 'GEOIP_CITY' , null ) ; $ ipInfo [ 'region' ] = $ request -> server -> get ( 'GEOIP_REGION_NAME' , null ) ; $ ipInfo [ 'ip' ] = $ request -> getClientIp ( ) ; return $ ipInfo ; }
|
Gets array with IP info and Geo Ip
|
13,547
|
public function getClassName ( ) { foreach ( $ this -> tokenlist as $ key => $ token ) { if ( T_CLASS === $ token [ 0 ] ) { return $ this -> tokenlist [ $ key + 2 ] [ 1 ] ; } } return '' ; }
|
Get the first classname
|
13,548
|
public function getNamespace ( ) { $ class = array ( ) ; $ inNamespace = false ; foreach ( $ this -> tokenlist as $ key => $ token ) { if ( T_NAMESPACE === $ token [ 0 ] ) { $ inNamespace = true ; continue ; } if ( T_STRING === $ token [ 0 ] && $ inNamespace ) { $ class [ ] = $ token [ 1 ] ; } if ( ';' === $ token && $ inNamespace ) { return $ class ; } } return array ( ) ; }
|
Get the first namespace of the given content
|
13,549
|
public function compose ( $ single = false ) { $ reflection = new \ ReflectionClass ( $ this -> class ) ; $ constructArgs = $ this -> constructArgs ; $ methodArgs = $ this -> methodArgs ; if ( $ single ) { static $ obj ; if ( $ obj == null ) { $ obj = ( new Asset ( $ this -> class ) ) -> single ( function ( ) use ( $ reflection , $ constructArgs , $ methodArgs ) { if ( $ constructArgs ) { $ object = $ reflection -> newInstanceArgs ( $ constructArgs ) ; } else { $ object = $ reflection -> newInstance ( ) ; } foreach ( $ methodArgs as $ method => $ params ) { if ( $ reflection -> hasMethod ( $ method ) ) { call_user_func_array ( [ $ object , $ method ] , $ params ) ; } } return $ object ; } ) ; } return $ obj ; } else { return new Asset ( $ this -> class , function ( ) use ( $ reflection , $ constructArgs , $ methodArgs ) { if ( $ constructArgs ) { $ object = $ reflection -> newInstanceArgs ( $ constructArgs ) ; } else { $ object = $ reflection -> newInstance ( ) ; } foreach ( $ methodArgs as $ method => $ params ) { if ( $ reflection -> hasMethod ( $ method ) ) { call_user_func_array ( [ $ object , $ method ] , $ params ) ; } } return $ object ; } ) ; } }
|
Build a configured Asset and return it .
|
13,550
|
public function connect ( float $ connectTimeout = 1.0 ) : Stream { $ errno = 0 ; $ errstr = '' ; $ fsockopen = $ this -> fsockopen ; $ resource = $ fsockopen ( $ this -> prefix . $ this -> host , $ this -> port , $ errno , $ errstr , $ connectTimeout ) ; if ( false === $ resource ) { throw new ConnectionFailure ( 'Connect to ' . $ this -> prefix . $ this -> host . ':' . $ this -> port . ' within ' . $ connectTimeout . ' second' . ( 1 == $ connectTimeout ? '' : 's' ) . ' failed: ' . $ errstr . ' (' . $ errno . ').' ) ; } return new Stream ( $ resource , $ this -> usesSsl ( ) ) ; }
|
opens a connection to host
|
13,551
|
public function createObjectSettingsAction ( $ object_id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ class_name = $ this -> container -> getParameter ( 'acs_settings.setting_class' ) ; $ object = $ em -> getRepository ( 'ACSACSPanelBundle:Service' ) -> find ( $ object_id ) ; $ object_fields = $ object -> getType ( ) -> getFieldTypes ( ) ; $ user = $ this -> get ( 'security.context' ) -> getToken ( ) -> getUser ( ) ; foreach ( $ object_fields as $ id => $ field_config ) { $ setting = $ em -> getRepository ( 'ACSACSPanelBundle:PanelSetting' ) -> findOneBy ( array ( 'user' => $ user -> getId ( ) , 'setting_key' => $ field_config -> getSettingKey ( ) , 'focus' => 'object_setting' , 'service' => $ object , ) ) ; if ( ! count ( $ setting ) ) { $ setting = new $ class_name ; $ setting -> setSettingKey ( $ field_config -> getSettingKey ( ) ) ; $ setting -> setValue ( $ field_config -> getDefaultValue ( ) ) ; $ setting -> setContext ( $ field_config -> getContext ( ) ) ; $ setting -> setLabel ( $ field_config -> getLabel ( ) ) ; $ setting -> setType ( $ field_config -> getType ( ) ) ; $ setting -> setFocus ( 'object_setting' ) ; $ setting -> setService ( $ object ) ; $ user -> addSetting ( $ setting ) ; $ em -> persist ( $ user ) ; $ em -> flush ( ) ; } } return $ this -> redirect ( $ this -> generateUrl ( 'settings' ) ) ; }
|
It creates the object settings specified
|
13,552
|
public function panelSettingsAction ( ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ user = $ this -> get ( 'security.context' ) -> getToken ( ) -> getUser ( ) ; $ settingmanager = $ this -> get ( 'acs.setting_manager' ) ; $ user_fields = $ settingmanager -> loadUserFields ( ) ; $ object_settings = $ settingmanager -> getObjectSettingsPrototype ( $ user ) ; array_merge ( $ user_fields , $ object_settings ) ; $ form = $ this -> createForm ( new ConfigSettingCollectionType ( $ user_fields , $ em ) , $ user ) ; $ contexts = $ settingmanager -> getContexts ( $ user ) ; return $ this -> render ( 'ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig' , array ( 'entity' => $ user , 'contexts' => $ contexts , 'form' => $ form -> createView ( ) , ) ) ; }
|
Displays a form with all the user settings
|
13,553
|
public function updateAction ( Request $ request , $ id ) { $ class_name = $ this -> container -> getParameter ( 'acs_settings.setting_class' ) ; $ settingmanager = $ this -> get ( 'acs.setting_manager' ) ; $ user_fields = $ settingmanager -> loadUserFields ( ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ this -> get ( 'security.context' ) -> getToken ( ) -> getUser ( ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find ConfigSetting entity.' ) ; } $ editForm = $ this -> createForm ( new ConfigSettingCollectionType ( $ user_fields , $ em ) , $ entity ) ; $ editForm -> bind ( $ request ) ; $ postData = $ request -> request -> get ( 'acs_settings_usersettings' ) ; if ( $ editForm -> isValid ( ) ) { if ( isset ( $ postData [ 'settings' ] ) ) { $ settings = $ postData [ 'settings' ] ; foreach ( $ settings as $ setting ) { $ args = array ( 'user' => $ entity -> getId ( ) , 'setting_key' => $ setting [ 'setting_key' ] , ) ; if ( isset ( $ setting [ 'service_id' ] ) ) { $ service = $ em -> getRepository ( 'ACSACSPanelBundle:Service' ) -> find ( $ setting [ 'service_id' ] ) ; $ args [ 'service' ] = $ service ; } $ panelsetting = $ em -> getRepository ( 'ACSACSPanelBundle:PanelSetting' ) -> findOneBy ( $ args ) ; if ( $ panelsetting && isset ( $ setting [ 'value' ] ) ) { $ panelsetting -> setValue ( $ setting [ 'value' ] ) ; $ em -> persist ( $ panelsetting ) ; $ em -> flush ( ) ; } } $ em -> flush ( ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'settings' ) ) ; } return $ this -> render ( 'ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig' , array ( 'entity' => $ entity , 'form' => $ editForm -> createView ( ) , ) ) ; }
|
Edits an existing ConfigSetting entity .
|
13,554
|
public static function validateType ( $ value ) { if ( get_called_class ( ) === $ value ) { return true ; } if ( array_key_exists ( $ value , class_implements ( get_called_class ( ) ) ) ) { return true ; } if ( array_key_exists ( $ value , class_parents ( get_called_class ( ) ) ) ) { return true ; } throw new InvalidDataTypeException ( __CLASS__ , new static ) ; }
|
Validate object type
|
13,555
|
public static function unFormatDecimal ( $ decimalString ) { if ( trim ( $ decimalString ) == '' ) { return NAN ; } $ decimalString = rtrim ( '+' , trim ( $ decimalString ) ) ; if ( preg_match ( '/^\-?\d+([,.]\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( ',' , '.' , $ decimalString ) ) ; } if ( preg_match ( '/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( array ( ',' , '\'' ) , array ( '' , '' ) , $ decimalString ) ) ; } if ( preg_match ( '/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( array ( '.' , ',' ) , array ( '' , '.' ) , $ decimalString ) ) ; } return ( float ) $ decimalString ; }
|
Strips decimal strings from everything but decimal point and negative prefix and returns the result as float
|
13,556
|
public function getRenderedEditor ( $ id , array $ options = array ( ) ) { $ config = clone $ this -> options ; $ config -> setFromArray ( $ options ) ; $ basePath = $ this -> getView ( ) -> basePath ( $ config -> getBasePath ( ) ) ; $ editor = new \ CKEditor ( $ basePath ) ; return $ editor -> replace ( $ id , $ this -> optionsToCKEditorConfig ( $ config ) ) ; }
|
Generates output needed for CKEditor .
|
13,557
|
protected function optionsToCKEditorConfig ( Options $ options ) { $ config = array ( ) ; foreach ( $ options -> toArray ( ) as $ key => $ value ) { if ( ! array_key_exists ( $ key , static :: $ optionsToConfigMap ) ) { continue ; } if ( in_array ( $ key , static :: $ optionsToPrependBasePath ) ) { if ( is_array ( $ value ) ) { foreach ( $ value as & $ deepValue ) { $ deepValue = $ this -> view -> basePath ( $ deepValue ) ; } } else { $ value = $ this -> view -> basePath ( $ value ) ; } } $ config [ static :: $ optionsToConfigMap [ $ key ] ] = $ value ; } return $ config ; }
|
Translates our internal Options object into a usable config array for CKEditor .
|
13,558
|
public function setDriver ( $ driver ) { if ( false === is_string ( $ driver ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ driver ) ) , E_USER_ERROR ) ; } if ( false === class_exists ( $ driver ) ) { $ driver = __NAMESPACE__ . '\\Driver\\' . $ driver ; if ( false === class_exists ( $ driver ) ) { return trigger_error ( sprintf ( 'Driver "%s" does not exists' , $ driver ) , E_USER_ERROR ) ; } } $ this -> driver = $ driver ; return $ this ; }
|
Sets the driver
|
13,559
|
private function call ( ) { if ( null === $ this -> driver ) { return trigger_error ( 'Driver is not set. Set the driver with the setDriver() method' , E_USER_ERROR ) ; } if ( null === $ this -> driverInstance ) { $ this -> driverInstance = new $ this -> driver ( ) ; } return $ this -> driverInstance ; }
|
Check if driver is set and returns it
|
13,560
|
public function encompasses ( TimeRange $ otherRange ) : bool { return $ this -> start -> isEarlierThanOrEqual ( $ otherRange -> start ) && $ this -> end -> isLaterThanOrEqual ( $ otherRange -> end ) ; }
|
Returns whether the supplied time range is encompassed by this time range .
|
13,561
|
static function getUploadDir ( $ withUploadUrl = TRUE ) { $ dir = __DIR__ . '/../../../../web/' ; if ( ! is_dir ( $ dir ) ) { $ dir = __DIR__ . '/../../../../../web' ; if ( ! is_dir ( $ dir ) ) { $ dir = __DIR__ . '/../../../../../../web' ; if ( ! is_dir ( $ dir ) ) { throw new \ Exception ( 'Upload dir not found' ) ; } } } if ( ! is_dir ( $ dir . self :: getUploadUrl ( ) ) ) { if ( ! is_writable ( $ dir ) ) { throw new \ Exception ( $ dir . ' is not writable' ) ; } else { mkdir ( $ dir . self :: getUploadUrl ( ) ) ; } } return $ withUploadUrl ? $ dir . self :: getUploadUrl ( ) : $ dir ; }
|
Get upload file dir
|
13,562
|
static public function getThumbFilename ( $ filename , $ mimeType , $ size ) { if ( substr ( $ mimeType , 0 , 5 ) == 'image' ) { $ pos = mb_strrpos ( $ filename , '.' ) ; if ( $ pos === FALSE ) { return $ filename . '_' . $ size [ 'width' ] . 'x' . $ size [ 'height' ] ; } else { return mb_substr ( $ filename , 0 , $ pos ) . '_' . $ size [ 'width' ] . 'x' . $ size [ 'height' ] . mb_substr ( $ filename , $ pos ) ; } } else if ( $ mimeType == 'application/pdf' ) { return $ GLOBALS [ 'kernel' ] -> getContainer ( ) -> get ( 'templating.helper.assets' ) -> getUrl ( 'bundles/fulguriolightcms/img/thumb_pdf.png' ) ; } else { return 'http://www.placehold.it/' . $ size [ 'width' ] . 'x' . $ size [ 'height' ] . '/EFEFEF/AAAAAA' ; } }
|
Get thumb filename for a specified size
|
13,563
|
protected function partial ( $ resource , array $ data = [ ] ) { if ( $ resource instanceof ViewModelInterface ) { return $ this -> view -> render ( $ resource , true ) ; } return $ this -> view -> render ( new ViewModel ( $ this -> view -> resolveResourcePath ( $ resource ) , $ data ) , true ) ; }
|
Render a partial view and return the generated output .
|
13,564
|
public function getProperty ( $ name ) { if ( $ this -> reflected -> hasProperty ( $ name ) ) return $ this -> annotations [ 'properties' ] [ $ name ] ; return null ; }
|
Returns the reflected parameter .
|
13,565
|
public function getMethod ( $ name ) { if ( $ this -> reflected -> hasMethod ( $ name ) ) return $ this -> annotations [ 'methods' ] [ $ name ] ; return null ; }
|
Returns the reflected method .
|
13,566
|
public function match ( $ method , $ url ) { $ params = array ( ) ; foreach ( $ this -> routes as $ name => $ route ) { if ( $ route -> isMatch ( $ method , $ url ) ) { $ params = $ route -> getMatchedParams ( ) ; break ; } } return $ params ; }
|
Loops through all of the registered routes and tries to find a match .
|
13,567
|
public function url ( $ name , $ params = array ( ) ) { if ( ! array_key_exists ( $ name , $ this -> routes ) ) { throw new \ UnexpectedValueException ( "A route with the name {$name} was not found" ) ; } $ route = $ this -> routes [ $ name ] ; return $ route -> url ( $ params ) ; }
|
Reverse routing helper .
|
13,568
|
public function getArray ( ) { $ errors = empty ( $ this -> errors ) ? null : $ this -> errors ; $ response = array ( 'status' => $ this -> getStatus ( ) , 'data' => $ this -> data , 'errors' => $ errors , ) ; if ( ! is_null ( $ this -> code ) ) { $ response [ 'code' ] = $ this -> code ; } if ( ! is_null ( $ this -> message ) ) { $ response [ 'message' ] = $ this -> message ; } return $ response ; }
|
Returns the array version of the request response
|
13,569
|
public function internalShutdownFunction ( ) { $ aError = error_get_last ( ) ; if ( ! $ this -> aConfig [ 'display_errors' ] && is_array ( $ aError ) && $ aError [ 'type' ] === E_ERROR ) { $ oException = new \ ErrorException ( $ aError [ 'message' ] , $ this -> aConfig [ 'default_error_code' ] , $ aError [ 'type' ] , $ aError [ 'file' ] , $ aError [ 'line' ] ) ; call_user_func ( $ this -> callbackGenericDisplay , $ oException ) ; } if ( ! empty ( $ this -> callbackAdditionalShutdownFct ) ) { call_user_func ( $ this -> callbackAdditionalShutdownFct ) ; } }
|
Registered shutdown function .
|
13,570
|
public function removeExcludedSimpleValue ( int $ index ) { if ( isset ( $ this -> simpleExcludedValues [ $ index ] ) ) { unset ( $ this -> simpleExcludedValues [ $ index ] ) ; -- $ this -> valuesCount ; } return $ this ; }
|
Remove a simple excluded value by index .
|
13,571
|
public function get ( string $ type ) : array { if ( ! isset ( $ this -> values [ $ type ] ) ) { return [ ] ; } return $ this -> values [ $ type ] ; }
|
Get all values from a specific type .
|
13,572
|
public function has ( string $ type ) : bool { return isset ( $ this -> values [ $ type ] ) && \ count ( $ this -> values [ $ type ] ) > 0 ; }
|
Get a single value by type and index .
|
13,573
|
public function remove ( string $ type , int $ index ) { if ( isset ( $ this -> values [ $ type ] [ $ index ] ) ) { unset ( $ this -> values [ $ type ] [ $ index ] ) ; -- $ this -> valuesCount ; } return $ this ; }
|
Remove a value by type and index .
|
13,574
|
public static function fromRgbString ( string $ string ) : Colour { list ( $ r , $ g , $ b ) = ColourStringParser :: parseRgbString ( $ string ) ; return new self ( $ r , $ g , $ b ) ; }
|
Creates a new colour from the supplied rgb string value
|
13,575
|
public static function fromHexString ( string $ string ) : Colour { list ( $ r , $ g , $ b ) = ColourStringParser :: parseHexString ( $ string ) ; return new self ( $ r , $ g , $ b ) ; }
|
Creates a new colour from the supplied hex value
|
13,576
|
public function toHexString ( ) : string { return '#' . sprintf ( '%02x' , $ this -> red ) . sprintf ( '%02x' , $ this -> green ) . sprintf ( '%02x' , $ this -> blue ) ; }
|
Gets the colour as a hex string .
|
13,577
|
protected function _call ( \ Communique \ RESTClientRequest $ request , $ debug = null ) { foreach ( $ this -> _interceptors as $ request_interceptor ) { $ request = $ request_interceptor -> request ( $ request ) ; } $ response = $ this -> _http -> request ( $ request ) ; foreach ( $ this -> _interceptors as $ response_interceptor ) { $ response = $ response_interceptor -> response ( $ response ) ; } if ( $ debug ) { $ debug ( $ request , $ response ) ; } return $ response ; }
|
Makes the HTTP request using the chosen HTTP client .
|
13,578
|
public function put ( $ url , $ payload , array $ headers = array ( ) , $ debug = null ) { $ request = new \ Communique \ RESTClientRequest ( 'put' , $ this -> _BASE_URL . $ url , $ payload , $ headers ) ; return $ this -> _call ( $ request , $ debug ) ; }
|
Make an HTTP PUT request
|
13,579
|
public function addMapping ( $ key , array $ accepted_names , $ required = true ) { $ lower_accepted_names = [ ] ; foreach ( $ accepted_names as $ name ) { $ lower_name = strtolower ( $ name ) ; if ( $ this -> getMapping ( $ lower_name ) !== false ) { throw new MappingOverlapException ( sprintf ( 'Column name %s already mapped on %s' , $ name , $ key ) ) ; } $ lower_accepted_names [ ] = $ lower_name ; } $ this -> mappings [ $ key ] = [ 'accepted_names' => $ lower_accepted_names , 'required' => $ required , 'index' => null , ] ; return $ this ; }
|
Add a mapping expectation
|
13,580
|
protected function getMapping ( $ name ) { foreach ( $ this -> mappings as $ key => $ data ) { if ( in_array ( strtolower ( $ name ) , $ data [ 'accepted_names' ] ) ) { return $ key ; } } return false ; }
|
Get a mapped column index
|
13,581
|
public function map ( array $ columns ) { $ maps = [ ] ; $ seenKeys = [ ] ; foreach ( $ columns as $ index => $ column_name ) { $ key = $ this -> getMapping ( $ column_name ) ; if ( $ key === false ) { continue ; } if ( in_array ( $ key , $ seenKeys ) ) { throw new OverlapColumnException ( $ key ) ; } $ seenKeys [ ] = $ key ; $ this -> mappings [ $ key ] [ 'index' ] = $ index ; $ maps [ $ key ] = $ index ; } foreach ( $ this -> mappings as $ key => $ data ) { if ( $ data [ 'required' ] && ! array_key_exists ( $ key , $ maps ) ) { throw new MappingIncompleteException ( $ key ) ; } } return $ maps ; }
|
Map columns on array
|
13,582
|
public static function currency ( $ value , $ decimals = 2 , $ currencyCode = null ) { $ app = Application :: instance ( ) ; $ currencyCode = $ currencyCode ? : $ app -> getConfig ( 'app.settings.currency' ) ; $ nf = new \ NumberFormatter ( \ Locale :: getDefault ( ) , \ NumberFormatter :: CURRENCY ) ; $ nf -> setAttribute ( \ NumberFormatter :: MAX_FRACTION_DIGITS , $ decimals ) ; return $ nf -> formatCurrency ( $ value , $ currencyCode ) ; }
|
returns a string with currency formatted accordingly to locale settings
|
13,583
|
public static function decimal ( $ value , $ decimals = 2 ) { $ nf = new \ NumberFormatter ( \ Locale :: getDefault ( ) , \ NumberFormatter :: DECIMAL ) ; $ nf -> setAttribute ( \ NumberFormatter :: MAX_FRACTION_DIGITS , $ decimals ) ; return $ nf -> format ( $ value ) ; }
|
returns a string with decimal formatted accordingly to locale settings
|
13,584
|
public static function percentage ( $ value , $ decimals = 0 ) { $ nf = new \ NumberFormatter ( \ Locale :: getDefault ( ) , \ NumberFormatter :: PERCENT ) ; $ nf -> setAttribute ( \ NumberFormatter :: MAX_FRACTION_DIGITS , $ decimals ) ; return $ value > 1 ? $ nf -> format ( $ value ) : $ nf -> format ( $ value ) ; }
|
returns a string with percentage formatted accordingly to Yii dateFormatter
|
13,585
|
public function validate ( $ value ) { return is_float ( $ value ) ? Ok :: unit ( ) : Error :: unit ( [ Error :: NON_FLOAT ] ) ; }
|
Tells if a given value is a valid float .
|
13,586
|
protected function checkParameters ( ) { $ this -> checkDocumentTypeParameter ( ) ; $ this -> checkResponseFolderParameter ( ) ; $ this -> checkSubTemplateParameter ( ) ; $ this -> checkFormParameterNameParameter ( ) ; $ this -> checkThankYouMessageParameter ( ) ; $ this -> checkSubmitOncePerSessionParameter ( ) ; }
|
Checks if parameters were given in the CMS configuration and sets them to their respective fields
|
13,587
|
protected function initialize ( $ storage ) { $ this -> parameters [ self :: PARAMETER_SMALLEST_IMAGE ] = $ storage -> getImageSet ( ) -> getSmallestImageSet ( ) ; $ this -> parameters [ self :: PARAMETER_CMS_PREFIX ] = '' ; $ this -> parameters [ self :: PARAMETER_DOCUMENT_TYPE ] = $ this -> storage -> getDocumentTypes ( ) -> getDocumentTypeBySlug ( $ this -> documentType , true ) ; $ this -> parameters [ self :: PARAMETER_DOCUMENT_TYPES ] = $ this -> storage -> getDocumentTypes ( ) -> getDocumentTypes ( ) ; $ this -> parameters [ self :: PARAMETER_HIDE_TITLE_AND_STATE ] = true ; $ this -> parameters [ self :: PARAMETER_FORM_ID ] = $ this -> formId ; }
|
Sets variables needed for rendering the form template
|
13,588
|
protected function setFormId ( ) { if ( isset ( $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] ) ) { $ this -> formId = $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] ; } else { $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] = ( string ) microtime ( true ) ; $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ 'submitted' ] = false ; $ this -> formId = $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] ; } }
|
Sets a unique id for this particular form so it can recognize it when a submit occurs
|
13,589
|
protected function setUserSessionBackup ( ) { $ this -> userSessionBackup = isset ( $ _SESSION [ self :: SESSION_PARAMETER_CLOUDCONTROL ] ) ? $ _SESSION [ self :: SESSION_PARAMETER_CLOUDCONTROL ] : null ; $ fakeUser = new \ stdClass ( ) ; $ fakeUser -> username = self :: SESSION_PARAMETER_FORM_COMPONENT ; $ _SESSION [ self :: SESSION_PARAMETER_CLOUDCONTROL ] = $ fakeUser ; }
|
Temporarily stores the current user session in a backup variable and sets a fake user instead
|
13,590
|
protected function restoreUserSessionBackup ( ) { if ( $ this -> userSessionBackup === null ) { unset ( $ _SESSION [ self :: SESSION_PARAMETER_CLOUDCONTROL ] ) ; } else { $ _SESSION [ self :: SESSION_PARAMETER_CLOUDCONTROL ] = $ this -> userSessionBackup ; } }
|
Removes the fake user and restores the existing user session if it was there
|
13,591
|
private function checkFormIdInPost ( $ request ) { if ( ! isset ( $ request :: $ post [ self :: PARAMETER_FORM_ID ] ) ) { return false ; } if ( ! $ request :: $ post [ self :: PARAMETER_FORM_ID ] === $ this -> formId ) { return false ; } return true ; }
|
Checks if form id is set in _POST variable
|
13,592
|
private function checkFormIdInSession ( ) { if ( ! isset ( $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] ) ) { return false ; } if ( ! $ _SESSION [ self :: SESSION_PARAMETER_FORM_COMPONENT ] [ $ this -> formParameterName ] [ self :: PARAMETER_FORM_ID ] === $ this -> formId ) { return false ; } return true ; }
|
Checks if form is is set in _SESSION variable
|
13,593
|
public function negotiate ( ) { $ catchedException = null ; try { $ this -> lock -> acquire ( ) ; $ this -> executeMigrations ( ) ; } catch ( LockingException $ exc ) { $ this -> logger -> emergency ( $ exc -> getMessage ( ) ) ; $ catchedException = $ exc ; } catch ( TopologyViolationException $ exc ) { $ this -> logger -> emergency ( 'The version to migrate to is older than the current one.' ) ; $ catchedException = $ exc ; } catch ( MigrationException $ exc ) { $ this -> logger -> emergency ( 'Migration of version ' . $ exc -> getCode ( ) . ' failed.' , array ( $ exc -> getMessage ( ) ) ) ; $ catchedException = $ exc ; } $ this -> lock -> release ( ) ; if ( ! is_null ( $ catchedException ) ) { throw $ catchedException ; } }
|
Negotiates the migration process
|
13,594
|
public static function angle ( Segment $ a , Segment $ b , Segment $ c ) : Degree { $ a = $ a -> length ( ) ; $ b = $ b -> length ( ) ; $ c = $ c -> length ( ) ; $ longest = max ( $ a , $ b , $ c ) ; $ opposites = ( new Set ( Number :: class ) ) -> add ( $ a ) -> add ( $ b ) -> add ( $ c ) -> remove ( $ longest ) ; $ opposites = add ( ... $ opposites ) ; if ( $ longest -> higherThan ( $ opposites ) && ! $ longest -> equals ( $ opposites ) ) { throw new SegmentsCannotBeJoined ; } $ cosAB = $ a -> power ( new Integer ( 2 ) ) -> add ( $ b -> power ( new Integer ( 2 ) ) ) -> subtract ( $ c -> power ( new Integer ( 2 ) ) ) -> divideBy ( ( new Integer ( 2 ) ) -> multiplyBy ( $ a ) -> multiplyBy ( $ b ) ) ; return arcCosine ( $ cosAB ) -> toDegree ( ) ; }
|
Return the angle between a and b sides
|
13,595
|
public function buildPath ( ) { $ slugs = func_get_args ( ) ; if ( is_array ( $ slugs [ 0 ] ) ) $ slugs = $ slugs [ 0 ] ; if ( count ( $ slugs ) == 0 ) return $ this -> basePath ; if ( Str :: startsWith ( $ slugs [ 0 ] , '__' ) ) { $ key = substr ( $ slugs [ 0 ] , 2 ) ; if ( $ key == 'base' ) $ slugs [ 0 ] = $ this -> basePath ; else if ( array_key_exists ( $ key , $ this -> paths ) ) { $ paths = $ this -> paths [ $ key ] ; if ( is_array ( $ paths ) ) { unset ( $ slugs [ 0 ] ) ; foreach ( array_reverse ( $ paths ) as $ slug ) $ slugs = Arr :: prepend ( $ slugs , $ slug ) ; } else $ slugs [ 0 ] = $ paths ; } else throw new FrameworkException ( "Path [" . $ key . "] is not set" ) ; return $ this -> buildPath ( $ slugs ) ; } else if ( ! Str :: startsWith ( $ slugs [ 0 ] , '/' ) ) $ slugs = Arr :: prepend ( $ slugs , $ this -> basePath ) ; $ dir = strpos ( end ( $ slugs ) , '.' ) !== false ? implode ( DIRECTORY_SEPARATOR , array_slice ( $ slugs , 0 , count ( $ slugs ) - 1 ) ) : implode ( DIRECTORY_SEPARATOR , $ slugs ) ; if ( ! file_exists ( $ dir ) ) if ( ! mkdir ( $ dir , 0755 , true ) ) throw new FrameworkException ( "The directory [" . $ dir . "] does not exist and we failed to create it" ) ; return implode ( DIRECTORY_SEPARATOR , $ slugs ) ; }
|
Append args to the base path
|
13,596
|
public static function getCode ( $ val ) { if ( self :: $ _languageFlip === array ( ) ) { self :: $ _languageFlip = array_flip ( self :: $ _languages ) ; } if ( array_key_exists ( $ val , self :: $ _languageFlip ) ) { return strtolower ( self :: $ _languageFlip [ $ val ] ) ; } return null ; }
|
Converts a KlarnaLanguage constant to the respective language code .
|
13,597
|
public function apply ( Builder $ builder ) { $ this -> builder = $ builder ; if ( method_exists ( $ this , $ this -> orderBy ( ) ) ) { call_user_func ( [ $ this , $ this -> orderBy ( ) ] ) ; } return $ this -> builder ; }
|
Apply the sorter to the builder .
|
13,598
|
public static function listOrderByKeys ( ) { $ classMethods = get_class_methods ( get_class ( ) ) ; $ calledClassMethods = get_class_methods ( get_called_class ( ) ) ; $ filteredMethods = array_filter ( $ calledClassMethods , function ( $ calledClassMethod ) use ( $ classMethods ) { return ! in_array ( $ calledClassMethod , $ classMethods , true ) ; } ) ; $ list = [ ] ; foreach ( $ filteredMethods as $ k => $ v ) { $ list [ $ v ] = $ v ; } return $ list ; }
|
Pluck all sorters from class methods .
|
13,599
|
public static function getAppliedSorters ( ) { $ order = static :: getOrderKey ( ) ; $ orderBy = static :: getOrderByKey ( ) ; $ applied = \ Illuminate \ Support \ Facades \ Request :: only ( $ order , $ orderBy ) ; $ applied = array_filter ( $ applied ) ; $ default = [ $ orderBy => static :: getDefaultOrderBy ( ) , $ order => static :: getDefaultOrder ( ) ] ; return $ applied ? : $ default ; }
|
Get applied sorters from request or fallback to default .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.