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
d9733637
Commit
d9733637
authored
Jan 07, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finally first, very basic, running CRUD tests for Doctrine 2
parent
1f6676f1
Changes
46
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
46 changed files
with
796 additions
and
312 deletions
+796
-312
Connection.php
lib/Doctrine/DBAL/Connection.php
+13
-8
Connection.php
lib/Doctrine/DBAL/Driver/Connection.php
+1
-2
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+1
-1
PDOStatement.php
lib/Doctrine/DBAL/Driver/PDOStatement.php
+3
-1
Statement.php
lib/Doctrine/DBAL/Driver/Statement.php
+2
-2
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+65
-23
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+36
-6
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+157
-1
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+7
-2
MySqlSchemaManger.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManger.php
+2
-7
OracleSchemaManager.php
lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
+2
-7
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+2
-12
SqliteSchemaManager.php
lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
+4
-126
ArrayType.php
lib/Doctrine/DBAL/Types/ArrayType.php
+1
-2
BigIntType.php
lib/Doctrine/DBAL/Types/BigIntType.php
+16
-0
BooleanType.php
lib/Doctrine/DBAL/Types/BooleanType.php
+0
-1
CharType.php
lib/Doctrine/DBAL/Types/CharType.php
+11
-0
IntegerType.php
lib/Doctrine/DBAL/Types/IntegerType.php
+11
-6
MediumIntType.php
lib/Doctrine/DBAL/Types/MediumIntType.php
+15
-0
SmallIntType.php
lib/Doctrine/DBAL/Types/SmallIntType.php
+15
-0
TextType.php
lib/Doctrine/DBAL/Types/TextType.php
+1
-9
TinyIntType.php
lib/Doctrine/DBAL/Types/TinyIntType.php
+15
-0
Type.php
lib/Doctrine/DBAL/Types/Type.php
+21
-12
VarcharType.php
lib/Doctrine/DBAL/Types/VarcharType.php
+27
-0
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+8
-8
EntityRepository.php
lib/Doctrine/ORM/EntityRepository.php
+7
-5
ClassExporter.php
lib/Doctrine/ORM/Export/ClassExporter.php
+142
-0
ClassMetadata.php
lib/Doctrine/ORM/Mapping/ClassMetadata.php
+3
-1
AnnotationDriver.php
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
+5
-9
annotations.php
lib/Doctrine/ORM/Mapping/Driver/addendum/annotations.php
+6
-6
AbstractEntityPersister.php
lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
+12
-29
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+16
-4
AllTests.php
tests/Orm/Functional/AllTests.php
+35
-0
BasicCRUDTest.php
tests/Orm/Functional/BasicCRUDTest.php
+38
-0
1Test.php
tests/Orm/Functional/Ticket/1Test.php
+10
-0
AllTests.php
tests/Orm/Functional/Ticket/AllTests.php
+30
-0
Doctrine_OrmFunctionalTestCase.php
tests/lib/Doctrine_OrmFunctionalTestCase.php
+22
-9
Doctrine_DatabasePlatformMock.php
tests/lib/mocks/Doctrine_DatabasePlatformMock.php
+21
-0
Doctrine_DriverConnectionMock.php
tests/lib/mocks/Doctrine_DriverConnectionMock.php
+1
-1
CmsArticle.php
tests/models/cms/CmsArticle.php
+2
-2
CmsComment.php
tests/models/cms/CmsComment.php
+2
-2
CmsPhonenumber.php
tests/models/cms/CmsPhonenumber.php
+1
-1
CmsUser.php
tests/models/cms/CmsUser.php
+3
-3
ForumCategory.php
tests/models/forum/ForumCategory.php
+1
-1
ForumEntry.php
tests/models/forum/ForumEntry.php
+1
-1
ForumUser.php
tests/models/forum/ForumUser.php
+2
-2
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
d9733637
...
...
@@ -216,9 +216,7 @@ class Doctrine_DBAL_Connection
*/
public
function
connect
()
{
if
(
$this
->
_isConnected
)
{
return
false
;
}
if
(
$this
->
_isConnected
)
return
false
;
$driverOptions
=
isset
(
$this
->
_params
[
'driverOptions'
])
?
$this
->
_params
[
'driverOptions'
]
:
array
();
...
...
@@ -259,6 +257,7 @@ class Doctrine_DBAL_Connection
*/
public
function
delete
(
$tableName
,
array
$identifier
)
{
$this
->
connect
();
$criteria
=
array
();
foreach
(
array_keys
(
$identifier
)
as
$id
)
{
$criteria
[]
=
$this
->
quoteIdentifier
(
$id
)
.
' = ?'
;
...
...
@@ -282,6 +281,7 @@ class Doctrine_DBAL_Connection
*/
public
function
update
(
$tableName
,
array
$data
,
array
$identifier
)
{
$this
->
connect
();
if
(
empty
(
$data
))
{
return
false
;
}
...
...
@@ -316,6 +316,7 @@ class Doctrine_DBAL_Connection
*/
public
function
insert
(
$tableName
,
array
$data
)
{
$this
->
connect
();
if
(
empty
(
$data
))
{
return
false
;
}
...
...
@@ -326,7 +327,7 @@ class Doctrine_DBAL_Connection
$a
=
array
();
foreach
(
$data
as
$columnName
=>
$value
)
{
$cols
[]
=
$this
->
quoteIdentifier
(
$columnName
);
if
(
$value
instanceof
Doctrine_Expression
)
{
if
(
$value
instanceof
Doctrine_
DBAL_
Expression
)
{
$a
[]
=
$value
->
getSql
();
unset
(
$data
[
$columnName
]);
}
else
{
...
...
@@ -395,6 +396,7 @@ class Doctrine_DBAL_Connection
*/
public
function
quote
(
$input
,
$type
=
null
)
{
$this
->
connect
();
return
$this
->
_conn
->
quote
(
$input
,
$type
);
}
...
...
@@ -492,10 +494,10 @@ class Doctrine_DBAL_Connection
*/
public
function
prepare
(
$statement
)
{
echo
$statement
;
$this
->
connect
();
try
{
$stmt
=
$this
->
_conn
->
prepare
(
$statement
);
return
new
Doctrine_DBAL_Statement
(
$this
,
$stmt
);
return
$this
->
_conn
->
prepare
(
$statement
);
}
catch
(
PDOException
$e
)
{
$this
->
rethrowException
(
$e
,
$this
);
}
...
...
@@ -530,6 +532,7 @@ class Doctrine_DBAL_Connection
{
$this
->
connect
();
try
{
echo
$query
.
PHP_EOL
;
if
(
!
empty
(
$params
))
{
$stmt
=
$this
->
prepare
(
$query
);
$stmt
->
execute
(
$params
);
...
...
@@ -566,7 +569,7 @@ class Doctrine_DBAL_Connection
return
$count
;
}
}
catch
(
PDOException
$e
)
{
$this
->
rethrowException
(
$e
,
$this
)
;
throw
$e
;
}
}
...
...
@@ -577,7 +580,7 @@ class Doctrine_DBAL_Connection
*/
public
function
rethrowException
(
Exception
$e
,
$invoker
)
{
throw
$e
xc
;
throw
$e
;
}
/**
...
...
@@ -667,6 +670,7 @@ class Doctrine_DBAL_Connection
*/
public
function
lastInsertId
(
$seqName
=
null
)
{
$this
->
connect
();
return
$this
->
_conn
->
lastInsertId
(
$seqName
);
}
...
...
@@ -680,6 +684,7 @@ class Doctrine_DBAL_Connection
*/
public
function
beginTransaction
()
{
$this
->
connect
();
if
(
$this
->
_transactionNestingLevel
==
0
)
{
return
$this
->
_conn
->
beginTransaction
();
}
...
...
lib/Doctrine/DBAL/Driver/Connection.php
View file @
d9733637
...
...
@@ -11,7 +11,7 @@
interface
Doctrine_DBAL_Driver_Connection
{
public
function
prepare
(
$prepareString
);
public
function
query
(
$queryString
);
public
function
query
();
public
function
quote
(
$input
);
public
function
exec
(
$statement
);
public
function
lastInsertId
();
...
...
@@ -22,4 +22,3 @@ interface Doctrine_DBAL_Driver_Connection
public
function
errorInfo
();
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
d9733637
...
...
@@ -59,7 +59,7 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver
* Gets the schema manager that is relevant for this driver.
*
* @param Doctrine\DBAL\Connection $conn
* @return Doctrine\DBAL\Schema\
Abstract
SchemaManager
* @return Doctrine\DBAL\Schema\
Sqlite
SchemaManager
*/
public
function
getSchemaManager
(
Doctrine_DBAL_Connection
$conn
)
{
...
...
lib/Doctrine/DBAL/Driver/PDOStatement.php
View file @
d9733637
<?php
class
Doctrine_DBAL_Driver_PDOStatement
extends
PDOStatement
implements
Doctrine_DBAL_Driver_Statement
{}
{
private
function
__construct
()
{}
}
lib/Doctrine/DBAL/Driver/Statement.php
View file @
d9733637
...
...
@@ -46,7 +46,7 @@ interface Doctrine_DBAL_Driver_Statement
* @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
* @return boolean Returns TRUE on success or FALSE on failure
*/
public
function
bindColumn
(
$column
,
$param
,
$type
=
null
);
public
function
bindColumn
(
$column
,
&
$param
,
$type
=
null
);
/**
* bindValue
...
...
@@ -292,5 +292,5 @@ interface Doctrine_DBAL_Driver_Statement
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
* @return boolean Returns 1 on success or FALSE on failure.
*/
public
function
setFetchMode
(
$mode
,
$arg1
=
null
,
$arg2
=
null
);
public
function
setFetchMode
(
$mode
,
$arg1
);
}
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
d9733637
...
...
@@ -991,7 +991,7 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
}
$queryFields
=
$this
->
getFieldDeclarationList
(
$columns
);
$queryFields
=
$this
->
getFieldDeclarationList
Sql
(
$columns
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
...
...
@@ -1193,7 +1193,7 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
}
/**
* Get declaration of a number of field in bulk
* Get declaration of a number of field
s
in bulk
*
* @param array $fields a multidimensional associative array.
* The first dimension determines the field name, while the second
...
...
@@ -1223,9 +1223,9 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
*/
public
function
getFieldDeclarationListSql
(
array
$fields
)
{
$queryFields
=
array
();
foreach
(
$fields
as
$fieldName
=>
$field
)
{
$query
=
$this
->
getDeclarationSql
(
$fieldName
,
$field
);
$queryFields
[]
=
$query
;
}
return
implode
(
', '
,
$queryFields
);
...
...
@@ -1265,32 +1265,63 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
*/
public
function
getDeclarationSql
(
$name
,
array
$field
)
{
$default
=
$this
->
getDefaultFieldDeclarationSql
(
$field
);
$default
=
$this
->
getDefaultFieldDeclarationSql
(
$field
);
$charset
=
(
isset
(
$field
[
'charset'
])
&&
$field
[
'charset'
])
?
' '
.
$this
->
getCharsetFieldDeclarationSql
(
$field
[
'charset'
])
:
''
;
$collation
=
(
isset
(
$field
[
'collation'
])
&&
$field
[
'collation'
])
?
' '
.
$this
->
getCollationFieldDeclarationSql
(
$field
[
'collation'
])
:
''
;
$notnull
=
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
?
' NOT NULL'
:
''
;
$unique
=
(
isset
(
$field
[
'unique'
])
&&
$field
[
'unique'
])
?
' '
.
$this
->
getUniqueFieldDeclarationSql
()
:
''
;
$check
=
(
isset
(
$field
[
'check'
])
&&
$field
[
'check'
])
?
' '
.
$field
[
'check'
]
:
''
;
$charset
=
(
isset
(
$field
[
'charset'
])
&&
$field
[
'charset'
])
?
' '
.
$this
->
getCharsetFieldDeclarationSql
(
$field
[
'charset'
])
:
''
;
$typeDecl
=
$field
[
'type'
]
->
getSqlDeclaration
(
$field
,
$this
);
return
$this
->
quoteIdentifier
(
$name
,
true
)
.
' '
.
$typeDecl
.
$charset
.
$default
.
$notnull
.
$unique
.
$check
.
$collation
;
}
$collation
=
(
isset
(
$field
[
'collation'
])
&&
$field
[
'collation'
])
?
' '
.
$this
->
getCollationFieldDeclarationSql
(
$field
[
'collation'
])
:
''
;
/**
*
* @param <type> $name
* @param <type> $field
*/
abstract
public
function
getIntegerTypeDeclarationSql
(
array
$columnDef
);
$notnull
=
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
?
' NOT NULL'
:
''
;
/**
* Gets the SQL snippet that declares a BIGINT column.
*
* @return string
*/
abstract
public
function
getBigIntTypeDeclarationSql
(
array
$columnDef
);
$unique
=
(
isset
(
$field
[
'unique'
])
&&
$field
[
'unique'
])
?
' '
.
$this
->
getUniqueFieldDeclarationSql
()
:
''
;
/**
* Gets the SQL snippet that declares a TINYINT column.
*
* @return string
*/
abstract
public
function
getTinyIntTypeDeclarationSql
(
array
$columnDef
);
$check
=
(
isset
(
$field
[
'check'
])
&&
$field
[
'check'
])
?
' '
.
$field
[
'check'
]
:
''
;
/**
* Gets the SQL snippet that declares a SMALLINT column.
*
* @return string
*/
abstract
public
function
getSmallIntTypeDeclarationSql
(
array
$columnDef
);
$method
=
'get'
.
$field
[
'type'
]
.
'Declaration'
;
/**
* Gets the SQL snippet that declares a MEDIUMINT column.
*
* @return string
*/
abstract
public
function
getMediumIntTypeDeclarationSql
(
array
$columnDef
);
if
(
method_exists
(
$this
,
$method
))
{
return
$this
->
$method
(
$name
,
$field
);
}
else
{
$dec
=
$this
->
getNativeDeclaration
(
$field
);
}
return
$this
->
quoteIdentifier
(
$name
,
true
)
.
' '
.
$dec
.
$charset
.
$default
.
$notnull
.
$unique
.
$check
.
$collation
;
}
/**
* Gets the SQL snippet that declares common properties of an integer column.
*
* @return string
*/
abstract
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
);
/**
* getDefaultDeclaration
...
...
@@ -1858,7 +1889,18 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform
{
return
true
;
}
public
function
getIdentityColumnNullInsertSql
()
{
return
""
;
}
/**
* Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
*
* @params array $field
*/
abstract
public
function
getVarcharDeclarationSql
(
array
$field
);
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
d9733637
...
...
@@ -230,7 +230,9 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
}
/**
* @TEST
* Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
*
* @params array $field
*/
public
function
getVarcharDeclarationSql
(
array
$field
)
{
...
...
@@ -243,7 +245,7 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
}
$length
=
(
$field
[
'length'
]
<=
$this
->
getVarcharMaxLength
())
?
$field
[
'length'
]
:
false
;
$fixed
=
(
isset
(
$field
[
'fixed'
]))
?
$field
[
'fixed'
]
:
false
;
$fixed
=
(
isset
(
$field
[
'fixed'
]))
?
$field
[
'fixed'
]
:
false
;
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
...
...
@@ -1037,7 +1039,37 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
* declare the specified field.
* @override
*/
public
function
getIntegerDeclarationSql
(
$name
,
$field
)
public
function
getIntegerTypeDeclarationSql
(
array
$field
)
{
return
'INT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getBigIntTypeDeclarationSql
(
array
$field
)
{
return
'BIGINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getTinyIntTypeDeclarationSql
(
array
$field
)
{
return
'TINYINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getSmallIntDeclarationSql
(
array
$field
)
{
return
'SMALLINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getMediumIntDeclarationSql
(
array
$field
)
{
return
'MEDIUMINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
$default
=
$autoinc
=
''
;
if
(
!
empty
(
$field
[
'autoincrement'
]))
{
...
...
@@ -1058,9 +1090,7 @@ class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_Abst
$notnull
=
(
isset
(
$field
[
'notnull'
])
&&
$field
[
'notnull'
])
?
' NOT NULL'
:
''
;
$unsigned
=
(
isset
(
$field
[
'unsigned'
])
&&
$field
[
'unsigned'
])
?
' UNSIGNED'
:
''
;
$name
=
$this
->
quoteIdentifier
(
$name
,
true
);
return
$name
.
' '
.
$this
->
getNativeDeclaration
(
$field
)
.
$unsigned
.
$default
.
$notnull
.
$autoinc
;
return
$unsigned
.
$default
.
$notnull
.
$autoinc
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
d9733637
...
...
@@ -391,6 +391,162 @@ class Doctrine_DBAL_Platforms_SqlitePlatform extends Doctrine_DBAL_Platforms_Abs
{
return
'PRAGMA read_uncommitted = '
.
$this
->
_getTransactionIsolationLevelSql
(
$level
);
}
/** @override */
public
function
prefersIdentityColumns
()
{
return
true
;
}
/** @override */
public
function
getIntegerTypeDeclarationSql
(
array
$field
)
{
return
'INT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getBigIntTypeDeclarationSql
(
array
$field
)
{
return
'BIGINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getTinyIntTypeDeclarationSql
(
array
$field
)
{
return
'TINYINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getSmallIntTypeDeclarationSql
(
array
$field
)
{
return
'SMALLINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
public
function
getMediumIntTypeDeclarationSql
(
array
$field
)
{
return
'MEDIUMINT '
.
$this
->
_getCommonIntegerTypeDeclarationSql
(
$field
);
}
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{
$default
=
$autoinc
=
''
;
if
(
!
empty
(
$columnDef
[
'autoincrement'
]))
{
$autoinc
=
' AUTO_INCREMENT'
;
}
else
if
(
array_key_exists
(
'default'
,
$columnDef
))
{
if
(
$field
[
'default'
]
===
''
)
{
$field
[
'default'
]
=
empty
(
$columnDef
[
'notnull'
])
?
null
:
0
;
}
if
(
is_null
(
$columnDef
[
'default'
]))
{
$default
=
' DEFAULT NULL'
;
}
else
{
$default
=
' DEFAULT '
.
$this
->
quote
(
$columnDef
[
'default'
]);
}
}
else
if
(
empty
(
$columnDef
[
'notnull'
]))
{
$default
=
' DEFAULT NULL'
;
}
$notnull
=
(
isset
(
$columnDef
[
'notnull'
])
&&
$columnDef
[
'notnull'
])
?
' NOT NULL'
:
''
;
$unsigned
=
(
isset
(
$columnDef
[
'unsigned'
])
&&
$columnDef
[
'unsigned'
])
?
' UNSIGNED'
:
''
;
return
$unsigned
.
$default
.
$notnull
.
$autoinc
;
}
/**
* create a new table
*
* @param string $name Name of the database that should be created
* @param array $fields Associative array that contains the definition of each field of the new table
* The indexes of the array entries are the names of the fields of the table an
* the array entry values are associative arrays like those that are meant to be
* passed with the field definitions to get[Type]Declaration() functions.
* array(
* 'id' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* 'notnull' => 1
* 'default' => 0
* ),
* 'name' => array(
* 'type' => 'text',
* 'length' => 12
* ),
* 'password' => array(
* 'type' => 'text',
* 'length' => 12
* )
* );
* @param array $options An associative array of table options:
*
* @return void
* @override
*/
public
function
getCreateTableSql
(
$name
,
array
$fields
,
array
$options
=
array
())
{
if
(
!
$name
)
{
throw
new
Doctrine_Exception
(
'no valid table name specified'
);
}
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Exception
(
'no fields specified for table '
.
$name
);
}
$queryFields
=
$this
->
getFieldDeclarationListSql
(
$fields
);
$autoinc
=
false
;
foreach
(
$fields
as
$field
)
{
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
]
||
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
]))
{
$autoinc
=
true
;
break
;
}
}
if
(
!
$autoinc
&&
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$keyColumns
=
array_values
(
$options
[
'primary'
]);
$keyColumns
=
array_map
(
array
(
$this
->
_conn
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$name
=
$this
->
quoteIdentifier
(
$name
,
true
);
$sql
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
;
if
(
$check
=
$this
->
getCheckDeclarationSql
(
$fields
))
{
$sql
.=
', '
.
$check
;
}
if
(
isset
(
$options
[
'checks'
])
&&
$check
=
$this
->
getCheckDeclarationSql
(
$options
[
'checks'
]))
{
$sql
.=
', '
.
$check
;
}
$sql
.=
')'
;
$query
[]
=
$sql
;
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
$query
[]
=
$this
->
createIndexSql
(
$name
,
$index
,
$definition
);
}
}
return
$query
;
}
/**
* {@inheritdoc}
*/
public
function
getVarcharDeclarationSql
(
array
$field
)
{
if
(
!
isset
(
$field
[
'length'
]))
{
if
(
array_key_exists
(
'default'
,
$field
))
{
$field
[
'length'
]
=
$this
->
getVarcharMaxLength
();
}
else
{
$field
[
'length'
]
=
false
;
}
}
$length
=
(
$field
[
'length'
]
<=
$this
->
getVarcharMaxLength
())
?
$field
[
'length'
]
:
false
;
$fixed
=
(
isset
(
$field
[
'fixed'
]))
?
$field
[
'fixed'
]
:
false
;
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
}
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Schema/SchemaManager.php
→
lib/Doctrine/DBAL/Schema/
Abstract
SchemaManager.php
View file @
d9733637
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::DBAL::
Schema;
#namespace Doctrine
\DBAL\
Schema;
/**
* Base class for schema managers. Schema managers are used to inspect and/or
...
...
@@ -28,14 +28,19 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @version $Revision$
* @since 2.0
* @todo Rename to AbstractSchemaManager
*/
abstract
class
Doctrine_DBAL_Schema_AbstractSchemaManager
{
protected
$_conn
;
public
function
__construct
(
Doctrine_DBAL_Connection
$conn
)
{
$this
->
_conn
=
$conn
;
}
/**
* lists all databases
*
...
...
lib/Doctrine/DBAL/Schema/MySqlSchemaManger.php
View file @
d9733637
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::DBAL::
Schema;
#namespace Doctrine
\DBAL\
Schema;
/**
* xxx
...
...
@@ -31,12 +31,7 @@
* @since 2.0
*/
class
Doctrine_DBAL_Schema_MySqlSchemaManager
extends
Doctrine_DBAL_Schema_AbstractSchemaManager
{
public
function
__construct
(
Doctrine_Connection
$conn
)
{
$this
->
_conn
=
$conn
;
}
{
/**
* lists all database sequences
*
...
...
lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
View file @
d9733637
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::DBAL::
Schema;
#namespace Doctrine
\DBAL\
Schema;
/**
* xxx
...
...
@@ -31,12 +31,7 @@
* @since 2.0
*/
class
Doctrine_DBAL_Schema_OracleSchemaManager
extends
Doctrine_DBAL_Schema_AbstractSchemaManager
{
public
function
__construct
(
Doctrine_Connection_Oracle
$conn
)
{
$this
->
_conn
=
$conn
;
}
{
/**
* create a new database
*
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
d9733637
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::DBAL::
Schema;
#namespace Doctrine
\DBAL\
Schema;
/**
* xxx
...
...
@@ -31,17 +31,7 @@
* @since 2.0
*/
class
Doctrine_DBAL_Schema_PostgreSqlSchemaManager
extends
Doctrine_DBAL_Schema_AbstractSchemaManager
{
/**
* Enter description here...
*
* @param Doctrine_Connection_Pgsql $conn
*/
public
function
__construct
(
Doctrine_Connection_Pgsql
$conn
)
{
$this
->
_conn
=
$conn
;
}
{
/**
* alter an existing table
*
...
...
lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
View file @
d9733637
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine
::DBAL::
Schema;
#namespace Doctrine
\DBAL\
Schema;
/**
* xxx
...
...
@@ -31,12 +31,7 @@
* @since 2.0
*/
class
Doctrine_DBAL_Schema_SqliteSchemaManager
extends
Doctrine_DBAL_Schema_AbstractSchemaManager
{
public
function
__construct
(
Doctrine_Connection_Sqlite
$conn
)
{
$this
->
_conn
=
$conn
;
}
{
/**
* lists all databases
*
...
...
@@ -44,11 +39,11 @@ class Doctrine_DBAL_Schema_SqliteSchemaManager extends Doctrine_DBAL_Schema_Abst
*/
public
function
listDatabases
()
{
}
/**
* lists all avail
i
ble database functions
* lists all avail
a
ble database functions
*
* @return array
*/
...
...
@@ -371,123 +366,6 @@ class Doctrine_DBAL_Schema_SqliteSchemaManager extends Doctrine_DBAL_Schema_Abst
return
implode
(
', '
,
$declFields
);
}
/**
* create a new table
*
* @param string $name Name of the database that should be created
* @param array $fields Associative array that contains the definition of each field of the new table
* The indexes of the array entries are the names of the fields of the table an
* the array entry values are associative arrays like those that are meant to be
* passed with the field definitions to get[Type]Declaration() functions.
* array(
* 'id' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* 'notnull' => 1
* 'default' => 0
* ),
* 'name' => array(
* 'type' => 'text',
* 'length' => 12
* ),
* 'password' => array(
* 'type' => 'text',
* 'length' => 12
* )
* );
* @param array $options An associative array of table options:
*
* @return void
*/
public
function
createTableSql
(
$name
,
array
$fields
,
array
$options
=
array
())
{
if
(
!
$name
)
{
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
}
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
}
$queryFields
=
$this
->
getFieldDeclarationList
(
$fields
);
$autoinc
=
false
;
foreach
(
$fields
as
$field
)
{
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
]
||
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
]))
{
$autoinc
=
true
;
break
;
}
}
if
(
!
$autoinc
&&
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$keyColumns
=
array_values
(
$options
[
'primary'
]);
$keyColumns
=
array_map
(
array
(
$this
->
_conn
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$name
=
$this
->
_conn
->
quoteIdentifier
(
$name
,
true
);
$sql
=
'CREATE TABLE '
.
$name
.
' ('
.
$queryFields
;
if
(
$check
=
$this
->
getCheckDeclaration
(
$fields
))
{
$sql
.=
', '
.
$check
;
}
if
(
isset
(
$options
[
'checks'
])
&&
$check
=
$this
->
getCheckDeclaration
(
$options
[
'checks'
]))
{
$sql
.=
', '
.
$check
;
}
$sql
.=
')'
;
$query
[]
=
$sql
;
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
$query
[]
=
$this
->
createIndexSql
(
$name
,
$index
,
$definition
);
}
}
return
$query
;
/**
try {
if ( ! empty($fk)) {
$this->_conn->beginTransaction();
}
$ret = $this->_conn->exec($query);
if ( ! empty($fk)) {
foreach ($fk as $definition) {
$query = 'CREATE TRIGGER doctrine_' . $name . '_cscd_delete '
. 'AFTER DELETE ON ' . $name . ' FOR EACH ROW '
. 'BEGIN '
. 'DELETE FROM ' . $definition['foreignTable'] . ' WHERE ';
$local = (array) $definition['local'];
foreach((array) $definition['foreign'] as $k => $field) {
$query .= $field . ' = old.' . $local[$k] . ';';
}
$query .= 'END;';
$this->_conn->exec($query);
}
$this->_conn->commit();
}
} catch(Doctrine_Exception $e) {
$this->_conn->rollback();
throw $e;
}
*/
}
/**
* getAdvancedForeignKeyOptions
* Return the FOREIGN KEY query section dealing with non-standard options
...
...
lib/Doctrine/DBAL/Types/ArrayType.php
View file @
d9733637
...
...
@@ -11,8 +11,7 @@ class Doctrine_DBAL_Types_ArrayType extends Doctrine_DBAL_Types_Type
public
function
getName
()
{
return
'
a
rray'
;
return
'
A
rray'
;
}
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Types/BigIntType.php
0 → 100644
View file @
d9733637
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Type that maps a database BIGINT to a PHP string.
*
* @author robo
*/
class
Doctrine_DBAL_Types_BigIntType
extends
Doctrine_DBAL_Types_Type
{
//put your code here
}
lib/Doctrine/DBAL/Types/BooleanType.php
View file @
d9733637
...
...
@@ -30,4 +30,3 @@ class Doctrine_DBAL_Types_BooleanType extends Doctrine_DBAL_Types_Type
}
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Types/CharType.php
0 → 100644
View file @
d9733637
<?php
/**
* Type that maps a database CHAR to a PHP string.
*
* @author robo
*/
class
CharType
{
//put your code here
}
lib/Doctrine/DBAL/Types/IntegerType.php
View file @
d9733637
<?php
/**
* Type that maps an SQL INT
/MEDIUMINT/BIGINT
to a PHP integer.
* Type that maps an SQL INT to a PHP integer.
*
*/
class
Doctrine_DBAL_Types_IntegerType
extends
Doctrine_DBAL_Types_Type
{
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DatabasePlatform
$platform
)
public
function
getName
()
{
return
"Integer"
;
}
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
)
{
return
$platform
->
getIntegerTypeDeclarationSql
(
$fieldDeclaration
);
}
public
function
convertToPHPValue
(
$value
)
{
return
(
int
)
$value
;
}
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Types/MediumIntType.php
0 → 100644
View file @
d9733637
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of MediumIntType
*
* @author robo
*/
class
MediumIntType
{
//put your code here
}
lib/Doctrine/DBAL/Types/SmallIntType.php
0 → 100644
View file @
d9733637
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of SmallIntType
*
* @author robo
*/
class
SmallIntType
{
//put your code here
}
?>
lib/Doctrine/DBAL/Types/TextType.php
View file @
d9733637
...
...
@@ -7,14 +7,7 @@
*/
class
Doctrine_DBAL_Types_TextType
extends
Doctrine_DBAL_Types_Type
{
/**
* Enter description here...
*
* @param array $fieldDeclaration
* @param Doctrine_DatabasePlatform $platform
* @return unknown
* @override
*/
/** @override */
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DatabasePlatform
$platform
)
{
return
$platform
->
getClobDeclarationSql
(
$fieldDeclaration
);
...
...
@@ -22,4 +15,3 @@ class Doctrine_DBAL_Types_TextType extends Doctrine_DBAL_Types_Type
}
?>
\ No newline at end of file
lib/Doctrine/DBAL/Types/TinyIntType.php
0 → 100644
View file @
d9733637
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of TinyIntType
*
* @author robo
*/
class
TinyIntType
{
//put your code here
}
lib/Doctrine/DBAL/Types/Type.php
View file @
d9733637
...
...
@@ -8,26 +8,35 @@ abstract class Doctrine_DBAL_Types_Type
{
private
static
$_typeObjects
=
array
();
private
static
$_typesMap
=
array
(
'integer'
=>
'Doctrine_DataType_IntegerType'
,
'string'
=>
'Doctrine_DataType_StringType'
,
'text'
=>
'Doctrine_DataType_TextType'
,
'datetime'
=>
'Doctrine_DataType_DateTimeType'
,
'decimal'
=>
'Doctrine_DataType_DecimalType'
,
'double'
=>
'Doctrine_DataType_DoubleType'
'integer'
=>
'Doctrine_DBAL_Types_IntegerType'
,
'int'
=>
'Doctrine_DBAL_Types_IntegerType'
,
'tinyint'
=>
'Doctrine_DBAL_Types_TinyIntType'
,
'smallint'
=>
'Doctrine_DBAL_Types_SmallIntType'
,
'mediumint'
=>
'Doctrine_DBAL_Types_MediumIntType'
,
'bigint'
=>
'Doctrine_DBAL_Types_BigIntType'
,
'varchar'
=>
'Doctrine_DBAL_Types_VarcharType'
,
'text'
=>
'Doctrine_DBAL_Types_TextType'
,
'datetime'
=>
'Doctrine_DBAL_Types_DateTimeType'
,
'decimal'
=>
'Doctrine_DBAL_Types_DecimalType'
,
'double'
=>
'Doctrine_DBAL_Types_DoubleType'
);
public
function
convertToDatabaseValue
(
$value
,
Doctrine_DBAL_Platforms_Abstract
Database
Platform
$platform
)
public
function
convertToDatabaseValue
(
$value
,
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
)
{
return
$value
;
}
public
function
convertTo
Object
Value
(
$value
)
public
function
convertTo
PHP
Value
(
$value
)
{
return
$value
;
}
abstract
public
function
getDefaultLength
(
Doctrine_DBAL_Platforms_AbstractDatabasePlatform
$platform
);
abstract
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DBAL_Platforms_AbstractDatabasePlatform
$platform
);
public
function
getDefaultLength
(
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
)
{
return
null
;
}
abstract
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
);
abstract
public
function
getName
();
/**
...
...
@@ -35,7 +44,7 @@ abstract class Doctrine_DBAL_Types_Type
* Type instances are implemented as flyweights.
*
* @param string $name The name of the type (as returned by getName()).
* @return Doctrine
::DBAL::Types::
Type
* @return Doctrine
\DBAL\Types\
Type
*/
public
static
function
getType
(
$name
)
{
...
...
lib/Doctrine/DBAL/Types/
String
Type.php
→
lib/Doctrine/DBAL/Types/
Varchar
Type.php
View file @
d9733637
<?php
#namespace Doctrine
::DBAL::
Types;
#namespace Doctrine
\DBAL\
Types;
/**
* Type that maps an SQL VARCHAR to a PHP string.
*
* @since 2.0
*/
class
Doctrine_DBAL_Types_
String
Type
extends
Doctrine_DBAL_Types_Type
class
Doctrine_DBAL_Types_
Varchar
Type
extends
Doctrine_DBAL_Types_Type
{
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DatabasePlatform
$platform
)
/** @override */
public
function
getSqlDeclaration
(
array
$fieldDeclaration
,
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
)
{
return
$platform
->
getVarcharDeclaration
(
$fieldDeclaration
);
return
$platform
->
getVarcharDeclaration
Sql
(
$fieldDeclaration
);
}
public
function
getDefaultLength
(
Doctrine_DatabasePlatform
$platform
)
/** @override */
public
function
getDefaultLength
(
Doctrine_DBAL_Platforms_AbstractPlatform
$platform
)
{
return
$platform
->
getVarcharDefaultLength
();
}
public
function
getName
()
{
return
'string'
;
}
/** @override */
public
function
getName
()
{
return
'Varchar'
;
}
}
?>
\ No newline at end of file
lib/Doctrine/ORM/EntityManager.php
View file @
d9733637
...
...
@@ -429,12 +429,12 @@ class Doctrine_ORM_EntityManager
/**
* Saves the given entity, persisting it's state.
*
* @param
Doctrine\ORM\Entity $entity
* @param
object $object
*/
public
function
save
(
Doctrine_ORM_Entity
$entity
)
public
function
save
(
$object
)
{
$this
->
_errorIfNotActiveOrClosed
();
$this
->
_unitOfWork
->
save
(
$
entity
);
$this
->
_unitOfWork
->
save
(
$
object
);
if
(
$this
->
_flushMode
==
self
::
FLUSHMODE_IMMEDIATE
)
{
$this
->
flush
();
}
...
...
@@ -496,7 +496,7 @@ class Doctrine_ORM_EntityManager
if
(
$customRepositoryClassName
!==
null
)
{
$repository
=
new
$customRepositoryClassName
(
$entityName
,
$metadata
);
}
else
{
$repository
=
new
Doctrine_ORM_EntityRepository
(
$
entityName
,
$metadata
);
$repository
=
new
Doctrine_ORM_EntityRepository
(
$
this
,
$metadata
);
}
$this
->
_repositories
[
$entityName
]
=
$repository
;
...
...
@@ -506,11 +506,11 @@ class Doctrine_ORM_EntityManager
/**
* Checks if the instance is managed by the EntityManager.
*
* @param
Doctrine\ORM\Entity
$entity
* @param
object
$entity
* @return boolean TRUE if this EntityManager currently manages the given entity
* (and has it in the identity map), FALSE otherwise.
*/
public
function
contains
(
Doctrine_ORM_Entity
$entity
)
public
function
contains
(
$entity
)
{
return
$this
->
_unitOfWork
->
isInIdentityMap
(
$entity
)
&&
!
$this
->
_unitOfWork
->
isRegisteredRemoved
(
$entity
);
...
...
@@ -543,8 +543,8 @@ class Doctrine_ORM_EntityManager
*/
private
function
_errorIfNotActiveOrClosed
()
{
if
(
!
$this
->
isActive
()
||
$this
->
_closed
)
{
throw
Doctrine_EntityManagerException
::
notActiveOrClosed
(
$this
->
_name
);
if
(
$this
->
_closed
)
{
throw
Doctrine_
ORM_Exceptions_
EntityManagerException
::
notActiveOrClosed
(
$this
->
_name
);
}
}
...
...
lib/Doctrine/ORM/EntityRepository.php
View file @
d9733637
...
...
@@ -38,10 +38,10 @@ class Doctrine_ORM_EntityRepository
protected
$_em
;
protected
$_classMetadata
;
public
function
__construct
(
$e
ntityName
,
Doctrine_ORM_Mapping_ClassMetadata
$classMetadata
)
public
function
__construct
(
$e
m
,
Doctrine_ORM_Mapping_ClassMetadata
$classMetadata
)
{
$this
->
_entityName
=
$
entityName
;
$this
->
_em
=
$
classMetadata
->
getConnection
()
;
$this
->
_entityName
=
$
classMetadata
->
getClassName
()
;
$this
->
_em
=
$
em
;
$this
->
_classMetadata
=
$classMetadata
;
}
...
...
@@ -77,7 +77,6 @@ class Doctrine_ORM_EntityRepository
* @param $id The identifier.
* @param int $hydrationMode The hydration mode to use.
* @return mixed Array or Doctrine_Entity or false if no result
* @todo Remove. Move to EntityRepository.
*/
public
function
find
(
$id
,
$hydrationMode
=
null
)
{
...
...
@@ -94,7 +93,10 @@ class Doctrine_ORM_EntityRepository
$keys
=
$this
->
_classMetadata
->
getIdentifier
();
}
//TODO: check identity map?
// Check identity map first
if
(
$entity
=
$this
->
_em
->
getUnitOfWork
()
->
tryGetById
(
$id
,
$this
->
_classMetadata
->
getRootClassName
()))
{
return
$entity
;
// Hit!
}
return
$this
->
_createQuery
()
->
where
(
implode
(
' = ? AND '
,
$keys
)
.
' = ?'
)
...
...
lib/Doctrine/ORM/Export/
Export
.php
→
lib/Doctrine/ORM/Export/
ClassExporter
.php
View file @
d9733637
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Mapping/ClassMetadata.php
View file @
d9733637
...
...
@@ -616,7 +616,9 @@ class Doctrine_ORM_Mapping_ClassMetadata
if
(
!
isset
(
$mapping
[
'type'
]))
{
throw
Doctrine_ORM_Exceptions_MappingException
::
missingType
();
}
$mapping
[
'type'
]
=
Doctrine_DBAL_Types_Type
::
getType
(
$mapping
[
'type'
]);
// Complete fieldName and columnName mapping
if
(
!
isset
(
$mapping
[
'columnName'
]))
{
$mapping
[
'columnName'
]
=
$mapping
[
'fieldName'
];
...
...
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
View file @
d9733637
...
...
@@ -2,14 +2,10 @@
#namespace Doctrine\ORM\Mapping\Driver;
/* Addendum annotation API */
require_once
dirname
(
__FILE__
)
.
'/addendum/annotations.php'
;
Addendum
::
setRawMode
(
false
);
Addendum
::
setParsedAnnotations
(
array
(
'DoctrineEntity'
,
'DoctrineInheritanceType'
,
'DoctrineDiscriminatorColumn'
,
'DoctrineDiscriminatorMap'
,
'DoctrineSubClasses'
,
'DoctrineTransient'
,
'DoctrineId'
,
'DoctrineIdGenerator'
,
'DoctrineColumn'
,
'DoctrineOneToOne'
,
'DoctrineOneToMany'
,
'DoctrineManyToOne'
,
'DoctrineManyToMany'
));
/* Addendum annotation reflection extensions */
if
(
!
class_exists
(
'Addendum'
,
false
))
{
require_once
dirname
(
__FILE__
)
.
'/addendum/annotations.php'
;
}
/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
...
...
@@ -122,7 +118,7 @@ final class DoctrineColumn extends Annotation {
public
$type
;
public
$length
;
public
$unique
;
public
$n
otnull
;
public
$n
ullable
;
}
final
class
DoctrineOneToOne
extends
Annotation
{
public
$targetEntity
;
...
...
lib/Doctrine/ORM/Mapping/Driver/addendum/annotations.php
View file @
d9733637
...
...
@@ -75,7 +75,7 @@ class AnnotationsBuilder {
$data
=
$this
->
parse
(
$targetReflection
);
$annotations
=
array
();
foreach
(
$data
as
$class
=>
$parameters
)
{
if
(
Addendum
::
parses
(
$class
))
{
if
(
is_subclass_of
(
$class
,
'Annotation'
))
{
foreach
(
$parameters
as
$params
)
{
$annotationReflection
=
new
ReflectionClass
(
$class
);
$annotations
[
$class
][]
=
$annotationReflection
->
newInstance
(
$params
,
$targetReflection
);
...
...
@@ -296,7 +296,7 @@ class ReflectionAnnotatedProperty extends ReflectionProperty {
class
Addendum
{
private
static
$rawMode
;
private
static
$
parsedAnnotations
;
private
static
$
ignored
;
public
static
function
getDocComment
(
$reflection
)
{
if
(
self
::
checkRawDocCommentParsingNeeded
())
{
...
...
@@ -324,12 +324,12 @@ class Addendum {
self
::
$rawMode
=
$enabled
;
}
public
static
function
setParsedAnnotations
(
array
$annotations
)
{
self
::
$
parsedAnnotations
=
array_combine
(
$annotations
,
array_fill
(
0
,
count
(
$annotations
),
true
));
public
static
function
ignore
(
array
$annotations
)
{
self
::
$
ignored
=
array_combine
(
$annotations
,
array_fill
(
0
,
count
(
$annotations
),
true
));
}
public
static
function
pars
es
(
$annotation
)
{
return
isset
(
self
::
$
parsedAnnotations
[
$annotation
]);
public
static
function
ignor
es
(
$annotation
)
{
return
isset
(
self
::
$
ignored
[
$annotation
]);
}
}
lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
View file @
d9733637
...
...
@@ -65,11 +65,6 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
* @var Doctrine\ORM\EntityManager
*/
protected
$_em
;
/**
* Null object.
*/
//private $_nullObject;
/**
* Initializes a new instance of a class derived from AbstractEntityPersister
...
...
@@ -238,48 +233,36 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister
protected
function
_prepareData
(
$entity
,
array
&
$result
,
$isInsert
=
false
)
{
foreach
(
$this
->
_em
->
getUnitOfWork
()
->
getDataChangeSet
(
$entity
)
as
$field
=>
$change
)
{
list
(
$oldVal
,
$newVal
)
=
each
(
$change
);
if
(
is_array
(
$change
))
{
list
(
$oldVal
,
$newVal
)
=
each
(
$change
);
}
else
{
$oldVal
=
null
;
$newVal
=
$change
;
}
$type
=
$this
->
_classMetadata
->
getTypeOfField
(
$field
);
$columnName
=
$this
->
_classMetadata
->
getColumnName
(
$field
);
if
(
is_null
(
$newVal
))
{
$result
[
$columnName
]
=
null
;
}
else
if
(
is_object
(
$newVal
))
{
if
(
$this
->
_classMetadata
->
hasAssociation
(
$field
))
{
$assocMapping
=
$this
->
_classMetadata
->
getAssociationMapping
(
$field
);
if
(
!
$assocMapping
->
isOneToOne
()
||
$assocMapping
->
isInverseSide
())
{
//echo "NOT TO-ONE OR INVERSE!";
continue
;
}
foreach
(
$assocMapping
->
getSourceToTargetKeyColumns
()
as
$sourceColumn
=>
$targetColumn
)
{
//TODO: What if both join columns (local/foreign) are just db-only
// columns (no fields in models) ? Currently we assume the foreign column
// is mapped to a field in the foreign entity.
//TODO: throw exc if field not set
$otherClass
=
$this
->
_em
->
getClassMetadata
(
$assocMapping
->
getTargetEntityName
());
$result
[
$sourceColumn
]
=
$otherClass
->
getReflectionProperty
(
$otherClass
->
getFieldName
(
$targetColumn
))
->
getValue
(
$newVal
);
}
}
else
if
(
is_null
(
$newVal
))
{
$result
[
$columnName
]
=
null
;
}
else
{
switch
(
$type
)
{
case
'array'
:
case
'object'
:
$result
[
$columnName
]
=
serialize
(
$newVal
);
break
;
case
'gzip'
:
$result
[
$columnName
]
=
gzcompress
(
$newVal
,
5
);
break
;
case
'boolean'
:
$result
[
$columnName
]
=
$this
->
_em
->
getConnection
()
->
convertBooleans
(
$newVal
);
break
;
default
:
$result
[
$columnName
]
=
$newVal
;
}
$result
[
$columnName
]
=
$type
->
convertToDatabaseValue
(
$newVal
,
$this
->
_conn
->
getDatabasePlatform
());
}
/*$result[$columnName] = $type->convertToDatabaseValue(
$newVal, $this->_em->getConnection()->getDatabasePlatform());*/
}
// Populate the discriminator column on insert in
Single & Class Table I
nheritance
// Populate the discriminator column on insert in
JOINED & SINGLE_TABLE i
nheritance
if
(
$isInsert
&&
(
$this
->
_classMetadata
->
isInheritanceTypeJoined
()
||
$this
->
_classMetadata
->
isInheritanceTypeSingleTable
()))
{
$discColumn
=
$this
->
_classMetadata
->
getDiscriminatorColumn
();
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
d9733637
...
...
@@ -279,12 +279,13 @@ class Doctrine_ORM_UnitOfWork
}
else
{
$entitySet
=
$this
->
_identityMap
;
}
foreach
(
$entitySet
as
$className
=>
$entities
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
$className
);
foreach
(
$entities
as
$entity
)
{
$oid
=
spl_object_hash
(
$entity
);
if
(
$this
->
getEntityState
(
$entity
)
==
self
::
STATE_MANAGED
)
{
$state
=
$this
->
getEntityState
(
$entity
);
if
(
$state
==
self
::
STATE_MANAGED
||
$state
==
self
::
STATE_NEW
)
{
if
(
!
$class
->
isInheritanceTypeNone
())
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
}
...
...
@@ -294,7 +295,7 @@ class Doctrine_ORM_UnitOfWork
$actualData
[
$name
]
=
$refProp
->
getValue
(
$entity
);
}
if
(
!
isset
(
$this
->
_originalEntityData
[
$oid
])
)
{
if
(
$state
==
self
::
STATE_NEW
)
{
$this
->
_dataChangeSets
[
$oid
]
=
$actualData
;
}
else
{
$originalData
=
$this
->
_originalEntityData
[
$oid
];
...
...
@@ -904,7 +905,6 @@ class Doctrine_ORM_UnitOfWork
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
getAssociationMappings
()
as
$assocMapping
)
{
if
(
!
$assocMapping
->
isCascadeSave
())
{
echo
"NOT cascade "
.
$assocMapping
->
getSourceFieldName
();
continue
;
}
$relatedEntities
=
$class
->
getReflectionProperty
(
$assocMapping
->
getSourceFieldName
())
...
...
@@ -1157,6 +1157,18 @@ class Doctrine_ORM_UnitOfWork
{
return
$this
->
_entityIdentifiers
[
spl_object_hash
(
$entity
)];
}
/**
*
*/
public
function
tryGetById
(
$id
,
$rootClassName
)
{
$idHash
=
$this
->
getIdentifierHash
((
array
)
$id
);
if
(
isset
(
$this
->
_identityMap
[
$rootClassName
][
$idHash
]))
{
return
$this
->
_identityMap
[
$rootClassName
][
$idHash
];
}
return
false
;
}
}
...
...
tests/Orm/Functional/AllTests.php
0 → 100644
View file @
d9733637
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Functional_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
// Suites
require_once
'Orm/Functional/Ticket/AllTests.php'
;
// Tests
require_once
'Orm/Functional/BasicCRUDTest.php'
;
class
Orm_Functional_AllTests
{
public
static
function
main
()
{
PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
Doctrine_OrmFunctionalTestSuite
(
'Doctrine Orm Functional'
);
$suite
->
addTestSuite
(
'Orm_Functional_BasicCRUDTest'
);
$suite
->
addTest
(
Orm_Functional_Ticket_AllTests
::
suite
());
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Functional_AllTests::main'
)
{
Orm_Functional_AllTests
::
main
();
}
\ No newline at end of file
tests/Orm/Functional/BasicCRUDTest.php
0 → 100644
View file @
d9733637
<?php
require_once
'lib/DoctrineTestInit.php'
;
/**
* Description of BasicCRUDTest
*
* @author robo
*/
class
Orm_Functional_BasicCRUDTest
extends
Doctrine_OrmFunctionalTestCase
{
public
function
testFoo
()
{
$em
=
$this
->
_getEntityManager
();
$exporter
=
new
Doctrine_ORM_Export_ClassExporter
(
$em
);
$exporter
->
exportClasses
(
array
(
$em
->
getClassMetadata
(
'CmsUser'
)));
// Create
$user
=
new
CmsUser
;
$user
->
name
=
'romanb'
;
$em
->
save
(
$user
);
$this
->
assertTrue
(
is_numeric
(
$user
->
id
));
$this
->
assertTrue
(
$em
->
contains
(
$user
));
$user2
=
new
CmsUser
;
$user2
->
name
=
'jwage'
;
$em
->
save
(
$user2
);
$this
->
assertTrue
(
is_numeric
(
$user2
->
id
));
$this
->
assertTrue
(
$em
->
contains
(
$user2
));
// Read
$user3
=
$em
->
find
(
'CmsUser'
,
$user
->
id
);
$this
->
assertTrue
(
$user
===
$user3
);
$user4
=
$em
->
find
(
'CmsUser'
,
$user2
->
id
);
$this
->
assertTrue
(
$user2
===
$user4
);
}
}
tests/Orm/Functional/Ticket/1Test.php
0 → 100644
View file @
d9733637
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_Functional_Ticket_1Test
extends
Doctrine_OrmTestCase
{
public
function
testTest
()
{
$this
->
assertEquals
(
0
,
0
);
}
}
\ No newline at end of file
tests/Orm/Functional/Ticket/AllTests.php
0 → 100644
View file @
d9733637
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Functional_Ticket_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
// Tests
require_once
'Orm/Functional/Ticket/1Test.php'
;
class
Orm_Functional_Ticket_AllTests
{
public
static
function
main
()
{
PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
Doctrine_TestSuite
(
'Doctrine Orm'
);
$suite
->
addTestSuite
(
'Orm_Functional_Ticket_1Test'
);
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Functional_Ticket_AllTests::main'
)
{
Ticket_AllTests
::
main
();
}
\ No newline at end of file
tests/lib/Doctrine_OrmFunctionalTestCase.php
View file @
d9733637
...
...
@@ -56,19 +56,18 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
}
$fixture
=
self
::
$_fixtures
[
$uniqueName
];
$this
->
_loadedFixtures
[]
=
$fixture
[
'
model
'
];
$this
->
_loadedFixtures
[]
=
$fixture
[
'
table
'
];
$em
=
$this
->
sharedFixture
[
'em'
];
$classMetadata
=
$em
->
getClassMetadata
(
$fixture
[
'model'
]);
$tableName
=
$classMetadata
->
getTableName
();
$conn
=
$this
->
sharedFixture
[
'conn'
];
$tableName
=
$fixture
[
'table'
];
if
(
!
in_array
(
$tableName
,
self
::
$_exportedTables
))
{
$
em
->
getConnection
()
->
getSchemaManager
()
->
exportClasses
(
array
(
$fixture
[
'model'
]));
$
conn
->
getSchemaManager
()
->
exportClasses
(
array
(
$fixture
[
'model'
]));
self
::
$_exportedTables
[]
=
$tableName
;
}
foreach
(
$fixture
[
'rows'
]
as
$row
)
{
$
em
->
getConnection
()
->
insert
(
$tableName
,
$row
);
$
conn
->
insert
(
$tableName
,
$row
);
}
}
...
...
@@ -100,9 +99,23 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase
*/
protected
function
tearDown
()
{
$
em
=
$this
->
sharedFixture
[
'em
'
];
foreach
(
array_reverse
(
$this
->
_loadedFixtures
)
as
$
model
)
{
$conn
->
exec
(
"DELETE FROM "
.
$
em
->
getClassMetadata
(
$model
)
->
getTableName
()
);
$
conn
=
$this
->
sharedFixture
[
'conn
'
];
foreach
(
array_reverse
(
$this
->
_loadedFixtures
)
as
$
table
)
{
$conn
->
exec
(
"DELETE FROM "
.
$
table
);
}
}
protected
function
setUp
()
{
if
(
!
isset
(
$this
->
sharedFixture
[
'conn'
]))
{
$this
->
sharedFixture
[
'conn'
]
=
Doctrine_TestUtil
::
getConnection
();
}
}
protected
function
_getEntityManager
(
$config
=
null
,
$eventManager
=
null
)
{
$config
=
new
Doctrine_ORM_Configuration
();
$eventManager
=
new
Doctrine_Common_EventManager
();
$conn
=
$this
->
sharedFixture
[
'conn'
];
return
Doctrine_ORM_EntityManager
::
create
(
$conn
,
'em'
,
$config
,
$eventManager
);
}
}
\ No newline at end of file
tests/lib/mocks/Doctrine_DatabasePlatformMock.php
View file @
d9733637
...
...
@@ -24,6 +24,27 @@ class Doctrine_DatabasePlatformMock extends Doctrine_DBAL_Platforms_AbstractPlat
public
function
prefersIdentityColumns
()
{
return
$this
->
_prefersIdentityColumns
;
}
/** @override */
public
function
getIntegerTypeDeclarationSql
(
array
$field
)
{}
/** @override */
public
function
getBigIntTypeDeclarationSql
(
array
$field
)
{}
/** @override */
public
function
getTinyIntTypeDeclarationSql
(
array
$field
)
{}
/** @override */
public
function
getSmallIntTypeDeclarationSql
(
array
$field
)
{}
/** @override */
public
function
getMediumIntTypeDeclarationSql
(
array
$field
)
{}
/** @override */
protected
function
_getCommonIntegerTypeDeclarationSql
(
array
$columnDef
)
{}
/** @override */
public
function
getVarcharDeclarationSql
(
array
$field
)
{}
/* MOCK API */
...
...
tests/lib/mocks/Doctrine_DriverConnectionMock.php
View file @
d9733637
...
...
@@ -5,7 +5,7 @@
class
Doctrine_DriverConnectionMock
implements
Doctrine_DBAL_Driver_Connection
{
public
function
prepare
(
$prepareString
)
{}
public
function
query
(
$queryString
)
{}
public
function
query
()
{}
public
function
quote
(
$input
)
{}
public
function
exec
(
$statement
)
{}
public
function
lastInsertId
()
{}
...
...
tests/models/cms/CmsArticle.php
View file @
d9733637
...
...
@@ -14,11 +14,11 @@ class CmsArticle
*/
public
$id
;
/**
* @DoctrineColumn(type="
string
", length=255)
* @DoctrineColumn(type="
varchar
", length=255)
*/
public
$topic
;
/**
* @DoctrineColumn(type="
string
")
* @DoctrineColumn(type="
varchar
")
*/
public
$text
;
/**
...
...
tests/models/cms/CmsComment.php
View file @
d9733637
...
...
@@ -14,11 +14,11 @@ class CmsComment
*/
public
$id
;
/**
* @DoctrineColumn(type="
string
", length=255)
* @DoctrineColumn(type="
varchar
", length=255)
*/
public
$topic
;
/**
* @DoctrineColumn(type="
string
")
* @DoctrineColumn(type="
varchar
")
*/
public
$text
;
/**
...
...
tests/models/cms/CmsPhonenumber.php
View file @
d9733637
...
...
@@ -6,7 +6,7 @@
class
CmsPhonenumber
implements
Doctrine_ORM_Entity
{
/**
* @DoctrineColumn(type="
string
", length=50)
* @DoctrineColumn(type="
varchar
", length=50)
* @DoctrineId
*/
public
$phonenumber
;
...
...
tests/models/cms/CmsUser.php
View file @
d9733637
...
...
@@ -14,15 +14,15 @@ class CmsUser
*/
public
$id
;
/**
* @DoctrineColumn(type="
string
", length=50)
* @DoctrineColumn(type="
varchar
", length=50)
*/
public
$status
;
/**
* @DoctrineColumn(type="
string
", length=255)
* @DoctrineColumn(type="
varchar
", length=255)
*/
public
$username
;
/**
* @DoctrineColumn(type="
string
", length=255)
* @DoctrineColumn(type="
varchar
", length=255)
*/
public
$name
;
/**
...
...
tests/models/forum/ForumCategory.php
View file @
d9733637
...
...
@@ -17,7 +17,7 @@ class ForumCategory
*/
public
$position
;
/**
* @DoctrineColumn(type="
string
", length=255)
* @DoctrineColumn(type="
varchar
", length=255)
*/
public
$name
;
/**
...
...
tests/models/forum/ForumEntry.php
View file @
d9733637
...
...
@@ -14,7 +14,7 @@ class ForumEntry
*/
public
$id
;
/**
* @DoctrineColumn(type="
string
", length=50)
* @DoctrineColumn(type="
varchar
", length=50)
*/
public
$topic
;
}
...
...
tests/models/forum/ForumUser.php
View file @
d9733637
...
...
@@ -7,7 +7,7 @@
/**
* @DoctrineEntity
* @DoctrineInheritanceType("joined")
* @DoctrineDiscriminatorColumn(name="dtype", type="
string
", length=20)
* @DoctrineDiscriminatorColumn(name="dtype", type="
varchar
", length=20)
* @DoctrineDiscriminatorMap({"user" = "ForumUser", "admin" = "ForumAdministrator"})
* @DoctrineSubclasses({"ForumAdministrator"})
*/
...
...
@@ -20,7 +20,7 @@ class ForumUser
*/
public
$id
;
/**
* @DoctrineColumn(type="
string
", length=50)
* @DoctrineColumn(type="
varchar
", length=50)
*/
public
$username
;
/**
...
...
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