Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
b6e93657
Commit
b6e93657
authored
Apr 16, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
842fee42
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
320 additions
and
16 deletions
+320
-16
DataDict.class.php
classes/DataDict.class.php
+2
-0
Doctrine.class.php
classes/Doctrine.class.php
+1
-0
Record.class.php
classes/Record.class.php
+3
-4
Sensei.class.php
classes/Sensei/Sensei.class.php
+192
-0
Session.class.php
classes/Session.class.php
+5
-3
Table.class.php
classes/Table.class.php
+0
-2
Notblank.class.php
classes/Validator/Notblank.class.php
+1
-1
SenseiTestCase.class.php
tests/SenseiTestCase.class.php
+109
-0
UnitTestCase.class.php
tests/UnitTestCase.class.php
+1
-3
run.php
tests/run.php
+6
-3
No files found.
classes/DataDict.class.php
View file @
b6e93657
...
@@ -50,6 +50,8 @@ class Doctrine_DataDict {
...
@@ -50,6 +50,8 @@ class Doctrine_DataDict {
return
"C(
$length
)"
;
return
"C(
$length
)"
;
elseif
(
$length
<
4000
)
elseif
(
$length
<
4000
)
return
"X"
;
return
"X"
;
else
return
"X2"
;
break
;
break
;
case
"mbstring"
:
case
"mbstring"
:
if
(
$length
<
255
)
if
(
$length
<
255
)
...
...
classes/Doctrine.class.php
View file @
b6e93657
...
@@ -214,6 +214,7 @@ final class Doctrine {
...
@@ -214,6 +214,7 @@ final class Doctrine {
case
"Exception"
:
case
"Exception"
:
case
"Session"
:
case
"Session"
:
case
"DQL"
:
case
"DQL"
:
case
"Sensei"
:
$a
[]
=
self
::
$path
.
DIRECTORY_SEPARATOR
.
$entry
;
$a
[]
=
self
::
$path
.
DIRECTORY_SEPARATOR
.
$entry
;
break
;
break
;
default
:
default
:
...
...
classes/Record.class.php
View file @
b6e93657
...
@@ -385,19 +385,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -385,19 +385,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if
(
$this
->
state
!=
Doctrine_Record
::
STATE_TDIRTY
&&
if
(
$this
->
state
!=
Doctrine_Record
::
STATE_TDIRTY
&&
$this
->
state
!=
Doctrine_Record
::
STATE_TCLEAN
&&
$this
->
state
!=
Doctrine_Record
::
STATE_TCLEAN
&&
$this
->
state
!=
Doctrine_Record
::
STATE_CLEAN
)
{
$this
->
state
!=
Doctrine_Record
::
STATE_CLEAN
)
{
$this
->
loaded
=
true
;
if
(
!
empty
(
$this
->
collections
))
{
if
(
!
empty
(
$this
->
collections
))
{
foreach
(
$this
->
collections
as
$collection
)
{
foreach
(
$this
->
collections
as
$collection
)
{
$collection
->
load
(
$this
);
$collection
->
load
(
$this
);
}
}
}
else
{
}
else
{
$this
->
refresh
();
$this
->
refresh
();
}
}
$this
->
state
=
Doctrine_Record
::
STATE_CLEAN
;
$this
->
state
=
Doctrine_Record
::
STATE_CLEAN
;
}
}
$this
->
loaded
=
true
;
}
}
if
(
is_array
(
$this
->
data
[
$name
]))
if
(
is_array
(
$this
->
data
[
$name
]))
...
@@ -458,6 +456,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -458,6 +456,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
modified
[]
=
$name
;
$this
->
modified
[]
=
$name
;
switch
(
$this
->
state
)
:
switch
(
$this
->
state
)
:
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_PROXY
:
case
Doctrine_Record
::
STATE_PROXY
:
...
...
classes/Sensei/Sensei.class.php
0 → 100644
View file @
b6e93657
<?php
class
Sensei_Group
extends
Doctrine_Record
{
}
//class Sensei_Company extends Sensei_Group { }
class
Sensei_User
extends
Doctrine_Record
{
}
//class Sensei_Customer extends Sensei_User { }
class
Sensei_Entity
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"loginname"
,
"string"
,
32
,
"unique"
);
$this
->
hasColumn
(
"password"
,
"string"
,
32
);
}
}
class
Sensei_Variable
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
50
);
$this
->
hasColumn
(
"value"
,
"string"
,
10000
);
$this
->
hasColumn
(
"session_id"
,
"integer"
);
}
}
class
Sensei_Entity_Var
extends
Sensei_Variable
{
}
class
Sensei_Session_Var
extends
Doctrine_Record
{
}
class
Sensei_Session
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
ownsMany
(
"Sensei_variable"
,
"Sensei_variable.session_id"
);
$this
->
hasOne
(
"Sensei_entity"
,
"Sensei_session.entity_id"
);
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"session_id"
,
"string"
,
32
);
$this
->
hasColumn
(
"logged_in"
,
"integer"
,
1
);
$this
->
hasColumn
(
"entity_id"
,
"integer"
);
$this
->
hasColumn
(
"user_agent"
,
"string"
,
200
);
$this
->
hasColumn
(
"updated"
,
"integer"
);
$this
->
hasColumn
(
"created"
,
"integer"
);
}
}
class
Sensei_Exception
extends
Exception
{
}
class
Sensei
extends
Doctrine_Access
{
const
ATTR_LIFESPAN
=
0
;
/**
* @var Sensei_Session $record
*/
private
$record
;
/**
* @var Doctrine_Session $session
*/
private
$session
;
/**
* @var Doctrine_Table $table
*/
private
$table
;
/**
* @var array $attributes
*/
private
$attributes
=
array
();
/**
* @var Doctrine_Collection $vars
*/
private
$vars
;
public
function
__construct
()
{
if
(
headers_sent
())
throw
new
Sensei_Exception
(
"Headers already sent. Couldn't initialize session."
);
$this
->
session
=
Doctrine_Manager
::
getInstance
()
->
getCurrentSession
();
$this
->
table
=
$this
->
session
->
getTable
(
"Sensei_session"
);
$this
->
init
();
$this
->
gc
(
1
);
if
(
!
isset
(
$_SESSION
))
session_start
();
}
/**
* getRecord
*/
public
function
getRecord
()
{
return
$this
->
record
;
}
/**
* init
*/
private
function
init
()
{
session_set_save_handler
(
array
(
$this
,
"open"
),
array
(
$this
,
"close"
),
array
(
$this
,
"read"
),
array
(
$this
,
"write"
),
array
(
$this
,
"destroy"
),
array
(
$this
,
"gc"
)
);
}
/**
* @param string $username
* @param string $password
* @return boolean
*/
public
function
login
(
$username
,
$password
)
{
$coll
=
$this
->
session
->
query
(
"FROM Sensei_Entity WHERE Sensei_Entity.loginname = ? && Sensei_Entity.password = ?"
,
array
(
$username
,
$password
));
if
(
count
(
$coll
)
>
0
)
{
$this
->
record
->
logged_in
=
1
;
$this
->
record
->
entity_id
=
$coll
[
0
]
->
getID
();
$this
->
record
->
save
();
return
true
;
}
return
false
;
}
/**
* logout
* @return boolean
*/
public
function
logout
()
{
if
(
$this
->
record
->
logged_in
==
true
)
{
$this
->
record
->
logged_in
=
0
;
$this
->
record
->
entity_id
=
0
;
return
true
;
}
else
{
return
false
;
}
}
public
function
get
(
$name
)
{
foreach
(
$this
->
vars
as
$var
)
{
if
(
$var
->
name
==
$name
)
{
return
$var
->
value
;
}
}
}
public
function
set
(
$name
,
$value
)
{
foreach
(
$this
->
vars
as
$var
)
{
if
(
$var
->
name
==
$name
)
{
$var
->
value
=
$value
;
return
true
;
}
}
return
false
;
}
public
function
setAttribute
(
$attr
,
$value
)
{
switch
(
$attr
)
:
case
Sensei
::
ATTR_LIFESPAN
:
break
;
default
:
throw
new
Sensei_Exception
(
"Unknown attribute"
);
endswitch
;
$this
->
attributes
[
$attr
]
=
$value
;
}
private
function
open
(
$save_path
,
$session_name
)
{
return
true
;
}
public
function
close
()
{
return
true
;
}
private
function
read
(
$id
)
{
$coll
=
$this
->
session
->
query
(
"FROM Sensei_Session WHERE Sensei_Session.session_id = ?"
,
array
(
$id
));
$this
->
record
=
$coll
[
0
];
$this
->
record
->
user_agent
=
$_SERVER
[
'HTTP_USER_AGENT'
];
$this
->
record
->
updated
=
time
();
$this
->
record
->
session_id
=
$id
;
if
(
$this
->
record
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
)
{
$this
->
record
->
created
=
time
();
$this
->
record
->
save
();
}
$this
->
vars
=
$this
->
record
->
Sensei_variable
;
return
""
;
}
public
function
write
(
$id
,
$sess_data
)
{
return
true
;
}
private
function
destroy
(
$id
)
{
$this
->
record
->
delete
();
return
$r
;
}
private
function
gc
(
$maxlifetime
)
{
return
true
;
}
public
function
flush
()
{
$this
->
record
->
save
();
}
public
function
__destruct
()
{
$this
->
flush
();
}
}
?>
classes/Session.class.php
View file @
b6e93657
...
@@ -169,13 +169,15 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
...
@@ -169,13 +169,15 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
if
(
isset
(
$this
->
tables
[
$name
]))
if
(
isset
(
$this
->
tables
[
$name
]))
return
$this
->
tables
[
$name
];
return
$this
->
tables
[
$name
];
$class
=
$name
.
"Table"
;
$class
=
$name
.
"Table"
;
if
(
class_exists
(
$class
,
false
)
&&
in_array
(
"Doctrine_Table"
,
class_parents
(
$class
)))
if
(
class_exists
(
$class
,
false
)
&&
in_array
(
"Doctrine_Table"
,
class_parents
(
$class
)))
{
return
new
$class
(
$name
);
return
new
$class
(
$name
);
else
}
else
{
return
new
Doctrine_Table
(
$name
);
return
new
Doctrine_Table
(
$name
);
}
}
}
/**
/**
* @return array -- an array of all initialized tables
* @return array -- an array of all initialized tables
...
...
classes/Table.class.php
View file @
b6e93657
...
@@ -145,8 +145,6 @@ class Doctrine_Table extends Doctrine_Configurable {
...
@@ -145,8 +145,6 @@ class Doctrine_Table extends Doctrine_Configurable {
if
(
isset
(
$this
->
columns
))
{
if
(
isset
(
$this
->
columns
))
{
$method
=
new
ReflectionMethod
(
$this
->
name
,
"setTableDefinition"
);
$method
=
new
ReflectionMethod
(
$this
->
name
,
"setTableDefinition"
);
$class
=
$method
->
getDeclaringClass
();
$class
=
$method
->
getDeclaringClass
();
print
$class
->
getName
();
if
(
!
isset
(
$this
->
tableName
))
if
(
!
isset
(
$this
->
tableName
))
$this
->
tableName
=
strtolower
(
$class
->
getName
());
$this
->
tableName
=
strtolower
(
$class
->
getName
());
...
...
classes/Validator/
B
lank.class.php
→
classes/Validator/
Notb
lank.class.php
View file @
b6e93657
<?php
<?php
class
Doctrine_Validator_
B
lank
{
class
Doctrine_Validator_
Notb
lank
{
/**
/**
* @param Doctrine_Record $record
* @param Doctrine_Record $record
* @param string $key
* @param string $key
...
...
tests/SenseiTestCase.class.php
0 → 100644
View file @
b6e93657
<?php
require_once
(
"../classes/Doctrine.class.php"
);
Doctrine
::
loadAll
();
class
Sensei_UnitTestCase
extends
UnitTestCase
{
protected
$manager
;
protected
$session
;
protected
$dbh
;
protected
$listener
;
protected
$users
;
protected
$tables
;
private
$init
=
false
;
public
function
init
()
{
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
Doctrine
::
CACHE_NONE
);
if
(
$this
->
manager
->
count
()
>
0
)
{
$this
->
session
=
$this
->
manager
->
getSession
(
0
);
$this
->
session
->
clear
();
$this
->
dbh
=
$this
->
session
->
getDBH
();
$this
->
listener
=
$this
->
manager
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
);
}
else
{
$this
->
dbh
=
Doctrine_DB
::
getConnection
();
$this
->
session
=
$this
->
manager
->
openSession
(
$this
->
dbh
);
}
$this
->
tables
=
array
(
"sensei_group"
,
"sensei_user"
,
"sensei_entity"
,
"sensei_session"
,
"sensei_variable"
);
$tables
=
$this
->
tables
;
foreach
(
$tables
as
$name
)
{
$this
->
dbh
->
query
(
"DROP TABLE IF EXISTS
$name
"
);
}
$this
->
sensei
=
new
Sensei
();
$entity
=
new
Sensei_Entity
();
$entity
->
loginname
=
"Chuck Norris"
;
$entity
->
password
=
"toughguy"
;
$entity
->
save
();
$this
->
init
=
true
;
$this
->
record
=
$this
->
sensei
->
getRecord
();
}
public
function
setUp
()
{
if
(
!
$this
->
init
)
$this
->
init
();
}
public
function
testConstructor
()
{
$this
->
assertTrue
(
$this
->
record
instanceof
Sensei_Session
);
if
(
isset
(
$_COOKIE
[
"PHPSESSID"
]))
{
$this
->
assertEqual
(
$this
->
record
->
session_id
,
$_COOKIE
[
"PHPSESSID"
]);
}
$updated
=
$this
->
record
->
updated
;
$this
->
assertFalse
(
empty
(
$updated
));
$created
=
$this
->
record
->
created
;
$this
->
assertFalse
(
empty
(
$created
));
$this
->
assertEqual
(
$this
->
record
->
user_agent
,
$_SERVER
[
'HTTP_USER_AGENT'
]);
// make the changes persistent
$this
->
sensei
->
flush
();
if
(
isset
(
$_COOKIE
[
"PHPSESSID"
]))
{
$this
->
assertEqual
(
$this
->
record
->
session_id
,
$_COOKIE
[
"PHPSESSID"
]);
}
$updated
=
$this
->
record
->
updated
;
$this
->
assertFalse
(
empty
(
$updated
));
$created
=
$this
->
record
->
created
;
$this
->
assertFalse
(
empty
(
$created
));
$this
->
assertEqual
(
$this
->
record
->
user_agent
,
$_SERVER
[
'HTTP_USER_AGENT'
]);
}
public
function
testLogin
()
{
$this
->
assertFalse
(
$this
->
sensei
->
login
(
'Chuck Norris'
,
'unknown'
));
$this
->
assertEqual
(
$this
->
record
->
logged_in
,
null
);
$this
->
assertEqual
(
$this
->
record
->
entity_id
,
null
);
$this
->
assertTrue
(
$this
->
sensei
->
login
(
'Chuck Norris'
,
'toughguy'
));
$this
->
assertEqual
(
$this
->
record
->
logged_in
,
1
);
$this
->
assertEqual
(
$this
->
record
->
entity_id
,
1
);
}
public
function
testLogout
()
{
$this
->
assertTrue
(
$this
->
sensei
->
logout
());
$this
->
assertEqual
(
$this
->
record
->
logged_in
,
0
);
$this
->
assertEqual
(
$this
->
record
->
entity_id
,
0
);
$this
->
sensei
->
flush
();
$this
->
assertEqual
(
$this
->
record
->
logged_in
,
0
);
$this
->
assertEqual
(
$this
->
record
->
entity_id
,
0
);
}
}
?>
tests/UnitTestCase.class.php
View file @
b6e93657
...
@@ -30,13 +30,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -30,13 +30,10 @@ class Doctrine_UnitTestCase extends UnitTestCase {
protected
$users
;
protected
$users
;
protected
$tables
;
protected
$tables
;
private
static
$instances
;
private
$init
=
false
;
private
$init
=
false
;
public
function
init
()
{
public
function
init
()
{
$name
=
get_class
(
$this
);
$name
=
get_class
(
$this
);
if
(
!
isset
(
$instances
[
$name
]))
$instances
[
$name
]
=
$this
;
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
=
Doctrine_Manager
::
getInstance
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
Doctrine
::
CACHE_NONE
);
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
Doctrine
::
CACHE_NONE
);
...
@@ -61,6 +58,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -61,6 +58,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
foreach
(
$tables
as
$name
)
{
foreach
(
$tables
as
$name
)
{
$table
=
$this
->
session
->
getTable
(
$name
);
$table
=
$this
->
session
->
getTable
(
$name
);
$table
->
getCache
()
->
deleteAll
();
$table
->
getCache
()
->
deleteAll
();
}
}
...
...
tests/run.php
View file @
b6e93657
<?php
<?php
ob_start
();
require_once
(
"ConfigurableTestCase.class.php"
);
require_once
(
"ConfigurableTestCase.class.php"
);
require_once
(
"ManagerTestCase.class.php"
);
require_once
(
"ManagerTestCase.class.php"
);
require_once
(
"SessionTestCase.class.php"
);
require_once
(
"SessionTestCase.class.php"
);
...
@@ -13,6 +13,7 @@ require_once("AccessTestCase.class.php");
...
@@ -13,6 +13,7 @@ require_once("AccessTestCase.class.php");
require_once
(
"ValidatorTestCase.class.php"
);
require_once
(
"ValidatorTestCase.class.php"
);
require_once
(
"CacheSqliteTestCase.class.php"
);
require_once
(
"CacheSqliteTestCase.class.php"
);
require_once
(
"SenseiTestCase.class.php"
);
print
"<pre>"
;
print
"<pre>"
;
...
@@ -23,7 +24,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
...
@@ -23,7 +24,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
...
@@ -40,6 +41,8 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
...
@@ -40,6 +41,8 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
*/
$test
->
addTestCase
(
new
Sensei_UnitTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
@@ -71,5 +74,5 @@ print "Executed queries: ".count($a)."\n";
...
@@ -71,5 +74,5 @@ print "Executed queries: ".count($a)."\n";
foreach
(
$a
as
$query
)
{
foreach
(
$a
as
$query
)
{
print
$query
.
"
\n
"
;
print
$query
.
"
\n
"
;
}
}
ob_end_flush
();
?>
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment