idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
15,000
public function get ( $ scheme = self :: REL ) { $ data = $ this -> data ; if ( $ scheme == self :: REL ) { unset ( $ data [ 'scheme' ] , $ data [ 'host' ] , $ data [ 'user' ] , $ data [ 'pass' ] , $ data [ 'port' ] ) ; return $ this -> build ( $ data ) ; } if ( ! isset ( $ data [ 'host' ] ) ) { $ data [ 'host' ] = $ this -> request -> getHost ( ) ; } if ( ! isset ( $ data [ 'scheme' ] ) ) { $ scheme = self :: SHORT_ABS ; } if ( $ scheme == self :: SHORT_ABS ) { unset ( $ data [ 'scheme' ] ) ; $ url = $ this -> build ( $ data , '//' ) ; } else { $ url = $ this -> build ( $ data ) ; } return $ this -> asProtect ( $ url , $ data [ 'host' ] ) ; }
Returns formatted URL .
15,001
public function offsetSet ( $ key , $ value ) { if ( $ key === 'query' && isset ( $ value ) ) { $ value = $ this -> _queryToArray ( $ value ) ; } $ this -> data [ $ key ] = $ value ; }
Sets a URL - data by key .
15,002
public function toResponse ( ) : Response { return new Response ( $ this -> status , $ this -> headers , $ this -> body , $ this -> httpVersion , $ this -> reason ) ; }
Generates HTTP Response .
15,003
public static function view ( $ package ) { $ settings = static :: get ( $ package ) ; if ( $ settings and array_key_exists ( 'view' , $ settings ) ) { return view ( $ settings [ 'view' ] ) ; } return '' ; }
Returns the settings view of the package .
15,004
protected function _processTemplateVars ( array $ options ) { $ templateVars = isset ( $ options [ 'options' ] [ 'templateVars' ] ) ? $ options [ 'options' ] [ 'templateVars' ] : [ ] ; if ( empty ( $ templateVars ) ) { return $ templateVars ; } if ( isset ( $ templateVars [ 'formRowLabel' ] ) && $ options [ 'options' ] [ 'id' ] !== false ) { $ templateVars [ 'formRowFor' ] = ' for="' . $ options [ 'options' ] [ 'id' ] . '"' ; } $ wrapInSmall = [ 'formRowLabelInfo' , 'formRowInfo' , 'info' ] ; foreach ( $ wrapInSmall as $ attr ) { if ( isset ( $ templateVars [ $ attr ] ) ) { $ templateVars [ $ attr ] = '<small>' . $ templateVars [ $ attr ] . '</small>' ; } } return $ templateVars ; }
Process templateVars to wrap info elements in a small tag and apply the for attribute to form row labels .
15,005
public function getLabel ( $ text , $ info = null ) { $ options = [ 'text' => $ text , 'templateVars' => [ ] ] ; if ( $ info !== null ) { $ options [ 'templateVars' ] [ 'labelInfo' ] = '<small>' . $ info . '</small>' ; } return $ options ; }
Get the options array for a label . This handles the optional placement of an info text below the label .
15,006
public function timeZoneSelect ( $ field , array $ options = [ ] ) { $ regions = [ 'Europe' => DateTimeZone :: EUROPE , 'America' => DateTimeZone :: AMERICA , 'Africa' => DateTimeZone :: AFRICA , 'Antarctica' => DateTimeZone :: ANTARCTICA , 'Asia' => DateTimeZone :: ASIA , 'Atlantic' => DateTimeZone :: ATLANTIC , 'Indian' => DateTimeZone :: INDIAN , 'Pacific' => DateTimeZone :: PACIFIC ] ; $ timezones = [ ] ; foreach ( $ regions as $ name => $ mask ) { $ zones = DateTimeZone :: listIdentifiers ( $ mask ) ; foreach ( $ zones as $ timezone ) { $ time = new DateTime ( null , new DateTimeZone ( $ timezone ) ) ; $ timezones [ $ name ] [ ] = [ 'value' => $ timezone , 'text' => 'UTC ' . $ time -> format ( 'P' ) . ' ' . substr ( $ timezone , strlen ( $ name ) + 1 ) ] ; } } $ options [ 'options' ] = $ timezones ; return $ this -> input ( $ field , $ options ) ; }
Render a grouped time zone select box .
15,007
public function toggleSwitch ( $ fieldName , array $ options = [ ] ) { $ options += [ 'hiddenField' => true , 'value' => 1 , 'id' => true ] ; $ value = $ options [ 'value' ] ; unset ( $ options [ 'value' ] ) ; $ options = $ this -> _initInputField ( $ fieldName , $ options ) ; $ options [ 'value' ] = $ value ; $ output = '' ; if ( $ options [ 'hiddenField' ] ) { $ hiddenOptions = [ 'name' => $ options [ 'name' ] , 'value' => ( $ options [ 'hiddenField' ] !== true && $ options [ 'hiddenField' ] !== '_split' ? $ options [ 'hiddenField' ] : '0' ) , 'form' => isset ( $ options [ 'form' ] ) ? $ options [ 'form' ] : null , 'secure' => false ] ; if ( isset ( $ options [ 'disabled' ] ) && $ options [ 'disabled' ] ) { $ hiddenOptions [ 'disabled' ] = 'disabled' ; } $ output = $ this -> hidden ( $ fieldName , $ hiddenOptions ) ; } if ( $ options [ 'hiddenField' ] === '_split' ) { unset ( $ options [ 'hiddenField' ] , $ options [ 'type' ] ) ; return [ 'hidden' => $ output , 'input' => $ this -> widget ( 'checkbox' , $ options ) ] ; } unset ( $ options [ 'hiddenField' ] , $ options [ 'type' ] ) ; return $ output . $ this -> widget ( 'toggleSwitch' , $ options ) ; }
Creates a toggleSwitch input widget .
15,008
public function save ( $ pConditions = NULL ) { foreach ( $ this -> _fields as & $ value ) { if ( is_array ( $ value ) ) { $ value = implode ( ',' , $ value ) ; } } return parent :: save ( $ pConditions ) ; }
Save the item in the database .
15,009
public static function IsAbsolute ( string $ path , bool $ dependToOS = true ) : bool { if ( \ is_null ( $ path ) || \ strlen ( $ path ) < 1 ) { return false ; } if ( $ dependToOS ) { if ( ! \ IS_WIN ) { return $ path [ 0 ] == '/' ; } if ( \ strlen ( $ path ) < 2 ) { return false ; } return $ path [ 1 ] == ':' || ( $ path [ 0 ] == '\\' && $ path [ 1 ] == '\\' ) ; } return $ path [ 0 ] == '/' || $ path [ 1 ] == ':' || ( $ path [ 0 ] == '\\' && $ path [ 1 ] == '\\' ) ; }
Returns if the defined path is a absolute path definition .
15,010
protected function resolveModule ( $ controller ) { $ modules = $ this -> getModules ( ) ; $ module = get_class ( $ controller ) ; while ( false !== $ pos = strrpos ( $ module , '\\' ) ) { $ module = substr ( $ module , 0 , $ pos ) ; if ( $ modules -> has ( $ module ) ) { return $ module ; } } throw new RuntimeException ( sprintf ( 'Failed to resolve the module namespace of the "%s" controller.' , get_class ( $ controller ) ) ) ; }
Resolves the module namespace of received controller .
15,011
public function sendJsonResponse ( & $ response_data , $ headers = [ ] ) { header ( 'Content-type: application/json' ) ; if ( ! empty ( $ headers ) ) { if ( is_array ( $ headers ) ) { foreach ( $ headers as $ header ) { header ( $ header ) ; } } } echo array_to_json ( $ response_data ) ; }
This is an auxiliary function for sending the response in JSON format .
15,012
public function exitWithException ( $ ex ) { $ response_data = [ ] ; $ response_data [ "result" ] = "error" ; $ response_data [ "errors" ] = [ [ "error_code" => "system_error" , "error_text" => $ ex -> getMessage ( ) ] ] ; $ this -> sendJsonResponse ( $ response_data ) ; exit ; }
This is an auxiliary function for sending the response in JSON format by an exception .
15,013
public function getApiRequest ( ) { if ( empty ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return "" ; } $ api_request = $ _SERVER [ 'REQUEST_URI' ] ; if ( ! empty ( $ _SERVER [ 'QUERY_STRING' ] ) ) { $ api_request = str_replace ( $ _SERVER [ 'QUERY_STRING' ] , "" , $ api_request ) ; } $ api_request = rtrim ( $ api_request , "/?" ) ; $ api_base = str_replace ( basename ( $ _SERVER [ 'SCRIPT_NAME' ] ) , "" , $ _SERVER [ 'SCRIPT_NAME' ] ) ; $ api_base = rtrim ( $ api_base , "/" ) ; return trim ( str_replace ( $ api_base , "" , $ api_request ) , "/" ) ; }
Defines the current API request name .
15,014
public function registerApiRequestHandler ( $ api_request , $ handler_class_name ) { if ( empty ( $ api_request ) ) { throw new \ Exception ( "The API request is undefined (empty)!" ) ; } if ( ! empty ( $ this -> handler_table [ $ api_request ] ) ) { throw new \ Exception ( "The API request '$api_request' has already the handler '" . $ this -> handler_table [ $ api_request ] . "'!" ) ; } $ this -> handler_table [ $ api_request ] = $ handler_class_name ; return true ; }
Registers a handler action for an API request call .
15,015
protected function _renderExpressionAndTerms ( ExpressionInterface $ expression , $ context = null ) { $ renderedTerms = [ ] ; foreach ( $ expression -> getTerms ( ) as $ _term ) { $ renderedTerms [ ] = $ this -> _renderExpressionTerm ( $ _term , $ context ) ; } return $ this -> _compileExpressionTerms ( $ expression , $ renderedTerms , $ context ) ; }
Renders a given expression and its terms .
15,016
public function getFormName ( $ data ) { $ context = $ data ; if ( $ data instanceof MediaCommonInterface ) { if ( $ data instanceof MediaProviderInterface ) { $ context = $ data -> getMedia ( ) -> getContext ( ) ; } else { $ context = $ data -> getContext ( ) ; } } return $ this -> providerService -> getProviderManager ( $ context ) -> getFormName ( ) ; }
Get form name
15,017
public function getFormByContext ( $ context , array $ options = array ( ) ) { $ formName = $ this -> providerService -> getProviderManager ( $ context ) -> getFormName ( ) ; $ mediaProvider = $ this -> mediaService -> create ( $ context ) ; return $ this -> getForm ( $ formName , $ mediaProvider , $ options ) ; }
Get form by the context
15,018
public function getFormByMediaProvider ( MediaProviderInterface $ mediaProvider , array $ options = array ( ) ) { $ formName = $ this -> providerService -> getProviderManager ( $ mediaProvider -> getMedia ( ) -> getContext ( ) ) -> getFormName ( ) ; return $ this -> getForm ( $ formName , $ mediaProvider , $ options ) ; }
Get form by mediaProvider
15,019
protected function getForm ( $ formName , MediaProviderInterface $ mediaProvider , array $ options = array ( ) ) { return $ this -> formFactory -> createBuilder ( $ formName , $ mediaProvider , $ options ) -> getForm ( ) ; }
Return the Form instance
15,020
public function getEnvVarsFromConsul ( array $ mappings ) { foreach ( $ mappings as $ environmentKey => $ consulPath ) { $ keyExists = $ this -> keyIsDefined ( $ environmentKey ) ; if ( $ keyExists && ! $ this -> overwriteEvenIfDefined ) { continue ; } $ consulValue = $ this -> getKeyValueFromConsul ( $ consulPath ) ; $ this -> saveKeyValueInEnvironmentVars ( $ environmentKey , $ consulValue ) ; } }
Add missing environment variables from Consul .
15,021
public function exposeEnvironmentIntoContainer ( ContainerBuilder $ container , array $ mappings ) : ContainerBuilder { foreach ( $ mappings as $ environmentKey => $ consulPath ) { $ container -> setParameter ( "env({$environmentKey})" , getenv ( $ environmentKey ) ) ; } return $ container ; }
Expose a set of mappings into the container builder .
15,022
private function keyIsDefined ( string $ environmentKey ) : bool { $ keyValue = getenv ( $ environmentKey ) ; if ( false === $ keyValue ) { return false ; } return true ; }
Check if an environment key is defined .
15,023
private function getKeyValueFromConsul ( string $ kvPath ) : string { return $ this -> kv -> get ( $ kvPath , [ 'raw' => true ] ) -> getBody ( ) ; }
Get a key value from Consul .
15,024
function Send ( ) { if ( count ( $ this -> to ) < 1 ) { $ this -> error_handler ( "You must provide at least one recipient email address" ) ; return false ; } if ( ! empty ( $ this -> AltBody ) ) $ this -> ContentType = "multipart/alternative" ; $ header = $ this -> create_header ( ) ; if ( ! $ body = $ this -> create_body ( ) ) return false ; if ( $ this -> Mailer == "sendmail" ) { if ( ! $ this -> sendmail_send ( $ header , $ body ) ) return false ; } elseif ( $ this -> Mailer == "mail" ) { if ( ! $ this -> mail_send ( $ header , $ body ) ) return false ; } elseif ( $ this -> Mailer == "smtp" ) { if ( ! $ this -> smtp_send ( $ header , $ body ) ) return false ; } else { $ this -> error_handler ( sprintf ( "%s mailer is not supported" , $ this -> Mailer ) ) ; return false ; } return true ; }
Creates message and assigns Mailer . If the message is not sent successfully then it returns false . Returns bool .
15,025
function addr_append ( $ type , $ addr ) { $ addr_str = "" ; $ addr_str .= sprintf ( "%s: %s <%s>" , $ type , $ addr [ 0 ] [ 1 ] , $ addr [ 0 ] [ 0 ] ) ; if ( count ( $ addr ) > 1 ) { for ( $ i = 1 ; $ i < count ( $ addr ) ; $ i ++ ) { $ addr_str .= sprintf ( ", %s <%s>" , $ addr [ $ i ] [ 1 ] , $ addr [ $ i ] [ 0 ] ) ; } $ addr_str .= "\r\n" ; } else $ addr_str .= "\r\n" ; return ( $ addr_str ) ; }
Creates recipient headers . Returns string .
15,026
function create_header ( ) { $ header = array ( ) ; $ header [ ] = sprintf ( "Date: %s\r\n" , $ this -> rfc_date ( ) ) ; if ( $ this -> Mailer != "mail" ) $ header [ ] = $ this -> addr_append ( "To" , $ this -> to ) ; $ header [ ] = sprintf ( "From: %s <%s>\r\n" , $ this -> FromName , trim ( $ this -> From ) ) ; if ( count ( $ this -> cc ) > 0 ) $ header [ ] = $ this -> addr_append ( "Cc" , $ this -> cc ) ; if ( ( ( $ this -> Mailer == "sendmail" ) || ( $ this -> Mailer == "mail" ) ) && ( count ( $ this -> bcc ) > 0 ) ) $ header [ ] = $ this -> addr_append ( "Bcc" , $ this -> bcc ) ; if ( count ( $ this -> ReplyTo ) > 0 ) $ header [ ] = $ this -> addr_append ( "Reply-to" , $ this -> ReplyTo ) ; if ( $ this -> Mailer != "mail" ) $ header [ ] = sprintf ( "Subject: %s\r\n" , trim ( $ this -> Subject ) ) ; $ header [ ] = sprintf ( "X-Priority: %d\r\n" , $ this -> Priority ) ; $ header [ ] = sprintf ( "X-Mailer: phpmailer [version %s]\r\n" , $ this -> Version ) ; $ header [ ] = sprintf ( "Return-Path: %s\r\n" , trim ( $ this -> From ) ) ; for ( $ index = 0 ; $ index < count ( $ this -> CustomHeader ) ; $ index ++ ) $ header [ ] = sprintf ( "%s\r\n" , $ this -> CustomHeader [ $ index ] ) ; if ( $ this -> UseMSMailHeaders ) $ header [ ] = $ this -> AddMSMailHeaders ( ) ; $ header [ ] = "MIME-Version: 1.0\r\n" ; if ( count ( $ this -> attachment ) > 0 || ! empty ( $ this -> AltBody ) ) { $ this -> boundary = "_b" . md5 ( uniqid ( time ( ) ) ) ; $ this -> subboundary = "_sb" . md5 ( uniqid ( time ( ) ) ) ; $ header [ ] = "Content-Type: Multipart/Mixed;\r\n" ; $ header [ ] = sprintf ( " boundary=\"Boundary-=%s\"\r\n\r\n" , $ this -> boundary ) ; } else { $ header [ ] = sprintf ( "Content-Transfer-Encoding: %s\r\n" , $ this -> Encoding ) ; $ header [ ] = sprintf ( "Content-Type: %s; charset = \"%s\"\r\n\r\n" , $ this -> ContentType , $ this -> CharSet ) ; } return ( join ( "" , $ header ) ) ; }
Assembles message header . Returns a string if successful or false if unsuccessful .
15,027
function create_body ( ) { if ( $ this -> WordWrap ) $ this -> Body = $ this -> wordwrap ( $ this -> Body , $ this -> WordWrap ) ; if ( ( ! empty ( $ this -> AltBody ) ) && ( count ( $ this -> attachment ) < 1 ) ) { $ mime = array ( ) ; $ mime [ ] = "This is a MIME message. If you are reading this text, you\r\n" ; $ mime [ ] = "might want to consider changing to a mail reader that\r\n" ; $ mime [ ] = "understands how to properly display MIME multipart messages.\r\n\r\n" ; $ mime [ ] = sprintf ( "--Boundary-=%s\r\n" , $ this -> boundary ) ; $ mime [ ] = sprintf ( "Content-Type: %s; charset = \"%s\"; boundary = \"Boundary-=%s\";\r\n" , $ this -> ContentType , $ this -> CharSet , $ this -> subboundary ) ; $ mime [ ] = sprintf ( "Content-Transfer-Encoding: %s\r\n\r\n" , $ this -> Encoding ) ; $ mime [ ] = sprintf ( "--Boundary-=%s\r\n" , $ this -> subboundary ) ; $ mime [ ] = sprintf ( "Content-Type: text/html; charset = \"%s\";\r\n" , $ this -> CharSet ) ; $ mime [ ] = sprintf ( "Content-Transfer-Encoding: %s\r\n\r\n" , $ this -> Encoding ) ; $ mime [ ] = sprintf ( "%s\r\n\r\n" , $ this -> Body ) ; $ mime [ ] = sprintf ( "--Boundary-=%s\r\n" , $ this -> subboundary ) ; $ mime [ ] = sprintf ( "Content-Type: text/plain; charset = \"%s\";\r\n" , $ this -> CharSet ) ; $ mime [ ] = sprintf ( "Content-Transfer-Encoding: %s\r\n\r\n" , $ this -> Encoding ) ; $ mime [ ] = sprintf ( "%s\r\n\r\n" , $ this -> AltBody ) ; $ mime [ ] = sprintf ( "\r\n--Boundary-=%s--\r\n\r\n" , $ this -> subboundary ) ; $ mime [ ] = sprintf ( "\r\n--Boundary-=%s--\r\n" , $ this -> boundary ) ; $ this -> Body = $ this -> encode_string ( join ( "" , $ mime ) , $ this -> Encoding ) ; } else { $ this -> Body = $ this -> encode_string ( $ this -> Body , $ this -> Encoding ) ; } if ( count ( $ this -> attachment ) > 0 ) { if ( ! $ body = $ this -> attach_all ( ) ) return false ; } else $ body = $ this -> Body ; return ( $ body ) ; }
Assembles the message body . Returns a string if successful or false if unsuccessful .
15,028
function AddAttachment ( $ path , $ name = "" , $ encoding = "base64" , $ type = "application/octet-stream" ) { if ( ! @ is_file ( $ path ) ) { $ this -> error_handler ( sprintf ( "Could not find %s file on filesystem" , $ path ) ) ; return false ; } $ filename = basename ( $ path ) ; if ( $ name == "" ) $ name = $ filename ; $ cur = count ( $ this -> attachment ) ; $ this -> attachment [ $ cur ] [ 0 ] = $ path ; $ this -> attachment [ $ cur ] [ 1 ] = $ filename ; $ this -> attachment [ $ cur ] [ 2 ] = $ name ; $ this -> attachment [ $ cur ] [ 3 ] = $ encoding ; $ this -> attachment [ $ cur ] [ 4 ] = $ type ; $ this -> attachment [ $ cur ] [ 5 ] = false ; return true ; }
Adds an attachment from the OS filesystem . Checks if attachment is valid and then adds the attachment to the list . Returns false if the file was not found .
15,029
function encode_file ( $ path , $ encoding = "base64" ) { if ( ! @ $ fd = fopen ( $ path , "rb" ) ) { $ this -> error_handler ( sprintf ( "File Error: Could not open file %s" , $ path ) ) ; return false ; } $ file = fread ( $ fd , filesize ( $ path ) ) ; $ encoded = $ this -> encode_string ( $ file , $ encoding ) ; fclose ( $ fd ) ; return ( $ encoded ) ; }
Encodes attachment in requested format . Returns a string if successful or false if unsuccessful .
15,030
function encode_string ( $ str , $ encoding = "base64" ) { switch ( strtolower ( $ encoding ) ) { case "base64" : $ encoded = chunk_split ( base64_encode ( $ str ) ) ; break ; case "7bit" : case "8bit" : $ encoded = $ this -> fix_eol ( $ str ) ; if ( substr ( $ encoded , - 2 ) != "\r\n" ) $ encoded .= "\r\n" ; break ; case "binary" : $ encoded = $ str ; break ; case "quoted-printable" : $ encoded = $ this -> encode_qp ( $ str ) ; break ; default : $ this -> error_handler ( sprintf ( "Unknown encoding: %s" , $ encoding ) ) ; return false ; } return ( $ encoded ) ; }
Encodes string to requested format . Returns a string if successful or false if unsuccessful .
15,031
function rfc_date ( ) { $ tz = date ( "Z" ) ; $ tzs = ( $ tz < 0 ) ? "-" : "+" ; $ tz = abs ( $ tz ) ; $ tz = ( $ tz / 3600 ) * 100 + ( $ tz % 3600 ) / 60 ; $ date = sprintf ( "%s %s%04d" , date ( "D, j M Y H:i:s" ) , $ tzs , $ tz ) ; return $ date ; }
Returns the proper RFC 822 formatted date . Returns string .
15,032
function fix_eol ( $ str ) { $ str = str_replace ( "\r\n" , "\n" , $ str ) ; $ str = str_replace ( "\r" , "\n" , $ str ) ; $ str = str_replace ( "\n" , "\r\n" , $ str ) ; return $ str ; }
Changes every end of line from CR or LF to CRLF . Returns string .
15,033
function AddMSMailHeaders ( ) { $ MSHeader = "" ; if ( $ this -> Priority == 1 ) $ MSPriority = "High" ; elseif ( $ this -> Priority == 5 ) $ MSPriority = "Low" ; else $ MSPriority = "Medium" ; $ MSHeader .= sprintf ( "X-MSMail-Priority: %s\r\n" , $ MSPriority ) ; $ MSHeader .= sprintf ( "Importance: %s\r\n" , $ MSPriority ) ; return ( $ MSHeader ) ; }
Adds all the Microsoft message headers . Returns string .
15,034
public function context ( ContextInterface $ context ) { if ( ! empty ( $ this -> vary ) ) { $ this -> varyValue = $ context -> get ( $ this -> vary ) ; } }
We assume pack format specifier I is equal in size to PHP_INT_SIZE
15,035
protected function getRatioStatus ( ) { if ( $ this -> ratio == 0.0 ) { return Status :: INACTIVE ; } if ( $ this -> ratio >= 1.0 ) { return Status :: ACTIVE ; } $ value = unpack ( 'nint' , md5 ( ( string ) $ this -> varyValue , true ) ) [ 'int' ] ; $ filter = ( int ) floor ( self :: RESOLUTION * ( float ) $ this -> ratio ) ; return ( $ value < $ filter ) ; }
Gets whether the feature is enabled according to the ratio alone
15,036
public function setAdapter ( $ adapter ) { if ( is_array ( $ adapter ) ) { $ adapter = Yii :: createObject ( $ adapter ) ; } if ( interface_exists ( 'League\Flysystem\AdapterInterface' ) && $ adapter instanceof AdapterInterface ) { $ this -> adapter = $ adapter ; } else { throw new InaccessibleKeyPairException ( "Flysystem adapter for retrieving the key pair is invalid" ) ; } }
Sets the adapter to use for the provider
15,037
public static function load ( $ name , $ options = array ( ) ) { if ( array_key_exists ( $ name , self :: $ _modules ) ) { throw new \ Exception ( "A module with the name $name has already been loaded." , 1 ) ; } $ module = new Module ( $ name , $ options ) ; self :: $ _modules [ $ name ] = $ module ; return $ module ; }
Load a Module
15,038
private function init ( $ config ) { $ this -> getParams = filter_input_array ( INPUT_GET ) ; $ this -> postParams = filter_input_array ( INPUT_POST ) ; $ this -> attributes = array ( ) ; $ this -> session = new Session ( $ config [ 'SESSION_AUTOSTART' ] ) ; $ this -> requestMethod = filter_input ( INPUT_SERVER , 'REQUEST_METHOD' ) ; $ this -> queryString = filter_input ( INPUT_SERVER , 'QUERY_STRING' ) ; $ this -> requestUri = filter_input ( INPUT_SERVER , 'REQUEST_URI' ) ; $ this -> httpHost = filter_input ( INPUT_SERVER , 'HTTP_HOST' ) ; $ this -> httpAccept = filter_input ( INPUT_SERVER , 'HTTP_ACCEPT' ) ; $ this -> httpAcceptLanguage = filter_input ( INPUT_SERVER , 'HTTP_ACCEPT_LANGUAGE' ) ; $ this -> httpUserAgent = filter_input ( INPUT_SERVER , 'HTTP_USER_AGENT' ) ; $ this -> clientIp = filter_input ( INPUT_SERVER , 'REMOTE_ADDR' ) ; $ this -> realBaseUrl = $ config [ 'REAL_BASE_URL' ] ; $ this -> baseUrlLocale = $ config [ 'BASEURL_LOCALE' ] ; $ this -> uriApp = $ config [ 'URIAPP' ] ; $ this -> uriAppLocale = $ config [ 'URIAPP_LOCALE' ] ; $ this -> localeUri = $ config [ 'LOCALE_URI' ] ; $ this -> locale = $ config [ 'LOCALE' ] ; }
Setea todas las propiedades de la instancia GET - POST - SERVER y FRAMEWORK
15,039
public function getParam ( $ name ) { if ( isset ( $ this -> getParams [ $ name ] ) ) { return $ this -> getParams [ $ name ] ; } else { return NULL ; } }
Devuelve un parametro GET si existe y si no devuelve NULL
15,040
public function postParam ( $ name ) { if ( isset ( $ this -> postParams [ $ name ] ) ) { return $ this -> postParams [ $ name ] ; } else { return NULL ; } }
Devuelve un parametro POST si existe y si no devuelve NULL
15,041
public function getCleanParam ( $ name ) { if ( isset ( $ this -> getParams [ $ name ] ) ) { return Security :: clean_vars ( $ this -> getParams [ $ name ] ) ; } else { return NULL ; } }
Devuelve un parametro GET limpiado si existe y si no devuelve NULL
15,042
public function postCleanParam ( $ name ) { if ( isset ( $ this -> postParams [ $ name ] ) ) { return Security :: clean_vars ( $ this -> postParams [ $ name ] ) ; } else { return NULL ; } }
Devuelve un parametro POST limpiado si existe y si no devuelve NULL
15,043
public function getHeader ( $ name ) { $ headers = $ this -> getHeaders ( ) ; if ( isset ( $ headers [ $ name ] ) ) { return $ headers [ $ name ] ; } else { return NULL ; } }
Retorna un header especifico o null si no existe
15,044
public function getToken ( ) { if ( ! $ this -> token ) { if ( $ this -> getHeader ( 'Authorization' ) != NULL ) { $ this -> token = $ this -> getHeader ( 'Authorization' ) ; } if ( ! $ this -> token && $ this -> getParam ( 'token' ) ) { $ this -> token = $ this -> getParam ( 'token' ) ; } } return $ this -> token ; }
Retorna el token actual de la peticion Busca en el header Authorization o una variable get token
15,045
public function addFormElement ( array $ element , $ options = array ( ) ) { if ( array_key_exists ( $ element [ 'name' ] , $ this -> formElements ) ) { throw new \ Exception ( 'Form element "' . $ element [ 'name' ] . '" is already added, use replaceFormElement() or removeElement() instead' ) ; } $ this -> formElements [ $ element [ 'name' ] ] = $ element ; if ( ! empty ( $ options ) && is_array ( $ options ) ) { $ this -> formElementOptions [ $ element [ 'name' ] ] = $ options ; } return $ this ; }
Add form element using short syntax
15,046
public function getFormElements ( ) { $ sm = $ this -> getServiceLocator ( ) ; $ formElements = array ( ) ; $ placeholders = $ this -> getPlaceholderParameters ( ) ; $ replacePlaceholderWithValues = array ( ) ; foreach ( $ this -> formElements as $ element ) { if ( in_array ( $ element [ 'name' ] , $ this -> removeElements ) ) { continue ; } $ formElement = $ this -> formatFormElement ( $ element ) ; $ replacePlaceholderWithValues = $ sm -> get ( $ this -> moduleService ) -> defaultConfig ( 'placeholder' ) ; if ( ! empty ( $ placeholders ) && is_array ( $ placeholders ) ) { if ( array_key_exists ( 'global' , $ placeholders ) && ! empty ( $ placeholders [ 'global' ] ) && is_array ( $ placeholders [ 'global' ] ) ) { $ replacePlaceholderWithValues = array_merge ( $ replacePlaceholderWithValues , $ placeholders [ 'global' ] ) ; } if ( array_key_exists ( 'element' , $ placeholders ) && ! empty ( $ placeholders [ 'element' ] ) && is_array ( $ placeholders [ 'element' ] ) ) { if ( array_key_exists ( $ element [ 'name' ] , $ placeholders [ 'element' ] ) ) { $ replacePlaceholderWithValues = array_merge ( $ replacePlaceholderWithValues , $ placeholders [ 'element' ] [ $ element [ 'name' ] ] ) ; } } } $ formElement = $ this -> searchAndReplacePlaceHolders ( $ formElement , $ replacePlaceholderWithValues ) ; $ formElements [ ] = $ formElement ; } return $ formElements ; }
Get form elements in array format with values merged from placeholder
15,047
protected function formatFormElement ( array $ element ) { $ sm = $ this -> getServiceLocator ( ) ; $ result = array ( ) ; if ( array_key_exists ( 'lazy-set' , $ element ) ) { $ result = $ sm -> get ( $ this -> moduleService ) -> lazySet ( $ element [ 'lazy-set' ] ) ; } $ result [ 'name' ] = $ element [ 'name' ] ; $ result [ 'type' ] = $ element [ 'type' ] ; if ( array_key_exists ( 'label' , $ element ) ) { $ result [ 'options' ] [ 'label' ] = $ element [ 'label' ] ; } return $ result ; }
Format form element by replacing keywords with values recognized by zend - form
15,048
protected function addInputFilter ( ) { $ sm = $ this -> getServiceLocator ( ) ; if ( empty ( $ sm ) ) { throw new \ Exception ( 'Form must be initialized using FormElementManager, refer document for more information' ) ; } $ config = $ sm -> get ( $ this -> moduleService ) -> config ( ) ; foreach ( $ this -> getFormElements ( ) as $ element ) { if ( array_key_exists ( 'filters' , $ element ) && false === $ element [ 'filters' ] ) { continue ; } $ element [ 'required' ] = false ; if ( array_key_exists ( 'validators' , $ element ) && is_array ( $ element [ 'validators' ] ) ) { foreach ( $ element [ 'validators' ] as $ validator ) { if ( in_array ( $ validator [ 'name' ] , array ( 'NotEmpty' ) ) ) { $ element [ 'required' ] = true ; } if ( in_array ( $ validator [ 'name' ] , array ( 'Callback' ) ) ) { $ callBackValidatorExist = true ; $ element [ 'allow_empty' ] = true ; $ element [ 'continue_if_empty' ] = true ; } } } if ( array_key_exists ( 'type' , $ element ) ) { unset ( $ element [ 'type' ] ) ; } $ element [ 'allow_empty' ] = true ; $ element [ 'continue_if_empty' ] = true ; $ this -> inputFilter -> add ( $ this -> inputFactory -> createInput ( $ element ) ) ; } return $ this -> inputFilter ; }
Add input filter to form elements - Skip filters if value is set to false - If NotEmpty validator is available add required element with value true else set required value to false - Remove type from element to avoid conflict with input filter
15,049
public function setPlaceholderParameter ( $ name , $ value , $ elementName = null ) { if ( null != $ elementName ) { $ this -> placeholderParameters [ 'element' ] [ $ elementName ] [ $ name ] = $ value ; } else { $ this -> placeholderParameters [ 'global' ] [ $ name ] = $ value ; } return $ this ; }
Replace place holder with given value in validators filters attributes or options
15,050
protected function searchAndReplacePlaceHolders ( array $ element , array $ placeHolders ) { array_walk_recursive ( $ element , function ( & $ v , $ k , $ ph ) { if ( is_string ( $ v ) && array_key_exists ( $ v , $ ph ) ) { $ v = $ ph [ $ v ] ; } } , $ placeHolders ) ; return $ element ; }
Search and replace occurences of place holders in an element
15,051
public function handleSignal ( $ signal ) { switch ( $ signal ) { case SIGINT : $ this -> log ( 'Received SIGINT, shutting down.' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_ALL ) ; $ this -> moribund = true ; break ; case SIGTERM : $ this -> log ( 'Received SIGTERM, shutting down.' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_ALL ) ; $ this -> moribund = true ; break ; } }
Handles UNIX signals
15,052
protected function relayNotification ( $ message ) { $ message = json_encode ( $ message ) ; foreach ( $ this -> listenClients as $ client ) { if ( $ client -> getState ( ) < Net_Notifier_WebSocket_Connection :: STATE_CLOSING ) { $ this -> log ( sprintf ( ' ... relaying message "%s" to %s ... ' , $ message , $ client -> getIPAddress ( ) ) , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; $ client -> writeText ( $ message ) ; $ this -> log ( 'done' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_CLIENT , false ) ; } } }
Notifies all connected clients of an event
15,053
protected function connect ( ) { $ errstr = '' ; $ errno = 0 ; $ this -> log ( 'creating socket ... ' , Net_Notifier_Logger :: VERBOSITY_ALL ) ; try { $ this -> socket = new Net_Notifier_Socket_Server ( sprintf ( 'tcp://0.0.0.0:%s' , $ this -> port ) , null ) ; } catch ( Net_Notifier_Socket_Exception $ e ) { $ this -> log ( 'failed' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_ALL , false ) ; throw $ e ; } $ this -> log ( 'done' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_ALL , false ) ; $ this -> connected = true ; }
Sets up this server s listen socket
15,054
protected function disconnect ( ) { $ this -> log ( 'closing sockets ... ' , Net_Notifier_Logger :: VERBOSITY_ALL ) ; foreach ( $ this -> clients as $ client ) { $ client -> startClose ( Net_Notifier_WebSocket_Connection :: CLOSE_GOING_AWAY , 'Server shutting down.' ) ; } $ this -> clients = array ( ) ; $ this -> socket = null ; $ this -> log ( 'done' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_ALL , false ) ; $ this -> connected = false ; }
Closes all client sockets and the server listen socket
15,055
protected function closeClient ( Net_Notifier_WebSocket_Connection $ client ) { $ this -> log ( sprintf ( 'closing client %s ... ' , $ client -> getIPAddress ( ) ) , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; if ( $ client -> getState ( ) < Net_Notifier_WebSocket_Connection :: STATE_CLOSED ) { $ client -> close ( ) ; } $ key = array_search ( $ client , $ this -> clients ) ; unset ( $ this -> clients [ $ key ] ) ; $ key = array_search ( $ client , $ this -> listenClients ) ; if ( $ key !== false ) { unset ( $ this -> listenClients [ $ key ] ) ; } $ this -> log ( 'done' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_CLIENT , false ) ; }
Closes a client socket and removes the client from the list of clients
15,056
protected function startCloseClient ( Net_Notifier_WebSocket_Connection $ client , $ code = Net_Notifier_WebSocket_Connection :: CLOSE_NORMAL , $ reason = '' ) { $ this -> log ( sprintf ( 'disconnecting client from %s for reason "%s" ... ' , $ client -> getIPAddress ( ) , $ reason ) , Net_Notifier_Logger :: VERBOSITY_CLIENT ) ; $ client -> startClose ( $ code , $ reason ) ; $ this -> log ( 'done' . PHP_EOL , Net_Notifier_Logger :: VERBOSITY_CLIENT , false ) ; }
Initiates the closing handshake for a client connection
15,057
protected function & getReadClients ( & $ read ) { $ clients = array ( ) ; foreach ( $ this -> clients as $ client ) { if ( in_array ( $ client -> getSocket ( ) -> getRawSocket ( ) , $ read ) ) { $ clients [ ] = $ client ; } } return $ clients ; }
Gets an array of client connections whose sockets were read
15,058
protected function & getReadArray ( ) { $ readArray = array ( ) ; $ readArray [ ] = $ this -> socket -> getRawSocket ( ) ; foreach ( $ this -> clients as $ client ) { if ( $ client -> getState ( ) < Net_Notifier_WebSocket_Connection :: STATE_CLOSED ) { $ readArray [ ] = $ client -> getSocket ( ) -> getRawSocket ( ) ; } } return $ readArray ; }
Gets an array of sockets to check for reading
15,059
protected function log ( $ message , $ priority = Net_Notifier_Logger :: VERBOSITY_MESSAGES , $ timestamp = true ) { if ( $ this -> logger instanceof Net_Notifier_Logger ) { $ this -> logger -> log ( $ message , $ priority , $ timestamp ) ; } return $ this ; }
Logs a message with the specified priority
15,060
public static function Atic13 ( $ ri , $ di , $ date1 , $ date2 , & $ rc , & $ dc , & $ eo ) { $ astrom = new iauASTROM ( ) ; IAU :: Apci13 ( $ date1 , $ date2 , $ astrom , $ eo ) ; IAU :: Aticq ( $ ri , $ di , $ astrom , $ rc , $ dc ) ; }
- - - - - - - - - - i a u A t i c 1 3 - - - - - - - - - -
15,061
public function preSave ( ) { $ script = '' ; foreach ( $ this -> getColumns ( ) as $ column ) { $ script .= $ this -> renderTemplate ( 'preSave' , array ( 'column' => $ this -> getTable ( ) -> getColumn ( $ column ) -> getFullyQualifiedName ( ) , 'setter' => $ this -> getColumnSetter ( $ column ) , 'getter' => $ this -> getColumnGetter ( $ column ) ) ) ; } return $ script ; }
Checks if need to move any uploaded files
15,062
public function read ( ) { if ( ! $ this -> valid ( ) ) { return null ; } $ resource = $ this -> resource ; $ item = $ this -> current ( ) ; $ this -> next ( ) ; $ event = new ResourceSerializeEvent ( $ resource , $ item ) ; $ this -> eventDispatcher -> dispatch ( FeedEvents :: RESOURCE_PRE_SERIALIZE , $ event ) ; $ item = $ this -> serialize ( $ item ) ; $ this -> eventDispatcher -> dispatch ( FeedEvents :: RESOURCE_POST_SERIALIZE , $ event ) ; return $ item ; }
Wrapper that implements various calls so you can use the iterator in a simple while loop .
15,063
public function decorate ( Style $ style , string $ value ) : string { if ( ! $ style -> isExpand ( ) ) { return $ value ; } $ lineWidth = $ style -> getLineWidth ( ) ; $ align = $ style -> getAlignValue ( ) ; return str_pad ( $ value , $ lineWidth , ' ' , $ align ) ; }
Decora un valor aplicando un estilo
15,064
public function inheritConfigure ( Samurai \ Application $ app ) { $ app -> setEnv ( $ this -> getEnvFromEnvironmentVariables ( ) ) ; $ app -> addAppPathUsePsr4 ( __DIR__ , __NAMESPACE__ , 'Samurai\\' , self :: PRIORITY_LOW ) ; }
configure from application console
15,065
public function before_insert ( Orm \ Model $ obj ) { if ( $ obj instanceof SortableInterface ) { $ max = $ obj -> getSortMax ( ) ; } else { $ max = $ obj -> query ( ) -> max ( $ this -> _property ) ; } $ obj -> { $ this -> _property } = $ max + $ this -> _offset ; }
Sets the sort property to the current sort value
15,066
public static function stucture ( $ table ) { $ drop = "DROP TABLE IF EXISTS `$table`;" ; $ res = Driver :: read ( 'SHOW CREATE TABLE ' . $ table ) ; $ struct = $ res [ 0 ] [ 'Create Table' ] ; return "\n\n-- $table\n\n-- '$table' Table Structure\n$drop\n" . $ struct . ";\n\n" ; }
Get SQL query of table stucture .
15,067
public static function tables ( ) { $ tables = false ; $ Tables = Driver :: read ( 'SHOW TABLES' , Driver :: INDEX ) ; foreach ( $ Tables as $ row ) { $ target_tables [ ] = $ row [ 0 ] ; } if ( $ tables !== false ) { $ target_tables = array_intersect ( $ target_tables , $ tables ) ; } return $ target_tables ; }
Get all data tables created in the current database .
15,068
public static function info ( ) { $ database = Config :: get ( 'database.database' ) ; $ host = Config :: get ( 'database.host' ) ; $ username = Config :: get ( 'database.username' ) ; return "\n\n-- Database : $database\n-- Host : $host\n-- User : $username\n" ; }
Get info about database server connection .
15,069
public static function save ( $ file , $ query ) { $ path = Application :: $ root . "database/backup/$file" ; return ( new Filesystem ( ) ) -> put ( $ path , $ query ) ; }
Save exported data in sql file .
15,070
public static function fetch ( $ tables ) { foreach ( $ tables as $ table ) { $ result = Driver :: query ( "SELECT * FROM $table" , Driver :: INDEX ) ; $ fields = $ result -> columnCount ( ) ; $ rows = $ result -> rowCount ( ) ; $ data = Driver :: read ( "SELECT * FROM $table" , Driver :: INDEX ) ; $ content = ( ! isset ( $ content ) ? '' : $ content ) . self :: stucture ( $ table ) ; $ st_counter = 0 ; foreach ( $ data as $ row ) { if ( $ st_counter % 100 == 0 || $ st_counter == 0 ) { $ content .= "\n-- Table Data\nINSERT INTO " . $ table . ' VALUES' ; } $ content .= "\n(" ; for ( $ j = 0 ; $ j < $ fields ; $ j ++ ) { $ row [ $ j ] = str_replace ( "\n" , '\\n' , addslashes ( $ row [ $ j ] ) ) ; if ( isset ( $ row [ $ j ] ) ) { if ( ! empty ( $ row [ $ j ] ) ) { $ content .= '"' . $ row [ $ j ] . '"' ; } else { $ content .= 'NULL' ; } } else { $ content .= '""' ; } if ( $ j < ( $ fields - 1 ) ) { $ content .= ',' ; } } $ content .= ')' ; if ( ( ( $ st_counter + 1 ) % 100 == 0 && $ st_counter != 0 ) || $ st_counter + 1 == $ rows ) { $ content .= ';' ; } else { $ content .= ',' ; } $ st_counter = $ st_counter + 1 ; } $ content .= "\n\n\n" ; } return $ content ; }
fetch data inside data tables .
15,071
public static function export ( $ name ) { $ now = time ( ) ; $ tables = self :: tables ( ) ; $ query = self :: time ( $ now ) . self :: info ( ) ; $ query .= self :: database ( ) ; $ query .= self :: fetch ( $ tables ) ; $ file = ( $ name ? : config ( 'database.database' ) . '_' . $ now ) . '.sql' ; self :: file ( $ file ) ; self :: save ( $ file , $ query ) ; return true ; }
Export the current database .
15,072
protected function getUuidFromUrl ( Url $ url ) { $ segments = $ url -> getPathSegments ( ) ; if ( count ( $ segments ) < 1 ) { throw new Exception ( 'Invalid UUID' ) ; } if ( count ( $ segments ) < 2 ) { return $ segments [ 0 ] ; } return $ segments [ count ( $ segments ) - 2 ] ; }
Extract the last part of a URL
15,073
private static function _initializeCW ( $ table ) { if ( isset ( static :: $ authModel ) && static :: $ authModel !== false ) { $ myClass = trim ( get_called_class ( ) , '\\ ' ) ; $ myAuth = null ; foreach ( Auth :: all ( ) as $ auth ) { if ( trim ( $ auth -> model , '\\ ' ) == $ myClass ) { $ myAuth = $ auth ; break ; } } if ( is_null ( $ myAuth ) ) { throw new \ Exception ( "There was no Auth defined with model '" . $ myClass . "'." , 1 ) ; } self :: $ auth = $ myAuth ; $ table -> callback -> register ( "beforeSave" , function ( \ ActiveRecord \ Model $ model ) { $ model -> _setAuthValues ( ) ; } ) ; } }
Initialize ChickenWire featues
15,074
public function resaltPassword ( $ password , $ salt = '' ) { $ auth = self :: $ auth ; if ( $ auth -> useSalt == false ) { throw new \ Exception ( "This Auth does not use salting." , 1 ) ; } $ this -> setAttributes ( array ( $ auth -> saltField => $ salt , $ auth -> passwordField => $ password ) ) ; }
Re - encrypt the password
15,075
public function cast ( $ value , $ connection ) { if ( $ value === null ) return null ; switch ( $ this -> type ) { case self :: STRING : return ( string ) $ value ; case self :: INTEGER : return ( int ) $ value ; case self :: DECIMAL : return ( double ) $ value ; case self :: DATETIME : case self :: DATE : if ( ! $ value ) return null ; if ( $ value instanceof DateTime ) return $ value ; if ( $ value instanceof \ DateTime ) return new DateTime ( $ value -> format ( 'Y-m-d H:i:s T' ) ) ; return $ connection -> stringToDateTime ( $ value ) ; } return $ value ; }
Casts a value to the column s type .
15,076
public static function cast ( $ value , $ phpType ) { if ( $ phpType === null or $ value === null ) return $ value ; switch ( $ phpType ) { case 'string' : return ( string ) $ value ; case 'float' : return ( float ) $ value ; case 'int' : return ( int ) $ value ; case 'bool' : if ( is_bool ( $ value ) ) return $ value ; if ( is_numeric ( $ value ) ) { if ( $ value == 1 ) return true ; if ( $ value == 0 ) return false ; } if ( is_string ( $ value ) ) { if ( in_array ( $ value , array ( 'yes' , 'true' , 'on' ) ) ) return true ; if ( in_array ( $ value , array ( 'no' , 'false' , 'off' , '' ) ) ) return false ; } throw new Exception ( "Invalid boolean representation: " . var_export ( $ value , true ) ) ; default : throw new Exception ( "Don't know how to cast to PHP type '$phpType'." ) ; } }
Convert a value to the named PHP scalar type using PHP s default conversion .
15,077
public static function fieldPropertyValue ( EarthIT_Schema_Field $ f , $ propUri , $ nonFakeDefault = null , $ fakeDefault = null ) { $ v = $ f -> getFirstPropertyValue ( $ propUri ) ; if ( $ v !== null ) return $ v ; $ isFake = $ f -> getFirstPropertyValue ( EarthIT_CMIPREST_NS :: IS_FAKE_FIELD ) ; return $ isFake ? $ fakeDefault : $ nonFakeDefault ; }
Get a field property value taking into account whether the field is fake or not and defaults for either case .
15,078
public static function singleErrorResponse ( $ status , $ message , array $ notes = array ( ) , array $ headers = array ( ) ) { return self :: multiErrorResponse ( $ status , array ( self :: errorStructure ( $ message , $ notes ) ) , $ headers ) ; }
Create a response to indicate a single error from a status code message and list of notes .
15,079
protected function mapElementToModelData ( ElementInterface $ child ) { $ this -> setModelValueFromElement ( $ child ) ; $ children = $ child -> getChildren ( ) ; if ( $ children -> count ( ) ) { $ this -> mapElementCollectionToModelData ( $ children ) ; } }
Maps element value to model data
15,080
protected function mapModelDataToElementCollection ( ElementCollection $ children ) { foreach ( $ children -> all ( ) as $ child ) { $ this -> mapModelDataToElement ( $ child ) ; } }
Maps data using recursion to all children
15,081
protected function setDefaultElementValue ( ElementInterface $ element ) { $ propertyPath = $ element -> getPropertyPath ( ) ; if ( $ propertyPath instanceof PropertyPathInterface ) { if ( $ this -> propertyAccessor -> isReadable ( $ this -> data , $ propertyPath ) ) { $ value = $ this -> propertyAccessor -> getValue ( $ this -> data , $ propertyPath ) ; if ( $ this -> isEmptyValue ( $ value ) ) { $ value = $ element -> getDefaultValue ( ) ; } if ( $ element -> hasTransformer ( ) && is_object ( $ value ) ) { $ transformer = $ element -> getTransformer ( ) ; $ value = $ transformer -> transform ( $ value ) ; } $ element -> setValue ( $ value ) ; } } }
Sets value for element
15,082
protected function setModelValueFromElement ( ElementInterface $ child ) { $ propertyPath = $ child -> getPropertyPath ( ) ; if ( $ propertyPath instanceof PropertyPathInterface ) { if ( $ this -> propertyAccessor -> isWritable ( $ this -> data , $ propertyPath ) ) { if ( $ child -> hasTransformer ( ) ) { $ transformer = $ child -> getTransformer ( ) ; $ transformer -> reverseTransform ( $ this -> data , $ propertyPath , $ child -> getValue ( ) ) ; } else { $ this -> propertyAccessor -> setValue ( $ this -> data , $ propertyPath , $ child -> getValue ( ) ) ; } } } }
Transforms value if needed or directly changes model property
15,083
protected function registerProviders ( Collection $ providers ) { $ providers -> each ( function ( $ providerClass ) { $ this -> app -> register ( $ providerClass ) ; } ) ; }
Register Unit Custom ServiceProviders .
15,084
protected function unitPath ( $ append = null ) { $ reflection = new \ ReflectionClass ( $ this ) ; $ realPath = realpath ( dirname ( $ reflection -> getFileName ( ) ) . '/../' ) ; if ( ! $ append ) { return $ realPath ; } return $ realPath . '/' . $ append ; }
Detects the unit base path so resources can be proper loaded on child classes .
15,085
protected function appendSuffix ( Name $ class ) { if ( $ class -> isFullyQualified ( ) ) { if ( count ( $ class -> parts ) == 1 ) { return $ class ; } return $ this -> append ( new Name ( '\\' . $ class -> toString ( ) ) ) ; } if ( $ this -> isImport ) { if ( ! $ this -> groupImport && count ( $ class -> parts ) == 1 ) { return $ class ; } return $ this -> append ( $ class ) ; } foreach ( $ this -> importNodes as $ import ) { if ( strcmp ( $ import -> getLast ( ) , $ class -> toString ( ) ) === 0 ) { return $ class ; } } return $ this -> append ( $ class ) ; }
Append a suffix to the node .
15,086
protected function buildAndOr ( array & $ cls , array $ where , $ idx ) { if ( $ idx ) { $ cls [ ] = $ where [ 2 ] ; } if ( $ where [ 1 ] ) { $ cls [ ] = $ where [ 1 ] ; } }
build AND NOT part of the clause part
15,087
protected function buildCondition ( array $ cls , array $ where , array $ settings ) { if ( ! empty ( $ where [ 3 ] ) ) { $ cls [ ] = $ this -> quoteItem ( $ where [ 3 ] , $ settings , $ this -> isRaw ( $ where [ 3 ] , $ where [ 0 ] ) ) ; } if ( WhereInterface :: NO_OPERATOR !== $ where [ 4 ] ) { $ cls [ ] = $ where [ 4 ] ; } if ( WhereInterface :: NO_VALUE !== $ where [ 5 ] ) { $ cls [ ] = $ this -> processValue ( $ where [ 5 ] , $ settings , ( bool ) preg_match ( '/\bbetween\b/i' , $ where [ 4 ] ) ) ; } return join ( ' ' , $ cls ) ; }
Build col = val part
15,088
public static function error_handler ( $ number , $ message , $ file , $ line ) { $ msg = "$message in $file on line $line" ; if ( ( $ number !== E_NOTICE ) && ( $ number < 2048 ) ) { self :: errorMessage ( $ msg , true ) ; self :: customErrorMsg ( ) ; } return 0 ; }
Saves error message from exception
15,089
protected function processInputBuffer ( ) { if ( $ this -> request === null ) { if ( isset ( $ this -> inputBuffer [ HttpRequest :: MAX_HEADER_LENGTH ] ) ) { $ this -> logger -> warning ( "Client $this sent headers larger than " . HttpRequest :: MAX_HEADER_LENGTH . ' bytes' ) ; $ this -> inputBuffer = '' ; throw new HttpException ( 'Server refused request exceeding ' . HttpRequest :: MAX_HEADER_LENGTH . ' bytes' , HttpCode :: REQUEST_HEADER_FIELDS_TOO_LARGE , array ( ) , true ) ; } $ headersBreakpoint = strpos ( $ this -> inputBuffer , "\r\n\r\n" ) ; if ( $ headersBreakpoint === false ) { return ; } list ( $ headers , $ this -> inputBuffer ) = explode ( "\r\n\r\n" , $ this -> inputBuffer , 2 ) ; $ this -> request = new HttpRequest ( $ headers , $ this -> logger ) ; } }
Handles HTTP request collection
15,090
public static function build ( array $ pointer , array $ context ) { if ( array_key_exists ( 'value' , $ pointer ) ) { return $ pointer [ 'value' ] ; } if ( ! empty ( $ pointer [ 'classname' ] ) ) { $ classname = NameResolver :: resolve ( $ pointer [ 'classname' ] , $ context ) ; return self :: buildByClassname ( $ classname , $ pointer , $ context ) ; } if ( ! empty ( $ pointer [ 'creator' ] ) ) { return Callback :: call ( $ pointer [ 'creator' ] , [ $ pointer , $ context ] ) ; } if ( ! empty ( $ context [ 'classname' ] ) ) { return self :: buildByClassname ( $ context [ 'classname' ] , $ pointer , $ context ) ; } if ( ! empty ( $ context [ 'creator' ] ) ) { return Callback :: call ( $ context [ 'creator' ] , [ $ pointer , $ context ] ) ; } throw new InvalidPointer ( '' ) ; }
Builds an object by the pointer
15,091
public function & block ( $ script , $ defer = false ) { $ script = new JavascriptObject ( ) ; $ script -> setType ( 'block' ) ; $ script -> setScript ( $ script ) ; $ script -> setDefer ( $ defer ) ; $ this -> add ( $ script ) ; return $ script ; }
Blocks with complete code . Use this for conditional scripts!
15,092
public function & bootstrap ( $ version , $ defer = false ) { $ url = $ this -> js_url . '/bootstrap-' . $ version . '.min.js' ; if ( str_replace ( BASEURL , BASEDIR , $ url ) ) { return $ this -> file ( $ url ) ; } }
Returns an file script block for the BS js lib
15,093
public function getFieldList ( ) { $ fields = dbQuery ( '\samson\cms\web\field\CMSField' ) -> join ( '\samson\cms\CMSNavField' ) -> cond ( 'StructureID' , $ this -> id ) -> exec ( ) ; $ items = '' ; if ( sizeof ( $ fields ) ) { foreach ( $ fields as $ field ) { $ items .= m ( 'structure' ) -> view ( 'form/field/field_item' ) -> field ( $ field ) -> structure ( $ this ) -> output ( ) ; } } else { $ items = m ( 'structure' ) -> view ( 'form/field/empty_field' ) -> output ( ) ; } return $ items ; }
Fet list of additional fields of current structure
15,094
public function fillFields ( ) { foreach ( $ _POST as $ key => $ val ) { if ( $ key == 'ParentID' && $ val == 0 ) { $ this [ $ key ] = null ; } elseif ( $ key != 'StructureID' ) { $ this [ $ key ] = $ val ; } } $ this [ 'applicationGenerate' ] = isset ( $ _POST [ 'generate-application' ] ) && ( $ _POST [ 'generate-application' ] == true ) ? 1 : 0 ; $ this [ 'applicationOutput' ] = isset ( $ _POST [ 'output-application' ] ) && ( $ _POST [ 'output-application' ] == true ) ? 1 : 0 ; $ this [ 'applicationOutputStructure' ] = isset ( $ _POST [ 'output-structure-application' ] ) && ( $ _POST [ 'output-structure-application' ] == true ) ? 1 : 0 ; $ this [ 'applicationRenderMain' ] = isset ( $ _POST [ 'render-main-application' ] ) && ( $ _POST [ 'render-main-application' ] == true ) ? 1 : 0 ; $ this [ 'system' ] = isset ( $ _POST [ 'generate-application' ] ) && ( $ _POST [ 'generate-application' ] == true ) ? 1 : 0 ; $ icon = isset ( $ _POST [ 'icon-application' ] ) ? filter_var ( $ _POST [ 'icon-application' ] ) : null ; if ( strlen ( $ icon ) > 0 ) { $ this [ 'applicationIcon' ] = $ icon ; } if ( ! $ this -> query -> entity ( '\samson\activerecord\user' ) -> where ( 'user_id' , $ this -> UserID ) -> first ( ) ) { $ this -> UserID = 1 ; } $ this -> save ( ) ; if ( isset ( $ _POST [ 'ParentID' ] ) && $ _POST [ 'ParentID' ] != 0 ) { $ strRelation = new \ samson \ activerecord \ structure_relation ( false ) ; $ strRelation -> parent_id = $ _POST [ 'ParentID' ] ; $ strRelation -> child_id = $ this -> id ; $ strRelation -> save ( ) ; } }
Filling the fields and creating relation of structure
15,095
public function beforePrepare ( Event $ event ) { $ command = $ event [ 'command' ] ; $ operation = $ command -> getOperation ( ) ; if ( $ command -> offsetGet ( 'collection' ) === 'user' || $ command -> getClient ( ) -> getCollectionName ( ) === 'user' ) { if ( strstr ( $ operation -> getURI ( ) , 'user' ) !== false ) return ; $ operation -> setURI ( '/user/{appKey}/{_id}' ) ; } elseif ( $ command -> offsetGet ( 'collection' ) === 'files' || $ command -> getClient ( ) -> getCollectionName ( ) === 'files' ) { if ( strstr ( $ operation -> getURI ( ) , 'files' ) !== false ) return ; $ operation -> setURI ( '/blob/{appKey}/{_id}' ) ; $ command -> getRequestHeaders ( ) -> add ( 'X-Kinvey-API-Version' , 3 ) ; } elseif ( $ command -> offsetGet ( 'collection' ) === 'group' || $ command -> getClient ( ) -> getCollectionName ( ) === 'group' ) { if ( strstr ( $ operation -> getURI ( ) , 'group' ) !== false ) return ; $ operation -> setURI ( '/group/{appKey}/{_id}' ) ; } }
If the query is targets the users or files collection rewrite the URI . This allows the same entity commands to be used for data store entities as well as users and files .
15,096
public static function Go ( Event $ event ) { $ event -> getIO ( ) -> writeError ( '<info>Updating .gitignore: </info>' , false ) ; $ composer = $ event -> getComposer ( ) ; $ repositoryManager = $ composer -> getRepositoryManager ( ) ; $ installManager = $ composer -> getInstallationManager ( ) ; $ extraConfiguration = $ composer -> getPackage ( ) -> getExtra ( ) ; $ devRequires = ( array_key_exists ( 'autogitignore' , $ extraConfiguration ) && $ extraConfiguration [ 'autogitignore' ] == 'devOnly' ) ; if ( $ devRequires ) { $ devRequires = array_keys ( $ composer -> getPackage ( ) -> getDevRequires ( ) ) ; $ requires = array_keys ( $ composer -> getPackage ( ) -> getRequires ( ) ) ; foreach ( $ repositoryManager -> getLocalRepository ( ) -> getPackages ( ) as $ package ) { $ devRequires = array_merge ( $ devRequires , array_keys ( $ package -> getDevRequires ( ) ) ) ; $ requires = array_merge ( $ requires , array_keys ( $ package -> getRequires ( ) ) ) ; } $ devRequires = array_unique ( $ devRequires ) ; $ requires = array_unique ( $ requires ) ; sort ( $ devRequires ) ; sort ( $ requires ) ; } $ packages = array ( ) ; foreach ( $ repositoryManager -> getLocalRepository ( ) -> getPackages ( ) as $ package ) { if ( $ devRequires && ( ! in_array ( $ package -> getName ( ) , $ devRequires ) || in_array ( $ package -> getName ( ) , $ requires ) ) ) { continue ; } $ path = $ installManager -> getInstallPath ( $ package ) ; $ packages [ ] = '/' . preg_replace ( '~^' . preg_quote ( str_replace ( '\\' , '/' , getcwd ( ) ) . '/' ) . '~' , '' , str_replace ( '\\' , '/' , realpath ( $ path ) ) ) . '/' ; } $ packages = array_unique ( $ packages ) ; sort ( $ packages ) ; try { $ gitIgnoreFile = GitIgnoreFile :: create ( getcwd ( ) . DIRECTORY_SEPARATOR . '.gitignore' ) ; $ gitIgnoreFile -> setLines ( $ packages ) ; $ gitIgnoreFile -> save ( ) ; } catch ( Exception $ exception ) { $ event -> getIO ( ) -> writeError ( '<info>Failed - ' . $ exception -> getMessage ( ) . '</info>' ) ; return false ; } $ event -> getIO ( ) -> writeError ( '<info>Done - ' . count ( $ packages ) . ' packages ignored.</info>' ) ; return true ; }
This runs the builder
15,097
protected function call ( array $ params ) { $ response = $ this -> client -> get ( null , array ( 'query' => $ params ) ) ; $ result = $ response -> json ( ) ; if ( $ result [ 'result' ] == 'ERR' ) { throw new ResponseException ( $ result [ 'message' ] , $ result [ 'code' ] ) ; } return $ result ; }
Sends a request to server
15,098
public function useSkillRelatedByStartPositionIdQuery ( $ relationAlias = null , $ joinType = Criteria :: LEFT_JOIN ) { return $ this -> joinSkillRelatedByStartPositionId ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'SkillRelatedByStartPositionId' , '\gossi\trixionary\model\SkillQuery' ) ; }
Use the SkillRelatedByStartPositionId relation Skill object
15,099
public function useSkillRelatedByEndPositionIdQuery ( $ relationAlias = null , $ joinType = Criteria :: LEFT_JOIN ) { return $ this -> joinSkillRelatedByEndPositionId ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'SkillRelatedByEndPositionId' , '\gossi\trixionary\model\SkillQuery' ) ; }
Use the SkillRelatedByEndPositionId relation Skill object