Skip to content

Commit

Permalink
Add new messages
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Apr 19, 2018
1 parent 841707c commit f661a73
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 16 deletions.
79 changes: 79 additions & 0 deletions src/Validation/AlertMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Odan\Validation;

/**
* StatusMessage.
*
* Represents a alert status (success, danger, warning, info) and a status message.
*/
class AlertMessage
{
/**
* @var string
*/
protected $status;

/**
* @var string
*/
protected $message;

/**
* Constructor.
*
* @param string $status Alert status
* @param string $message The message
*/
public function __construct(string $status, string $message)
{
$this->status = $status;
$this->message = $message;
}

/**
* Clone object.
*
* @param string $status Status code
* @param string $message The message
*
* @return self
*/
public function with(string $status, string $message): self
{
return new self($status, $message);
}

/**
* Returns the message.
*
* @return string The message
*/
public function message(): string
{
return $this->message;
}

/**
* Returns the status code.
*
* @return string The status
*/
public function status(): string
{
return $this->status;
}

/**
* Convert to array.
*
* @return array Data
*/
public function toArray(): array
{
return [
'status' => $this->status(),
'message' => $this->message(),
];
}
}
52 changes: 52 additions & 0 deletions src/Validation/AlertMessageStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Odan\Validation;

/**
* AlertStatus.
*
* Can be used in combination with AlertMessage.
*/
class AlertMessageStatus
{
// Bootstrap
const PRIMARY = 'primary';

// Bootstrap
const SECONDARY = 'secondary';

// Bootstrap
const SUCCESS = 'success';

// Bootstrap
const DANGER = 'danger';

// Bootstrap
const LIGHT = 'light';

// Bootstrap
const DARK = 'dark';

// RFC 5424
const DEBUG = 'debug';

// RFC 5424 and Bootstrap
const INFO = 'info';

const NOTICE = 'notice';

// RFC 5424 and Bootstrap
const WARNING = 'warning';

// RFC 5424
const ERROR = 'error';

// RFC 5424
const CRITICAL = 'critical';

// RFC 5424
const ALERT = 'alert';

// RFC 5424
const EMERGENCY = 'emergency';
}
79 changes: 79 additions & 0 deletions src/Validation/StatusMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Odan\Validation;

/**
* StatusMessage.
*
* Represents a numeric status code and a status message.
*/
class StatusMessage
{
/**
* @var int
*/
protected $status = 0;

/**
* @var string
*/
protected $message;

/**
* Constructor.
*
* @param int $status Status code
* @param string $message The message
*/
public function __construct(int $status, string $message)
{
$this->status = $status;
$this->message = $message;
}

/**
* Clone object.
*
* @param int $status Status code
* @param string $message The message
*
* @return self
*/
public function with(int $status, string $message): self
{
return new self($status, $message);
}

/**
* Returns the message.
*
* @return string The message
*/
public function message(): string
{
return $this->message;
}

/**
* Returns the status code.
*
* @return int The status code
*/
public function status(): int
{
return $this->status;
}

/**
* Convert to array.
*
* @return array Data
*/
public function toArray(): array
{
return [
'status' => $this->status(),
'message' => $this->message(),
];
}
}
89 changes: 89 additions & 0 deletions src/Validation/SuccessMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Odan\Validation;

/**
* SuccessMessage.
*
* Represents a boolean success status and a success message.
*/
class SuccessMessage
{
/**
* @var bool
*/
protected $success = false;

/**
* @var string
*/
protected $message = null;

/**
* Constructor.
*
* @param bool $success Success
* @param string $message Message
*/
public function __construct(bool $success, string $message)
{
$this->success = $success;
$this->message = $message;
}

/**
* Get message.
*
* @param bool $success
* @param string $message
*
* @return self
*/
public function with(bool $success, string $message): self
{
return new self($success, $message);
}

/**
* Returns the message.
*
* @return string
*/
public function message(): string
{
return $this->message;
}

/**
* Returns the success status.
*
* @return bool The success status
*/
public function success(): bool
{
return $this->success;
}

/**
* Returns the failed status.
*
* @return bool The failed status
*/
public function failed(): bool
{
return !$this->success;
}

/**
* Convert to array.
*
* @return array Data
*/
public function toArray(): array
{
return [
'success' => $this->success(),
'message' => $this->message(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Odan\Validation;

/**
* ValidationResult.
* ValidationMessage.
*
* Represents a container for the results of a validation request.
*/
class ValidationResult
class ValidationMessage
{
/**
* @var array
Expand Down
Loading

0 comments on commit f661a73

Please sign in to comment.