Renamed engine type classes for PHP7 compatibility (fixes #204).

This commit is contained in:
alextselegidis 2016-10-10 17:46:29 +02:00
parent 9b5428a91d
commit 5229ed5767
32 changed files with 96 additions and 95 deletions

View file

@ -11,7 +11,7 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\String;
use \EA\Engine\Types\Alphanumeric;
use \EA\Engine\Types\Email;
use \EA\Engine\Types\Url;
@ -203,7 +203,7 @@ class Appointments extends CI_Controller {
if ($send_provider === TRUE) {
$email->sendDeleteAppointment($appointment, $provider,
$service, $customer, $company_settings, new Email($provider['email']),
new String($_POST['cancel_reason']));
new Alphanumeric($_POST['cancel_reason']));
}
$send_customer = filter_var($this->settings_model->get_setting('customer_notifications'),
@ -212,7 +212,7 @@ class Appointments extends CI_Controller {
if ($send_customer === TRUE) {
$email->sendDeleteAppointment($appointment, $provider,
$service, $customer, $company_settings, new Email($customer['email']),
new String($_POST['cancel_reason']));
new Alphanumeric($_POST['cancel_reason']));
}
} catch(Exception $exc) {
@ -431,16 +431,16 @@ class Appointments extends CI_Controller {
$email = new \EA\Engine\Notifications\Email($this, $this->config->config);
if ($post_data['manage_mode'] == FALSE) {
$customer_title = new String($this->lang->line('appointment_booked'));
$customer_message = new String($this->lang->line('thank_you_for_appointment'));
$provider_title = new String($this->lang->line('appointment_added_to_your_plan'));
$provider_message = new String($this->lang->line('appointment_link_description'));
$customer_title = new Alphanumeric($this->lang->line('appointment_booked'));
$customer_message = new Alphanumeric($this->lang->line('thank_you_for_appointment'));
$provider_title = new Alphanumeric($this->lang->line('appointment_added_to_your_plan'));
$provider_message = new Alphanumeric($this->lang->line('appointment_link_description'));
} else {
$customer_title = new String($this->lang->line('appointment_changes_saved'));
$customer_message = new String('');
$provider_title = new String($this->lang->line('appointment_details_changed'));
$provider_message = new String('');
$customer_title = new Alphanumeric($this->lang->line('appointment_changes_saved'));
$customer_message = new Alphanumeric('');
$provider_title = new Alphanumeric($this->lang->line('appointment_details_changed'));
$provider_message = new Alphanumeric('');
}
$customer_link = new Url(site_url('appointments/index/' . $appointment['hash']));

View file

@ -11,8 +11,9 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\String;
use \EA\Engine\Types\Email;
use \EA\Engine\Types\Decimal;
use \EA\Engine\Types\Alphanumeric;
use \EA\Engine\Types\Email;
use \EA\Engine\Types\Url;
/**
@ -295,15 +296,15 @@ class Backend_api extends CI_Controller {
->get_setting('notifications', $provider['id']);
if (!$manage_mode) {
$customer_title = new String($this->lang->line('appointment_booked'));
$customer_message = new String($this->lang->line('thank_you_for_appointment'));
$provider_title = new String($this->lang->line('appointment_added_to_your_plan'));
$provider_message = new String($this->lang->line('appointment_link_description'));
$customer_title = new Alphanumeric($this->lang->line('appointment_booked'));
$customer_message = new Alphanumeric($this->lang->line('thank_you_for_appointment'));
$provider_title = new Alphanumeric($this->lang->line('appointment_added_to_your_plan'));
$provider_message = new Alphanumeric($this->lang->line('appointment_link_description'));
} else {
$customer_title = new String($this->lang->line('appointment_changes_saved'));
$customer_message = new String('');
$provider_title = new String($this->lang->line('appointment_details_changed'));
$provider_message = new String('');
$customer_title = new Alphanumeric($this->lang->line('appointment_changes_saved'));
$customer_message = new Alphanumeric('');
$provider_title = new Alphanumeric($this->lang->line('appointment_details_changed'));
$provider_message = new Alphanumeric('');
}
$customer_link = new Url(site_url('appointments/index/' . $appointment['hash']));
@ -410,7 +411,7 @@ class Backend_api extends CI_Controller {
if ((bool)$send_provider === TRUE) {
$email->sendDeleteAppointment($appointment, $provider,
$service, $customer, $company_settings, new Email($provider['email']),
new String($_POST['delete_reason']));
new Alphanumeric($_POST['delete_reason']));
}
$send_customer = $this->settings_model->get_setting('customer_notifications');
@ -418,7 +419,7 @@ class Backend_api extends CI_Controller {
if ((bool)$send_customer === TRUE) {
$email->sendDeleteAppointment($appointment, $provider,
$service, $customer, $company_settings, new Email($customer['email']),
new String($_POST['delete_reason']));
new Alphanumeric($_POST['delete_reason']));
}
} catch(Exception $exc) {
$warnings[] = exceptionToJavaScript($exc);

View file

@ -11,7 +11,7 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
use \EA\Engine\Types\Email;
/**
@ -159,7 +159,7 @@ class User extends CI_Controller {
'company_email' => $this->settings_model->get_setting('company_email')
);
$email->sendPassword(new NonEmptyString($new_password), new Email($_POST['email']), $company_settings);
$email->sendPassword(new NonEmptyAlphanumeric($new_password), new Email($_POST['email']), $company_settings);
}
echo ($new_password != FALSE) ? json_encode(AJAX_SUCCESS) : json_encode(AJAX_FAILURE);

View file

@ -11,7 +11,7 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* API V1 Controller
@ -41,8 +41,8 @@ class API_V1_Controller extends CI_Controller {
parent::__construct();
try {
$username = new NonEmptyString($_SERVER['PHP_AUTH_USER']);
$password = new NonEmptyString($_SERVER['PHP_AUTH_PW']);
$username = new NonEmptyAlphanumeric($_SERVER['PHP_AUTH_USER']);
$password = new NonEmptyAlphanumeric($_SERVER['PHP_AUTH_PW']);
$authorization = new \EA\Engine\Api\V1\Authorization($this);
$authorization->basic($username, $password);
} catch(\Exception $exception) {

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Admins Controller
@ -88,7 +88,7 @@ class Admins extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->admins_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Appointments Controller
@ -88,7 +88,7 @@ class Appointments extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->appointments_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch(\Exception $exception) {
exit($this->_handleException($exception));

View file

@ -16,7 +16,7 @@ require_once __DIR__ . '/../../Appointments.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\UnsignedInt;
use \EA\Engine\Types\UnsignedInteger;
/**
* Availabilities Controller
@ -44,8 +44,8 @@ class Availabilities extends API_V1_Controller {
*/
public function get() {
try {
$providerId = new UnsignedInt($this->input->get('providerId'));
$serviceId = new UnsignedInt($this->input->get('serviceId'));
$providerId = new UnsignedInteger($this->input->get('providerId'));
$serviceId = new UnsignedInteger($this->input->get('serviceId'));
if ($this->input->get('date')) {
$date = new DateTime($this->input->get('date'));

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Categories Controller
@ -88,7 +88,7 @@ class Categories extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->services_model->get_all_categories('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Customers Controller
@ -88,7 +88,7 @@ class Customers extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->customers_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Providers Controller
@ -88,7 +88,7 @@ class Providers extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->providers_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Secretaries Controller
@ -88,7 +88,7 @@ class Secretaries extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->secretaries_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Services Controller
@ -88,7 +88,7 @@ class Services extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->services_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch (\Exception $exception) {
$this->_handleException($exception);

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Settings Controller

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* Unavailabilities Controller
@ -88,7 +88,7 @@ class Unavailabilities extends API_V1_Controller {
// Fetch the new object from the database and return it to the client.
$batch = $this->appointments_model->get_batch('id = ' . $id);
$response = new Response($batch);
$status = new NonEmptyString('201 Created');
$status = new NonEmptyAlphanumeric('201 Created');
$response->encode($this->parser)->singleEntry(true)->output($status);
} catch(\Exception $exception) {
exit($this->_handleException($exception));

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Api\V1;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
/**
* API v1 Authorization Class
@ -40,12 +40,12 @@ class Authorization {
/**
* Perform Basic Authentication
*
* @param NonEmptyString $username Admin Username
* @param NonEmptyString $password Admin Password
* @param NonEmptyAlphanumeric $username Admin Username
* @param NonEmptyAlphanumeric $password Admin Password
*
* @throws \EA\Engine\Api\V1\Exception Throws 401-Unauthorized exception if the authentication fails.
*/
public function basic(NonEmptyString $username, NonEmptyString $password) {
public function basic(NonEmptyAlphanumeric $username, NonEmptyAlphanumeric $password) {
$this->framework->load->model('user_model');
if (!$this->framework->user_model->check_login($username->get(), $password->get())) {

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Api\V1;
use EA\Engine\Types\NonEmptyString;
use EA\Engine\Types\NonEmptyAlphanumeric;
/**
* API v1 Response
@ -124,12 +124,12 @@ class Response {
/**
* Output the response as a JSON with the provided status header.
*
* @param \EA\Engine\Types\NonEmptyString $status Optional (null), if provided it must contain the status
* @param \EA\Engine\Types\NonEmptyAlphanumeric $status Optional (null), if provided it must contain the status
* header value. Default string: '200 OK'.
*
* @return \EA\Engine\Api\V1\Response
*/
public function output(NonEmptyString $status = null) {
public function output(NonEmptyAlphanumeric $status = null) {
$header = $status ? $status->get() : '200 OK';
header('HTTP/1.0 ' . $header);

View file

@ -13,8 +13,8 @@
namespace EA\Engine\Notifications;
use \EA\Engine\Types\String;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\Alphanumeric;
use \EA\Engine\Types\NonEmptyAlphanumeric;
use \EA\Engine\Types\Url;
use \EA\Engine\Types\Email as EmailAddress;
@ -98,15 +98,15 @@ class Email {
* @param array $customer Contains the customer data.
* @param array $company Contains settings of the company. By the time the
* "company_name", "company_link" and "company_email" values are required in the array.
* @param \EA\Engine\Types\String $title The email title may vary depending the receiver.
* @param \EA\Engine\Types\String $message The email message may vary depending the receiver.
* @param \EA\Engine\Types\Alphanumeric $title The email title may vary depending the receiver.
* @param \EA\Engine\Types\Alphanumeric $message The email message may vary depending the receiver.
* @param \EA\Engine\Types\Url $appointmentLink This link is going to enable the receiver to make changes
* to the appointment record.
* @param \EA\Engine\Types\Email $recipientEmail The recipient email address.
*/
public function sendAppointmentDetails(array $appointment, array $provider, array $service,
array $customer, array $company, String $title, String $message, Url $appointmentLink,
EmailAddress $recipientEmail) {
array $customer, array $company, Alphanumeric $title, Alphanumeric $message, Url $appointmentLink,
EmailAddress $recipientEmail) {
// Prepare template replace array.
$replaceArray = array(
@ -172,8 +172,8 @@ class Email {
* @param \EA\Engine\Tyeps\String $reason The reason why the appointment is deleted.
*/
public function sendDeleteAppointment(array $appointment, array $provider,
array $service, array $customer, array $company, EmailAddress $recipientEmail,
String $reason) {
array $service, array $customer, array $company, EmailAddress $recipientEmail,
Alphanumeric $reason) {
// Prepare email template data.
$replaceArray = array(
'$email_title' => $this->framework->lang->line('appointment_cancelled_title'),
@ -223,11 +223,11 @@ class Email {
/**
* This method sends an email with the new password of a user.
*
* @param \EA\Engine\Types\NonEmptyString $password Contains the new password.
* @param \EA\Engine\Types\NonEmptyAlphanumeric $password Contains the new password.
* @param \EA\Engine\Types\Email $email The receiver's email address.
* @param array $company The company settings to be included in the email.
*/
public function sendPassword(NonEmptyString $password, EmailAddress $recipientEmail, array $company) {
public function sendPassword(NonEmptyAlphanumeric $password, EmailAddress $recipientEmail, array $company) {
$replaceArray = array(
'$email_title' => $this->framework->lang->line('new_account_password'),
'$email_message' => $this->framework->lang->line('new_password_is'),

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class String extends Type {
class Alphanumeric extends Type {
protected function _validate($value) {
return is_string($value);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class Bool extends Type {
class Boolean extends Type {
protected function _validate($value) {
return is_bool($value);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class Float extends Type {
class Decimal extends Type {
protected function _validate($value) {
return is_float($value);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class Email extends NonEmptyString {
class Email extends NonEmptyAlphanumeric {
protected function _validate($value) {
return parent::_validate($value) && filter_var($value, FILTER_VALIDATE_EMAIL);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class Int extends Type {
class Integer extends Type {
protected function _validate($value) {
return is_numeric($value) && !is_float($value);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class NonEmptyString extends String {
class NonEmptyAlphanumeric extends Alphanumeric {
protected function _validate($value) {
return parent::_validate($value) && $value !== '';
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class UnsignedInt extends Int {
class UnsignedInteger extends Integer {
protected function _validate($value) {
return parent::_validate($value) && $value > -1;
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Types;
class Url extends NonEmptyString {
class Url extends NonEmptyAlphanumeric {
protected function _validate($value) {
return parent::_validate($value) && filter_var($value, FILTER_VALIDATE_URL);
}

View file

@ -13,7 +13,7 @@
namespace EA\Engine\Api\V1;
use \EA\Engine\Types\NonEmptyString;
use \EA\Engine\Types\NonEmptyAlphanumeric;
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
public function testBasicMethodPerformsBasicAuthentication() {

View file

@ -13,14 +13,14 @@
namespace EA\Engine\Types;
class StringTest extends \PHPUnit_Framework_TestCase {
class AlphanumericTest extends \PHPUnit_Framework_TestCase {
public function testStringType() {
$type = new String('Hello!');
$type = new Alphanumeric('Hello!');
$this->assertEquals('Hello!', $type->get());
}
public function testStringTypeThrowsExceptionWithInvalidValue() {
$this->setExpectedException('\InvalidArgumentException');
new String(null);
new Alphanumeric(null);
}
}

View file

@ -13,14 +13,14 @@
namespace EA\Engine\Types;
class BoolTest extends \PHPUnit_Framework_TestCase {
class BooleanTest extends \PHPUnit_Framework_TestCase {
public function testBoolType() {
$type = new Bool(true);
$type = new Boolean(true);
$this->assertEquals(true, $type->get());
}
public function testBoolTypeThrowsExceptionWithInvalidValue() {
$this->setExpectedException('\InvalidArgumentException');
new Bool(null);
new Boolean(null);
}
}

View file

@ -13,14 +13,14 @@
namespace EA\Engine\Types;
class FloatTest extends \PHPUnit_Framework_TestCase {
class DecimalTest extends \PHPUnit_Framework_TestCase {
public function testFloatType() {
$type = new Float(100.00);
$type = new Decimal(100.00);
$this->assertEquals(100.00, $type->get());
}
public function testFloatTypeThrowsExceptionWithInvalidValue() {
$this->setExpectedException('\InvalidArgumentException');
new Float(null);
new Decimal(null);
}
}

View file

@ -13,19 +13,19 @@
namespace EA\Engine\Types;
class IntTest extends \PHPUnit_Framework_TestCase {
class IntegerTest extends \PHPUnit_Framework_TestCase {
public function testIntType() {
$type = new Int(1);
$type = new Integer(1);
$this->assertEquals(1, $type->get());
}
public function testIntTypeThrowsExceptionWithFloat() {
$this->setExpectedException('\InvalidArgumentException');
new Int(100.00);
new Integer(100.00);
}
public function testIntTypeThrowsExceptionWithWithString() {
$this->setExpectedException('\InvalidArgumentException');
new Int('invalid');
new Integer('invalid');
}
}

View file

@ -13,19 +13,19 @@
namespace EA\Engine\Types;
class NonEmptyStringTest extends \PHPUnit_Framework_TestCase {
class NonEmptyAlphanumericTest extends \PHPUnit_Framework_TestCase {
public function testNonEmptyStringType() {
$type = new NonEmptyString('Hello!');
$type = new NonEmptyAlphanumeric('Hello!');
$this->assertEquals('Hello!', $type->get());
}
public function testNonEmptyStringTypeThrowsExceptionWithEmptyString() {
$this->setExpectedException('\InvalidArgumentException');
new NonEmptyString('');
new NonEmptyAlphanumeric('');
}
public function testNonEmptyStringTypeThrowsExceptionWithInvalidValue() {
$this->setExpectedException('\InvalidArgumentException');
new NonEmptyString(null);
new NonEmptyAlphanumeric(null);
}
}

View file

@ -13,19 +13,19 @@
namespace EA\Engine\Types;
class UnsignedIntTest extends \PHPUnit_Framework_TestCase {
class UnsignedIntegerTest extends \PHPUnit_Framework_TestCase {
public function testUnsignedIntType() {
$type = new UnsignedInt(1);
$type = new UnsignedInteger(1);
$this->assertEquals(1, $type->get());
}
public function testUnsignedIntTypeThrowsExceptionWithNegative() {
$this->setExpectedException('\InvalidArgumentException');
new UnsignedInt(-1);
new UnsignedInteger(-1);
}
public function testUnsignedIntTypeThrowsExceptionWithWithString() {
$this->setExpectedException('\InvalidArgumentException');
new UnsignedInt('invalid');
new UnsignedInteger('invalid');
}
}