@@ -1495,21 +1495,26 @@ public static function getConfigData($key)
1495
1495
* @param string|null $value The value to set. If null, the config
1496
1496
* entry is deleted, reverting it to the
1497
1497
* default value.
1498
+ * @param boolean $temp Set this config data temporarily for this
1499
+ * script run. This will not write the config
1500
+ * data to the config file.
1498
1501
*
1499
1502
* @return boolean
1500
1503
* @see getConfigData()
1501
1504
* @throws PHP_CodeSniffer_Exception If the config file can not be written.
1502
1505
*/
1503
- public static function setConfigData ($ key , $ value )
1506
+ public static function setConfigData ($ key , $ value, $ temp = false )
1504
1507
{
1505
- $ configFile = dirname (__FILE__ ).'/CodeSniffer.conf ' ;
1506
- if (is_file ($ configFile ) === false ) {
1507
- $ configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf ' ;
1508
- }
1508
+ if ($ temp === false ) {
1509
+ $ configFile = dirname (__FILE__ ).'/CodeSniffer.conf ' ;
1510
+ if (is_file ($ configFile ) === false ) {
1511
+ $ configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf ' ;
1512
+ }
1509
1513
1510
- if (is_file ($ configFile ) === true && is_writable ($ configFile ) === false ) {
1511
- $ error = "Config file $ configFile is not writable " ;
1512
- throw new PHP_CodeSniffer_Exception ($ error );
1514
+ if (is_file ($ configFile ) === true && is_writable ($ configFile ) === false ) {
1515
+ $ error = "Config file $ configFile is not writable " ;
1516
+ throw new PHP_CodeSniffer_Exception ($ error );
1517
+ }
1513
1518
}
1514
1519
1515
1520
$ phpCodeSnifferConfig = self ::getAllConfigData ();
@@ -1522,14 +1527,18 @@ public static function setConfigData($key, $value)
1522
1527
$ phpCodeSnifferConfig [$ key ] = $ value ;
1523
1528
}
1524
1529
1525
- $ output = '< ' .'?php ' ."\n" .' $phpCodeSnifferConfig = ' ;
1526
- $ output .= var_export ($ phpCodeSnifferConfig , true );
1527
- $ output .= "\n? " .'> ' ;
1530
+ if ($ temp === false ) {
1531
+ $ output = '< ' .'?php ' ."\n" .' $phpCodeSnifferConfig = ' ;
1532
+ $ output .= var_export ($ phpCodeSnifferConfig , true );
1533
+ $ output .= "\n? " .'> ' ;
1528
1534
1529
- if (file_put_contents ($ configFile , $ output ) === false ) {
1530
- return false ;
1535
+ if (file_put_contents ($ configFile , $ output ) === false ) {
1536
+ return false ;
1537
+ }
1531
1538
}
1532
1539
1540
+ $ GLOBALS ['PHP_CODESNIFFER_CONFIG_DATA ' ] = $ phpCodeSnifferConfig ;
1541
+
1533
1542
return true ;
1534
1543
1535
1544
}//end setConfigData()
@@ -1543,6 +1552,10 @@ public static function setConfigData($key, $value)
1543
1552
*/
1544
1553
public static function getAllConfigData ()
1545
1554
{
1555
+ if (isset ($ GLOBALS ['PHP_CODESNIFFER_CONFIG_DATA ' ]) === true ) {
1556
+ return $ GLOBALS ['PHP_CODESNIFFER_CONFIG_DATA ' ];
1557
+ }
1558
+
1546
1559
$ configFile = dirname (__FILE__ ).'/CodeSniffer.conf ' ;
1547
1560
if (is_file ($ configFile ) === false ) {
1548
1561
$ configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf ' ;
@@ -1553,7 +1566,8 @@ public static function getAllConfigData()
1553
1566
}
1554
1567
1555
1568
include $ configFile ;
1556
- return $ phpCodeSnifferConfig ;
1569
+ $ GLOBALS ['PHP_CODESNIFFER_CONFIG_DATA ' ] = $ phpCodeSnifferConfig ;
1570
+ return $ GLOBALS ['PHP_CODESNIFFER_CONFIG_DATA ' ];
1557
1571
1558
1572
}//end getAllConfigData()
1559
1573
0 commit comments