Skip to content

Commit

Permalink
Merge branch '3.1' into email-viewbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Aug 18, 2015
2 parents e0579da + d195734 commit b71dd88
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 91 deletions.
19 changes: 14 additions & 5 deletions src/Mailer/Mailer.php
Expand Up @@ -73,7 +73,7 @@
* if ($entity->isNew()) {
* $this->send('welcome', [$entity]);
* }
* }
* }
* ```
*
* The onRegistration method converts the application event into a mailer method.
Expand All @@ -82,6 +82,7 @@
*/
abstract class Mailer implements ArrayAccess, EventListenerInterface
{

use ModelAwareTrait;

/**
Expand All @@ -98,6 +99,14 @@ abstract class Mailer implements ArrayAccess, EventListenerInterface
*/
public $layout;

/**
* Email view template to render, defaults to the triggered mailer
* action's name.
*
* @var string
*/
public $template;

/**
* Email instance.
*
Expand All @@ -116,10 +125,6 @@ public function __construct(Email $email = null)
$email = new Email();
}

if ($this->layout === null) {
$this->layout = Inflector::underscore($this->getName());
}

$this->_email = $email;
}

Expand Down Expand Up @@ -226,6 +231,10 @@ public function send($action, $args = [], $headers = [])

call_user_func_array([$this, $action], $args);

if ($this->template === null) {
$this->template = $action;
}

$result = $this->_email
->profile((array)$this)
->send();
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Query.php
Expand Up @@ -720,7 +720,7 @@ public function count()
}

$count = ['count' => $query->func()->count('*')];
$complex = count($query->clause('group')) || $query->clause('distinct');
$complex = count($query->clause('group')) || $query->clause('distinct') || $query->clause('having');
$complex = $complex || count($query->clause('union'));

if (!$complex) {
Expand Down
73 changes: 72 additions & 1 deletion src/Validation/Validation.php
Expand Up @@ -34,7 +34,9 @@ class Validation
* @var array
*/
protected static $_pattern = [
'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})'
'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})',
'latitude' => '[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)',
'longitude' => '[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)',
];

/**
Expand Down Expand Up @@ -1026,6 +1028,75 @@ public static function uploadedFile($file, array $options = [])
return true;
}

/**
* Validates a geographic coordinate.
*
* Supported formats:
*
* - `<latitude>, <longitude>` Example: `-25.274398, 133.775136`
*
* ### Options
*
* - `type` - A string of the coordinate format, right now only `latLong`.
* - `format` - By default `both`, can be `long` and `lat` as well to validate
* only a part of the coordinate.
*
* @param string $value Geographic location as string
* @param array $options Options for the validation logic.
* @return bool
*/
public static function geoCoordinate($value, array $options = [])
{
$options += [
'format' => 'both',
'type' => 'latLong'
];
if ($options['type'] !== 'latLong') {
throw new \RuntimeException(sprintf(
'Unsupported coordinate type "%s". Use "latLong" instead.',
$options['type']
));
}
$pattern = '/^' . self::$_pattern['latitude'] . ',\s*' . self::$_pattern['longitude'] . '$/';
if ($options['format'] === 'long') {
$pattern = '/^' . self::$_pattern['longitude'] . '$/';
}
if ($options['format'] === 'lat') {
$pattern = '/^' . self::$_pattern['latitude'] . '$/';
}
return (bool)preg_match($pattern, $value);
}

/**
* Convenience method for latitude validation.
*
* @param string $value Latitude as string
* @param array $options Options for the validation logic.
* @return bool
* @link https://en.wikipedia.org/wiki/Latitude
* @see Validation::geoCoordinate()
*/
public static function latitude($value, array $options = [])
{
$options['format'] = 'lat';
return self::geoCoordinate($value, $options);
}

/**
* Convenience method for longitude validation.
*
* @param string $value Latitude as string
* @param array $options Options for the validation logic.
* @return bool
* @link https://en.wikipedia.org/wiki/Longitude
* @see Validation::geoCoordinate()
*/
public static function longitude($value, array $options = [])
{
$options['format'] = 'long';
return self::geoCoordinate($value, $options);
}

/**
* Converts an array representing a date or datetime into a ISO string.
* The arrays are typically sent for validation from a form generated by
Expand Down
2 changes: 1 addition & 1 deletion src/View/Cell.php
Expand Up @@ -173,7 +173,7 @@ public function render($template = null)
$render = function () use ($template) {
$className = substr(strrchr(get_class($this), "\\"), 1);
$name = substr($className, 0, -4);
$this->View->viewPath('Cell' . DS . $name);
$this->View->templatePath('Cell' . DS . $name);

try {
return $this->View->render($template);
Expand Down

0 comments on commit b71dd88

Please sign in to comment.