本文整理汇总了PHP中Server::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::find方法的具体用法?PHP Server::find怎么用?PHP Server::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server::find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find_one
public static function find_one($parameters = array())
{
$results = Server::find($parameters, 1);
if (!sizeof($results)) {
return;
}
return $results[0];
}
示例2: get_delete
public function get_delete($id = NULL)
{
$server = Server::find($id);
if (is_null($server)) {
return View::make('msg.error')->with('error', 'Server doesn\'t exist.');
}
$server->delete();
return Redirect::to('/admin/server/overview');
}
示例3: pingServer
public function pingServer()
{
$id = intval(Input::get('id'));
$server = Server::find($id);
if ($id && $server && Auth::user()->pj_is_mine($server->project_id)) {
return Response::json(Task::pingRsyncServer($server->ip));
}
return Response::json(false);
}
示例4: getServer
public function getServer($id)
{
$players_array = [];
$mods_array = [];
$server = Server::find($id);
if (!$server) {
return Response::json(['error' => 'No mod with that ID found.']);
}
$server_status = ServerStatus::where('server_id', $id)->first();
if (!$server->player_list_hide) {
$raw_players = json_decode($server_status->players);
if ($raw_players) {
foreach ($raw_players as $player) {
$players_array[] = ['name' => preg_replace('/\\x{00A7}.{1}/u', '', $player->name)];
}
}
}
if ($server_status->mods) {
$raw_mods = json_decode($server_status->mods);
foreach ($raw_mods->modList as $mod) {
$mods_array[] = ['name' => htmlspecialchars($mod->modid), 'version' => $mod->version];
}
}
if ($server->server_address_hide) {
$server_address = 'Hidden';
} else {
$server_address = $server->ip_host . ':' . $server->port;
}
$result = ['id' => $server->id, 'modpack_id' => $server->modpack_id, 'name' => $server->name, 'short_description' => $server->deck, 'server_address' => $server_address, 'country' => $server->country, 'permissions' => $server->permissions, 'website' => $server->wiki_link, 'application_url' => $server->description, 'description' => $server->slug, 'players' => $players_array, 'mods' => $mods_array, 'server_address_hide' => $server->server_address_hide, 'player_list_hide' => $server->player_list_hide, 'slug' => $server->slug, 'last_world_reset' => $server->last_world_reset, 'next_world_reset' => $server->next_world_reset, 'created_at' => $server->created_at, 'updated_at' => $server->updated_at];
return Response::json($result);
}
示例5: _runRsync
/**
*
* 针对一个服务器,调用Rsync将项目发布到线上,然后回写Server的版本和更新结果
* @link http://www.cnblogs.com/mchina/p/2829944.html Rsync的配置
*/
private function _runRsync($task)
{
$current_dir = getcwd();
$server = \Server::find($task->server_id);
$pj_dir = \Project::getTempDir($server->project_id);
chdir($pj_dir);
$excludes = '';
$exclude_files = explode("\n", $server->project->ignore_files);
foreach ($exclude_files as $_file) {
$_file = trim($_file);
if ($_file) {
$excludes .= ' --exclude ' . escapeshellarg($_file);
}
}
$rsync_cmd = sprintf("rsync -azc --delete %s . %s::%s", $excludes, $server->ip, $server->rsync_name);
file_put_contents(app_path() . "/storage/rsync.log", $rsync_cmd . "\n", FILE_APPEND);
exec($rsync_cmd, $output, $return_var);
if ($return_var == 0) {
$server->current_version = $this->get_dir_version('.');
$server->save();
}
chdir($current_dir);
return array('result' => true, 'output' => implode("\n", $output) . " code {$return_var}");
}
示例6: index
<?php
if (!TUTORIAL_ENABLED) {
Server::find()->serveNotFound();
exit;
}
/**
* THis is the basic tutorial module.
* @author carl
* @package nth-example
*/
class Tutorial extends Templator
{
public static $route_okay = array('index');
public function index()
{
return $this->display($this->getTpl('main', array('main' => $this->getTpl('intro_main'), 'menu' => $this->getTpl('intro_menu'))));
}
}
示例7: server
/**
* Gets a single server
* If $id is empty, create a repository that we can use to save a new server
*
* @param integer $id optional
* @param array $scopes optional
*
* @return Server
*/
public function server($id = null, $scopes = [])
{
$server = new Server($this);
if (is_null($id)) {
return $server;
}
return $server->find($id, $scopes);
}
示例8: getServerPlayers
public function getServerPlayers($id)
{
$players_array = [];
$server = Server::find($id);
if (!$server->player_list_hide) {
$server_status = ServerStatus::select('id', 'server_id', 'players')->where('server_id', $id)->first();
$raw_players = json_decode($server_status->players);
if ($raw_players) {
foreach ($raw_players as $player) {
$players_array[] = ['name' => preg_replace('/\\x{00A7}.{1}/u', '', $player->name)];
}
}
}
return $this->buildDTServerPlayerOutput($players_array);
}
示例9: getConfirm
public function getConfirm($id, $password)
{
$error = 'Unable to activate server!';
$server = Server::find($id);
if (!$server) {
App::abort(404);
}
$server_user = $server->serverUser;
if (Hash::check($password, $server_user->edit_password)) {
if ($server_user->is_confirmed) {
$error = 'Server is already confirmed!';
} else {
$server_user->is_confirmed = 1;
$server->active = 1;
$server->save();
$server_user->save();
$error = false;
}
}
$title = 'Server Confirmation - ' . $this->site_name;
return View::make('servers.confirmed', ['server' => $server, 'error' => $error, 'title' => $title]);
}
示例10: getCss
/**
* Retrieves the contents of a relative module css file
* @param string $css_file
* @return string The contents of the local css file
*/
public function getCss($css_file)
{
$file = $this->locateInclude('/css/' . $css_file);
Server::find()->setCacheMtime(filemtime($file));
return $this->getInclude($file);
}
示例11: fire
public function fire($job, $data)
{
Config::set('services.mandrill.secret', 'J3gPgh8LNHx4Paw-a7j26g');
//since we are outside of nginx, no env variables
$cache_key = 'server-update-version-cache';
if (Cache::has($cache_key)) {
$versions = Cache::get($cache_key);
} else {
$versions = [];
$raw_versions = MinecraftVersion::select('id', 'name')->get();
foreach ($raw_versions as $v) {
$key = $v->id;
$versions[$key] = $v->name;
}
Cache::put($cache_key, $versions, 60);
}
$server = Server::find($data['server_id']);
$server_status = ServerStatus::where('server_id', $server->id)->first();
$server_version_id = $server->minecraft_version_id;
$version = $versions[$server_version_id];
$server_query = Server::check($server->ip_host, $server->port, $version);
$current_timestamp = Carbon\Carbon::now()->toDateTimeString();
if ($server_query) {
if (isset($server_query['players']['online'])) {
$server_status->current_players = $server_query['players']['online'];
} elseif (isset($server_query['Players'])) {
$server_status->current_players = $server_query['Players'];
}
if (isset($server_query['players']['max'])) {
$server_status->max_players = $server_query['players']['max'];
} elseif (isset($server_query['MaxPlayers'])) {
$server_status->max_players = $server_query['MaxPlayers'];
}
if (isset($server_query['modinfo'])) {
$server_status->mods = json_encode($server_query['modinfo']);
}
if (isset($server_query['players']['sample'])) {
$server_status->players = json_encode($server_query['players']['sample']);
}
$server_status->failed_attempts = 0;
$server_status->failed_checks = 0;
$server_status->last_success = $current_timestamp;
} else {
$server_status->failed_attempts = $server_status->failed_attempts + 1;
$server_status->last_failure = $current_timestamp;
if ($server_status->failed_attempts >= Config::get('app.server_failed_attempts')) {
$server_status->failed_checks = $server_status->failed_checks + 1;
$server_status->total_failed_checks = $server_status->total_failed_checks + 1;
$server_status->failed_attempts = 0;
}
if ($server_status->failed_checks >= Config::get('app.server_failed_disable')) {
$server->active = 0;
$server_status->current_players = 0;
$server_status->max_players = 0;
if ($server->email_alerts) {
$message_array = ['server_name' => $server->name, 'user' => $server->user];
Mail::send('emails.disabled_server', array('server' => $server, 'site_url' => Config::get('app.url')), function ($message) use($message_array) {
$message->from('noreply@modpackindex.com', 'Modpack Index');
$message->to($message_array['user']->email, $message_array['user']->username)->subject('Server Deactivated: ' . $message_array['server_name']);
});
}
}
}
$server_status->total_checks = $server_status->total_checks + 1;
$server_status->last_check = $current_timestamp;
$server_status->save();
$server->queued = 0;
$server->last_check = $current_timestamp;
$server->save();
$job->delete();
}
示例12: deleteServerSubmit
public function deleteServerSubmit()
{
//Find sid by decrypting the post data
$sid = str_replace(Core::getSalt(), '', Crypt::decrypt(Input::get('delete')));
//Decrypt the server
//Find server to delete
$server = Server::find($sid);
if ($server != '') {
//If the server exists
if ($server->user_id == Auth::user()->id) {
//Check oif the user owns the server
$sname = $server->name;
$server->delete();
//Delete server
return Redirect::route('dashboard')->with('message', 'Server ' . e($sname) . ' Deleted Successfully!');
} else {
return Redirect::route('dashboard')->with('message', 'Sorry, You Are Not Authorized To Delete This Server!');
}
} else {
return Redirect::route('dashboard')->with('message', 'Sorry, The Server Does Not Exist!');
}
}