idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,700
private function _isGoutte1 ( ) { $ reflection = new \ ReflectionParameter ( array ( 'Goutte\Client' , 'setClient' ) , 0 ) ; if ( $ reflection -> getClass ( ) && 'Guzzle\Http\ClientInterface' === $ reflection -> getClass ( ) -> getName ( ) ) { return true ; } return false ; }
Determines Goutte client version .
48,701
public function add ( IMinkDriverFactory $ driver_factory ) { $ driver_name = $ driver_factory -> getDriverName ( ) ; if ( isset ( $ this -> _registry [ $ driver_name ] ) ) { throw new \ LogicException ( 'Driver factory for "' . $ driver_name . '" driver is already registered.' ) ; } $ this -> _registry [ $ driver_name ] = $ driver_factory ; }
Registers Mink driver factory .
48,702
public function get ( $ driver_name ) { if ( ! isset ( $ this -> _registry [ $ driver_name ] ) ) { throw new \ OutOfBoundsException ( sprintf ( 'No driver factory for "%s" driver.' , $ driver_name ) ) ; } return $ this -> _registry [ $ driver_name ] ; }
Looks up driver factory by name of the driver it can create .
48,703
protected function getSessionId ( Session $ session ) { $ driver = $ session -> getDriver ( ) ; if ( $ driver instanceof Selenium2Driver ) { return $ driver -> getWebDriverSessionId ( ) ; } throw new \ RuntimeException ( 'Unsupported session driver' ) ; }
Get Selenium2 current session id .
48,704
public function session ( BrowserConfiguration $ browser ) { if ( $ this -> _lastTestFailed ) { $ this -> stopSession ( ) ; $ this -> _lastTestFailed = false ; } if ( $ this -> _session === null ) { $ this -> _session = $ this -> _originalStrategy -> session ( $ browser ) ; } else { $ this -> _switchToMainWindow ( ) ; } return $ this -> _session ; }
Returns Mink session with given browser configuration .
48,705
protected function stopSession ( ) { if ( $ this -> _session === null ) { return ; } $ this -> _session -> stop ( ) ; $ this -> _session = null ; }
Stops session .
48,706
public function updateStatus ( $ session_id , $ test_status ) { $ data = array ( 'status' => $ test_status ? 'completed' : 'error' ) ; $ result = $ this -> execute ( 'PUT' , 'sessions/' . $ session_id . '.json' , $ data ) ; return $ result [ 'automation_session' ] ; }
Update status of the test that was executed in the given session .
48,707
protected function execute ( $ request_method , $ url , $ parameters = null ) { $ extra_options = array ( CURLOPT_HTTPAUTH => CURLAUTH_BASIC , CURLOPT_USERPWD => $ this -> _apiUsername . ':' . $ this -> _apiKey , ) ; $ url = 'https://www.browserstack.com/automate/' . $ url ; list ( $ raw_results , ) = $ this -> _curlService -> execute ( $ request_method , $ url , $ parameters , $ extra_options ) ; return json_decode ( $ raw_results , true ) ; }
Execute BrowserStack REST API command .
48,708
public function register ( BrowserConfiguration $ browser ) { $ type = $ browser -> getType ( ) ; if ( isset ( $ this -> browserConfigurations [ $ type ] ) ) { throw new \ InvalidArgumentException ( 'Browser configuration with type "' . $ type . '" is already registered' ) ; } $ this -> browserConfigurations [ $ type ] = $ browser ; }
Registers a browser configuration .
48,709
public function createBrowserConfiguration ( array $ config , BrowserTestCase $ test_case ) { $ aliases = $ test_case -> getBrowserAliases ( ) ; $ config = BrowserConfiguration :: resolveAliases ( $ config , $ aliases ) ; $ type = isset ( $ config [ 'type' ] ) ? $ config [ 'type' ] : 'default' ; unset ( $ config [ 'type' ] ) ; return $ this -> create ( $ type ) -> setAliases ( $ aliases ) -> setup ( $ config ) ; }
Returns browser configuration instance .
48,710
protected function create ( $ type ) { if ( ! isset ( $ this -> browserConfigurations [ $ type ] ) ) { throw new \ InvalidArgumentException ( 'Browser configuration type "' . $ type . '" not registered' ) ; } return clone $ this -> browserConfigurations [ $ type ] ; }
Creates browser configuration based on give type .
48,711
public static function getInstance ( DIContainer $ container = null ) { static $ instance = null ; if ( null === $ instance ) { $ instance = new static ( $ container ) ; } return $ instance ; }
Returns instance of strategy manager .
48,712
public function replaceObject ( $ service_id , $ callable , $ is_factory = false ) { if ( ! isset ( $ this -> container [ $ service_id ] ) ) { throw new \ InvalidArgumentException ( 'Service "' . $ service_id . '" not found' ) ; } $ backup = $ this -> container -> raw ( $ service_id ) ; unset ( $ this -> container [ $ service_id ] ) ; $ this -> container [ $ service_id ] = $ is_factory ? $ this -> container -> factory ( $ callable ) : $ callable ; return $ backup ; }
Replaces object in the container .
48,713
public function compile ( \ Twig_Compiler $ compiler ) { $ compiler -> addDebugInfo ( $ this ) -> write ( 'return ' ) ; if ( $ this -> hasNode ( 'expr' ) ) { $ compiler -> subcompile ( $ this -> getNode ( 'expr' ) ) ; } else { $ compiler -> raw ( '""' ) ; } $ compiler -> raw ( ";\n" ) ; }
Compiles a Return_Node into PHP .
48,714
public function setMinimumProportions ( $ width = null , $ height = null ) { $ this -> minimumWidth = $ width ; $ this -> minimumHeight = $ height ; }
Set the minimum proportions of the uploaded image .
48,715
public function setMaximumProportions ( $ width = null , $ height = null ) { $ this -> maximumWidth = $ width ; $ this -> maximumHeight = $ height ; return $ this ; }
Set the maximum proportions of the uploaded image .
48,716
public function setAllowAspectRatio ( $ x , $ y ) { $ this -> allowAspectRatioX = ( int ) $ x ; $ this -> allowAspectRatioY = ( int ) $ y ; return $ this ; }
Set the aspect ratio . By setting these only images with this aspect ratio can be uploaded .
48,717
public function setDenyAspectRatio ( $ x , $ y ) { $ this -> denyAspectRatioX = ( int ) $ x ; $ this -> denyAspectRatioY = ( int ) $ y ; return $ this ; }
Set the denied aspect ratio . By setting these images with this aspect ratio are denied for uploading .
48,718
protected function validateAspectRatio ( $ width , $ height ) { if ( $ this -> allowAspectRatioX && $ this -> allowAspectRatioY ) { $ gcd = $ this -> gcd ( $ width , $ height ) ; $ x = $ width / $ gcd ; $ y = $ height / $ gcd ; if ( $ x != $ this -> allowAspectRatioX || $ y != $ this -> allowAspectRatioY ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'aspect_ratio' ] , $ x . ':' . $ y , $ this -> allowAspectRatioX . ':' . $ this -> allowAspectRatioY ) ) ; return false ; } } if ( $ this -> denyAspectRatioX && $ this -> denyAspectRatioY ) { $ gcd = $ this -> gcd ( $ width , $ height ) ; $ x = $ width / $ gcd ; $ y = $ height / $ gcd ; if ( $ x == $ this -> denyAspectRatioX && $ y == $ this -> denyAspectRatioY ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'aspect_ratio_denied' ] , $ x . ':' . $ y ) ) ; return false ; } } return true ; }
Validate the aspect ratio . If the size is invalid we will also push an error message with setErrorMessage .
48,719
protected function gcd ( $ a , $ b ) { while ( $ b != 0 ) { $ remainder = $ a % $ b ; $ a = $ b ; $ b = $ remainder ; } return abs ( $ a ) ; }
Calculate the greatest common divisor
48,720
protected function validateSize ( $ width , $ height ) { if ( $ this -> maximumHeight && $ height > $ this -> maximumHeight ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'size_height_max' ] , $ height , $ this -> maximumHeight ) ) ; return false ; } if ( $ this -> maximumWidth && $ width > $ this -> maximumWidth ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'size_width_max' ] , $ width , $ this -> maximumWidth ) ) ; return false ; } if ( $ this -> minimumHeight && $ height < $ this -> minimumHeight ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'size_height_min' ] , $ height , $ this -> minimumHeight ) ) ; return false ; } if ( $ this -> minimumWidth && $ width < $ this -> minimumWidth ) { $ this -> setErrorMessage ( sprintf ( $ this -> messages [ 'size_width_min' ] , $ width , $ this -> minimumWidth ) ) ; return false ; } return true ; }
Validate the size . If the size is invalid we will also push an error message with setErrorMessage .
48,721
protected function getField2 ( ) { if ( ! $ this -> field2 instanceof AbstractFormField ) { $ this -> field2 = $ this -> field -> getForm ( ) -> getFieldByName ( $ this -> field2 ) ; } return $ this -> field2 ; }
Return the instance of the second passfield
48,722
public function imageButton ( ImageButton $ button ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , 'image' ) ; $ tag -> setAttribute ( 'src' , $ button -> getSrc ( ) ) ; $ tag -> setAttribute ( 'alt' , $ button -> getAlt ( ) ) ; return $ this -> parseTag ( $ tag , $ button ) ; }
Render an ImageButton
48,723
public function optgroup ( Optgroup $ optgroup ) { $ innerHtml = '' ; foreach ( $ optgroup -> getOptions ( ) as $ option ) { $ innerHtml .= $ this -> render ( $ option ) . PHP_EOL ; } $ tag = new Tag ( 'optgroup' , $ innerHtml ) ; $ tag -> setAttribute ( 'label' , $ optgroup -> getLabel ( ) ) ; return $ this -> parseTag ( $ tag , $ optgroup ) ; }
Render an Optgroup
48,724
public function render ( Element $ element ) { $ method = $ this -> getMethodNameForClass ( $ element ) ; if ( ! method_exists ( $ this , $ method ) ) { throw new \ Exception ( 'Error, render method "' . $ method . '" was not found' ) ; } $ errorHtml = $ this -> renderErrorMessages ( $ element ) ; $ helpHtml = $ this -> renderHelpText ( $ element ) ; $ html = $ this -> $ method ( $ element ) ; return $ html . $ helpHtml . $ errorHtml ; }
Render the given element .
48,725
protected function renderErrorMessages ( Element $ element ) { $ html = '' ; if ( $ element instanceof AbstractFormField && sizeof ( $ element -> getErrorMessages ( ) ) > 0 ) { if ( $ this -> errorFormat == self :: RENDER_AS_ATTRIBUTE ) { $ element -> setAttribute ( $ this -> errorTagOrAttr , implode ( "\n" , $ element -> getErrorMessages ( ) ) ) ; } elseif ( $ this -> errorFormat == self :: RENDER_AS_TAG ) { $ tag = new Tag ( $ this -> errorTagOrAttr ) ; $ tag -> setInnerHtml ( implode ( '<br />' . PHP_EOL , $ element -> getErrorMessages ( ) ) ) ; $ html .= $ tag -> render ( ) ; } } return $ html ; }
If the given element is a form field and it has error messages then also render those and return them in the expected format .
48,726
public function option ( Option $ option ) { $ value = $ option -> getLabel ( ) ? : htmlentities ( $ option -> getValue ( ) , ENT_QUOTES , 'UTF-8' ) ; $ tag = new Tag ( 'option' , $ value ) ; if ( $ option -> isSelected ( ) ) { $ tag -> setAttribute ( 'selected' , 'selected' ) ; } return $ this -> parseTag ( $ tag , $ option ) ; }
Render an Option
48,727
public function passField ( PassField $ passField ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , 'password' ) ; $ tag -> setAttribute ( 'maxlength' , $ passField -> getMaxlength ( ) ) ; return $ this -> parseTag ( $ tag , $ passField ) ; }
Render a PassField
48,728
public function selectField ( SelectField $ selectField ) { $ value = $ selectField -> getValue ( ) ; $ values = is_array ( $ value ) ? $ value : array ( ( string ) $ value ) ; $ innerHtml = '' ; foreach ( $ selectField -> getOptions ( ) as $ option ) { if ( $ option instanceof Option ) { $ option -> setSelected ( in_array ( ( string ) $ option -> getValue ( ) , $ values ) ) ; } else { if ( $ option instanceof Optgroup ) { foreach ( $ option -> getOptions ( ) as $ option2 ) { $ option2 -> setSelected ( in_array ( ( string ) $ option2 -> getValue ( ) , $ values ) ) ; } } } $ innerHtml .= $ this -> render ( $ option ) ; } $ tag = new Tag ( 'select' , $ innerHtml ) ; if ( $ selectField -> isMultiple ( ) ) { $ tag -> setAttribute ( 'multiple' , 'multiple' ) ; } return $ this -> parseTag ( $ tag , $ selectField ) ; }
Render a selectField
48,729
public function textArea ( TextArea $ textArea ) { $ value = htmlentities ( $ textArea -> getValue ( ) , ENT_QUOTES , 'UTF-8' ) ; $ tag = new Tag ( 'textarea' , $ value ) ; $ tag -> setAttribute ( 'cols' , $ textArea -> getCols ( ) ) ; $ tag -> setAttribute ( 'rows' , $ textArea -> getRows ( ) ) ; return $ this -> parseTag ( $ tag , $ textArea ) ; }
Render a TextArea
48,730
public function textField ( TextField $ textField ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , $ textField -> getType ( ) ) ; return $ this -> parseTag ( $ tag , $ textField ) ; }
Render a TextField
48,731
public function uploadField ( UploadField $ uploadField ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , 'file' ) ; $ tag -> setAttribute ( 'accept' , $ uploadField -> getAccept ( ) ) ; if ( $ uploadField -> isMultiple ( ) ) { $ tag -> setAttribute ( 'multiple' , 'multiple' ) ; } return $ this -> parseTag ( $ tag , $ uploadField ) ; }
Render an UploadField
48,732
protected function checkBox ( CheckBox $ checkbox ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , 'checkbox' ) ; if ( ! $ checkbox -> getId ( ) && $ checkbox -> getLabel ( ) ) { $ checkbox -> setId ( 'field-' . uniqid ( 'checkbox' ) ) ; } if ( $ checkbox -> isChecked ( ) ) { $ tag -> setAttribute ( 'checked' , 'checked' ) ; } $ html = $ this -> parseTag ( $ tag , $ checkbox ) ; if ( $ checkbox -> getLabel ( ) ) { $ label = new Tag ( 'label' , $ checkbox -> getLabel ( ) ) ; $ label -> setAttribute ( 'for' , $ checkbox -> getId ( ) ) ; $ html .= $ label -> render ( ) ; } return $ html ; }
Render a CheckBox
48,733
protected function submitButton ( SubmitButton $ button ) { $ tag = new Tag ( 'input' ) ; $ tag -> setAttribute ( 'type' , 'submit' ) ; return $ this -> parseTag ( $ tag , $ button ) ; }
Render a SubmitButton
48,734
public function setWhitelist ( $ whitelist ) { if ( is_array ( $ whitelist ) ) { $ this -> whitelist = array_map ( 'strval' , $ whitelist ) ; } elseif ( $ whitelist instanceof \ ArrayObject && true ) { $ this -> whitelist = array_map ( 'strval' , $ whitelist -> getArrayCopy ( ) ) ; } elseif ( is_string ( $ whitelist ) ) { $ this -> whitelist = [ ] ; for ( $ i = 0 ; $ i < strlen ( $ whitelist ) ; $ i ++ ) { $ this -> whitelist [ ] = $ whitelist [ $ i ] ; } } else { throw new \ Exception ( 'Incorrect whitelist given. Allowed whitelist are: string, array or ArrayObject.' ) ; } }
Set the whitelist of characters which are allowed for this field . This can either be an array or a string .
48,735
public function getRegex ( ) { switch ( $ this -> decimalPoint ) { case self :: DECIMAL_COMMA : $ regex = '/^-?\d+(,\d+)?$/' ; break ; case self :: DECIMAL_POINT_OR_COMMA : $ regex = '/^-?\d+((\.|,)\d+)?$/' ; break ; case self :: DECIMAL_POINT : default : $ regex = '/^-?\d+(\.\d+)?$/' ; break ; } return $ regex ; }
Return the regex used for matching valid float
48,736
protected function isValueTooLow ( $ value ) { if ( $ this -> min !== null ) { if ( ( function_exists ( 'bcsub' ) && floatval ( bcsub ( $ this -> min , $ value , 4 ) ) > 0 ) || $ value < $ this -> min ) { return true ; } } return false ; }
Check if the given value is too low .
48,737
protected function isValueTooHigh ( $ value ) { if ( $ this -> max !== null ) { if ( ( ( function_exists ( 'bcsub' ) && floatval ( bcsub ( $ this -> max , $ value , 4 ) ) < 0 ) || $ value > $ this -> max ) && ( ( string ) $ this -> max ) != ( ( string ) $ value ) ) { return true ; } } return false ; }
Check if the given value is too high
48,738
public function setDecimalPoint ( $ decimalPoint ) { switch ( $ decimalPoint ) { case self :: DECIMAL_COMMA : case ',' : $ this -> decimalPoint = self :: DECIMAL_COMMA ; break ; case self :: DECIMAL_POINT_OR_COMMA : case '.,' : case ',.' : $ this -> decimalPoint = self :: DECIMAL_POINT_OR_COMMA ; break ; case self :: DECIMAL_POINT : case '.' : default : $ this -> decimalPoint = self :: DECIMAL_POINT ; } return $ this ; }
Set the decimal point
48,739
protected function setCheckedBasedOnValue ( ) { $ value = $ this -> form -> getFieldValue ( $ this -> name ) ; if ( is_array ( $ value ) ) { $ this -> setChecked ( in_array ( $ this -> getValue ( ) , $ value ) ) ; } else { $ this -> setChecked ( $ this -> getValue ( ) == $ value ) ; } }
Set this field to checked if the value matches
48,740
public function addErrorMessage ( $ message , $ setToInvalid = true ) { $ this -> errors [ ] = $ message ; if ( $ setToInvalid ) { $ this -> setValid ( false ) ; } return $ this ; }
Add a error message
48,741
public function isValid ( ) { if ( $ this -> valid === null ) { $ this -> valid = true ; if ( sizeof ( $ this -> validators ) > 0 ) { foreach ( $ this -> validators as $ validator ) { if ( ! $ validator -> isValid ( ) ) { $ this -> errors [ ] = $ validator -> getErrorMessage ( ) ; $ this -> valid = false ; } } } } return $ this -> valid ; }
Check if this field is valid or not . It will cache it s result . If a new validator is added it s cached value is reset .
48,742
public static function getFileExtension ( $ filename ) { $ filename = basename ( $ filename ) ; $ pos = strpos ( $ filename , '?' ) ; if ( $ pos !== false ) { $ filename = substr ( $ filename , 0 , $ pos ) ; } $ pos = strrpos ( $ filename , '.' ) ; if ( $ pos !== false ) { return strtolower ( substr ( $ filename , $ pos + 1 ) ) ; } return '' ; }
Return the extension of a filename or null if no extension could be found . The extension is lower - cased and does NOT contain a leading dot . When no extension can be found we will return an empty string .
48,743
public static function getMaxUploadSize ( ) { if ( ! ini_get ( 'file_uploads' ) ) { return 0 ; } $ max = 0 ; try { $ max = FormUtils :: sizeToBytes ( ini_get ( 'upload_max_filesize' ) ) ; } catch ( \ Exception $ e ) { } try { $ max2 = FormUtils :: sizeToBytes ( ini_get ( 'post_max_size' ) ) ; if ( $ max2 < $ max || $ max == 0 ) { $ max = $ max2 ; } } catch ( \ Exception $ e ) { } return $ max ; }
Return the max upload size in bytes
48,744
public static function sizeToBytes ( $ str ) { if ( ! preg_match ( '/^(\d+(\.\d+)?)([bkmg]*)$/i' , trim ( $ str ) , $ parts ) ) { throw new \ Exception ( 'Failed to convert string to bytes, incorrect size given: ' . $ str ) ; } switch ( substr ( strtolower ( $ parts [ 3 ] ) , 0 , 1 ) ) { case 'g' : $ size = ( int ) ( $ parts [ 1 ] * 1073741824 ) ; break ; case 'm' : $ size = ( int ) ( $ parts [ 1 ] * 1048576 ) ; break ; case 'k' : $ size = ( int ) ( $ parts [ 1 ] * 1024 ) ; break ; case 'b' : default : $ size = ( int ) $ parts [ 1 ] ; break ; } return $ size ; }
Make a size like 2M to bytes
48,745
public function isUploaded ( ) { if ( $ this -> form -> isSubmitted ( ) && is_array ( $ this -> value ) && $ this -> value [ 'error' ] == UPLOAD_ERR_OK ) { return true ; } return false ; }
Returns true if the form was submited and there was a file uploaded .
48,746
public static function generateToken ( ) { $ token = time ( ) . '.' ; $ length = 32 ; $ characterset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ token .= $ characterset [ mt_rand ( 0 , strlen ( $ characterset ) - 1 ) ] ; } $ sessions = [ ] ; if ( isset ( $ _SESSION [ 'csrftokens' ] ) ) { $ sessions = array_slice ( $ _SESSION [ 'csrftokens' ] , - 50 , 50 ) ; } $ sessions [ ] = $ token ; $ _SESSION [ 'csrftokens' ] = $ sessions ; return $ token ; }
Generate a session token and store it in the token - basket . We return the generated token here which can be used to set the hidden form field .
48,747
protected function isExtensionAllowed ( $ filename ) { $ pos = strrpos ( $ filename , '.' ) ; $ extension = '' ; if ( $ pos !== false ) { $ extension = strtolower ( substr ( $ filename , $ pos + 1 ) ) ; } if ( $ extension ) { if ( sizeof ( $ this -> allowedExtensions ) > 0 && ! in_array ( $ extension , $ this -> allowedExtensions ) ) { return false ; } if ( sizeof ( $ this -> deniedExtensions ) && in_array ( $ extension , $ this -> deniedExtensions ) ) { return false ; } } elseif ( sizeof ( $ this -> allowedExtensions ) > 0 ) { return false ; } return true ; }
Check if the extension of the given filename is allowed .
48,748
protected function isMimetypeAllowed ( $ filename , $ default = "" ) { $ numAllowed = sizeof ( $ this -> allowedMimeTypes ) ; $ numDenied = sizeof ( $ this -> deniedMimeTypes ) ; if ( $ numAllowed == 0 && $ numDenied == 0 ) { return true ; } if ( @ ( $ data = getimagesize ( $ filename ) ) ) { $ mimetype = $ data [ 'mime' ] ; } else { if ( function_exists ( 'finfo_open' ) && function_exists ( 'finfo_file' ) ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimetype = finfo_file ( $ finfo , $ filename ) ; finfo_close ( $ finfo ) ; } else { $ mimetype = function_exists ( 'mime_content_type' ) ? mime_content_type ( $ filename ) : $ default ; } } if ( $ numAllowed > 0 && ! in_array ( $ mimetype , $ this -> allowedMimeTypes ) ) { return false ; } if ( $ numDenied > 0 && in_array ( $ mimetype , $ this -> deniedMimeTypes ) ) { return false ; } return true ; }
Check if the mime type of the given file is allowed .
48,749
public function removeAllowedMimeType ( $ type ) { $ key = array_search ( $ type , $ this -> allowedMimeTypes ) ; if ( $ key !== false ) { unset ( $ this -> allowedMimeTypes [ $ key ] ) ; return true ; } return false ; }
Remove an allowed mime type from the list .
48,750
public function removeAllowedExtension ( $ extension ) { $ key = array_search ( $ extension , $ this -> allowedExtensions ) ; if ( $ key !== false ) { unset ( $ this -> allowedExtensions [ $ key ] ) ; return true ; } return false ; }
Remove an allowed extension from the list .
48,751
public function removeDeniedMimeType ( $ type ) { $ key = array_search ( $ type , $ this -> deniedMimeTypes ) ; if ( $ key !== false ) { unset ( $ this -> deniedMimeTypes [ $ key ] ) ; return true ; } return false ; }
Remove an denied mime type from the list .
48,752
public function removeDeniedExtension ( $ extension ) { $ key = array_search ( $ extension , $ this -> deniedExtensions ) ; if ( $ key !== false ) { unset ( $ this -> deniedExtensions [ $ key ] ) ; return true ; } return false ; }
Remove an denied extension from the list .
48,753
public function setCsrfProtection ( $ value ) { $ this -> csrfProtection = ( bool ) $ value ; if ( ! $ value ) { $ this -> removeFieldByName ( 'csrftoken' ) ; } else { $ field = $ this -> getFieldByName ( 'csrftoken' ) ; if ( $ field === null ) { $ submitted = $ this -> isSubmitted ( ) ; $ field = $ this -> hiddenField ( 'csrftoken' ) ; $ field -> addValidator ( new CsrfValidator ( ) ) ; if ( ! $ submitted && ! $ field -> getValue ( ) ) { $ field -> setValue ( CsrfValidator :: generateToken ( ) ) ; } } } return $ this ; }
Should we enable Cross Site Request Forgery protection? If not given we will use possible default settings . If those are not set we will enable it for POST forms . Set the value for csrfProtection
48,754
public function removeFieldByName ( $ name ) { foreach ( $ this -> fields as $ i => $ field ) { if ( $ field -> getName ( ) == $ name ) { unset ( $ this -> fields [ $ i ] ) ; break ; } } return $ this ; }
Remove a field from the form by the name of the field . If there are more then 1 field with the given name then only the first one will be removed .
48,755
public function getFieldByName ( $ name ) { foreach ( $ this -> fields as $ field ) { if ( $ field -> getName ( ) == $ name ) { return $ field ; } } return null ; }
Return a field by it s name . We will return null if it s not found .
48,756
public function setMethod ( $ method ) { $ method = strtolower ( $ method ) ; if ( in_array ( $ method , [ Form :: METHOD_GET , Form :: METHOD_POST ] ) ) { $ this -> method = $ method ; } else { throw new \ Exception ( 'Incorrect method value given' ) ; } return $ this ; }
Set the method how this form should be submitted
48,757
public function clearCache ( ) { static :: $ cache = [ ] ; $ this -> submitted = null ; foreach ( $ this -> fields as $ field ) { if ( $ field instanceof AbstractFormField ) { $ field -> clearCache ( ) ; } } return $ this ; }
Clear our cache of the submitted values . This could be useful when you have changed the submitted values and want to re - analyze them .
48,758
public function getDataAsArray ( ) { $ fields = $ this -> getFields ( ) ; if ( ! $ fields ) { return [ ] ; } $ result = [ ] ; foreach ( $ fields as $ field ) { if ( ! $ field instanceof AbstractFormField ) { continue ; } if ( $ field -> isDisabled ( ) ) { if ( ! array_key_exists ( $ field -> getName ( ) , $ result ) ) { $ result [ $ field -> getName ( ) ] = '' ; } continue ; } if ( $ field instanceof CheckBox ) { $ result [ $ field -> getName ( ) ] = $ field -> isChecked ( ) ? $ field -> getValue ( ) : '' ; } elseif ( $ field instanceof RadioButton ) { if ( ! $ field -> isChecked ( ) ) { if ( ! array_key_exists ( $ field -> getName ( ) , $ result ) ) { $ result [ $ field -> getName ( ) ] = '' ; } } else { $ result [ $ field -> getName ( ) ] = $ field -> getValue ( ) ; } } elseif ( $ field instanceof UploadField ) { $ value = $ field -> getValue ( ) ; if ( ! $ value || ! isset ( $ value [ 'error' ] ) || $ value [ 'error' ] == UPLOAD_ERR_NO_FILE || empty ( $ value [ 'name' ] ) ) { continue ; } $ result [ $ field -> getName ( ) ] = $ value [ 'name' ] ; } elseif ( $ field instanceof AbstractFormField ) { $ result [ $ field -> getName ( ) ] = $ field -> getValue ( ) ; } } return $ result ; }
Get the values of all fields as an array .
48,759
public function getValidationErrors ( ) { $ fields = $ this -> getFields ( ) ; if ( ! $ fields ) { return [ ] ; } $ result = [ ] ; foreach ( $ fields as $ field ) { if ( $ field instanceof AbstractFormField ) { if ( ! $ field -> isValid ( ) ) { $ result = array_merge ( $ result , $ field -> getErrorMessages ( ) ) ; } } } return $ result ; }
Get an array with all validation errors
48,760
public function removeField ( Element $ field ) { foreach ( $ this -> fields as $ i => $ elem ) { if ( $ elem == $ field ) { unset ( $ this -> fields [ $ i ] ) ; break ; } } return $ this ; }
Remove a field from the form
48,761
public function removeAllFieldsByName ( $ name ) { foreach ( $ this -> fields as $ i => $ field ) { if ( $ field -> getName ( ) == $ name ) { unset ( $ this -> fields [ $ i ] ) ; } } return $ this ; }
Remove all fields by the given name . If there are more then 1 field with the given name then all will be removed .
48,762
public function removeFieldById ( $ id ) { foreach ( $ this -> fields as $ i => $ field ) { if ( $ field -> getId ( ) == $ id ) { unset ( $ this -> fields [ $ i ] ) ; break ; } } return $ this ; }
Remove a field from the form by the name of the field
48,763
public function getErrorMessages ( ) { $ errors = [ ] ; foreach ( $ this -> fields as $ field ) { if ( $ field instanceof AbstractFormField && ! $ field -> isValid ( ) ) { $ fldErrors = $ field -> getErrorMessages ( ) ; $ errors = array_merge ( $ errors , $ fldErrors ) ; } } return $ errors ; }
Fetch all error messages for fields
48,764
public function setEncodingFilter ( InterfaceEncodingFilter $ value ) { $ this -> encodingFilter = $ value ; $ this -> encodingFilter -> init ( $ this ) ; return $ this ; }
Set an encodingFilter . This filter will be used to filter all the imput so that its of the correct character encoding .
48,765
public function submitButton ( $ name , $ value = '' ) { $ button = new SubmitButton ( $ this , $ value ) ; $ button -> setName ( $ name ) ; return $ button ; }
Create a new SubmitButton
48,766
public function imageButton ( $ name , $ src = '' ) { $ button = new ImageButton ( $ this , $ src ) ; $ button -> setName ( $ name ) ; return $ button ; }
Create a new ImageButton
48,767
public function setValue ( $ value ) { parent :: setValue ( $ value ) ; $ this -> setChecked ( $ this -> form -> getFieldValue ( $ this -> name ) == $ this -> getValue ( ) ) ; return $ this ; }
Set the value for this field and return the CheckBox reference
48,768
public function setChecked ( $ checked = true ) { $ this -> clearCache ( ) ; $ this -> checked = ( bool ) $ checked ; return $ this ; }
Specifies that an input element should be preselected when the page loads
48,769
public function setBlacklist ( $ blacklist ) { if ( is_array ( $ blacklist ) ) { $ this -> blacklist = array_map ( 'strval' , $ blacklist ) ; } elseif ( $ blacklist instanceof \ ArrayObject && true ) { $ this -> blacklist = array_map ( 'strval' , $ blacklist -> getArrayCopy ( ) ) ; } elseif ( is_string ( $ blacklist ) ) { $ this -> blacklist = [ ] ; for ( $ i = 0 ; $ i < strlen ( $ blacklist ) ; $ i ++ ) { $ this -> blacklist [ ] = $ blacklist [ $ i ] ; } } else { throw new \ Exception ( 'Incorrect blacklist given. Allowed blacklist are: string, array or ArrayObject.' ) ; } }
Set the blacklist of characters which are allowed for this field . This can either be an array or a string .
48,770
protected function getMethodNameForClass ( Element $ element ) { $ className = get_class ( $ element ) ; $ className = substr ( $ className , strrpos ( $ className , '\\' ) + 1 ) ; return strtolower ( substr ( $ className , 0 , 1 ) ) . substr ( $ className , 1 ) ; }
Return the name of the method as we would expect it for this class .
48,771
protected function parseTag ( Tag $ tag , Element $ element ) { $ list = [ 'disabled' => 'isDisabled' , 'readonly' => 'isReadonly' , 'required' => 'isRequired' , 'placeholder' => 'getPlaceholder' , 'id' => 'getId' , 'title' => 'getTitle' , 'style' => 'getStyle' , 'class' => 'getClass' , 'tabindex' => 'getTabindex' , 'accesskey' => 'getAccessKey' , 'size' => 'getSize' ] ; foreach ( $ list as $ attribute => $ method ) { if ( method_exists ( $ element , $ method ) ) { $ value = $ element -> $ method ( ) ; if ( substr ( $ method , 0 , 2 ) == 'is' ) { if ( $ value ) { $ tag -> setAttribute ( $ attribute , $ attribute ) ; } } else { $ tag -> setAttribute ( $ attribute , $ value ) ; } } } if ( method_exists ( $ element , 'getName' ) && $ element -> getName ( ) ) { $ name = $ element -> getName ( ) ; $ suffix = '' ; if ( method_exists ( $ element , 'isMultiple' ) && $ element -> isMultiple ( ) && substr ( $ name , - 1 ) != ']' ) { $ suffix = '[]' ; } $ tag -> setAttribute ( 'name' , $ name . $ suffix ) ; } if ( method_exists ( $ element , 'getValue' ) && $ element -> getValue ( ) !== null && $ tag -> getName ( ) != 'textarea' && is_scalar ( $ element -> getValue ( ) ) ) { $ tag -> setAttribute ( 'value' , htmlentities ( $ element -> getValue ( ) , ENT_QUOTES , 'UTF-8' ) ) ; } foreach ( $ element -> getAttributes ( ) as $ name => $ value ) { $ tag -> setAttribute ( $ name , $ value ) ; } return $ tag -> render ( ) ; }
Parse the given element and put it s attributes in the given tag . Then render the HTML tag and return its HTML body .
48,772
protected function selectOptionsFromValue ( ) { if ( ! $ this -> options ) { return ; } if ( $ this -> value === null ) { return ; } foreach ( $ this -> options as $ option ) { if ( $ option instanceof Option ) { if ( is_array ( $ this -> value ) ) { $ option -> setSelected ( in_array ( $ option -> getValue ( ) , $ this -> value ) ) ; } else { $ option -> setSelected ( $ option -> getValue ( ) == $ this -> value ) ; } } else { if ( $ option instanceof Optgroup ) { $ options = $ option -> getOptions ( ) ; if ( $ options ) { foreach ( $ options as $ option2 ) { if ( is_array ( $ this -> value ) ) { $ option2 -> setSelected ( in_array ( $ option2 -> getValue ( ) , $ this -> value ) ) ; } else { $ option2 -> setSelected ( $ option2 -> getValue ( ) == $ this -> value ) ; } } } } } } }
This function will use the value for this field to select the correct options
48,773
public function addOptionsAsArray ( array $ options , $ useArrayKeyAsValue = true ) { foreach ( $ options as $ value => $ label ) { $ option = new Option ( ) ; $ option -> setLabel ( $ label ) ; $ option -> setValue ( $ useArrayKeyAsValue ? $ value : $ label ) ; $ this -> options [ ] = $ option ; } $ this -> selectOptionsFromValue ( ) ; return $ this ; }
Add options with an assoc array
48,774
public function addOptions ( array $ options ) { foreach ( $ options as $ option ) { $ this -> options [ ] = $ option ; } $ this -> selectOptionsFromValue ( ) ; return $ this ; }
Add more options to this selectfield
48,775
public function getValue ( ) { $ selected = [ ] ; foreach ( $ this -> options as $ option ) { if ( $ option instanceof Option ) { if ( $ option -> isSelected ( ) ) { $ selected [ ] = $ option -> getValue ( ) ; } } else { if ( $ option instanceof Optgroup ) { $ options = $ option -> getOptions ( ) ; foreach ( $ options as $ option2 ) { if ( $ option2 -> isSelected ( ) ) { $ selected [ ] = $ option2 -> getValue ( ) ; } } } } } $ count = sizeof ( $ selected ) ; if ( $ count > 0 ) { if ( $ this -> isMultiple ( ) ) { return $ selected ; } else { return $ selected [ $ count - 1 ] ; } } return $ this -> isMultiple ( ) ? [ ] : "" ; }
Return the value for this field . This will return an array if the field is setup as multiple . Otherwise it will return a string with the selected value .
48,776
public function getOptionByValue ( $ value ) { foreach ( $ this -> options as $ option ) { if ( $ option instanceof Option ) { if ( $ option -> getValue ( ) == $ value ) { return $ option ; } } else { if ( $ option instanceof Optgroup ) { $ options = $ option -> getOptions ( ) ; foreach ( $ options as $ option2 ) { if ( $ option2 -> getValue ( ) == $ value ) { return $ option2 ; } } } } } return null ; }
Return the option which has the given value . If there are multiple options with the same value the first will be returned .
48,777
public function removeOptionByValue ( $ value ) { $ options = $ this -> options ; $ this -> options = [ ] ; foreach ( $ options as $ option ) { if ( $ option instanceof Option ) { if ( $ option -> getValue ( ) != $ value ) { $ this -> options [ ] = $ option ; } } else { if ( $ option instanceof Optgroup ) { $ subOptions = [ ] ; $ options2 = $ option -> getOptions ( ) ; foreach ( $ options2 as $ option2 ) { if ( $ option2 -> getValue ( ) != $ value ) { $ subOptions [ ] = $ option2 ; } } $ option -> setOptions ( $ subOptions ) ; if ( sizeof ( $ subOptions ) > 0 ) { $ this -> options [ ] = $ option ; } } } } return $ this ; }
Remove option by value .
48,778
public function isValid ( ) { $ value = $ this -> field -> getValue ( ) ; if ( $ value == '' && $ this -> required == false ) { return true ; } $ parsedDate = date_parse ( $ value ) ; if ( $ parsedDate [ 'warning_count' ] == 0 && $ parsedDate [ 'error_count' ] == 0 && isset ( $ parsedDate [ 'year' ] ) && isset ( $ parsedDate [ 'month' ] ) ) { return true ; } return false ; }
Check if the given field is valid or not . The date should be parsable by strtotime .
48,779
public function render ( Element $ element ) { if ( $ element instanceof AbstractFormField && ! $ element instanceof CheckBox ) { if ( ! $ element -> getId ( ) ) { $ element -> setId ( 'field-' . uniqid ( ) ) ; } $ label = new Tag ( 'label' ) ; $ label -> setAttribute ( 'for' , $ element -> getId ( ) ) ; $ label -> setInnerHtml ( $ element -> getTitle ( ) ) ; if ( $ this -> mode == self :: MODE_INLINE_NO_LABELS ) { $ label -> setAttribute ( 'class' , 'sr-only' ) ; } $ element -> addClass ( 'form-control' ) ; $ field = parent :: render ( $ element ) ; $ helpBlock = '' ; if ( $ element -> getHelpText ( ) ) { $ helpTag = new Tag ( 'p' ) ; $ helpTag -> setAttribute ( 'class' , 'help-block' ) ; $ helpTag -> setInnerHtml ( $ element -> getHelpText ( ) ) ; $ helpBlock = $ helpTag -> render ( ) ; } $ tag = new Tag ( 'div' ) ; $ cssClass = 'form-group' ; if ( $ element -> getForm ( ) -> isSubmitted ( ) ) { if ( ! $ element -> isValid ( ) ) { $ cssClass .= ' has-error has-feedback' ; } else { $ cssClass .= ' has-success has-feedback' ; } } $ tag -> setAttribute ( 'class' , $ cssClass ) ; $ tag -> setInnerHtml ( $ label -> render ( ) . PHP_EOL . $ field . PHP_EOL . $ helpBlock . PHP_EOL ) ; return $ tag -> render ( ) ; } elseif ( $ element instanceof AbstractFormButton ) { $ element -> addClass ( 'btn' ) ; $ buttons = $ element -> getForm ( ) -> getFieldsByClass ( '\FormHandler\Field\AbstractFormButton' ) ; if ( sizeof ( $ buttons ) == 1 ) { $ element -> addClass ( 'btn-primary' ) ; } return parent :: render ( $ element ) ; } return parent :: render ( $ element ) ; }
This method is executed when an Element needs to be rendered . Here we add some logic to add the label an optional help block and the form group .
48,780
private function getStatus ( ) { if ( ! ( $ statusArray = preg_grep ( '/^HTTP\/(1.0|1.1)\s+(\d+)\s+(.+)/' , $ this -> headers ) ) ) { throw new \ RuntimeException ( 'Could not determine HTTP status from API response' ) ; } if ( ! preg_match ( '/^HTTP\/(1.0|1.1)\s+(\d+)\s+(.+)/' , $ statusArray [ 0 ] , $ matchesArray ) ) { throw new \ RuntimeException ( 'Could not determine HTTP status from API response' ) ; } return array ( 'code' => $ matchesArray [ 2 ] , 'message' => $ matchesArray [ 3 ] , ) ; }
Extract the HTTP status code and message from the Response headers
48,781
private static function toArrayRecursive ( $ object ) { $ output = get_object_vars ( $ object ) ; foreach ( $ output as $ key => $ value ) { if ( $ value instanceof \ DateTime ) { $ output [ $ key ] = $ value -> format ( 'c' ) ; } elseif ( is_object ( $ value ) ) { $ output [ $ key ] = static :: toArrayRecursive ( $ value ) ; } } return $ output ; }
Recursively cast an object into an array .
48,782
private static function mapDataToEntity ( $ entityName , \ stdClass $ data ) { $ entity = new $ entityName ( ) ; if ( ! ( $ entity instanceof Entity ) ) { throw new \ RuntimeException ( sprintf ( 'Object "%s" must extend Entity' , $ entityName ) ) ; } $ foreignKeyEntityMap = $ entity -> foreignKeyEntityMap ( ) ; $ properties = array_keys ( get_object_vars ( $ data ) ) ; foreach ( $ properties as $ propertyName ) { if ( ! property_exists ( $ entity , $ propertyName ) ) { throw new \ UnexpectedValueException ( sprintf ( 'Property %s->%s does not exist' , get_class ( $ entity ) , $ propertyName ) ) ; } if ( isset ( $ foreignKeyEntityMap [ $ propertyName ] ) ) { $ entity -> $ propertyName = self :: mapDataToEntity ( $ foreignKeyEntityMap [ $ propertyName ] , $ data -> $ propertyName ) ; } elseif ( is_string ( $ data -> $ propertyName ) && preg_match ( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/' , $ data -> $ propertyName ) ) { $ entity -> $ propertyName = new \ DateTime ( $ data -> $ propertyName ) ; } else { $ entity -> $ propertyName = json_decode ( json_encode ( $ data -> $ propertyName ) , true ) ; } } return $ entity ; }
Map array of data to an entity
48,783
public static function makeFromResponse ( $ entityName , $ content ) { $ content = $ content ; $ output = array ( ) ; if ( is_array ( $ content ) ) { foreach ( $ content as $ entityData ) { $ output [ ] = self :: makeFromResponse ( $ entityName , $ entityData ) ; } } elseif ( is_object ( $ content ) ) { $ output = self :: mapDataToEntity ( $ entityName , $ content ) ; } else { $ output = $ content ; } return $ output ; }
Make an array of specified entity from a Response
48,784
private function makeEndPointUrls ( ) { $ endPointUrls ; foreach ( $ this -> methodNameEntityMap as $ classes ) { $ endPointUrls [ $ classes ] = $ this -> apiurl . $ this -> endPointUrls [ $ classes ] ; } $ this -> endPointUrls = $ endPointUrls ; }
Get API EndPoint URL from an entity name
48,785
private function curlInit ( ) { $ curlHandle = curl_init ( ) ; curl_setopt ( $ curlHandle , CURLOPT_ENCODING , 'gzip,deflate' ) ; curl_setopt ( $ curlHandle , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ curlHandle , CURLOPT_VERBOSE , false ) ; curl_setopt ( $ curlHandle , CURLOPT_HEADER , true ) ; curl_setopt ( $ curlHandle , CURLOPT_USERPWD , ( string ) $ this -> credentials ) ; curl_setopt ( $ curlHandle , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ curlHandle , CURLOPT_SSL_VERIFYHOST , 2 ) ; curl_setopt ( $ curlHandle , CURLOPT_TIMEOUT , 4 ) ; curl_setopt ( $ curlHandle , CURLOPT_FOLLOWLOCATION , true ) ; return $ curlHandle ; }
Initialise cURL with the options we need to communicate successfully with API URL .
48,786
private function curlExec ( $ curlHandle , $ endPointUrl ) { curl_setopt ( $ curlHandle , CURLOPT_URL , $ endPointUrl ) ; if ( ( $ response = @ curl_exec ( $ curlHandle ) ) === false ) { throw new \ RuntimeException ( sprintf ( 'cURL Error (%d): %s' , curl_errno ( $ curlHandle ) , curl_error ( $ curlHandle ) ) ) ; } curl_close ( $ curlHandle ) ; $ response_parts = explode ( "\r\n\r\n" , $ response ) ; $ content = array_pop ( $ response_parts ) ; $ headers = explode ( "\r\n" , array_pop ( $ response_parts ) ) ; return new Response ( $ endPointUrl , $ content , $ headers ) ; }
Execute cURL request using the specified API EndPoint
48,787
private function curlGet ( $ endPointUrl ) { $ curlHandle = $ this -> curlInit ( ) ; curl_setopt ( $ curlHandle , CURLOPT_HTTPHEADER , $ this -> childauth ) ; return $ this -> curlExec ( $ curlHandle , $ endPointUrl ) ; }
Make a GET request using cURL
48,788
private function applyOffsetLimit ( $ endPointUrl ) { $ endPointUrlArray = parse_url ( $ endPointUrl ) ; if ( ! isset ( $ endPointUrlArray [ 'query' ] ) ) { $ endPointUrlArray [ 'query' ] = null ; } parse_str ( $ endPointUrlArray [ 'query' ] , $ queryStringArray ) ; $ queryStringArray [ 'offset' ] = $ this -> offset ; $ queryStringArray [ 'limit' ] = min ( max ( 1 , $ this -> limit ) , 500 ) ; $ endPointUrlArray [ 'query' ] = http_build_query ( $ queryStringArray , null , '&' ) ; $ endPointUrl = ( isset ( $ endPointUrlArray [ 'scheme' ] ) ) ? "{$endPointUrlArray['scheme']}://" : '' ; $ endPointUrl .= ( isset ( $ endPointUrlArray [ 'host' ] ) ) ? "{$endPointUrlArray['host']}" : '' ; $ endPointUrl .= ( isset ( $ endPointUrlArray [ 'port' ] ) ) ? ":{$endPointUrlArray['port']}" : '' ; $ endPointUrl .= ( isset ( $ endPointUrlArray [ 'path' ] ) ) ? "{$endPointUrlArray['path']}" : '' ; $ endPointUrl .= ( isset ( $ endPointUrlArray [ 'query' ] ) ) ? "?{$endPointUrlArray['query']}" : '' ; return $ endPointUrl ; }
Apply offset and limit to a end point URL .
48,789
public function deleteApiKey ( $ apikey ) { $ endPointUrl = $ this -> apiurl . "/account/apikey/" . $ apikey ; $ response = $ this -> curlDelete ( $ endPointUrl ) ; return $ response ; }
Delete an ApiKey for a child account
48,790
public function deleteTag ( $ tag ) { $ endPointUrl = $ this -> apiurl . "/account/tag/" . $ tag ; $ response = $ this -> curlDelete ( $ endPointUrl ) ; return $ response ; }
Delete a tag for a child account
48,791
public function getClientKey ( $ uuid , $ edition , $ version ) { $ endPointUrl = $ this -> apiurl . "/client/key/" . $ uuid . "?edition=" . $ edition . "&version=" . $ version ; $ response = $ this -> curlGet ( $ endPointUrl ) ; return $ response ; }
Returns a client key .
48,792
public function getPrintJobStates ( ) { $ arguments = func_get_args ( ) ; if ( count ( $ arguments ) > 1 ) { throw new InvalidArgumentException ( sprintf ( 'Too many arguments given to getPrintJobsStates.' ) ) ; } $ endPointUrl = $ this -> apiurl . "/printjobs/" ; if ( count ( $ arguments ) == 0 ) { $ endPointUrl .= 'states/' ; } else { $ arg_1 = array_shift ( $ arguments ) ; $ endPointUrl .= $ arg_1 . '/states/' ; } $ response = $ this -> curlGet ( $ endPointUrl ) ; if ( $ response -> getStatusCode ( ) != '200' ) { throw new \ RuntimeException ( sprintf ( 'HTTP Error (%d): %s' , $ response -> getStatusCode ( ) , $ response -> getStatusMessage ( ) ) ) ; } return Entity :: makeFromResponse ( "PrintNode\State" , json_decode ( $ response -> getContent ( ) ) ) ; }
Gets print job states .
48,793
public function getScales ( $ computerId ) { $ endPointUrl = $ this -> apiurl . "/computer/" ; $ endPointUrl .= $ computerId ; $ endPointUrl .= '/scales' ; $ response = $ this -> curlGet ( $ endPointUrl ) ; if ( $ response -> getStatusCode ( ) != '200' ) { throw new \ RuntimeException ( sprintf ( 'HTTP Error (%d): %s' , $ response -> getStatusCode ( ) , $ response -> getStatusMessage ( ) ) ) ; } return Entity :: makeFromResponse ( "PrintNode\Scale" , json_decode ( $ response -> getContent ( ) ) ) ; }
Gets scales relative to a computer .
48,794
public function generate ( ) { if ( TL_MODE === 'BE' ) { return parent :: generate ( ) ; } if ( $ this -> news_relatedCategories ) { return $ this -> generateRelated ( ) ; } return parent :: generate ( ) ; }
Set the flag to filter news by categories
48,795
protected function generateRelated ( ) { $ this -> news_archives = $ this -> sortOutProtected ( StringUtil :: deserialize ( $ this -> news_archives , true ) ) ; if ( count ( $ this -> news_archives ) === 0 ) { return '' ; } $ alias = Input :: get ( 'items' ) ? : Input :: get ( 'auto_item' ) ; if ( ( $ news = NewsModel :: findPublishedByParentAndIdOrAlias ( $ alias , $ this -> news_archives ) ) === null ) { return '' ; } $ this -> currentNews = $ news ; return parent :: generate ( ) ; }
Generate the list in related categories mode
48,796
public function onNewsListCountItems ( array $ archives , $ featured , ModuleNewsList $ module ) { if ( null === ( $ criteria = $ this -> getCriteria ( $ archives , $ featured , $ module ) ) ) { return 0 ; } return $ criteria -> getNewsModelAdapter ( ) -> countBy ( $ criteria -> getColumns ( ) , $ criteria -> getValues ( ) ) ; }
On news list count items .
48,797
public function onNewsListFetchItems ( array $ archives , $ featured , $ limit , $ offset , ModuleNewsList $ module ) { if ( null === ( $ criteria = $ this -> getCriteria ( $ archives , $ featured , $ module ) ) ) { return null ; } $ criteria -> setLimit ( $ limit ) ; $ criteria -> setOffset ( $ offset ) ; return $ criteria -> getNewsModelAdapter ( ) -> findBy ( $ criteria -> getColumns ( ) , $ criteria -> getValues ( ) , $ criteria -> getOptions ( ) ) ; }
On news list fetch items .
48,798
private function getCriteria ( array $ archives , $ featured , ModuleNewsList $ module ) { try { $ criteria = $ this -> searchBuilder -> getCriteriaForListModule ( $ archives , $ featured , $ module ) ; } catch ( CategoryNotFoundException $ e ) { throw new PageNotFoundException ( $ e -> getMessage ( ) ) ; } return $ criteria ; }
Get the criteria .
48,799
public function generate ( ) { if ( TL_MODE === 'FE' && ! BE_USER_LOGGED_IN && ( $ this -> invisible || ( $ this -> start > 0 && $ this -> start > \ time ( ) ) || ( $ this -> stop > 0 && $ this -> stop < \ time ( ) ) ) ) { return '' ; } if ( null === ( $ moduleModel = ModuleModel :: findByPk ( $ this -> news_module ) ) ) { return '' ; } $ class = Module :: findClass ( $ moduleModel -> type ) ; if ( ! \ class_exists ( $ class ) ) { return '' ; } $ moduleModel -> typePrefix = 'ce_' ; $ module = new $ class ( $ moduleModel , $ this -> strColumn ) ; $ this -> mergeCssId ( $ module ) ; $ module -> news_filterCategories = $ this -> news_filterCategories ; $ module -> news_relatedCategories = $ this -> news_relatedCategories ; $ module -> news_includeSubcategories = $ this -> news_includeSubcategories ; $ module -> news_filterDefault = $ this -> news_filterDefault ; $ module -> news_filterPreserve = $ this -> news_filterPreserve ; $ module -> news_categoryFilterPage = $ this -> news_categoryFilterPage ; $ module -> news_categoryImgSize = $ this -> news_categoryImgSize ; return $ module -> generate ( ) ; }
Parse the template .