idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
7,600
|
public function decodeFiles ( array $ files ) { $ suiteDocument = new Document ( 'phpbench' ) ; $ rootEl = $ suiteDocument -> createRoot ( 'phpbench' ) ; foreach ( $ files as $ file ) { $ fileDom = new Document ( ) ; $ fileDom -> load ( $ file ) ; foreach ( $ fileDom -> query ( './suite' ) as $ suiteEl ) { $ importedEl = $ suiteDocument -> importNode ( $ suiteEl , true ) ; $ rootEl -> appendChild ( $ importedEl ) ; } } return $ this -> decode ( $ suiteDocument ) ; }
|
Return a SuiteCollection from a number of PHPBench xml files .
|
7,601
|
public function evaluate ( array $ points ) { $ count = count ( $ this -> dataset ) ; $ bigger = count ( $ points ) > $ count ; if ( $ bigger ) { $ range = $ count - 1 ; } else { $ range = count ( $ points ) - 1 ; } $ result = array_fill ( 0 , count ( $ points ) , 0 ) ; foreach ( range ( 0 , $ range ) as $ i ) { if ( $ bigger ) { $ dataValue = $ this -> dataset [ $ i ] ; $ diff = array_map ( function ( $ point ) use ( $ dataValue ) { return $ dataValue - $ point ; } , $ points ) ; } else { $ diff = array_map ( function ( $ v ) use ( $ points , $ i ) { return $ v - $ points [ $ i ] ; } , $ this -> dataset ) ; } $ invCov = $ this -> invCov ; $ tDiff = array_map ( function ( $ v ) use ( $ invCov ) { return $ invCov * $ v ; } , $ diff ) ; $ multiplied = [ ] ; foreach ( $ diff as $ index => $ value ) { $ multiplied [ $ index ] = $ diff [ $ index ] * $ tDiff [ $ index ] ; } $ energy = array_map ( function ( $ v ) { return exp ( - ( $ v / 2 ) ) ; } , $ multiplied ) ; if ( $ bigger ) { $ sum = $ result ; foreach ( $ sum as $ index => $ value ) { $ sum [ $ index ] = $ sum [ $ index ] + $ energy [ $ index ] ; } $ result = $ sum ; } else { $ result [ $ i ] = array_sum ( $ energy ) ; } } $ result = array_map ( function ( $ v ) { return $ v / $ this -> normFactor ; } , $ result ) ; return $ result ; }
|
Evaluate the estimated pdf on a set of points .
|
7,602
|
public function setBandwidth ( $ bwMethod = null ) { if ( $ bwMethod == 'scott' || null === $ bwMethod ) { $ this -> coVarianceFactor = function ( ) { return pow ( count ( $ this -> dataset ) , - 1. / ( 5 ) ) ; } ; } elseif ( $ bwMethod == 'silverman' ) { $ this -> coVarianceFactor = function ( ) { return pow ( count ( $ this -> dataset ) * ( 3.0 ) / 4.0 , - 1. / ( 5 ) ) ; } ; } elseif ( is_numeric ( $ bwMethod ) ) { $ this -> coVarianceFactor = function ( ) use ( $ bwMethod ) { return $ bwMethod ; } ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Unknown bandwidth method "%s"' , $ bwMethod ) ) ; } $ this -> computeCovariance ( ) ; }
|
Compute the estimator bandwidth with given method .
|
7,603
|
public function visit ( Constraint $ constraint ) { $ sql = $ this -> doVisit ( $ constraint ) ; $ return = [ $ sql , $ this -> values ] ; $ this -> values = [ ] ; $ this -> paramCounter = 0 ; $ select = [ 'run.id' , 'run.uuid' , 'run.tag' , 'run.date' , 'subject.benchmark' , 'subject.name' , 'subject.id' , 'variant.id' , 'variant.sleep' , 'variant.output_time_unit' , 'variant.output_time_precision' , 'variant.output_mode' , 'variant.revolutions' , 'variant.retry_threshold' , 'variant.warmup' , 'iteration.time' , 'iteration.memory' , 'iteration.reject_count' , ] ; $ extraJoins = [ ] ; $ fieldNames = $ this -> getFieldNames ( $ constraint ) ; if ( in_array ( 'group' , $ fieldNames ) ) { $ extraJoins [ ] = 'LEFT JOIN sgroup_subject ON sgroup_subject.subject_id = subject.id' ; $ select [ ] = 'sgroup_subject.sgroup' ; } if ( in_array ( 'param' , $ fieldNames ) ) { $ extraJoins [ ] = 'LEFT JOIN variant_parameter ON variant_parameter.variant_id = variant.id' ; $ extraJoins [ ] = 'LEFT JOIN parameter ON variant_parameter.parameter_id = parameter.id' ; $ select [ ] = 'parameter.pkey' ; $ select [ ] = 'parameter.value' ; } $ selectSql = <<<'EOT'SELECT %s FROM iteration LEFT JOIN variant ON iteration.variant_id = variant.id LEFT JOIN subject ON variant.subject_id = subject.id LEFT JOIN run ON variant.run_id = run.id %sWHEREEOT ; $ select = array_map ( function ( $ value ) { return sprintf ( '%s AS "%s"' , $ value , $ value ) ; } , $ select ) ; $ selectSql = sprintf ( $ selectSql , implode ( ', ' , $ select ) , implode ( ' ' , $ extraJoins ) ) ; $ return [ 0 ] = $ selectSql . $ return [ 0 ] ; return $ return ; }
|
Convert the given constraint into an SQL query .
|
7,604
|
public function findBenchmarks ( $ path , array $ subjectFilter = [ ] , array $ groupFilter = [ ] ) { $ finder = new Finder ( ) ; $ path = PhpBench :: normalizePath ( $ path ) ; if ( ! file_exists ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'File or directory "%s" does not exist (cwd: %s)' , $ path , getcwd ( ) ) ) ; } if ( is_dir ( $ path ) ) { $ finder -> in ( $ path ) -> name ( '*.php' ) ; } else { $ finder -> in ( dirname ( $ path ) ) -> depth ( 0 ) -> name ( basename ( $ path ) ) ; } $ benchmarks = [ ] ; foreach ( $ finder as $ file ) { if ( ! is_file ( $ file ) ) { continue ; } $ benchmark = $ this -> factory -> getMetadataForFile ( $ file -> getPathname ( ) ) ; if ( null === $ benchmark ) { continue ; } if ( $ groupFilter ) { $ benchmark -> filterSubjectGroups ( $ groupFilter ) ; } if ( $ subjectFilter ) { $ benchmark -> filterSubjectNames ( $ subjectFilter ) ; } if ( false === $ benchmark -> hasSubjects ( ) ) { continue ; } $ benchmarks [ ] = $ benchmark ; } return $ benchmarks ; }
|
Build the BenchmarkMetadata collection .
|
7,605
|
public function generateReports ( SuiteCollection $ collection , array $ reportNames ) { $ reportDoms = [ ] ; $ reportConfigs = [ ] ; foreach ( $ reportNames as $ reportName ) { $ reportConfigs [ $ reportName ] = $ this -> generatorRegistry -> getConfig ( $ reportName ) ; } foreach ( $ reportConfigs as $ reportName => $ reportConfig ) { $ generatorName = $ reportConfig [ 'generator' ] ; $ generator = $ this -> generatorRegistry -> getService ( $ generatorName ) ; $ reportDom = $ generator -> generate ( $ collection , $ reportConfig ) ; if ( ! $ reportDom instanceof Document ) { throw new \ RuntimeException ( sprintf ( 'Report generator "%s" should have return a PhpBench\Dom\Document class, got: "%s"' , $ generatorName , is_object ( $ reportDom ) ? get_class ( $ reportDom ) : gettype ( $ reportDom ) ) ) ; } $ reportDom -> schemaValidate ( __DIR__ . '/schema/report.xsd' ) ; $ reportDoms [ ] = $ reportDom ; } return $ reportDoms ; }
|
Generate the named reports .
|
7,606
|
public function getMetric ( $ class , $ metric ) { $ metrics = $ this -> getResult ( $ class ) -> getMetrics ( ) ; if ( ! isset ( $ metrics [ $ metric ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown metric "%s" for result class "%s". Available metrics: "%s"' , $ metric , $ class , implode ( '", "' , array_keys ( $ metrics ) ) ) ) ; } return $ metrics [ $ metric ] ; }
|
Return the named metric for the given result class .
|
7,607
|
public function mergeCollection ( self $ collection ) { foreach ( $ collection -> getSuites ( ) as $ suite ) { $ this -> addSuite ( $ suite ) ; } }
|
Merge another collection into this one .
|
7,608
|
public function getParameterSets ( $ file , $ paramProviders ) { $ parameterSets = $ this -> launcher -> payload ( __DIR__ . '/template/parameter_set_extractor.template' , [ 'file' => $ file , 'class' => $ this -> getClassNameFromFile ( $ file ) , 'paramProviders' => var_export ( $ paramProviders , true ) , ] ) -> launch ( ) ; $ parameters = new \ RecursiveIteratorIterator ( new \ RecursiveArrayIterator ( $ parameterSets ) ) ; iterator_apply ( $ parameters , function ( \ Iterator $ iterator ) { $ parameter = $ iterator -> current ( ) ; if ( ! is_scalar ( $ parameter ) && isset ( $ parameter ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Parameter values must be scalar. Got "%s"' , is_object ( $ parameter ) ? get_class ( $ parameter ) : gettype ( $ parameter ) ) ) ; } } , [ $ parameters ] ) ; return $ parameterSets ; }
|
Return the parameter sets for the benchmark container in the given file .
|
7,609
|
public function toDestUnit ( float $ time , string $ destUnit = null , string $ mode = null ) { return self :: convert ( $ time , $ this -> sourceUnit , $ this -> getDestUnit ( $ destUnit ) , $ this -> getMode ( $ mode ) ) ; }
|
Convert instance value to given unit .
|
7,610
|
public function overrideDestUnit ( $ destUnit ) { self :: validateUnit ( $ destUnit ) ; $ this -> destUnit = $ destUnit ; $ this -> overriddenDestUnit = true ; }
|
Override the destination unit .
|
7,611
|
public function overrideMode ( $ mode ) { self :: validateMode ( $ mode ) ; $ this -> mode = $ mode ; $ this -> overriddenMode = true ; }
|
Override the mode .
|
7,612
|
public function getDestSuffix ( string $ unit = null , string $ mode = null ) { return self :: getSuffix ( $ this -> getDestUnit ( $ unit ) , $ this -> getMode ( $ mode ) ) ; }
|
Return the destination unit suffix .
|
7,613
|
public function format ( float $ time , string $ unit = null , string $ mode = null , int $ precision = null , bool $ suffix = true ) { $ value = number_format ( $ this -> toDestUnit ( $ time , $ unit , $ mode ) , $ precision !== null ? $ precision : $ this -> precision ) ; if ( false === $ suffix ) { return $ value ; } $ suffix = $ this -> getDestSuffix ( $ unit , $ mode ) ; return $ value . $ suffix ; }
|
Return a human readable representation of the unit including the suffix .
|
7,614
|
public static function convert ( float $ time , string $ unit , string $ destUnit , string $ mode ) { self :: validateMode ( $ mode ) ; if ( $ mode === self :: MODE_TIME ) { return self :: convertTo ( $ time , $ unit , $ destUnit ) ; } return self :: convertInto ( $ time , $ unit , $ destUnit ) ; }
|
Convert given time in given unit to given destination unit in given mode .
|
7,615
|
public static function convertInto ( float $ time , string $ unit , string $ destUnit ) { if ( ! $ time ) { return 0 ; } self :: validateUnit ( $ unit ) ; self :: validateUnit ( $ destUnit ) ; $ destMultiplier = self :: $ map [ $ destUnit ] ; $ sourceMultiplier = self :: $ map [ $ unit ] ; $ time = $ destMultiplier / ( $ time * $ sourceMultiplier ) ; return $ time ; }
|
Convert a given time INTO the given unit . That is how many times the given time will fit into the the destination unit . i . e . x per unit .
|
7,616
|
public static function convertTo ( float $ time , string $ unit , string $ destUnit ) { self :: validateUnit ( $ unit ) ; self :: validateUnit ( $ destUnit ) ; $ destM = self :: $ map [ $ destUnit ] ; $ sourceM = self :: $ map [ $ unit ] ; $ time = ( $ time * $ sourceM ) / $ destM ; return $ time ; }
|
Convert the given time from the given unit to the given destination unit .
|
7,617
|
public static function getSuffix ( $ unit , $ mode = null ) { self :: validateUnit ( $ unit ) ; $ suffix = self :: $ suffixes [ $ unit ] ; if ( $ mode === self :: MODE_THROUGHPUT ) { return sprintf ( 'ops/%s' , $ suffix ) ; } return $ suffix ; }
|
Return the suffix for a given unit .
|
7,618
|
public function classesFromFile ( $ filename ) { $ classes = $ this -> loader -> load ( $ filename ) ; $ this -> registerClasses ( $ classes ) ; }
|
Register classes from a given JSON encoded class definition file .
|
7,619
|
public function registerClasses ( array $ classDefinitions ) { foreach ( $ classDefinitions as $ className => $ formatDefinitions ) { $ this -> registerClass ( $ className , $ formatDefinitions ) ; } }
|
Register class definitions .
|
7,620
|
public function hasMethod ( $ name ) { foreach ( $ this -> reflectionClasses as $ reflectionClass ) { if ( isset ( $ reflectionClass -> methods [ $ name ] ) ) { return true ; } } return false ; }
|
Return true if the class hierarchy contains the named method .
|
7,621
|
public function hasStaticMethod ( $ name ) { foreach ( $ this -> reflectionClasses as $ reflectionClass ) { if ( isset ( $ reflectionClass -> methods [ $ name ] ) ) { $ method = $ reflectionClass -> methods [ $ name ] ; if ( $ method -> isStatic ) { return true ; } break ; } } return false ; }
|
Return true if the class hierarchy contains the named static method .
|
7,622
|
public function offsetGet ( $ offset ) { if ( ! $ this -> offsetExists ( $ offset ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Column "%s" does not exist, valid columns: "%s"' , $ offset , implode ( '", "' , array_keys ( $ this -> getArrayCopy ( ) ) ) ) ) ; } return parent :: offsetGet ( $ offset ) ; }
|
Return the given offset . Throw an exception if the given offset does not exist .
|
7,623
|
public function register ( $ name , FormatInterface $ format ) { if ( isset ( $ this -> formats [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Formatter with name "%s" is already registered' , $ name ) ) ; } $ this -> formats [ $ name ] = $ format ; }
|
Register a format class .
|
7,624
|
public function get ( $ name ) { if ( ! isset ( $ this -> formats [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown format "%s", known formats: "%s"' , $ name , implode ( ', ' , array_keys ( $ this -> formats ) ) ) ) ; } return $ this -> formats [ $ name ] ; }
|
Return the named format class .
|
7,625
|
public function encode ( SuiteCollection $ suiteCollection ) { $ dom = new Document ( ) ; $ rootEl = $ dom -> createRoot ( 'phpbench' ) ; $ rootEl -> setAttribute ( 'version' , PhpBench :: VERSION ) ; $ rootEl -> setAttributeNS ( 'http://www.w3.org/2000/xmlns/' , 'xmlns:xsi' , 'http://www.w3.org/2001/XMLSchema-instance' ) ; foreach ( $ suiteCollection -> getSuites ( ) as $ suite ) { $ suiteEl = $ rootEl -> appendElement ( 'suite' ) ; $ suiteEl -> setAttribute ( 'tag' , $ suite -> getTag ( ) ) ; $ suiteEl -> setAttribute ( 'context' , $ suite -> getTag ( ) ) ; $ suiteEl -> setAttribute ( 'date' , $ suite -> getDate ( ) -> format ( 'c' ) ) ; $ suiteEl -> setAttribute ( 'config-path' , $ suite -> getConfigPath ( ) ) ; $ suiteEl -> setAttribute ( 'uuid' , $ suite -> getUuid ( ) ) ; $ envEl = $ suiteEl -> appendElement ( 'env' ) ; foreach ( $ suite -> getEnvInformations ( ) as $ information ) { $ infoEl = $ envEl -> appendElement ( $ information -> getName ( ) ) ; foreach ( $ information as $ key => $ value ) { $ infoEl -> setAttribute ( $ key , $ value ) ; } } foreach ( $ suite -> getBenchmarks ( ) as $ benchmark ) { $ this -> processBenchmark ( $ benchmark , $ suiteEl ) ; } } return $ dom ; }
|
Encode a Suite object into a XML document .
|
7,626
|
public function addBaselineCallable ( $ name , $ callable ) { if ( isset ( $ this -> callables [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Baseline callable "%s" has already been registered.' , $ name ) ) ; } if ( ! is_callable ( $ callable ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Given baseline "%s" callable "%s" is not callable.' , $ name , is_string ( $ callable ) ? $ callable : gettype ( $ callable ) ) ) ; } $ this -> callables [ $ name ] = $ callable ; }
|
Add a baseline callable . The callable can be any callable accepted by call_user_func .
|
7,627
|
public function benchmark ( $ name , $ revs ) { if ( ! isset ( $ this -> callables [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown baseline callable "%s", known baseline callables: "%s"' , $ name , implode ( '", "' , array_keys ( $ this -> callables ) ) ) ) ; } $ start = microtime ( true ) ; call_user_func ( $ this -> callables [ $ name ] , $ revs ) ; return ( microtime ( true ) - $ start ) / $ revs * 1E6 ; }
|
Return mean time taken to execute the named baseline callable in microseconds .
|
7,628
|
private function configureFormatters ( OutputFormatterInterface $ formatter ) { $ formatter -> setStyle ( 'title' , new OutputFormatterStyle ( 'white' , null , [ 'bold' ] ) ) ; $ formatter -> setStyle ( 'subtitle' , new OutputFormatterStyle ( 'white' , null , [ ] ) ) ; $ formatter -> setStyle ( 'description' , new OutputFormatterStyle ( null , null , [ ] ) ) ; }
|
Adds some output formatters .
|
7,629
|
public function generateUuid ( ) { $ serialized = serialize ( $ this -> envInformations ) ; $ this -> uuid = dechex ( $ this -> getDate ( ) -> format ( 'Ymd' ) ) . substr ( sha1 ( implode ( [ microtime ( ) , $ serialized , $ this -> configPath , ] ) ) , 0 , - 7 ) ; }
|
Generate a universally unique identifier .
|
7,630
|
public function createSubject ( $ name ) { $ subject = new Subject ( $ this , $ name ) ; $ this -> subjects [ $ name ] = $ subject ; return $ subject ; }
|
Create and add a subject .
|
7,631
|
public static function stdev ( array $ values , $ sample = false ) { $ variance = self :: variance ( $ values , $ sample ) ; return \ sqrt ( $ variance ) ; }
|
Return the standard deviation of a given population .
|
7,632
|
public static function variance ( array $ values , $ sample = false ) { $ average = self :: mean ( $ values ) ; $ sum = 0 ; foreach ( $ values as $ value ) { $ diff = pow ( $ value - $ average , 2 ) ; $ sum += $ diff ; } if ( count ( $ values ) === 0 ) { return 0 ; } $ variance = $ sum / ( count ( $ values ) - ( $ sample ? 1 : 0 ) ) ; return $ variance ; }
|
Return the variance for a given population .
|
7,633
|
public static function kdeMode ( array $ population , $ space = 512 , $ bandwidth = null ) : float { if ( count ( $ population ) === 1 ) { return current ( $ population ) ; } if ( count ( $ population ) === 0 ) { return 0.0 ; } if ( min ( $ population ) == max ( $ population ) ) { return min ( $ population ) ; } $ kde = new Kde ( $ population , $ bandwidth ) ; $ space = self :: linspace ( min ( $ population ) , max ( $ population ) , $ space , true ) ; $ dist = $ kde -> evaluate ( $ space ) ; $ maxKeys = array_keys ( $ dist , max ( $ dist ) ) ; $ modes = [ ] ; foreach ( $ maxKeys as $ maxKey ) { $ modes [ ] = $ space [ $ maxKey ] ; } $ mode = array_sum ( $ modes ) / count ( $ modes ) ; return $ mode ; }
|
Return the mode using the kernel density estimator using the normal distribution .
|
7,634
|
public static function histogram ( array $ values , $ steps = 10 , $ lowerBound = null , $ upperBound = null ) { $ min = $ lowerBound ? : min ( $ values ) ; $ max = $ upperBound ? : max ( $ values ) ; $ range = $ max - $ min ; $ step = $ range / $ steps ; $ steps ++ ; $ histogram = [ ] ; $ floor = $ min ; for ( $ i = 0 ; $ i < $ steps ; $ i ++ ) { $ ceil = $ floor + $ step ; if ( ! isset ( $ histogram [ ( string ) $ floor ] ) ) { $ histogram [ ( string ) $ floor ] = 0 ; } foreach ( $ values as $ value ) { if ( $ value >= $ floor && $ value < $ ceil ) { $ histogram [ ( string ) $ floor ] ++ ; } } $ floor += $ step ; $ ceil += $ step ; } return $ histogram ; }
|
Generate a histogram .
|
7,635
|
public function createIteration ( array $ results = [ ] ) { $ index = count ( $ this -> iterations ) ; $ iteration = new Iteration ( $ index , $ this , $ results ) ; $ this -> iterations [ ] = $ iteration ; return $ iteration ; }
|
Create and add a new iteration .
|
7,636
|
public function getMetricValues ( $ resultClass , $ metricName ) { $ values = [ ] ; foreach ( $ this -> iterations as $ iteration ) { if ( $ iteration -> hasResult ( $ resultClass ) ) { $ values [ ] = $ iteration -> getMetric ( $ resultClass , $ metricName ) ; } } return $ values ; }
|
Return result values by class and metric name .
|
7,637
|
public function getMetricValuesByRev ( $ resultClass , $ metric ) { return array_map ( function ( $ value ) { return $ value / $ this -> getRevolutions ( ) ; } , $ this -> getMetricValues ( $ resultClass , $ metric ) ) ; }
|
Return the average metric values by revolution .
|
7,638
|
public function computeStats ( ) { $ this -> rejects = [ ] ; $ revs = $ this -> getRevolutions ( ) ; if ( 0 === count ( $ this -> iterations ) ) { return ; } $ times = $ this -> getMetricValuesByRev ( TimeResult :: class , 'net' ) ; $ retryThreshold = $ this -> getSubject ( ) -> getRetryThreshold ( ) ; $ this -> stats = new Distribution ( $ times , $ this -> computedStats ) ; foreach ( $ this -> iterations as $ iteration ) { $ timeResult = $ iteration -> getResult ( TimeResult :: class ) ; assert ( $ timeResult instanceof TimeResult ) ; if ( $ this -> stats -> getMean ( ) > 0 ) { $ deviation = 100 / $ this -> stats -> getMean ( ) * ( ( $ timeResult -> getRevTime ( $ iteration -> getVariant ( ) -> getRevolutions ( ) ) ) - $ this -> stats -> getMean ( ) ) ; } else { $ deviation = 0 ; } $ revTime = $ timeResult -> getRevTime ( $ revs ) ; $ zValue = $ this -> stats -> getStdev ( ) ? ( $ revTime - $ this -> stats -> getMean ( ) ) / $ this -> stats -> getStdev ( ) : 0 ; if ( null !== $ retryThreshold ) { if ( abs ( $ deviation ) >= $ retryThreshold ) { $ this -> rejects [ ] = $ iteration ; } } $ iteration -> setResult ( new ComputedResult ( $ zValue , $ deviation ) ) ; } $ this -> computed = true ; }
|
Calculate and set the deviation from the mean time for each iteration . If the deviation is greater than the rejection threshold then mark the iteration as rejected .
|
7,639
|
public function getStats ( ) { if ( null !== $ this -> errorStack ) { throw new \ RuntimeException ( sprintf ( 'Cannot retrieve stats when an exception was encountered ([%s] %s)' , $ this -> errorStack -> getTop ( ) -> getClass ( ) , $ this -> errorStack -> getTop ( ) -> getMessage ( ) ) ) ; } if ( false === $ this -> computed ) { throw new \ RuntimeException ( 'No statistics have yet been computed for this iteration set (::computeStats should be called)' ) ; } return $ this -> stats ; }
|
Return statistics about this iteration collection .
|
7,640
|
public function setException ( \ Exception $ exception ) { $ errors = [ ] ; do { $ errors [ ] = Error :: fromException ( $ exception ) ; } while ( $ exception = $ exception -> getPrevious ( ) ) ; $ this -> errorStack = new ErrorStack ( $ this , $ errors ) ; }
|
Create an error stack from an Exception .
|
7,641
|
public function assertionsFromRawCliConfig ( array $ rawAssertions ) { $ assertions = [ ] ; foreach ( $ rawAssertions as $ rawAssertion ) { $ config = $ this -> jsonDecoder -> decode ( $ rawAssertion ) ; $ assertions [ ] = new AssertionMetadata ( $ config ) ; } return $ assertions ; }
|
Return an array of assertion metadatas from the raw JSON - like stuff from the CLI .
|
7,642
|
public function registerService ( $ name , $ serviceId ) { if ( isset ( $ this -> serviceMap [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s service "%s" is already registered' , $ this -> serviceType , $ name ) ) ; } $ this -> serviceMap [ $ name ] = $ serviceId ; $ this -> services [ $ name ] = null ; }
|
Register a service ID with against the given name .
|
7,643
|
public function setService ( $ name , $ object ) { if ( isset ( $ this -> services [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s service "%s" already exists.' , $ this -> serviceType , $ name ) ) ; } $ this -> services [ $ name ] = $ object ; }
|
Directly set a named service .
|
7,644
|
public function getService ( $ name = null ) { $ name = $ name ? : $ this -> defaultService ; if ( ! $ name ) { throw new \ RuntimeException ( sprintf ( 'You must configure a default %s service, registered %s services: "%s"' , $ this -> serviceType , $ this -> serviceType , implode ( '", "' , array_keys ( $ this -> services ) ) ) ) ; } if ( isset ( $ this -> services [ $ name ] ) ) { return $ this -> services [ $ name ] ; } $ this -> assertServiceExists ( $ name ) ; $ this -> services [ $ name ] = $ this -> container -> get ( $ this -> serviceMap [ $ name ] ) ; return $ this -> services [ $ name ] ; }
|
Return the named service lazily creating it from the container if it has not yet been accessed .
|
7,645
|
private function parse ( $ input , $ context = '' ) { try { $ annotations = $ this -> docParser -> parse ( $ input , $ context ) ; } catch ( AnnotationException $ e ) { if ( ! preg_match ( '/The annotation "(.*)" .* was never imported/' , $ e -> getMessage ( ) , $ matches ) ) { throw $ e ; } throw new \ InvalidArgumentException ( sprintf ( 'Unrecognized annotation %s, valid PHPBench annotations: @%s' , $ matches [ 1 ] , implode ( ', @' , array_keys ( self :: $ phpBenchImports ) ) ) , 0 , $ e ) ; } return $ annotations ; }
|
Delegates to the doctrine DocParser but catches annotation not found errors and throws something useful .
|
7,646
|
public function getOrCreateSubject ( $ name ) { if ( isset ( $ this -> subjects [ $ name ] ) ) { return $ this -> subjects [ $ name ] ; } $ this -> subjects [ $ name ] = new SubjectMetadata ( $ this , $ name ) ; return $ this -> subjects [ $ name ] ; }
|
Get or create a new SubjectMetadata instance with the given name .
|
7,647
|
public function filterSubjectNames ( array $ filters ) { foreach ( array_keys ( $ this -> subjects ) as $ subjectName ) { $ unset = true ; foreach ( $ filters as $ filter ) { if ( preg_match ( sprintf ( '{^.*?%s.*?$}' , $ filter ) , sprintf ( '%s::%s' , $ this -> getClass ( ) , $ subjectName ) ) ) { $ unset = false ; break ; } } if ( true === $ unset ) { unset ( $ this -> subjects [ $ subjectName ] ) ; } } }
|
Remove all subjects whose name is not in the given list .
|
7,648
|
public function filterSubjectGroups ( array $ groups ) { foreach ( $ this -> subjects as $ subjectName => $ subject ) { if ( 0 === count ( array_intersect ( $ subject -> getGroups ( ) , $ groups ) ) ) { unset ( $ this -> subjects [ $ subjectName ] ) ; } } }
|
Remove all the subjects which are not contained in the given list of groups .
|
7,649
|
public function getConfig ( $ name ) { if ( is_array ( $ name ) ) { $ config = $ name ; $ name = uniqid ( ) ; $ this -> setConfig ( $ name , $ config ) ; } $ name = trim ( $ name ) ; $ name = $ this -> processRawCliConfig ( $ name ) ; if ( ! isset ( $ this -> configs [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'No %s configuration named "%s" exists. Known configurations: "%s"' , $ this -> serviceType , $ name , implode ( '", "' , array_keys ( $ this -> configs ) ) ) ) ; } if ( ! isset ( $ this -> resolvedConfigs [ $ name ] ) ) { $ this -> resolveConfig ( $ name ) ; } return $ this -> resolvedConfigs [ $ name ] ; }
|
Return the named configuration .
|
7,650
|
public function setConfig ( $ name , array $ config ) { if ( isset ( $ this -> configs [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s config "%s" already exists.' , $ this -> serviceType , $ name ) ) ; } $ this -> configs [ $ name ] = $ config ; }
|
Set a named configuration .
|
7,651
|
public function getInformations ( ) { $ informations = [ ] ; foreach ( $ this -> providers as $ provider ) { if ( false === $ provider -> isApplicable ( ) ) { continue ; } $ informations [ ] = $ provider -> getInformation ( ) ; } return $ informations ; }
|
Return information from the current environment .
|
7,652
|
private function getEntryIterator ( ) { $ files = $ this -> days -> current ( ) ; $ files = new \ DirectoryIterator ( $ this -> days -> current ( ) ) ; $ historyEntries = [ ] ; foreach ( $ files as $ file ) { if ( ! $ file -> isFile ( ) ) { continue ; } if ( $ file -> getExtension ( ) !== 'xml' ) { continue ; } $ historyEntries [ ] = $ this -> getHistoryEntry ( $ file -> getPathname ( ) ) ; } usort ( $ historyEntries , function ( $ entry1 , $ entry2 ) { if ( $ entry1 -> getDate ( ) -> format ( 'U' ) === $ entry2 -> getDate ( ) -> format ( 'U' ) ) { return ; } return $ entry1 -> getDate ( ) -> format ( 'U' ) < $ entry2 -> getDate ( ) -> format ( 'U' ) ; } ) ; return new \ ArrayIterator ( $ historyEntries ) ; }
|
Return an iterator for the history entries .
|
7,653
|
private function getHistoryEntry ( $ path ) { $ dom = new Document ( ) ; $ dom -> load ( $ path ) ; $ collection = $ this -> xmlDecoder -> decode ( $ dom ) ; $ suites = $ collection -> getSuites ( ) ; $ suite = reset ( $ suites ) ; $ envInformations = $ suite -> getEnvInformations ( ) ; $ vcsBranch = null ; if ( isset ( $ envInformations [ 'vcs' ] [ 'branch' ] ) ) { $ vcsBranch = $ envInformations [ 'vcs' ] [ 'branch' ] ; } $ summary = $ suite -> getSummary ( ) ; $ entry = new HistoryEntry ( $ suite -> getUuid ( ) , $ suite -> getDate ( ) , $ suite -> getTag ( ) , $ vcsBranch , $ summary -> getNbSubjects ( ) , $ summary -> getNbIterations ( ) , $ summary -> getNbRevolutions ( ) , $ summary -> getMinTime ( ) , $ summary -> getMaxTime ( ) , $ summary -> getMeanTime ( ) , $ summary -> getMeanRelStDev ( ) , $ summary -> getTotalTime ( ) ) ; return $ entry ; }
|
Hydrate and return the history entry for the given path .
|
7,654
|
private function processDiffs ( array $ tables , Config $ config ) { $ stat = $ config [ 'diff_col' ] ; if ( $ config [ 'compare' ] ) { return $ tables ; } if ( ! in_array ( 'diff' , $ config [ 'cols' ] ) ) { return $ tables ; } if ( ! in_array ( $ stat , $ config [ 'cols' ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The "%s" column must be visible when using the diff column' , $ stat ) ) ; } return F \ map ( $ tables , function ( $ table ) use ( $ stat ) { $ means = F \ map ( $ table , function ( $ row ) use ( $ stat ) { return $ row [ $ stat ] ; } ) ; $ min = min ( $ means ) ; return F \ map ( $ table , function ( $ row ) use ( $ min , $ stat ) { if ( $ row [ $ stat ] === 0 ) { $ row [ 'diff' ] = 0 ; return $ row ; } $ row [ 'diff' ] = $ row [ $ stat ] / $ min ; return $ row ; } ) ; } ) ; }
|
Calculate the diff column if it is displayed .
|
7,655
|
private function processSort ( array $ table , Config $ config ) { if ( $ config [ 'sort' ] ) { $ cols = array_reverse ( $ config [ 'sort' ] ) ; foreach ( $ cols as $ colName => $ direction ) { Sort :: mergeSort ( $ table , function ( $ elementA , $ elementB ) use ( $ colName , $ direction ) { if ( $ elementA [ $ colName ] == $ elementB [ $ colName ] ) { return 0 ; } if ( $ direction === 'asc' ) { return $ elementA [ $ colName ] < $ elementB [ $ colName ] ? - 1 : 1 ; } return $ elementA [ $ colName ] > $ elementB [ $ colName ] ? - 1 : 1 ; } ) ; } } if ( $ config [ 'break' ] ) { foreach ( $ config [ 'break' ] as $ colName ) { Sort :: mergeSort ( $ table , function ( $ elementA , $ elementB ) use ( $ colName ) { if ( $ elementA [ $ colName ] == $ elementB [ $ colName ] ) { return 0 ; } return $ elementA [ $ colName ] < $ elementB [ $ colName ] ? - 1 : 1 ; } ) ; } } return $ table ; }
|
Process the sorting also break sorting .
|
7,656
|
private function processCols ( array $ tables , Config $ config ) { if ( $ config [ 'cols' ] ) { $ cols = $ config [ 'cols' ] ; if ( $ config [ 'compare' ] ) { $ cols [ ] = $ config [ 'compare' ] ; $ cols = array_merge ( $ cols , $ config [ 'compare_fields' ] ) ; } $ tables = F \ map ( $ tables , function ( $ table ) use ( $ cols ) { return F \ map ( $ table , function ( $ row ) use ( $ cols ) { $ newRow = $ row -> newInstance ( [ ] ) ; foreach ( $ cols as $ col ) { if ( $ col === 'diff' ) { continue ; } $ newRow [ $ col ] = $ row [ $ col ] ; } return $ newRow ; } ) ; } ) ; } return $ tables ; }
|
Remove unwanted columns from the tables .
|
7,657
|
private function generateDocument ( array $ tables , Config $ config ) { $ document = new Document ( ) ; $ reportsEl = $ document -> createRoot ( 'reports' ) ; $ reportsEl -> setAttribute ( 'name' , 'table' ) ; $ reportEl = $ reportsEl -> appendElement ( 'report' ) ; $ classMap = array_merge ( $ this -> classMap , $ config [ 'class_map' ] ) ; if ( isset ( $ config [ 'title' ] ) ) { $ reportEl -> setAttribute ( 'title' , $ config [ 'title' ] ) ; } if ( isset ( $ config [ 'description' ] ) ) { $ reportEl -> appendElement ( 'description' , $ config [ 'description' ] ) ; } foreach ( $ tables as $ breakHash => $ table ) { $ tableEl = $ reportEl -> appendElement ( 'table' ) ; foreach ( $ table as $ row ) { $ colsEl = $ tableEl -> appendElement ( 'cols' ) ; foreach ( $ row -> getNames ( ) as $ colName ) { $ colEl = $ colsEl -> appendElement ( 'col' ) ; $ colEl -> setAttribute ( 'name' , $ colName ) ; $ colLabel = $ colName ; if ( isset ( $ config [ 'labels' ] [ $ colName ] ) ) { $ colLabel = $ config [ 'labels' ] [ $ colName ] ; } $ colEl -> setAttribute ( 'label' , $ colLabel ) ; } break ; } if ( $ breakHash ) { $ tableEl -> setAttribute ( 'title' , $ breakHash ) ; } $ groupEl = $ tableEl -> appendElement ( 'group' ) ; $ groupEl -> setAttribute ( 'name' , 'body' ) ; foreach ( $ table as $ row ) { $ rowEl = $ groupEl -> appendElement ( 'row' ) ; foreach ( $ row -> getFormatParams ( ) as $ paramName => $ paramValue ) { $ paramEl = $ rowEl -> appendElement ( 'formatter-param' , $ paramValue ) ; $ paramEl -> setAttribute ( 'name' , $ paramName ) ; } foreach ( $ row as $ key => $ value ) { $ cellEl = $ rowEl -> appendElement ( 'cell' , $ value ) ; $ cellEl -> setAttribute ( 'name' , $ key ) ; if ( isset ( $ classMap [ $ key ] ) ) { $ cellEl -> setAttribute ( 'class' , implode ( ' ' , $ classMap [ $ key ] ) ) ; } } } } return $ document ; }
|
Generate the report DOM document to pass to the report renderer .
|
7,658
|
private function resolveCompareColumnName ( Row $ row , $ name , $ index = 1 ) { if ( ! isset ( $ row [ $ name ] ) ) { return $ name ; } $ newName = $ name . '#' . ( string ) $ index ++ ; if ( ! isset ( $ row [ $ newName ] ) ) { return $ newName ; } return $ this -> resolveCompareColumnName ( $ row , $ name , $ index ) ; }
|
Recursively resolve a comparison column - find a column name that doesn t already exist by adding and incrementing an index .
|
7,659
|
private function normalize ( $ jsonString ) { if ( ! is_string ( $ jsonString ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected a string, got "%s"' , gettype ( $ jsonString ) ) ) ; } $ chars = str_split ( $ jsonString ) ; $ inRight = $ inQuote = $ inFakeQuote = false ; $ fakeQuoteStart = null ; if ( empty ( $ chars ) ) { return ; } if ( $ chars [ 0 ] !== '{' ) { array_unshift ( $ chars , '{' ) ; $ chars [ ] = '}' ; } for ( $ index = 0 ; $ index < count ( $ chars ) ; $ index ++ ) { $ char = $ chars [ $ index ] ; $ prevChar = isset ( $ chars [ $ index - 1 ] ) ? $ chars [ $ index - 1 ] : null ; if ( ! $ inQuote && $ prevChar == ':' ) { $ inRight = true ; } if ( ! $ inQuote && preg_match ( '{\{,}' , $ char ) ) { $ inRight = false ; } if ( ! $ inQuote && preg_match ( '{[\$a-zA-Z0-9]}' , $ char ) ) { array_splice ( $ chars , $ index , 0 , '"' ) ; $ fakeQuoteStart = $ index ; $ index ++ ; $ inQuote = $ inFakeQuote = true ; continue ; } if ( $ inFakeQuote && preg_match ( '{[\s:\}\],]}' , $ char ) ) { if ( ! $ inRight && $ char === ']' ) { continue ; } if ( $ inRight ) { $ string = implode ( '' , array_slice ( $ chars , $ fakeQuoteStart + 1 , $ index - 1 - $ fakeQuoteStart ) ) ; if ( is_numeric ( $ string ) ) { unset ( $ chars [ $ fakeQuoteStart ] ) ; $ chars = array_values ( $ chars ) ; $ inQuote = $ inFakeQuote = false ; $ index -- ; continue ; } if ( in_array ( $ string , [ 'true' , 'false' ] ) ) { unset ( $ chars [ $ fakeQuoteStart ] ) ; $ chars = array_values ( $ chars ) ; $ inQuote = $ inFakeQuote = false ; $ index -- ; continue ; } } array_splice ( $ chars , $ index , 0 , '"' ) ; $ index ++ ; $ inQuote = $ inFakeQuote = false ; continue ; } if ( ! $ inQuote && $ char === '"' ) { $ inQuote = true ; continue ; } if ( $ inQuote && $ char === '"' && $ prevChar !== '\\' ) { $ inQuote = $ inFakeQuote = false ; continue ; } } if ( $ inFakeQuote ) { $ chars [ ] = '"' ; } $ normalized = implode ( '' , $ chars ) ; return $ normalized ; }
|
Allow non - strict JSON - i . e . if no quotes are provided then try and add them .
|
7,660
|
public function createVariant ( ParameterSet $ parameterSet , $ revolutions , $ warmup , array $ computedStats = [ ] ) { $ variant = new Variant ( $ this , $ parameterSet , $ revolutions , $ warmup , $ computedStats ) ; $ this -> variants [ ] = $ variant ; return $ variant ; }
|
Create and add a new variant based on this subject .
|
7,661
|
public function setFailureCount ( $ service , $ failureCount ) { $ this -> adapter -> save ( $ this -> failureKey ( $ service ) , $ failureCount ) ; }
|
sets failure count
|
7,662
|
public function setLastFailureTime ( $ service , $ lastFailureTime ) { $ this -> adapter -> saveLastFailureTime ( $ this -> lastFailureKey ( $ service ) , $ lastFailureTime ) ; }
|
sets last failure time
|
7,663
|
private function throwExceptionIfErrorOccurred ( ) { $ errorResultCodes = [ \ Memcached :: RES_FAILURE , \ Memcached :: RES_SERVER_TEMPORARILY_DISABLED , \ Memcached :: RES_SERVER_MEMORY_ALLOCATION_FAILURE , ] ; if ( in_array ( $ this -> memcached -> getResultCode ( ) , $ errorResultCodes , true ) ) { throw new StorageException ( $ this -> memcached -> getResultMessage ( ) ) ; } }
|
Throws an exception if some error occurs in memcached .
|
7,664
|
public function getAuthorizeUrl ( string $ response_type , int $ client_id , string $ redirect_uri , string $ display , ? array $ scope = null , ? string $ state = null , ? array $ group_ids = null , bool $ revoke = false ) : string { $ scope_mask = 0 ; foreach ( $ scope as $ scope_setting ) { $ scope_mask |= $ scope_setting ; } $ params = array ( static :: PARAM_CLIENT_ID => $ client_id , static :: PARAM_REDIRECT_URI => $ redirect_uri , static :: PARAM_DISPLAY => $ display , static :: PARAM_SCOPE => $ scope_mask , static :: PARAM_STATE => $ state , static :: PARAM_RESPONSE_TYPE => $ response_type , static :: PARAM_VERSION => $ this -> version , ) ; if ( $ group_ids ) { $ params [ static :: PARAM_GROUP_IDS ] = implode ( ',' , $ group_ids ) ; } if ( $ revoke ) { $ params [ static :: PARAM_REVOKE ] = 1 ; } return $ this -> host . static :: ENDPOINT_AUTHORIZE . '?' . http_build_query ( $ params ) ; }
|
Get authorize url
|
7,665
|
protected function checkOAuthResponse ( TransportClientResponse $ response ) { $ this -> checkHttpStatus ( $ response ) ; $ body = $ response -> getBody ( ) ; $ decode_body = $ this -> decodeBody ( $ body ) ; if ( isset ( $ decode_body [ static :: RESPONSE_KEY_ERROR ] ) ) { throw new VKOAuthException ( "{$decode_body[static::RESPONSE_KEY_ERROR_DESCRIPTION]}. OAuth error {$decode_body[static::RESPONSE_KEY_ERROR]}" ) ; } return $ decode_body ; }
|
Decodes the authorization response and checks its status code and whether it has an error .
|
7,666
|
protected function decodeBody ( string $ body ) { $ decoded_body = json_decode ( $ body , true ) ; if ( $ decoded_body === null || ! is_array ( $ decoded_body ) ) { $ decoded_body = [ ] ; } return $ decoded_body ; }
|
Decodes body .
|
7,667
|
public function listen ( ? int $ ts = null ) { if ( $ this -> server === null ) { $ this -> server = $ this -> getLongPollServer ( ) ; } if ( $ this -> last_ts === null ) { $ this -> last_ts = $ this -> server [ static :: SERVER_TIMESTAMP ] ; } if ( $ ts === null ) { $ ts = $ this -> last_ts ; } try { $ response = $ this -> getEvents ( $ this -> server [ static :: SERVER_URL ] , $ this -> server [ static :: SERVER_KEY ] , $ ts ) ; foreach ( $ response [ static :: EVENTS_UPDATES ] as $ event ) { $ this -> handler -> parseObject ( $ this -> group_id , null , $ event [ static :: EVENT_TYPE ] , $ event [ static :: EVENT_OBJECT ] ) ; } $ this -> last_ts = $ response [ static :: EVENTS_TS ] ; } catch ( VKLongPollServerKeyExpiredException $ e ) { $ this -> server = $ this -> getLongPollServer ( ) ; } return $ this -> last_ts ; }
|
Starts listening to LongPoll events .
|
7,668
|
protected function getLongPollServer ( ) { $ params = array ( static :: PARAM_GROUP_ID => $ this -> group_id ) ; $ server = $ this -> api_client -> groups ( ) -> getLongPollServer ( $ this -> access_token , $ params ) ; return array ( static :: SERVER_URL => $ server [ 'server' ] , static :: SERVER_TIMESTAMP => $ server [ 'ts' ] , static :: SERVER_KEY => $ server [ 'key' ] , ) ; }
|
Get long poll server
|
7,669
|
public function getEvents ( string $ host , string $ key , int $ ts ) { $ params = array ( static :: PARAM_KEY => $ key , static :: PARAM_TS => $ ts , static :: PARAM_WAIT => $ this -> wait , static :: PARAM_ACT => static :: VALUE_ACT ) ; try { $ response = $ this -> http_client -> get ( $ host , $ params ) ; } catch ( TransportRequestException $ e ) { throw new VKClientException ( $ e ) ; } return $ this -> parseResponse ( $ params , $ response ) ; }
|
Retrieves events from long poll server starting from the specified timestamp .
|
7,670
|
private function parseResponse ( array $ params , TransportClientResponse $ response ) { $ this -> checkHttpStatus ( $ response ) ; $ body = $ response -> getBody ( ) ; $ decode_body = $ this -> decodeBody ( $ body ) ; if ( isset ( $ decode_body [ static :: EVENTS_FAILED ] ) ) { switch ( $ decode_body [ static :: EVENTS_FAILED ] ) { case static :: ERROR_CODE_INCORRECT_TS_VALUE : $ ts = $ params [ static :: PARAM_TS ] ; $ msg = '\'ts\' value is incorrect, minimal value is 1, maximal value is ' . $ ts ; throw new VKLongPollServerTsException ( $ msg ) ; case static :: ERROR_CODE_TOKEN_EXPIRED : throw new VKLongPollServerKeyExpiredException ( 'Try to generate a new key.' ) ; default : throw new VKClientException ( 'Unknown LongPollServer exception, something went wrong. ' . $ decode_body ) ; } } return $ decode_body ; }
|
Decodes the LongPoll response and checks its status code and whether it has a failed key .
|
7,671
|
public function get ( string $ url , ? array $ payload = null ) : TransportClientResponse { return $ this -> sendRequest ( $ url . static :: QUESTION_MARK . http_build_query ( $ payload ) , array ( ) ) ; }
|
Makes get request .
|
7,672
|
public function upload ( string $ url , string $ parameter_name , string $ path ) : TransportClientResponse { $ payload = array ( ) ; $ payload [ $ parameter_name ] = ( class_exists ( 'CURLFile' , false ) ) ? new \ CURLFile ( $ path ) : '@' . $ path ; return $ this -> sendRequest ( $ url , array ( CURLOPT_POST => 1 , CURLOPT_HTTPHEADER => array ( static :: HEADER_UPLOAD_CONTENT_TYPE , ) , CURLOPT_POSTFIELDS => $ payload ) ) ; }
|
Makes upload request .
|
7,673
|
public function sendRequest ( string $ url , array $ opts ) { $ curl = curl_init ( $ url ) ; curl_setopt_array ( $ curl , $ this -> initial_opts + $ opts ) ; $ response = curl_exec ( $ curl ) ; $ curl_error_code = curl_errno ( $ curl ) ; $ curl_error = curl_error ( $ curl ) ; $ http_status = curl_getinfo ( $ curl , CURLINFO_RESPONSE_CODE ) ; curl_close ( $ curl ) ; if ( $ curl_error || $ curl_error_code ) { $ error_msg = "Failed curl request. Curl error {$curl_error_code}" ; if ( $ curl_error ) { $ error_msg .= ": {$curl_error}" ; } $ error_msg .= '.' ; throw new TransportRequestException ( $ error_msg ) ; } return $ this -> parseRawResponse ( $ http_status , $ response ) ; }
|
Makes and sends request .
|
7,674
|
protected function parseRawResponse ( int $ http_status , string $ response ) { list ( $ raw_headers , $ body ) = $ this -> extractResponseHeadersAndBody ( $ response ) ; $ headers = $ this -> getHeaders ( $ raw_headers ) ; return new TransportClientResponse ( $ http_status , $ headers , $ body ) ; }
|
Breaks the raw response down into its headers body and http status code .
|
7,675
|
protected function extractResponseHeadersAndBody ( string $ response ) { $ parts = explode ( "\r\n\r\n" , $ response ) ; $ raw_body = array_pop ( $ parts ) ; $ raw_headers = implode ( "\r\n\r\n" , $ parts ) ; return [ trim ( $ raw_headers ) , trim ( $ raw_body ) ] ; }
|
Extracts the headers and the body into a two - part array .
|
7,676
|
protected function getHeaders ( string $ raw_headers ) { $ raw_headers = str_replace ( "\r\n" , "\n" , $ raw_headers ) ; $ header_collection = explode ( "\n\n" , trim ( $ raw_headers ) ) ; $ raw_header = array_pop ( $ header_collection ) ; $ header_components = explode ( "\n" , $ raw_header ) ; $ result = array ( ) ; $ http_status = 0 ; foreach ( $ header_components as $ line ) { if ( strpos ( $ line , ': ' ) === false ) { $ http_status = $ this -> getHttpStatus ( $ line ) ; } else { list ( $ key , $ value ) = explode ( ': ' , $ line , 2 ) ; $ result [ $ key ] = $ value ; } } return array ( $ http_status , $ result ) ; }
|
Parses the raw headers and sets as an array .
|
7,677
|
public function upload ( string $ upload_url , string $ parameter_name , string $ path ) { try { $ response = $ this -> http_client -> upload ( $ upload_url , $ parameter_name , $ path ) ; } catch ( TransportRequestException $ e ) { throw new VKClientException ( $ e ) ; } return $ this -> parseResponse ( $ response ) ; }
|
Uploads data by its path to the given url .
|
7,678
|
private function parseResponse ( TransportClientResponse $ response ) { $ this -> checkHttpStatus ( $ response ) ; $ body = $ response -> getBody ( ) ; $ decode_body = $ this -> decodeBody ( $ body ) ; if ( isset ( $ decode_body [ static :: KEY_ERROR ] ) ) { $ error = $ decode_body [ static :: KEY_ERROR ] ; $ api_error = new VKApiError ( $ error ) ; throw ExceptionMapper :: parse ( $ api_error ) ; } if ( isset ( $ decode_body [ static :: KEY_RESPONSE ] ) ) { return $ decode_body [ static :: KEY_RESPONSE ] ; } else { return $ decode_body ; } }
|
Decodes the response and checks its status code and whether it has an Api error . Returns decoded response .
|
7,679
|
private function formatParams ( array $ params ) { foreach ( $ params as $ key => $ value ) { if ( is_array ( $ value ) ) { $ params [ $ key ] = implode ( ',' , $ value ) ; } else if ( is_bool ( $ value ) ) { $ params [ $ key ] = $ value ? 1 : 0 ; } } return $ params ; }
|
Formats given array of parameters for making the request .
|
7,680
|
public function send ( DocumentInterface $ document ) { $ xml = $ this -> getXmlSigned ( $ document ) ; return $ this -> sender -> send ( $ document -> getName ( ) , $ xml ) ; }
|
Build and send document .
|
7,681
|
public function getXmlSigned ( DocumentInterface $ document ) { $ classDoc = get_class ( $ document ) ; return $ this -> factory -> setBuilder ( $ this -> getBuilder ( $ classDoc ) ) -> getXmlSigned ( $ document ) ; }
|
Get signed xml from document .
|
7,682
|
public function send ( DocumentInterface $ document ) { $ classDoc = get_class ( $ document ) ; $ this -> factory -> setBuilder ( $ this -> getBuilder ( $ classDoc ) ) -> setSender ( $ this -> getSender ( $ classDoc ) ) ; return $ this -> factory -> send ( $ document ) ; }
|
Envia documento .
|
7,683
|
public function sendXml ( $ type , $ name , $ xml ) { $ this -> factory -> setBuilder ( $ this -> getBuilder ( $ type ) ) -> setSender ( $ this -> getSender ( $ type ) ) ; return $ this -> factory -> sendXml ( $ name , $ xml ) ; }
|
Envia xml generado .
|
7,684
|
protected function attempLoginUsingUsernameAsAnEmail ( Request $ request ) { return $ this -> guard ( ) -> attempt ( [ 'email' => $ request -> input ( 'username' ) , 'password' => $ request -> input ( 'password' ) ] , $ request -> has ( 'remember' ) ) ; }
|
Attempt to log the user into application using username as an email .
|
7,685
|
protected function createAdminUser ( ) { try { factory ( get_class ( app ( 'App\User' ) ) ) -> create ( [ "name" => env ( 'ADMIN_USER' , $ this -> username ( ) ) , "email" => env ( 'ADMIN_EMAIL' , $ this -> email ( ) ) , "password" => bcrypt ( env ( 'ADMIN_PWD' , '123456' ) ) ] ) ; } catch ( \ Illuminate \ Database \ QueryException $ exception ) { } }
|
Create admin user .
|
7,686
|
protected function sendResetLinkResponse ( Request $ request , $ response ) { if ( $ request -> expectsJson ( ) ) { return response ( ) -> json ( [ 'status' => trans ( $ response ) ] ) ; } return back ( ) -> with ( 'status' , trans ( $ response ) ) ; }
|
Get the response for a successful password reset link .
|
7,687
|
protected function obtainReplacements ( ) { return [ 'ROUTE_LINK' => $ link = $ this -> getReplacements ( ) [ 0 ] , 'ROUTE_CONTROLLER' => $ this -> controller ( $ this -> getReplacements ( ) [ 1 ] ) , 'ROUTE_METHOD' => $ this -> getReplacements ( ) [ 2 ] , 'ROUTE_NAME' => dot_path ( $ link ) , ] ; }
|
Obtain replacements .
|
7,688
|
public function publicAssets ( ) { return [ ADMINLTETEMPLATE_PATH . '/public/css' => public_path ( 'css' ) , ADMINLTETEMPLATE_PATH . '/public/js' => public_path ( 'js' ) , ADMINLTETEMPLATE_PATH . '/public/fonts' => public_path ( 'fonts' ) , ADMINLTETEMPLATE_PATH . '/public/img' => public_path ( 'img' ) , ADMINLTETEMPLATE_PATH . '/public/mix-manifest.json' => public_path ( 'mix-manifest.json' ) ] ; }
|
Public assets copy path .
|
7,689
|
public function views ( ) { return [ ADMINLTETEMPLATE_PATH . '/resources/views/auth' => resource_path ( 'views/vendor/adminlte/auth' ) , ADMINLTETEMPLATE_PATH . '/resources/views/errors' => resource_path ( 'views/vendor/adminlte/errors' ) , ADMINLTETEMPLATE_PATH . '/resources/views/layouts' => resource_path ( 'views/vendor/adminlte/layouts' ) , ADMINLTETEMPLATE_PATH . '/resources/views/home.blade.php' => resource_path ( 'views/vendor/adminlte/home.blade.php' ) , ADMINLTETEMPLATE_PATH . '/resources/views/welcome.blade.php' => resource_path ( 'views/welcome.blade.php' ) , ] ; }
|
Views copy path .
|
7,690
|
public function resourceAssets ( ) { return [ ADMINLTETEMPLATE_PATH . '/resources/assets/css' => resource_path ( 'assets/css' ) , ADMINLTETEMPLATE_PATH . '/resources/assets/img' => resource_path ( 'assets/img' ) , ADMINLTETEMPLATE_PATH . '/resources/assets/js' => resource_path ( 'assets/js' ) , ADMINLTETEMPLATE_PATH . '/webpack.mix.js' => base_path ( 'webpack.mix.js' ) , ADMINLTETEMPLATE_PATH . '/package.json' => base_path ( 'package.json' ) , ] ; }
|
Resource assets copy path .
|
7,691
|
private function install ( $ files ) { foreach ( $ files as $ fileSrc => $ fileDst ) { if ( file_exists ( $ fileDst ) && ! $ this -> force && ! $ this -> confirmOverwrite ( basename ( $ fileDst ) ) ) { return ; } if ( $ this -> files -> isFile ( $ fileSrc ) ) { $ this -> publishFile ( $ fileSrc , $ fileDst ) ; } elseif ( $ this -> files -> isDirectory ( $ fileSrc ) ) { $ this -> publishDirectory ( $ fileSrc , $ fileDst ) ; } else { $ this -> error ( "Can't locate path: <{$fileSrc}>" ) ; } } }
|
Install files from array .
|
7,692
|
protected function command ( ) { $ api = $ this -> option ( 'api' ) ? ' --api ' : '' ; $ action = $ this -> argument ( 'action' ) ? ' ' . $ this -> argument ( 'action' ) . ' ' : '' ; return 'php artisan make:route ' . $ this -> argument ( 'link' ) . $ action . ' --type=' . $ this -> option ( 'type' ) . ' --method=' . $ this -> option ( 'method' ) . $ api . ' -a --menu' ; }
|
Obtain command .
|
7,693
|
protected function controllerMethod ( $ controllername ) { if ( str_contains ( $ controller = $ controllername , '@' ) ) { return substr ( $ controllername , strpos ( $ controllername , '@' ) + 1 , strlen ( $ controllername ) ) ; } return 'index' ; }
|
Get method from controller name .
|
7,694
|
protected function email ( ) { if ( ( $ email = env ( 'ADMIN_EMAIL' , null ) ) != null ) { return $ email ; } if ( ( $ email = git_user_email ( ) ) != null ) { return $ email ; } return "admin@example.com" ; }
|
Obtain admin email .
|
7,695
|
public function username ( ) { if ( ( $ username = env ( 'ADMIN_USERNAME' , null ) ) != null ) { return $ username ; } if ( ( $ username = git_user_name ( ) ) != null ) { return $ username ; } return "Admin" ; }
|
Obtains username .
|
7,696
|
protected function routeExists ( $ link ) { if ( $ this -> option ( 'api' ) ) { return $ this -> apiRouteExists ( $ link ) ; } return $ this -> webRouteExists ( $ link ) ; }
|
Check if route exists .
|
7,697
|
protected function webRouteExists ( $ link ) { $ link = $ this -> removeTrailingSlashIfExists ( $ link ) ; $ link = $ this -> removeDuplicatedTrailingSlashes ( $ link ) ; foreach ( Route :: getRoutes ( ) as $ value ) { if ( in_array ( strtoupper ( $ this -> option ( 'method' ) ) , array_merge ( $ value -> methods ( ) , [ 'ANY' ] ) ) && $ value -> uri ( ) === $ link ) { return true ; } } return false ; }
|
Check if web route exists .
|
7,698
|
protected function action ( ) { if ( $ this -> argument ( 'action' ) != null ) { return $ this -> argument ( 'action' ) ; } if ( strtolower ( $ this -> option ( 'type' ) ) != 'regular' ) { return $ this -> argument ( 'link' ) . 'Controller' ; } return $ this -> argument ( 'link' ) ; }
|
Get the action replacement .
|
7,699
|
protected function validateMethod ( ) { if ( ! in_array ( strtoupper ( $ this -> option ( 'method' ) ) , $ methods = array_merge ( Router :: $ verbs , [ 'ANY' ] ) ) ) { throw new MethodNotAllowedException ( $ methods ) ; } }
|
Validate option method .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.