-
Notifications
You must be signed in to change notification settings - Fork 19
User config and profiling #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace spec\PHPCR\Shell\Config; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class ConfigSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('PHPCR\Shell\Config\Config'); | ||
} | ||
|
||
function let() | ||
{ | ||
$this->beConstructedWith(array( | ||
'foo' => 'bar', | ||
'bar' => array( | ||
'boo' => 'baz' | ||
), | ||
)); | ||
} | ||
|
||
function it_should_be_able_to_access_data_values() | ||
{ | ||
$this['foo']->shouldReturn('bar'); | ||
} | ||
|
||
function it_should_be_able_to_access_nested_config() | ||
{ | ||
$this['bar']['boo']->shouldReturn('baz'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace PHPCR\Shell\Config; | ||
|
||
/** | ||
* Configuration profile object | ||
*/ | ||
class Config implements \ArrayAccess, \Iterator | ||
{ | ||
private $data; | ||
|
||
public function __construct($data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
public function offsetSet($offset, $value) | ||
{ | ||
throw new \InvalidArgumentException(sprintf( | ||
'Setting values not permitted on configuration objects (trying to set "%s" to "%s"', | ||
$offset, $value | ||
)); | ||
} | ||
|
||
public function offsetExists($offset) | ||
{ | ||
return isset($this->data[$offset]); | ||
} | ||
|
||
public function offsetUnset($offset) | ||
{ | ||
unset($this->data[$offset]); | ||
} | ||
|
||
public function offsetGet($offset) | ||
{ | ||
if (isset($this->data[$offset])) { | ||
$value = $this->data[$offset]; | ||
if (is_array($value)) { | ||
return new self($value); | ||
} else { | ||
return $value; | ||
} | ||
} | ||
} | ||
|
||
public function current() | ||
{ | ||
return current($this->data); | ||
} | ||
|
||
public function key() | ||
{ | ||
return key($this->data); | ||
} | ||
|
||
public function next() | ||
{ | ||
return next($this->data); | ||
} | ||
|
||
public function rewind() | ||
{ | ||
return reset($this->data); | ||
} | ||
|
||
public function valid() | ||
{ | ||
return current($this->data); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ class NodeListCommand extends BasePhpcrCommand | |
protected $formatter; | ||
protected $textHelper; | ||
protected $maxLevel; | ||
protected $time; | ||
protected $nbNodes; | ||
|
||
protected function configure() | ||
{ | ||
|
@@ -54,6 +56,10 @@ public function execute(InputInterface $input, OutputInterface $output) | |
$this->showChildren = $input->getOption('children'); | ||
$this->showProperties = $input->getOption('properties'); | ||
$this->showTemplate = $input->getOption('template'); | ||
$this->time = 0; | ||
$this->nbNodes = 0; | ||
|
||
$config = $this->get('config.config.phpcrsh'); | ||
|
||
$session = $this->get('phpcr.session'); | ||
$path = $input->getArgument('path'); | ||
|
@@ -70,7 +76,10 @@ public function execute(InputInterface $input, OutputInterface $output) | |
$filter = substr($filter, 1); | ||
} | ||
|
||
|
||
$start = microtime(true); | ||
$nodes = $session->findNodes($parentPath); | ||
$this->time = microtime(true) - $start; | ||
} | ||
|
||
if (!$this->showChildren && !$this->showProperties) { | ||
|
@@ -88,10 +97,18 @@ public function execute(InputInterface $input, OutputInterface $output) | |
} | ||
} | ||
|
||
if ($config['show_execution_time_list']) { | ||
$output->writeln(sprintf( | ||
'%s nodes in set (%s sec)', | ||
$this->nbNodes, | ||
number_format($this->time, $config['execution_time_expansion'])) | ||
); | ||
} | ||
} | ||
|
||
private function renderNode($currentNode, $table, $spacers = array(), $filter = null) | ||
{ | ||
$this->nbNodes++; | ||
if ($this->showChildren) { | ||
$this->renderChildren($currentNode, $table, $spacers, $filter); | ||
} | ||
|
@@ -103,7 +120,9 @@ private function renderNode($currentNode, $table, $spacers = array(), $filter = | |
|
||
private function renderChildren($currentNode, $table, $spacers, $filter = null) | ||
{ | ||
$start = microtime(true); | ||
$children = $currentNode->getNodes($filter ? : null); | ||
$this->time += microtime(true) - $start; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use the stopwatch component if I do much more of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would leave it as is for now and add StopWatch if you have more cases. |
||
|
||
$nodeType = $currentNode->getPrimaryNodeType(); | ||
$childNodeDefinitions = $nodeType->getDeclaredChildNodeDefinitions(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# PHPCRSH configuration | ||
# | ||
# This is a copy of the default configuration | ||
# | ||
# You may delete any or all of the keys as it will be merged | ||
# on top of the default configuration. | ||
# | ||
|
||
# Amount of decimal expansion when showing timing information | ||
execution_time_expansion: 6 | ||
|
||
# Show execution time for queries | ||
show_execution_time_query: true | ||
|
||
# Show execution time for node list operations (i.e. node:list) | ||
show_execution_time_list: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it make sense to use OptionsResolver instead of this class? the cool thing about it is that you get validation and defaults handling for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would still need this class to represent the instance of the configuration, but yeah we could integrate the OptionResolver
tbh the current config system is still a bit messy/strange and could use a general refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#123