Skip to content

Commit

Permalink
add: Global functions to 'NelsonMartell' namespace.
Browse files Browse the repository at this point in the history
- Deprecated global functions for next release.
- Update Copyright date in related files.

ref. #17
  • Loading branch information
nelson6e65 committed Mar 16, 2016
1 parent 1f4780a commit bc71dea
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
5 changes: 3 additions & 2 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
* - File to perform manual autoload. For non composer instalation, must be
* required at app initialization.
*
* Copyright © 2015 Nelson Martell (http://nelson6e65.github.io)
* Copyright © 2015-2016 Nelson Martell (http://nelson6e65.github.io)
*
* Licensed under The MIT License (MIT)
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright 2015 Nelson Martell
* @copyright 2015-2016 Nelson Martell
* @link http://nelson6e65.github.io/php_nml/
* @since v0.3.0
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
* */

require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'constants.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'deprecated_functions.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'functions.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'bootstrap.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'autoloader.php';

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"files": [
"src/constants.php",
"src/deprecated_functions.php",
"src/functions.php",
"config/bootstrap.php"
]
},
Expand Down
14 changes: 10 additions & 4 deletions src/deprecated_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* Content:
* - Global functions definition for NML.
*
* Copyright © 2015 Nelson Martell (http://nelson6e65.github.io)
* Copyright © 2015-2016 Nelson Martell (http://nelson6e65.github.io)
*
* Licensed under The MIT License (MIT)
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright 2015 Nelson Martell
* @copyright 2015-2016 Nelson Martell
* @link http://nelson6e65.github.io/php_nml/
* @since v0.4.5
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
Expand All @@ -29,7 +29,9 @@
* argumentos que se van a incluir en las cadenas de formato del mensaje.
*
* @return string
* @see dgettext
* @deprecated since v0.6.0, will be removed in v0.7.0. Use `\NelsonMartell\msg()` instead.
* @see dgettext()
* @see \NelsonMartell\msg()
* */
function nml_msg($message, $args = null)
{
Expand All @@ -56,7 +58,9 @@ function nml_msg($message, $args = null)
* argumentos que se van a incluir en las cadenas de formato del mensaje.
*
* @return string
* @see dngettext
* @deprecated since v0.6.0, will be removed in v0.7.0. Use `\NelsonMartell\nmsg()` instead.
* @see dngettext()
* @see \NelsonMartell\nmsg()
* */
function nml_nmsg($singular, $plural, $n, $args = null)
{
Expand All @@ -77,6 +81,8 @@ function nml_nmsg($singular, $plural, $n, $args = null)
* @param mixed $obj Objeto al cual se le extraerá su tipo.
*
* @return Type
* @deprecated since v0.6.0, will be removed in v0.7.0. Use `\NelsonMartell\typeof()` instead.
* @see \NelsonMartell\typeof()
* */
function typeof($obj)
{
Expand Down
88 changes: 88 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* PHP: Nelson Martell Library file
*
* Content:
* - Global functions definition for NML.
*
* Copyright © 2016 Nelson Martell (http://nelson6e65.github.io)
*
* Licensed under The MIT License (MIT)
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*
* @copyright 2016 Nelson Martell
* @link http://nelson6e65.github.io/php_nml/
* @since v0.6.0
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
* */

namespace NelsonMartell;

use NelsonMartell\Extensions\String;

/**
* Busca un mensaje único traducido en el dominio 'nml'.
* El mensaje puede contener cadenas de formato.
*
* @param string $message Mensaje con formato que se va a buscar.
* @param array|mixed $args Un objeto, una lista de objetos o múltiples
* argumentos que se van a incluir en las cadenas de formato del mensaje.
*
* @return string
* @since v0.6.0
* @see \dgettext()
* */
function msg($message, $args = null)
{
$translated = \dgettext(NML_GETTEXT_DOMAIN, $message);

if (\func_num_args() > 2) {
$args = \array_slice(func_get_args(), 1);
}

return String::format($translated, $args);
}


/**
* Busca un mensaje único, en singular y plural, traducido en el dominio 'nml'.
* El mensaje puede contener cadenas de formato.
*
* @param string $singular Mensaje con formato que se va a buscar cuando $n
* es uno (1).
* @param string $plural Mensaje con formato que se va a buscar cuando $n
* es distinto a (1).
* @param integer $n Cantidad
* @param array|mixed $args Un objeto, una lista de objetos o múltiples
* argumentos que se van a incluir en las cadenas de formato del mensaje.
*
* @return string
* @since v0.6.0
* @see \dngettext()
* */
function nmsg($singular, $plural, $n, $args = null)
{
$translated = \dngettext(NML_GETTEXT_DOMAIN, $singular, $plural, $n);

if (\func_num_args() > 4) {
$args = \array_slice(func_get_args(), 3);
}

return String::format($translated, $args);
}


/**
* Obtiene el tipo del objeto especificado.
* Es un alias para el constructor de la clase Type.
*
* @param mixed $obj Objeto al cual se le extraerá su tipo.
*
* @return Type
* @since v0.6.0
* */
function typeof($obj)
{
return new Type($obj);
}

0 comments on commit bc71dea

Please sign in to comment.