Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fde7653cf | ||
|
|
7dcc790e65 | ||
|
|
5797328adc | ||
|
|
6f1e5e4467 | ||
|
|
8ebc4cd91f | ||
|
|
4b92511bae | ||
|
|
74c4f31f7f |
460 changed files with 6552 additions and 19136 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ config.php
|
|||
.idea/
|
||||
coverage/
|
||||
src/application/cache/*
|
||||
src/application/configs/local.php
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
|
||||
script: sh build/build.sh
|
||||
146
build.xml
Normal file
146
build.xml
Normal 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>
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -16,6 +16,3 @@ SetEnv DEPRECATION On
|
|||
RewriteCond %{REQUEST_FILENAME} !-l
|
||||
RewriteRule .* index.php [L]
|
||||
</IfModule>
|
||||
|
||||
# OVH.com
|
||||
SetEnv PHP_VER 5_4
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
require_once dirname(__FILE__) .'/application/bc.php';
|
||||
require_once dirname(__FILE__) .'/application/bootstrap.php';
|
||||
|
||||
$mode = Wootook::getRequest()->getPost('mode');
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin');
|
||||
|
|
@ -76,4 +76,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/Queries');
|
||||
|
|
@ -56,4 +56,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
|
||||
includeLang('admin');
|
||||
|
||||
|
|
@ -135,4 +135,4 @@ function WootookResetUnivers ( $CurrentUser ) {
|
|||
display ($Page, $lang['Reset'], false, '', true);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ define('INSIDE' , true);
|
|||
define('INSTALL' , false);
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/addmoon');
|
||||
|
|
@ -66,4 +66,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
} else {
|
||||
AdminMessage ( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
doquery("UPDATE {{table}} SET `banaday` =` banaday` - '1' WHERE `banaday` != '0';",'users');
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin');
|
||||
|
|
@ -86,4 +86,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
AdminMessage ($lang['sys_noalloaw'], $lang['sys_noaccess']);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
includeLang('changelog');
|
||||
$template = gettemplate('changelog_table');
|
||||
|
||||
|
|
@ -53,4 +53,4 @@ $page .= parsetemplate(gettemplate('changelog_body'), $parse);
|
|||
|
||||
display( $page, "Changelog", false, '', true);
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
includeLang('admin');
|
||||
$parse = $lang;
|
||||
|
||||
|
|
@ -63,4 +63,4 @@ $parse = $lang;
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
includeLang('credit');
|
||||
$parse = $lang;
|
||||
|
||||
|
|
@ -70,4 +70,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN))) {
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin');
|
||||
|
|
@ -84,4 +84,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
$PageTpl = gettemplate( "admin/deletuser" );
|
||||
|
|
@ -47,4 +47,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
|
||||
includeLang('admin');
|
||||
$parse = $lang;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
|
||||
includeLang('leftmenu');
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/changepass');
|
||||
|
||||
|
|
@ -57,4 +57,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/md5enc');
|
||||
|
|
@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/messagelist');
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ define('INSIDE' , true);
|
|||
define('INSTALL' , false);
|
||||
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 (!empty($_POST)) {
|
||||
|
|
@ -72,4 +72,4 @@ if (in_array($user['authlevel'], array(LEVEL_ADMIN, LEVEL_OPERATOR, LEVEL_MODERA
|
|||
}
|
||||
} else {
|
||||
message($lang['sys_noalloaw'], $lang['sys_noaccess']);
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('overview');
|
||||
|
||||
|
|
@ -59,4 +59,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
} else {
|
||||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin/multi');
|
||||
|
|
@ -62,4 +62,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin');
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ define('INSIDE' , true);
|
|||
define('INSTALL' , false);
|
||||
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))) {
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
|
||||
|
|
@ -60,4 +60,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
}
|
||||
|
||||
// Created by e-Zobar. All rights reversed (C) Wootook Team 2008
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
define('IN_ADMIN', true);
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
||||
require_once dirname(dirname(__FILE__)) .'/application/bootstrap.php';
|
||||
|
||||
|
||||
function DisplayGameSettingsPage($CurrentUser) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ define('INSIDE' , true);
|
|||
define('INSTALL' , false);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
|
||||
|
|
@ -54,4 +54,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
includeLang('admin');
|
||||
|
|
@ -90,4 +90,4 @@ require_once dirname(dirname(__FILE__)) .'/application/bc.php';
|
|||
message( $lang['sys_noalloaw'], $lang['sys_noaccess'] );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
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))) {
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
define('INSTALL' , false);
|
||||
define('INSIDE' , true);
|
||||
require_once dirname(__FILE__) .'/application/bc.php';
|
||||
require_once dirname(__FILE__) .'/application/bootstrap.php';
|
||||
|
||||
$user = Wootook_Player_Model_Session::getSingleton()->getPlayer();
|
||||
$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);
|
||||
display($page, $lang['your_alliance']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
define('INSIDE' , true);
|
||||
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');
|
||||
$writeAdapter = Wootook_Core_Database_ConnectionManager::getSingleton()->getConnection('core_write');
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
define('INSIDE' , true);
|
||||
define('INSTALL' , false);
|
||||
require_once dirname(__FILE__) .'/application/bc.php';
|
||||
require_once dirname(__FILE__) .'/application/bootstrap.php';
|
||||
|
||||
$actions = $_GET['action'];
|
||||
|
||||
|
|
@ -59,4 +59,4 @@ HTML;
|
|||
|
||||
display($page);
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -28,9 +28,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
define('DEBUG', true);
|
||||
define('DEPRECATION', true);
|
||||
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = explode('.',PHP_VERSION);
|
||||
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');
|
||||
|
||||
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()
|
||||
)));
|
||||
|
||||
include APPLICATION_PATH . 'code' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'Wootook.php';
|
||||
include 'WootookCore' . DIRECTORY_SEPARATOR . 'autoload_register.php';
|
||||
function __autoload($class) {
|
||||
include_once str_replace('_', '/', $class) . '.php';
|
||||
}
|
||||
|
||||
Wootook\Core\Profiler\ErrorProfiler::register();
|
||||
Wootook\Core\Helper\Config\Events::registerEvents();
|
||||
if (defined('IN_ADMIN')) {
|
||||
$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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item
|
|||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array(
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
|
@ -87,4 +87,4 @@ class Legacies_Empire_Block_Planet_ResearchLab_Item
|
|||
{
|
||||
return $this->getBuildingTime($this->getNextLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_ResearchLab_Queue_Item
|
|||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array(
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Item
|
|||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array(
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class Legacies_Empire_Block_Planet_Shipyard_Queue_Item
|
|||
|
||||
$resourceConfig = array();
|
||||
foreach ($resources as $resourceId => $resourceValue) {
|
||||
$resourceConfig[$resourceId] = new Wootook\Core\BaseObject(array(
|
||||
$resourceConfig[$resourceId] = new Wootook_Object(array(
|
||||
'resource_id' => $resourceId,
|
||||
'value' => $resourceValue
|
||||
));
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
|
|||
{
|
||||
$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));
|
||||
$levelTime = Math::sub($partialLevelTime, $firstLevelTime);
|
||||
|
||||
$speedFactor = Wootook::app()->getDefaultGame()->getConfig('game/speed/general');
|
||||
$speedFactor = Wootook::getGameConfig('game/speed/general');
|
||||
if ($speedFactor == null) {
|
||||
$speedFactor = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
|||
Math::setPrecision(50);
|
||||
$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()));
|
||||
Math::setPrecision();
|
||||
|
||||
|
|
|
|||
|
|
@ -351,8 +351,8 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('planets')} (
|
|||
`gauss_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,
|
||||
`small_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0,
|
||||
`big_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',
|
||||
`interceptor_misil` SMALLINT NOT NULL DEFAULT 0,
|
||||
`interplanetary_misil` SMALLINT NOT NULL DEFAULT 0,
|
||||
`metal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
use Wootook\Core\Exception as CoreException,
|
||||
Wootook\Core\Profiler;
|
||||
|
||||
/**
|
||||
* Bootstrap class, used to access main and global functionalities
|
||||
*
|
||||
|
|
@ -53,6 +50,20 @@ class Wootook
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
|
@ -67,6 +78,34 @@ class Wootook
|
|||
*/
|
||||
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 ...
|
||||
|
|
@ -74,9 +113,15 @@ class Wootook
|
|||
*/
|
||||
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.
|
||||
|
|
@ -120,7 +165,7 @@ class Wootook
|
|||
*/
|
||||
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])) {
|
||||
return $eventObject;
|
||||
|
|
@ -137,17 +182,17 @@ class Wootook
|
|||
*
|
||||
* Enter description here ...
|
||||
* @param unknown_type $namespace
|
||||
* @return Wootook\Core\Model\Session
|
||||
* @return Wootook_Core_Model_Session
|
||||
*/
|
||||
public static function getSession($namespace)
|
||||
{
|
||||
return Wootook\Core\Model\Session::factory($namespace);
|
||||
return Wootook_Core_Model_Session::factory($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param string|null $locale
|
||||
* @return Wootook\Core\Model\Translator
|
||||
* @return Wootook_Core_Model_Translator
|
||||
*/
|
||||
public static function getTranslator($locale = null)
|
||||
{
|
||||
|
|
@ -157,7 +202,7 @@ class Wootook
|
|||
|
||||
if (!isset($translator[$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];
|
||||
}
|
||||
|
|
@ -177,7 +222,7 @@ class Wootook
|
|||
|
||||
public static function getLocale()
|
||||
{
|
||||
$availableLocales = self::app()->getDefaultWebsite()->getConfig('locales');
|
||||
$availableLocales = self::getWebsiteConfig('locales');
|
||||
if ($availableLocales !== null) {
|
||||
return self::getPreferredLocale($availableLocales->toArray());
|
||||
}
|
||||
|
|
@ -203,17 +248,14 @@ class Wootook
|
|||
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)) {
|
||||
return $userLocale;
|
||||
}
|
||||
*/
|
||||
|
||||
$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)
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return Wootook\Core\DateTime
|
||||
* @return Wootook_Core_DateTime
|
||||
*/
|
||||
public static function now()
|
||||
{
|
||||
if (self::$_now === null) {
|
||||
self::$_now = time();
|
||||
}
|
||||
return new Wootook\Core\DateTime(self::$_now);
|
||||
return new Wootook_Core_DateTime(self::$_now);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @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
|
||||
* @return Wootook_Core_Mvc_Controller_Request_Http
|
||||
*/
|
||||
public static function getRequest()
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getFrontController()->getRequest();
|
||||
if (self::$_request === null) {
|
||||
self::$_request = new Wootook_Core_Mvc_Controller_Request_Http();
|
||||
}
|
||||
return self::$_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @deprecated
|
||||
* @param Wootook\Core\Mvc\Controller\Request\Request $request
|
||||
*/
|
||||
public static function setRequest(Wootook\Core\Mvc\Controller\Request\Request $request)
|
||||
public static function setRequest($request)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
self::app()->getFrontController()->setRequest($request);
|
||||
self::$_request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return Wootook\Core\Mvc\Controller\Response\Response
|
||||
* @return Wootook_Core_Mvc_Controller_Response_Http
|
||||
*/
|
||||
public static function getResponse()
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getFrontController()->getResponse();
|
||||
if (self::$_response === null) {
|
||||
self::$_response = new Wootook_Core_Mvc_Controller_Response_Http();
|
||||
}
|
||||
return self::$_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @deprecated
|
||||
* @param Wootook\Core\Mvc\Controller\Response\Response $response
|
||||
*/
|
||||
public static function setResponse(Wootook\Core\Mvc\Controller\Response\Response $response)
|
||||
public static function setResponse($response)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
self::app()->getFrontController()->setResponse($response);
|
||||
self::$_response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @deprecated
|
||||
* @param null $filename
|
||||
* @return null|Wootook_Core_Helper_Config_ConfigHandler
|
||||
* @throws CoreException\DataAccessException
|
||||
*/
|
||||
public static function loadConfig($filename = null)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getGlobalConfig();
|
||||
self::$_websiteConfigs = array();
|
||||
self::$_gameConfigs = array();
|
||||
|
||||
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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getWebsite($websiteId);
|
||||
if (is_numeric($websiteId)) {
|
||||
if (isset(self::$_websitesById[$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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getGame($gameId);
|
||||
if (is_numeric($gameId)) {
|
||||
if (isset(self::$_gamesById[$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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
$websiteId = $website->getId();
|
||||
$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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
$gameId = $game->getId();
|
||||
$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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
self::app()->setDefaultWebsiteId($website->getId());
|
||||
self::$_defaultWebsite = $website;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getDefaultWebsite();
|
||||
if (self::$_defaultWebsite === null) {
|
||||
self::$_defaultWebsite = new Wootook_Core_Model_Website();
|
||||
self::$_defaultWebsite->setId(1)->setData('code', Wootook_Core_Model_Website::DEFAULT_CODE);
|
||||
}
|
||||
return self::$_defaultWebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @deprecated
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getDefaultGame()
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getDefaultGame();
|
||||
if (self::$_defaultGame === null) {
|
||||
self::$_defaultGame = new Wootook_Core_Model_Game();
|
||||
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)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
return self::app()->getGlobalConfig($path);
|
||||
if (self::$_config === null) {
|
||||
self::loadConfig();
|
||||
}
|
||||
|
||||
if ($path !== null) {
|
||||
return self::$_globalConfig->getConfig($path);
|
||||
}
|
||||
return self::$_globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @deprecated
|
||||
* @param null $path
|
||||
* @param null $gameKey
|
||||
* @return Wootook_Core_Config_Node
|
||||
*/
|
||||
public static function getWebsiteConfig($path = null, $websiteKey = null)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
|
||||
if ($websiteKey === null) {
|
||||
$websiteKey = self::app()->getDefaultWebsiteId();
|
||||
if (self::$_config === null) {
|
||||
self::loadConfig();
|
||||
}
|
||||
|
||||
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
|
||||
* @deprecated
|
||||
* @param null $path
|
||||
* @param null $gameKey
|
||||
* @return Wootook_Core_Config_Node
|
||||
*/
|
||||
public static function getGameConfig($path = null, $gameKey = null)
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
|
||||
if ($gameKey === null) {
|
||||
$gameKey = self::app()->getDefaultGameId();
|
||||
if (self::$_config === null) {
|
||||
self::loadConfig();
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -524,7 +756,7 @@ class Wootook
|
|||
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -536,7 +768,7 @@ class Wootook
|
|||
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -599,13 +831,13 @@ class Wootook
|
|||
return false;
|
||||
}
|
||||
|
||||
Profiler\ErrorProfiler::getSingleton()->sleep();
|
||||
Wootook_Core_ErrorProfiler::getSingleton()->sleep();
|
||||
if (($fp = @fopen($path, 'r', true)) === false) {
|
||||
Profiler\ErrorProfiler::getSingleton()->wakeup();
|
||||
Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
Profiler\ErrorProfiler::getSingleton()->wakeup();
|
||||
Wootook_Core_ErrorProfiler::getSingleton()->wakeup();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
155
src/application/code/core/Wootook/Core/App.php
Normal file
155
src/application/code/core/Wootook/Core/App.php
Normal 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())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
14
src/application/code/core/Wootook/Core/Block/Concat.php
Normal file
14
src/application/code/core/Wootook/Core/Block/Concat.php
Normal 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;
|
||||
}
|
||||
}
|
||||
10
src/application/code/core/Wootook/Core/Block/Deprecated.php
Normal file
10
src/application/code/core/Wootook/Core/Block/Deprecated.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Block_Deprecated
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
public function getScriptPath()
|
||||
{
|
||||
return $this->getLayout()->getScriptPath();
|
||||
}
|
||||
}
|
||||
11
src/application/code/core/Wootook/Core/Block/Html/Form.php
Normal file
11
src/application/code/core/Wootook/Core/Block/Html/Form.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,7 @@
|
|||
<?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 Head
|
||||
extends Template
|
||||
class Wootook_Core_Block_Html_Head
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
const TYPE_GLOBAL_CSS = 'global_css';
|
||||
const TYPE_GLOBAL_JS = 'global_js';
|
||||
|
|
@ -314,4 +284,4 @@ HTML_EOF;
|
|||
}
|
||||
return $render;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/application/code/core/Wootook/Core/Block/Html/Home.php
Normal file
22
src/application/code/core/Wootook/Core/Block/Html/Home.php
Normal 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Block,
|
||||
Wootook\Core\Exception as CoreException;
|
||||
|
||||
class Menu
|
||||
extends Block\Template
|
||||
class Wootook_Core_Block_Html_Navigation
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if ($child instanceof Link) {
|
||||
throw new CoreException\RuntimeException('Node is a link. Could not append a child node to a link node.');
|
||||
if ($child instanceof Wootook_Core_Block_Html_Navigation_Link) {
|
||||
throw new Wootook_Core_Exception_RuntimeException('Node is a link. Could not append a child node to a link node.');
|
||||
}
|
||||
|
||||
if (count($explodedPath) == 0) {
|
||||
|
|
@ -1,39 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Block;
|
||||
|
||||
class Link
|
||||
extends Block\Template
|
||||
class Wootook_Core_Block_Html_Navigation_Link
|
||||
extends Wootook_Core_Block_Template
|
||||
{
|
||||
protected $_label = '';
|
||||
protected $_title = '';
|
||||
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
19
src/application/code/core/Wootook/Core/Block/Html/Page.php
Normal file
19
src/application/code/core/Wootook/Core/Block/Html/Page.php
Normal 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;
|
||||
}
|
||||
}
|
||||
47
src/application/code/core/Wootook/Core/Block/Messages.php
Normal file
47
src/application/code/core/Wootook/Core/Block/Messages.php
Normal 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;
|
||||
}
|
||||
}
|
||||
46
src/application/code/core/Wootook/Core/Block/Template.php
Normal file
46
src/application/code/core/Wootook/Core/Block/Template.php
Normal 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;
|
||||
}
|
||||
}
|
||||
28
src/application/code/core/Wootook/Core/Block/Text.php
Normal file
28
src/application/code/core/Wootook/Core/Block/Text.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Config_Adapter_Adapter
|
||||
extends Wootook_Core_Config_Node
|
||||
{
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Exception as CoreException;
|
||||
|
||||
class Node
|
||||
implements \ArrayAccess, \Iterator, \Countable
|
||||
class Wootook_Core_Config_Node
|
||||
implements ArrayAccess, Iterator, Countable
|
||||
{
|
||||
protected $_children = array();
|
||||
|
||||
|
|
@ -86,7 +54,7 @@ class Node
|
|||
for ($i = 0; $i < $length; $i++) {
|
||||
if ($i < ($length - 1)) {
|
||||
if (!$currentNode->offsetExists($explodedPath[$i])) {
|
||||
$newNode = new Node(array(), $currentNode);
|
||||
$newNode = new Wootook_Core_Config_Node(array(), $currentNode);
|
||||
$currentNode->offsetSet($explodedPath[$i], $newNode);
|
||||
}
|
||||
} else if (is_array($value)) {
|
||||
|
|
@ -99,8 +67,8 @@ class Node
|
|||
|
||||
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
|
||||
|
||||
if (!$currentNode instanceof Node) {
|
||||
throw new CoreException\RuntimeException();
|
||||
if (!$currentNode instanceof Wootook_Core_Config_Node) {
|
||||
throw new Wootook_Core_Exception_RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,8 +82,8 @@ class Node
|
|||
$length = count($explodedPath);
|
||||
$currentNode = $this;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (!$currentNode instanceof Node) {
|
||||
throw new CoreException\RuntimeException();
|
||||
if (!$currentNode instanceof Wootook_Core_Config_Node) {
|
||||
throw new Wootook_Core_Exception_RuntimeException();
|
||||
}
|
||||
if (!$currentNode->offsetExists($explodedPath[$i])) {
|
||||
return null;
|
||||
|
|
@ -133,7 +101,7 @@ class Node
|
|||
foreach ($this->_children as $key => $child) {
|
||||
if ($child instanceof self) {
|
||||
$result[$key] = $child->toArray();
|
||||
} else if ($child instanceof Leaf) {
|
||||
} else if ($child instanceof Wootook_Core_Config_Leaf) {
|
||||
$result[$key] = $child->getValue();
|
||||
} else {
|
||||
$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()
|
||||
{
|
||||
return current($this->_children);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_children);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return count($this->_children);
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Controller_IndexController
|
||||
extends Wootook_Core_Mvc_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->loadLayout('home');
|
||||
$this->renderLayout();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +1,9 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core,
|
||||
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
|
||||
class Wootook_Core_Database_ConnectionManager
|
||||
extends Wootook_Core_PluginLoader_PluginLoader
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
use Service\App;
|
||||
|
||||
const PROFILER = 'profiler';
|
||||
const CASE_FOLDING = 'case-folding';
|
||||
const AUTO_QUOTE_IDENTIFIERS = 'auto-quote-identifiers';
|
||||
|
|
@ -138,20 +99,20 @@ class ConnectionManager
|
|||
|
||||
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()
|
||||
{
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
->addException(new CoreException\RuntimeException('Method ' . __METHOD__ . ' is deprecated.'));
|
||||
|
||||
return \Wootook::app()->getConnectionManager();
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected $_defaultOptions = array(
|
||||
|
|
@ -160,7 +121,7 @@ class ConnectionManager
|
|||
|
||||
/**
|
||||
* @param $connectionName
|
||||
* @return Adapter\Adapter
|
||||
* @return Wootook_Core_Database_Adapter_Adapter
|
||||
*/
|
||||
public function getConnection($connectionName)
|
||||
{
|
||||
|
|
@ -173,7 +134,7 @@ class ConnectionManager
|
|||
return $this->_connectionAliases[$connectionName];
|
||||
}
|
||||
|
||||
$connectionConfig = \Wootook::app()->getGlobalConfig("resource/database/{$connectionName}");
|
||||
$connectionConfig = Wootook::getConfig("resource/database/{$connectionName}");
|
||||
if ($connectionConfig === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -193,12 +154,12 @@ class ConnectionManager
|
|||
private function _initConnection($connectionName, $engine, $params, $options = array())
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$params = new Config\Node($params);
|
||||
} else if (!$params instanceof Config\Node) {
|
||||
$params = new Config\Node(array());
|
||||
$params = new Wootook_Core_Config_Node($params);
|
||||
} else if (!$params instanceof Wootook_Core_Config_Node) {
|
||||
$params = new Wootook_Core_Config_Node(array());
|
||||
}
|
||||
|
||||
if ($options instanceof Config\Node) {
|
||||
if ($options instanceof Wootook_Core_Config_Node) {
|
||||
$options = $options->toArray();
|
||||
} else if (!is_array($options)) {
|
||||
$options = array();
|
||||
|
|
@ -208,28 +169,24 @@ class ConnectionManager
|
|||
return null;
|
||||
}
|
||||
|
||||
$event = \Wootook::dispatchEvent('database.prepare-options', array(
|
||||
$event = Wootook::dispatchEvent('database.prepare-options', array(
|
||||
'name' => $connectionName,
|
||||
'options' => array_merge($this->_defaultOptions, $options)
|
||||
));
|
||||
|
||||
$options = $event->getData('options');
|
||||
|
||||
try {
|
||||
$connection = $this->load($engine, false, array($params, $options));
|
||||
} catch (CoreException\Database\AdapterError $e) {
|
||||
Profiler\ErrorProfiler::getSingleton()->addException($e);
|
||||
return null;
|
||||
}
|
||||
$connection = $this->load($engine, false, array($params, $options));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
\Wootook::dispatchEvent('database.init', array(
|
||||
Wootook::dispatchEvent('database.init', array(
|
||||
'name' => $connectionName,
|
||||
'handler' => $connection
|
||||
));
|
||||
|
|
@ -239,7 +196,7 @@ class ConnectionManager
|
|||
|
||||
protected function _load($className, $useSingleton, Array $constructorParams = array())
|
||||
{
|
||||
$reflection = new \ReflectionClass($className);
|
||||
$reflection = new ReflectionClass($className);
|
||||
return $reflection->newInstanceArgs($constructorParams);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Config,
|
||||
Wootook\Core\Database,
|
||||
Wootook\Core\Mvc\Model,
|
||||
Wootook\Core\PluginLoader,
|
||||
Wootook\Core\Profiler;
|
||||
|
||||
class DataMapper
|
||||
extends PluginLoader\PluginLoader
|
||||
class Wootook_Core_Database_Orm_DataMapper
|
||||
extends Wootook_Core_PluginLoader_PluginLoader
|
||||
{
|
||||
protected $_rules = array();
|
||||
|
||||
|
|
@ -45,9 +9,9 @@ class DataMapper
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -89,16 +53,16 @@ class DataMapper
|
|||
|
||||
protected function _load($className, $useSingleton, Array $constructorParams = array())
|
||||
{
|
||||
$reflection = new \ReflectionClass($className);
|
||||
if ($useSingleton && $reflection->implementsInterface('Wootook\\Core\\Base\\Singleton')) {
|
||||
$reflection = new ReflectionClass($className);
|
||||
if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) {
|
||||
$method = $reflection->getMethod('getSingleton');
|
||||
return $method->invoke(null);
|
||||
}
|
||||
|
||||
try {
|
||||
return $reflection->newInstance($this);
|
||||
} catch (\ReflectionException $e) {
|
||||
Profiler\ErrorProfiler::getSingleton()
|
||||
} catch (ReflectionException $e) {
|
||||
Wootook_Core_ErrorProfiler::getSingleton()
|
||||
->addException($e);
|
||||
return null;
|
||||
}
|
||||
|
|
@ -106,11 +70,11 @@ class DataMapper
|
|||
|
||||
/**
|
||||
*
|
||||
* @param Database\Resource $entity
|
||||
* @param Wootook_Core_Database_Resource $entity
|
||||
* @param Array $datas
|
||||
* @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);
|
||||
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
|
||||
* @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) {
|
||||
if (isset($this->_rules[$field])) {
|
||||
|
|
@ -148,4 +112,4 @@ class DataMapper
|
|||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
89
src/application/code/core/Wootook/Core/Database/Resource.php
Normal file
89
src/application/code/core/Wootook/Core/Database/Resource.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,7 @@
|
|||
<?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 Delete
|
||||
extends DmlQuery
|
||||
class Wootook_Core_Database_Sql_Delete
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
const FROM = 'FROM';
|
||||
|
||||
24
src/application/code/core/Wootook/Core/Database/Sql/Dml.php
Normal file
24
src/application/code/core/Wootook/Core/Database/Sql/Dml.php
Normal 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);
|
||||
}
|
||||
|
|
@ -1,45 +1,31 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core,
|
||||
Wootook\Core\Database\Adapter,
|
||||
Wootook\Core\Database\Statement,
|
||||
Wootook\Core\Database\Sql\Placeholder;
|
||||
|
||||
trait Where
|
||||
abstract class Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
extends Wootook_Core_Database_Sql_DmlQuery
|
||||
{
|
||||
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)
|
||||
{
|
||||
if ($condition instanceof Placeholder\Placeholder) {
|
||||
if ($condition instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
|
||||
$this->_placeholders[] = $condition;
|
||||
$this->_parts[self::WHERE][] = $condition;
|
||||
} else if (is_array($value)) {
|
||||
|
|
@ -47,7 +33,7 @@ trait Where
|
|||
if ($where !== null) {
|
||||
$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;
|
||||
} else {
|
||||
$this->_parts[self::WHERE][] = $this->getConnection()->quoteInto("{$this->getConnection()->quoteIdentifier($condition)}=?", $value);
|
||||
|
|
@ -56,6 +42,14 @@ trait Where
|
|||
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()
|
||||
{
|
||||
if (count($this->_parts[self::WHERE]) <= 0) {
|
||||
|
|
@ -65,6 +59,17 @@ trait 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)
|
||||
{
|
||||
if ($value === null) {
|
||||
|
|
@ -89,7 +94,7 @@ trait Where
|
|||
return "{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}FALSE";
|
||||
} else if (is_numeric($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;
|
||||
return sprintf("{$adapter->quoteIdentifier($field)}{$basicBinayOperatorList[$operator]}%s", $adapter->quote($value->toString()));
|
||||
} else {
|
||||
|
|
@ -177,7 +182,7 @@ trait Where
|
|||
case self::OPERATOR_DATE:
|
||||
$dateValues = array();
|
||||
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']))}";
|
||||
} else if (is_string($value['from'])) {
|
||||
$dateValues['from'] = "{$adapter->quoteIdentifier($field)} >= {$adapter->quote($value['from'])}";
|
||||
|
|
@ -186,7 +191,7 @@ trait Where
|
|||
}
|
||||
}
|
||||
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']))}";
|
||||
} else if (is_string($value['to'])) {
|
||||
$dateValues['to'] = "{$adapter->quoteIdentifier($field)} <= {$adapter->quote($value['to'])}";
|
||||
107
src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php
Normal file
107
src/application/code/core/Wootook/Core/Database/Sql/DmlQuery.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Database\Sql\Placeholder;
|
||||
|
||||
class Insert
|
||||
extends DmlQuery
|
||||
class Wootook_Core_Database_Sql_Insert
|
||||
extends Wootook_Core_Database_Sql_DmlQuery
|
||||
{
|
||||
const SET = 'SET';
|
||||
const INTO = 'INTO';
|
||||
|
|
@ -72,7 +40,7 @@ class Insert
|
|||
}
|
||||
|
||||
foreach ($column as $field => $value) {
|
||||
if ($value instanceof Placeholder\Placeholder) {
|
||||
if ($value instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
|
||||
$this->_placeholders[] = $value;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +102,7 @@ class Insert
|
|||
{
|
||||
$fields = array();
|
||||
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()}";
|
||||
} else {
|
||||
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Database_Sql_Mysql_Select
|
||||
extends Wootook_Core_Database_Sql_Select
|
||||
{
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +1,10 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Database\Sql\Dml\Section,
|
||||
Wootook\Core\Database\Sql\Placeholder;
|
||||
|
||||
class Select
|
||||
extends DmlQuery
|
||||
class Wootook_Core_Database_Sql_Select
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
use Section\Where, Section\Limit;
|
||||
|
||||
const COLUMNS = 'COLUMNS';
|
||||
const FROM = 'FROM';
|
||||
const JOIN = 'JOIN';
|
||||
const ORDER = 'ORDER';
|
||||
const UNION = 'UNION';
|
||||
|
|
@ -102,7 +68,7 @@ class Select
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if ($column instanceof Placeholder\Placeholder) {
|
||||
if ($column instanceof Wootook_Core_Database_Sql_Placeholder_Placeholder) {
|
||||
$this->_placeholders[] = $column;
|
||||
}
|
||||
|
||||
|
|
@ -245,13 +211,13 @@ class Select
|
|||
{
|
||||
$fields = array();
|
||||
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) {
|
||||
$fields[] = "({$field['field']}) AS {$field['alias']}";
|
||||
} else {
|
||||
$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) {
|
||||
$fields[] = "({$field['field']}) AS {$field['alias']}";
|
||||
} else {
|
||||
|
|
@ -280,7 +246,7 @@ class Select
|
|||
{
|
||||
$tables = array();
|
||||
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) {
|
||||
$tables[] = "({$table['table']}) AS {$this->_connection->quoteIdentifier($table['alias'])}";
|
||||
} else {
|
||||
|
|
@ -1,43 +1,10 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Database\Sql\Dml\Section,
|
||||
Wootook\Core\Database\Sql\Placeholder;
|
||||
|
||||
class Update
|
||||
extends DmlQuery
|
||||
implements Section\IntoAware, Section\LimitAware, Section\SetAware
|
||||
class Wootook_Core_Database_Sql_Update
|
||||
extends Wootook_Core_Database_Sql_DmlFilterableQuery
|
||||
{
|
||||
use Section\Set, Section\Into, Section\Where, Section\Limit;
|
||||
const SET = 'SET';
|
||||
const INTO = 'INTO';
|
||||
|
||||
protected function _init($tableName = null)
|
||||
{
|
||||
|
|
@ -67,6 +34,36 @@ class Update
|
|||
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()
|
||||
{
|
||||
return $this->render();
|
||||
|
|
@ -94,7 +91,7 @@ class Update
|
|||
{
|
||||
$fields = array();
|
||||
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()}";
|
||||
} else {
|
||||
$fields[] = "{$this->_connection->quoteIdentifier($field['field'])}={$this->_connection->quote($field['value'])}";
|
||||
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +1,7 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Date and time management class
|
||||
* @todo : refactor to be compatible with \DateTime
|
||||
*/
|
||||
class DateTime
|
||||
class Wootook_Core_DateTime
|
||||
{
|
||||
const ISO_8601 = 'c';
|
||||
|
||||
|
|
@ -104,18 +71,16 @@ class DateTime
|
|||
|
||||
protected $_datetime = null;
|
||||
|
||||
protected $_timezone = null;
|
||||
|
||||
public static function init($timezone = null, $force = false)
|
||||
{
|
||||
static $init = false;
|
||||
|
||||
if ($init === false || $force === true) {
|
||||
if ($timezone === null) {
|
||||
//$timezone = \Wootook::app()->getGlobalConfig('system/date/timezone');
|
||||
//$timezone = Wootook::getConfig('system/date/timezone');
|
||||
}
|
||||
if ($timezone === null) {
|
||||
$timezone = 'UTC';
|
||||
$timezone = 'GMT';
|
||||
}
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
|
|
@ -123,11 +88,7 @@ class DateTime
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string|int $timestamp
|
||||
* @param string $format
|
||||
*/
|
||||
public function __construct($timestamp = null, $format = null, $timezone = 'UTC')
|
||||
public function __construct($timestamp = null, $format = null)
|
||||
{
|
||||
self::init();
|
||||
|
||||
|
|
@ -138,8 +99,6 @@ class DateTime
|
|||
} else {
|
||||
$this->_datetime = $this->_parse($timestamp, $format);
|
||||
}
|
||||
|
||||
$this->_timezone = $timezone;
|
||||
}
|
||||
|
||||
public function getIso($useTimezone = false)
|
||||
|
|
@ -263,12 +222,18 @@ class DateTime
|
|||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -278,7 +243,10 @@ class DateTime
|
|||
|
||||
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)
|
||||
51
src/application/code/core/Wootook/Core/Email.php
Normal file
51
src/application/code/core/Wootook/Core/Email.php
Normal 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;
|
||||
}
|
||||
}
|
||||
16
src/application/code/core/Wootook/Core/Email/Part/Part.php
Normal file
16
src/application/code/core/Wootook/Core/Email/Part/Part.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +1,7 @@
|
|||
<?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;
|
||||
|
||||
use Wootook\Core\Email\Part,
|
||||
Wootook\Core\Exception as CoreException;
|
||||
|
||||
class Sendmail
|
||||
implements Transport
|
||||
class Wootook_Core_Email_Transport_Sendmail
|
||||
implements Wootook_Core_Email_Transport_Transport
|
||||
{
|
||||
protected static $_defaultHeaders = array();
|
||||
|
||||
|
|
@ -122,7 +89,7 @@ class Sendmail
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addPart(Part\Part $part)
|
||||
public function addPart(Wootook_Core_Email_Part_Part $part)
|
||||
{
|
||||
$this->_parts[] = $part;
|
||||
|
||||
|
|
@ -187,9 +154,9 @@ class Sendmail
|
|||
$this->addHeader('To', implode(',', $this->_recipients));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -50,11 +48,11 @@ class ErrorProfiler
|
|||
|
||||
private $_listen = true;
|
||||
|
||||
private $_mute = false;
|
||||
private $_mute = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ErrorProfiler
|
||||
* @return Wootook_Core_ErrorProfiler
|
||||
*/
|
||||
public static function getSingleton()
|
||||
{
|
||||
|
|
@ -64,14 +62,6 @@ class ErrorProfiler
|
|||
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())
|
||||
{
|
||||
if (!$this->_listen) {
|
||||
|
|
@ -81,59 +71,59 @@ class ErrorProfiler
|
|||
$trace = debug_backtrace();
|
||||
|
||||
switch ($errno) {
|
||||
case E_RECOVERABLE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
case E_ERROR:
|
||||
$this->_errors[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
case E_RECOVERABLE_ERROR:
|
||||
case E_USER_ERROR:
|
||||
case E_ERROR:
|
||||
$this->_errors[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
);
|
||||
break;
|
||||
|
||||
case E_USER_WARNING:
|
||||
case E_WARNING:
|
||||
$this->_warnings[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
case E_USER_WARNING:
|
||||
case E_WARNING:
|
||||
$this->_warnings[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
);
|
||||
break;
|
||||
|
||||
case E_USER_NOTICE:
|
||||
case E_NOTICE:
|
||||
$this->_notices[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
case E_USER_NOTICE:
|
||||
case E_NOTICE:
|
||||
$this->_notices[] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!isset($this->_otherErrors[$errno])) {
|
||||
$this->_otherErrors[$errno] = array();
|
||||
}
|
||||
default:
|
||||
if (!isset($this->_otherErrors[$errno])) {
|
||||
$this->_otherErrors[$errno] = array();
|
||||
}
|
||||
|
||||
$this->_otherErrors[$errno][] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
$this->_otherErrors[$errno][] = array(
|
||||
'time' => explode(' ', microtime()),
|
||||
'code' => $errno,
|
||||
'message' => $errstr,
|
||||
'file' => $errfile,
|
||||
'line' => $errline,
|
||||
'context' => $errcontext,
|
||||
'trace' => $trace
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
@ -141,36 +131,19 @@ class ErrorProfiler
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a caught exception to the error profiler
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function addException(\Exception $exception)
|
||||
public function addException($exception)
|
||||
{
|
||||
$this->_exceptions[] = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception manager, fallback function for uncaught exceptions
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function exceptionManager(\Exception $exception)
|
||||
public function exceptionManager($exception)
|
||||
{
|
||||
if (!$this->_listen) {
|
||||
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)
|
||||
{
|
||||
$types = array(
|
||||
|
|
@ -189,7 +162,7 @@ class ErrorProfiler
|
|||
0x1000 => 'E_RECOVERABLE_ERROR',
|
||||
0x2000 => 'E_DEPRECATED',
|
||||
0x4000 => 'E_USER_DEPRECATED',
|
||||
);
|
||||
);
|
||||
|
||||
if (isset($error['code']) && isset($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]);
|
||||
$microSec = (int) ($error['time'][0] * 1000000);
|
||||
$microsec = (int) ($error['time'][0] * 1000000);
|
||||
|
||||
return <<<ERROR_EOF
|
||||
On: {$date} +{$microSec}µs
|
||||
On: {$date} +{$microsec}µs
|
||||
Type: {$code}
|
||||
Message: {$error['message']}
|
||||
File: {$error['file']}
|
||||
|
|
@ -265,13 +238,13 @@ ERROR_EOF;
|
|||
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">';
|
||||
foreach ($config as $key => $value) {
|
||||
$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);
|
||||
if ($value instanceof Config\Node) {
|
||||
if ($value instanceof Wootook_Core_Config_Node) {
|
||||
if (count($value) > 0) {
|
||||
$output .= $this->_renderConfig($value, $level + 1);
|
||||
} else {
|
||||
|
|
@ -293,39 +266,6 @@ ERROR_EOF;
|
|||
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;
|
||||
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>';
|
||||
|
|
@ -394,11 +334,12 @@ JS_EOF;
|
|||
echo PHP_EOL;
|
||||
echo '</pre>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo <<<JS_EOF
|
||||
<script>
|
||||
WootookProfilerCallback(function(){
|
||||
(function(){
|
||||
var sections = jQuery('.error-profiler');
|
||||
sections.each(function(){
|
||||
var element = jQuery(this);
|
||||
|
|
@ -416,33 +357,32 @@ jQuery('.error-profiler-link').click(function(e){
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
JS_EOF;
|
||||
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Configuration profiler</h1>';
|
||||
$config = \Wootook::app()->getGlobalConfig();
|
||||
if ($config !== null) {
|
||||
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>';
|
||||
echo '<div class="config-profiler global">';
|
||||
$config = clone $config;
|
||||
foreach ($config->getConfig('resource/database') as $node) {
|
||||
if ($node->params) {
|
||||
$node->params->reset();
|
||||
}
|
||||
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>';
|
||||
echo '<div class="config-profiler global">';
|
||||
$config = clone Wootook::getConfig();
|
||||
foreach ($config->getConfig('resource/database') as $node) {
|
||||
if ($node->params) {
|
||||
$node->params->reset();
|
||||
}
|
||||
echo $this->_renderConfig($config, 0);
|
||||
echo '</div>';
|
||||
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 class="config-profiler website">';
|
||||
echo $this->_renderConfig(\Wootook::app()->getDefaultWebsite()->getConfig());
|
||||
echo '</div>';
|
||||
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 class="config-profiler game">';
|
||||
echo $this->_renderConfig(\Wootook::app()->getDefaultGame()->getConfig());
|
||||
echo '</div>';
|
||||
echo <<<JS_EOF
|
||||
}
|
||||
echo $this->_renderConfig(Wootook::getConfig(), 0);
|
||||
echo '</div>';
|
||||
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 class="config-profiler website">';
|
||||
echo $this->_renderConfig(Wootook::getWebsiteConfig());
|
||||
echo '</div>';
|
||||
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 class="config-profiler game">';
|
||||
echo $this->_renderConfig(Wootook::getGameConfig());
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo <<<JS_EOF
|
||||
<script>
|
||||
WootookProfilerCallback(function(){
|
||||
(function(){
|
||||
var sections = jQuery('.config-profiler');
|
||||
sections.each(function(){
|
||||
var element = jQuery(this);
|
||||
|
|
@ -460,13 +400,9 @@ jQuery('.config-profiler-link').click(function(e){
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
JS_EOF;
|
||||
} else {
|
||||
echo '<em>Could not load application configuration.</em>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public static function register()
|
||||
|
|
@ -474,7 +410,9 @@ JS_EOF;
|
|||
set_error_handler(array(self::getSingleton(), 'errorManager'));
|
||||
set_exception_handler(array(self::getSingleton(), 'exceptionManager'));
|
||||
|
||||
self::getSingleton()->_mute = false;
|
||||
if (defined('DEBUG')) {
|
||||
self::getSingleton()->_mute = false;
|
||||
}
|
||||
|
||||
if (self::$_isTraceRegistered === false && defined('DEBUG')) {
|
||||
self::$_isTraceRegistered = true;
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
7
src/application/code/core/Wootook/Core/Event/Break.php
Normal file
7
src/application/code/core/Wootook/Core/Event/Break.php
Normal 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
Loading…
Reference in a new issue