Compare commits

..
Author SHA1 Message Date
Grégory PLANCHAT
2fde7653cf Merge pull request #6 from Noxgame/patch-1
Update src/application/code/core/Legacies/Empire/install/mysql5/install-...
2013-02-26 00:40:39 -08:00
Grégory PLANCHAT
7dcc790e65 Merge pull request #7 from loic-talon/master
Fix different error
2013-02-26 00:39:42 -08:00
Loïc TALON
5797328adc Fix date of messages and undefined var 2013-02-24 20:45:07 +01:00
Loïc TALON
6f1e5e4467 Fix Marchand
Fix undefined value in options.php
2013-02-24 19:01:04 +01:00
Loïc TALON
8ebc4cd91f Fix undefined dpath (options.php) 2013-02-24 18:11:09 +01:00
Loïc TALON
4b92511bae Fix second parameter of function date (options.php) 2013-02-24 17:58:42 +01:00
Mandalorien
74c4f31f7f Update src/application/code/core/Legacies/Empire/install/mysql5/install-1.5.0.php
correction
2013-01-22 17:21:24 +01:00
460 changed files with 6552 additions and 19136 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ config.php
.idea/ .idea/
coverage/ coverage/
src/application/cache/* src/application/cache/*
src/application/configs/local.php

View file

@ -1,6 +0,0 @@
language: php
php:
- 5.4
script: sh build/build.sh

146
build.xml Normal file
View file

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="name-of-project" default="build">
<target name="build"
depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpdoc,phpunit,phpcb"/>
<target name="build-parallel"
depends="prepare,lint,tools-parallel,phpunit,phpcb"/>
<target name="tools-parallel"
description="Run tools in parallel">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs-ci"/>
<antcall target="phploc"/>
<antcall target="phpdoc"/>
</parallel>
</target>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/code-browser"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
</target>
<target name="prepare" depends="clean"
description="Prepare for build">
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>
<target name="lint">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/src">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="phploc">
<arg value="--log-csv" />
<arg value="${basedir}/build/logs/phploc.csv" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="pdepend"
description="Calculate software metrics using PHP_Depend">
<exec executable="pdepend">
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpmd"
description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
<exec executable="phpmd">
<arg path="${basedir}/src" />
<arg value="text" />
<arg value="${basedir}/build/phpmd.xml" />
</exec>
</target>
<target name="phpmd-ci"
description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
<exec executable="phpmd">
<arg path="${basedir}/src" />
<arg value="xml" />
<arg value="${basedir}/build/phpmd.xml" />
<arg value="--reportfile" />
<arg value="${basedir}/build/logs/pmd.xml" />
</exec>
</target>
<target name="phpcs"
description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<exec executable="phpcs">
<arg value="--standard=${basedir}/build/phpcs.xml" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
<exec executable="phpcs" output="/dev/null">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=${basedir}/build/phpcs.xml" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--log-pmd" />
<arg value="${basedir}/build/logs/pmd-cpd.xml" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpdoc"
description="Generate API documentation using PHPDocumentor">
<exec executable="phpdoc">
<arg value="--directory" />
<arg path="${basedir}/src" />
<arg value="--target" />
<arg path="${basedir}/build/api" />
</exec>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true"/>
</target>
<target name="phpcb"
description="Aggregate tool output with PHP_CodeBrowser">
<exec executable="phpcb">
<arg value="--log" />
<arg path="${basedir}/build/logs" />
<arg value="--source" />
<arg path="${basedir}/src" />
<arg value="--output" />
<arg path="${basedir}/build/code-browser" />
</exec>
</target>
</project>

View file

@ -1,13 +0,0 @@
echo " * Wootook unit testing"
MODULES_DIR="`pwd`/src/application/modules"
for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d`
do
echo " * Running `basename ${file}` module tests (Unit tests)"
phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit
#echo " * Running `basename ${file}` module tests (Integration tests)"
#phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit
done

View file

@ -16,6 +16,3 @@ SetEnv DEPRECATION On
RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L] RewriteRule .* index.php [L]
</IfModule> </IfModule>
# OVH.com
SetEnv PHP_VER 5_4

View file

@ -30,7 +30,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
require_once dirname(__FILE__) .'/application/bc.php'; require_once dirname(__FILE__) .'/application/bootstrap.php';
$mode = Wootook::getRequest()->getPost('mode'); $mode = Wootook::getRequest()->getPost('mode');

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin'); includeLang('admin');
@ -76,4 +76,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN))) {
includeLang('admin/Queries'); includeLang('admin/Queries');
@ -56,4 +56,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
include(ROOT_PATH . 'includes/functions/BuildFlyingFleetTable.'.PHPEXT); include(ROOT_PATH . 'includes/functions/BuildFlyingFleetTable.'.PHPEXT);

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('admin'); includeLang('admin');
@ -135,4 +135,4 @@ function WootookResetUnivers ( $CurrentUser ) {
display ($Page, $lang['Reset'], false, '', true); display ($Page, $lang['Reset'], false, '', true);
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $user = Wootook_Player_Model_Session::getSingleton()->getPlayer();

View file

@ -32,7 +32,7 @@ define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $user = Wootook_Player_Model_Session::getSingleton()->getPlayer();

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $user = Wootook_Player_Model_Session::getSingleton()->getPlayer();

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
includeLang('admin/addmoon'); includeLang('admin/addmoon');
@ -66,4 +66,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
} else { } else {
AdminMessage ( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); AdminMessage ( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN))) {
doquery("UPDATE {{table}} SET `banaday` =` banaday` - '1' WHERE `banaday` != '0';",'users'); doquery("UPDATE {{table}} SET `banaday` =` banaday` - '1' WHERE `banaday` != '0';",'users');

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin'); includeLang('admin');
@ -86,4 +86,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
AdminMessage ($lang['sys_noalloaw'], $lang['sys_noaccess']); AdminMessage ($lang['sys_noalloaw'], $lang['sys_noaccess']);
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('changelog'); includeLang('changelog');
$template = gettemplate('changelog_table'); $template = gettemplate('changelog_table');
@ -53,4 +53,4 @@ $page .= parsetemplate(gettemplate('changelog_body'), $parse);
display( $page, "Changelog", false, '', true); display( $page, "Changelog", false, '', true);
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('admin'); includeLang('admin');
$parse = $lang; $parse = $lang;
@ -63,4 +63,4 @@ $parse = $lang;
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('credit'); includeLang('credit');
$parse = $lang; $parse = $lang;
@ -70,4 +70,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN))) {
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
includeLang('admin'); includeLang('admin');
@ -84,4 +84,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($CurrentUser['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($CurrentUser['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
$PageTpl = gettemplate( "admin/deletuser" ); $PageTpl = gettemplate( "admin/deletuser" );
@ -47,4 +47,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('admin'); includeLang('admin');
$parse = $lang; $parse = $lang;

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
includeLang('leftmenu'); includeLang('leftmenu');

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin/changepass'); includeLang('admin/changepass');
@ -57,4 +57,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin/md5enc'); includeLang('admin/md5enc');
@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
includeLang('admin/messagelist'); includeLang('admin/messagelist');

View file

@ -32,7 +32,7 @@ define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
if (!empty($_POST)) { if (!empty($_POST)) {
@ -72,4 +72,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERA
} }
} else { } else {
message($lang['sys_noalloaw'], $lang['sys_noaccess']); message($lang['sys_noalloaw'], $lang['sys_noaccess']);
} }

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
includeLang('overview'); includeLang('overview');
@ -59,4 +59,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
} else { } else {
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin/multi'); includeLang('admin/multi');
@ -62,4 +62,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {
includeLang('admin'); includeLang('admin');

View file

@ -32,7 +32,7 @@ define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
@ -60,4 +60,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
} }
// Created by e-Zobar. All rights reversed (C) Wootook Team 2008 // Created by e-Zobar. All rights reversed (C) Wootook Team 2008
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
function DisplayGameSettingsPage($CurrentUser) { function DisplayGameSettingsPage($CurrentUser) {

View file

@ -32,7 +32,7 @@ define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
include(ROOT_PATH . 'admin/statfunctions.' . PHPEXT); include(ROOT_PATH . 'admin/statfunctions.' . PHPEXT);

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR))) {
includeLang('admin'); includeLang('admin');
@ -90,4 +90,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] ); message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
} }
?> ?>

View file

@ -31,7 +31,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
define('IN_ADMIN', true); define('IN_ADMIN', true);
require_once dirname(dirname(__FILE__)) .'/application/bc.php'; require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) { if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERATOR))) {

View file

@ -30,7 +30,7 @@
define('INSTALL' , false); define('INSTALL' , false);
define('INSIDE' , true); define('INSIDE' , true);
require_once dirname(__FILE__) .'/application/bc.php'; require_once dirname(__FILE__) .'/application/bootstrap.php';
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer(); $user = Wootook_Player_Model_Session::getSingleton()->getPlayer();
$db = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection(Wootook_Core_Database_ConnectionManager::DEFAULT_CONNECTION_NAME); $db = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection(Wootook_Core_Database_ConnectionManager::DEFAULT_CONNECTION_NAME);
@ -1228,4 +1228,4 @@ elseif ($user->getData('ally_id') != 0 && $user->getData('ally_request') == 0) {
$page .= parsetemplate(gettemplate('alliance_frontpage'), $lang); $page .= parsetemplate(gettemplate('alliance_frontpage'), $lang);
display($page, $lang['your_alliance']); display($page, $lang['your_alliance']);
} }
} }

View file

@ -30,7 +30,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
require_once dirname(__FILE__) .'/application/bc.php'; require_once dirname(__FILE__) .'/application/bootstrap.php';
$readAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_read'); $readAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_read');
$writeAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_write'); $writeAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_write');

View file

@ -30,7 +30,7 @@
define('INSIDE' , true); define('INSIDE' , true);
define('INSTALL' , false); define('INSTALL' , false);
require_once dirname(__FILE__) .'/application/bc.php'; require_once dirname(__FILE__) .'/application/bootstrap.php';
$actions = $_GET['action']; $actions = $_GET['action'];
@ -59,4 +59,4 @@ HTML;
display($page); display($page);
} }
?> ?>

View file

@ -1,103 +0,0 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2009-Present, Wootook Support Team <http://wootook.org>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
require_once __DIR__ . '/bc.php';
if (defined('IN_ADMIN')) {
Wootook::app()->setDefaultWebsiteId(0);
Wootook::app()->setDefaultGameId(0);
}
include ROOT_PATH . 'includes/constants.php';
if (!Wootook::$isInstalled) {
Wootook::app()->getFrontController()
->getResponse()
->setRedirect(Wootook::getStaticUrl('install/'), Wootook\Core\Mvc\Controller\Response\Http::REDIRECT_TEMPORARY)
->sendHeaders();
exit(0);
}
$lang = array();
define('DEFAULT_LANG', 'fr');
include(ROOT_PATH . 'includes/functions.' . PHPEXT);
include(ROOT_PATH . 'includes/unlocalised.' . PHPEXT);
include(ROOT_PATH . 'includes/todofleetcontrol.' . PHPEXT);
include(ROOT_PATH . 'language/' . DEFAULT_LANG . '/lang_info.cfg');
include(ROOT_PATH . 'includes/vars.' . PHPEXT);
include(ROOT_PATH . 'includes/strings.' . PHPEXT);
$user = Wootook\Player\Model\Session::getSingleton()->getPlayer();
if (!defined('DISABLE_IDENTITY_CHECK')) {
if ($user === null || !$user->getId()) {
Wootook::getResponse()
->setRedirect(Wootook::getUrl('player/account/login'))
->sendHeaders();
exit(0);
}
if (!Wootook::getGameConfig('game/general/active') && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))) {
$layout = new Wootook\Core\Layout\Manager(Wootook\Core\Layout\Manager::DOMAIN_FRONTEND);
$layout->load('message');
$block = $layout->getBlock('message');
$block['title'] = Wootook::__('Game is disabled.');
$block['message'] = Wootook::getGameConfig('game/general/closing-message');
echo $layout->render();
exit(0);
}
}
includeLang('system');
includeLang('tech');
if (($user !== null && $user->getId())) {
if (isset($_GET['cp']) && !empty($_GET['cp'])) {
$user->updateCurrentPlanet((int) $_GET['cp']);
}
$planet = $user->getCurrentPlanet();
foreach ($user->getPlanetCollection() as $userPlanet) {
FlyingFleetHandler($userPlanet); // TODO: implement logic into a refactored model
}
/*
* Update planet resources and constructions
*/
Wootook::dispatchEvent('planet.update', array(
'planet' => $planet
));
$planet->save();
}

View file

