GithubHelp home page GithubHelp logo

support's Introduction

Support

Timer

A timer class that can be called static or dynamically.

Source code: support/blob/master/src/Timer.php

Methods

Those are the methods:

Timer::start();
Timer::stop();
Timer::isStarted();
Timer::isStopped();
Timer::elapsed(); // returns a formatted value 9.0192
Timer::elapsedRaw(); // returns a double 9.019223049023
Timer::setFormat(default = '%.4f');

You can name your timers and have more than one running:

Timer::start('mary');
Timer::stop('mary');
Timer::elapsed('mary');

Examples

Timer::start();
Timer::start('2nd timer');

var_dump("started: " . (Timer::isStarted() ? 'yes' : 'no'));
var_dump("stopped: " . (Timer::isStopped() ? 'yes' : 'no'));

sleep(5);

Timer::stop();

var_dump("started: " . (Timer::isStarted() ? 'yes' : 'no'));
var_dump("stopped: " . (Timer::isStopped() ? 'yes' : 'no'));
var_dump("elapsed: " . Timer::elapsed());
var_dump("raw: " . Timer::elapsedRaw());

sleep(2);

var_dump("'2nd timer' started: " . (Timer::isStarted('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' stopped: " . (Timer::isStopped('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' elapsed: " . Timer::elapsed('2nd timer'));
var_dump("'2nd timer' raw: " . Timer::elapsedRaw('2nd timer'));

sleep(2);

Timer::stop('2nd timer');

var_dump("'2nd timer' started: " . (Timer::isStarted('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' stopped: " . (Timer::isStopped('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' elapsed: " . Timer::elapsed('2nd timer'));
var_dump("'2nd timer' raw: " . Timer::elapsedRaw('2nd timer'));

Timer::setFormat('%.8f');
var_dump("'2nd timer' elapsed 8 decimals: " . Timer::elapsed('2nd timer'));

/// And you can instantiate it and do it all over again:

$t = new Timer;
$t->start();
sleep(3);
$t->stop();
var_dump("elapsed dynamic: " . $t->elapsed());

This should give you this result:

string(12) "started: yes"
string(11) "stopped: no"
string(11) "started: no"
string(12) "stopped: yes"
string(15) "elapsed: 5.0004"
string(20) "raw: 5.0005040168762"
string(24) "'2nd timer' started: yes"
string(23) "'2nd timer' stopped: no"
string(27) "'2nd timer' elapsed: 7.0008"
string(32) "'2nd timer' raw: 7.0008120536804"
string(23) "'2nd timer' started: no"
string(24) "'2nd timer' stopped: yes"
string(27) "'2nd timer' elapsed: 9.0011"
string(32) "'2nd timer' raw: 9.0010931491852"
string(42) "'2nd timer' elapsed 8 decimals: 9.00113106"
string(27) "elapsed dynamic: 3.00018883"

support's People

Contributors

alr2413 avatar antonioribeiro avatar chrisbjr avatar cmorbitzer avatar drbyte avatar ethanransdellrarebird avatar fgreinus avatar grahamcampbell avatar koozza avatar przemekperon avatar rogervila avatar swilla avatar vidhyut-pandya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

support's Issues

ErrorException in console (composer update / php artisan command)

Laravel Framework: 6.20.11
PHP Version: 7.4.14
Package version: Support v0.9.3
Used as a depencency for: Tracker v4.0.1

$ composer update

...

ErrorException  : session_start(): Cannot start session when headers already sent

at /vendor/pragmarx/support/src/PhpSession.php:23
    19| 	private function startSession()
    20| 	{
    21| 		if ( ! $this->isStarted())
    22| 		{
  > 23| 			session_start();
    24| 		}
    25| 	}

Config file

I was just wondering,

public function get($key, $default = null)
{
return $this->config->get($this->namespace.$key, $default);
}

It should not have been $this->namespace.'.'.$key???

isLaravel5 funciton is not visible

You've already done these changes but it wasn't pushed to release

There is an error.

I think it's because the call of isLaravel5 is placed before it's declaration:

declaration on 1086 line

if ( ! function_exists( 'isLaravel5' ))
{
	_function isLaravel5()_
	{
		return Laravel::VERSION >= '5.0.0';
	}
   ...

and call on 927

if ( ! function_exists( 'csrf_token' ) && ! isLaravel5())

An error

$ php artisan optimaze                                                                                                                                                                              
                                                                                                                                                                                                    
Fatal error: Call to undefined function isLaravel5() in C:\OpenServer\domains\shaman-admin-api\vendor\pragmarx\support\src\helpers.php on line 927                                                  
                                                                                                                                                                                                    
Call Stack:                                                                                                                                                                                         
    0.0002     128976   1. {main}() C:\OpenServer\domains\shaman-admin-api\artisan:0                                                                                                                
    0.0004     131064   2. require('C:\OpenServer\domains\shaman-admin-api\bootstrap\autoload.php') C:\OpenServer\domains\shaman-admin-api\artisan:16                                               
    0.0006     132496   3. require('C:\OpenServer\domains\shaman-admin-api\vendor\autoload.php') C:\OpenServer\domains\shaman-admin-api\bootstrap\autoload.php:17                                   
    0.0008     145080   4. ComposerAutoloaderInit5e6695309826f98ddf2a06b49a4e09ac::getLoader() C:\OpenServer\domains\shaman-admin-api\vendor\autoload.php:7                                         
    0.0161    1593912   5. composerRequire5e6695309826f98ddf2a06b49a4e09ac() C:\OpenServer\domains\shaman-admin-api\vendor\composer\autoload_real.php:56                                            
    0.0174    1741464   6. require('C:\OpenServer\domains\shaman-admin-api\vendor\pragmarx\support\src\helpers.php') C:\OpenServer\domains\shaman-admin-api\vendor\composer\autoload_real.php:66    
                                                                                                                                                                                                    
Dump $_SERVER                                                                                                                                                                                       
   $_SERVER['REMOTE_ADDR'] is undefined                                                                                                                                                             
   $_SERVER['REQUEST_METHOD'] is undefined                                                                                                                                                          
Dump $_SESSION                                                                                                                                                                                      
   $_SESSION['*'] is undefined                                                                                                                                                                      
Dump $_REQUEST              

v0.6.14 breaks artisan optimize --force

I'm currently using v0.6.11, but updating to v0.6.14 breaks php artisan optimize --force (the versions in between are also broken).

The error I get is the following;

Fatal error: Cannot declare interface Illuminate\Contracts\Container\Container, because the name is already in use in {...}\bootstrap\cache\compiled.php on line 4

I think it has something to do with 98da8d4 or 7376acd

Not respecting APP_ENV in user's .env file?

Curious why this package isn't respecting the user's APP_ENV setting in their .env file?

We have our environment set to APP_ENV=local, yet we noticed this when running our seeders:
screen shot 2016-04-05 at 2 11 56 pm

I investigated further, and it seems the setting is being overwritten by your package:
screen shot 2016-04-05 at 2 13 22 pm

If I disable your putenv() call here, then my APP_ENV setting is respected. The issue I see is that other packages and/or users may rely on that APP_ENV setting. Is there reason why it needs to be overridden by pragmarx/support?

Helpers Function env conflicting with laravels env

After updating to Laravel 5.2 my APP_ENV environment var was always empty. I figured the cause was your helpers env function. I did not investigate it any further. I just removed the tracker package and with it the support package as well. Since I didn't use it anymore. I just wanted to let you know something is wrong there.

Alex

csrf_token helper method in Laravel 5.4 has been updated

if ( ! function_exists( 'csrf_token' )) { function csrf_token() { return app()->make('session.store')->getToken(); } }

should now be:

if ( ! function_exists( 'csrf_token' )) { function csrf_token() { return app()->make('session')->token(); } }

to_carbon helper alternateFormat issue.

$alternateFormat in to_carbon helper is used too late in the method and will sometimes be missed completely.

The date format m/d/Y comes out wrong when being passed to to_carbon because of this

to_carbon('06/02/2000', 'm/d/Y')->format('m/d/Y');
// outputs 02/06/2000

$value is caught by line 947

// Try to convert it using strtotime().
if (($date = strtotime($value)) !== false)
{
	return Carbon\Carbon::createFromTimestamp($date);
}

If $alternateFormat is used i believe createFromFormat() should come sooner in this method.

PhpSession messing up with tests?

After upgrading to Laravel 5.4 running phpunit outputs the error below.

There was 1 error:

  1. Tests\Feature\ExampleTest::testBasicTest
    ErrorException: session_start(): Cannot send session cookie - headers already sent by (output started at /project/vendor/phpunit/phpunit/src/Util/Printer.php:114)

/project/vendor/pragmarx/support/src/PhpSession.php:23
/project/vendor/pragmarx/support/src/PhpSession.php:14
/project/vendor/pragmarx/tracker/src/Vendor/Laravel/ServiceProvider.php:268
...

I've solved it temporarily by adding @ before session_start() in src/PhpSession.php, but I'm not quite sure what's going on and whether the issue comes from this package or from my setup.

private function startSession()
{
	if ( ! $this->isStarted())
	{
		@session_start();
	}
}

Not compatible with Laravel 10 Mailer

In /laravel/framework/src/Illuminate/Mail/Mailer.php it uses the value() function with two arguments.

This corresponds with laravel/framework/src/Illuminate/Collections/helpers.php where it accepts two arguments.

In helpers.php in this package (which gets loaded first and overrides the Laravel version) it only accepts one argument.

There is a pull request to bring helpers.php up to date, but it has failed your tests as it's not compatible with php <=7.1. That shouldn't matter because Laravel is also not compatible with these versions of PHP.

Can the tests be updated and the pull request merged?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.