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
2f1badc7
Commit
2f1badc7
authored
Mar 21, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged fix for #852 from 0.10 to trunk.
parent
45d41f1c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
385 deletions
+135
-385
Locator.php
lib/Doctrine/Locator.php
+0
-197
Injectable.php
lib/Doctrine/Locator/Injectable.php
+0
-149
Validator.php
lib/Doctrine/Validator.php
+7
-3
Time.php
lib/Doctrine/Validator/Time.php
+62
-36
Timestamp.php
lib/Doctrine/Validator/Timestamp.php
+66
-0
No files found.
lib/Doctrine/Locator.php
deleted
100644 → 0
View file @
45d41f1c
<?php
/**
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Locator
*
* @package Doctrine
* @subpackage Doctrine_Locator
* @category Locator
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
* @link http://www.phpdoctrine.org
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Eevert Saukkokoski <dmnEe0@gmail.com>
* @version $Revision$
* @since 1.0
*/
class
Doctrine_Locator
implements
Countable
,
IteratorAggregate
{
/**
* @var array $_resources an array of bound resources
*/
protected
$_resources
=
array
();
/**
* @var string $_classPrefix the default class prefix
*/
protected
$_classPrefix
=
'Doctrine_'
;
/**
* @var array $_instances a pool of this object's instances
*/
protected
static
$_instances
=
array
();
/**
* Constructor. Provide an array of resources to set initial contents.
*
* @param array
* @return void
*/
public
function
__construct
(
array
$defaults
=
null
)
{
if
(
null
!==
$defaults
)
{
foreach
(
$defaults
as
$name
=>
$resource
)
{
if
(
$resource
instanceof
Doctrine_Locator_Injectable
)
{
$resource
->
setLocator
(
$this
);
}
$this
->
_resources
[
$name
]
=
$resource
;
}
}
self
::
$_instances
[]
=
$this
;
}
/**
* instance
*
* @return Sensei_Locator
*/
public
static
function
instance
()
{
if
(
empty
(
self
::
$_instances
))
{
$obj
=
new
Doctrine_Locator
();
}
return
current
(
self
::
$_instances
);
}
/**
* setClassPrefix
*
* @param string $prefix
*/
public
function
setClassPrefix
(
$prefix
)
{
$this
->
_classPrefix
=
$prefix
;
}
/**
* getClassPrefix
*
* @return string
*/
public
function
getClassPrefix
()
{
return
$this
->
_classPrefix
;
}
/**
* contains
* checks if a resource exists under the given name
*
* @return boolean whether or not given resource name exists
*/
public
function
contains
(
$name
)
{
return
isset
(
$this
->
_resources
[
$name
]);
}
/**
* bind
* binds a resource to a name
*
* @param string $name the name of the resource to bind
* @param mixed $value the value of the resource
* @return Sensei_Locator this object
*/
public
function
bind
(
$name
,
$value
)
{
$this
->
_resources
[
$name
]
=
$value
;
return
$this
;
}
/**
* locate
* locates a resource by given name and returns it
*
* @throws Doctrine_Locator_Exception if the resource could not be found
* @param string $name the name of the resource
* @return mixed the located resource
*/
public
function
locate
(
$name
)
{
if
(
isset
(
$this
->
_resources
[
$name
]))
{
return
$this
->
_resources
[
$name
];
}
else
{
$className
=
$name
;
if
(
!
class_exists
(
$className
))
{
$name
=
explode
(
'.'
,
$name
);
$name
=
array_map
(
'strtolower'
,
$name
);
$name
=
array_map
(
'ucfirst'
,
$name
);
$name
=
implode
(
'_'
,
$name
);
$className
=
$this
->
_classPrefix
.
$name
;
if
(
!
class_exists
(
$className
))
{
throw
new
Doctrine_Locator_Exception
(
"Couldn't locate resource "
.
$className
);
}
}
$this
->
_resources
[
$name
]
=
new
$className
();
if
(
$this
->
_resources
[
$name
]
instanceof
Doctrine_Locator_Injectable
)
{
$this
->
_resources
[
$name
]
->
setLocator
(
$this
);
}
return
$this
->
_resources
[
$name
];
}
throw
new
Doctrine_Locator_Exception
(
"Couldn't locate resource "
.
$name
);
}
/**
* count
* returns the number of bound resources associated with
* this object
*
* @see Countable interface
* @return integer the number of resources
*/
public
function
count
()
{
return
count
(
$this
->
_resources
);
}
/**
* getIterator
* returns an ArrayIterator that iterates through all
* bound resources
*
* @return ArrayIterator an iterator for iterating through
* all bound resources
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_resources
);
}
}
lib/Doctrine/Locator/Injectable.php
deleted
100644 → 0
View file @
45d41f1c
<?php
/**
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Locator_Injectable
*
* @package Doctrine
* @subpackage Doctrine_Locator
* @category Locator
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
* @link http://www.phpdoctrine.org
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Eevert Saukkokoski <dmnEe0@gmail.com>
* @version $Revision$
* @since 1.0
*/
class
Doctrine_Locator_Injectable
{
/**
* @var Doctrine_Locator the locator object
*/
protected
$_locator
;
/**
* @var array an array of bound resources
*/
protected
$_resources
=
array
();
/**
* @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking
*/
protected
static
$_null
;
/**
* setLocator
* this method can be used for setting the locator object locally
*
* @param Doctrine_Locator the locator object
* @return Doctrine_Locator_Injectable this instance
*/
public
function
setLocator
(
Doctrine_Locator
$locator
)
{
$this
->
_locator
=
$locator
;
return
$this
;
}
/**
* getLocator
* returns the locator associated with this object
*
* if there are no locator locally associated then
* this method tries to fetch the current global locator
*
* @return Doctrine_Locator
*/
public
function
getLocator
()
{
if
(
!
isset
(
$this
->
_locator
))
{
$this
->
_locator
=
Doctrine_Locator
::
instance
();
}
return
$this
->
_locator
;
}
/**
* locate
* locates a resource by given name and returns it
*
* if the resource cannot be found locally this method tries
* to use the global locator for finding the resource
*
* @see Doctrine_Locator::locate()
* @throws Doctrine_Locator_Exception if the resource could not be found
* @param string $name the name of the resource
* @return mixed the located resource
*/
public
function
locate
(
$name
)
{
if
(
isset
(
$this
->
_resources
[
$name
]))
{
if
(
is_object
(
$this
->
_resources
[
$name
]))
{
return
$this
->
_resources
[
$name
];
}
else
{
// get the name of the concrete implementation
$concreteImpl
=
$this
->
_resources
[
$name
];
return
$this
->
getLocator
()
->
locate
(
$concreteImpl
);
}
}
else
{
return
$this
->
getLocator
()
->
locate
(
$name
);
}
}
/**
* bind
* binds a resource to a name
*
* @param string $name the name of the resource to bind
* @param mixed $value the value of the resource
* @return Doctrine_Locator this object
*/
public
function
bind
(
$name
,
$resource
)
{
$this
->
_resources
[
$name
]
=
$resource
;
return
$this
;
}
/**
* initNullObject
* initializes the null object
*
* @param Doctrine_Null $null
* @return void
*/
public
static
function
initNullObject
(
Doctrine_Null
$null
)
{
self
::
$_null
=
$null
;
}
/**
* getNullObject
* returns the null object associated with this object
*
* @return Doctrine_Null
*/
public
static
function
getNullObject
()
{
return
self
::
$_null
;
}
}
lib/Doctrine/Validator.php
View file @
2f1badc7
...
...
@@ -173,6 +173,7 @@ class Doctrine_Validator
switch
(
$type
)
{
case
'float'
:
case
'double'
:
case
'decimal'
:
return
(
string
)
$var
==
strval
(
floatval
(
$var
));
case
'integer'
:
return
(
string
)
$var
==
strval
(
intval
(
$var
));
...
...
@@ -189,8 +190,11 @@ class Doctrine_Validator
case
'boolean'
:
return
is_bool
(
$var
);
case
'timestamp'
:
// todo: validate the timestamp is in YYYY-MM-DD HH:MM:SS format
return
true
;
$validator
=
self
::
getValidator
(
'timestamp'
);
return
$validator
->
validate
(
$var
);
case
'time'
:
$validator
=
self
::
getValidator
(
'time'
);
return
$validator
->
validate
(
$var
);
case
'date'
:
$validator
=
self
::
getValidator
(
'date'
);
return
$validator
->
validate
(
$var
);
...
...
lib/Doctrine/
Locator/Exception
.php
→
lib/Doctrine/
Validator/Time
.php
View file @
2f1badc7
<?php
/*
* $Id
$
* $Id
: Time.php 3884 2008-02-22 18:26:35Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
...
...
@@ -20,17 +20,43 @@
*/
/**
* Doctrine_
Locator_Exception
* Doctrine_
Validator_Time
*
* @package Doctrine
* @subpackage Doctrine_Locator
* @category Locator
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
* @link http://www.phpdoctrine.org
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @version $Revision$
* @subpackage Validator
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 3884 $
* @author Mark Pearson <mark.pearson0@googlemail.com>
*/
class
Doctrine_Locator_Exception
extends
Doctrine_Exception
{
}
class
Doctrine_Validator_Time
{
/**
* checks if given value is a valid time
*
* @param mixed $value
* @return boolean
*/
public
function
validate
(
$value
)
{
if
(
$value
===
null
)
{
return
true
;
}
$e
=
explode
(
':'
,
$value
);
if
(
count
(
$e
)
!==
3
)
{
return
false
;
}
if
(
!
preg_match
(
'/^ *[0-9]{2}:[0-9]{2}:[0-9]{2} *$/'
,
$value
))
{
return
false
;
}
$hr
=
intval
(
$e
[
0
],
10
);
$min
=
intval
(
$e
[
1
],
10
);
$sec
=
intval
(
$e
[
2
],
10
);
return
$hr
>=
0
&&
$hr
<=
23
&&
$min
>=
0
&&
$min
<=
59
&&
$sec
>=
0
&&
$sec
<=
59
;
}
}
\ No newline at end of file
lib/Doctrine/Validator/Timestamp.php
0 → 100644
View file @
2f1badc7
<?php
/*
* $Id: Timestamp.php 3884 2008-02-22 18:26:35Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
/**
* Doctrine_Validator_Timestamp
*
* @package Doctrine
* @subpackage Validator
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 3884 $
* @author Mark Pearson <mark.pearson0@googlemail.com>
*/
class
Doctrine_Validator_Timestamp
{
/**
* checks if given value is a valid timestamp (YYYY-MM-DD HH:MM:SS)
*
* @param mixed $value
* @return boolean
*/
public
function
validate
(
$value
)
{
if
(
$value
===
null
)
{
return
true
;
}
if
(
!
preg_match
(
'/^ *[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} *$/'
,
$value
))
{
return
false
;
}
list
(
$date
,
$time
)
=
explode
(
' '
,
trim
(
$value
));
$dateValidator
=
Doctrine_Validator
::
getValidator
(
'date'
);
$timeValidator
=
Doctrine_Validator
::
getValidator
(
'time'
);
if
(
!
$dateValidator
->
validate
(
$date
))
{
return
false
;
}
if
(
!
$timeValidator
->
validate
(
$time
))
{
return
false
;
}
return
true
;
}
}
\ No newline at end of file
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