本文整理汇总了PHP中KInflector::isSingular方法的典型用法代码示例。如果您正苦于以下问题:PHP KInflector::isSingular方法的具体用法?PHP KInflector::isSingular怎么用?PHP KInflector::isSingular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KInflector
的用法示例。
在下文中一共展示了KInflector::isSingular方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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)));
}
示例2: _initialize
/**
* Initializes the configuration for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param array Configuration settings
*/
protected function _initialize(KConfig $config)
{
$config->append(array(
'layout' => KInflector::isSingular($this->getName()) ? 'form' : 'default'
));
parent::_initialize($config);
}
示例3: addCommand
/**
* Add a command
*
* Disable the menubar only for singular views that are editable.
*
* @param string The command name
* @param mixed Parameters to be passed to the command
* @return KControllerToolbarInterface
*/
public function addCommand($name, $config = array())
{
parent::addCommand($name, $config);
$controller = $this->getController();
if ($controller->isEditable() && KInflector::isSingular($controller->getView()->getName())) {
$this->_commands[$name]->disabled = true;
}
return $this;
}
示例4: _actionGet
/**
* _actionGet here we will check if the we access a singular or a plural,
* when plural the action will return true if singular we will check if the requested tile exists.
*
* @param KCommandContext $context
* @return bool|KDatabaseRow
*/
protected function _actionGet(KCommandContext $context)
{
if (KInflector::isSingular($this->_request->view) && !$this->_request->type) {
if (!file_exists(JPATH_FILES . '/' . $this->_request->path) || is_dir(JPATH_FILES . '/' . $this->_request->path)) {
return false;
}
}
return parent::_actionGet($context);
}
示例5: _actionDisplay
/**
* Display the view
*
* @return void
*/
protected function _actionDisplay(KCommandContext $context)
{
//Check if we are reading or browsing
$action = KInflector::isSingular($this->getView()->getName()) ? 'read' : 'browse';
//Execute the action
$this->execute($action, $context);
$view = $this->getView();
if (!$view instanceof ComNinjaViewHtml && $view instanceof KViewTemplate) {
$view->getTemplate()->addFilters(array(KFactory::get('admin::com.ninja.template.filter.document')));
}
$view->setLayout($this->_request->layout);
return $view->display();
}
示例6: _createToolbar
public function _createToolbar()
{
$identifier = $this->getToolbar();
$name = $identifier->name;
$package = $identifier->package;
KFactory::get('admin::com.ninja.helper.default')->css('/toolbar.css');
$img = KInflector::isPLural($name) ? KFactory::get('admin::com.ninja.helper.default')->img('/48/' . $name . '.png') : KFactory::get('admin::com.ninja.helper.default')->img('/48/' . KInflector::pluralize($name) . '.png');
if (!$img) {
$img = KInflector::isSingular($name) ? KFactory::get('admin::com.ninja.helper.default')->img('/48/' . $name . '.png') : KFactory::get('admin::com.ninja.helper.default')->img('/48/' . KInflector::singularize($name) . '.png');
}
if ($img) {
KFactory::get('admin::com.ninja.helper.default')->css('.header.icon-48-' . $name . ' { background-image: url(' . $img . '); }');
}
return KFactory::get($identifier, array('icon' => $name));
}
示例7: __getRelation
/**
* @param $column
* @return null
*/
private function __getRelation($type, $column)
{
$relations = $this->getRelations();
$taxonomies = json_decode($this->{$type});
if (KInflector::isSingular($column)) {
return $this->getService($relations->{$type}->{$column}->identifier)->id($taxonomies->{$column})->getItem();
}
if (KInflector::isPlural($column)) {
$model = $this->getService($relations->{$type}->{$column}->identifier);
$state = $model->getState();
if ($relations->{$type}->{$column}->{$column}->state) {
foreach ($relations->{$type}->{$column}->state as $key => $value) {
if ($filter = $state[$key]->filter) {
$state->remove($key)->insert($key, $filter, $value);
}
}
}
return $model->id($taxonomies->{$column})->getList();
}
}
示例8: _actionRender
/**
* Push the controller data into the document
*
* This function divert the standard behavior and will push specific controller data
* into the document
*
* @return KDispatcherDefault
*/
protected function _actionRender(KCommandContext $context)
{
$controller = KFactory::get($this->getController());
$view = $controller->getView();
$document = KFactory::get('lib.joomla.document');
$document->setMimeEncoding($view->mimetype);
if ($view instanceof ComDefaultViewHtml) {
$document->setBuffer($view->getToolbar()->render(), 'modules', 'toolbar');
$document->setBuffer($view->getToolbar()->renderTitle(), 'modules', 'title');
if (KInflector::isSingular($view->getName()) && !KRequest::has('get.hidemainmenu')) {
KRequest::set('get.hidemainmenu', 1);
}
if (isset($view->views)) {
foreach ($view->views as $name => $title) {
$active = $name == strtolower($view->getName());
$component = $this->_identifier->package;
JSubMenuHelper::addEntry(JText::_($title), 'index.php?option=com_' . $component . '&view=' . $name, $active);
}
}
}
return parent::_actionRender($context);
}
示例9: __getRelation
/**
* @param $column
* @return null
*/
private function __getRelation($type, $column)
{
$relations = $this->getRelations();
$taxonomies = json_decode($this->{$type});
$identifier = new KServiceIdentifier($relations->{$type}->{$column}->identifier);
if ($this->getRelations()->{$type}->{$column}->fallback == 1) {
$identity_column = KInflector::singularize($this->getIdentifier()->name) . '_id';
$id = $this->id;
} else {
$identity_column = 'id';
$id = $taxonomies->{$column};
}
if (KInflector::isSingular($column)) {
$result = $this->getService($identifier)->set($identity_column, $id)->getItem();
if (!$result->id) {
$result = null;
}
} else {
$model = $this->getService($identifier);
$state = $model->getState();
if (isset($relations->{$type}->{$column}->{$column}->state)) {
foreach ($relations->{$type}->{$column}->state as $key => $value) {
if ($filter = $state[$key]->filter) {
$state->remove($key)->insert($key, $filter, $value);
}
}
}
try {
$result = $model->{$identity_column}($id)->getList();
} catch (Exception $e) {
return $result = null;
}
if ($result->count() == 0) {
$result = null;
}
}
return $result;
}
示例10: _has
/**
* Add many-to-many or one-to-many or one-to-one relationship to a mapper. The cardinality
* of a relationship can be an integer or the string 'many'.
*
* @param KConfig $config Relationship options
*
* @return AnDomainRelationshipManytoone
*/
protected static function _has(KConfig $config)
{
//since the mixer is a singleton use the mixer object directly
$description = $config['description'];
//set the default cardinality
//If name singular 1 else many
$config->append(array('cardinality' => KInflector::isSingular($config['name']) ? 1 : 'many'));
$cardinality = (int) $config->cardinality;
$config->parent = $description->getEntityIdentifier();
//a one to one relationship
if (is_numeric($config->cardinality) && (int) $cardinality == 1) {
$relationship = AnDomainPropertyAbstract::getInstance('relationship.onetoone', $config);
//add the belnogs to relation to the child description
//if it doesn't exists. Since it's a one-to-one relatonship
//the parent entity uniquly identifies the child entity
$child_description = $relationship->getChildRepository()->getDescription();
$property = $child_description->getProperty($relationship->getChildKey());
if (!$property) {
$property = $child_description->setRelationship($relationship->getChildKey(), array('type' => 'belongs_to', 'parent' => $relationship->getParent()));
}
if ($relationship->isRequired()) {
$child_description->addIdentifyingProperty($property);
}
} elseif (!$config->through) {
$relationship = AnDomainPropertyAbstract::getInstance('relationship.onetomany', $config);
//the child repository must have a belongs to relationship
//if not then lets create one for it automatically
if (!$relationship->getChildProperty()) {
$child_key = $relationship->getChildKey();
$belongs_to_options = array('parent' => $description->getEntityIdentifier(), 'type' => 'belongs_to');
if ($config->child_column) {
$belongs_to_options['child_column'] = $config->child_column;
}
if ($config->parent_key) {
$belongs_to_options['parent_key'] = $config->parent_key;
}
$property = $relationship->getChildRepository()->getDescription()->setRelationship($child_key, $belongs_to_options);
}
} else {
$through_one_to_many = null;
//if subscription is through a one-to-many relationship
if (strpos($config->through, '.') === false && ($through_one_to_many = $description->getProperty($config->through))) {
unset($config->through);
$config->append(array('parent_delete' => $through_one_to_many->getDeleteRule(), 'as' => $through_one_to_many->getName(), 'through' => $through_one_to_many->getChild(), 'parent' => $through_one_to_many->getParent(), 'child_key' => $through_one_to_many->getChildKey(), 'parent_key' => $through_one_to_many->getParentKey()));
}
$relationship = AnDomainPropertyAbstract::getInstance('relationship.manytomany', $config);
//lets create a child relationship for the parent
//in the link entity if it doesn't exists
if (!$relationship->getChildProperty()) {
$child_key = $relationship->getChildKey();
$belongs_to_options = array('parent' => $description->getEntityIdentifier(), 'type' => 'belongs_to');
if ($config->child_column) {
$belongs_to_options['child_column'] = $config->child_column;
}
$property = $relationship->getChildRepository()->getDescription()->setRelationship($child_key, $belongs_to_options);
}
//lets create a child relationship for the target
//in the link entity if it doesn't exists
if (!$relationship->getTargetChildProperty()) {
$child_key = $relationship->getTargetChildKey();
$belongs_to_options = array('type' => 'belongs_to', 'parent' => $relationship->getTargetRepository()->getDescription()->getEntityIdentifier());
if ($config->target_child_column) {
$belongs_to_options['target_child_column'] = $config->child_column;
}
$property = $relationship->getChildRepository()->getDescription()->setRelationship($child_key, $belongs_to_options);
}
//create has_many relationship for both the parent and the target
//if there's no relationship set before
$parent = $relationship->getJunctionAlias();
$target = $parent;
if (empty($through_one_to_many)) {
$through_one_to_many = $description->setRelationship($target, array('type' => 'has', 'cardinality' => $config->cardinality, 'child_key' => $relationship->getChildKey(), 'parent_key' => $relationship->getParentKey(), 'child' => $relationship->getChild(), 'parent_delete' => $relationship->getDeleteRule()));
} elseif ($through_one_to_many->getName() != $target) {
$description->setAlias($through_one_to_many->getName(), $target);
}
$through_one_to_many_target = $relationship->getTargetRepository()->getDescription()->setRelationship($parent, array('cardinality' => $config->cardinality, 'type' => 'has', 'child_key' => $relationship->getTargetChildKey(), 'parent_key' => $relationship->getTargetParentKey(), 'child' => $relationship->getChild(), 'parent_delete' => $relationship->getDeleteRule()));
/*
* Duplicate Delete for two object that have has many to has many
* relationship with each other
*/
// print $through_one_to_many_target->getParentRepository()->getIdentifier()->name.' has many '.$through_one_to_many_target->getName().'<br/>'.
// $through_one_to_many->getParentRepository()->getIdentifier()->name.' has many '.$through_one_to_many->getName().'<br/><hr/>';
}
return $relationship;
}
示例11: _initialize
/**
* Initializes the configuration for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param array Configuration settings
*/
protected function _initialize(KConfig $config)
{
$path[] = dirname($this->getIdentifier()->filepath) . '/html';
$config->append(array('template_filters' => array('form', 'module'), 'media_url' => JURI::base() . '../media', 'layout' => KInflector::isSingular($this->getName()) ? 'form' : 'default', 'template_paths' => $path));
parent::_initialize($config);
}
示例12: _actionDisplay
/**
* Display action
*
* This function translates a GET request into a read or browse action. If the view name is
* singular a read action will be executed, if plural a browse action will be executed.
*
* This function will not render anything if the following conditions are met :
*
* - The result of the read or browse action is not a row or rowset object
* - The contex::status is 404 NOT FOUND and the view is not a HTML view
*
* @param KCommandContext A command context object
* @return string|false The rendered output of the view or FALSE if something went wrong
*/
protected function _actionDisplay(KCommandContext $context)
{
//Check if we are reading or browsing
$action = KInflector::isSingular($this->getView()->getName()) ? 'read' : 'browse';
//Execute the action
$result = $this->execute($action, $context);
//Only process the result if a valid row or rowset object has been returned
if ($result instanceof KDatabaseRowInterface || $result instanceof KDatabaseRowsetInterface) {
$view = $this->getView();
if ($context->status != KHttpResponse::NOT_FOUND || $view instanceof KViewHtml) {
if ($view instanceof KViewTemplate && isset($this->_request->layout)) {
$view->setLayout($this->_request->layout);
}
$result = $view->display();
} else {
$result = false;
}
}
return $result;
}
示例13: _actionRender
/**
* Set the mimetype of the document and hide the menu if required
*
* @return KDispatcherDefault
*/
protected function _actionRender(KCommandContext $context)
{
$view = $this->getController()->getView();
//Set the document mimetype
JFactory::getDocument()->setMimeEncoding($view->mimetype);
//Disabled the application menubar
if ($this->getController()->isEditable() && KInflector::isSingular($view->getName())) {
KRequest::set('get.hidemainmenu', 1);
}
return parent::_actionRender($context);
}
示例14: defined
<?php
/**
* @version $Id: inline.php 1042 2011-10-09 02:16:36Z johanjanssens $
* @category Nooku
* @package Nooku_Modules
* @subpackage Widget
* @copyright Copyright (C) 2011 - 2012 Timble CVBA and Contributors. (http://www.timble.net).
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.nooku.org
*/
defined('KOOWA') or die('Restricted access');
$parts = $url->getQuery(true);
$package = substr($parts['option'], 4);
$view = $parts['view'];
unset($parts['option']);
unset($parts['view']);
$action = KInflector::isSingular($view) ? 'read' : 'browse';
echo @service('admin::com.' . $package . '.controller.' . KInflector::singularize($view))->setRequest($parts)->{$action}();
示例15: getReadableName
/**
* Function for getting a plural and human readable version of a name
*
* @author Stian Didriksen <stian@ninjaforge.com>
* @param bool $pluralize Wether to pluralize or not
*/
public function getReadableName($pluralize = true)
{
$name = $this->getName();
if ($pluralize && KInflector::isSingular($name)) {
$name = KInflector::pluralize($name);
}
return KInflector::humanize($name);
}