本文整理汇总了PHP中StringUtils::smartSplit方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::smartSplit方法的具体用法?PHP StringUtils::smartSplit怎么用?PHP StringUtils::smartSplit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtils
的用法示例。
在下文中一共展示了StringUtils::smartSplit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getNodeRefs
protected function _getNodeRefs()
{
$noderefs = $this->Request->getParameter('NodeRefs');
if (!empty($noderefs) && strlen($noderefs) > 0) {
$noderefs = StringUtils::smartSplit($noderefs, ',');
$noderefObjs = array();
foreach ($noderefs as $noderef) {
$nr = $this->NodeRefService->parseFromString($noderef);
if ($nr != null) {
$noderefObjs[] = $nr;
}
}
return $noderefObjs;
} else {
return array();
}
}
示例2: execute
public function execute()
{
$this->_beginBulkaction();
$noderefs = $this->_getNodeRefs();
$tags = $this->Request->getParameter('Tags');
$tagStrings = array();
if (!empty($tags)) {
$tagStrings = StringUtils::smartSplit($tags);
}
foreach ($noderefs as $noderef) {
try {
foreach ($tagStrings as $tagString) {
$this->RegulatedNodeService->addOutTag($noderef, new Tag($tagString));
}
$this->_updateBulkaction($noderef->getElement()->Slug, $noderef->Slug);
} catch (Exception $e) {
$this->_failureBulkaction($e->getMessage(), $noderef->getElement()->Slug, $noderef->Slug);
}
}
return $this->_endBulkaction();
}
示例3: __construct
public function __construct($tagOrElement, $slug = '', $role = '', $value = '')
{
if ($tagOrElement instanceof TagPartial || $tagOrElement instanceof Tag) {
$this->fields = $tagOrElement->toArray();
return;
}
$this->fields = array_merge($this->fields, array('TagElement' => '', 'TagAspect' => '', 'TagSlug' => '', 'TagRole' => '', 'TagValue' => ''));
if (is_array($tagOrElement)) {
$this->fields = array_merge($this->fields, $tagOrElement);
} else {
if (is_string($tagOrElement)) {
// assume first param is element
if (!empty($slug) || !empty($role) || !empty($value)) {
if (substr($tagOrElement, 0, 1) == '@') {
$this->fields['TagAspect'] = substr($tagOrElement, 1);
} else {
$this->fields['TagElement'] = $tagOrElement;
}
$this->fields['TagSlug'] = $slug;
$this->fields['TagRole'] = $role;
$this->fields['TagValue'] = $value;
// assume first param is tag string
} else {
$expressions = StringUtils::smartSplit($tagOrElement, ".", '"', '\\"', 2);
if (preg_match("/^(((?P<ai>@)?(?P<el>[a-z0-9-]+))?(:(?P<s>[a-z0-9\\/\\-]+)?)?)?(#(?P<r>[a-z0-9-]+)?)?(=(?P<v>.+?))?\$/", array_shift($expressions), $m)) {
if (!empty($m['ai'])) {
$this->fields['TagAspect'] = !empty($m['el']) ? $m['el'] : '';
} else {
$this->fields['TagElement'] = !empty($m['el']) ? $m['el'] : '';
}
$this->fields['TagSlug'] = !empty($m['s']) ? $m['s'] : '';
$this->fields['TagRole'] = !empty($m['r']) ? $m['r'] : '';
$this->fields['TagValue'] = !empty($m['v']) ? $m['v'] : '';
if (!empty($expressions)) {
// if(count($expressions) > 1)
$this->fields['ChildPartials'] = current($expressions);
// else
// $this->fields['ChildPartial'] = $expressions[0];
}
}
}
} else {
throw new Exception('Invalid parameter to TagPartial: ' . ClassUtils::getQualifiedType($tagOrElement));
}
}
if (empty($this->fields['TagElement']) && empty($this->fields['TagAspect']) && empty($this->fields['TagRole'])) {
throw new TagException('Invalid partial: No element, aspect, or role was specified [' . print_r($tagOrElement, true) . ']');
}
if (!empty($this->fields['TagAspect'])) {
// $this->fields['TagAspect'] = strtolower($this->fields['TagAspect']);
if (!preg_match("/[a-z0-9-]+/", $this->fields['TagAspect'])) {
throw new TagException('Invalid partial: Aspect "' . $this->fields['TagAspect'] . '" must contain only characters or dash');
}
}
if (!empty($this->fields['TagSlug'])) {
$this->fields['TagSlug'] = strtolower($this->fields['TagSlug']);
if (!SlugUtils::isSlug($this->fields['TagSlug'], true)) {
throw new TagException('Invalid tag: "' . $this->fields['TagSlug'] . '" must be valid slug');
}
}
if (!empty($this->fields['TagRole']) && !SlugUtils::isSlug($this->fields['TagRole'])) {
$this->fields['TagRole'] = SlugUtils::createSlug($this->fields['TagRole']);
}
if (!empty($this->fields['TagValue']) && !SlugUtils::isSlug($this->fields['TagValue'])) {
$this->fields['TagValue'] = SlugUtils::createSlug($this->fields['TagValue']);
}
// lowercase all parts
foreach (array('TagElement', 'TagAspect', 'TagSlug', 'TagRole', 'TagValue') as $name) {
$this->fields[$name] = strtolower($this->fields[$name]);
}
}
示例4: findTags
//.........这里部分代码省略.........
$tag->Deleted = true;
} else {
// We're deleting a tag that was already added to the results array. Therefore just keep track of
// it so that we can remove it from the results array later.
if ($fixedId) {
$deletedTags[$fixedId][] = $tagIDToDelete;
} else {
$deletedTags[$row['ID']][] = $tagIDToDelete;
}
}
// read repair
$this->Logger->debug("Delete {$tag->getTagDirection()} tag: {$tag->toString()}");
$affectedRows = $this->getConnectionForWrite($originNodeRef)->write("DELETE FROM {$db->quoteIdentifier($table)} WHERE TagID = {$db->quote($tagIDToDelete)}");
if ($affectedRows > 0) {
$this->NodeEvents->fireTagEvents($direction . 'tags', 'remove', $originNodeRef, $nodeRef, $tag);
}
// If the current tag is the one that got deleted, we're done processing this tag and can move to
// the next. This tag will not get added to the results.
if ($tag->Deleted) {
continue;
}
}
}
$existingTagsPerNode[$row['ID']][$tag->toString()] = $tag->TagID;
if ($resolveLinkedRecords) {
$tagNodeRefs[] = $nodeRef;
// $strTagNodeRefs[$k] = (string)$nodeRef;
// if need to merge more tags in
if (array_key_exists($row['TagRole'], $childexprPartials)) {
// TODO: check partial matches
$rowRefKey = $rowElement->getSlug();
$outPartials = $childexprPartials[$row['TagRole']];
foreach ($outPartials as $outPartial) {
$expressions = StringUtils::smartSplit($outPartial->getChildPartials(), ".", '"', '\\"', 2);
$firstExpression = array_shift($expressions);
if (strtolower($firstExpression) == 'meta') {
$addlParams[$rowRefKey]['Meta.select'][] = 'all';
} elseif (strtolower($firstExpression) == 'fields') {
$addlParams[$rowRefKey]['Meta.select'][] = 'all';
$addlParams[$rowRefKey]['OutTags.select'][] = 'fields';
$addlParams[$rowRefKey]['InTags.select'][] = 'fields';
} else {
unset($schemaDef);
$isTag = true;
try {
$jPartial = new TagPartial($firstExpression);
$role = $jPartial->getTagRole();
if ($nodeRef->getElement()->getSchema()->hasTagDef($role)) {
$schemaDef = $nodeRef->getElement()->getSchema()->getTagDef($role);
} else {
if ($nodeRef->getElement()->getSchema()->hasMetaDef($role)) {
$jPartial = new MetaPartial($firstExpression);
$schemaDef = $nodeRef->getElement()->getSchema()->getMetaDef($role);
$isTag = false;
}
}
} catch (Exception $e) {
$jPartial = new MetaPartial($firstExpression);
$role = $jPartial->getMetaName();
if ($nodeRef->getElement()->getSchema()->hasMetaDef($role)) {
$schemaDef = $nodeRef->getElement()->getSchema()->getMetaDef($role);
}
$isTag = false;
}
if (empty($schemaDef)) {
continue;
示例5: getUniqueThumbnailSizes
/**
* @param null $elementSlug
* @return array
* @throws Exception
*/
public function getUniqueThumbnailSizes($elementSlug = null)
{
$sizes = $this->thumbnailCmsSize;
if (is_string($this->thumbnailSizes)) {
$sizes .= ',' . $this->thumbnailSizes;
} else {
if (is_array($this->thumbnailSizes)) {
if (array_key_exists($elementSlug, $this->thumbnailSizes)) {
$sizes .= ',' . $this->thumbnailSizes[$elementSlug];
}
} else {
throw new Exception("Invalid thumbnail sizes [{$elementSlug}]");
}
}
return array_unique(StringUtils::smartSplit($sizes, ','));
}
示例6: decreasePartials
public static function decreasePartials($partials, $decrease)
{
if (empty($partials)) {
return $partials;
}
if (($k = array_search($decrease, $explodedPartials = StringUtils::smartSplit($partials, ',', '"', '\\"'))) !== FALSE) {
unset($explodedPartials[$k]);
return implode(',', $explodedPartials);
}
return $partials;
}
示例7: fireBindEvents
protected function fireBindEvents($action, Node &$node, Errors &$errors, array $fields, array $rawFields)
{
if (isset($fields['OutTags_partials'])) {
foreach (StringUtils::smartSplit($fields['OutTags_partials'], ',', '"', '\\"') as $partial) {
$node->getNodePartials()->increaseOutPartials($partial);
}
}
if (isset($fields['InTags_partials'])) {
foreach (StringUtils::smartSplit($fields['InTags_partials'], ',', '"', '\\"') as $partial) {
$node->getNodePartials()->increaseInPartials($partial);
}
}
foreach ((array) $node->getNodeRef()->getElement()->getAspects() as $aspect) {
$this->Events->trigger('Node.@' . $aspect->Slug . '.bind', $action, $node, $errors, $fields, $rawFields);
$schema = $aspect->getSchema();
foreach ($schema->getMetaDefs() as $metaDef) {
$bound = $this->Events->trigger('Node.@' . $aspect->Slug . '.meta.#' . $metaDef->Id . '.bind', $action, $node, $errors, $fields, $rawFields);
if (!$bound) {
$this->bindMeta($node, $errors, $fields, $rawFields, $metaDef->Id);
}
}
foreach ($schema->getTagDefs() as $tagDef) {
if ($tagDef->Direction == 'in') {
$bound = $this->Events->trigger('Node.@' . $aspect->Slug . '.intags.#' . $tagDef->Id . '.bind', $action, $node, $errors, $fields, $rawFields);
if (!$bound && $tagDef->isFieldlike()) {
$this->bindInTags($node, $errors, $fields, $rawFields, $tagDef->Id);
}
} else {
$bound = $this->Events->trigger('Node.@' . $aspect->Slug . '.outtags.#' . $tagDef->Id . '.bind', $action, $node, $errors, $fields, $rawFields);
if (!$bound && $tagDef->isFieldlike()) {
$this->bindOutTags($node, $errors, $fields, $rawFields, $tagDef->Id);
}
}
}
}
$errors->throwOnError();
}
示例8: import
/**
* Imports and runs sql contained in the specified file.
* The file must contain only valid sql.
*
* @param string $filename The filename to load
*
* @return void
*/
public function import($filename)
{
// TODO: Wrap this in a transaction!
if (!file_exists($filename)) {
throw new Exception("File not found: {$filename}");
}
$sql_queries = file_get_contents($filename);
$sql_queries = $this->_removeRemarks($sql_queries);
$sql_queries = StringUtils::smartSplit($sql_queries, ";", "'", "\\'");
foreach ($sql_queries as $sql) {
$sql = trim($sql);
// Trim newlines so we don't have blank queries
if (empty($sql)) {
continue;
}
$this->write($sql);
}
}
示例9: flattenObjectsUsingKeys
public static function flattenObjectsUsingKeys($obj, array $keys)
{
$array = self::flattenObjects($obj);
$newArray = array();
foreach ($keys as $key) {
if (array_key_exists($key, $array)) {
$newArray[$key] = $array[$key];
} else {
if (strpos($key, '.') !== FALSE) {
$parts = StringUtils::smartSplit($key, '.', '"', '\\');
if (!empty($parts)) {
$newArray = array_merge_recursive($newArray, self::breakDownArray($array, $parts));
}
}
}
}
return $newArray;
}
示例10: _getPendingThumbnails
protected function _getPendingThumbnails($elementSlug, $thumbnails)
{
$sizes = $this->imagesThumbnailCmsSize;
if (is_string($this->thumbnailSizes)) {
$sizes .= ',' . $this->thumbnailSizes;
} else {
if (is_array($this->thumbnailSizes)) {
if (array_key_exists($elementSlug, $this->thumbnailSizes)) {
$sizes .= ',' . $this->thumbnailSizes[$elementSlug];
}
} else {
throw new Exception("Invalid thumbnail sizes [{$elementSlug}]");
}
}
$sizes = array_unique(StringUtils::smartSplit($sizes, ','));
$have = array();
foreach ($thumbnails as $thumb) {
$have[] = $thumb->value;
}
return array_values(array_diff($sizes, $have));
}
示例11: _storeTemporary
/**
* Store the temporary-zipped-media nodes as proper media nodes.
*
* @throws MediaServiceException
* @param $params
* @return
*/
protected function _storeTemporary($params)
{
if (empty($params['NodeRef'])) {
throw new MediaServiceException('NodeRef must be specified');
}
list($element, $slug) = explode(':', $params['NodeRef']);
$tmpParams = array('ElementSlug' => $element, 'NodeSlug' => $slug);
// get node with all tags
$node = $this->getNode($tmpParams, 'all');
// will spit error if not found
$nodeTitle = $node->Title;
$nodeSlug = $node->Slug;
// if a custom title is specified, override existing title & slug
if (!empty($params['Title']) && $params['Title'] !== $node->Title) {
$nodeTitle = $params['Title'];
$nodeSlug = SlugUtils::createSlug($nodeTitle);
}
$nodeRef = new NodeRef($this->ElementService->getBySlug($params['ElementSlug']), $nodeSlug);
$nodeRef = $this->NodeService->generateUniqueNodeRef($nodeRef, $nodeTitle);
$params['Slug'] = $nodeRef->getSlug();
$rawParams = $this->Request->getRawParameters();
// Clean the param keys removing uid
foreach ($params as $key => $value) {
if (preg_match('/^#/', $key)) {
$nkey = preg_replace('/-uid\\d+$/', '', $key);
if (strcmp($nkey, $key) == 0) {
continue;
}
$params[$nkey] = $params[$key];
$rawParams[$nkey] = $rawParams[$key];
unset($params[$key]);
unset($rawParams[$key]);
}
}
foreach (array('In', 'Out') as $dir) {
// Clean the _partials
if (!empty($params[$dir . 'Tags_partials'])) {
$newPartials = array();
$partials = StringUtils::smartSplit($params[$dir . 'Tags_partials'], ',', '"', '\\"');
foreach ($partials as $p) {
$newPartials[] = preg_replace('/-uid\\d+$/', '', $p);
}
$params[$dir . 'Tags_partials'] = implode(',', $newPartials);
$rawParams[$dir . 'Tags_partials'] = implode(',', $newPartials);
}
// Clean the tags
if (isset($params[$dir . 'Tags']) && is_array($params[$dir . 'Tags'])) {
foreach ($params[$dir . 'Tags'] as $key => $value) {
$nkey = preg_replace('/-uid\\d+$/', '', $key);
if (strcmp($nkey, $key) == 0) {
continue;
}
$params[$dir . 'Tags'][$nkey] = $params[$dir . 'Tags'][$key];
$rawParams[$dir . 'Tags'][$nkey] = $rawParams[$dir . 'Tags'][$key];
unset($params[$dir . 'Tags'][$key]);
unset($rawParams[$dir . 'Tags'][$key]);
}
}
}
// create node
$newNode = $nodeRef->generateNode();
$this->NodeMapper->defaultsOnNode($newNode);
//bind posted params to form backing object
$this->NodeBinder->bindPersistentFields($newNode, $this->getErrors(), $params, $rawParams);
$this->NodeBinder->fireAddBindEvents($newNode, $this->getErrors(), $params, $rawParams);
$this->getErrors()->throwOnError();
$newNode->Title = $nodeTitle;
// copy other permanent fields
$newNode->ActiveDate = $node->ActiveDate;
$newNode->Status = $node->Status;
// clone all the file out tags
$outTags = $node->getOutTags();
$newOutTags = array();
foreach ($outTags as $tag) {
if ($tag->getTagElement() == 'file') {
$tnode = $this->RegulatedNodeService->getByNodeRef($tag->getTagLinkNode()->getNodeRef(), new NodePartials('#parent-element'));
$fileNode = $this->cloneFileNode($tnode, $newNode->getElement());
$newTag = new Tag($fileNode->getNodeRef(), '', $tag->getTagRole(), $tag->getTagValue(), $tag->getTagValueDisplay());
$newOutTags[] = $newTag;
} else {
$newOutTags[] = $tag;
}
}
$newNode->addOutTags($newOutTags);
// copy all in tags
$newNode->addInTags($node->getInTags());
// and add the new node
$newNode = $this->RegulatedNodeService->add($newNode);
// then remove the temporary node
$this->RegulatedNodeService->delete($node->getNodeRef());
// commit so the node is ready for the worker
$this->TransactionManager->commit()->begin();
//-----------
//.........这里部分代码省略.........