本文整理汇总了PHP中arrayValue函数的典型用法代码示例。如果您正苦于以下问题:PHP arrayValue函数的具体用法?PHP arrayValue怎么用?PHP arrayValue使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了arrayValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: firstThrown_returnFiveDices
/**
* @test
*/
public function firstThrown_returnFiveDices()
{
$player = new Player();
$result = $player->throwDices();
assertThat($result, arrayValue());
assertThat(count($result), is(equalTo(5)));
}
示例2: isRemovable
/**
* Is the application/plugin/theme removable?
*
* @param string $Type self::TYPE_APPLICATION or self::TYPE_PLUGIN or self::TYPE_THEME
* @param string $Name
* @return boolean
*/
public static function isRemovable($Type, $Name)
{
switch ($Type) {
case self::TYPE_APPLICATION:
$ApplicationManager = Gdn::Factory('ApplicationManager');
if ($IsRemovable = !array_key_exists($Name, $ApplicationManager->EnabledApplications())) {
$ApplicationInfo = arrayValue($Name, $ApplicationManager->AvailableApplications(), array());
$ApplicationFolder = arrayValue('Folder', $ApplicationInfo, '');
$IsRemovable = IsWritable(PATH_APPLICATIONS . DS . $ApplicationFolder);
}
break;
case self::TYPE_PLUGIN:
if ($IsRemovable = !array_key_exists($Name, Gdn::pluginManager()->EnabledPlugins())) {
$PluginInfo = arrayValue($Name, Gdn::pluginManager()->AvailablePlugins(), false);
$PluginFolder = arrayValue('Folder', $PluginInfo, false);
$IsRemovable = IsWritable(PATH_PLUGINS . DS . $PluginFolder);
}
break;
case self::TYPE_THEME:
// TODO
$IsRemovable = false;
break;
}
return $IsRemovable;
}
示例3: testAccessorForCredentialsConvertsStringIntoArray
public function testAccessorForCredentialsConvertsStringIntoArray()
{
$user = Factory::create('User', ['id' => 1]);
$credentialsNotAccessed = $user->getAttributes()['credentials'];
$credentialsAccessed = $user->credentials;
assertThat($credentialsNotAccessed, is(stringValue()));
assertThat($credentialsAccessed, is(arrayValue()));
}
示例4: config
/**
* Update the configuration.
*
* @return void
*/
protected function config()
{
saveToConfig('Garden.Cookie.Salt', RandomString(10));
$ApplicationInfo = [];
include CombinePaths([PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'about.php']);
// Detect Internet connection for CDNs
$Disconnected = !(bool) @fsockopen('ajax.googleapis.com', 80);
saveToConfig(['Garden.Version' => arrayValue('Version', val('Dashboard', $ApplicationInfo, []), 'Undefined'), 'Garden.Cdns.Disable' => $Disconnected, 'Garden.CanProcessImages' => function_exists('gd_info'), 'EnabledPlugins.HtmLawed' => 'HtmLawed']);
}
示例5: getVisitIp
function getVisitIp()
{
$matchIp = '/^([0-9]{1,3}\\.){3}[0-9]{1,3}$/';
$ipKeys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_CF_CONNECTING_IP');
foreach ($ipKeys as $ipKey) {
if (isset($_SERVER[$ipKey]) && preg_match($matchIp, $_SERVER[$ipKey])) {
return $_SERVER[$ipKey];
}
}
return arrayValue($_SERVER, 'REMOTE_ADDR');
}
示例6: __construct
/**
* Constructor
*
* @param array $connectionData Connection Data parsed by parse_url()
* @return self
*/
public function __construct(array $connectionData)
{
if (!class_exists("Memcache", false)) {
error("Memcache Extension not installed - Update your PHP configuration");
}
$this->memcache = new Memcache();
$host = $connectionData["host"];
$port = arrayValue($connectionData, "port");
$port = $port ? $port : 11211;
$connectState = $this->memcache->connect($host, $port);
if (!$connectState) {
error("Could not connect to Memcache Server at " . $host . ":" . $port);
}
}
示例7: getRoute
/**
* Get an route that exactly matches a string.
* @param string|int $Route The route to search for.
* @param int $Indexed If the route is a number then it will be looked up as an index.
*
* @return array|bool A route or false if there is no matching route.
*/
public function getRoute($Route, $Indexed = true)
{
if ($Indexed && is_numeric($Route) && $Route !== false) {
$Keys = array_keys($this->Routes);
$Route = arrayValue($Route, $Keys);
}
$Decoded = $this->_decodeRouteKey($Route);
if ($Decoded !== false && array_key_exists($Decoded, $this->Routes)) {
$Route = $Decoded;
}
if ($Route === false || !array_key_exists($Route, $this->Routes)) {
return false;
}
//return $this->Routes[$Route];
return array_merge($this->Routes[$Route], array('TypeLocale' => T($this->RouteTypes[$this->Routes[$Route]['Type']]), 'FinalDestination' => $this->Routes[$Route]['Destination']));
}
示例8: edit
/**
* Edit a route.
*
* @since 2.0.0
* @access public
* @param string $RouteIndex Name of route.
*/
public function edit($RouteIndex = false)
{
$this->permission('Garden.Settings.Manage');
$this->addSideMenu('dashboard/routes');
$this->Route = Gdn::router()->GetRoute($RouteIndex);
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->setField(array('Route', 'Target', 'Type'));
// Set the model on the form.
$this->Form->setModel($ConfigurationModel);
// If seeing the form for the first time...
if (!$this->Form->authenticatedPostBack()) {
// Apply the route info to the form.
if ($this->Route !== false) {
$this->Form->setData(array('Route' => $this->Route['Route'], 'Target' => $this->Route['Destination'], 'Type' => $this->Route['Type']));
}
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->applyRule('Route', 'Required');
$ConfigurationModel->Validation->applyRule('Target', 'Required');
$ConfigurationModel->Validation->applyRule('Type', 'Required');
// Validate & Save
$FormPostValues = $this->Form->formValues();
// Dunno.
if ($this->Route['Reserved']) {
$FormPostValues['Route'] = $this->Route['Route'];
}
if ($ConfigurationModel->validate($FormPostValues)) {
$NewRouteName = arrayValue('Route', $FormPostValues);
if ($this->Route !== false && $NewRouteName != $this->Route['Route']) {
Gdn::router()->DeleteRoute($this->Route['Route']);
}
Gdn::router()->SetRoute($NewRouteName, arrayValue('Target', $FormPostValues), arrayValue('Type', $FormPostValues));
$this->informMessage(t("The route was saved successfully."));
$this->RedirectUrl = url('dashboard/routes');
} else {
$this->Form->setValidationResults($ConfigurationModel->validationResults());
}
}
$this->render();
}
示例9: comment
//.........这里部分代码省略.........
$this->EventArguments['Comment'] = $Comment;
$this->fireEvent('AfterCommentSave');
} elseif ($CommentID === SPAM || $CommentID === UNAPPROVED) {
$this->StatusMessage = t('CommentRequiresApprovalStatus', 'Your comment will appear after it is approved.');
}
$this->Form->setValidationResults($this->CommentModel->validationResults());
if ($CommentID > 0 && $DraftID > 0) {
$this->DraftModel->delete($DraftID);
}
}
// Handle non-ajax requests first:
if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
if ($this->Form->errorCount() == 0) {
// Make sure that this form knows what comment we are editing.
if ($CommentID > 0) {
$this->Form->addHidden('CommentID', $CommentID);
}
// If the comment was not a draft
if (!$Draft) {
// Redirect to the new comment.
if ($CommentID > 0) {
redirect("discussion/comment/{$CommentID}/#Comment_{$CommentID}");
} elseif ($CommentID == SPAM) {
$this->setData('DiscussionUrl', DiscussionUrl($Discussion));
$this->View = 'Spam';
}
} elseif ($Preview) {
// If this was a preview click, create a comment shell with the values for this comment
$this->Comment = new stdClass();
$this->Comment->InsertUserID = $Session->User->UserID;
$this->Comment->InsertName = $Session->User->Name;
$this->Comment->InsertPhoto = $Session->User->Photo;
$this->Comment->DateInserted = Gdn_Format::date();
$this->Comment->Body = arrayValue('Body', $FormValues, '');
$this->Comment->Format = val('Format', $FormValues, c('Garden.InputFormatter'));
$this->AddAsset('Content', $this->fetchView('preview'));
} else {
// If this was a draft save, notify the user about the save
$this->informMessage(sprintf(t('Draft saved at %s'), Gdn_Format::date()));
}
}
} else {
// Handle ajax-based requests
if ($this->Form->errorCount() > 0) {
// Return the form errors
$this->ErrorMessage($this->Form->errors());
} else {
// Make sure that the ajax request form knows about the newly created comment or draft id
$this->setJson('CommentID', $CommentID);
$this->setJson('DraftID', $DraftID);
if ($Preview) {
// If this was a preview click, create a comment shell with the values for this comment
$this->Comment = new stdClass();
$this->Comment->InsertUserID = $Session->User->UserID;
$this->Comment->InsertName = $Session->User->Name;
$this->Comment->InsertPhoto = $Session->User->Photo;
$this->Comment->DateInserted = Gdn_Format::date();
$this->Comment->Body = arrayValue('Body', $FormValues, '');
$this->View = 'preview';
} elseif (!$Draft) {
// If the comment was not a draft
// If Editing a comment
if ($Editing) {
// Just reload the comment in question
$this->Offset = 1;
$Comments = $this->CommentModel->GetIDData($CommentID, array('Slave' => false));
示例10: getValue
/**
* Gets the value associated with $FieldName.
*
* If the form has been posted back, it will retrieve the value from the form.
* If it hasn't been posted back, it gets the value from $this->_DataArray.
* Failing either of those, it returns $Default.
*
* @param string $FieldName
* @param mixed $Default
* @return mixed
*
* @todo check returned value type
*/
public function getValue($FieldName, $Default = false)
{
$Return = '';
// Only retrieve values from the form collection if this is a postback.
if ($this->isMyPostBack()) {
$Return = $this->getFormValue($FieldName, $Default);
} else {
$Return = arrayValue($FieldName, $this->_DataArray, $Default);
}
return $Return;
}
示例11: toTimestamp
/**
* Convert a datetime to a timestamp
*
* @param string $DateTime The Mysql-formatted datetime to convert to a timestamp. Should be in one
* of the following formats: YYYY-MM-DD or YYYY-MM-DD HH:MM:SS. Returns
* FALSE upon failure.
* @return unknown
*/
public static function toTimestamp($DateTime = '')
{
if ($DateTime === '0000-00-00 00:00:00') {
return false;
} elseif (($TestTime = strtotime($DateTime)) !== false) {
return $TestTime;
} elseif (preg_match('/^(\\d{4})-(\\d{1,2})-(\\d{1,2})(?:\\s{1}(\\d{1,2}):(\\d{1,2})(?::(\\d{1,2}))?)?$/', $DateTime, $Matches)) {
$Year = $Matches[1];
$Month = $Matches[2];
$Day = $Matches[3];
$Hour = arrayValue(4, $Matches, 0);
$Minute = arrayValue(5, $Matches, 0);
$Second = arrayValue(6, $Matches, 0);
return mktime($Hour, $Minute, $Second, $Month, $Day, $Year);
} elseif (preg_match('/^(\\d{4})-(\\d{1,2})-(\\d{1,2})$/', $DateTime, $Matches)) {
$Year = $Matches[1];
$Month = $Matches[2];
$Day = $Matches[3];
return mktime(0, 0, 0, $Month, $Day, $Year);
// } elseif ($DateTime == '') {
// return time();
} else {
return false;
}
}
示例12: get
/**
* Get attribute value
*
* @param mixed $key
* @return string
*/
public function get($key)
{
return arrayValue($this->arr, $key, "");
}
示例13: json
/**
* If JSON is going to be sent to the client, this method allows you to add
* extra values to the JSON array.
*
* @param string $Key The name of the array key to add.
* @param mixed $Value The value to be added. If null, then it won't be set.
* @return mixed The value at the key.
*/
public function json($Key, $Value = null)
{
if (!is_null($Value)) {
$this->_Json[$Key] = $Value;
}
return arrayValue($Key, $this->_Json, null);
}
示例14: getId
/**
* Get the database id
* 0 if not stored in database
*
* @return int
*/
public function getId()
{
return (int) arrayValue($this->_dbValues, "id");
}
示例15: save
/**
* Save a message.
*
* @param array $FormPostValues Message data.
* @param bool $Settings
* @return int The MessageID.
*/
public function save($FormPostValues, $Settings = false)
{
// The "location" is packed into a single input with a / delimiter. Need to explode it into three different fields for saving
$Location = arrayValue('Location', $FormPostValues, '');
if ($Location != '') {
$Location = explode('/', $Location);
$Application = val(0, $Location, '');
if (in_array($Application, $this->_SpecialLocations)) {
$FormPostValues['Application'] = null;
$FormPostValues['Controller'] = $Application;
$FormPostValues['Method'] = null;
} else {
$FormPostValues['Application'] = $Application;
$FormPostValues['Controller'] = val(1, $Location, '');
$FormPostValues['Method'] = val(2, $Location, '');
}
}
Gdn::cache()->remove('Messages');
return parent::save($FormPostValues, $Settings);
}