Skip to content

Commit 929c913

Browse files
committed
Stato for php 5.2 : unit test result : Tests: 284, Assertions: 498, Failures: 1, Skipped: 9.
1 parent 9d3dd78 commit 929c913

File tree

131 files changed

+9727
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+9727
-0
lines changed

MIT-LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2005-2009 Rapha�l Rougeron
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docs/fr/faq.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
====== FAQ ======
2+
3+
===== Pourquoi n'y a t-il pas telle ou telle fonctionnalité dans Stato ? =====
4+
Stato se veut être un framework léger et n'offrant que le strict nécessaire : à mes yeux, les fonctionnalités indispensables pour le développement d'une application web sont le support de l'architecture MVC, une bonne couche ORM, des fonctionnalités d'i18n et d'envoi de mails. Ces fonctionnalités couvrent en règle générale 80% des besoins des développeurs, et je préfère passer mon temps à améliorer du code utilisé dans tous les projets qu'à essayer de couvrir une partie des 20% restants, d'autant plus que répondre à certains de ces besoins spécifiques serait extrêmement consommateur de temps, et qu'il existe déjà des librairies pour répondre à ces besoins. Prenons par exemple l'export PDF : écrire une librairie de génération de PDF me demanderait énormément de temps (sans compter le temps nécessaire pour en assurer le support), et cette librairie ne serait que très peu utilisée par rapport au reste. Le jeu n'en vaut donc pas la chandelle, et je vous recommande donc si vous devez générer des PDFs d'utiliser Zend_Pdf. Un autre exemple : les fonctionnalités d'i18n de Stato ne couvrent que la traduction, et ce pour une raison simple, c'est qu'il existe aujourd'hui une excellente extension PECL nommée intl pour gérer tout le reste. Etant une extension codée en C, ses performances sont de plus bien supérieures à un équivalent PHP.
5+
6+
===== Mon hébergement ne me permet pas d'utiliser telle ou telle extension PHP recommandée | Mon serveur est encore en PHP 5.1.x... =====
7+
PHP évolue, et de nouvelles fonctionnalités sont sans cesse ajoutées pour répondre aux besoins des développeurs. Pour ne citer que 2 exemples, l'ajout des nouvelles classes DateTime et DateTimeZone, ou encore l'extension intl sont de réelles avancées de PHP, et méritent à elles seules la mise à jour de PHP. Je comprends bien évidemmment que tout le monde ne puisse pas être maître de la mise à jour de son serveur, mais je souhaite que Stato et les développeurs l'utilisant continuent à exploiter les nouveautés de PHP, spécialement quand ces nouveautés offrent de meilleures performances qu'une solution codée en PHP.

