getValue($objectOrArray, $propertyPath)
method getValue($objectOrArray, $propertyPath)
gets the value from an array or object according to $propertyPath
: use Symfony\Component\PropertyAccess\PropertyAccess; // ... $row = array(); $accessor = PropertyAccess::getPropertyAccessor(); // $row[] = $item[firstName]; $row[] = $accessor->getValue($item, '[firstName]'); // $row[] = $item->getFirstName() $row[] = $accessor->getValue($item, 'firstName'); // $row[] = $item[user][firstName]; $row[] = $accessor->getValue($item, '[user][firstName]'); // $row[] = $item->getUser()->getFirstName() $row[] = $accessor->getValue($item, 'user.firstName');
$item->getProp(); $item->isProp(); $item->hasProp(); $item->__get('prop'); $item->prop;
setValue($objectOrArray, $propertyPath, $value)
, which sets the value to $propertyPath
. if ($this->has('debug.stopwatch')) { $stopwatch = $this->get('debug.stopwatch'); } $stopwatch->start('foo'); // ... $stopwatch->lap('foo'); // ... $stopwatch->lap('foo'); // ... $event = $stopwatch->stop('foo');
// 2.2 glob regexp Finder::create()->files()->name('*.php'); Finder::create()->files()->name('/\.php$/'); // Finder::create()->path('some/special/dir'); Finder::create()->path('/^foo\/bar/'); // glob in() Finder::create()->files()->in('src/Symfony/*/*/Resources/translations');
example.org/blog/what-a-wonderful-world
// Twig {{ url('blog', { post: 'what-a-wonderful-world' }) }} // PHP $generator->generate('blog', array('post' => 'what-a-wonderful-world'), true); $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::ABSOLUTE_URL);
/blog/what-a-wonderful-world
// Twig {{ path('blog', { post: 'what-a-wonderful-world' }) }} // PHP $generator->generate('blog', array('post' => 'what-a-wonderful-world')); $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::ABSOLUTE_PATH);
//example.org/blog/what-a-wonderful-world
// Twig {{ url('blog', { post: 'what-a-wonderful-world' }, true) }} // PHP $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::NETWORK_PATH);
../
// Twig {{ path('blog', { post: 'what-a-wonderful-world' }, true) }} // PHP $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::RELATIVE_PATH);
user_homepage: path: / host: "{user}.example.com" defaults: { _controller: AcmeDemoBundle:User:profile } main_homepage: path: / defaults: { _controller: AcmeDemoBundle:Main:homepage }
run()
method (which takes the lambda function as an argument for data processing), it became possible to start the process using the start()
method and get data using the getOutput()
method. In addition, you can use the getIncrementalOutput () method, which returns new data from the process from the previous call to this method. use Symfony\Component\Process\Process; $process = new Process('ls -lsa'); $process->run(function ($type, $data) { echo $data; });
use Symfony\Component\Process\Process; $process = new Process('ls -lsa'); $process->start(); while ($process->isRunning()) { echo $process->getIncrementalOutput(); sleep(1); }
getErrorOutput()
and getIncrementalErrorOutput()
errors. $process->isSuccessful(); $process->hasBeenSignaled(); $process->hasBeenStopped(); $process->isRunning(); // 2.2 $process->isStarted(); $process->isTerminated();
Source: https://habr.com/ru/post/171243/
All Articles