本文整理汇总了PHP中KInflector类的典型用法代码示例。如果您正苦于以下问题:PHP KInflector类的具体用法?PHP KInflector怎么用?PHP KInflector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KInflector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findPath
/**
* Get the path based on a class name
*
* @param string The class name
* @return string|false Returns the path on success FALSE on failure
*/
public function findPath($classname, $basepath = null)
{
$path = false;
if (strpos($classname, $this->_prefix) === 0) {
$word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $classname));
$parts = explode('_', $word);
if (array_shift($parts) == 'tmpl') {
$name = array_shift($parts);
$file = array_pop($parts);
if (count($parts)) {
if ($parts[0] != 'view') {
foreach ($parts as $key => $value) {
$parts[$key] = KInflector::pluralize($value);
}
} else {
$parts[0] = KInflector::pluralize($parts[0]);
}
$path = implode('/', $parts) . '/' . $file;
} else {
$path = $file;
}
$path = $this->_basepath . '/templates/' . $name . '/' . $path . '.php';
}
}
return $path;
}
示例2: _initialize
/**
* Initializes the options for the object.
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param object An optional KConfig object with configuration options.
*/
protected function _initialize(KConfig $config)
{
$child = clone $this->_parent;
$child->name = KInflector::singularize($config->name);
$config->append(array('entityset' => 'anahita:domain.entityset.onetomany', 'cardinality' => 'many', 'child_key' => $this->_parent->name, 'parent_delete' => AnDomain::DELETE_CASCADE, 'child' => $child));
parent::_initialize($config);
}
示例3: _initialize
/**
* Initializes the options for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param object An optional KConfig object with configuration options.
* @return void
*/
protected function _initialize(KConfig $config)
{
$package = $this->_identifier->package;
$name = KInflector::singularize($this->_identifier->name);
$config->append(array('xml_path' => JPATH_ADMINISTRATOR . '/components/com_' . $package . '/views/' . $name . '/tmpl/' . $name . '.xml'));
parent::_initialize($config);
}
示例4: onContentSearch
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
{
if ($text) {
$rows = array();
$rowset = KService::get('com://admin/kutafuta.model.terms')->type($phrase)->search($text)->getList();
foreach ($rowset as $row) {
// We have table and row.
// Row is always multiple but we check non the less.
$parts = explode('_', $row->table);
$data = KService::get('com://site/' . $parts[0] . '.model.' . KInflector::pluralize($parts[1]))->id($row->row)->getItem();
if (empty($data->id)) {
continue;
}
$result = new stdClass();
$result->title = $data->title;
$result->metadesc = $data->meta_description;
$result->metakey = $data->meta_keywords;
$result->created = $data->created_on;
$result->text = $data->introtext . $data->fulltext;
$result->href = 'index.php?option=com_' . $parts[0] . '&view=' . KInflector::singularize($parts[1]) . '&id=' . $row->row;
$rows[] = $result;
}
return $rows;
}
}
示例5: _commandDelete
/**
* Delete Command for an entity.
*
* @param LibBaseTemplateObject $command The action object
*/
protected function _commandDelete($command)
{
$entity = $this->getController()->getItem();
$name = KInflector::pluralize($this->getController()->getIdentifier()->name);
$redirect = 'option=com_' . $this->getIdentifier()->package . '&view=' . $name;
$command->append(array('label' => JText::_('LIB-AN-ACTION-DELETE')))->href(JRoute::_($entity->getURL()))->setAttribute('data-action', 'delete')->setAttribute('data-redirect', JRoute::_($redirect))->class('action-delete');
}
示例6: _pathFromIdentifier
/**
* Get the path based on an identifier
*
* @param object An Identifier object - com:[//application/]component.view.[.path].name
* @return string|false Returns the path on success FALSE on failure
*/
protected function _pathFromIdentifier($identifier)
{
$path = false;
if($identifier->type == 'yaml')
{
$parts = $identifier->path;
$component = 'com_'.strtolower($identifier->package);
//Store the basepath for re-use
if($identifier->basepath) {
$this->_basepath = $identifier->basepath;
}
if(!empty($identifier->name))
{
if(count($parts))
{
$path = KInflector::pluralize(array_shift($parts));
$path .= count($parts) ? '/'.implode('/', $parts) : '';
$path .= '/'.strtolower($identifier->name);
}
else $path = strtolower($identifier->name);
}
$path = $this->_basepath.'/components/'.$component.'/'.$path.'.yaml';
}
return $path;
}
示例7: setPermissions
/**
* Generic function for setting the permissions
*
* @return void
*/
public function setPermissions($context)
{
//Temp fix
if (KInflector::isPlural(KRequest::get('get.view', 'cmd')) || KRequest::type() == 'AJAX') {
return;
}
$model = KFactory::get($this->getModel());
$table = KFactory::tmp(KFactory::get(KFactory::get('admin::com.ninja.helper.access')->models->assets)->getTable());
$query = $table->getDatabase()->getQuery();
$item = $model->getItem();
$identifier = $this->getIdentifier();
$id = $identifier->type . '_' . $identifier->package . '.' . $identifier->name . '.' . $item->id . '.';
$permissions = (array) KRequest::get('post.permissions', 'int');
$editable = KRequest::get('post.editpermissions', 'boolean', false);
if (!$permissions && $editable) {
$query->where('tbl.name', 'LIKE', $id . '%');
$table->select($query)->delete();
}
$safe = array();
$query = $table->getDatabase()->getQuery()->where('name', 'like', $id . '%');
foreach ((array) KRequest::get('post.params.permissions', 'raw') as $group => $other) {
$safe[] = $id . $group;
}
if ($safe) {
$query->where('name', 'not in', $safe);
}
$table->select($query, KDatabase::FETCH_ROWSET)->delete();
foreach ($permissions as $usergroup => $rules) {
foreach ($rules as $name => $permission) {
KFactory::tmp(KFactory::get('admin::com.ninja.helper.access')->models->assets)->name($id . $usergroup . '.' . $name)->getItem()->setData(array('name' => $id . $usergroup . '.' . $name, 'level' => $permission))->save();
}
}
}
示例8: _buildQueryJoins
/**
* @param KDatabaseQuery $query
*/
protected function _buildQueryJoins(KDatabaseQuery $query)
{
$state = $this->_state;
parent::_buildQueryJoins($query);
$iso_code = substr(JFactory::getLanguage()->getTag(), 0, 2);
if ($iso_code != 'en') {
$prefix = $iso_code . '_';
}
if (is_array($state->type)) {
$subquery = '(';
$i = 1;
foreach ($state->type as $type) {
$subquery .= 'SELECT ' . KInflector::pluralize($type) . '_' . KInflector::singularize($type) . '_id AS id, LOWER("' . strtoupper(KInflector::pluralize($type)) . '_' . strtoupper(KInflector::pluralize($type)) . '") AS test FROM #__' . $prefix . KInflector::pluralize($type) . '_' . KInflector::pluralize($type) . ' AS ' . KInflector::pluralize($type) . '
WHERE enabled = 1 AND frontpage = 1';
if (KInflector::singularize($type) == 'event') {
$subquery .= ' AND start_date >= CURDATE()';
}
if ($i < count($state->type)) {
$subquery .= ' UNION ALL ';
}
$i++;
}
$subquery .= ')';
$query->join[] = array('type' => 'INNER', 'table' => $subquery . 'AS b', 'condition' => array('tbl.row = b.id AND tbl.table = b.test'));
}
}
示例9: _updateLanguages
public function _updateLanguages($id, $items)
{
foreach ($items as $language => $item) {
$model_identifier = clone $item->getIdentifier();
$model_identifier->path = array('model');
$model_identifier->name = KInflector::pluralize($model_identifier->name);
// Original Data
$data = $item->getData();
unset($data['id']);
if (isset($data['featured'])) {
unset($data['featured']);
}
$this->_checkName($item, false);
$title = $item->title . ' (' . $this->count . ')';
$slug = $item->slug . '-' . $this->count;
JFactory::getLanguage()->setLanguage($language);
$row = $this->getService($model_identifier)->id($id)->getItem();
$row->setData($data);
$row->title = $title;
$row->enabled = 0;
$row->slug = $slug;
$row->translated = 0;
if ($row->isRelationable()) {
$row->setData(json_decode($row->ancestors));
$row->setData(json_decode($row->descendants));
}
$row->save();
}
}
示例10: translations
public function translations($config = array())
{
$config = new KConfig($config);
$config->append(array('row' => null, 'table' => ''));
// First for our knowledge we get the original language (if exists.)
$original = $this->_getOriginalLanguage($config->row, $config->table);
$html = '<style src="media://com_translations/css/translations.css" />';
$view = KInflector::singularize(KRequest::get('get.view', 'string'));
foreach ($this->_getLanguages() as $language) {
$relation = $this->_getLanguage($config, $language->lang_code);
if ($language->lang_code == $original->iso_code) {
$html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-info">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
} else {
if ($relation->translated) {
$html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-success">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
} else {
if (strtotime('+ 2 weeks', strtotime($original->created_on)) > strtotime(date('d-m-Y H:i:s'))) {
$html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-warning">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
} else {
if (strtotime('+ 2 weeks', strtotime($original->created_on)) < strtotime(date('d-m-Y H:i:s'))) {
$html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-important">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
}
}
}
}
}
return $html;
}
示例11: getCommands
/**
* Get the list of commands
*
* Will attempt to use information from the xml manifest if possible
*
* @return array
*/
public function getCommands()
{
$name = $this->getController()->getIdentifier()->name;
$package = $this->_identifier->package;
$manifest = JPATH_ADMINISTRATOR.'/components/com_'.$package.'/manifest.xml';
if(file_exists($manifest))
{
$xml = simplexml_load_file($manifest);
if(isset($xml->administration->submenu))
{
foreach($xml->administration->submenu->children() as $menu)
{
$view = (string)$menu['view'];
$this->addCommand(JText::_((string)$menu), array(
'href' => JRoute::_('index.php?option=com_'.$package.'&view='.$view),
'active' => ($name == KInflector::singularize($view))
));
}
}
}
return parent::getCommands();
}
示例12: id
/**
* Helper for creating DOM element ids used by javascript behaviors
*
* If no type and package identifiers were supplied,
* uses the current option $_GET variable, and changing com_foo_bar to com-foo_bar.
* '-' are used as separators, and in our javascript used to parse identifier strings.
* If a form got the id com-foo_bar-people,
* then we can assume that the toolbar will have the id toolbar-people,
*
* @author Stian Didriksen <stian@ninjaforge.com>
* @param array | int $parts
* @return string
*/
public function id($parts = array())
{
if (!is_array($parts) && is_int($parts)) {
$parts['id'] = (int) $parts;
}
// If we pass a string, set $parts back as an array in order to proceed.
if (!is_array($parts)) {
settype($parts, 'array');
}
// Set the defaults, if needed
$defaults = array();
if (!isset($parts['type.package'])) {
// We only want to replace the first underscore, not the rest.
$defaults['type_package'] = str_replace('com_', 'com-', KRequest::get('get.option', 'cmd'));
}
if (!isset($parts['view'])) {
$view = KRequest::get('get.view', 'cmd');
// The view part always needs to be plural to allow ajax BREAD.
if (KInflector::isSingular($view)) {
$view = KInflector::pluralize($view);
}
$defaults['view'] = $view;
}
if (!isset($parts['id']) && KRequest::has('get.id', 'int')) {
$defaults['id'] = KRequest::get('get.id', 'int');
}
// Filter away parts that are unset on purpose using a null value, or a negative boolean.
return implode('-', array_filter(array_merge($defaults, $parts)));
}
示例13: setModel
public function setModel($model)
{
$model = parent::setModel($model);
$model->package = KInflector::pluralize($this->_identifier->name);
return $model;
}
示例14: loadClass
/**
* Load the file for a class
*
* @param string $class The class that will be loaded
* @return boolean True on success
*/
public static function loadClass($class)
{
// pre-empt further searching for the named class or interface.
// do not use autoload, because this method is registered with
// spl_autoload already.
if (class_exists($class, false) || interface_exists($class, false)) {
return;
}
// if class start with a 'Nooku' it is a Nooku class.
// create the path and register it with the loader.
switch (substr($class, 0, 6)) {
case 'Picman':
$word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', substr_replace($class, '', 0, 6)));
$parts = explode('_', $word);
if (count($parts) > 1) {
$path = KInflector::pluralize(array_shift($parts)) . DS . implode(DS, $parts);
} else {
$path = $word;
}
if (is_file(dirname(__FILE__) . DS . $path . '.php')) {
KLoader::register($class, dirname(__FILE__) . DS . $path . '.php');
}
break;
}
$classes = KLoader::register();
if (array_key_exists(strtolower($class), $classes)) {
include $classes[strtolower($class)];
return true;
}
return false;
}
示例15: order
public function order($config = array())
{
$config = new KConfig($config);
$config->append(array(
'name' => 'order',
'state' => null,
'attribs' => array(),
'model' => null,
'package' => $this->getIdentifier()->package,
'selected' => 0
));
//@TODO can be removed when name collisions fixed
$config->name = 'order';
$app = $this->getIdentifier()->application;
$identifier = 'com://'.$app.'/'.$config->package.'.model.'.($config->model ? $config->model : KInflector::pluralize($config->package));
$list = KFactory::get($identifier)->limit(0)->set($config->filter)->getList();
$options = array();
foreach($list as $item) {
$options[] = $this->option(array('text' => $item->ordering, 'value' => $item->ordering - $config->ordering));
}
$list = $this->optionlist(array(
'options' => $options,
'name' => $config->name,
'attribs' => $config->attribs,
'selected' => $config->selected
));
return $list;
}