@ -28,9 +28,6 @@
* *
*/ */
define('DEBUG', true);
define('DEPRECATION', true);
if (!defined('PHP_VERSION_ID')) { if (!defined('PHP_VERSION_ID')) {
$version = explode('.',PHP_VERSION); $version = explode('.',PHP_VERSION);
define('PHP_VERSION_ID', (((int)$version[0]) * 10000 + ((int)$version[1]) * 100 + ((int)$version[2]))); define('PHP_VERSION_ID', (((int)$version[0]) * 10000 + ((int)$version[1]) * 100 + ((int)$version[2])));
@ -70,12 +67,97 @@ defined('PHPEXT') || define('PHPEXT', 'php');
defined('VERSION') || define('VERSION', '1.5.0-beta2'); defined('VERSION') || define('VERSION', '1.5.0-beta2');
set_include_path(implode(PATH_SEPARATOR, array( set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules', APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'libraries',
APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'local',
APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'community',
APPLICATION_PATH . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR . 'core',
get_include_path() get_include_path()
))); )));
include APPLICATION_PATH . 'code' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'Wootook.php'; function __autoload($class) {
include 'WootookCore' . DIRECTORY_SEPARATOR . 'autoload_register.php'; include_once str_replace('_', '/', $class) . '.php';
}
Wootook\Core\Profiler\ErrorProfiler::register(); if (defined('IN_ADMIN')) {
Wootook\Core\Helper\Config\Events::registerEvents(); $website = new Wootook_Core_Model_Website();
$website->setId(0)->setData('code', 'admin');
Wootook::addWebsite($website);
Wootook::setDefaultWebsite($website);
$game = new Wootook_Core_Model_Game();
$game->setId(0)->setData('code', 'admin')->setData('website_id', $website->getId());
Wootook::addGame($game);
Wootook::setDefaultGame($game);
}
include ROOT_PATH . 'includes/constants.php';
if (defined('DEBUG')) {
Wootook_Core_ErrorProfiler::register();
}
Wootook_Core_Helper_Config_Events::registerEvents();
if (!Wootook::$isInstalled) {
Wootook::getResponse()
->setRedirect(Wootook::getStaticUrl('install/'), Wootook_Core_Mvc_Controller_Response_Http::REDIRECT_TEMPORARY)
->sendHeaders();
exit(0);
}
$lang = array();
define('DEFAULT_LANG', 'fr');
include(ROOT_PATH . 'includes/functions.' . PHPEXT);
include(ROOT_PATH . 'includes/unlocalised.' . PHPEXT);
include(ROOT_PATH . 'includes/todofleetcontrol.' . PHPEXT);
include(ROOT_PATH . 'language/' . DEFAULT_LANG . '/lang_info.cfg');
include(ROOT_PATH . 'includes/vars.' . PHPEXT);
include(ROOT_PATH . 'includes/strings.' . PHPEXT);
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer();
if (!defined('DISABLE_IDENTITY_CHECK')) {
if ($user === null || !$user->getId()) {
Wootook::getResponse()
->setRedirect(Wootook::getUrl('player/account/login'))
->sendHeaders();
exit(0);
}
//var_dump(Wootook::getGameConfig('game/general/active'));
if (!Wootook::getGameConfig('game/general/active')/* && !in_array($user->getData('authlevel'), array(LEVEL_ADMIN, LEVEL_MODERATOR, LEVEL_OPERATOR))*/) {
$layout = new Wootook_Core_Model_Layout(Wootook_Core_Model_Layout::DOMAIN_FRONTEND);
$layout->load('message');
$block = $layout->getBlock('message');
$block['title'] = Wootook::__('Game is disabled.');
$block['message'] = Wootook::getGameConfig('game/general/closing-message');
echo $layout->render();
exit(0);
}
}
includeLang('system');
includeLang('tech');
if (($user !== null && $user->getId())) {
if (isset($_GET['cp']) && !empty($_GET['cp'])) {
$user->updateCurrentPlanet((int) $_GET['cp']);
}
$planet = $user->getCurrentPlanet();
foreach ($user->getPlanetCollection() as $userPlanet) {
FlyingFleetHandler($userPlanet); // TODO: implement logic into a refactored model
}
/*
* Update planet resources and constructions
*/
Wootook::dispatchEvent('planet.update', array(
'planet' => $planet
));
$planet->save();
}

View file

@ -63,7 +63,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item
$resourceConfig = array(); $resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) { foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( $resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId, 'resource_id' => $resourceId,
'value' => $resourceValue 'value' => $resourceValue
)); ));
@ -87,4 +87,4 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item
{ {
return $this->getBuildingTime($this->getNextLevel()); return $this->getBuildingTime($this->getNextLevel());
} }
} }

View file

@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Queue_Item
$resourceConfig = array(); $resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) { foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( $resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId, 'resource_id' => $resourceId,
'value' => $resourceValue 'value' => $resourceValue
)); ));

View file

@ -68,7 +68,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Item
$resourceConfig = array(); $resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) { foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( $resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId, 'resource_id' => $resourceId,
'value' => $resourceValue 'value' => $resourceValue
)); ));

View file

@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Queue_Item
$resourceConfig = array(); $resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) { foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array( $resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId, 'resource_id' => $resourceId,
'value' => $resourceValue 'value' => $resourceValue
)); ));

View file

