Skip to content

Commit 7dde123

Browse files
author
ifsale
committed
composer json added to beta release
1 parent d47332f commit 7dde123

File tree

6 files changed

+188
-179
lines changed

6 files changed

+188
-179
lines changed

PtcDebug.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,16 +1042,15 @@ protected static function _codeCoverageAnalysis( $backtrace = null)
10421042
*/
10431043
protected static function _formatVar($var)
10441044
{
1045-
if(is_array($var) || is_object($var)){ $html_string=static::_doDump($var); }
1046-
else if(@is_bool($var))
1045+
if ( is_array( $var ) || is_object( $var ) ){ $html_string = static::_doDump( $var ); }
1046+
else if ( @is_bool( $var ) )
10471047
{
1048-
$html_string='<span style="color:#92008d;">'.($var==1 ? 'TRUE' : 'FALSE').'</span>';
1048+
$html_string = '<span style="color:#92008d;">' . ( $var == 1 ? 'TRUE' : 'FALSE' ) . '</span>';
10491049
}
1050-
else if(@is_null($var)){ $html_strisng='<span style="color:black;">NULL</span>'; }
1051-
else if(@is_float($var)){ $html_string='<span style="color:#10C500;">'.$var.'</span>'; }
1052-
else if(is_int($var)){ $html_string='<span style="color:red;">'.$var.'</span>'; }
1053-
// could be a string
1054-
else{ $html_string='<span>'.static::_cleanBuffer(@print_r($var,true)).'</span>'; }
1050+
else if( @is_null( $var ) ){ $html_strisng = '<span style="color:black;">NULL</span>'; }
1051+
else if( @is_float( $var ) ){ $html_string = '<span style="color:#10C500;">' . $var . '</span>'; }
1052+
else if( is_int( $var ) ){ $html_string = '<span style="color:red;">' . $var . '</span>'; }
1053+
else{ $html_string = '<span>' . static::_cleanBuffer( @print_r( $var , true ) ) . '</span>'; }
10551054
return @$html_string;
10561055
}
10571056
/**
@@ -1116,10 +1115,10 @@ protected static function _findReference($reference,$type=1)
11161115
}
11171116
/**
11181117
* Custom dump to properly format a given variable and make it more friendly to read
1119-
* @param mixed $var the string to pass
1120-
* @param mixed $varName some statement preceding the variable
1118+
* @param mixed $var the string to pass
1119+
* @param mixed $varName some statement preceding the variable
11211120
* @param string $indent uses "|" as indents by default
1122-
* @param string $reference a reference to prevent recursion
1121+
* @param string $reference a reference to prevent recursion
11231122
* @param int $depth maximun depth
11241123
* @return the html output with the variable
11251124
*/
@@ -1207,12 +1206,13 @@ protected static function _doDump( &$var , $varName = NULL , $indent = NULL , $r
12071206
else if ( is_object( $avar ) )
12081207
{
12091208
$continue = true;
1210-
if ( false === strpos( @get_class( $avar ) , 'Reflection' ) ) // something is wrong with the reflection
1209+
if ( false === strpos( @get_class( $avar ) , 'Reflection' ) &&
1210+
false === strpos( @get_class( $avar ) , 'SimpleXML' ) )
12111211
{
12121212
$rf = @new \ReflectionFunction( $avar );
1213-
if ( ( @$rf->getName( ) == '{closure}' ) ) // work with lambda functions first
1213+
if ( false !== @strpos( $rf->getName( ) , '{closure}' ) ) // work with lambda functions first
12141214
{
1215-
$result .= $indent . ( $varName ? $varName . ' => ' : '');
1215+
@$result .= $indent . ( $varName ? $varName . ' => ' : '');
12161216
$result .= '<span>**RUNTIME CREATED FUNCTION** ';
12171217
if ( @$rf->getFileName( ) ) { $result .= @$rf->getFileName( ); }
12181218
if ( @$rf->getStartLine( ) ) { $result .= ':' . @$rf->getStartLine( ); }

PtcEvent.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
* PHP version 5.3
66
* @category Libraries
77
* @package PhpToolCase
8-
* @version 0.9.1b
8+
* @version 0.9.3b
99
* @author Irony <carlo@salapc.com>
1010
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
1111
* @link http://phptoolcase.com
1212
*/
13-
13+
1414
class PtcEvent
1515
{
16+
/**
17+
* Alias of @ref getEvents()
18+
*/
19+
public static function getEvent( $name = null ){ return static::getEvents( $name ); }
1620
/**
1721
* Registers the component with a constant for ptc helpers functions
1822
*/
1923
public static function register( )
2024
{
21-
if ( !defined( '_PTCEVENT_' ) ) // declare the class namespace
22-
{
23-
@define( '_PTCEVENT_' , get_called_class( ) );
24-
}
25+
if ( !defined( '_PTCEVENT_' ) ) { @define( '_PTCEVENT_' , get_called_class( ) ); }
2526
}
2627
/**
2728
* Adds a listener to an event
@@ -38,14 +39,15 @@ public static function listen( $event , $callback , $priority = 0 )
3839
trigger_error( 'All event names must use "."!' , E_USER_ERROR );
3940
return false;
4041
}
41-
if ( $callback instanceof Closure || is_callable( $callback ) ){ $call = $callback; }
42+
if ( $callback instanceof \Closure || is_callable( $callback ) ){ $call = $callback; }
4243
else
4344
{
4445
$try = explode( '@' , $callback );
45-
if ( @class_exists( $try[ 0 ] ) )
46+
$clean_name = explode( '::' , $try[ 0 ] );
47+
if ( @class_exists( $clean_name[ 0 ] ) )
4648
{
4749
$method = ( sizeof( $try ) > 1 ) ? $try[ 1 ] : 'handle';
48-
$call = array( new $try[ 0 ] , $method );
50+
$call = ( false !== strpos( $try[ 0 ] , '::' ) ) ? $try[ 0 ] : array( new $try[ 0 ] , $method );
4951
}
5052
else // no valid callback found
5153
{
@@ -92,8 +94,8 @@ public static function remove( $event , $key = null )
9294
{
9395
if ( !array_key_exists( $key , static::$_events[ $event[ 0 ] ][ $event[ 1 ] ] ) )
9496
{
95-
trigger_error( $key . ' not found in <b>' . $event[ 0 ] . '.' . $event[ 1 ] .
96-
'</b>!' , E_USER_WARNING );
97+
trigger_error( $key . ' not found in <b>' .
98+
$event[ 0 ] . '.' . $event[ 1 ] . '</b>!' , E_USER_WARNING );
9799
return false;
98100
}
99101
static::_debug( static::$_events[ $event[ 0 ] ][ $event[ 1 ] ][ $key ] ,
@@ -121,7 +123,7 @@ public static function remove( $event , $key = null )
121123
* @param string $event the event name to fire
122124
* @param array $data an array with the data you wish to pass to the listeners
123125
*/
124-
public static function fire( $event , $data = array( ) )
126+
public static function fire( $event , $data )
125127
{
126128
static::register( );
127129
$main = $event;
@@ -143,7 +145,7 @@ public static function fire( $event , $data = array( ) )
143145
{
144146
$data = ( is_array( $data ) ) ? $data : array( $data );
145147
static::_debug( array( 'callback' => $wildcard , 'data' => array( $data , $main ) ) ,
146-
'firing wildcard <b>' . $event[ 0 ] . '.' . $event[ 1 ] . '[ ' . $a . ' ]</b>' , 'Event Manager' );
148+
'firing wildcard <b>' . $event[ 0 ] . '.' . $event[ 1 ] . '[ ' . $a . ' ]</b>' , 'Event Manager' );
147149
$a++;
148150
if ( false === static::_run( $wildcard , array( $data , $main ) ) ){ return; }
149151
}

PtcQueryBuilder.php

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,7 @@ public function __construct( \PDO $pdo = null )
2929
public function table( $table )
3030
{
3131
$this->reset( );
32-
$table = ( is_array( $table ) ) ? $table : array( $table );
33-
foreach ( $table as $v )
34-
{
35-
if ( $val = $this->_checkRawValue( $v ) )
36-
{
37-
$this->_table .= ' ' . $val. ',';
38-
continue;
39-
}
40-
$divider = ( strpos( $v , ' as ' ) ) ? ' as ' : ' AS ';
41-
$table = explode( $divider , $v );
42-
$t = $this->addBackTicks( $table[ 0 ] );
43-
if ( array_key_exists( 1 , $table ) )
44-
{
45-
$t .= ' as ' . $this->addBackTicks( $table[ 1 ] );
46-
}
47-
$this->_table .= $this->sanitize( $t ) . ',';
48-
//$this->_table .= $this->addBackTicks( $this->sanitize( $v ) ) . ',';
49-
}
50-
$this->_table = substr( $this->_table , 0 , strlen( $this->_table ) - 1 );
32+
$this->_table = $this->_formatTable( $table );
5133
$this->_currentQueryType = 'select'; // set query type as select by default
5234
return $this;
5335
}
@@ -115,22 +97,23 @@ public function raw( $value ){ return $this->_randomId . 'RAW{' .$value . '}'; }
11597
public function addBackTicks( $string )
11698
{
11799
if ( $val = $this->_checkRawValue( $string ) ){ return $val; }
118-
$raw = explode( '.' , $string );
100+
$raw = array_map( 'trim' , explode( '.' , $string ) );
119101
$string = ( $raw[ 0 ] === '*' ) ? $raw[ 0 ] : '`' . $raw[ 0 ] . '`';
120-
return $string .= ( @$raw[ 1 ] ) ? '.`' . $raw[ 1 ] . '`': '';
102+
if ( @$raw[ 1 ] ){ $string .= ( $raw[ 1 ] === '*' ) ? '.' . $raw[ 1 ] : '.`' . $raw[ 1 ] . '`'; }
103+
return $string;
121104
}
122105
/**
123106
* Creates a join based on the parameters. See @ref qb_joins
124-
* @param string $table the name of the table to join
125-
* @param string $first the first column
107+
* @param string $table the name of the table to join
108+
* @param string $first the first column
126109
* @param string $operator the operator to use for the join
127110
* @param string $second the second column
128-
* @param string $type the type of join
111+
* @param string $type the type of join
129112
*/
130113
public function join( $table , $first , $operator = null , $second = null , $type = 'inner' )
131114
{
132115
if ( !$this->_isTableSet( ) ) { return false; }
133-
$this->_join .= ' ' . strtoupper( $type ) . ' JOIN ' . $this->addBackTicks( $table );
116+
$this->_join .= ' ' . strtoupper( $type ) . ' JOIN ' . $this->_formatTable( $table );
134117
$this->_isClosure = true;
135118
if ( $first instanceof \Closure ){ $this->_runClosure( $first , 'join' ); }
136119
else{ $this->on( $first, $operator, $second ); }
@@ -208,8 +191,7 @@ public function run( $query = null , $bind = null , $type = null )
208191
if ( !$type )
209192
{
210193
$type = 3;
211-
// check statement that needs data in return
212-
foreach ( $this->_returnStatements as $statement )
194+
foreach ( $this->_returnStatements as $statement ) // statements that need return data
213195
{
214196
if ( strpos( trim( strtoupper( $this->_currentQuery ) ) , $statement ) === 0 )
215197
{
@@ -256,7 +238,7 @@ public function prepare( )
256238
{
257239
if ( is_string( $v ) )
258240
{
259-
if ( false === strpos( $v, ':' ) ) { continue; }
241+
if ( false === strpos( $v , ':' ) ) { continue; }
260242
$query = preg_replace( '/\?/' , $v , $query , 1 );
261243
}
262244
}
@@ -266,7 +248,7 @@ public function prepare( )
266248
/**
267249
* Adds order to the query. See @ref qb_order_group_limit
268250
* @param string $column the column names
269-
* @param string $direction asc or desc
251+
* @param string $direction asc or desc
270252
*/
271253
public function order( $column , $direction = 'asc' )
272254
{
@@ -408,7 +390,7 @@ public function setFetchMode( $mode , $class = null )
408390
return false;
409391
}
410392
$this->_fetchMode = ( $class ) ? array( $mode , $class ) : array( $mode );
411-
393+
return $this;
412394
}
413395
/**
414396
* Adds where operators and joins to the query
@@ -783,6 +765,33 @@ protected function _checkPdo( )
783765
return true;
784766
}
785767
/**
768+
* Adds backticks properly to table names
769+
* @param string|array $table the table name
770+
*/
771+
protected function _formatTable( $table )
772+
{
773+
$string = null;
774+
$table = ( is_array( $table ) ) ? $table : array( $table );
775+
foreach ( $table as $v )
776+
{
777+
if ( $val = $this->_checkRawValue( $v ) )
778+
{
779+
$string .= ' ' . $val. ',';
780+
continue;
781+
}
782+
$divider = ( strpos( $v , ' as ' ) ) ? ' as ' : ' AS ';
783+
$table = explode( $divider , $v );
784+
$t = $this->addBackTicks( $table[ 0 ] );
785+
if ( array_key_exists( 1 , $table ) )
786+
{
787+
$t .= ' as ' . $this->addBackTicks( $table[ 1 ] );
788+
}
789+
$string .= $this->sanitize( $t ) . ',';
790+
//$string .= $this->addBackTicks( $this->sanitize( $v ) ) . ',';
791+
}
792+
return $string = substr( $string , 0 , strlen( $string ) - 1 );
793+
}
794+
/**
786795
* Checks if a table was set
787796
*/
788797
protected function _isTableSet( )
@@ -851,10 +860,10 @@ protected function _debugQuery( $string , $data )
851860
}
852861
/**
853862
* Adds execution time and query results to the PtcDebug class
854-
* @param string $reference a reference to look for ("$statement")
855-
* @param string $type the type of debug (timer, attach)
863+
* @param string $reference a reference to look for ("$statement")
864+
* @param string $type the type of debug (timer, attach)
856865
* @param mixed $string the string to pass
857-
* @param mixed $statement some new statement if required
866+
* @param mixed $statement some new statement if required
858867
*/
859868
protected static function _debugBuffer( $reference , $type = null , $string = null , $statement = null )
860869
{

0 commit comments

Comments
 (0)