sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function getJs()
{
$sJsLibUri = $this->getJsLibUri();
$sJsLibExt = $this->getJsLibExt();
$sJsCoreUrl = $sJsLibUri . 'jaxon.core' . $sJsLibExt;
$sJsDebugUrl = $sJsLibUri . 'jaxon.debug' . $sJsLibExt;
// $sJsVerboseUrl = $sJsLibUri . 'jaxon.verbose' . $sJsLibExt;
$sJsLanguageUrl = $sJsLibUri . 'lang/jaxon.' . $this->getOption('core.language') . $sJsLibExt;
// Add component files to the javascript file array;
$aJsFiles = array($sJsCoreUrl);
if($this->getOption('core.debug.on'))
{
$aJsFiles[] = $sJsDebugUrl;
$aJsFiles[] = $sJsLanguageUrl;
/*if($this->getOption('core.debug.verbose'))
{
$aJsFiles[] = $sJsVerboseUrl;
}*/
}
// Set the template engine cache dir
$this->setTemplateCacheDir();
$this->makePluginsCode();
return $this->render('jaxon::plugins/includes.js', [
'sJsOptions' => $this->getOption('js.app.options'),
'aUrls' => $aJsFiles,
]) . $this->sJsCode;
}
|
Get the HTML tags to include Jaxon javascript files into the page
@return string
|
entailment
|
private function getOptionVars()
{
return [
'sResponseType' => self::RESPONSE_TYPE,
'sVersion' => $this->getOption('core.version'),
'sLanguage' => $this->getOption('core.language'),
'bLanguage' => $this->hasOption('core.language') ? true : false,
'sRequestURI' => $this->getOption('core.request.uri'),
'sDefaultMode' => $this->getOption('core.request.mode'),
'sDefaultMethod' => $this->getOption('core.request.method'),
'sCsrfMetaName' => $this->getOption('core.request.csrf_meta'),
'bDebug' => $this->getOption('core.debug.on'),
'bVerboseDebug' => $this->getOption('core.debug.verbose'),
'sDebugOutputID' => $this->getOption('core.debug.output_id'),
'nResponseQueueSize' => $this->getOption('js.lib.queue_size'),
'sStatusMessages' => $this->getOption('js.lib.show_status') ? 'true' : 'false',
'sWaitCursor' => $this->getOption('js.lib.show_cursor') ? 'true' : 'false',
'sDefer' => $this->getOption('js.app.options'),
];
}
|
Get the correspondances between previous and current config options
They are used to keep the deprecated config options working.
They will be removed when the deprecated options will lot be supported anymore.
@return array
|
entailment
|
private function _getScript()
{
$aVars = $this->getOptionVars();
$sYesScript = 'jaxon.ajax.response.process(command.response)';
$sNoScript = 'jaxon.confirm.skip(command);jaxon.ajax.response.process(command.response)';
$sConfirmScript = jaxon()->dialog()->confirm('msg', $sYesScript, $sNoScript);
$aVars['sConfirmScript'] = $this->render('jaxon::plugins/confirm.js', ['sConfirmScript' => $sConfirmScript]);
return $this->render('jaxon::plugins/config.js', $aVars) . "\n" . $this->sJsReady . "\n";
}
|
Get the javascript code to be sent to the browser
@return string
|
entailment
|
public function getScript()
{
// Set the template engine cache dir
$this->setTemplateCacheDir();
$this->makePluginsCode();
if($this->canExportJavascript())
{
$sJsAppURI = rtrim($this->getOption('js.app.uri'), '/') . '/';
$sJsAppDir = rtrim($this->getOption('js.app.dir'), '/') . '/';
// The plugins scripts are written into the javascript app dir
$sHash = $this->generateHash();
$sOutFile = $sHash . '.js';
$sMinFile = $sHash . '.min.js';
if(!is_file($sJsAppDir . $sOutFile))
{
file_put_contents($sJsAppDir . $sOutFile, $this->_getScript());
}
if(($this->getOption('js.app.minify')) && !is_file($sJsAppDir . $sMinFile))
{
if(($this->minify($sJsAppDir . $sOutFile, $sJsAppDir . $sMinFile)))
{
$sOutFile = $sMinFile;
}
}
// The returned code loads the generated javascript file
$sScript = $this->render('jaxon::plugins/include.js', array(
'sJsOptions' => $this->getOption('js.app.options'),
'sUrl' => $sJsAppURI . $sOutFile,
));
}
else
{
// The plugins scripts are wrapped with javascript tags
$sScript = $this->render('jaxon::plugins/wrapper.js', array(
'sJsOptions' => $this->getOption('js.app.options'),
'sScript' => $this->_getScript(),
));
}
return $sScript;
}
|
Get the javascript code to be sent to the browser
Also call each of the request plugins giving them the opportunity
to output some javascript to the page being generated.
This is called only when the page is being loaded initially.
This is not called when processing a request.
@return string
|
entailment
|
public function getOption($sName, $xDefault = null)
{
return Container::getInstance()->getConfig()->getOption($sName, $xDefault);
}
|
Get the value of a config option
@param string $sName The option name
@param mixed $xDefault The default value, to be returned if the option is not defined
@return mixed The option value, or null if the option is unknown
|
entailment
|
protected function includeAssets()
{
$sPluginOptionName = 'assets.include.' . $this->getName();
if($this->hasOption($sPluginOptionName) && !$this->getOption($sPluginOptionName))
{
return false;
}
if($this->hasOption('assets.include.all') && !$this->getOption('assets.include.all'))
{
return false;
}
return true;
}
|
Check if the assets of this plugin shall be included in Jaxon generated code
@return boolean
|
entailment
|
private function setDefaultOptions()
{
// The default configuration settings.
$this->di()->getConfig()->setOptions([
'core.version' => $this->getVersion(),
'core.language' => 'en',
'core.encoding' => 'utf-8',
'core.decode_utf8' => false,
'core.prefix.function' => 'jaxon_',
'core.prefix.class' => 'Jaxon',
// 'core.request.uri' => '',
'core.request.mode' => 'asynchronous',
'core.request.method' => 'POST', // W3C: Method is case sensitive
'core.response.merge.ap' => true,
'core.response.merge.js' => true,
'core.debug.on' => false,
'core.debug.verbose' => false,
'core.process.exit' => true,
'core.process.clean' => false,
'core.process.timeout' => 6000,
'core.error.handle' => false,
'core.error.log_file' => '',
'core.jquery.no_conflict' => false,
'js.lib.output_id' => 0,
'js.lib.queue_size' => 0,
'js.lib.load_timeout' => 2000,
'js.lib.show_status' => false,
'js.lib.show_cursor' => true,
'js.app.dir' => '',
'js.app.minify' => true,
'js.app.options' => '',
]);
}
|
Set the default options of all components of the library
@return void
|
entailment
|
public function register($sType, $sCallable, $aOptions = [])
{
return $this->getPluginManager()->register($sType, $sCallable, $aOptions);
}
|
Register request handlers, including functions, callable classes and directories.
@param string $sType The type of request handler being registered
Options include:
- Jaxon::USER_FUNCTION: a function declared at global scope
- Jaxon::CALLABLE_CLASS: a class who's methods are to be registered
- Jaxon::CALLABLE_DIR: a directory containing classes to be registered
@param string $sCallable
When registering a function, this is the name of the function
When registering a callable class, this is the class name
When registering a callable directory, this is the full path to the directory
@param array|string $aOptions | $sIncludeFile | $sNamespace
When registering a function, this is an (optional) array
of call options, or the (optional) include file
When registering a callable class, this is an (optional) array
of call options for the class methods
When registering a callable directory, this is an (optional) array
of call options for the class methods, or the (optional) namespace
@return mixed
|
entailment
|
public function setup($sConfigFile)
{
$aConfigOptions = $this->config()->read($sConfigFile);
// Setup the config options into the library.
$sLibKey = 'lib';
$xLibConfig = $this->di()->getConfig();
$xLibConfig->setOptions($aConfigOptions, $sLibKey);
$sAppKey = 'app';
$xAppConfig = new \Jaxon\Config\Config();
$xAppConfig->setOptions($aConfigOptions, $sAppKey);
// Register user functions and classes
$this->getPluginManager()->registerFromConfig($xAppConfig);
return $this;
}
|
Read config options from a config file and setup the library
@param string $sConfigFile The full path to the config file
@return Jaxon
|
entailment
|
public function getScript($bIncludeJs = false, $bIncludeCss = false)
{
if(!$this->getOption('core.request.uri'))
{
$this->setOption('core.request.uri', URI::detect());
}
$sCode = '';
$xCodeGenerator = $this->di()->getCodeGenerator();
if(($bIncludeCss))
{
$sCode .= $xCodeGenerator->getCss() . "\n";
}
if(($bIncludeJs))
{
$sCode .= $xCodeGenerator->getJs() . "\n";
}
$sCode .= $xCodeGenerator->getScript();
return $sCode;
}
|
Returns the Jaxon Javascript header and wrapper code to be printed into the page
The javascript code returned by this function is dependent on the plugins
that are included and the functions and classes that are registered.
@param boolean $bIncludeJs Also get the JS files
@param boolean $bIncludeCss Also get the CSS files
@return string
|
entailment
|
public function processRequest()
{
// Check to see if headers have already been sent out, in which case we can't do our job
if(headers_sent($filename, $linenumber))
{
echo $this->trans('errors.output.already-sent', array(
'location' => $filename . ':' . $linenumber
)), "\n", $this->trans('errors.output.advice');
exit();
}
// Check if there is a plugin to process this request
if(!$this->canProcessRequest())
{
return;
}
$bEndRequest = false;
$mResult = true;
$xResponseManager = $this->getResponseManager();
// Handle before processing event
if(isset($this->aProcessingEvents[self::PROCESSING_EVENT_BEFORE]))
{
$this->aProcessingEvents[self::PROCESSING_EVENT_BEFORE]->call(array(&$bEndRequest));
}
if(!$bEndRequest)
{
try
{
$mResult = $this->getRequestHandler()->processRequest();
}
catch(Exception $e)
{
// An exception was thrown while processing the request.
// The request missed the corresponding handler function,
// or an error occurred while attempting to execute the handler.
// Replace the response, if one has been started and send a debug message.
$xResponseManager->clear();
$xResponseManager->append(new Response\Response());
$xResponseManager->debug($e->getMessage());
$mResult = false;
if($e instanceof \Jaxon\Exception\Error)
{
$sEvent = self::PROCESSING_EVENT_INVALID;
$aParams = array($e->getMessage());
}
else
{
$sEvent = self::PROCESSING_EVENT_ERROR;
$aParams = array($e);
}
if(isset($this->aProcessingEvents[$sEvent]))
{
// Call the processing event
$this->aProcessingEvents[$sEvent]->call($aParams);
}
else
{
// The exception is not to be processed here.
throw $e;
}
}
}
// Clean the processing buffer
if(($this->getOption('core.process.clean')))
{
$er = error_reporting(0);
while (ob_get_level() > 0)
{
ob_end_clean();
}
error_reporting($er);
}
if($mResult === true)
{
// Handle after processing event
if(isset($this->aProcessingEvents[self::PROCESSING_EVENT_AFTER]))
{
$bEndRequest = false;
$this->aProcessingEvents[self::PROCESSING_EVENT_AFTER]->call(array($bEndRequest));
}
// If the called function returned no response, give the the global response instead
if($xResponseManager->hasNoResponse())
{
$xResponseManager->append($this->getResponse());
}
}
$xResponseManager->printDebug();
if(($this->getOption('core.process.exit')))
{
$xResponseManager->sendOutput();
exit();
}
}
|
If this is a jaxon request, call the requested PHP function, build the response and send it back to the browser
This is the main server side engine for Jaxon.
It handles all the incoming requests, including the firing of events and handling of the response.
If your RequestURI is the same as your web page, then this function should be called before ANY
headers or HTML is output from your script.
This function may exit after the request is processed, if the 'core.process.exit' option is set to true.
@return void
@see <Jaxon\Jaxon->canProcessRequest>
|
entailment
|
public function initiate(array $config): void
{
$this->fieldsets = new Collection();
foreach ($config as $key => $value) {
if (\property_exists($this, $key)) {
$this->{$key} = $value;
}
}
$this->data = new Fluent();
}
|
Load grid configuration.
@param array $config
@return void
|
entailment
|
public function with($data)
{
if (\is_array($data)) {
$data = new Fluent($data);
}
$this->data = $data;
return $this;
}
|
Attach data.
<code>
// assign a data
$form->with(DB::table('users')->get());
</code>
@param array|\stdClass|\Illuminate\Database\Eloquent\Model $data
@return mixed
|
entailment
|
public function fieldset($name, Closure $callback = null): FieldsetContract
{
$fieldset = new Fieldset($this->app, $this->templates, $name, $callback);
if (\is_null($name = $fieldset->getName())) {
$name = \sprintf('fieldset-%d', $this->fieldsets->count());
} else {
$name = Str::slug($name);
}
$this->keyMap[$name] = $fieldset;
$this->fieldsets->push($fieldset);
return $fieldset;
}
|
Create a new Fieldset instance.
@param string|\Closure $name
@param \Closure|null $callback
@return \Orchestra\Contracts\Html\Form\Fieldset
|
entailment
|
public function hidden(string $name, $callback = null): void
{
$value = \data_get($this->data, $name);
$field = new Fluent([
'name' => $name,
'value' => $value ?: '',
'attributes' => [],
]);
if ($callback instanceof Closure) {
$callback($field);
}
$this->hiddens[$name] = $this->app->make('form')->hidden($name, $field->get('value'), $field->get('attributes'));
}
|
Add hidden field.
@param string $name
@param \Closure $callback
@return void
|
entailment
|
public function resource(Presenter $listener, $url, Model $model, array $attributes = [])
{
$method = 'POST';
if ($model->exists) {
$url = "{$url}/{$model->getKey()}";
$method = 'PUT';
}
$attributes['method'] = $method;
return $this->setup($listener, $url, $model, $attributes);
}
|
Setup form configuration.
@param \Orchestra\Contracts\Html\Form\Presenter $listener
@param string $url
@param \Illuminate\Database\Eloquent\Model $model
@param array $attributes
@return $this
|
entailment
|
public function setup(Presenter $listener, $url, $model, array $attributes = [])
{
$attributes = \array_merge($attributes, [
'url' => $listener->handles($url),
'method' => $attributes['method'] ?? 'POST',
]);
$this->with($model);
$this->attributes($attributes);
$listener->setupForm($this);
return $this;
}
|
Setup simple form configuration.
@param \Orchestra\Contracts\Html\Form\Presenter $listener
@param string $url
@param \Illuminate\Database\Eloquent\Model $model
@param array $attributes
@return $this
|
entailment
|
protected function getPrevLink()
{
if(!($sCall = $this->xPaginator->getPrevCall()))
{
return '';
}
return $this->xTemplate->render('pagination::links/prev',
['call' => $sCall, 'text' => $this->xPaginator->getPreviousText()]);
}
|
Render the previous link.
@return string
|
entailment
|
protected function getNextLink()
{
if(!($sCall = $this->xPaginator->getNextCall()))
{
return '';
}
return $this->xTemplate->render('pagination::links/next',
['call' => $sCall, 'text' => $this->xPaginator->getNextText()]);
}
|
Render the next link.
@return string
|
entailment
|
protected function getLinks()
{
$sLinks = '';
foreach($this->xPaginator->getPages() as $page)
{
if($page['call'])
{
$sTemplate = ($page['isCurrent'] ? 'pagination::links/current' : 'pagination::links/enabled');
$sLinks .= $this->xTemplate->render($sTemplate, ['call' => $page['call'], 'text' => $page['num']]);
}
else
{
$sLinks .= $this->xTemplate->render('pagination::links/disabled', ['text' => $page['num']]);
}
}
return $sLinks;
}
|
Render the pagination links.
@return string
|
entailment
|
public function render()
{
return $this->xTemplate->render('pagination::wrapper', [
'links' => $this->getLinks(),
'prev' => $this->getPrevLink(),
'next' => $this->getNextLink(),
]);
}
|
Render an HTML pagination control.
@return string
|
entailment
|
public function registerPlugin(\Jaxon\Plugin\Plugin $xPlugin, $nPriority = 1000)
{
$this->getPluginManager()->registerPlugin($xPlugin, $nPriority);
}
|
Register a plugin
Below is a table for priorities and their description:
- 0 thru 999: Plugins that are part of or extensions to the jaxon core
- 1000 thru 8999: User created plugins, typically, these plugins don't care about order
- 9000 thru 9999: Plugins that generally need to be last or near the end of the plugin list
@param Jaxon\Plugin\Plugin $xPlugin An instance of a plugin
@param integer $nPriority The plugin priority, used to order the plugins
@return void
|
entailment
|
public function registerRequestPlugins()
{
$callableRepository = $this->di()->get(CallableRepository::class);
$this->registerPlugin(new CallableClass($callableRepository), 101);
$this->registerPlugin(new CallableDir($callableRepository), 102);
$this->registerPlugin(new UserFunction(), 103);
$this->registerPlugin(new FileUpload(), 104);
}
|
Register the Jaxon request plugins
@return void
|
entailment
|
public static function read($sConfigFile)
{
$sConfigFile = realpath($sConfigFile);
if(!is_readable($sConfigFile))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.access', array('path' => $sConfigFile)));
}
$sFileContent = file_get_contents($sConfigFile);
$aConfigOptions = json_decode($sFileContent, true);
if(!is_array($aConfigOptions))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.content', array('path' => $sConfigFile)));
}
return $aConfigOptions;
}
|
Read options from a JSON formatted config file
@param string $sConfigFile The full path to the config file
@return array
|
entailment
|
public function set(string $key, $value)
{
return Arr::set($this->meta, $key, $value);
}
|
Set meta value.
@param string $key
@param mixed $value
@return array
|
entailment
|
protected function buildFluentAttributes($name, $callback = null): array
{
$label = $name;
if (! \is_string($label)) {
$callback = $label;
$name = '';
$label = '';
} elseif (\is_string($callback)) {
$name = Str::lower($callback);
$callback = null;
} else {
$name = Str::lower($name);
$label = Str::humanize($name);
}
return [$label, $name, $callback];
}
|
Build basic name, label and callback option.
@param mixed $name
@param mixed $callback
@return array
|
entailment
|
public function __isset(string $key): bool
{
if (! \in_array($key, $this->definition['__isset'])) {
throw new InvalidArgumentException("Unable to use __isset for [{$key}].");
}
return isset($this->{$key});
}
|
Magic Method for checking dynamically-set data.
@param string $key
@throws \InvalidArgumentException
@return bool
|
entailment
|
public function register($sType, $sClassName, $aOptions)
{
if($sType != $this->getName())
{
return false;
}
if(!is_string($sClassName))
{
throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
}
if(is_string($aOptions))
{
$aOptions = ['include' => $aOptions];
}
if(!is_array($aOptions))
{
throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration'));
}
$this->xRepository->addClass($sClassName, $aOptions);
return true;
}
|
Register a callable class
@param string $sType The type of request handler being registered
@param string $sClassName The name of the class being registered
@param array|string $aOptions The associated options
@return boolean
|
entailment
|
public function canProcessRequest()
{
// Check the validity of the class name
if(($this->sRequestedClass !== null && !$this->validateClass($this->sRequestedClass)) ||
($this->sRequestedMethod !== null && !$this->validateMethod($this->sRequestedMethod)))
{
$this->sRequestedClass = null;
$this->sRequestedMethod = null;
}
return ($this->sRequestedClass !== null && $this->sRequestedMethod !== null);
}
|
Check if this plugin can process the incoming Jaxon request
@return boolean
|
entailment
|
public function processRequest()
{
if(!$this->canProcessRequest())
{
return false;
}
// Find the requested method
$xCallableObject = $this->xRepository->getCallableObject($this->sRequestedClass);
if(!$xCallableObject || !$xCallableObject->hasMethod($this->sRequestedMethod))
{
// Unable to find the requested object or method
throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid',
['class' => $this->sRequestedClass, 'method' => $this->sRequestedMethod]));
}
// Call the requested method
$jaxon = jaxon();
$aArgs = $jaxon->getRequestHandler()->processArguments();
$xResponse = $xCallableObject->call($this->sRequestedMethod, $aArgs);
if(($xResponse))
{
$jaxon->getResponseManager()->append($xResponse);
}
return true;
}
|
Process the incoming Jaxon request
@return boolean
|
entailment
|
private function setPluginPriority(Plugin $xPlugin, $nPriority)
{
while (isset($this->aPlugins[$nPriority]))
{
$nPriority++;
}
$this->aPlugins[$nPriority] = $xPlugin;
// Sort the array by ascending keys
ksort($this->aPlugins);
}
|
Inserts an entry into an array given the specified priority number
If a plugin already exists with the given priority, the priority is automatically incremented until a free spot is found.
The plugin is then inserted into the empty spot in the array.
@param Plugin $xPlugin An instance of a plugin
@param integer $nPriority The desired priority, used to order the plugins
@return void
|
entailment
|
public function registerPlugin(Plugin $xPlugin, $nPriority = 1000)
{
$bIsAlert = ($xPlugin instanceof \Jaxon\Dialog\Interfaces\Alert);
$bIsConfirm = ($xPlugin instanceof \Jaxon\Dialog\Interfaces\Confirm);
if($xPlugin instanceof Request)
{
// The name of a request plugin is used as key in the plugin table
$this->aRequestPlugins[$xPlugin->getName()] = $xPlugin;
}
elseif($xPlugin instanceof Response)
{
// The name of a response plugin is used as key in the plugin table
$this->aResponsePlugins[$xPlugin->getName()] = $xPlugin;
}
elseif(!$bIsConfirm && !$bIsAlert)
{
throw new \Jaxon\Exception\Error($this->trans('errors.register.invalid', ['name' => get_class($xPlugin)]));
}
// This plugin implements the Alert interface
if($bIsAlert)
{
jaxon()->dialog()->setAlert($xPlugin);
}
// This plugin implements the Confirm interface
if($bIsConfirm)
{
jaxon()->dialog()->setConfirm($xPlugin);
}
// Register the plugin as an event listener
if($xPlugin instanceof \Jaxon\Utils\Interfaces\EventListener)
{
$this->addEventListener($xPlugin);
}
$this->setPluginPriority($xPlugin, $nPriority);
}
|
Register a plugin
Below is a table for priorities and their description:
- 0 thru 999: Plugins that are part of or extensions to the jaxon core
- 1000 thru 8999: User created plugins, typically, these plugins don't care about order
- 9000 thru 9999: Plugins that generally need to be last or near the end of the plugin list
@param Plugin $xPlugin An instance of a plugin
@param integer $nPriority The plugin priority, used to order the plugins
@return void
|
entailment
|
public function registerPackage(string $sPackageClass, Closure $xClosure)
{
$this->aPackages[] = $sPackageClass;
jaxon()->di()->set($sPackageClass, $xClosure);
}
|
Register a package
@param string $sPackageClass The package class name
@param Closure $xClosure A closure to create package instance
@return void
|
entailment
|
public function register($sType, $sCallable, $aOptions = [])
{
if(!key_exists($sType, $this->aRequestPlugins))
{
throw new \Jaxon\Exception\Error($this->trans('errors.register.plugin', ['name' => $sType]));
}
$xPlugin = $this->aRequestPlugins[$sType];
return $xPlugin->register($sType, $sCallable, $aOptions);
// foreach($this->aRequestPlugins as $xPlugin)
// {
// if($mResult instanceof \Jaxon\Request\Request || is_array($mResult) || $mResult === true)
// {
// return $mResult;
// }
// }
// throw new \Jaxon\Exception\Error($this->trans('errors.register.method', ['args' => print_r($aArgs, true)]));
}
|
Register a function, event or callable object
Call the request plugin with the $sType defined as name.
@param string $sType The type of request handler being registered
@param string $sCallable The callable entity being registered
@param array|string $aOptions The associated options
@return mixed
|
entailment
|
public function registerFromConfig($xAppConfig)
{
// Register user functions
$aFunctionsConfig = $xAppConfig->getOption('functions', []);
foreach($aFunctionsConfig as $xKey => $xValue)
{
if(is_integer($xKey) && is_string($xValue))
{
// Register a function without options
$this->register(Jaxon::USER_FUNCTION, $xValue);
}
elseif(is_string($xKey) && is_array($xValue))
{
// Register a function with options
$this->register(Jaxon::USER_FUNCTION, $xKey, $xValue);
}
else
{
continue;
// Todo: throw an exception
}
}
// Register classes and directories
$aClassesConfig = $xAppConfig->getOption('classes', []);
foreach($aClassesConfig as $xKey => $xValue)
{
if(is_integer($xKey) && is_string($xValue))
{
// Register a class without options
$this->register(Jaxon::CALLABLE_CLASS, $xValue);
}
elseif(is_string($xKey) && is_array($xValue))
{
// Register a class with options
$this->register(Jaxon::CALLABLE_CLASS, $xKey, $xValue);
}
elseif(is_integer($xKey) && is_array($xValue))
{
// The directory path is required
if(!key_exists('directory', $xValue))
{
continue;
// Todo: throw an exception
}
// Registering a directory
$sDirectory = $xValue['directory'];
$aOptions = [];
if(key_exists('options', $xValue) &&
(is_array($xValue['options']) || is_string($xValue['options'])))
{
$aOptions = $xValue['options'];
}
// Setup directory options
if(key_exists('namespace', $xValue))
{
$aOptions['namespace'] = $xValue['namespace'];
}
if(key_exists('separator', $xValue))
{
$aOptions['separator'] = $xValue['separator'];
}
// Register a class without options
$this->register(Jaxon::CALLABLE_DIR, $sDirectory, $aOptions);
}
else
{
continue;
// Todo: throw an exception
}
}
}
|
Read and set Jaxon options from a JSON config file
@param Config $xAppConfig The config options
@return void
|
entailment
|
public function getResponsePlugin($sName)
{
if(array_key_exists($sName, $this->aResponsePlugins))
{
return $this->aResponsePlugins[$sName];
}
return null;
}
|
Find the specified response plugin by name and return a reference to it if one exists
@param string $sName The name of the plugin
@return \Jaxon\Plugin\Response
|
entailment
|
public function getRequestPlugin($sName)
{
if(array_key_exists($sName, $this->aRequestPlugins))
{
return $this->aRequestPlugins[$sName];
}
return null;
}
|
Find the specified request plugin by name and return a reference to it if one exists
@param string $sName The name of the plugin
@return \Jaxon\Plugin\Request
|
entailment
|
public function paginator($nItemsTotal, $nItemsPerPage, $nCurrentPage, $xRequest)
{
$paginator = Container::getInstance()->getPaginator();
$paginator->setup($nItemsTotal, $nItemsPerPage, $nCurrentPage, $xRequest);
return $paginator;
}
|
Get the pagination object for a Jaxon request
@param integer $nItemsTotal The total number of items
@param integer $nItemsPerPage The number of items per page page
@param integer $nCurrentPage The current page
@param Jaxon\Request\Request $xRequest A request to a Jaxon function
@return Jaxon\Utils\Paginator The paginator instance
|
entailment
|
protected function registerOrchestraFormBuilder(): void
{
$this->app->singleton(FormControlContract::class, Control::class);
$this->app->singleton(TemplateContract::class, function (Application $app) {
$namespace = $this->hasPackageRepository() ? 'orchestra/html::form' : 'orchestra.form';
$class = $app->make('config')->get("{$namespace}.presenter", BootstrapThreePresenter::class);
return $app->make($class);
});
$this->app->singleton('orchestra.form', function (Application $app) {
return new FormFactory($app);
});
}
|
Register the Orchestra\Form builder instance.
@return void
|
entailment
|
protected function bootConfiguration(): void
{
$config = $this->app->make('config');
$namespace = $this->hasPackageRepository() ? 'orchestra/html::' : 'orchestra.';
$this->app->make('orchestra.form')->setConfig($config->get("{$namespace}form"));
$this->app->make('orchestra.table')->setConfig($config->get("{$namespace}table"));
}
|
Boot extension configurations.
@return void
|
entailment
|
protected function bootComponents(): void
{
$path = realpath(__DIR__.'/../');
$this->addConfigComponent('orchestra/html', 'orchestra/html', "{$path}/config");
$this->addViewComponent('orchestra/html', 'orchestra/html', "{$path}/resources/views");
if (! $this->hasPackageRepository()) {
$this->bootUsingLaravel($path);
}
}
|
Boot extension components.
@return void
|
entailment
|
protected function bootUsingLaravel(string $path): void
{
$this->mergeConfigFrom("{$path}/config/form.php", 'orchestra.form');
$this->mergeConfigFrom("{$path}/config/table.php", 'orchestra.table');
$this->publishes([
"{$path}/config/form.php" => \config_path('orchestra/form.php'),
"{$path}/config/table.php" => \config_path('orchestra/table.php'),
]);
}
|
Boot using Laravel setup.
@param string $path
@return void
|
entailment
|
public function addViewNamespace($sNamespace, $sDirectory, $sExtension = '')
{
return Container::getInstance()->getTemplate()->addNamespace($sNamespace, $sDirectory, $sExtension);
}
|
Add a namespace to the template system
@param string $sNamespace The namespace name
@param string $sDirectory The namespace directory
@param string $sExtension The extension to append to template names
@return void
|
entailment
|
public function plugin($sName)
{
$xPlugin = $this->getPluginManager()->getResponsePlugin($sName);
if(!$xPlugin)
{
return null;
}
$xPlugin->setResponse($this);
return $xPlugin;
}
|
Provides access to registered response plugins
Pass the plugin name as the first argument and the plugin object will be returned.
You can then access the methods of the plugin directly.
@param string $sName The name of the plugin
@return null|\Jaxon\Plugin\Response
|
entailment
|
public function addCommand($aAttributes, $mData)
{
/* merge commands if possible */
if(in_array($aAttributes['cmd'], array('js', 'ap')))
{
if(($aLastCommand = array_pop($this->aCommands)))
{
if($aLastCommand['cmd'] == $aAttributes['cmd'])
{
if($this->getOption('core.response.merge.js') &&
$aLastCommand['cmd'] == 'js')
{
$mData = $aLastCommand['data'].'; '.$mData;
}
elseif($this->getOption('core.response.merge.ap') &&
$aLastCommand['cmd'] == 'ap' &&
$aLastCommand['id'] == $aAttributes['id'] &&
$aLastCommand['prop'] == $aAttributes['prop'])
{
$mData = $aLastCommand['data'].' '.$mData;
}
else
{
$this->aCommands[] = $aLastCommand;
}
}
else
{
$this->aCommands[] = $aLastCommand;
}
}
}
$aAttributes['data'] = $mData;
$this->aCommands[] = $aAttributes;
return $this;
}
|
Add a response command to the array of commands that will be sent to the browser
@param array $aAttributes Associative array of attributes that will describe the command
@param mixed $mData The data to be associated with this command
@return \Jaxon\Plugin\Response
|
entailment
|
public function addPluginCommand($xPlugin, $aAttributes, $mData)
{
$aAttributes['plg'] = $xPlugin->getName();
return $this->addCommand($aAttributes, $mData);
}
|
Add a response command that is generated by a plugin
@param \Jaxon\Plugin\Plugin $xPlugin The plugin object
@param array $aAttributes The attributes for this response command
@param mixed $mData The data to be sent with this command
@return \Jaxon\Plugin\Response
|
entailment
|
public function appendResponse($mCommands, $bBefore = false)
{
$aCommands = [];
if($mCommands instanceof Response)
{
$this->returnValue = $mCommands->returnValue;
$aCommands = $mCommands->aCommands;
}
elseif(is_array($mCommands))
{
$aCommands = $mCommands;
}
else
{
if(!empty($mCommands))
{
throw new \Jaxon\Exception\Error($this->trans('errors.response.data.invalid'));
}
}
if(count($aCommands) > 0)
{
if($bBefore)
{
$this->aCommands = array_merge($aCommands, $this->aCommands);
}
else
{
$this->aCommands = array_merge($this->aCommands, $aCommands);
}
}
}
|
Merge the response commands from the specified <Response> object with
the response commands in this <Response> object
@param Response $mCommands The <Response> object
@param boolean $bBefore Add the new commands to the beginning of the list
@return void
|
entailment
|
public function assign($sTarget, $sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'as',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to assign the specified value to the given element's attribute
@param string $sTarget The id of the html element on the browser
@param string $sAttribute The attribute to be assigned
@param string $sData The value to be assigned to the attribute
@return \Jaxon\Plugin\Response
|
entailment
|
public function append($sTarget, $sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'ap',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to append the specified data to the given element's attribute
@param string $sTarget The id of the element to be updated
@param string $sAttribute The name of the attribute to be appended to
@param string $sData The data to be appended to the attribute
@return \Jaxon\Plugin\Response
|
entailment
|
public function prepend($sTarget, $sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'pp',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to prepend the specified data to the given element's attribute
@param string $sTarget The id of the element to be updated
@param string $sAttribute The name of the attribute to be prepended to
@param string $sData The value to be prepended to the attribute
@return \Jaxon\Plugin\Response
|
entailment
|
public function replace($sTarget, $sAttribute, $sSearch, $sData)
{
return $this->addCommand(
array(
'cmd' => 'rp',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sAttribute, " \t")
),
array(
's' => trim((string)$sSearch, " \t\n"),
'r' => trim((string)$sData, " \t\n")
)
);
}
|
Add a command to replace a specified value with another value within the given element's attribute
@param string $sTarget The id of the element to update
@param string $sAttribute The attribute to be updated
@param string $sSearch The needle to search for
@param string $sData The data to use in place of the needle
@return \Jaxon\Plugin\Response
|
entailment
|
public function clear($sTarget, $sAttribute)
{
return $this->assign(trim((string)$sTarget, " \t"), trim((string)$sAttribute, " \t"), '');
}
|
Add a command to clear the specified attribute of the given element
@param string $sTarget The id of the element to be updated.
@param string $sAttribute The attribute to be cleared
@return \Jaxon\Plugin\Response
|
entailment
|
public function contextAssign($sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'c:as',
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to assign a value to a member of a javascript object (or element)
that is specified by the context member of the request
The object is referenced using the 'this' keyword in the sAttribute parameter.
@param string $sAttribute The attribute to be updated
@param string $sData The value to assign
@return \Jaxon\Plugin\Response
|
entailment
|
public function contextAppend($sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'c:ap',
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to append a value onto the specified member of the javascript
context object (or element) specified by the context member of the request
The object is referenced using the 'this' keyword in the sAttribute parameter.
@param string $sAttribute The attribute to be appended to
@param string $sData The value to append
@return \Jaxon\Plugin\Response
|
entailment
|
public function contextPrepend($sAttribute, $sData)
{
return $this->addCommand(
array(
'cmd' => 'c:pp',
'prop' => trim((string)$sAttribute, " \t")
),
trim((string)$sData, " \t\n")
);
}
|
Add a command to prepend the speicified data to the given member of the current
javascript object specified by context in the current request
The object is access via the 'this' keyword in the sAttribute parameter.
@param string $sAttribute The attribute to be updated
@param string $sData The value to be prepended
@return \Jaxon\Plugin\Response
|
entailment
|
public function redirect($sURL, $iDelay=0)
{
// we need to parse the query part so that the values are rawurlencode()'ed
// can't just use parse_url() cos we could be dealing with a relative URL which
// parse_url() can't deal with.
$queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
if($queryStart !== false)
{
$queryStart++;
$queryEnd = strpos($sURL, '#', $queryStart);
if($queryEnd === false)
$queryEnd = strlen($sURL);
$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
parse_str($queryPart, $queryParts);
$newQueryPart = "";
if($queryParts)
{
$first = true;
foreach($queryParts as $key => $value)
{
if($first)
$first = false;
else
$newQueryPart .= '&';
$newQueryPart .= rawurlencode($key).'='.rawurlencode($value);
}
} elseif($_SERVER['QUERY_STRING']) {
//couldn't break up the query, but there's one there
//possibly "http://url/page.html?query1234" type of query?
//just encode it and hope it works
$newQueryPart = rawurlencode($_SERVER['QUERY_STRING']);
}
$sURL = str_replace($queryPart, $newQueryPart, $sURL);
}
if($iDelay)
$this->script('window.setTimeout("window.location = \'' . $sURL . '\';",' . ($iDelay*1000) . ');');
else
$this->script('window.location = "' . $sURL . '";');
return $this;
}
|
Add a command to ask the browser to navigate to the specified URL
@param string $sURL The relative or fully qualified URL
@param integer $iDelay Number of seconds to delay before the redirect occurs
@return \Jaxon\Plugin\Response
|
entailment
|
public function call($sFunc)
{
$aArgs = func_get_args();
array_shift($aArgs);
return $this->addCommand(
array(
'cmd' => 'jc',
'func' => $sFunc
),
$aArgs
);
}
|
Add a command to call the specified javascript function with the given (optional) parameters
@param string $sFunc The name of the function to call
@return \Jaxon\Plugin\Response
|
entailment
|
public function create($sParent, $sTag, $sId)
{
return $this->addCommand(
array(
'cmd' => 'ce',
'id' => trim((string)$sParent, " \t"),
'prop' => trim((string)$sId, " \t")
),
trim((string)$sTag, " \t\n")
);
}
|
Add a command to create a new element on the browser
@param string $sParent The id of the parent element
@param string $sTag The tag name to be used for the new element
@param string $sId The id to assign to the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function insert($sBefore, $sTag, $sId)
{
return $this->addCommand(
array(
'cmd' => 'ie',
'id' => trim((string)$sBefore, " \t"),
'prop' => trim((string)$sId, " \t")
),
trim((string)$sTag, " \t\n")
);
}
|
Add a command to insert a new element just prior to the specified element
@param string $sBefore The id of the element used as a reference point for the insertion
@param string $sTag The tag name to be used for the new element
@param string $sId The id to assign to the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function insertAfter($sAfter, $sTag, $sId)
{
return $this->addCommand(
array(
'cmd' => 'ia',
'id' => trim((string)$sAfter, " \t"),
'prop' => trim((string)$sId, " \t")
),
trim((string)$sTag, " \t\n")
);
}
|
Add a command to insert a new element after the specified
@param string $sAfter The id of the element used as a reference point for the insertion
@param string $sTag The tag name to be used for the new element
@param string $sId The id to assign to the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function createInput($sParent, $sType, $sName, $sId)
{
return $this->addCommand(
array(
'cmd' => 'ci',
'id' => trim((string)$sParent, " \t"),
'prop' => trim((string)$sId, " \t"),
'type' => trim((string)$sType, " \t")
),
trim((string)$sName, " \t\n")
);
}
|
Add a command to create an input element on the browser
@param string $sParent The id of the parent element
@param string $sType The type of the new input element
@param string $sName The name of the new input element
@param string $sId The id of the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function insertInput($sBefore, $sType, $sName, $sId)
{
return $this->addCommand(
array(
'cmd' => 'ii',
'id' => trim((string)$sBefore, " \t"),
'prop' => trim((string)$sId, " \t"),
'type' => trim((string)$sType, " \t")
),
trim((string)$sName, " \t\n")
);
}
|
Add a command to insert a new input element preceding the specified element
@param string $sBefore The id of the element to be used as the reference point for the insertion
@param string $sType The type of the new input element
@param string $sName The name of the new input element
@param string $sId The id of the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function insertInputAfter($sAfter, $sType, $sName, $sId)
{
return $this->addCommand(
array(
'cmd' => 'iia',
'id' => trim((string)$sAfter, " \t"),
'prop' => trim((string)$sId, " \t"),
'type' => trim((string)$sType, " \t")
),
trim((string)$sName, " \t\n")
);
}
|
Add a command to insert a new input element after the specified element
@param string $sAfter The id of the element to be used as the reference point for the insertion
@param string $sType The type of the new input element
@param string $sName The name of the new input element
@param string $sId The id of the new element
@return \Jaxon\Plugin\Response
|
entailment
|
public function setEvent($sTarget, $sEvent, $sScript)
{
return $this->addCommand(
array(
'cmd' => 'ev',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sEvent, " \t")
),
trim((string)$sScript, " \t\n")
);
}
|
Add a command to set an event handler on the browser
@param string $sTarget The id of the element that contains the event
@param string $sEvent The name of the event
@param string $sScript The javascript to execute when the event is fired
@return \Jaxon\Plugin\Response
|
entailment
|
public function addHandler($sTarget, $sEvent, $sHandler)
{
return $this->addCommand(
array(
'cmd' => 'ah',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sEvent, " \t")
),
trim((string)$sHandler, " \t\n")
);
}
|
Add a command to install an event handler on the specified element
You can add more than one event handler to an element's event using this method.
@param string $sTarget The id of the element
@param string $sEvent The name of the event
@param string $sHandler The name of the javascript function to call when the event is fired
@return \Jaxon\Plugin\Response
|
entailment
|
public function removeHandler($sTarget, $sEvent, $sHandler)
{
return $this->addCommand(
array(
'cmd' => 'rh',
'id' => trim((string)$sTarget, " \t"),
'prop' => trim((string)$sEvent, " \t")
),
trim((string)$sHandler, " \t\n")
);
}
|
Add a command to remove an event handler from an element
@param string $sTarget The id of the element
@param string $sEvent The name of the event
@param string $sHandler The name of the javascript function called when the event is fired
@return \Jaxon\Plugin\Response
|
entailment
|
public function setFunction($sFunction, $sArgs, $sScript)
{
return $this->addCommand(
array(
'cmd' => 'sf',
'func' => trim((string)$sFunction, " \t"),
'prop' => trim((string)$sArgs, " \t")
),
trim((string)$sScript, " \t\n")
);
}
|
Add a command to construct a javascript function on the browser
@param string $sFunction The name of the function to construct
@param string $sArgs Comma separated list of parameter names
@param string $sScript The javascript code that will become the body of the function
@return \Jaxon\Plugin\Response
|
entailment
|
public function wrapFunction($sFunction, $sArgs, $aScripts, $sReturnValueVar)
{
return $this->addCommand(
array(
'cmd' => 'wpf',
'func' => trim((string)$sFunction, " \t"),
'prop' => trim((string)$sArgs, " \t"),
'type' => trim((string)$sReturnValueVar, " \t")
),
$aScripts
);
}
|
Add a command to construct a wrapper function around an existing javascript function on the browser
@param string $sFunction The name of the existing function to wrap
@param string $sArgs The comma separated list of parameters for the function
@param array $aScripts An array of javascript code snippets that will be used to build
the body of the function
The first piece of code specified in the array will occur before
the call to the original function, the second will occur after
the original function is called.
@param string $sReturnValueVar The name of the variable that will retain the return value
from the call to the original function
@return \Jaxon\Plugin\Response
|
entailment
|
public function includeScriptOnce($sFileName, $sType = null, $sId = null)
{
$command = array('cmd' => 'ino');
if(($sType))
$command['type'] = trim((string)$sType, " \t");
if(($sId))
$command['elm_id'] = trim((string)$sId, " \t");
return $this->addCommand($command, trim((string)$sFileName, " \t"));
}
|
Add a command to include a javascript file on the browser if it has not already been loaded
@param string $sFileName The relative or fully qualified URI of the javascript file
@param string $sType Determines the script type. Defaults to 'text/javascript'
@return \Jaxon\Plugin\Response
|
entailment
|
public function removeScript($sFileName, $sUnload = '')
{
return $this->addCommand(
array(
'cmd' => 'rjs',
'unld' => trim((string)$sUnload, " \t")
),
trim((string)$sFileName, " \t")
);
}
|
Add a command to remove a SCRIPT reference to a javascript file on the browser
Optionally, you can call a javascript function just prior to the file being unloaded (for cleanup).
@param string $sFileName The relative or fully qualified URI of the javascript file
@param string $sUnload Name of a javascript function to call prior to unlaoding the file
@return \Jaxon\Plugin\Response
|
entailment
|
public function includeCSS($sFileName, $sMedia = null)
{
$command = array('cmd' => 'css');
if(($sMedia))
$command['media'] = trim((string)$sMedia, " \t");
return $this->addCommand($command, trim((string)$sFileName, " \t"));
}
|
Add a command to include a LINK reference to the specified CSS file on the browser.
This will cause the browser to load and apply the style sheet.
@param string $sFileName The relative or fully qualified URI of the css file
@param string $sMedia The media type of the CSS file. Defaults to 'screen'
@return \Jaxon\Plugin\Response
|
entailment
|
public function domRemoveChildren($parent, $skip = null, $remove = null)
{
$command = array('cmd' => 'DRC');
if(($skip))
$command['skip'] = $skip;
if(($remove))
$command['remove'] = $remove;
return $this->addCommand($command, $parent);
}
|
Add a command to remove children from a DOM element
@param string $parent The DOM parent element
@param string $skip The ??
@param string $remove The ??
@return \Jaxon\Plugin\Response
|
entailment
|
public function sendHeaders()
{
if($this->getRequesthandler()->getRequestMethod() == Jaxon::METHOD_GET)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
}
$sCharacterSet = '';
$sCharacterEncoding = trim($this->getOption('core.encoding'));
if(($sCharacterEncoding) && strlen($sCharacterEncoding) > 0)
{
$sCharacterSet = '; charset="' . trim($sCharacterEncoding) . '"';
}
header('content-type: ' . $this->sContentType . ' ' . $sCharacterSet);
}
|
Used internally to generate the response headers
@return void
|
entailment
|
public function getOutput()
{
$response = [];
if(($this->returnValue))
{
$response['jxnrv'] = $this->returnValue;
}
$response['jxnobj'] = [];
foreach($this->aCommands as $xCommand)
{
$response['jxnobj'][] = $xCommand;
}
return json_encode($response);
}
|
Return the output, generated from the commands added to the response, that will be sent to the browser
@return string
|
entailment
|
public function setProperties($nItemsTotal, $nItemsPerPage, $nCurrentPage)
{
$this->nItemsTotal = $nItemsTotal;
$this->nItemsPerPage = $nItemsPerPage;
$this->nCurrentPage = $nCurrentPage;
return $this;
}
|
Set the paginator properties
@param integer $nItemsTotal the total number of items
@param integer $nItemsPerPage the number of items per page
@param integer $nCurrentPage the current page
@return Paginator
|
entailment
|
private function _loadTranslations($sLanguage, $sPrefix, array $aTranslations)
{
foreach($aTranslations as $sName => $xTranslation)
{
$sName = trim($sName);
$sName = ($sPrefix) ? $sPrefix . '.' . $sName : $sName;
if(!is_array($xTranslation))
{
// Save this translation
$this->aTranslations[$sLanguage][$sName] = $xTranslation;
}
else
{
// Recursively read the translations in the array
$this->_loadTranslations($sLanguage, $sName, $xTranslation);
}
}
}
|
Recursively load translated strings from a array
@param string $sLanguage The language of the translations
@param string $sPrefix The prefix for names
@param array $aTranslations The translated strings
@return void
|
entailment
|
public function loadTranslations($sFilePath, $sLanguage)
{
if(!file_exists($sFilePath))
{
return;
}
$aTranslations = require($sFilePath);
if(!is_array($aTranslations))
{
return;
}
// Load the translations
if(!array_key_exists($sLanguage, $this->aTranslations))
{
$this->aTranslations[$sLanguage] = [];
}
$this->_loadTranslations($sLanguage, '', $aTranslations);
}
|
Load translated strings from a file
@param string $sFilePath The file full path
@param string $sLanguage The language of the strings in this file
@return void
|
entailment
|
public function trans($sText, array $aPlaceHolders = [], $sLanguage = null)
{
$sText = trim((string)$sText);
if(!$sLanguage)
{
$sLanguage = $this->xConfig->getOption('language');
}
if(!$sLanguage)
{
$sLanguage = $this->sDefaultLocale;
}
if(!array_key_exists($sLanguage, $this->aTranslations) || !array_key_exists($sText, $this->aTranslations[$sLanguage]))
{
return $sText;
}
$message = $this->aTranslations[$sLanguage][$sText];
foreach($aPlaceHolders as $name => $value)
{
$message = str_replace(':' . $name, $value, $message);
}
return $message;
}
|
Get a translated string
@param string $sText The key of the translated string
@param string $aPlaceHolders The placeholders of the translated string
@param string $sLanguage The language of the translated string
@return string The translated string
|
entailment
|
public function getField($row, array $templates = []): string
{
$value = $this->attributes['field']($row, $this, $templates);
if ($value instanceof Renderable) {
return $value->render();
}
return $value;
}
|
Get value of column.
@param mixed $row
@param array $templates
@return string
|
entailment
|
public function attributes(array $value = [])
{
$this->attributes['attributes'] = $this->decorate(
$value, $this->attributes['attributes']
);
return $this;
}
|
Setup attributes via decorate.
@param array $value
@return $this
|
entailment
|
protected function filterFilename($sFilename, $sVarName)
{
if(($this->fFileFilter))
{
$fFileFilter = $this->fFileFilter;
$sFilename = (string)$fFileFilter($sFilename, $sVarName);
}
return $sFilename;
}
|
Filter uploaded file name
@param string $sFilename The filename
@param string $sVarName The associated variable name
@return string
|
entailment
|
protected function getUploadDir($sFieldId)
{
// Default upload dir
$sDefaultUploadDir = $this->getOption('upload.default.dir');
$sUploadDir = $this->getOption('upload.files.' . $sFieldId . '.dir', $sDefaultUploadDir);
$sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// Verify that the upload dir exists and is writable
if(!is_writable($sUploadDir))
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
}
$sUploadDir .= $this->sUploadSubdir;
if(!@mkdir($sUploadDir))
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
}
return $sUploadDir;
}
|
Get the path to the upload dir
@param string $sFieldId The filename
@return string
|
entailment
|
protected function getUploadTempDir()
{
// Default upload dir
$sUploadDir = $this->getOption('upload.default.dir');
$sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// Verify that the upload dir exists and is writable
if(!is_writable($sUploadDir))
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
}
$sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR;
if(!@mkdir($sUploadDir))
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
}
return $sUploadDir;
}
|
Get the path to the upload temp dir
@return string
|
entailment
|
protected function getUploadTempFile()
{
$sUploadDir = $this->getOption('upload.default.dir');
$sUploadDir = rtrim(trim($sUploadDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR;
$sUploadTempFile = $sUploadDir . $this->sTempFile . '.json';
if(!is_readable($sUploadTempFile))
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.access'));
}
return $sUploadTempFile;
}
|
Get the path to the upload temp file
@return string
|
entailment
|
protected function readFromHttpData()
{
// Check validity of the uploaded files
$aTempFiles = [];
foreach($_FILES as $sVarName => $aFile)
{
if(is_array($aFile['name']))
{
$nFileCount = count($aFile['name']);
for($i = 0; $i < $nFileCount; $i++)
{
if(!$aFile['name'][$i])
{
continue;
}
if(!array_key_exists($sVarName, $aTempFiles))
{
$aTempFiles[$sVarName] = [];
}
// Filename without the extension
$sFilename = $this->filterFilename(pathinfo($aFile['name'][$i], PATHINFO_FILENAME), $sVarName);
// Copy the file data into the local array
$aTempFiles[$sVarName][] = [
'name' => $aFile['name'][$i],
'type' => $aFile['type'][$i],
'tmp_name' => $aFile['tmp_name'][$i],
'error' => $aFile['error'][$i],
'size' => $aFile['size'][$i],
'filename' => $sFilename,
'extension' => pathinfo($aFile['name'][$i], PATHINFO_EXTENSION),
];
}
}
else
{
if(!$aFile['name'])
{
continue;
}
if(!array_key_exists($sVarName, $aTempFiles))
{
$aTempFiles[$sVarName] = [];
}
// Filename without the extension
$sFilename = $this->filterFilename(pathinfo($aFile['name'], PATHINFO_FILENAME), $sVarName);
// Copy the file data into the local array
$aTempFiles[$sVarName][] = [
'name' => $aFile['name'],
'type' => $aFile['type'],
'tmp_name' => $aFile['tmp_name'],
'error' => $aFile['error'],
'size' => $aFile['size'],
'filename' => $sFilename,
'extension' => pathinfo($aFile['name'], PATHINFO_EXTENSION),
];
}
}
// Check uploaded files validity
foreach($aTempFiles as $sVarName => $aFiles)
{
foreach($aFiles as $aFile)
{
// Verify upload result
if($aFile['error'] != 0)
{
throw new \Jaxon\Exception\Error($this->trans('errors.upload.failed', $aFile));
}
// Verify file validity (format, size)
if(!$this->validateUploadedFile($sVarName, $aFile))
{
throw new \Jaxon\Exception\Error($this->getValidatorMessage());
}
// Get the path to the upload dir
$this->getUploadDir($sVarName);
}
}
// Copy the uploaded files from the temp dir to the user dir
foreach($aTempFiles as $sVarName => $aTempFiles)
{
$this->aUserFiles[$sVarName] = [];
foreach($aTempFiles as $aFile)
{
// Get the path to the upload dir
$sUploadDir = $this->getUploadDir($sVarName);
// Set the user file data
$xUploadedFile = UploadedFile::fromHttpData($sUploadDir, $aFile);
// All's right, move the file to the user dir.
move_uploaded_file($aFile["tmp_name"], $xUploadedFile->path());
$this->aUserFiles[$sVarName][] = $xUploadedFile;
}
}
}
|
Read uploaded files info from HTTP request data
@return void
|
entailment
|
protected function saveToTempFile()
{
// Convert uploaded file to an array
$aFiles = [];
foreach($this->aUserFiles as $sVarName => $aUserFiles)
{
$aFiles[$sVarName] = [];
foreach($aUserFiles as $aUserFile)
{
$aFiles[$sVarName][] = $aUserFile->toTempData();
}
}
// Save upload data in a temp file
$sUploadDir = $this->getUploadTempDir();
$this->sTempFile = uniqid();
file_put_contents($sUploadDir . $this->sTempFile . '.json', json_encode($aFiles));
}
|
Save uploaded files info to a temp file
@return void
|
entailment
|
protected function readFromTempFile()
{
// Upload temp file
$sUploadTempFile = $this->getUploadTempFile();
$aFiles = json_decode(file_get_contents($sUploadTempFile), true);
foreach($aFiles as $sVarName => $aUserFiles)
{
$this->aUserFiles[$sVarName] = [];
foreach($aUserFiles as $aUserFile)
{
$this->aUserFiles[$sVarName][] = UploadedFile::fromTempData($aUserFile);
}
}
unlink($sUploadTempFile);
}
|
Read uploaded files info from a temp file
@return void
|
entailment
|
public function processRequest()
{
if(!$this->canProcessRequest())
{
return false;
}
if(count($_FILES) > 0)
{
$this->readFromHttpData();
}
elseif(($this->sTempFile))
{
$this->readFromTempFile();
}
return true;
}
|
Process the uploaded files into the HTTP request
@return boolean
|
entailment
|
public function ifeq($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '==' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is equal to another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public function ifne($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '!=' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is not equal to another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public function ifgt($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '>' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is greater than another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public function ifge($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '>=' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is greater or equal to another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public function iflt($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '<' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is lower than another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public function ifle($sValue1, $sValue2)
{
$this->sCondition = '(' . Parameter::make($sValue1) . '<=' . Parameter::make($sValue2) . ')';
return $this;
}
|
Check if a value is lower or equal to another before sending the request
@param string $sValue1 The first value to compare
@param string $sValue2 The second value to compare
@return Request
|
entailment
|
public static function read($sConfigFile)
{
$sConfigFile = realpath($sConfigFile);
if(!is_readable($sConfigFile))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.access', array('path' => $sConfigFile)));
}
$aConfigOptions = include($sConfigFile);
if(!is_array($aConfigOptions))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.content', array('path' => $sConfigFile)));
}
return $aConfigOptions;
}
|
Read options from a PHP config file
@param string $sConfigFile The full path to the config file
@return array
|
entailment
|
public function element($sSelector = '', $sContext = '')
{
$xElement = new Element($sSelector, $sContext);
$this->addCommand(array('cmd' => 'jquery'), $xElement);
return $xElement;
}
|
Create a JQuery Element with a given selector, and link it to the current response.
Since this element is linked to a response, its code will be automatically sent to the client.
The returned object can be used to call jQuery functions on the selected elements.
@param string $sSelector The jQuery selector
@param string $sContext A context associated to the selector
@return Element
|
entailment
|
public function render(): string
{
$grid = $this->grid;
// Add paginate value for current listing while appending query string,
// however we also need to remove ?page from being added twice.
$input = Arr::except($this->request->query(), [$grid->pageName]);
$grid->data();
$pagination = (true === $grid->paginated() ? $grid->model->appends($input) : '');
$data = [
'empty' => $this->translator->get($grid->empty),
'grid' => $grid,
'pagination' => $pagination,
'meta' => $grid->viewData,
];
// Build the view and render it.
$view = $this->view->make($grid->view())->with($data);
return $view->render();
}
|
{@inheritdoc}
|
entailment
|
public static function read($sConfigFile)
{
$sConfigFile = realpath($sConfigFile);
if(!extension_loaded('yaml'))
{
throw new \Jaxon\Config\Exception\Yaml(jaxon_trans('config.errors.yaml.install'));
}
if(!is_readable($sConfigFile))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.access', array('path' => $sConfigFile)));
}
$aConfigOptions = yaml_parse_file($sConfigFile);
if(!is_array($aConfigOptions))
{
throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.content', array('path' => $sConfigFile)));
}
return $aConfigOptions;
}
|
Read options from a YAML formatted config file
@param string $sConfigFile The full path to the config file
@return array
|
entailment
|
public function checkbox(FieldContract $field): Htmlable
{
return $this->form->checkbox(
$field->get('name'),
$field->get('value'),
$field->get('checked'),
$field->get('attributes')
);
}
|
Checkbox template.
@param \Orchestra\Contracts\Html\Form\Field $field
@return \Illuminate\Contracts\Support\Htmlable
|
entailment
|
public function checkboxes(FieldContract $field): Htmlable
{
return $this->form->checkboxes(
$field->get('name'),
$this->asArray($field->get('options')),
$field->get('checked'),
$field->get('attributes')
);
}
|
Checkboxes template.
@param \Orchestra\Contracts\Html\Form\Field $field
@return \Illuminate\Contracts\Support\Htmlable
|
entailment
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.