@ -54,7 +54,7 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
{ {
$this->_unserializeQueue($this->_currentPlanet->getData(self::FIELD_SERIALIZED)); $this->_unserializeQueue($this->_currentPlanet->getData(self::FIELD_SERIALIZED));
$this->_maxLength = Wootook::app()->getDefaultGame()->getConfig('engine/core/lab_queue_size'); $this->_maxLength = Wootook::getGameConfig('engine/core/lab_queue_size');
} }
/** /**
@ -144,7 +144,7 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
$partialLevelTime = Math::mul($firstLevelTime, Math::pow($prices[$technologyId][Legacies_Empire::RESOURCE_MULTIPLIER], $level)); $partialLevelTime = Math::mul($firstLevelTime, Math::pow($prices[$technologyId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
$levelTime = Math::sub($partialLevelTime, $firstLevelTime); $levelTime = Math::sub($partialLevelTime, $firstLevelTime);
$speedFactor = Wootook::app()->getDefaultGame()->getConfig('game/speed/general'); $speedFactor = Wootook::getGameConfig('game/speed/general');
if ($speedFactor == null) { if ($speedFactor == null) {
$speedFactor = 1; $speedFactor = 1;
} }

View file

@ -207,7 +207,7 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
Math::setPrecision(50); Math::setPrecision(50);
$buildingTime = Math::mul($prices[$shipId][Legacies_Empire::BASE_BUILDING_TIME], intval($qty)); $buildingTime = Math::mul($prices[$shipId][Legacies_Empire::BASE_BUILDING_TIME], intval($qty));
$speedFactor = Wootook::app()->getDefaultGame()->getConfig('game/speed/general') / 1000; $speedFactor = Wootook::getGameConfig('game/speed/general') / 1000;
$baseTime = Math::mul(Math::div($buildingTime, 5000), Math::mul($speedFactor, $this->getSpeedEnhancement())); $baseTime = Math::mul(Math::div($buildingTime, 5000), Math::mul($speedFactor, $this->getSpeedEnhancement()));
Math::setPrecision(); Math::setPrecision();

View file

@ -351,8 +351,8 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('planets')} (
`gauss_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, `gauss_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`ionic_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, `ionic_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`buster_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0, `buster_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`small_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0, `small_protection_shield` ENUM('0','1') NOT NULL DEFAULT '0',
`big_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0, `big_protection_shield` ENUM('0','1') NOT NULL DEFAULT '0',
`interceptor_misil` SMALLINT NOT NULL DEFAULT 0, `interceptor_misil` SMALLINT NOT NULL DEFAULT 0,
`interplanetary_misil` SMALLINT NOT NULL DEFAULT 0, `interplanetary_misil` SMALLINT NOT NULL DEFAULT 0,
`metal_mine_porcent` TINYINT NOT NULL DEFAULT 10, `metal_mine_porcent` TINYINT NOT NULL DEFAULT 10,

View file

@ -28,9 +28,6 @@
* *
*/ */
use Wootook\Core\Exception as CoreException,
Wootook\Core\Profiler;
/** /**
* Bootstrap class, used to access main and global functionalities * Bootstrap class, used to access main and global functionalities
* *
@ -53,6 +50,20 @@ class Wootook
*/ */
private static $_translators = array(); private static $_translators = array();
/**
* HTTP request management object
*
* @var Legacies_Core_Controller_Request_Http
*/
private static $_request = null;
/**
* HTTP response management object
*
* @var Legacies_Core_Controller_Response
*/
private static $_response = null;
/** /**
* The current timestamp * The current timestamp
* *
@ -67,6 +78,34 @@ class Wootook
*/ */
private static $_defaultLocale = 'fr_FR'; private static $_defaultLocale = 'fr_FR';
/**
*
* Enter description here ...
* @var Wootook_Core_Helper_Config_ConfigHandler
*/
private static $_config = null;
/**
*
* Enter description here ...
* @var Wootook_Core_Helper_Config_ConfigHandler
*/
private static $_globalConfig = null;
/**
*
* Enter description here ...
* @var array
*/
private static $_websiteConfigs = array();
/**
*
* Enter description here ...
* @var array
*/
private static $_gameConfigs = array();
/** /**
* *
* Enter description here ... * Enter description here ...
@ -74,9 +113,15 @@ class Wootook
*/ */
private static $_ignoreDatabaseConfig = false; private static $_ignoreDatabaseConfig = false;
public static $isInstalled = true; private static $_defaultWebsite = null;
private static $_defaultGame = null;
protected static $_app = array(); private static $_websitesById = array();
private static $_websitesByCode = array();
private static $_gamesById = array();
private static $_gamesByCode = array();
public static $isInstalled = true;
/** /**
* Registers an event listener to be called later in the application. * Registers an event listener to be called later in the application.
@ -120,7 +165,7 @@ class Wootook
*/ */
public static function dispatchEvent($event, $params) public static function dispatchEvent($event, $params)
{ {
$eventObject = new Wootook\Core\Event\Event(self::app(), $params); $eventObject = new Wootook_Core_Event($params);
if (!isset(self::$_listeners[$event])) { if (!isset(self::$_listeners[$event])) {
return $eventObject; return $eventObject;
@ -137,17 +182,17 @@ class Wootook
* *
* Enter description here ... * Enter description here ...
* @param unknown_type $namespace * @param unknown_type $namespace
* @return Wootook\Core\Model\Session * @return Wootook_Core_Model_Session
*/ */
public static function getSession($namespace) public static function getSession($namespace)
{ {
return Wootook\Core\Model\Session::factory($namespace); return Wootook_Core_Model_Session::factory($namespace);
} }
/** /**
* @static * @static
* @param string|null $locale * @param string|null $locale
* @return Wootook\Core\Model\Translator * @return Wootook_Core_Model_Translator
*/ */
public static function getTranslator($locale = null) public static function getTranslator($locale = null)
{ {
@ -157,7 +202,7 @@ class Wootook
if (!isset($translator[$locale])) { if (!isset($translator[$locale])) {
$path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'locale'; $path = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'locale';
$translator[$locale] = new Wootook\Core\Model\Translator($path, $locale); $translator[$locale] = new Wootook_Core_Model_Translator($path, $locale);
} }
return $translator[$locale]; return $translator[$locale];
} }
@ -177,7 +222,7 @@ class Wootook
public static function getLocale() public static function getLocale()
{ {
$availableLocales = self::app()->getDefaultWebsite()->getConfig('locales'); $availableLocales = self::getWebsiteConfig('locales');
if ($availableLocales !== null) { if ($availableLocales !== null) {
return self::getPreferredLocale($availableLocales->toArray()); return self::getPreferredLocale($availableLocales->toArray());
} }
@ -203,17 +248,14 @@ class Wootook
return self::getDefaultLocale(); return self::getDefaultLocale();
} }
// FIXME: Dependency should not exist $userLocale = Wootook_Player_Model_Session::getSingleton()->getData('locale');
/*
$userLocale = Wootook\Player\Model\Session::getSingleton()->getData('locale');
if ($userLocale !== null && in_array($userLocale, $availableLocales)) { if ($userLocale !== null && in_array($userLocale, $availableLocales)) {
return $userLocale; return $userLocale;
} }
*/
$locales = array(); $locales = array();
if (($accept = self::app()->getFrontController()->getRequest()->getServer('HTTP_ACCEPT_LANGUAGE')) !== null) { if (($accept = self::getRequest()->getServer('HTTP_ACCEPT_LANGUAGE')) !== null) {
// break up string into pieces (languages and q factors) // break up string into pieces (languages and q factors)
preg_match_all('/([a-z]{1,8}(?:-([a-z]{1,8}))?)\s*(?:;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $accept, $matches); preg_match_all('/([a-z]{1,8}(?:-([a-z]{1,8}))?)\s*(?:;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $accept, $matches);
@ -245,247 +287,437 @@ class Wootook
} }
} }
// FIXME: Dependency should not exist Wootook_Player_Model_Session::getSingleton()->setData('locale', $preferredLocale);
//Wootook\Player\Model\Session::getSingleton()->setData('locale', $preferredLocale);
return $preferredLocale; return $preferredLocale;
} }
/** /**
* @static * @static
* @return Wootook\Core\DateTime * @return Wootook_Core_DateTime
*/ */
public static function now() public static function now()
{ {
if (self::$_now === null) { if (self::$_now === null) {
self::$_now = time(); self::$_now = time();
} }
return new Wootook\Core\DateTime(self::$_now); return new Wootook_Core_DateTime(self::$_now);
} }
/** /**
* @static * @return Wootook_Core_Mvc_Controller_Request_Http
* @return Wootook\Core\App
*/
public static function app($domain = Wootook\Core\App::DOMAIN_FRONTEND, $environment = Wootook\Core\App::ENV_PRODUCTION)
{
if (!isset(self::$_app[$environment])) {
self::$_app[$environment] = array();
}
if (!isset(self::$_app[$environment][$domain])) {
$configPath = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs';
self::$_app[$environment][$domain] = new Wootook\Core\App($configPath, $domain, $environment);
}
return self::$_app[$environment][$domain];
}
/**
* @deprecated
* @return Wootook\Core\Mvc\Controller\Request\Request
*/ */
public static function getRequest() public static function getRequest()
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_request === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_request = new Wootook_Core_Mvc_Controller_Request_Http();
return self::app()->getFrontController()->getRequest(); }
return self::$_request;
} }
/** public static function setRequest($request)
* @static
* @deprecated
* @param Wootook\Core\Mvc\Controller\Request\Request $request
*/
public static function setRequest(Wootook\Core\Mvc\Controller\Request\Request $request)
{ {
Profiler\ErrorProfiler::getSingleton() self::$_request = $request;
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
self::app()->getFrontController()->setRequest($request);
} }
/** /**
* @deprecated * @return Wootook_Core_Mvc_Controller_Response_Http
* @return Wootook\Core\Mvc\Controller\Response\Response
*/ */
public static function getResponse() public static function getResponse()
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_response === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_response = new Wootook_Core_Mvc_Controller_Response_Http();
return self::app()->getFrontController()->getResponse(); }
return self::$_response;
} }
/** public static function setResponse($response)
* @static
* @deprecated
* @param Wootook\Core\Mvc\Controller\Response\Response $response
*/
public static function setResponse(Wootook\Core\Mvc\Controller\Response\Response $response)
{ {
Profiler\ErrorProfiler::getSingleton() self::$_response = $response;
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
self::app()->getFrontController()->setResponse($response);
} }
/**
* @static
* @deprecated
* @param null $filename
* @return null|Wootook_Core_Helper_Config_ConfigHandler
* @throws CoreException\DataAccessException
*/
public static function loadConfig($filename = null) public static function loadConfig($filename = null)
{ {
Profiler\ErrorProfiler::getSingleton() self::$_websiteConfigs = array();
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_gameConfigs = array();
return self::app()->getGlobalConfig();
self::$_config = new Wootook_Core_Config_Adapter_Array();
try {
self::$_config->load(APPLICATION_PATH . 'configs' . DIRECTORY_SEPARATOR . 'system.php');
if ($filename === null) {
$filename = APPLICATION_PATH . 'configs' . DIRECTORY_SEPARATOR . 'local.php';
}
if (is_string($filename)) {
if (!self::$isInstalled) {
throw new Wootook_Core_Exception_DataAccessException();
}
$localConfig = new Wootook_Core_Config_Adapter_Array($filename);
self::$_config->merge($localConfig);
} else if (is_array($filename)) {
$localConfig = new Wootook_Core_Config_Node($filename);
self::$_config->merge($localConfig);
} else if ($filename instanceof Wootook_Core_Config_Node) {
self::$_config->merge($filename);
} else {
throw new Wootook_Core_Exception_DataAccessException();
}
} catch (Wootook_Core_Exception_DataAccessException $e) {
self::$_globalConfig = new Wootook_Core_Config_Node(array(), self::$_config);
self::$_ignoreDatabaseConfig = true;
return self::$_config;
}
self::$_globalConfig = clone self::$_config['default'];
if (isset(self::$_config['global'])) {
self::$_globalConfig->merge(self::$_config['global']);
}
self::_appendDatabaseConfig(self::$_globalConfig);
return self::$_config;
}
private static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $model = null)
{
if (self::$_ignoreDatabaseConfig || !self::$isInstalled) {
return $config;
}
try {
$adapter = Wootook_Core_Database_ConnectionManager::getSingleton()
->getConnection('core_read');
} catch (Wootook_Core_Exception_Database_AdapterError $e) {
// This may also occur when the pdo_sqlite driver isn't loaded
self::$isInstalled = false;
Wootook_Core_ErrorProfiler::getSingleton()->addException($e);
return $config;
}
$select = $adapter->select($adapter->getTable('core_config'));
switch ($type) {
case 'website':
$select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('website_id = :website_id', array('website_id' => $model->getId())));
break;
case 'game':
$select->where(new Wootook_Core_Database_Sql_Placeholder_Expression('game_id = :game_id', array('game_id' => $model->getId())));
break;
default:
$select->where('website_id', 0);
$select->where('game_id', 0);
break;
}
$statement = $select->prepare();
$statement->execute();
foreach ($statement as $row) {
$config->setConfig($row['config_path'], $row['config_value']);
}
return $config;
} }
/**
* @static
* @deprecated
* @param $websiteId
* @return mixed
*/
public static function getWebsite($websiteId) public static function getWebsite($websiteId)
{ {
Profiler\ErrorProfiler::getSingleton() if (is_numeric($websiteId)) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); if (isset(self::$_websitesById[$websiteId])) {
return self::app()->getWebsite($websiteId); return self::$_websitesById[$websiteId];
}
$website = new Wootook_Core_Model_Website();
try {
$website->load($websiteId);
$websiteCode = $website->getData('code');
self::$_websitesById[$websiteId] = $website;
self::$_websitesByCode[$websiteCode] = $website;
} catch (Wootook_Core_Exception_DataAccessException $e) {
throw new Wootook_Core_Exception_WebsiteError('Could not load website entity.', null, $e);
}
return $website;
} else {
if (isset(self::$_websitesByCode[$websiteId])) {
return self::$_websitesByCode[$websiteId];
}
$website = new Wootook_Core_Model_Website();
try {
$website->load($websiteId, 'code');
$websiteId = $website->getId();
$websiteCode = $website->getData('code');
self::$_websitesById[$websiteId] = $website;
self::$_websitesByCode[$websiteCode] = $website;
} catch (Wootook_Core_Exception_DataAccessException $e) {
throw new Wootook_Core_Exception_WebsiteError('Could not load website entity.', null, $e);
}
return $website;
}
} }
/**
* @static
* @deprecated
* @param $gameId
* @return Wootook_Core_Model_Game
* @throws CoreException\GameError
*/
public static function getGame($gameId) public static function getGame($gameId)
{ {
Profiler\ErrorProfiler::getSingleton() if (is_numeric($gameId)) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); if (isset(self::$_gamesById[$gameId])) {
return self::app()->getGame($gameId); return self::$_gamesById[$gameId];
}
$game = new Wootook_Core_Model_Game();
try {
$game->load($gameId);
$gameCode = $game->getData('code');
self::$_gamesById[$gameId] = $game;
self::$_gamesByCode[$gameCode] = $game;
} catch (Wootook_Core_Exception_DataAccessException $e) {
throw new Wootook_Core_Exception_GameError('Could not load game entity.', null, $e);
}
return $game;
} else {
if (isset(self::$_gamesByCode[$gameId])) {
return self::$_gamesByCode[$gameId];
}
$game = new Wootook_Core_Model_Game();
try {
$game->load($gameId, 'code');
$gameId = $game->getId();
$gameCode = $game->getData('code');
self::$_gamesById[$gameId] = $game;
self::$_gamesByCode[$gameCode] = $game;
} catch (Wootook_Core_Exception_DataAccessException $e) {
throw new Wootook_Core_Exception_GameError('Could not load game entity.', null, $e);
}
return $game;
}
} }
/**
* @static
* @deprecated
* @param Wootook_Core_Model_Website $website
*/
public static function addWebsite(Wootook_Core_Model_Website $website) public static function addWebsite(Wootook_Core_Model_Website $website)
{ {
Profiler\ErrorProfiler::getSingleton() $websiteId = $website->getId();
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); $websiteKey = $website->getData('code');
self::$_websitesById[$websiteId] = $website;
self::$_websitesByCode[$websiteKey] = $website;
} }
/**
* @static
* @deprecated
* @param Wootook_Core_Model_Game $game
*/
public static function addGame(Wootook_Core_Model_Game $game) public static function addGame(Wootook_Core_Model_Game $game)
{ {
Profiler\ErrorProfiler::getSingleton() $gameId = $game->getId();
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); $gameKey = $game->getData('code');
self::$_gamesById[$gameId] = $game;
self::$_gamesByCode[$gameKey] = $game;
} }
/**
* @static
* @deprecated
* @param Wootook_Core_Model_Website $website
*/
public static function setDefaultWebsite(Wootook_Core_Model_Website $website) public static function setDefaultWebsite(Wootook_Core_Model_Website $website)
{ {
Profiler\ErrorProfiler::getSingleton() self::$_defaultWebsite = $website;
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
self::app()->setDefaultWebsiteId($website->getId());
} }
/**
* @static
* @deprecated
* @param Wootook_Core_Model_Game $game
*/
public static function setDefaultGame(Wootook_Core_Model_Game $game)
{
Profiler\ErrorProfiler::getSingleton()
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
self::app()->setDefaultGameId($game->getId());
}
/**
* @static
* @deprecated
* @return mixed
*/
public static function getDefaultWebsite() public static function getDefaultWebsite()
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_defaultWebsite === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_defaultWebsite = new Wootook_Core_Model_Website();
return self::app()->getDefaultWebsite(); self::$_defaultWebsite->setId(1)->setData('code', Wootook_Core_Model_Website::DEFAULT_CODE);
}
return self::$_defaultWebsite;
} }
/**
* @static
* @deprecated
* @return mixed
*/
public static function getDefaultGame() public static function getDefaultGame()
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_defaultGame === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_defaultGame = new Wootook_Core_Model_Game();
return self::app()->getDefaultGame(); self::$_defaultGame->setId(1)->setData('code', Wootook_Core_Model_Game::DEFAULT_CODE);
}
return self::$_defaultGame;
}
public static function setDefaultGame(Wootook_Core_Model_Game $game)
{
self::$_defaultGame = $game;
}
private static function _initWebsiteConfig($websiteId)
{
if (self::$_config === null) {
self::loadConfig();
}
if (!self::$isInstalled) {
if (isset(self::$_config['default'])) {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = clone self::$_config['default'];
} else {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config);
}
if (isset(self::$_config['install'])) {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE]->merge(self::$_config['install']);
}
return self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE];
}
try {
$website = self::getWebsite($websiteId);
} catch (Wootook_Core_Exception_WebsiteError $e) {
self::$isInstalled = false;
Wootook_Core_ErrorProfiler::getSingleton()->addException($e);
$website = new Wootook_Core_Model_Website();
$website->setId(0)->setData('code', 'install');
self::addWebsite($website);
self::setDefaultWebsite($website);
} catch (Wootook_Core_Exception_RuntimeException $e) {
Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e);
return null;
}
$websiteKey = $website->getData('code');
$websiteId = $website->getId();
if (!isset(self::$_websiteConfigs[$websiteKey])) {
self::$_websiteConfigs[$websiteKey] = clone self::$_config['default'];
if ($websiteId != 0 && isset(self::$_config['frontend'])) {
self::$_websiteConfigs[$websiteKey]->merge(self::$_config['frontend']);
} else if ($websiteId == 0 && isset(self::$_config['backend'])) {
self::$_websiteConfigs[$websiteKey]->merge(self::$_config['backend']);
}
$websiteConfig = self::$_config->getConfig("website/{$websiteKey}");
if ($websiteConfig !== null) {
self::$_websiteConfigs[$websiteKey]->merge($websiteConfig);
}
self::_appendDatabaseConfig(self::$_websiteConfigs[$websiteKey], 'website', $website);
}
return self::$_websiteConfigs[$websiteKey];
}
private static function _initGameConfig($gameId)
{
if (self::$_config === null) {
self::loadConfig();
}
if (!self::$isInstalled) {
if (isset(self::$_config['default'])) {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = clone self::$_config['default'];
} else {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config);
}
if (isset(self::$_config['install'])) {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE]->merge(self::$_config['install']);
}
return self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE];
}
try {
$game = self::getGame($gameId);
} catch (Wootook_Core_Exception_GameError $e) {
self::$isInstalled = false;
Wootook_Core_ErrorProfiler::getSingleton()->addException($e);
$game = new Wootook_Core_Model_Game();
$game->setId(0)->setData('code', 'install')->setData('website_id', self::getDefaultWebsite()->getId());
self::addGame($game);
self::setDefaultGame($game);
} catch (Wootook_Core_Exception_RuntimeException $e) {
Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e);
return null;
}
$gameKey = $game->getData('code');
$gameId = $game->getId();
$websiteId = $game->getData('website_id');
if (!isset(self::$_gameConfigs[$gameKey])) {
$websiteConfig = self::_initWebsiteConfig($websiteId);
if ($websiteConfig === null) {
return null;
}
self::$_gameConfigs[$gameKey] = clone $websiteConfig;
$gameConfig = self::$_config->getConfig("game/{$gameKey}");
if ($gameConfig !== null) {
self::$_gameConfigs[$gameKey]->merge($gameConfig);
}
self::_appendDatabaseConfig(self::$_gameConfigs[$gameKey], 'game', $game);
}
return self::$_gameConfigs[$gameKey];
} }
/**
* @static
* @deprecated
* @param null $path
* @return null|Wootook_Core_Config_Adapter_Array
*/
public static function getConfig($path = null) public static function getConfig($path = null)
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_config === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::loadConfig();
return self::app()->getGlobalConfig($path); }
if ($path !== null) {
return self::$_globalConfig->getConfig($path);
}
return self::$_globalConfig;
} }
/** /**
* @static * @static
* @deprecated
* @param null $path * @param null $path
* @param null $gameKey * @param null $gameKey
* @return Wootook_Core_Config_Node * @return Wootook_Core_Config_Node
*/ */
public static function getWebsiteConfig($path = null, $websiteKey = null) public static function getWebsiteConfig($path = null, $websiteKey = null)
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_config === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::loadConfig();
if ($websiteKey === null) {
$websiteKey = self::app()->getDefaultWebsiteId();
} }
return self::app()->getWebsite($websiteKey)->getConfig($path); if ($websiteKey === null) {
//$websiteKey = Wootook_Core_Model_Website::DEFAULT_CODE;
$websiteKey = self::getDefaultWebsite()->getData('code');
}
$config = self::_initWebsiteConfig($websiteKey);
if ($config === null) {
return null;
}
if ($path !== null) {
return $config->getConfig($path);
}
return $config;
} }
/** /**
* @static * @static
* @deprecated
* @param null $path * @param null $path
* @param null $gameKey * @param null $gameKey
* @return Wootook_Core_Config_Node * @return Wootook_Core_Config_Node
*/ */
public static function getGameConfig($path = null, $gameKey = null) public static function getGameConfig($path = null, $gameKey = null)
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_config === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::loadConfig();
if ($gameKey === null) {
$gameKey = self::app()->getDefaultGameId();
} }
return self::app()->getGame($gameKey)->getConfig($path); if ($gameKey === null) {
//$gameKey = Wootook_Core_Model_Game::DEFAULT_CODE;
$gameKey = self::getDefaultGame()->getData('code');
}
$config = self::_initGameConfig($gameKey);
if ($config === null) {
return null;
}
if ($path !== null) {
return $config->getConfig($path);
}
return $config;
} }
public static function setConfig($path, $value, $websiteId = null, $gameId = null) public static function setConfig($path, $value, $websiteId = null, $gameId = null)
@ -524,7 +756,7 @@ class Wootook
public static function getBaseUrl($domain = 'base') public static function getBaseUrl($domain = 'base')
{ {
$urlConfig = self::app()->getDefaultGame()->getConfig('web/url'); $urlConfig = self::getGameConfig('web/url');
if (!$urlConfig instanceof Wootook_Core_Config_Node) { if (!$urlConfig instanceof Wootook_Core_Config_Node) {
return null; return null;
} }
@ -536,7 +768,7 @@ class Wootook
public static function getBasePath($domain = 'base') public static function getBasePath($domain = 'base')
{ {
$pathConfig = self::app()->getDefaultGame()->getConfig('system/path'); $pathConfig = self::getGameConfig('system/path');
if (!$pathConfig instanceof Wootook_Core_Config_Node) { if (!$pathConfig instanceof Wootook_Core_Config_Node) {
return null; return null;
} }
@ -599,13 +831,13 @@ class Wootook
return false; return false;
} }
Profiler\ErrorProfiler::getSingleton()->sleep(); Wootook_Core_ErrorProfiler::getSingleton()->sleep();
if (($fp = @fopen($path, 'r', true)) === false) { if (($fp = @fopen($path, 'r', true)) === false) {
Profiler\ErrorProfiler::getSingleton()->wakeup(); Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
return false; return false;
} }
fclose($fp); fclose($fp);
Profiler\ErrorProfiler::getSingleton()->wakeup(); Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
return true; return true;
} }
} }

View file

