本文整理汇总了PHP中ObjectConfig类的典型用法代码示例。如果您正苦于以下问题:PHP ObjectConfig类的具体用法?PHP ObjectConfig怎么用?PHP ObjectConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initialize
/**
* Initializes the options for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options
* @return void
*/
protected function _initialize(ObjectConfig $config)
{
if (empty($config->resolvers)) {
$config->append(array('resolvers' => array('extension')));
}
parent::_initialize($config);
}
示例2: _initialize
/**
* Initializes the config for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options
* @return void
*/
protected function _initialize(ObjectConfig $config)
{
//Clone the identifier
$identifier = clone $this->getIdentifier();
$config->append(array('data' => array(), 'layout' => '', 'template' => $this->getName(), 'template_filters' => array('shorttag', 'function', 'url', 'decorator'), 'auto_assign' => true));
parent::_initialize($config);
}
示例3: _initialize
/**
* Initializes the options for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options.
* @return void
*/
protected function _initialize(ObjectConfig $config)
{
//Create permission identifier
$permission = clone $this->getIdentifier();
$permission->path = array('dispatcher', 'permission');
$config->append(array('controller' => $this->getIdentifier()->package, 'request' => 'lib:dispatcher.request', 'response' => 'lib:dispatcher.response', 'user' => 'lib:dispatcher.user', 'behaviors' => array($permission)));
parent::_initialize($config);
}
示例4: _initialize
/**
* Initializes the options for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options
*/
protected function _initialize(ObjectConfig $config)
{
$self = $this;
$config->append(array('autoescape' => true, 'strict_variables' => false, 'optimizations' => -1, 'functions' => array('import' => function ($url, $data) use($self) {
return $self->renderPartial($url, $data);
})));
parent::_initialize($config);
}
示例5: _initialize
/**
* Initializes the default configuration for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options.
* @return void
*/
protected function _initialize(ObjectConfig $config)
{
$toolbars = array();
if ($config->dispatched && $config->user->isAuthentic()) {
$toolbars[] = $this->getIdentifier()->name;
}
$config->append(array('toolbars' => $toolbars, 'model' => $this->getIdentifier()->name));
parent::_initialize($config);
}
示例6: preview
/**
* Generates an HTML image preview listbox
*
* $config options:
*
* name string column name of helper
* directory string image directory (relative to docroot)
* width int image width
* height int image height
* border int border width
* style string style string
* selected string currently selected vallue
*
* @param array $config An optional array with configuration options
* @return string Html
*/
public function preview($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('name' => 'image_name', 'directory' => JPATH_IMAGES . '/stories', 'width' => 80, 'height' => 80, 'border' => 2, 'style' => 'margin: 10px 0;'))->append(array('selected' => $config->{$config->name}));
$image = $this->getObject('request')->getBasePath() . str_replace(JPATH_ROOT, '', $config->directory) . '/' . $config->selected;
$path = $config->selected ? $image : 'media://images/blank.png';
$html = '<img ' . $this->_buildAttributes(array('src' => $path, 'id' => $config->name . '-preview', 'class' => 'preview', 'width' => $config->width, 'height' => $config->height, 'border' => $config->border, 'alt' => \JText::_('Preview'), 'style' => $config->style)) . ' />';
return $html;
}
示例7: humanize
/**
* Returns human readable date.
*
* @param array $config An optional array with configuration options.
* @return string Formatted date.
*/
public function humanize($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => \JText::_('Never'), 'smallest_period' => 'second'));
$result = $config->default;
if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
$lengths = array(60, 60, 24, 7, 4.35, 12, 10);
$now = new \DateTime();
try {
$date = new Date(array('date' => $config->date, 'timezone' => 'UTC'));
$date->setTimezone(new \DateTimeZone($config->timezone));
if ($now != $date) {
// TODO: Use DateTime::getTimeStamp().
if ($now > $date) {
$difference = $now->format('U') - $date->format('U');
$tense = 'ago';
} else {
$difference = $date->format('U') - $now->format('U');
$tense = 'from now';
}
for ($i = 0; $difference >= $lengths[$i] && $i < 6; $i++) {
$difference /= $lengths[$i];
}
$difference = round($difference);
$period_index = array_search($config->smallest_period, $periods);
$omitted_periods = $periods;
array_splice($omitted_periods, $period_index);
if (in_array($periods[$i], $omitted_periods)) {
$difference = 1;
$i = $period_index;
}
if ($periods[$i] == 'day' && ($difference == 1 || $difference == 2)) {
if ($difference == 1) {
$result = \JText::_('Today');
} else {
$result = $tense == 'ago' ? \JText::_('Yesterday') : \JText::_('Tomorrow');
}
} else {
if ($difference != 1) {
$periods[$i] .= 's';
}
$result = sprintf(\JText::_('%d ' . $periods[$i] . ' ' . $tense), $difference);
}
} else {
$result = \JText::_('Now');
}
} catch (\Exception $e) {
}
}
return $result;
}
示例8: options
/**
* Generates a select option list
*
* @param array $config An optional array with configuration options
* @return array An array of objects containing the option attributes
*/
public function options($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('entity' => array(), 'name' => 'id', 'value' => 'id', 'label' => 'id', 'disabled' => null, 'attribs' => array()));
$options = array();
foreach ($config->entity as $entity) {
$option = array('id' => isset($entity->{$config->name}) ? $entity->{$config->name} : null, 'name' => $config->name, 'disabled' => $config->disabled, 'attribs' => ObjectConfig::unbox($config->attribs), 'value' => $entity->{$config->value}, 'label' => $entity->{$config->label});
if ($config->entity instanceof \RecursiveIteratorIterator) {
$option['level'] = $config->entity->getDepth() + 1;
}
$options[] = $this->option($option);
}
return $options;
}
示例9: humanize
/**
* Returns human readable date.
*
* @param array $config An optional array with configuration options.
* @return string Formatted date.
*/
public function humanize($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => $this->getObject('translator')->translate('Never'), 'period' => 'second'));
$result = $config->default;
if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
try {
$date = $this->getObject('date', array('date' => $config->date, 'timezone' => 'UTC'));
$date->setTimezone(new \DateTimeZone($config->timezone));
$result = $date->humanize($config->period);
} catch (Exception $e) {
}
}
return $result;
}
示例10: buildAttributes
/**
* Build a string with xml style attributes from an array of key/value pairs
*
* @param mixed $array The array of Key/Value pairs for the attributes
* @return string String containing xml style attributes
*/
public function buildAttributes($array)
{
$output = array();
if ($array instanceof ObjectConfig) {
$array = ObjectConfig::unbox($array);
}
if (is_array($array)) {
foreach ($array as $key => $item) {
if (is_array($item)) {
if (empty($item)) {
continue;
}
$item = implode(' ', $item);
}
if (is_bool($item)) {
if ($item === false) {
continue;
}
$item = $key;
}
$output[] = $key . '="' . str_replace('"', '"', $item) . '"';
}
}
return implode(' ', $output);
}
示例11: invokeHelper
/**
* Invoke a template helper
*
* This function accepts a partial identifier, in the form of helper.method or schema:package.helper.method. If
* a partial identifier is passed a full identifier will be created using the template identifier.
*
* If the state have the same string keys, then the parameter value for that key will overwrite the state.
*
* @param string $identifier Name of the helper, dot separated including the helper function to call
* @param array $params An optional associative array of functions parameters to be passed to the helper
* @return string Helper output
* @throws \BadMethodCallException If the helper function cannot be called.
*/
public function invokeHelper($identifier, $params = array())
{
//Get the function and helper based on the identifier
$parts = explode('.', $identifier);
$function = array_pop($parts);
$identifier = array_pop($parts);
//Handle schema:package.helper.function identifiers
if (!empty($parts)) {
$identifier = implode('.', $parts) . '.template.helper.' . $identifier;
}
//Create the complete identifier if a partial identifier was passed
if (is_string($identifier) && strpos($identifier, '.') === false) {
$helper = $this->getMixer()->getIdentifier()->toArray();
if ($helper['type'] != 'lib') {
$helper['path'] = array('template', 'helper');
} else {
$helper['path'] = array('helper');
}
$helper['name'] = $identifier;
} else {
$helper = $this->getIdentifier($identifier);
}
$helper = $this->getObject('template.helper.factory')->createHelper($helper, ObjectConfig::unbox($params));
//Call the helper function
if (!is_callable(array($helper, $function))) {
throw new \BadMethodCallException(get_class($helper) . '::' . $function . ' not supported.');
}
//Merge the parameters if helper asks for it
if ($helper instanceof TemplateHelperParameterizable) {
$params = array_merge($this->getParameters()->toArray(), $params);
}
return $helper->{$function}($params);
}
示例12: _actionRender
/**
* Return the views output
*
* @param ViewContextTemplate $context A view context object
* @return string The output of the view
*/
protected function _actionRender(ViewContextTemplate $context)
{
$data = ObjectConfig::unbox($context->data);
$path = $this->qualifyLayout($context->layout);
//Render the template
$content = $this->getTemplate()->setParameters($context->parameters)->render($path, $data);
return $content;
}
示例13: humanize
/**
* Returns human readable date.
*
* @param array $config An optional array with configuration options.
* @return string Formatted date.
*/
public function humanize($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => $this->translate('Never'), 'smallest_period' => 'second'));
$result = $config->default;
if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
$lengths = array(60, 60, 24, 7, 4.35, 12, 10);
$now = new \DateTime();
try {
$date = new Date(array('date' => $config->date, 'timezone' => 'UTC'));
$date->setTimezone(new \DateTimeZone($config->timezone));
$result = $date->humanize($config->period);
} catch (\Exception $e) {
}
}
return $result;
}
示例14: _afterReset
/**
* Recalculate offset
*
* @param ModelContextInterface $context A model context object
* @return void
*/
protected function _afterReset(ModelContextInterface $context)
{
$modified = (array) ObjectConfig::unbox($context->modified);
if (in_array('limit', $modified)) {
$limit = $context->state->limit;
if ($limit) {
$context->state->offset = floor($context->state->offset / $limit) * $limit;
}
}
}
示例15: __construct
/**
* Constructor
*
* @param ObjectConfig $config An optional ObjectConfig object with configuration options.
*/
public function __construct(ObjectConfig $config)
{
parent::__construct($config);
//Add the toolbars
$toolbars = (array) ObjectConfig::unbox($config->toolbars);
foreach ($toolbars as $key => $value) {
if (is_numeric($key)) {
$this->attachToolbar($value);
} else {
$this->attachToolbar($key, $value);
}
}
}