idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
43,000
public static function htToTtc ( $ price , $ tax , bool $ taxIsPercent = false ) { if ( $ taxIsPercent ) { $ tax = $ tax / 100 ; } return $ price + ( $ price * $ tax ) ; }
HT to TTC transformation
43,001
public static function TtcToHt ( $ price , $ tax , bool $ taxIsPercent = false ) { if ( $ taxIsPercent ) { $ tax = $ tax / 100 ; } return $ price / ( 1 + $ tax ) ; }
TTC to HT transformation
43,002
public static function priceWithDiscount ( $ price , $ discount , bool $ discountIsPercent = false ) { if ( $ discountIsPercent ) { $ discount = $ discount / 100 ; } return $ price - ( $ price * $ discount ) ; }
Get a price minus the discount
43,003
public function areAllowed ( array $ testRoles , array $ testActions ) { if ( count ( $ testRoles ) == 0 ) { $ testRoles = [ '' ] ; } $ roleMatch = false ; foreach ( $ this -> roles as $ role ) { if ( count ( array_filter ( $ testRoles , function ( $ testRole ) use ( $ role ) { return preg_match ( $ role , $ testRole ) ; } ) ) > 0 ) { $ roleMatch = true ; break ; } } if ( ! $ roleMatch ) { return new AllowedResult ; } $ allowMatches = 0 ; foreach ( $ testActions as $ testAction ) { $ allowMatch = count ( array_filter ( $ this -> allow , function ( $ action ) use ( $ testAction ) { return preg_match ( $ action , $ testAction ) ; } ) ) > 0 ; $ denyMatch = count ( array_filter ( $ this -> deny , function ( $ action ) use ( $ testAction ) { return preg_match ( $ action , $ testAction ) ; } ) ) > 0 ; if ( $ denyMatch ) { return new AllowedResult ( false , [ ] , [ $ this -> stateField => $ this -> regex ( $ this -> states ) ] ) ; } if ( $ allowMatch ) { $ allowMatches ++ ; } } if ( $ allowMatches == count ( $ testActions ) ) { return new AllowedResult ( true , [ ] , [ $ this -> stateField => $ this -> regex ( $ this -> states ) ] ) ; } return new AllowedResult ; }
Will test if a user with the supplied roles can do ALL the supplied actions .
43,004
private function resolveSubject ( Subject $ part ) { $ subject = $ part -> getSubject ( ) ; foreach ( $ part -> getParameters ( ) as $ search => $ replace ) { $ subject = str_replace ( $ search , $ replace , $ subject ) ; } return $ subject ; }
Resolve the subject .
43,005
protected function getModuleName ( PackageInterface $ package ) { $ extra = $ package -> getExtra ( ) ; if ( isset ( $ extra [ 'modulename' ] ) ) { $ name = $ extra [ 'modulename' ] ; } else { $ name = strtr ( $ package -> getPrettyName ( ) , array ( '\\' => '.' , '-' => '.' , '_' => '.' , ' ' => '' ) ) ; } return $ name ; }
Get the module name
43,006
protected function _normalizeInt ( $ value ) { $ origValue = $ value ; if ( $ value instanceof Stringable ) { $ value = $ this -> _normalizeString ( $ value ) ; } if ( ! is_numeric ( $ value ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Not a number' ) , null , null , $ origValue ) ; } $ value += 0 ; if ( fmod ( $ value , 1 ) !== 0.00 ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Not a whole number' ) , null , null , $ origValue ) ; } $ value = ( int ) $ value ; return $ value ; }
Normalizes a value into an integer .
43,007
public function count ( $ stat_key , $ count = 1 ) { if ( ! isset ( $ this -> config [ 'user_key' ] ) ) { throw new Exception ( 'StatHat user key not set.' ) ; } $ this -> post ( 'c' , [ 'ukey' => $ this -> config [ 'user_key' ] , 'key' => $ stat_key , 'count' => $ count ] ) ; }
Increment a counter using the classic API .
43,008
public function value ( $ stat_key , $ value ) { if ( ! isset ( $ this -> config [ 'user_key' ] ) ) { throw new Exception ( 'StatHat user key not set.' ) ; } $ this -> post ( 'v' , [ 'ukey' => $ this -> config [ 'user_key' ] , 'key' => $ stat_key , 'value' => $ value ] ) ; }
Send a value using the classic API .
43,009
public function ezCount ( $ stat , $ count = 1 ) { if ( ! isset ( $ this -> config [ 'ez_key' ] ) ) { throw new Exception ( 'StatHat EZ key not set.' ) ; } if ( ! empty ( $ this -> config [ 'prefix' ] ) ) { $ stat = $ this -> config [ 'prefix' ] . $ stat ; } $ this -> post ( 'ez' , [ 'ezkey' => $ this -> config [ 'ez_key' ] , 'stat' => $ stat , 'count' => $ count ] ) ; }
Increment a counter using the EZ API .
43,010
public function ezValue ( $ stat , $ value ) { if ( ! isset ( $ this -> config [ 'ez_key' ] ) ) { throw new Exception ( 'StatHat EZ key not set.' ) ; } if ( ! empty ( $ this -> config [ 'prefix' ] ) ) { $ stat = $ this -> config [ 'prefix' ] . $ stat ; } $ this -> post ( 'ez' , [ 'ezkey' => $ this -> config [ 'ez_key' ] , 'stat' => $ stat , 'value' => $ value ] ) ; }
Send a value using the EZ API .
43,011
public function listAlerts ( ) { if ( ! isset ( $ this -> config [ 'access_token' ] ) ) { throw new Exception ( 'StatHat Alerts API Access Token not set.' ) ; } $ result = $ this -> deleteAlertCurl ( 'x/' . $ this -> config [ 'access_token' ] . '/alerts/' . $ alert_id ) ; return $ result ; }
List stat alerts using the Alerts API . Used to look up alert IDs of alerts assigned to certain stats .
43,012
public function getAlerts ( ) { if ( ! isset ( $ this -> config [ 'access_token' ] ) ) { throw new Exception ( 'StatHat Alerts API Access Token not set.' ) ; } $ result = $ this -> curlGet ( $ this -> alerts_url . '/x/' . $ this -> config [ 'access_token' ] . '/alerts' ) ; return $ result ; }
Get listing of all stat alerts using the Alerts API .
43,013
public function deleteAlert ( $ alert_id ) { if ( ! isset ( $ this -> config [ 'access_token' ] ) ) { throw new Exception ( 'StatHat Alerts API Access Token not set.' ) ; } $ result = $ this -> curlDelete ( $ this -> alerts_url . '/x/' . $ this -> config [ 'access_token' ] . '/alerts/' . $ alert_id ) ; return $ result ; }
Delete a stat alert using the Alerts API .
43,014
private function post ( $ route = '' , array $ body = [ ] ) { if ( $ this -> config [ 'debug' ] ) { return ; } $ contents = http_build_query ( $ body ) ; $ parts = parse_url ( $ this -> url . '/' . $ route ) ; $ err_num = null ; $ err_str = null ; $ fp = fsockopen ( $ parts [ 'host' ] , isset ( $ parts [ 'port' ] ) ? $ parts [ 'port' ] : 80 , $ err_num , $ err_str , 30 ) ; $ out = 'POST ' . $ parts [ 'path' ] . ' HTTP/1.1' . "\r\n" ; $ out .= 'Host: ' . $ parts [ 'host' ] . "\r\n" ; $ out .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n" ; $ out .= 'Content-Length: ' . strlen ( $ contents ) . "\r\n" ; $ out .= 'Connection: Close' . "\r\n\r\n" ; if ( isset ( $ contents ) ) { $ out .= $ contents ; } fwrite ( $ fp , $ out ) ; fclose ( $ fp ) ; }
Perform an asynchronous POST request to the given route .
43,015
public function build ( ) : Response { $ view_root = '' ; $ template_name = $ this -> get_template_name ( ) ; $ file_extension = $ this -> get_file_extension ( $ view_root , $ template_name ) ; $ view_data = $ this -> view_data ; $ content = '' ; if ( 'handlebars' === $ file_extension ) { $ view = new Simple_Handlebars_View ( $ view_root , $ template_name , function ( $ engine ) use ( $ template_name , $ view_data ) { return $ engine -> render ( $ template_name , $ view_data ) ; } , $ this -> path_to_views ) ; $ content = $ view -> output ( ) ; } return new Response ( array ( 'content' => $ content , 'head' => $ this -> head_data , ) ) ; }
By default this will create a View instance and will generate a Response from that View using the data and head that has been provided .
43,016
private function get_file_extension ( $ view_root , $ template_name ) { $ paths = to_array ( $ this -> get_path_to_views ( ) ) ; $ path = reset ( $ paths ) ; if ( ! empty ( $ view_root ) ) { $ path .= '/' . $ view_root ; } $ path .= '/' . $ template_name ; $ files = glob ( $ path . '.*' ) ; return pathinfo ( reset ( $ files ) , PATHINFO_EXTENSION ) ; }
Find the first file extension that matches for this view template
43,017
public function get ( $ field , $ default = null ) { return isset ( $ this -> user -> { $ field } ) ? $ this -> user -> { $ field } : $ default ; }
Getter for user data .
43,018
public function get_profile_fields ( $ field = null , $ default = null ) { $ profile_fields = array ( ) ; foreach ( $ this -> user -> metadata as $ metadata ) { if ( empty ( $ field ) ) { $ profile_fields [ $ metadata -> key ] = $ metadata -> value ; } elseif ( $ field == $ metadata -> key ) { return $ metadata -> value ; } } return empty ( $ profile_fields ) ? $ default : $ profile_fields ; }
for compatibility will map to the user metadata
43,019
protected function replaceClassNameSingular ( & $ stub , $ name ) { $ stub = str_replace ( '[[DummyClassNameSingular]]' , Str :: singular ( $ this -> getNameInput ( ) ) , $ stub ) ; return $ this ; }
Replace the class name into singular form for the given stub . Used in the model class name declaration in service stub .
43,020
protected function replaceClassNameLowerCase ( & $ stub , $ name ) { $ stub = str_replace ( '[[DummyClassNameLowerCase]]' , Str :: plural ( Str :: lower ( $ this -> getNameInput ( ) ) ) , $ stub ) ; return $ this ; }
Replace the class name into lowercase form for the given stub . Used in the model class name declaration in the model stub .
43,021
public function run ( ) { try { $ response = $ this -> buildResponse ( ) ; } catch ( Error \ Base $ ex ) { $ response = $ this -> handleError ( $ ex ) ; } $ this -> serializer -> serialize ( $ response , $ this ) ; return $ this ; }
Runs the API route .
43,022
public function handleError ( Error \ Base $ ex ) { $ body = [ 'type' => $ this -> singularClassName ( $ ex ) , 'message' => $ ex -> getMessage ( ) , ] ; if ( $ ex instanceof InvalidRequest && $ param = $ ex -> getParam ( ) ) { $ body [ 'param' ] = $ param ; } $ this -> response -> setCode ( $ ex -> getHttpStatus ( ) ) ; return $ body ; }
Handles exceptions thrown in this route .
43,023
public function getEndpoint ( ) { $ basePath = $ this -> app [ 'config' ] -> get ( 'api.base_path' , self :: DEFAULT_BASE_PATH ) ; $ basePath = $ this -> stripTrailingSlash ( $ basePath ) ; $ urlBase = $ this -> app [ 'config' ] -> get ( 'api.url' ) ; if ( $ urlBase ) { $ urlBase = $ this -> stripTrailingSlash ( $ urlBase ) ; } else { $ urlBase = $ this -> app [ 'base_url' ] ; $ urlBase = $ this -> stripTrailingSlash ( $ urlBase ) . $ basePath ; } $ path = $ this -> stripTrailingSlash ( $ this -> request -> path ( ) ) ; if ( $ basePath ) { $ path = str_replace ( $ basePath , '' , $ path ) ; } return $ urlBase . $ path ; }
Gets the full URL for this API route .
43,024
public function humanClassName ( $ class ) { if ( is_object ( $ class ) ) { $ class = get_class ( $ class ) ; } $ namespace = explode ( '\\' , $ class ) ; $ className = end ( $ namespace ) ; $ inflector = Inflector :: get ( ) ; return $ inflector -> titleize ( $ inflector -> underscore ( $ className ) ) ; }
Generates the human name for a class i . e . LineItem - > Line Item .
43,025
public function singularClassName ( $ class ) { if ( is_object ( $ class ) ) { $ class = get_class ( $ class ) ; } $ namespace = explode ( '\\' , $ class ) ; $ className = end ( $ namespace ) ; $ inflector = Inflector :: get ( ) ; return $ inflector -> underscore ( $ className ) ; }
Generates the singular key from a class i . e . LineItem - > line_item .
43,026
public function pluralClassName ( $ class ) { if ( is_object ( $ class ) ) { $ class = get_class ( $ class ) ; } $ namespace = explode ( '\\' , $ class ) ; $ className = end ( $ namespace ) ; $ inflector = Inflector :: get ( ) ; return $ inflector -> pluralize ( $ inflector -> underscore ( $ className ) ) ; }
Generates the plural key from a class i . e . LineItem - > line_items .
43,027
public function run ( ) { $ helperSet = $ this -> getConsoleHelperSet ( ) ; ConsoleRunner :: run ( $ helperSet , $ this -> getConsoleCommands ( $ helperSet ) ) ; }
Run doctrine console tool .
43,028
public function add ( $ name , $ title , $ properties , $ controllerClass ) { register_widget ( new Widget ( $ name , $ title , $ properties , $ this -> plugin , $ controllerClass ) ) ; }
AddWidget Add Plugin Container
43,029
public function generate ( ) { $ reference = [ ] ; $ scanner = $ this -> getScanner ( ) ; foreach ( $ scanner -> getClasses ( ) as $ class ) { $ footprint = $ this -> getClassFootprint ( $ class ) ; $ reference [ $ class -> getName ( ) ] = $ footprint -> export ( ) ; } $ reference = json_encode ( $ reference ) ; return $ reference ; }
Create JSON reference from given directories
43,030
protected function getClassFootprint ( ClassScanner $ class ) { $ footprint = new ClassFootprint ( ) ; if ( $ class -> isInterface ( ) ) { $ footprint -> setType ( ClassFootprint :: TYPE_INTERFACE ) ; } elseif ( $ class -> isTrait ( ) ) { $ footprint -> setType ( ClassFootprint :: TYPE_TRAIT ) ; } $ footprint -> setParent ( $ class -> getParentClass ( ) ) ; foreach ( $ class -> getConstants ( false ) as $ constant ) { $ footprint -> addConstant ( $ constant -> getName ( ) , $ constant -> getValue ( ) ) ; } foreach ( $ class -> getInterfaces ( ) as $ interface ) { $ footprint -> addInterface ( $ interface ) ; } return $ footprint ; }
Retrieve class footprint from class scanner
43,031
protected function buildIdentificationCriteria ( array $ subject ) { $ criteria = [ ] ; foreach ( $ this -> identificationFields as $ dbField => $ subjectField ) { if ( empty ( $ subject [ $ subjectField ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Subject must contain a(n) "%s" field' , $ subjectField ) ) ; } if ( is_numeric ( $ dbField ) ) { $ dbField = $ subjectField ; } $ criteria [ $ dbField ] = $ subject [ $ subjectField ] ; } return $ criteria ; }
Checks if all identification field is included in the subject and builds a criteria
43,032
protected function addExpectedValue ( $ key , $ value ) { if ( isset ( $ this -> expectedMocks [ $ key ] ) || isset ( $ this -> expectedMocksCollections [ $ key ] ) || isset ( $ this -> expectedValues [ $ key ] ) ) { throw new \ LogicException ( sprintf ( 'The expected value "%s" you are trying to add is already set as mock, mock collection or value.' , $ key ) ) ; } if ( is_object ( $ value ) ) { throw new \ InvalidArgumentException ( 'The expected value you are trying to add is an object. Use addExpectedMock() instead.' ) ; } $ this -> expectedValues [ $ key ] = $ value ; return $ this ; }
Add an expected value .
43,033
protected function addHelpMock ( $ key , \ PHPUnit_Framework_MockObject_MockObject $ mock ) { if ( isset ( $ this -> helpMocks [ $ key ] ) ) { throw new \ LogicException ( 'The help mock you are trying to add is already set.' ) ; } $ this -> helpMocks [ $ key ] = $ mock ; return $ this ; }
Add a mock object .
43,034
protected function addHelpResource ( $ key , $ resource ) { if ( isset ( $ this -> helpResources [ $ key ] ) ) { throw new \ LogicException ( 'The resource you are trying to add is already set.' ) ; } if ( false === is_object ( ( $ resource ) ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The resource "%s" you are trying to add is not an object. addHelpResource() accepts only objects. Use addHelpValue() to store other kind of values.' , $ key ) ) ; } $ this -> helpResources [ $ key ] = $ resource ; return $ this ; }
Add a resource to help during the test of the class .
43,035
protected function addHelpValue ( $ key , $ value ) { if ( is_object ( $ value ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The HelpValue with ID "%s" you are trying to add is an object. Use $this->addHelpMock() instead.' , $ key ) ) ; } if ( isset ( $ this -> helpValues [ $ key ] ) ) { throw new \ LogicException ( 'The HelpValue you are trying to add is already set. Set the fourth parameter to "true" to overwrite it.' ) ; } $ this -> helpValues [ $ key ] = $ value ; return $ this ; }
Add a value used in tests .
43,036
protected function bindExpectedToObject ( ) { $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; $ values = array_merge ( $ this -> expectedValues , $ this -> expectedMocks , $ this -> expectedMocksCollections ) ; foreach ( $ values as $ property => $ value ) { if ( is_array ( $ value ) ) { $ addMethod = 'add' . ucfirst ( $ property ) ; foreach ( $ value as $ mock ) { $ this -> getObjectToTest ( ) -> $ addMethod ( $ mock ) ; } } else { if ( $ accessor -> isWritable ( $ this -> getObjectToTest ( ) , $ property ) ) { $ accessor -> setValue ( $ this -> objectToTest , $ property , $ value ) ; } } } unset ( $ values ) ; unset ( $ accessor ) ; return $ this ; }
Automatically set the properties of the Resource with expected values .
43,037
protected function generateMocksCollection ( \ PHPUnit_Framework_MockObject_MockObject $ mock , $ repeatFor = 1 ) { $ collection = [ ] ; for ( $ i = 1 ; $ i <= $ repeatFor ; $ i ++ ) { $ collection [ ] = clone $ mock ; } return $ collection ; }
Clone a mock object generating a collection populated with mocks of the same kind .
43,038
protected function getHelpMock ( $ key ) { if ( ! isset ( $ this -> helpMocks [ $ key ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The required mock object "%s" doesn\'t exist.' , $ key ) ) ; } return $ this -> helpMocks [ $ key ] ; }
Get a mock object .
43,039
protected function getHelpResource ( $ key ) { if ( ! isset ( $ this -> helpResources [ $ key ] ) ) { throw new \ InvalidArgumentException ( sprintf ( "The resource \"%s\" you are asking for doesn't exist." , $ key ) ) ; } return $ this -> helpResources [ $ key ] ; }
Get a resource to help during testing .
43,040
protected function getMockFromMocksCollection ( $ mockName , $ collection , $ andRemove = false ) { if ( ! isset ( $ this -> expectedMocksCollections [ $ collection ] [ $ mockName ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The required mock "%s" doesn\'t exist in collection "%s".' , $ mockName , $ collection ) ) ; } if ( $ andRemove ) { $ this -> removeMockFromMocksCollection ( $ mockName , $ collection ) ; } return $ this -> expectedMocksCollections [ $ collection ] [ $ mockName ] ; }
Get a mock from a collection .
43,041
protected function removeMockFromMocksCollection ( $ mockName , $ collection ) { if ( ! isset ( $ this -> expectedMocksCollections [ $ collection ] [ $ mockName ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The required mock "%s" doesn\'t exist in collection "%s".' , $ mockName , $ collection ) ) ; } $ return = $ this -> expectedMocksCollections [ $ collection ] [ $ mockName ] ; unset ( $ this -> expectedMocksCollections [ $ collection ] [ $ mockName ] ) ; return $ return ; }
Removes a mock from a collection . Optionally also from the expected values .
43,042
protected function helpTearDown ( ) { $ this -> actualResult = null ; $ this -> expectedMocks = null ; $ this -> expectedMocksCollections = null ; $ this -> expectedValues = null ; $ this -> helpMocks = null ; $ this -> helpResources = null ; $ this -> helpValues = null ; $ this -> objectToTest = null ; }
Sets to null all instantiated properties to freeup memory .
43,043
public function printMemoryUsageInfo ( ) { if ( null === $ this -> memoryBeforeTearDown ) { throw new \ BadMethodCallException ( 'To use measurement features you need to call PHPUnit_Helper::measureMemoryBeforeTearDown() first.' ) ; } if ( null === $ this -> memoryAfterTearDown ) { $ this -> measureMemoryAfterTearDown ( ) ; } printf ( "\n(Memory used before tearDown(): %s)" , $ this -> formatMemory ( $ this -> memoryBeforeTearDown ) ) ; printf ( "\n(Memory used after tearDown(): %s)" , $ this -> formatMemory ( $ this -> memoryAfterTearDown ) ) ; printf ( "\n(Memory saved with tearDown(): %s)\n" , $ this -> formatMemory ( $ this -> memoryBeforeTearDown - $ this -> memoryAfterTearDown ) ) ; }
Print memory usage info .
43,044
public function tearDownWithReflection ( ) { $ this -> helpTearDown ( ) ; $ refl = new \ ReflectionObject ( $ this ) ; foreach ( $ refl -> getProperties ( ) as $ prop ) { if ( ! $ prop -> isStatic ( ) && 0 !== strpos ( $ prop -> getDeclaringClass ( ) -> getName ( ) , 'PHPUnit_' ) ) { $ prop -> setAccessible ( true ) ; $ prop -> setValue ( $ this , null ) ; } } $ refl = null ; unset ( $ refl ) ; }
Set toggle or off the use of the reflection to tear down the test .
43,045
private function formatMemory ( $ size ) { $ isNegative = false ; $ unit = [ 'b' , 'kb' , 'mb' , 'gb' , 'tb' , 'pb' ] ; if ( 0 > $ size ) { $ isNegative = true ; } $ return = ( $ isNegative ) ? '-' : '' ; return $ return . round ( abs ( $ size ) / pow ( 1024 , ( $ i = floor ( log ( abs ( $ size ) , 1024 ) ) ) ) , 2 ) . ' ' . $ unit [ $ i ] ; }
Format an integer in bytes .
43,046
public static function smrtr ( $ haystack , $ aMatch , $ aDelimiter = array ( "{" , "}" ) ) { $ aCleaned = array ( ) ; foreach ( $ aMatch as $ key => $ v ) { $ aCleaned [ $ aDelimiter [ 0 ] . $ key . $ aDelimiter [ 1 ] ] = $ v ; } return strtr ( $ haystack , $ aCleaned ) ; }
Smrtr the smartest micro template engine
43,047
public function setPresenter ( $ presenter ) { if ( is_string ( $ presenter ) ) { $ this -> presenter = $ this -> getPresenter ( $ presenter ) ; } else { $ this -> presenter = $ presenter ; } return $ this -> presenter ; }
Manullay set a Presenter
43,048
public function setExpireTimestamp ( $ unixTimestamp ) { $ this -> expire = new \ DateTime ( ) ; $ this -> expire -> setTimestamp ( $ unixTimestamp ) ; return $ this ; }
Sets the cookie s expire timestamp to a given unix timestamp .
43,049
final public function __send ( ) { $ args = func_get_args ( ) ; $ method = array_shift ( $ args ) ; if ( $ this -> __respondTo ( $ method ) ) { return call_user_func_array ( array ( $ this , $ method ) , $ args ) ; } $ message = new KoineString ( "Undefined method '" ) ; $ message -> append ( $ method ) -> append ( "' for " ) -> append ( $ this -> getClass ( ) ) ; throw new NoMethodException ( $ message ) ; }
Dinamicaly calls method
43,050
public function contains ( $ name ) { foreach ( $ this -> segments as $ segment ) { if ( $ segment -> getName ( ) == $ name ) return true ; } return false ; }
Return true if this document contains a segment with the given name
43,051
public function addSegment ( $ segment , $ other = null ) { if ( ! $ segment instanceof Segment ) { $ segment = new Segment ( $ segment ) ; } if ( $ this -> getIndexOf ( $ segment -> getName ( ) ) ) throw new \ Exception ( 'Section with this name already exists' ) ; if ( $ other ) { if ( ( $ index = $ this -> getIndexOf ( $ other ) ) === false ) throw new \ Exception ( 'Segment not found' ) ; array_splice ( $ this -> segments , $ index , 0 , [ $ segment ] ) ; } else { $ this -> segments [ ] = $ segment ; } return $ segment ; }
Adds a new segment
43,052
public function getSegment ( $ name ) { foreach ( $ this -> segments as $ segment ) { if ( $ segment -> getName ( ) == $ name ) return $ segment ; } return false ; }
Returns the segment with the given name otherwise false
43,053
private function getIndexOf ( $ segment ) { if ( $ segment instanceof Segment ) { foreach ( $ this -> segments as $ index => $ other ) { if ( $ other === $ segment ) { return $ index ; } } } else { foreach ( $ this -> segments as $ index => $ other ) { if ( $ other -> getName ( ) === $ segment ) { return $ index ; } } } return false ; }
Returns the index of the segment
43,054
protected function _loadSettings ( ) { $ settings = Cache :: remember ( 'settings' , function ( ) { $ Settings = $ this -> loadModel ( 'Wasabi/Core.Settings' ) ; return $ Settings -> getAllKeyValues ( ) ; } , 'wasabi/core/longterm' ) ; $ event = new Event ( 'Settings.afterLoad' , $ settings ) ; $ this -> eventManager ( ) -> dispatch ( $ event ) ; if ( $ event -> result !== null ) { $ settings = $ event -> result ; } Configure :: write ( 'Settings' , $ settings ) ; }
Loads all settings from db and triggers the event Settings . afterLoad that can be listened to by plugins to further modify the settings .
43,055
protected function logSending ( ) { $ text = $ this -> getText ( ) ; Log :: Debug ( "Sending sms to recipients: " . $ this -> getRecipientList ( ) , "Sms" ) ; Log :: BulkData ( "Sms content" , "Sms" , "\r\n\r\n" . $ text ) ; return ; }
Called when sending occurs providing an opportunity to log the event .
43,056
private static function myParse ( string $ scheme , ? string & $ result = null , ? int & $ type = null , ? int & $ defaultPort = null , ? string & $ error = null ) : bool { if ( $ scheme === '' ) { $ error = 'Scheme "' . $ scheme . '" is empty.' ; return false ; } $ result = strtolower ( $ scheme ) ; if ( ! isset ( self :: $ mySchemes [ $ result ] ) ) { $ error = 'Scheme "' . $ scheme . '" is invalid: Scheme must be "http" or "https".' ; return false ; } $ schemeInfo = self :: $ mySchemes [ $ result ] ; $ type = $ schemeInfo [ 0 ] ; $ defaultPort = $ schemeInfo [ 1 ] ; return true ; }
Tries to parse a scheme and returns the result or error text .
43,057
public function editAction ( $ id = null ) { try { return parent :: editAction ( $ id ) ; } catch ( \ Exception $ e ) { return $ this -> editActionException ( $ e ) ; } }
editAction override from CRUDController .
43,058
public function deleteAction ( $ id ) { try { return parent :: deleteAction ( $ id ) ; } catch ( \ Exception $ e ) { return $ this -> deleteActionException ( $ e ) ; } }
deleteAction override from CRUDController .
43,059
public function notifyObjects ( $ method , array $ args = [ ] ) { if ( $ this -> _classes ) { foreach ( $ this -> _classes as $ options ) { if ( ! $ options [ 'callback' ] || in_array ( $ options [ 'alias' ] , $ this -> _restricted ) ) { continue ; } $ object = $ this -> getObject ( $ options [ 'alias' ] ) ; if ( $ object && method_exists ( $ object , $ method ) ) { call_user_func_array ( [ $ object , $ method ] , $ args ) ; } } } return $ this ; }
Cycle through all loaded objects and trigger the defined hook method .
43,060
public static function format ( $ value , $ format ) { if ( is_array ( $ value ) ) { return array_map ( function ( $ val ) use ( $ format ) { return sprintf ( $ format , $ val ) ; } , $ value ) ; } return sprintf ( $ format , $ value ) ; }
Aplica um formato ao valor ou nos valores de um array .
43,061
protected function initialize ( ) { parent :: initialize ( ) ; $ this -> data = new stdClass ( ) ; $ this -> data -> ownId = null ; $ this -> data -> amount = new stdClass ( ) ; $ this -> data -> amount -> currency = self :: AMOUNT_CURRENCY ; $ this -> data -> amount -> subtotals = new stdClass ( ) ; $ this -> data -> items = [ ] ; }
Initialize Orders Data Object
43,062
public function find ( $ order_id ) { $ response = $ this -> client -> get ( '/{order_id}' , [ $ order_id ] ) ; $ this -> populate ( $ response ) ; return $ this ; }
Find a order
43,063
public function addItem ( $ product , $ quantity , $ detail , $ price ) { $ item = new stdClass ( ) ; $ item -> product = $ product ; $ item -> quantity = $ quantity ; $ item -> detail = $ detail ; $ item -> price = $ this -> convertAmount ( $ price ) ; $ this -> data -> items [ ] = $ item ; return $ this ; }
Add item to a order
43,064
public function setCustomer ( $ customer ) { $ this -> data -> customer = new stdClass ; $ this -> data -> customer = $ customer ; return $ this ; }
Set a new Customer
43,065
public function setAddition ( $ value ) { $ this -> data -> amount -> subtotals -> addition = $ this -> convertAmount ( $ value ) ; return $ this ; }
Set a value addition
43,066
public function addAddition ( $ value ) { $ this -> data -> amount -> subtotals -> addition += $ this -> convertAmount ( $ value ) ; return $ this ; }
Add a value addition
43,067
public function setDiscount ( $ value ) { $ this -> data -> amount -> subtotals -> discount = $ this -> convertAmount ( $ value ) ; return $ this ; }
Set a value discount
43,068
public function addDiscount ( $ value ) { $ this -> data -> amount -> subtotals -> discount -= $ this -> convertAmount ( $ value ) ; return $ this ; }
Add a value discount
43,069
public function setShippingAmount ( $ value ) { $ this -> data -> amount -> subtotals -> shipping = $ this -> convertAmount ( $ value ) ; return $ this ; }
Set a value for shipping
43,070
public function route ( $ name , $ parameters = [ ] ) { $ route = router ( ) -> route ( $ name ) ; if ( is_null ( $ route ) ) { throw new \ Exception ( "Route name [$name] not found" ) ; } $ route_url = $ route -> url ( $ parameters ) ; return $ this -> to ( $ route_url ) ; }
Generate an absolute URL to the route .
43,071
protected function loadAccessLevels ( ) { $ accessLevels = $ this -> accessLevelsObjectBackend -> loadObject ( ) ; if ( ! is_array ( $ accessLevels ) ) { $ accessLevels = array ( ) ; } $ this -> accessLevels = $ accessLevels ; }
Loads the access levels from the object backend
43,072
public function addAccessLevel ( AccessLevel $ accessLevel ) { $ this -> accessLevels [ $ accessLevel -> getKey ( ) ] = $ accessLevel ; $ this -> saveAccessLevels ( ) ; }
Adds a new access level .
43,073
public function removeAccessLevel ( $ key ) { if ( ! isset ( $ this -> accessLevels [ $ key ] ) ) { return false ; } unset ( $ this -> accessLevels [ $ key ] ) ; $ this -> saveAccessLevels ( ) ; $ runtimeManager = $ this -> framework -> getRuntimeManager ( ) ; $ runtimeManager -> executeFilter ( '\\Zepi\\Core\\AccessControl\\Filter\\AccessLevelManager\\RemoveAccessLevel' , $ key ) ; }
Removes the access level .
43,074
public function getAccessLevels ( ) { $ runtimeManager = $ this -> framework -> getRuntimeManager ( ) ; $ accessLevels = $ runtimeManager -> executeFilter ( '\\Zepi\\Core\\AccessControl\\Filter\\AccessLevelManager\\RegisterAccessLevels' , $ this -> accessLevels ) ; return $ accessLevels ; }
Returns all access levels
43,075
public function errorArray ( ) { $ messages = [ ] ; foreach ( $ this -> failures as $ key => $ rule ) { foreach ( $ rule -> getFailures ( ) as $ fail ) { $ messages [ ] = $ fail ; } } return $ messages ; }
Flatten out the error messages into a single level array
43,076
public static function filter ( array $ arr , callable $ callback ) { foreach ( $ arr as $ key => $ value ) { if ( is_array ( $ value ) && count ( $ value ) > 0 ) { $ arr [ $ key ] = static :: filter ( $ value , $ callback ) ; } if ( ! call_user_func ( $ callback , $ arr [ $ key ] , $ key ) ) { unset ( $ arr [ $ key ] ) ; } } return $ arr ; }
Recursively remove elements and from an array using a callback function
43,077
public static function pull ( & $ array , $ key , $ default = null ) { if ( array_key_exists ( $ key , $ array ) ) { $ value = $ array [ $ key ] ; unset ( $ array [ $ key ] ) ; } else { $ value = $ default ; } return $ value ; }
Get a value from the array and remove it .
43,078
public static function toString ( array $ arr , $ kvsep , $ psep ) { $ result = [ ] ; foreach ( $ arr as $ k => $ v ) { $ result [ ] = "{$k}{$kvsep}{$v}" ; } return implode ( $ psep , $ result ) ; }
Makes a string from array by concatenating each key with it value and subsequent concatenation the resulted string with each other
43,079
public static function getObjectWithKey ( array $ array , $ key ) { foreach ( $ array as $ object ) { if ( is_array ( $ object ) && array_key_exists ( $ key , $ object ) ) { return $ object ; } } return null ; }
Looks for an array inside input array by key and returns one if found
43,080
public static function getObjectWithKeyAndValue ( array $ array , $ key , $ value ) { foreach ( $ array as $ object ) { if ( is_array ( $ object ) && array_key_exists ( $ key , $ object ) && $ object [ $ key ] === $ value ) { return $ object ; } } return null ; }
Looks for an array inside input array by key and value and returns one if found
43,081
public function getFieldInput ( $ field ) { $ model = ClassRegistry :: init ( $ this -> usersModel ) ; switch ( $ field ) { case 'username' : $ username = trim ( $ this -> in ( 'Username:' ) ) ; if ( ! $ username ) { $ username = $ this -> getFieldInput ( $ field ) ; } else { $ result = $ model -> find ( 'count' , array ( 'conditions' => array ( $ model -> alias . '.' . $ this -> userFields [ 'username' ] => $ username ) ) ) ; if ( $ result ) { $ this -> out ( '<error>Username already exists, please try again</error>' ) ; $ username = $ this -> getFieldInput ( $ field ) ; } } return $ username ; break ; case 'email' : $ email = trim ( $ this -> in ( 'Email:' ) ) ; if ( ! $ email ) { $ email = $ this -> getFieldInput ( $ field ) ; } else if ( ! Validation :: email ( $ email ) ) { $ this -> out ( '<error>Invalid email address, please try again</error>' ) ; $ email = $ this -> getFieldInput ( $ field ) ; } else { $ result = $ model -> find ( 'count' , array ( 'conditions' => array ( $ model -> alias . '.' . $ this -> userFields [ 'email' ] => $ email ) ) ) ; if ( $ result ) { $ this -> out ( '<error>Email already exists, please try again</error>' ) ; $ email = $ this -> getFieldInput ( $ field ) ; } } return $ email ; break ; default : $ value = trim ( $ this -> in ( sprintf ( '%s:' , Inflector :: humanize ( $ field ) ) ) ) ; if ( ! $ value ) { $ value = $ this -> getFieldInput ( $ field ) ; } return $ value ; break ; } }
Get the value of an input .
43,082
public function addListener ( $ name , $ listener , $ priority = 0 ) { if ( ! isset ( $ this -> listeners [ $ name ] ) ) $ this -> listeners [ $ name ] = [ ] ; $ this -> listeners [ $ name ] [ $ priority ] [ ] = $ listener ; }
add event listener
43,083
public function setAttribute ( string $ name , $ value = '' , bool $ replaceIfExists = false , $ condition = true ) { $ name = trim ( Text :: toLower ( $ name ) ) ; if ( $ condition ) { if ( ! preg_match ( '/^[a-z0-9_-]+$/' , $ name ) ) { Checkers :: notice ( 'Attribute name [' . $ name . '] syntax error.' ) ; } else if ( $ name === 'class' ) { $ this -> addCssClass ( $ value ) ; } else if ( $ name === 'style' ) { $ this -> appendStyle ( $ value ) ; } else if ( ! $ replaceIfExists && array_key_exists ( $ name , $ this -> attributes ) ) { Checkers :: notice ( 'Attribute [' . $ name . '] already exists.' ) ; } else { $ value = $ value !== null ? ( string ) str_replace ( '"' , '\"' , ( string ) $ value ) : null ; $ this -> attributes [ $ name ] = $ value ; } } return $ this ; }
Attributes . If value is null the = xx part is not generated Attributes class is append . Other attributes are replaced or errors
43,084
public function removeCssClass ( $ cssClass ) { if ( array_key_exists ( $ cssClass , $ this -> cssClasses ) ) { unset ( $ this -> cssClasses [ $ cssClass ] ) ; } return $ this ; }
Supprime un style css
43,085
public function appendStyle ( $ cssStyle ) { $ cssStyle = trim ( $ cssStyle , " \n;" ) ; $ cssStyle && $ this -> styles [ ] = $ cssStyle ; return $ this ; }
Add css style to the element
43,086
public function getAttributes ( ) : array { $ attributes = $ this -> attributes ; if ( $ this -> cssClasses ) { $ attributes [ 'class' ] = implode ( ' ' , array_keys ( $ this -> cssClasses ) ) ; } if ( $ this -> styles ) { $ attributes [ 'style' ] = implode ( ';' , $ this -> styles ) ; } return $ attributes ; }
Attributes with values
43,087
protected function buildIdAttr ( $ eltId = null , bool $ errorIfExists = false ) { if ( $ errorIfExists && isset ( $ this -> attributes [ 'id' ] ) ) { throw new \ Osf \ Exception \ ArchException ( 'Id element already set' ) ; } if ( $ eltId === null ) { $ eltId = 'e' . self :: $ eltIdCount ++ ; } $ this -> setAttribute ( 'id' , $ eltId ) ; return $ this ; }
Build an id attribute
43,088
public function getAssociationCategories ( ) { $ url = $ this -> getBaseApiUrl ( ) . '/meta/association/categories' ; $ xml = $ this -> queryXml ( $ url ) ; return $ xml -> metalist ; }
return a list of association categories
43,089
public function getAssociationRepertoires ( ) { $ url = $ this -> getBaseApiUrl ( ) . '/meta/association/repertoires' ; $ xml = $ this -> queryXml ( $ url ) ; return $ xml -> metalist ; }
return a list of association repertoires
43,090
public function getAssociationPerformancelevels ( ) { $ url = $ this -> getBaseApiUrl ( ) . '/meta/association/performancelevels' ; $ xml = $ this -> queryXml ( $ url ) ; return $ xml -> metalist ; }
return a list of association performancelevels
43,091
public function getEventTypes ( ) { $ url = $ this -> getBaseApiUrl ( ) . '/meta/event/types' ; $ xml = $ this -> queryXml ( $ url ) ; return $ xml -> metalist ; }
return a list of event types
43,092
protected function replaceParamInSql ( ) { $ count = 0 ; $ params = $ this -> params ; return preg_replace_callback ( '/\?|\:\w+/' , function ( $ m ) use ( $ count , $ params ) { if ( '?' === $ m [ 0 ] ) { $ res = $ params [ $ count ++ ] ; } else { $ res = isset ( $ params [ $ m [ 0 ] ] ) ? $ params [ $ m [ 0 ] ] : $ params [ substr ( $ m [ 0 ] , 1 ) ] ; } return $ this -> getDriver ( ) -> quote ( $ res ) ; } , $ this -> sql ) ; }
Replace params in the SQL
43,093
public function escape ( $ VAL ) { if ( is_numeric ( $ VAL ) ) { if ( floatval ( $ VAL ) == intval ( $ VAL ) ) { $ VAL = intval ( $ VAL ) ; settype ( $ VAL , 'integer' ) ; } else { $ VAL = floatval ( $ VAL ) ; settype ( $ VAL , 'float' ) ; } } else { $ VAL = substr ( $ this -> sql -> quote ( strval ( $ VAL ) , \ PDO :: PARAM_STR ) , 1 , - 1 ) ; } return $ VAL ; }
save sql data
43,094
public function get ( $ table , $ cols , $ options = array ( ) , $ distinct = false , $ total_rows = false ) { $ rows = array ( ) ; $ result = $ this -> select ( $ table , $ cols , $ options , $ distinct , $ total_rows ) ; while ( $ row = $ result -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ rows [ ] = $ row ; } $ num = count ( $ rows ) ; if ( $ total_rows ) { $ result = $ this -> doQuery ( 'SELECT FOUND_ROWS()' ) ; list ( $ total_rows ) = $ result -> fetch ( \ PDO :: FETCH_NUM ) ; } else { $ total_rows = $ num ; } return array ( 'data' => $ rows , 'num' => $ num , 'num_all' => $ total_rows , ) ; }
get data from database
43,095
public function getRow ( $ table , $ cols , $ options = array ( ) , $ start = 0 ) { $ options [ 'L' ] = $ start . ",1" ; $ result = $ this -> get ( $ table , $ cols , $ options ) ; if ( count ( $ result [ 'data' ] ) >= 1 ) { return $ result [ 'data' ] [ 0 ] ; } else { return array ( ) ; } }
only a single data row
43,096
public function getField ( $ table , $ field , $ options = array ( ) , $ start = 0 ) { $ result = $ this -> getRow ( $ table , array ( $ field ) , $ options , $ start ) ; if ( count ( $ result ) >= 1 ) return array_shift ( $ result ) ; else return false ; }
only a single data field
43,097
public function save ( $ table , $ data , $ id = 'id' , $ auto_id = true ) { if ( isset ( $ data [ $ id ] ) && $ this -> getFieldById ( $ table , $ id , $ this -> escape ( $ data [ $ id ] ) , $ id ) !== false ) { try { return $ this -> updateById ( $ table , $ data , $ id ) ; } catch ( \ Exception $ e ) { throw $ e ; } } else { try { if ( $ auto_id ) { unset ( $ data [ $ id ] ) ; } return $ this -> insertId ( $ table , $ data ) ; } catch ( \ Exception $ e ) { throw $ e ; } } }
Saving to DB by Id existing entry = > update else = > insert
43,098
public function error ( $ return = false ) { if ( ! empty ( $ this -> error ) ) { if ( $ return ) { return $ this -> error ; } var_dump ( $ this -> error ) ; return null ; } return false ; }
print or return last error
43,099
public function last ( $ return = false ) { if ( ! empty ( $ this -> query ) ) { if ( $ return ) { return $ this -> query ; } var_dump ( $ this -> query ) ; return null ; } return false ; }
print or return last query