@ -0,0 +1,155 @@
<?php
class Wootook_Core_App
{
/**
*
* Enter description here ...
* @var Wootook_Core_Config_Adapter_Adapter
*/
private $_globalConfig = null;
public function __construct($websiteCode, $gameCode)
{
$this->_globalConfig = Wootook::getConfig();
}
protected function _resolveClassType(&$namespaces, $module, $class)
{
$class = str_replace(' ', '', ucwords(str_replace('-', ' ', $class)));
$class = str_replace(' ', '_', ucwords(str_replace('.', ' ', $class)));
if (isset($namespaces[$module])) {
foreach ($namespaces[$module] as $namespace => $path) {
$className = $namespace . $class;
$fileName = $path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
Wootook_Core_ErrorProfiler::getSingleton()->sleep();
if (!($fp = @fopen($fileName, 'r', true))) {
Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
continue;
}
Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
fclose($fp);
if (!class_exists($className, true)) {
continue;
}
return $className;
}
}
Wootook_Core_ErrorProfiler::getSingleton()
->addException(new Wootook_Core_Exception_LayoutException(sprintf('Class type "%s" could not be resolved.', $type)));
return null;
}
protected function _newInstance($className, Array $constructorParams)
{
if ($className === null) {
return null;
}
if (empty($constructorParams)) {
return new $className;
} else {
$reflection = new ReflectionClass($className);
return $reflection->newInstanceArgs($constructorParams);
}
}
protected function _parseIdentifier($identifier, &$module, &$class)
{
$offset = strpos($identifier, '/');
if ($offset === false) {
$module = $identifier;
$class = null;
return;
}
$module = substr($type, 0, $offset);
$class = substr($type, $offset + 1);
}
public function block($identifier)
{
$this->_parseIdentifier($identifier, $module, $class);
return $this->getBlock($module, $class);
}
public function model($identifier)
{
$this->_parseIdentifier($identifier, $module, $class);
return $this->getModel($module, $class);
}
public function resource($identifier)
{
$this->_parseIdentifier($identifier, $module, $class);
return $this->getResource($module, $class);
}
public function helper($identifier)
{
$this->_parseIdentifier($identifier, $module, $class);
if ($class === null) {
$class = 'data';
}
return $this->getResource($module, $class);
}
public function getBlock($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->blocks, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getModel($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->models, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getResource($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->resources, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getHelper($module, $class, Array $constructorParams = array())
{
$className = $this->_resolveClassType($this->_globalConfig->helpers, $module, $class);
return $this->_newInstance($className, $constructorParams);
}
public function getBlockSingleton($module, $class, Array $constructorParams = array())
{
}
public function getModelSingleton($module, $class, Array $constructorParams = array())
{
}
public function getResourceSingleton($module, $class, Array $constructorParams = array())
{
}
public function getHelperSingleton($module, $class, Array $constructorParams = array())
{
}
}

View file

@ -0,0 +1,14 @@
<?php
class Wootook_Core_Block_Concat
extends Wootook_Core_Mvc_View_View
{
public function render()
{
$content = '';
foreach ($this->_partials as $partial) {
$content .= $partial->render();
}
return $content;
}
}

View file

@ -0,0 +1,10 @@
<?php
class Wootook_Core_Block_Deprecated
extends Wootook_Core_Block_Template
{
public function getScriptPath()
{
return $this->getLayout()->getScriptPath();
}
}

View file

@ -0,0 +1,11 @@
<?php
class Wootook_Core_Block_Html_Form
extends Wootook_Core_Block_Template
{
public function getFormKey()
{
$session = Wootook::getSession('security');
return $session->getFormKey(true);
}
}

View file

@ -1,37 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block; class Wootook_Core_Block_Html_Head
extends Wootook_Core_Block_Template
class Head
extends Template
{ {
const TYPE_GLOBAL_CSS = 'global_css'; const TYPE_GLOBAL_CSS = 'global_css';
const TYPE_GLOBAL_JS = 'global_js'; const TYPE_GLOBAL_JS = 'global_js';
@ -314,4 +284,4 @@ HTML_EOF;
} }
return $render; return $render;
} }
} }

View file

@ -0,0 +1,22 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: Greg
* Date: 24/03/12
* Time: 10:51
* To change this template use File | Settings | File Templates.
*/
class Wootook_Core_Block_Html_Home
extends Wootook_Core_Block_Template
{
public function getTitle()
{
return Wootook::getGameConfig('game/home/title');
}
public function getFormatedWelcomeText()
{
return Wootook::getGameConfig('game/home/formated-welcome-text');
}
}

View file