docs/fr/i18n/index.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
====== L'API d'internationalisation (i18n) de Stato ======
2+
3+
===== Configurer votre application =====
4+
5+
==== Définir la locale ====
6+
Afin d'offrir un contenu localisé aux utilisateurs de votre application, vous devez préciser à Stato la locale à utiliser pour la requête en cours, et pour cela, détecter la locale souhaitée par l'utilisateur. Le moyen le plus simple et le plus RESTful est de faire en sorte que la locale fasse partie de l'URL. Vous pouvez par exemple définir une route par défaut de ce type :
7+
<code php>
8+
$set->addRoute(':locale/:controller/:action/:id', array('locale' => 'fr', 'controller' => 'home'));
9+
</code>
10+
Vous pouvez ainsi récupérer dans vos contrôleurs la locale souhaitée dans ''$this->params['locale']''. Il vous suffit alors de créer un filtre dans votre ''ApplicationController'' :
11+
<code php>
12+
class ApplicationController extends Stato_Controller
13+
{
14+
protected function initialize()
15+
{
16+
$this->beforeFilters->append('setLocale');
17+
}
18+
19+
protected function setLocale()
20+
{
21+
Stato_I18n::setLocale($this->params['locale']);
22+
}
23+
}
24+
</code>
25+
26+
=== Définir la locale en fonction des informations fournies par le client ===
27+
Une des sources d'information possibles est l'entête ''Accept-Language'' qui est fournie notamment par les navigateurs. Une implémentation possible serait donc :
28+
<code php>
29+
protected function setLocale()
30+
{
31+
Stato_I18n::setLocale(Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']));
32+
}
33+
</code>

docs/fr/index.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
====== Manuel du développeur ======
2+
**Ce manuel concerne la version 2.0 en cours de développement.**
3+
4+
* [[FAQ]]
5+
* [[install|Installation et création d'un nouveau projet]]
6+
7+
[[.i18n:index|API d'internationalisation]]
8+
9+

library/Stato/Cli/Command.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
4+
5+
abstract class Stato_Cli_Command
6+
{
7+
protected $shortDesc;
8+
9+
protected $longDesc;
10+
11+
protected $options;
12+
13+
abstract public function run($options = array(), $args = array());
14+
15+
public function __construct()
16+
{
17+
$this->options = array();
18+
}
19+
20+
public function getOptions()
21+
{
22+
return $this->options;
23+
}
24+
25+
public function getHelp()
26+
{
27+
$help = "{$this->shortDesc}\n\n{$this->longDesc}\n\noptions:\n";
28+
foreach ($this->options as $o) $help.= $o->getHelp();
29+
return $help;
30+
}
31+
32+
protected function addOption($short, $long, $type = Stato_Cli_Option::BOOLEAN, $dest = null, $help = null, $metavar = null)
33+
{
34+
$this->options[] = new Stato_Cli_Option($short, $long, $type, $dest, $help, $metavar);
35+
}
36+
37+
protected function announce($message)
38+
{
39+
echo " $message\n";
40+
}
41+
42+
protected function ask($message)
43+
{
44+
// @codeCoverageIgnoreStart
45+
echo " $message (y/n) ";
46+
$answer = trim(fgets(STDIN, 1024));
47+
return $answer == 'y';
48+
// @codeCoverageIgnoreStop
49+
}
50+
51+
protected function mkdir($dirname, $path)
52+
{
53+
$dirpath = "$path/$dirname";
54+
if (file_exists($dirpath))
55+
$this->announce("exists $dirpath");
56+
else {
57+
$this->announce("create $dirpath");
58+
mkdir($dirpath);
59+
}
60+
}
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
4+
5+
6+
7+
8+
class Stato_Cli_Command_Createapp extends Stato_Cli_Command
9+
{
10+
public function __construct()
11+
{
12+
parent::__construct();
13+
$this->shortDesc = 'stato createapp - Create a skeleton application';
14+
$this->longDesc = 'Create a skeleton application.';
15+
16+
$this->addOption('-p', '--path', Stato_Cli_Option::STRING);
17+
}
18+
19+
public function run($options = array(), $args = array())
20+
{
21+
if (empty($args)) {
22+
echo "No app name specified.\n";
23+
return;
24+
}
25+
26+
if (isset($options['path'])) $rootPath = $options['path'];
27+
else $rootPath = getcwd();
28+
29+
$projetName = $args[0];
30+
$appPath = $rootPath.'/'.$projetName;
31+
32+
$this->mkdir($projetName, $rootPath);
33+
$this->createAppDirs($appPath);
34+
}
35+
36+
private function createAppDirs($appPath)
37+
{
38+
$this->mkdir('app', $appPath);
39+
$this->mkdir('app/controllers', $appPath);
40+
$this->mkdir('app/helpers', $appPath);
41+
$this->mkdir('app/models', $appPath);
42+
$this->mkdir('app/views', $appPath);
43+
$this->mkdir('app/views/layout', $appPath);
44+
$this->mkdir('cache', $appPath);
45+
$this->mkdir('conf', $appPath);
46+
$this->mkdir('db', $appPath);
47+
$this->mkdir('db/migrate', $appPath);
48+
$this->mkdir('lib', $appPath);
49+
$this->mkdir('log', $appPath);
50+
$this->mkdir('public', $appPath);
51+
$this->mkdir('script', $appPath);
52+
$this->mkdir('test', $appPath);
53+
}
54+
}

library/Stato/Cli/Command/Help.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
4+
5+
6+
7+
8+
class Stato_Cli_Command_Help extends Stato_Cli_Command
9+
{
10+
public function run($params)
11+
{
12+
13+
}
14+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
4+
5+
6+
7+
8+
class Stato_Cli_Command_I18n_Makemessages extends Stato_Cli_Command
9+
{
10+
private $rootPath;
11+
private $tokens;
12+
private $messages;
13+
private $functions = array('__', '_f', '_p');
14+
15+
public function __construct()
16+
{
17+
parent::__construct();
18+
$this->shortDesc = 'stato i18n:makemessages - Create a message file for a new language';
19+
$this->longDesc = 'The command runs over your application source tree and pulls out all strings marked for translation.';
20+
21+
$this->addOption('-p', '--path', Stato_Cli_Option::STRING);
22+
$this->addOption('-l', '--lang', Stato_Cli_Option::STRING);
23+
$this->addOption('-b', '--backend', Stato_Cli_Option::STRING);
24+
}
25+
26+
public function run($options = array(), $args = array())
27+
{
28+
if (isset($options['path'])) $this->rootPath = rtrim($options['path'], '/');
29+
else $this->rootPath = getcwd();
30+
31+
$appPath = $this->rootPath.'/app';
32+
$localePath = $this->rootPath.'/locale';
33+
34+
if (!file_exists($appPath)) {
35+
echo "It looks like you're not at the root directory of a Stato project.\n";
36+
return;
37+
}
38+
39+
if (!isset($options['lang'])) {
40+
echo "Please provide a language code.\n";
41+
return;
42+
}
43+
44+
$backendName = (!isset($options['backend'])) ? 'simple' : $options['backend'];
45+
$backendClass = 'Stato_I18n_Backend_'.ucfirst($backendName);
46+
$backend = new $backendClass($localePath);
47+
48+
$this->messages = array();
49+
50+
$it = new RecursiveDirectoryIterator($appPath);
51+
foreach (new RecursiveIteratorIterator($it) as $file) {
52+
if ($file->isFile()) $this->extractMessages((string) $file);
53+
}
54+
55+
foreach ($this->messages as $comment => $message) {
56+
$backend->addKey($options['lang'], $message, $comment);
57+
}
58+
59+
$backend->save($options['lang'], $localePath);
60+
}
61+
62+
private function extractMessages($filepath)
63+
{
64+
$this->tokens = token_get_all(file_get_contents($filepath));
65+
while ($token = current($this->tokens)) {
66+
if (!is_string($token)) {
67+
list($id, $text) = $token;
68+
if ($id == T_STRING && in_array($text, $this->functions)) {
69+
$this->processMessage($filepath);
70+
continue;
71+
}
72+
}
73+
next($this->tokens);
74+
}
75+
}
76+
77+
private function processMessage($currentFile)
78+
{
79+
next($this->tokens);
80+
while ($t = current($this->tokens)) {
81+
if (is_string($t) || (is_array($t) && ($t[0] == T_WHITESPACE || $t[0] == T_DOC_COMMENT || $t[0] == T_COMMENT))) {
82+
next($this->tokens);
83+
} else {
84+
$this->storeMessage(trim($t[1], "'"), $currentFile, $t[2]);
85+
next($this->tokens);
86+
return;
87+
}
88+
}
89+
}
90+
91+
private function storeMessage($message, $currentFile, $line)
92+
{
93+
$file = str_replace($this->rootPath.'/', '', $currentFile);
94+
$this->messages[$file.':'.$line] = $message;
95+
}
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
4+
5+
class Stato_Cli_CommandRunner
6+
{
7+
private static $version = '2.0b1';
8+
9+
private static $commandsBasePath = null;
10+
11+
public static function main($args)
12+
{
13+
self::handleArguments($args);
14+
}
15+
16+
private static function handleArguments($args)
17+
{
18+
$scriptName = array_shift($args);
19+
if (count($args) == 0) {
20+
echo self::getHelp();
21+
} elseif ($args[0]{0} == '-') {
22+
$parser = new Stato_Cli_OptionParser(self::getOptions());
23+
list($opts, $nonOpts) = $parser->parseArgs($args);
24+
if (isset($opts['version']))
25+
echo 'stato version '.self::$version."\n";
26+
if (isset($opts['help'])) {
27+
$command = self::getCommand($opts['help']);
28+
if (!$command) echo("stato: '{$opts['help']}' is not a stato command. See 'stato --help'.\n");
29+
else echo $command->getHelp();
30+
}
31+
} else {
32+
$commandName = array_shift($args);
33+
$command = self::getCommand($commandName);
34+
if (!$command) {
35+
echo("stato: '{$commandName}' is not a stato command. See 'stato --help'.\n");
36+
return;
37+
}
38+
$parser = new Stato_Cli_OptionParser($command->getOptions());
39+
list($opts, $nonOpts) = $parser->parseArgs($args);
40+
$command->run($opts, $nonOpts);
41+
}
42+
}
43+
44+
public static function setCommandsBasePath($commandsBasePath)
45+
{
46+
self::$commandsBasePath = $commandsBasePath;
47+
}
48+
49+
private static function getCommand($commandName)
50+
{
51+
$commandClass = self::getCommandClass($commandName);
52+
$commandFile = self::getCommandPath($commandName);
53+
if (!file_exists($commandFile)) return false;
54+
require_once $commandFile;
55+
if (!class_exists($commandClass, false)) return false;
56+
return new $commandClass;
57+
}
58+
59+
private static function getOptions()
60+
{
61+
return array(
62+
new Stato_Cli_Option('-v', '--version', Stato_Cli_Option::BOOLEAN),
63+
new Stato_Cli_Option('-h', '--help', Stato_Cli_Option::STRING)
64+
);
65+
}
66+
67+
private static function getHelp()
68+
{
69+
$help = <<<EOT
70+
usage: stato [-v|--version] [-h|--help] COMMAND [ARGS]
71+
72+
The most commonly used stato commands are:
73+
createapp Create a skeleton application
74+
migrate Migrate the application db to a specific version
75+
76+
See 'stato help COMMAND' for more information on a specific command.
77+
78+
EOT;
79+
return $help;
80+
}
81+
82+
private static function getCommandPath($commandName)
83+
{
84+
if (self::$commandsBasePath === null) self::$commandsBasePath = dirname(__FILE__) . '/Command';
85+
$commandPath = self::$commandsBasePath;
86+
foreach (explode(':', $commandName) as $segment) $commandPath.= '/'.ucfirst($segment);
87+
return $commandPath.'.php';
88+
}
89+
90+
private static function getCommandClass($commandName)
91+
{
92+
$commandClass = 'Stato_Cli_Command';
93+
foreach (explode(':', $commandName) as $segment) $commandClass.= '_'.ucfirst($segment);
94+
return $commandClass;
95+
}
96+
}

library/Stato/Cli/Exception.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
4+
5+
class Stato_Cli_Exception extends Exception {}

0 commit comments

Comments
 (0)