@ -1,40 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html\Navigation; class Wootook_Core_Block_Html_Navigation
extends Wootook_Core_Block_Template
use Wootook\Core\Block,
Wootook\Core\Exception as CoreException;
class Menu
extends Block\Template
{ {
public function addLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array()) public function addLink($name, $label, $title, $uri, Array $params = array(), Array $classes = array(), $template = null, Array $attributes = array())
{ {
@ -148,8 +115,8 @@ class Menu
$this->setPartial($name, $child); $this->setPartial($name, $child);
} }
if ($child instanceof Link) { if ($child instanceof Wootook_Core_Block_Html_Navigation_Link) {
throw new CoreException\RuntimeException('Node is a link. Could not append a child node to a link node.'); throw new Wootook_Core_Exception_RuntimeException('Node is a link. Could not append a child node to a link node.');
} }
if (count($explodedPath) == 0) { if (count($explodedPath) == 0) {

View file

@ -1,39 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Block\Html\Navigation; class Wootook_Core_Block_Html_Navigation_Link
extends Wootook_Core_Block_Template
use Wootook\Core\Block;
class Link
extends Block\Template
{ {
protected $_label = ''; protected $_label = '';
protected $_title = ''; protected $_title = '';

View file

@ -0,0 +1,27 @@
<?php
class Wootook_Core_Block_Html_Navigation_Node
extends Wootook_Core_Block_Html_Navigation
{
protected $_title = '';
public function setTitle($title)
{
$this->_title = $title;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function getTemplate()
{
if ($this->_template !== null) {
return $this->_template;
}
return 'page/html/navigation/node.phtml';
}
}

View file

@ -0,0 +1,19 @@
<?php
class Wootook_Core_Block_Html_Page
extends Wootook_Core_Block_Template
{
protected $_bodyClasses = array();
public function getBodyClasses()
{
return implode(' ', $this->_bodyClasses);
}
public function addBodyClass($class)
{
$this->_bodyClasses[] = $class;
return $this;
}
}

View file

@ -0,0 +1,47 @@
<?php
class Wootook_Core_Block_Messages
extends Wootook_Core_Block_Template
{
protected $_storages = array();
public function prepareMessages($namespace)
{
$this->_storages[] = $namespace;
}
public function renderGroupedHtml()
{
$messages = array();
foreach ($this->_storages as $namespace) {
$session = Wootook::getSession($namespace);
$messageList = $session->getMessages();
if (!is_array($messageList)) {
continue;
}
foreach ($messageList as $messageLevel => $messageList) {
if (!isset($messages[$messageLevel])) {
$messages[$messageLevel] = $messageList;
} else {
$messages[$messageLevel] += $messageList;
}
}
}
rsort($messages, SORT_NUMERIC);
$output = '<div class="messages">';
foreach ($messages as $messageLevel => $messageList) {
$output .= "<ul class=\"{$messageLevel}\">";
foreach ($messageList as $message) {
$output .= "<li>{$message}</li>";
}
$output .= '</ul>';
}
$output .= '</div>';
return $output;
}
}

View file

@ -0,0 +1,46 @@
<?php
class Wootook_Core_Block_Template
extends Wootook_Core_Mvc_View_View
{
protected function _getTemplatePath($file)
{
if ($this->getScriptPath() == '') {
Wootook_Core_ErrorProfiler::getSingleton()
->addException(new Wootook_Core_Exception_RuntimeException("No script path defined in block {$this->getNameInLayout()}."));
return null;
}
$pattern = "{$this->getScriptPath()}/%s/%s/scripts/{$file}";
if (($layout = $this->getLayout()) !== null) {
$package = $this->getLayout()->getPackage();
$theme = $this->getLayout()->getTheme();
if ($package !== Wootook_Core_Model_Layout::DEFAULT_PACKAGE) {
if ($theme !== Wootook_Core_Model_Layout::DEFAULT_THEME) {
$path = sprintf($pattern, $package, $theme);
if (Wootook::fileExists($path)) {
return $path;
}
}
$path = sprintf($pattern, $package, Wootook_Core_Model_Layout::DEFAULT_THEME);
if (Wootook::fileExists($path)) {
return $path;
}
}
} else {
Wootook_Core_ErrorProfiler::getSingleton()
->addException(new Wootook_Core_Exception_RuntimeException("No layout defined."));
}
$path = sprintf($pattern, Wootook_Core_Model_Layout::DEFAULT_PACKAGE, Wootook_Core_Model_Layout::DEFAULT_THEME);
if (Wootook::fileExists($path)) {
return $path;
}
Wootook_Core_ErrorProfiler::getSingleton()
->addException(new Wootook_Core_Exception_RuntimeException("Template '{$file}' could not be found."));
return null;
}
}

View file

@ -0,0 +1,28 @@
<?php
class Wootook_Core_Block_Text
extends Wootook_Core_Mvc_View_View
{
protected $_content = null;
public function setContent($content)
{
$this->_content = $content;
return $this;
}
public function getContent()
{
return $this->_content;
}
public function render()
{
$content = $this->getContent();
if (empty($content)) {
return null;
}
return $content;
}
}

View file

@ -0,0 +1,6 @@
<?php
abstract class Wootook_Core_Config_Adapter_Adapter
extends Wootook_Core_Config_Node
{
}

View file

@ -0,0 +1,35 @@
<?php
class Wootook_Core_Config_Adapter_Array
extends Wootook_Core_Config_Adapter_Adapter
{
public function __construct($filename = null)
{
if ($filename !== null) {
$this->load($filename);
}
}
public function load($filename)
{
if (!file_exists($filename)) {
throw new Wootook_Core_Exception_DataAccessException(sprintf('Could not load config file "%s"', $filename));
}
$data = include $filename;
if (!is_array($data)) {
throw new Wootook_Core_Exception_DataAccessException('Configuration file could not be loaded.');
}
$this->_init($data);
return $this;
}
public function save($filename)
{
file_put_contents($filename, '<' . '?p' . 'hp return ' . var_export($this->toArray(), true) . ';');
return $this;
}
}

View file

@ -1,39 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Config; class Wootook_Core_Config_Node
implements ArrayAccess, Iterator, Countable
use Wootook\Core\Exception as CoreException;
class Node
implements \ArrayAccess, \Iterator, \Countable
{ {
protected $_children = array(); protected $_children = array();
@ -86,7 +54,7 @@ class Node
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {
if ($i < ($length - 1)) { if ($i < ($length - 1)) {
if (!$currentNode->offsetExists($explodedPath[$i])) { if (!$currentNode->offsetExists($explodedPath[$i])) {
$newNode = new Node(array(), $currentNode); $newNode = new Wootook_Core_Config_Node(array(), $currentNode);
$currentNode->offsetSet($explodedPath[$i], $newNode); $currentNode->offsetSet($explodedPath[$i], $newNode);
} }
} else if (is_array($value)) { } else if (is_array($value)) {
@ -99,8 +67,8 @@ class Node
$currentNode = $currentNode->offsetGet($explodedPath[$i]); $currentNode = $currentNode->offsetGet($explodedPath[$i]);
if (!$currentNode instanceof Node) { if (!$currentNode instanceof Wootook_Core_Config_Node) {
throw new CoreException\RuntimeException(); throw new Wootook_Core_Exception_RuntimeException();
} }
} }
@ -114,8 +82,8 @@ class Node
$length = count($explodedPath); $length = count($explodedPath);
$currentNode = $this; $currentNode = $this;
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {
if (!$currentNode instanceof Node) { if (!$currentNode instanceof Wootook_Core_Config_Node) {
throw new CoreException\RuntimeException(); throw new Wootook_Core_Exception_RuntimeException();
} }
if (!$currentNode->offsetExists($explodedPath[$i])) { if (!$currentNode->offsetExists($explodedPath[$i])) {
return null; return null;
@ -133,7 +101,7 @@ class Node
foreach ($this->_children as $key => $child) { foreach ($this->_children as $key => $child) {
if ($child instanceof self) { if ($child instanceof self) {
$result[$key] = $child->toArray(); $result[$key] = $child->toArray();
} else if ($child instanceof Leaf) { } else if ($child instanceof Wootook_Core_Config_Leaf) {
$result[$key] = $child->getValue(); $result[$key] = $child->getValue();
} else { } else {
$result[$key] = $child; $result[$key] = $child;
@ -247,31 +215,31 @@ class Node
} }
} }
public function valid()
{
return key($this->_children);
}
public function next()
{
next($this->_children);
}
public function current() public function current()
{ {
return current($this->_children); return current($this->_children);
} }
public function rewind()
{
reset($this->_children);
}
public function key() public function key()
{ {
return key($this->_children); return key($this->_children);
} }
public function next()
{
return next($this->_children);
}
public function rewind()
{
return reset($this->_children);
}
public function valid()
{
return key($this->_children) !== null;
}
public function count() public function count()
{ {
return count($this->_children); return count($this->_children);

View file

@ -0,0 +1,11 @@
<?php
class Wootook_Core_Controller_ErrorController
extends Wootook_Core_Mvc_Controller_Action
{
public function noRouteAction()
{
$this->loadLayout('no-route');
$this->renderLayout();
}
}

View file

@ -0,0 +1,11 @@
<?php
class Wootook_Core_Controller_IndexController
extends Wootook_Core_Mvc_Controller_Action
{
public function indexAction()
{
$this->loadLayout('home');
$this->renderLayout();
}
}

View file

@ -0,0 +1,199 @@
<?php
abstract class Wootook_Core_Database_Adapter_Adapter
{
protected $_handler = null;
protected $_tablePrefix = null;
public function getDriverHandler()
{
return $this->_handler;
}
public function getDataMapper()
{
return new Wootook_Core_Database_Orm_DataMapper();
}
/**
*
* @param string $prefix
* @return Wootook_Core_Database_Adapter_Pdo_Mysql
*/
public function setTablePrefix($prefix)
{
$this->_tablePrefix = $prefix;
return $this;
}
/**
* @return string
*/
public function getTablePrefix()
{
return $this->_tablePrefix;
}
/**
* @return string
*/
public function getTable($table)
{
return $this->getTablePrefix() . $table;
}
/**
* @return Wootook_Core_Database_Sql_Select
*/
public function select()
{
return new Wootook_Core_Database_Sql_Select($this);
}
/**
* @return Wootook_Core_Database_Sql_Insert
*/
public function insert()
{
return new Wootook_Core_Database_Sql_Insert($this);
}
/**
* @return Wootook_Core_Database_Sql_Update
*/
public function update()
{
return new Wootook_Core_Database_Sql_Update($this);
}
/**
* @return Wootook_Core_Database_Sql_Delete
*/
public function delete()
{
return new Wootook_Core_Database_Sql_Delete($this);
}
/**
* @param string $data
* @return string
*/
abstract public function quote($data);
/**
* @param string $identifier
* @return string
*/
abstract public function quoteIdentifier($identifier);
/**
* @param string $identifier
* @return string
*/
public function quoteInto($string, $values)
{
$parts = preg_split('#(:[\w_]+|[?])#', $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$result = '';
if (is_array($values)) {
$index = 0;
foreach ($parts as $part) {
if ($part == '?') {
$result .= $this->quote($values[$index++]);
} else if (!empty($part) && $part[0] == ':') {
$key = substr($part, 1);
if (isset($values[$key])) {
$result .= $this->quote($values[$key]);
} else if (isset($values[$part])) {
$result .= $this->quote($values[$part]);
} else {
$result .= $part;
}
} else {
$result .= $part;
}
}
} else {
foreach ($parts as $part) {
if ($part == '?' || $part[0] == ':') {
$result .= $this->quote($values);
} else {
$result .= $part;
}
}
}
return $result;
}
/**
* @return Wootook_Core_Database_Statement_Statement
*/
public function query($sql, Array $params = null)
{
$statement = $this->prepare($sql, $params);
if (!$statement->execute()) {
$message = sprintf('[SQLSTATE %s] Could not execute query: %s', $statement->errorState(), $statement->errorMessage());
throw new Wootook_Core_Exception_Database_StatementError($statement, $message);
}
return $statement;
}
/**
* @return bool
*/
public function execute($sql, Array $params = null)
{
$statement = $this->prepare($sql);
return $statement->execute($params);
}
/**
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function prepare($sql, Array $params = null);
/**
* @return bool
*/
abstract public function beginTransaction();
/**
* @return bool
*/
abstract public function commit();
/**
* @return bool
*/
abstract public function rollback();
/**
* @return bool
*/
abstract public function lastInsertId();
/**
* @return string
*/
abstract public function errorCode();
/**
* @return string
*/
abstract public function errorMessage();
/**
* @return array
*/
abstract public function errorInfo();
/**
* @return string
*/
abstract public function errorState();
}

View file

@ -0,0 +1,170 @@
<?php
class Wootook_Core_Database_Adapter_Pdo_Mysql
extends Wootook_Core_Database_Adapter_Adapter
{
/**
*
* Enter description here ...
* @param Wootook_Core_Config_Node $config
* @param array $params
*/
public function __construct(Wootook_Core_Config_Node $config, Array $options = array())
{
$dsn = "mysql:host={$config->hostname};dbname={$config->database}";
if (is_numeric($config->port)) {
$dsn .= ";port={$config->database}";
}
if (!isset($options[Wootook_Core_Database_ConnectionManager::ATTR_ERRMODE])) {
$options[Wootook_Core_Database_ConnectionManager::ATTR_ERRMODE] = Wootook_Core_Database_ConnectionManager::ERRMODE_EXCEPTION;
}
try {
$this->_handler = new PDO($dsn, $config->username, $config->password, $options);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
}
/**
* (non-PHPdoc)
* @see Wootook_Core_Database_Adapter_Adapter::quoteIdentifier()
*/
public function quoteIdentifier($identifier)
{
return "`$identifier`";
}
public function quote($data)
{
try {
return $this->_handler->quote($data);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return null;
}
/**
*
* @param string $name
* @return string
*/
public function getTable($name)
{
return $this->getTablePrefix() . $name;
}
/**
* @see Wootook_Core_Database_Adapter_Adapter::select()
*/
public function select($tableName = null)
{
return new Wootook_Core_Database_Sql_Mysql_Select($this, $tableName);
}
/**
* @return Wootook_Core_Database_Statement_Statement
*/
public function prepare($sql, Array $params = null)
{
$statement = new Wootook_Core_Database_Statement_Pdo_Mysql($this, $sql);
if ($params !== null) {
foreach ($params as $paramKey => $paramValue) {
$statement->bindValue($paramKey, $paramValue, $statement->getParamType($paramValue));
}
}
return $statement;
}
/**
* @return bool
*/
public function beginTransaction()
{
try {
return $this->_handler->beginTransaction();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return bool
*/
public function commit()
{
try {
return $this->_handler->commit();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return bool
*/
public function rollback()
{
try {
return $this->_handler->rollback();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return int
*/
public function lastInsertId()
{
try {
return $this->_handler->lastInsertId();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errorCode();
}
/**
* @return array
*/
public function errorInfo()
{
return $this->_handler->errorInfo();
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->errorInfo();
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->errorInfo();
return $info[0];
}
}

View file

@ -1,48 +1,9 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database; class Wootook_Core_Database_ConnectionManager
extends Wootook_Core_PluginLoader_PluginLoader
use Wootook\Core, implements Wootook_Core_Singleton
Wootook\Core\Base\Service,
Wootook\Core\Config,
Wootook\Core\Exception as CoreException,
Wootook\Core\PluginLoader,
Wootook\Core\Profiler;
class ConnectionManager
extends PluginLoader\PluginLoader
implements Core\Base\Singleton
{ {
use Service\App;
const PROFILER = 'profiler'; const PROFILER = 'profiler';
const CASE_FOLDING = 'case-folding'; const CASE_FOLDING = 'case-folding';
const AUTO_QUOTE_IDENTIFIERS = 'auto-quote-identifiers'; const AUTO_QUOTE_IDENTIFIERS = 'auto-quote-identifiers';
@ -138,20 +99,20 @@ class ConnectionManager
protected static $_singleton = null; protected static $_singleton = null;
protected function _construct() public function __construct()
{ {
$this->registerNamespace('Wootook\\Core\\Database\\Adapter'); $this->registerNamespace('Wootook_Core_Database_Adapter_');
} }
/** /**
* @return ConnectionManager * @return Wootook_Core_Database_ConnectionManager
*/ */
public static function getSingleton() public static function getSingleton()
{ {
Profiler\ErrorProfiler::getSingleton() if (self::$_singleton === null) {
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.')); self::$_singleton = new self();
}
return \Wootook::app()->getConnectionManager(); return self::$_singleton;
} }
protected $_defaultOptions = array( protected $_defaultOptions = array(
@ -160,7 +121,7 @@ class ConnectionManager
/** /**
* @param $connectionName * @param $connectionName
* @return Adapter\Adapter * @return Wootook_Core_Database_Adapter_Adapter
*/ */
public function getConnection($connectionName) public function getConnection($connectionName)
{ {
@ -173,7 +134,7 @@ class ConnectionManager
return $this->_connectionAliases[$connectionName]; return $this->_connectionAliases[$connectionName];
} }
$connectionConfig = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}"); $connectionConfig = Wootook::getConfig("resource/database/{$connectionName}");
if ($connectionConfig === null) { if ($connectionConfig === null) {
return null; return null;
} }
@ -193,12 +154,12 @@ class ConnectionManager
private function _initConnection($connectionName, $engine, $params, $options = array()) private function _initConnection($connectionName, $engine, $params, $options = array())
{ {
if (is_array($params)) { if (is_array($params)) {
$params = new Config\Node($params); $params = new Wootook_Core_Config_Node($params);
} else if (!$params instanceof Config\Node) { } else if (!$params instanceof Wootook_Core_Config_Node) {
$params = new Config\Node(array()); $params = new Wootook_Core_Config_Node(array());
} }
if ($options instanceof Config\Node) { if ($options instanceof Wootook_Core_Config_Node) {
$options = $options->toArray(); $options = $options->toArray();
} else if (!is_array($options)) { } else if (!is_array($options)) {
$options = array(); $options = array();
@ -208,28 +169,24 @@ class ConnectionManager
return null; return null;
} }
$event = \Wootook::dispatchEvent('database.prepare-options', array( $event = Wootook::dispatchEvent('database.prepare-options', array(
'name' => $connectionName, 'name' => $connectionName,
'options' => array_merge($this->_defaultOptions, $options) 'options' => array_merge($this->_defaultOptions, $options)
)); ));
$options = $event->getData('options'); $options = $event->getData('options');
try { $connection = $this->load($engine, false, array($params, $options));
$connection = $this->load($engine, false, array($params, $options));
} catch (CoreException\Database\AdapterError $e) {
Profiler\ErrorProfiler::getSingleton()->addException($e);
return null;
}
if (!$connection) { if (!$connection) {
throw new CoreException\DataAccessException('Could not find data connection handler.'); throw new Wootook_Core_Exception_Database_AdapterError('Could not find data connection handler.');
} }
if (($prefix = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}/table_prefix")) !== null) { if (($prefix = Wootook::getConfig("resource/database/{$connectionName}/table_prefix")) !== null) {
$connection->setTablePrefix($prefix); $connection->setTablePrefix($prefix);
} }
\Wootook::dispatchEvent('database.init', array( Wootook::dispatchEvent('database.init', array(
'name' => $connectionName, 'name' => $connectionName,
'handler' => $connection 'handler' => $connection
)); ));
@ -239,7 +196,7 @@ class ConnectionManager
protected function _load($className, $useSingleton, Array $constructorParams = array()) protected function _load($className, $useSingleton, Array $constructorParams = array())
{ {
$reflection = new \ReflectionClass($className); $reflection = new ReflectionClass($className);
return $reflection->newInstanceArgs($constructorParams); return $reflection->newInstanceArgs($constructorParams);
} }
} }

View file

@ -1,43 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Orm; class Wootook_Core_Database_Orm_DataMapper
extends Wootook_Core_PluginLoader_PluginLoader
use Wootook\Core\Config,
Wootook\Core\Database,
Wootook\Core\Mvc\Model,
Wootook\Core\PluginLoader,
Wootook\Core\Profiler;
class DataMapper
extends PluginLoader\PluginLoader
{ {
protected $_rules = array(); protected $_rules = array();
@ -45,9 +9,9 @@ class DataMapper
public function __construct($config = array()) public function __construct($config = array())
{ {
$this->registerNamespace('Wootook\\Core\\Database\\Orm\\DataMapper'); $this->registerNamespace('Wootook_Core_Database_Orm_DataMapper_');
if (!is_array($config) || !$config instanceof Config\Node) { if (!is_array($config) || !$config instanceof Wootook_Core_Config_Node) {
return; return;
} }
@ -89,16 +53,16 @@ class DataMapper
protected function _load($className, $useSingleton, Array $constructorParams = array()) protected function _load($className, $useSingleton, Array $constructorParams = array())
{ {
$reflection = new \ReflectionClass($className); $reflection = new ReflectionClass($className);
if ($useSingleton && $reflection->implementsInterface('Wootook\\Core\\Base\\Singleton')) { if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) {
$method = $reflection->getMethod('getSingleton'); $method = $reflection->getMethod('getSingleton');
return $method->invoke(null); return $method->invoke(null);
} }
try { try {
return $reflection->newInstance($this); return $reflection->newInstance($this);
} catch (\ReflectionException $e) { } catch (ReflectionException $e) {
Profiler\ErrorProfiler::getSingleton() Wootook_Core_ErrorProfiler::getSingleton()
->addException($e); ->addException($e);
return null; return null;
} }
@ -106,11 +70,11 @@ class DataMapper
/** /**
* *
* @param Database\Resource $entity * @param Wootook_Core_Database_Resource $entity
* @param Array $datas * @param Array $datas
* @return Array * @return Array
*/ */
public function encode(Model\Entity $entity, Array $datas = array()) public function encode(Wootook_Core_Database_Resource $entity, Array $datas = array())
{ {
$aliasTable = array_flip($this->_alias); $aliasTable = array_flip($this->_alias);
foreach ($entity->getAllDatas() as $aliasedField => $decodedValue) { foreach ($entity->getAllDatas() as $aliasedField => $decodedValue) {
@ -132,11 +96,11 @@ class DataMapper
/** /**
* *
* @param Database\Resource $entity * @param Wootook_Core_Database_Resource $entity
* @param Array $datas * @param Array $datas
* @return Database\Resource * @return Wootook_Core_Database_Resource
*/ */
public function decode(Model\Entity $entity, Array $datas = array()) public function decode(Wootook_Core_Database_Resource $entity, Array $datas = array())
{ {
foreach ($datas as $field => $encodedValue) { foreach ($datas as $field => $encodedValue) {
if (isset($this->_rules[$field])) { if (isset($this->_rules[$field])) {
@ -148,4 +112,4 @@ class DataMapper
return $entity; return $entity;
} }
} }

View file

@ -0,0 +1,15 @@
<?php
class Wootook_Core_Database_Orm_DataMapper_Array
extends Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
public function encode($value)
{
return serialize($value);
}
public function decode($value)
{
return unserialize($value);
}
}

View file

@ -0,0 +1,15 @@
<?php
class Wootook_Core_Database_Orm_DataMapper_Config
extends Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
public function encode($value)
{
return parent::encode($value->toArray());
}
public function decode($value)
{
return new Wootook_Core_Config_Node(parent::decode($value));
}
}

View file

@ -0,0 +1,38 @@
<?php
class Wootook_Core_Database_Orm_DataMapper_DateTime
extends Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
const DATE_FORMAT_MYSQL = 'Y-m-d G:i:s';
protected $_format = self::DATE_FORMAT_MYSQL;
public function setFormat($format = null)
{
if ($format === null) {
$this->_format = self::DATE_FORMAT_MYSQL;
} else {
$this->_format = $format;
}
return $this;
}
public function getFormat()
{
return $this->_format;
}
public function encode($value)
{
if (!$value instanceof Wootook_Core_DateTime) {
$value = new Wootook_Core_DateTime($value);
}
return $value->toString($this->getFormat());
}
public function decode($value)
{
return new Wootook_Core_DateTime($value, $this->getFormat());
}
}

View file

@ -0,0 +1,15 @@
<?php
abstract class Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
protected $_mapper = null;
public function __construct(Wootook_Core_Database_Orm_DataMapper $mapper = null)
{
$this->_mapper = $mapper;
}
abstract public function encode($value);
abstract public function decode($value);
}

View file

@ -0,0 +1,43 @@
<?php
class Wootook_Core_Database_Orm_DataMapper_Object
extends Wootook_Core_Database_Orm_DataMapper_FieldMapper
{
protected $_entityClass = null;
protected $_reflectionClass = null;
public function setEntityClass($class)
{
$this->_entityClass = $class;
return $this;
}
public function getEntityClass()
{
return $this->_entityClass;
}
protected function _newInstance(Array $args = array())
{
if ($this->_reflectionClass === null && $this->_entityClass !== null) {
$this->_reflectionClass = new ReflectionClass($this->_entityClass);
}
return $this->newInstanceArgs($args);
}
public function encode($value)
{
return parent::encode($value->getAllDatas());
}
public function decode($value)
{
$object = $this->_newInstance();
$object->addData(parent::decode($value));
return $object;
}
}

View file

@ -0,0 +1,89 @@
<?php
abstract class Wootook_Core_Database_Resource
extends Wootook_Core_Mvc_Model_Model
{
protected $_readConnection = null;
protected $_writeConnection = null;
protected $_tableName = null;
protected $_dataMapper = null;
/**
*
* @return Wootook_Core_Database_Orm_DataMapper
*/
public function getDataMapper()
{
if ($this->_dataMapper === null) {
$this->_dataMapper = new Wootook_Core_Database_Orm_DataMapper();
}
return $this->_dataMapper;
}
public function setTableName($tableName)
{
$this->_tableName = $tableName;
return $this;
}
public function getTableName()
{
return $this->_tableName;
}
/**
* @return Wootook_Core_Database_Adapter_Adapter
*/
public function getReadConnection()
{
if ($this->_readConnection === null) {
$this->_readConnection = Wootook_Core_Database_ConnectionManager::getSingleton()
->getConnection('core_read');
}
return $this->_readConnection;
}
public function setReadConnection($connection)
{
if ($connection instanceof Wootook_Core_Database_Adapter_Pdo_Mysql) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = $this->getConnection($connection);
} else {
throw new Wootook_Core_Exception_RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
/**
* @return Wootook_Core_Database_Adapter_Adapter
*/
public function getWriteConnection()
{
if ($this->_writeConnection === null) {
$this->_writeConnection = Wootook_Core_Database_ConnectionManager::getSingleton()
->getConnection('core_write');
}
return $this->_writeConnection;
}
public function setWriteConnection($connection)
{
if ($connection instanceof Wootook_Core_Database_Adapter_Pdo_Mysql) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = $this->getConnection($connection);
} else {
throw new Wootook_Core_Exception_RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
}

View file

@ -1,37 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml; class Wootook_Core_Database_Sql_Delete
extends Wootook_Core_Database_Sql_DmlFilterableQuery
class Delete
extends DmlQuery
{ {
const FROM = 'FROM'; const FROM = 'FROM';

View file

@ -0,0 +1,24 @@
<?php
interface Wootook_Core_Database_Sql_Dml
{
function __construct(Wootook_Core_Database_Adapter_Adapter $connection, $param = null);
function render();
function toString($part = null);
function getPart($part = null);
function reset($part = null);
function quote($data);
function quoteIdentifier($identifier);
function setConnection(Wootook_Core_Database_Adapter_Adapter $connection);
function getConnection();
function beforePrepare(Wootook_Core_Database_Statement_Statement $statement);
function afterPrepare(Wootook_Core_Database_Statement_Statement $statement);
function beforeExecute(Wootook_Core_Database_Statement_Statement $statement);
function afterExecute(Wootook_Core_Database_Statement_Statement $statement);
}

View file

@ -1,45 +1,31 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml\Section\Renderer; abstract class Wootook_Core_Database_Sql_DmlFilterableQuery
extends Wootook_Core_Database_Sql_DmlQuery
use Wootook\Core,
Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql\Placeholder;
trait Where
{ {
const WHERE = 'WHERE';
const LIMIT = 'LIMIT';
const OFFSET = 'OFFSET';
const OPERATOR_AND = 'AND';
const OPERATOR_OR = 'OR';
const OPERATOR_XOR = 'XOR';
const OPERATOR_EQUALS = 'EQ';
const OPERATOR_NOT_EQUALS = 'NEQ';
const OPERATOR_LOWER = 'LT';
const OPERATOR_GREATER = 'GT';
const OPERATOR_LOWER_EQUALS = 'LTEQ';
const OPERATOR_GREATER_EQUALS = 'GTEQ';
const OPERATOR_IS_NULL = 'NULL';
const OPERATOR_IN = 'IN';
const OPERATOR_NOT_IN = 'NIN';
const OPERATOR_FIND_IN_SET = 'FINSET';
const OPERATOR_NOT_FIND_IN_SET = 'NFINSET';
const OPERATOR_DATE = 'DATE';
public function where($condition, $value = null) public function where($condition, $value = null)
{ {
if ($condition instanceof Placeholder\Placeholder) { if ($condition instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_placeholders[] = $condition; $this->_placeholders[] = $condition;
$this->_parts[self::WHERE][] = $condition; $this->_parts[self::WHERE][] = $condition;
} else if (is_array($value)) { } else if (is_array($value)) {
@ -47,7 +33,7 @@ trait Where
if ($where !== null) { if ($where !== null) {
$this->_parts[self::WHERE][] = $where; $this->_parts[self::WHERE][] = $where;
} }
} else if ($value instanceof Placeholder\Placeholder) { } else if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_parts[self::WHERE][] = "{$this->getConnection()->quoteIdentifier($condition)}=" . $value; $this->_parts[self::WHERE][] = "{$this->getConnection()->quoteIdentifier($condition)}=" . $value;
} else { } else {
$this->_parts[self::WHERE][] = $this->getConnection()->quoteInto("{$this->getConnection()->quoteIdentifier($condition)}=?", $value); $this->_parts[self::WHERE][] = $this->getConnection()->quoteInto("{$this->getConnection()->quoteIdentifier($condition)}=?", $value);
@ -56,6 +42,14 @@ trait Where
return $this; return $this;
} }
public function limit($limit, $offset = null)
{
$this->_parts[self::LIMIT] = intval($limit);
$this->_parts[self::OFFSET] = intval($offset);
return $this;
}
public function renderWhere() public function renderWhere()
{ {
if (count($this->_parts[self::WHERE]) <= 0) { if (count($this->_parts[self::WHERE]) <= 0) {
@ -65,6 +59,17 @@ trait Where
return " WHERE (" . implode(")\n AND (", $this->_parts[self::WHERE]) . ')'; return " WHERE (" . implode(")\n AND (", $this->_parts[self::WHERE]) . ')';
} }
public function renderLimit()
{
if (!$this->_parts[self::LIMIT]) {
return '';
}
if (!$this->_parts[self::OFFSET]) {
return sprintf(" LIMIT %d", $this->_parts[self::LIMIT]);
}
return sprintf(" LIMIT %d,%d", $this->_parts[self::LIMIT], $this->_parts[self::OFFSET]);
}
protected function _translateSqlWhere($field, $operator, $value) protected function _translateSqlWhere($field, $operator, $value)
{ {
if ($value === null) { if ($value === null) {
@ -89,7 +94,7 @@ trait Where
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE"; return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE";
} else if (is_numeric($value)) { } else if (is_numeric($value)) {
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value); return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%d", $value);
} else if ($value instanceof Placeholder\Placeholder) { } else if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_placeholders[] = $value; $this->_placeholders[] = $value;
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString())); return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString()));
} else { } else {
@ -177,7 +182,7 @@ trait Where
case self::OPERATOR_DATE: case self::OPERATOR_DATE:
$dateValues = array(); $dateValues = array();
if (isset($value['from'])) { if (isset($value['from'])) {
if ($value['from'] instanceof Core\DateTime) { if ($value['from'] instanceof Wootook_Core_DateTime) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['from']))}"; $dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['from']))}";
} else if (is_string($value['from'])) { } else if (is_string($value['from'])) {
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}"; $dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}";
@ -186,7 +191,7 @@ trait Where
} }
} }
if (isset($value['to'])) { if (isset($value['to'])) {
if ($value['to'] instanceof Core\DateTime) { if ($value['to'] instanceof Wootook_Core_DateTime) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['to']))}"; $dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($this->getConnection()->getDataMapper()->load('DateTime')->encode($value['to']))}";
} else if (is_string($value['to'])) { } else if (is_string($value['to'])) {
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}"; $dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}";

View file

@ -0,0 +1,107 @@
<?php
abstract class Wootook_Core_Database_Sql_DmlQuery
implements Wootook_Core_Database_Sql_Dml
{
protected $_parts = array();
protected $_connection = null;
protected $_placeholders = array();
public function __construct(Wootook_Core_Database_Adapter_Adapter $connection, $tableName = null)
{
$this->setConnection($connection);
$this->reset();
$this->_init($tableName);
}
/**
* @return Wootook_Core_Database_Adapter_Adapter
*/
public function getConnection()
{
return $this->_connection;
}
public function setConnection(Wootook_Core_Database_Adapter_Adapter $connection)
{
$this->_connection = $connection;
return $this;
}
protected function _init($param = null)
{
return $this;
}
public function getPart($part = null)
{
if ($part === null) {
return $this->_parts;
}
if (isset($this->_parts[$part])) {
return $this->_parts[$part];
}
return null;
}
public function quote($data)
{
return $this->getConnection()->quote($data);
}
public function quoteIdentifier($identifier)
{
return $this->getConnection()->quoteIdentifier($identifier);
}
public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->beforePrepare($statement);
}
return $this;
}
public function afterPrepare(Wootook_Core_Database_Statement_Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->afterPrepare($statement);
}
return $this;
}
public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->beforeExecute($statement);
}
return $this;
}
public function afterExecute(Wootook_Core_Database_Statement_Statement $statement)
{
foreach ($this->_placeholders as $placeholder) {
$placeholder->afterExecute($statement);
}
return $this;
}
public function prepare()
{
return $this->getConnection()->prepare($this);
}
public function execute(Array $params = null)
{
return $this->getConnection()->execute($this, $params);
}
}

View file

@ -1,39 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml; class Wootook_Core_Database_Sql_Insert
extends Wootook_Core_Database_Sql_DmlQuery
use Wootook\Core\Database\Sql\Placeholder;
class Insert
extends DmlQuery
{ {
const SET = 'SET'; const SET = 'SET';
const INTO = 'INTO'; const INTO = 'INTO';
@ -72,7 +40,7 @@ class Insert
} }
foreach ($column as $field => $value) { foreach ($column as $field => $value) {
if ($value instanceof Placeholder\Placeholder) { if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_placeholders[] = $value; $this->_placeholders[] = $value;
} }
@ -134,7 +102,7 @@ class Insert
{ {
$fields = array(); $fields = array();
foreach ($this->_parts[self::SET] as $field) { foreach ($this->_parts[self::SET] as $field) {
if ($field['value'] instanceof Placeholder\Placeholder) { if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}"; $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}";
} else { } else {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}"; $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";

View file

@ -0,0 +1,6 @@
<?php
class Wootook_Core_Database_Sql_Mysql_Select
extends Wootook_Core_Database_Sql_Select
{
}

View file

@ -0,0 +1,30 @@
<?php
class Wootook_Core_Database_Sql_Placeholder_Expression
extends Wootook_Core_Database_Sql_Placeholder_Placeholder
{
protected $_expression = null;
protected $_params = array();
public function __construct($expression, Array $params = array())
{
$this->_expression = (string) $expression;
$this->_params = $params;
}
public function __toString()
{
return $this->_expression;
}
public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement)
{
parent::beforeExecute($statement);
foreach ($this->_params as $paramName => $value) {
$statement->bindValue($paramName, $value, $statement->getParamType($value));
}
return $this;
}
}

View file

@ -0,0 +1,31 @@
<?php
class Wootook_Core_Database_Sql_Placeholder_Param
extends Wootook_Core_Database_Sql_Placeholder_Placeholder
{
protected $_paramType = null;
protected $_paramName = null;
protected $_value = null;
public function __construct($paramName, $value, $type = null)
{
$this->_paramName = $paramName;
$this->_paramType = $type;
$this->_value = $value;
}
public function __toString()
{
return ':' . $this->_paramName;
}
public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement)
{
parent::beforeExecute($statement);
$type = $this->_paramType !== null ? $this->_paramType : $statement->getParamType($this->_value);
$statement->bindValue($this->_paramName, $this->_value, $type);
return $this;
}
}

View file

@ -0,0 +1,31 @@
<?php
abstract class Wootook_Core_Database_Sql_Placeholder_Placeholder
{
public function toString()
{
return $this->__toString();
}
abstract public function __toString();
public function beforePrepare(Wootook_Core_Database_Statement_Statement $statement)
{
return $this;
}
public function afterPrepare(Wootook_Core_Database_Statement_Statement $statement)
{
return $this;
}
public function beforeExecute(Wootook_Core_Database_Statement_Statement $statement)
{
return $this;
}
public function afterExecute(Wootook_Core_Database_Statement_Statement $statement)
{
return $this;
}
}

View file

@ -0,0 +1,20 @@
<?php
class Wootook_Core_Database_Sql_Placeholder_Variable
extends Wootook_Core_Database_Sql_Placeholder_Placeholder
{
protected $_paramType = null;
protected $_paramName = null;
protected $_value = null;
public function __construct($paramName, $type = null)
{
$this->_paramName = $paramName;
$this->_paramType = $type;
}
public function __toString()
{
return ':' . $this->_paramName;
}
}

View file

@ -1,44 +1,10 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml; class Wootook_Core_Database_Sql_Select
extends Wootook_Core_Database_Sql_DmlFilterableQuery
use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder;
class Select
extends DmlQuery
{ {
use Section\Where, Section\Limit;
const COLUMNS = 'COLUMNS'; const COLUMNS = 'COLUMNS';
const FROM = 'FROM';
const JOIN = 'JOIN'; const JOIN = 'JOIN';
const ORDER = 'ORDER'; const ORDER = 'ORDER';
const UNION = 'UNION'; const UNION = 'UNION';
@ -102,7 +68,7 @@ class Select
} }
} }
} else { } else {
if ($column instanceof Placeholder\Placeholder) { if ($column instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_placeholders[] = $column; $this->_placeholders[] = $column;
} }
@ -245,13 +211,13 @@ class Select
{ {
$fields = array(); $fields = array();
foreach ($this->_parts[self::COLUMNS] as $field) { foreach ($this->_parts[self::COLUMNS] as $field) {
if ($field['field'] instanceof Dml) { if ($field['field'] instanceof Wootook_Core_Database_Sql_Dml) {
if ($field['alias'] !== null) { if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}"; $fields[] = "({$field['field']}) AS {$field['alias']}";
} else { } else {
$fields[] = "({$field['field']})"; $fields[] = "({$field['field']})";
} }
} else if ($field['field'] instanceof Placeholder\Placeholder) { } else if ($field['field'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
if ($field['alias'] !== null) { if ($field['alias'] !== null) {
$fields[] = "({$field['field']}) AS {$field['alias']}"; $fields[] = "({$field['field']}) AS {$field['alias']}";
} else { } else {
@ -280,7 +246,7 @@ class Select
{ {
$tables = array(); $tables = array();
foreach ($this->_parts[self::FROM] as $table) { foreach ($this->_parts[self::FROM] as $table) {
if ($table['table'] instanceof Dml) { if ($table['table'] instanceof Wootook_Core_Database_Sql_Dml) {
if ($table['alias'] !== null) { if ($table['alias'] !== null) {
$tables[] = "({$table['table']}) AS {$this->_connection->quoteIdentifier($table['alias'])}"; $tables[] = "({$table['table']}) AS {$this->_connection->quoteIdentifier($table['alias'])}";
} else { } else {

View file

@ -1,43 +1,10 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Database\Sql\Dml; class Wootook_Core_Database_Sql_Update
extends Wootook_Core_Database_Sql_DmlFilterableQuery
use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder;
class Update
extends DmlQuery
implements Section\IntoAware, Section\LimitAware, Section\SetAware
{ {
use Section\Set, Section\Into, Section\Where, Section\Limit; const SET = 'SET';
const INTO = 'INTO';
protected function _init($tableName = null) protected function _init($tableName = null)
{ {
@ -67,6 +34,36 @@ class Update
return $this; return $this;
} }
public function set($column, $value = null)
{
if (!is_array($column)) {
$column = array($column => $value);
}
foreach ($column as $field => $value) {
if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$this->_placeholders[] = $value;
}
$this->_parts[self::SET][] = array(
'value' => $value,
'field' => $field
);
}
return $this;
}
public function into($table, $schema = null)
{
$this->_parts[self::INTO] = array(
'table' => $table,
'schema' => $schema,
);
return $this;
}
public function __toString() public function __toString()
{ {
return $this->render(); return $this->render();
@ -94,7 +91,7 @@ class Update
{ {
$fields = array(); $fields = array();
foreach ($this->_parts[self::SET] as $field) { foreach ($this->_parts[self::SET] as $field) {
if ($field['value'] instanceof Placeholder\Placeholder) { if ($field['value'] instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}"; $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$field['value']->toString()}";
} else { } else {
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}"; $fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";

View file

@ -0,0 +1,321 @@
<?php
class Wootook_Core_Database_Statement_Pdo_Mysql
extends Wootook_Core_Database_Statement_Statement
{
/**
* @var PDOStatement
*/
protected $_handler = null;
protected $_query = null;
protected function _init($query)
{
$this->_query = $query;
if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) {
$this->_query->beforePrepare($this);
}
try {
$this->_handler = $this->_adapter->getDriverHandler()->prepare($this->_query);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) {
$this->_query->afterPrepare($this);
}
return $this;
}
/**
*
* @param string|int $column
* @param mixed $param
* @param int $type
* @return Wootook_Core_Database_Statement_Statement
*/
public function bindColumn($column, &$param, $type = null)
{
try {
return $this->_handler->bindColumn($column, $param, $type);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
*
* @param string|int $parameter
* @param mixed $variable
* @param int $type
* @param int $length
* @param unknown_type $options
* @return Wootook_Core_Database_Statement_Statement
*/
public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
try {
return $this->_handler->bindParam($parameter, $variable, $type, $length, $options);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
*
* @param string|int $parameter
* @param mixed $value
* @param int $type
* @return Wootook_Core_Database_Statement_Statement
*/
public function bindValue($parameter, $value, $type = null)
{
try {
return $this->_handler->bindValue($parameter, $value, $type);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
*
* @param array $params
* @return bool
*/
public function execute(Array $params = null)
{
if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) {
$this->_query->beforeExecute($this);
}
try {
$result = $this->_handler->execute($params);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
if ($this->_query instanceof Wootook_Core_Database_Sql_Dml) {
$this->_query->afterExecute($this);
}
return $result;
}
/**
*
* @param int $style
* @param int $col
* @return mixed
*/
public function fetchAll($style = null, $col = null)
{
try {
if ($style !== null) {
if ($col !== null) {
$result = $this->_handler->fetchAll($style, $col);
} else {
$result = $this->_handler->fetchAll($style);
}
} else {
$result = $this->_handler->fetchAll($style);
}
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return $result;
}
/**
*
* @param int $col
* @return mixed
*/
public function fetchColumn($col = 0)
{
try {
return $this->_handler->fetchColumn($col);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return null;
}
/**
*
* @return Wootook_Core_Database_Adapter_Adapter
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
*
* @param string $key
*/
public function getAttribute($key)
{
try {
return $this->_handler->getAttribute($key);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return null;
}
/**
*
* @param string $key
* @param mixed $value
* @return Wootook_Core_Database_Statement_Statement
*/
public function setAttribute($key, $value)
{
try {
return $this->_handler->setAttribute($key, $value);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @param unknown_type $mode
* @return Wootook_Core_Database_Statement_Statement
*/
public function setFetchMode($mode)
{
try {
$params = func_get_args();
return call_user_func_array($array($this->_handler, 'setFetchMode'), $params);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return int
*/
public function columnCount()
{
try {
return $this->_handler->columnCount();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return 0;
}
/**
* @return int
*/
public function rowCount()
{
try {
return $this->_handler->rowCount();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return 0;
}
/**
* @param int $col
* @return mixed
*/
public function fetch($style = null, $orientation = Wootook_Core_Database_ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0)
{
try {
return $this->_handler->fetch($style, $orientation, $cursorOffset);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return null;
}
/**
* @param string $class
* @param array $config
* @return Wootook_Object
*/
public function fetchObject($class = 'Wootook_Object', Array $constructorArgs = array())
{
try {
return $this->_handler->fetchObject($class, $constructorArgs);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_StatementError($this, $e->getMessage(), null, $e);
}
return null;
}
/**
* @return bool
*/
public function closeCursor()
{
try {
return $this->_handler->closeCursor();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return bool
*/
public function nextRowset()
{
try {
return $this->_handler->nextRowset();
} catch (PDOException $e) {
throw new Wootook_Core_Exception_Database_AdapterError($this, $e->getMessage(), null, $e);
}
return false;
}
/**
* @return string
*/
public function errorCode()
{
return $this->_handler->errorCode();
}
/**
* @return array
*/
public function errorInfo()
{
return $this->_handler->errorInfo();
}
/**
* @return string
*/
public function errorMessage()
{
$info = $this->_handler->errorInfo();
return $info[2];
}
/**
* @return string
*/
public function errorState()
{
$info = $this->_handler->errorInfo();
return $info[0];
}
}

View file

@ -0,0 +1,215 @@
<?php
abstract class Wootook_Core_Database_Statement_Statement
implements Iterator
{
protected $_adapter = null;
protected $_currentIndex = 0;
protected $_currentRow = null;
public function __construct(Wootook_Core_Database_Adapter_Adapter $adapter, $sql)
{
$this->_adapter = $adapter;
$this->_init($sql);
}
abstract protected function _init($sql);
/**
*
* @param string|int $column
* @param mixed $param
* @param int $type
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function bindColumn($column, &$param, $type = null);
/**
*
* @param string|int $parameter
* @param mixed $variable
* @param int $type
* @param int $length
* @param unknown_type $options
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null);
/**
*
* @param string|int $parameter
* @param mixed $value
* @param int $type
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function bindValue($parameter, $value, $type = null);
/**
*
* @param array $params
* @return bool
*/
abstract public function execute(Array $params = null);
/**
*
* @param int $style
* @param int $col
* @return mixed
*/
abstract public function fetch($style = null, $orientation = Wootook_Core_Database_ConnectionManager::FETCH_ORI_NEXT, $cursorOffset = 0);
/**
*
* @param int $style
* @param int $col
* @return mixed
*/
abstract public function fetchAll($style = null, $col = null);
/**
*
* @param int $col
* @return mixed
*/
abstract public function fetchColumn($col = 0);
/**
*
* @param string $class
* @param array $config
* @return Wootook_Object
*/
abstract public function fetchObject($class = 'Wootook_Object', Array $constructorArgs = array());
/**
*
* @param string $class
* @param array $config
* @return Wootook_Object
*/
public function fetchEntity($class = 'Wootook_Core_Mvc_Model_Entity', Array $constructorArgs = array())
{
$reflection = new ReflectionClass($class);
$object = $reflection->newInstanceArgs($constructorArgs);
if (!$object instanceof Wootook_Object) {
throw new Wootook_Core_Exception_Database_StatementError($this, 'Destination object should be a Wootook_Core_Mvc_Model_Entity instance.');
}
$data = $this->fetch(Wootook_Core_Database_ConnectionManager::FETCH_ASSOC);
if ($data !== false) {
$object->getDataMapper()->decode($object, $data);
}
return $object;
}
/**
*
* @return Wootook_Core_Database_Adapter_Adapter
*/
abstract public function getAdapter();
/**
*
* @param string $key
*/
abstract public function getAttribute($key);
/**
*
* @param string $key
* @param mixed $value
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function setAttribute($key, $value);
/**
* @param unknown_type $mode
* @return Wootook_Core_Database_Statement_Statement
*/
abstract public function setFetchMode($mode);
/**
* @return int
*/
abstract public function columnCount();
/**
* @return string
*/
abstract public function errorCode();
/**
* @return string
*/
abstract public function errorMessage();
/**
* @return array
*/
abstract public function errorInfo();
/**
* @return string
*/
abstract public function errorState();
/**
* @return int
*/
abstract public function rowCount();
/**
* @return bool
*/
abstract public function closeCursor();
/**
* @return bool
*/
abstract public function nextRowset();
public function getParamType($value)
{
if (is_numeric($value)) {
return Wootook_Core_Database_ConnectionManager::PARAM_INT;
} else if (is_bool($value)) {
return Wootook_Core_Database_ConnectionManager::PARAM_BOOL;
} else if (is_string($value)) {
return Wootook_Core_Database_ConnectionManager::PARAM_STR;
}
return null;
}
public function current()
{
return $this->_currentRow;
}
public function next()
{
$this->_currentRow = $this->fetch();
$this->_currentIndex++;
}
public function key()
{
return $this->_currentIndex;
}
public function rewind()
{
return $this->_currentIndex;
}
public function valid()
{
$rows = $this->rowCount();
return $rows > 0 && $this->_currentIndex <= $rows;
}
}

View file

@ -1,40 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\DateTime;
/** class Wootook_Core_DateTime
* Date and time management class
* @todo : refactor to be compatible with \DateTime
*/
class DateTime
{ {
const ISO_8601 = 'c'; const ISO_8601 = 'c';
@ -104,18 +71,16 @@ class DateTime
protected $_datetime = null; protected $_datetime = null;
protected $_timezone = null;
public static function init($timezone = null, $force = false) public static function init($timezone = null, $force = false)
{ {
static $init = false; static $init = false;
if ($init === false || $force === true) { if ($init === false || $force === true) {
if ($timezone === null) { if ($timezone === null) {
//$timezone = \Wootook::app()->getGlobalConfig('system/date/timezone'); //$timezone = Wootook::getConfig('system/date/timezone');
} }
if ($timezone === null) { if ($timezone === null) {
$timezone = 'UTC'; $timezone = 'GMT';
} }
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
@ -123,11 +88,7 @@ class DateTime
} }
} }
/** public function __construct($timestamp = null, $format = null)
* @param null|string|int $timestamp
* @param string $format
*/
public function __construct($timestamp = null, $format = null, $timezone = 'UTC')
{ {
self::init(); self::init();
@ -138,8 +99,6 @@ class DateTime
} else { } else {
$this->_datetime = $this->_parse($timestamp, $format); $this->_datetime = $this->_parse($timestamp, $format);
} }
$this->_timezone = $timezone;
} }
public function getIso($useTimezone = false) public function getIso($useTimezone = false)
@ -263,12 +222,18 @@ class DateTime
protected function _parseShortMonth($match) protected function _parseShortMonth($match)
{ {
return 1 + array_search(strtolower($match), array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec')); if ($key = array_search(strtolower($match), array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'))) {
return $key + 1;
}
return false;
} }
protected function _parseShortWeekday($match) protected function _parseShortWeekday($match)
{ {
return array_search(strtolower($match), array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')); if ($key = array_search(strtolower($match), array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'))) {
return $key;
}
return false;
} }
protected function _parseWeekday($match) protected function _parseWeekday($match)
@ -278,7 +243,10 @@ class DateTime
protected function _parseMeridiem($match) protected function _parseMeridiem($match)
{ {
return strtolower($match); if (in_array(strtolower($match), array(self::MERIDIEM_AM, self::MERIDIEM_PM))) {
return strtolower($match);
}
return false;
} }
protected function _parse($datetime, $format) protected function _parse($datetime, $format)

View file

@ -0,0 +1,51 @@
<?php
class Wootook_Core_Email
{
/**
* @var Wootook_Core_Email_Transport_Transport
*/
protected $_transport = null;
public function __construct(Wootook_Core_Email_Transport_Transport $transport = null)
{
if ($transport === null) {
$transport = new Wootook_Core_Email_Transport_Sendmail();
}
$this->setTransport($transport);
}
public function setTransport(Wootook_Core_Email_Transport_Transport $transport)
{
$this->_transport = $transport;
}
/**
* @return Wootook_Core_Email_Transport_Transport
*/
public function getTransport()
{
return $this->_transport;
}
public function send($to, $from, $subject, $body, Array $headers = array())
{
try {
$this->_transport
->addRecipient($to)
->setFrom($from)
->setSubject($subject)
->addPart(new Wootook_Core_Email_Part_Part($body))
->addHeaders($headers)
->connect()
->send()
;
} catch (Wootook_Core_Exception_RuntimeException $e) {
throw new Wootook_Core_Exception_RuntimeException('Could not send mail.', null, $e);
}
$this->_transport->disconnect();
return $this;
}
}

View file

@ -0,0 +1,16 @@
<?php
class Wootook_Core_Email_Part_Part
{
protected $_content = null;
public function __construct($content, $mime = 'text/plain')
{
$this->_content = $content;
}
public function render()
{
return $this->_content;
}
}

View file

@ -1,40 +1,7 @@
<?php <?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Email\Transport; class Wootook_Core_Email_Transport_Sendmail
implements Wootook_Core_Email_Transport_Transport
use Wootook\Core\Email\Part,
Wootook\Core\Exception as CoreException;
class Sendmail
implements Transport
{ {
protected static $_defaultHeaders = array(); protected static $_defaultHeaders = array();
@ -122,7 +89,7 @@ class Sendmail
return $this; return $this;
} }
public function addPart(Part\Part $part) public function addPart(Wootook_Core_Email_Part_Part $part)
{ {
$this->_parts[] = $part; $this->_parts[] = $part;
@ -187,9 +154,9 @@ class Sendmail
$this->addHeader('To', implode(',', $this->_recipients)); $this->addHeader('To', implode(',', $this->_recipients));
if (!mail(implode(',', $this->_recipients), $this->_subject, $content, implode("\r\n", $this->_headers))) { if (!mail(implode(',', $this->_recipients), $this->_subject, $content, implode("\r\n", $this->_headers))) {
throw new CoreException\RuntimeException('Could not send mail.'); throw new Wootook_Core_Exception_RuntimeException('Could not send mail.');
} }
return $this; return $this;
} }
} }

View file

@ -0,0 +1,22 @@
<?php
interface Wootook_Core_Email_Transport_Transport
{
public function setFrom($from);
public function addRecipient($recipient);
public function setSubject($subject);
public function addHeader($name, $value);
public function addPart(Wootook_Core_Email_Part_Part $part);
public function reset();
public function clearFrom();
public function clearHeaders();
public function clearRecipients();
public function clearSubject();
public function clearParts();
public function connect();
public function disconnect();
public function send();
}

View file

@ -28,15 +28,13 @@
* *
*/ */
namespace Wootook\Core\Profiler;
use Wootook\Core\Config,
Wootook\Core\Exception as CoreException;
/** /**
* Error profiler, displays details about PHP core errors and uncaught exceptions. *
* Enter description here ...
* @author Greg
*
*/ */
class ErrorProfiler class Wootook_Core_ErrorProfiler
{ {
private static $_singleton = null; private static $_singleton = null;
@ -50,11 +48,11 @@ class ErrorProfiler
private $_listen = true; private $_listen = true;
private $_mute = false; private $_mute = true;
/** /**
* *
* @return ErrorProfiler * @return Wootook_Core_ErrorProfiler
*/ */
public static function getSingleton() public static function getSingleton()
{ {
@ -64,14 +62,6 @@ class ErrorProfiler
return self::$_singleton; return self::$_singleton;
} }
/**
* @param $errno
* @param $errstr
* @param null $errfile
* @param null $errline
* @param array $errcontext
* @return bool
*/
public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array()) public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array())
{ {
if (!$this->_listen) { if (!$this->_listen) {
@ -81,59 +71,59 @@ class ErrorProfiler
$trace = debug_backtrace(); $trace = debug_backtrace();
switch ($errno) { switch ($errno) {
case E_RECOVERABLE_ERROR: case E_RECOVERABLE_ERROR:
case E_USER_ERROR: case E_USER_ERROR:
case E_ERROR: case E_ERROR:
$this->_errors[] = array( $this->_errors[] = array(
'time' => explode(' ', microtime()), 'time' => explode(' ', microtime()),
'code' => $errno, 'code' => $errno,
'message' => $errstr, 'message' => $errstr,
'file' => $errfile, 'file' => $errfile,
'line' => $errline, 'line' => $errline,
'context' => $errcontext, 'context' => $errcontext,
'trace' => $trace 'trace' => $trace
); );
break; break;
case E_USER_WARNING: case E_USER_WARNING:
case E_WARNING: case E_WARNING:
$this->_warnings[] = array( $this->_warnings[] = array(
'time' => explode(' ', microtime()), 'time' => explode(' ', microtime()),
'code' => $errno, 'code' => $errno,
'message' => $errstr, 'message' => $errstr,
'file' => $errfile, 'file' => $errfile,
'line' => $errline, 'line' => $errline,
'context' => $errcontext, 'context' => $errcontext,
'trace' => $trace 'trace' => $trace
); );
break; break;
case E_USER_NOTICE: case E_USER_NOTICE:
case E_NOTICE: case E_NOTICE:
$this->_notices[] = array( $this->_notices[] = array(
'time' => explode(' ', microtime()), 'time' => explode(' ', microtime()),
'code' => $errno, 'code' => $errno,
'message' => $errstr, 'message' => $errstr,
'file' => $errfile, 'file' => $errfile,
'line' => $errline, 'line' => $errline,
'context' => $errcontext, 'context' => $errcontext,
'trace' => $trace 'trace' => $trace
); );
break; break;
default: default:
if (!isset($this->_otherErrors[$errno])) { if (!isset($this->_otherErrors[$errno])) {
$this->_otherErrors[$errno] = array(); $this->_otherErrors[$errno] = array();
} }
$this->_otherErrors[$errno][] = array( $this->_otherErrors[$errno][] = array(
'time' => explode(' ', microtime()), 'time' => explode(' ', microtime()),
'code' => $errno, 'code' => $errno,
'message' => $errstr, 'message' => $errstr,
'file' => $errfile, 'file' => $errfile,
'line' => $errline, 'line' => $errline,
'context' => $errcontext, 'context' => $errcontext,
'trace' => $trace 'trace' => $trace
); );
break; break;
} }
@ -141,36 +131,19 @@ class ErrorProfiler
return true; return true;
} }
/** public function addException($exception)
* Add a caught exception to the error profiler
*
* @param \Exception $exception
* @return void
*/
public function addException(\Exception $exception)
{ {
$this->_exceptions[] = $exception; $this->_exceptions[] = $exception;
} }
/** public function exceptionManager($exception)
* Exception manager, fallback function for uncaught exceptions
*
* @param \Exception $exception
* @return void
*/
public function exceptionManager(\Exception $exception)
{ {
if (!$this->_listen) { if (!$this->_listen) {
return; return;
} }
$this->_exceptions[] = new CoreException\Exception('Uncaught Exception: ' . $exception->getMessage(), null, $exception); $this->_exceptions[] = new Wootook_Core_Exception_Exception('Uncaught Exception: ' . $exception->getMessage(), null, $exception);
} }
/**
* @param $id
* @param $error
* @return string
*/
protected function _renderError($id, $error) protected function _renderError($id, $error)
{ {
$types = array( $types = array(
@ -189,7 +162,7 @@ class ErrorProfiler
0x1000 => 'E_RECOVERABLE_ERROR', 0x1000 => 'E_RECOVERABLE_ERROR',
0x2000 => 'E_DEPRECATED', 0x2000 => 'E_DEPRECATED',
0x4000 => 'E_USER_DEPRECATED', 0x4000 => 'E_USER_DEPRECATED',
); );
if (isset($error['code']) && isset($types[$error['code']])) { if (isset($error['code']) && isset($types[$error['code']])) {
$code = $types[$error['code']]; $code = $types[$error['code']];
@ -198,10 +171,10 @@ class ErrorProfiler
} }
$date = date('Y-m-d H:i:s', (int) $error['time'][1]); $date = date('Y-m-d H:i:s', (int) $error['time'][1]);
$microSec = (int) ($error['time'][0] * 1000000); $microsec = (int) ($error['time'][0] * 1000000);
return <<<ERROR_EOF return <<<ERROR_EOF
On: {$date} +{$microSec}µs On: {$date} +{$microsec}µs
Type: {$code} Type: {$code}
Message: {$error['message']} Message: {$error['message']}
File: {$error['file']} File: {$error['file']}
@ -265,13 +238,13 @@ ERROR_EOF;
return $argumentList; return $argumentList;
} }
protected function _renderConfig(Config\Node $config, $level = 0) protected function _renderConfig(Wootook_Core_Config_Node $config, $level = 0)
{ {
$output = '<ul style="list-style:none;padding:5px;margin:5px 10px;border:1px solid gray">'; $output = '<ul style="list-style:none;padding:5px;margin:5px 10px;border:1px solid gray">';
foreach ($config as $key => $value) { foreach ($config as $key => $value) {
$output .= sprintf('<li style="">', $level); $output .= sprintf('<li style="">', $level);
$output .= sprintf('<span style="text-decoration:underline;padding-right:10px;font-family:monospace;color:darkred;font-weight:bold;font-size:12px;">%s</span>', $key); $output .= sprintf('<span style="text-decoration:underline;padding-right:10px;font-family:monospace;color:darkred;font-weight:bold;font-size:12px;">%s</span>', $key);
if ($value instanceof Config\Node) { if ($value instanceof Wootook_Core_Config_Node) {
if (count($value) > 0) { if (count($value) > 0) {
$output .= $this->_renderConfig($value, $level + 1); $output .= $this->_renderConfig($value, $level + 1);
} else { } else {
@ -293,39 +266,6 @@ ERROR_EOF;
return; return;
} }
$jqueryUrl = 'scripts/jquery/jquery-1.6.4.js';
echo <<< JS_EOF
<script>
var registeredWootookProfilerCallback = false;
var callbackList = [];
function WootookProfilerCallback(callbackFunction) {
callbackList.push(callbackFunction);
if (callbackList.length == 1 && !document.jQuery) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '{$jqueryUrl}';
var eventListener = function() {
if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
for (var i = 0; i < callbackList.length; i++) {
callbackList[i]();
}
}
};
script.addEventListener('load', eventListener, false);
script.addEventListener('readystatechange', eventListener, false);
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(script, s);
} else {
callbackFunction();
}
}
</script>
JS_EOF;
$index = 0; $index = 0;
echo '<div style="background:#FFF;border:5px solid #933;border-top-width:15px;border-radius:5px;color:#000;padding:0;margin:20px;text-align:left;margin:50px auto;width:800px;">'; echo '<div style="background:#FFF;border:5px solid #933;border-top-width:15px;border-radius:5px;color:#000;padding:0;margin:20px;text-align:left;margin:50px auto;width:800px;">';
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Debug profiler</h1>'; echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Debug profiler</h1>';
@ -394,11 +334,12 @@ JS_EOF;
echo PHP_EOL; echo PHP_EOL;
echo '</pre>'; echo '</pre>';
} }
echo '</div>';
} }
echo '</div>'; echo '</div>';
echo <<<JS_EOF echo <<<JS_EOF
<script> <script>
WootookProfilerCallback(function(){ (function(){
var sections = jQuery('.error-profiler'); var sections = jQuery('.error-profiler');
sections.each(function(){ sections.each(function(){
var element = jQuery(this); var element = jQuery(this);
@ -416,33 +357,32 @@ jQuery('.error-profiler-link').click(function(e){
} }
}); });
}); });
}); })();
</script> </script>
JS_EOF; JS_EOF;
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Configuration profiler</h1>'; echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Configuration profiler</h1>';
$config = \Wootook::app()->getGlobalConfig(); echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="global" class="config-profiler-link">Global configuration</h2>';
if ($config !== null) { echo '<div class="config-profiler global">';
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="global" class="config-profiler-link">Global configuration</h2>'; $config = clone Wootook::getConfig();
echo '<div class="config-profiler global">'; foreach ($config->getConfig('resource/database') as $node) {
$config = clone $config; if ($node->params) {
foreach ($config->getConfig('resource/database') as $node) { $node->params->reset();
if ($node->params) {
$node->params->reset();
}
} }
echo $this->_renderConfig($config, 0); }
echo '</div>'; echo $this->_renderConfig(Wootook::getConfig(), 0);
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="website" class="config-profiler-link">Website configuration</h2>'; echo '</div>';
echo '<div class="config-profiler website">'; echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="website" class="config-profiler-link">Website configuration</h2>';
echo $this->_renderConfig(\Wootook::app()->getDefaultWebsite()->getConfig()); echo '<div class="config-profiler website">';
echo '</div>'; echo $this->_renderConfig(Wootook::getWebsiteConfig());
echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="game" class="config-profiler-link">Game configuration</h2>'; echo '</div>';
echo '<div class="config-profiler game">'; echo '<h2 style="font-size:1.5em;text-decoration:none;margin:0;padding:15px 10px 5px;border-color:#000;border-style:solid;border-width:0 0 1px;background-color:#EEE" rel="game" class="config-profiler-link">Game configuration</h2>';
echo $this->_renderConfig(\Wootook::app()->getDefaultGame()->getConfig()); echo '<div class="config-profiler game">';
echo '</div>'; echo $this->_renderConfig(Wootook::getGameConfig());
echo <<<JS_EOF echo '</div>';
echo '</div>';
echo <<<JS_EOF
<script> <script>
WootookProfilerCallback(function(){ (function(){
var sections = jQuery('.config-profiler'); var sections = jQuery('.config-profiler');
sections.each(function(){ sections.each(function(){
var element = jQuery(this); var element = jQuery(this);
@ -460,13 +400,9 @@ jQuery('.config-profiler-link').click(function(e){
} }
}); });
}); });
}); })();
</script> </script>
JS_EOF; JS_EOF;
} else {
echo '<em>Could not load application configuration.</em>';
}
echo '</div>';
} }
public static function register() public static function register()
@ -474,7 +410,9 @@ JS_EOF;
set_error_handler(array(self::getSingleton(), 'errorManager')); set_error_handler(array(self::getSingleton(), 'errorManager'));
set_exception_handler(array(self::getSingleton(), 'exceptionManager')); set_exception_handler(array(self::getSingleton(), 'exceptionManager'));
self::getSingleton()->_mute = false; if (defined('DEBUG')) {
self::getSingleton()->_mute = false;
}
if (self::$_isTraceRegistered === false && defined('DEBUG')) { if (self::$_isTraceRegistered === false && defined('DEBUG')) {
self::$_isTraceRegistered = true; self::$_isTraceRegistered = true;

View file

@ -28,12 +28,13 @@
* *
*/ */
namespace Wootook\Core\Mvc\Model\Action;
/** /**
*
* Enter description here ...
* @author Greg
* *
*/ */
interface Deletable class Wootook_Core_Event
extends Wootook_Object
{ {
public function save(); }
}

View file

@ -0,0 +1,7 @@
<?php
class Wootook_Core_Event_Break
extends Exception
implements Wootook_Core_Exception
{
}

Some files were not shown because too many files have changed in this diff Show more