idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
21,800 | protected function removeNonExistentClasses ( & $ pathnameArray ) { foreach ( $ pathnameArray as $ pathname => $ phpClass ) { if ( ! file_exists ( $ pathname ) ) { unset ( $ pathnameArray [ $ pathname ] ) ; } } } | Removes files which are no longer present in this directory |
21,801 | protected function modifyModifiedClasses ( & $ pathnameArray ) { foreach ( $ pathnameArray as $ pathname => $ phpClass ) { if ( file_exists ( $ phpClass -> getFile ( ) -> getPathname ( ) ) && $ phpClass -> getLastModified ( ) -> getTimestamp ( ) != $ phpClass -> getFile ( ) -> getMTime ( ) ) { $ file = $ phpClass -> getFile ( ) ; $ phpClass -> clear ( ) ; $ result = $ this -> phpClassParser -> parse ( $ phpClass , $ file ) ; if ( $ result === false ) { unset ( $ pathnameArray [ $ pathname ] ) ; } } } } | Checks if a file is modified and if so reparse the file |
21,802 | protected function addNewClasses ( & $ pathnameArray , & $ nonClassFiles , $ excludeVendor = true , PhpClass $ phpClassClone ) { $ files = $ this -> findFiles ( $ excludeVendor ) ; foreach ( $ files as $ file ) { $ pathname = $ file -> getPathname ( ) ; if ( ( ! isset ( $ pathnameArray [ $ pathname ] ) && ! isset ( $ nonClassFiles [ $ pathname ] ) ) || ( isset ( $ nonClassFiles [ $ pathname ] ) && md5_file ( $ file -> getPathname ( ) ) !== $ nonClassFiles [ $ pathname ] ) ) { $ phpClass = clone $ phpClassClone ; $ fileInfo = $ this -> parseSplFileInfo ( $ file , $ phpClass ) ; if ( is_object ( $ fileInfo ) ) { $ pathnameArray [ $ pathname ] = $ fileInfo ; } else { $ nonClassFiles [ $ fileInfo [ 'pathname' ] ] = $ fileInfo [ 'md5' ] ; } } } } | Finds classes which are not added to the cache |
21,803 | public function registerTwigModules ( ) { $ twig = \ Config :: get ( 'twigbridge::extensions' ) ; $ twig [ ] = 'Lablog\Lablog\Twig\PaginationLoader' ; $ twig [ ] = 'Lablog\Lablog\Twig\PostLoader' ; $ twig [ ] = 'Lablog\Lablog\Twig\PageLoader' ; $ twig [ ] = 'Lablog\Lablog\Twig\CategoryLoader' ; $ twig [ ] = 'Lablog\Lablog\Twig\CountLoader' ; \ Config :: set ( 'twigbridge::extensions' , $ twig ) ; } | Register twig modules . |
21,804 | public static function populateForm ( Form $ form ) { if ( static :: $ builder === null ) { static :: setBuilder ( new V1Model ) ; static :: $ builder -> setWrapperElement ( null ) ; } $ elements = static :: $ builder -> generate ( get_called_class ( ) ) ; return $ form -> setContents ( $ elements ) ; } | Populates the given form with the needed fields |
21,805 | public function toArray ( ) { $ data = array ( ) ; foreach ( $ this -> parameters as $ parameter => $ value ) { if ( is_object ( $ value ) && method_exists ( $ value , 'toArray' ) ) { $ data [ $ parameter ] = $ value -> toArray ( ) ; } elseif ( is_object ( $ value ) ) { $ data [ $ parameter ] = get_object_vars ( $ value ) ; } else { $ data [ $ parameter ] = $ value ; } } return $ data ; } | Get an array of the parameters |
21,806 | public function getBestFormat ( $ accept , $ supported ) { $ parts = $ this -> parseHeader ( $ accept ) ; $ parts = $ this -> sortParts ( $ parts ) ; foreach ( $ parts as $ part ) { if ( in_array ( $ part [ 'value' ] , $ supported ) ) { return $ part ; } if ( substr ( $ part [ 'value' ] , - 2 ) === '/*' ) { $ range = substr ( $ part [ 'value' ] , 0 , - 2 ) ; foreach ( $ supported as $ support ) { if ( strpos ( $ support , $ range , 0 ) === 0 ) { $ part [ 'value' ] = $ support ; return $ part ; } } } if ( $ part [ 'value' ] === '*/*' ) { return $ this -> acceptsAnything ( $ part [ 'quality' ] , $ supported ) ; } } return null ; } | Get the best format based on the accept header and the list of supported mime types . |
21,807 | private function parseParts ( array $ parts = [ ] ) { $ mimeType = $ parts [ 0 ] ; unset ( $ parts [ 0 ] ) ; $ support = [ 'value' => $ mimeType , 'quality' => ( float ) 1 ] ; foreach ( $ parts as $ part ) { $ param = explode ( '=' , $ part ) ; if ( isset ( $ param [ 1 ] ) ) { if ( $ param [ 0 ] === 'q' ) { $ support [ 'quality' ] = ( float ) $ param [ 1 ] ; } else { $ support [ 'parameters' ] [ $ param [ 0 ] ] = $ param [ 1 ] ; } } } return $ support ; } | Parse the different parts of the media range |
21,808 | public function matchUrl ( RequestInterface $ request , array $ maps ) { $ matched = [ ] ; $ uri = ( string ) $ request -> getUri ( ) ; foreach ( $ maps as $ map ) { if ( ( string ) $ map -> getRequest ( ) -> getUri ( ) === $ uri ) { $ matched [ ] = $ map ; } } return $ matched ; } | Match Url . |
21,809 | public function matchMethod ( RequestInterface $ request , array $ maps ) { $ matched = [ ] ; $ method = $ request -> getMethod ( ) ; foreach ( $ maps as $ map ) { if ( $ map -> getRequest ( ) -> getMethod ( ) === $ method ) { $ matched [ ] = $ map ; } } return $ matched ; } | Match method . |
21,810 | private function InitPlaceholders ( ) { return array ( Placeholders \ PhpDocPlaceholders :: AUTHOR => "Jeremie Litzler" , Placeholders \ PhpDocPlaceholders :: COPYRIGHT_YEAR => date ( "Y" ) , Placeholders \ PhpDocPlaceholders :: LICENCE => "http://opensource.org/licenses/gpl-license.php GNU Public License" , Placeholders \ PhpDocPlaceholders :: LINK => "https://github.com/Puzzlout/" , Placeholders \ PhpDocPlaceholders :: PACKAGE => $ this -> className , Placeholders \ PhpDocPlaceholders :: SUBPACKAGE => "" , Placeholders \ PhpDocPlaceholders :: VERSION_NUMBER => "PACKAGE_VERSION" , Placeholders \ ClassFilePlaceholders :: NAMESPACE_FRAMEWORK => "Puzzlout\Framework\BO" , Placeholders \ ClassFilePlaceholders :: NAMESPACE_APP => "\Applications\"" . "APP_NAME" . "\Models\Dao" , Placeholders \ ClassFilePlaceholders :: CLASS_NAME => $ this -> className ) ; } | Builds the associative array of placeholders . |
21,811 | public function AddNameSpace ( ) { $ output = "" ; if ( $ this -> isFrameworkClass ) { $ output = strtr ( CodeSnippets \ ClassFileSnippets :: SNIPPET_NAMESPACE_FRAMEWORK , $ this -> placeholders ) ; } else { $ output = strtr ( CodeSnippets \ ClassFileSnippets :: SNIPPET_NAMESPACE_APP , $ this -> placeholders ) ; } fwrite ( $ this -> writer , $ output ) ; } | Computes the namespace and writes it to the output . |
21,812 | public function AddFileDescription ( ) { $ output = CodeSnippets \ PhpDocSnippets :: OPENING . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: AUTHOR , $ this -> placeholders ) . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: COPYRIGHT , $ this -> placeholders ) . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: LICENCE , $ this -> placeholders ) . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: LINK , $ this -> placeholders ) . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: SINCE , $ this -> placeholders ) . $ this -> _LF . strtr ( CodeSnippets \ PhpDocSnippets :: PACKAGE , $ this -> placeholders ) . $ this -> _LF . CodeSnippets \ PhpDocSnippets :: CLOSING . $ this -> _LF ; fwrite ( $ this -> writer , $ output ) ; } | Computes the class description using PhpDoc and writes it to the output . |
21,813 | public function ClassStart ( ) { $ output = $ this -> _CRLF . "class " . ucfirst ( $ this -> className ) . " extends " . $ this -> baseClass . " {" . $ this -> _LF ; fwrite ( $ this -> writer , $ output ) ; } | Writes the start of the class . |
21,814 | private function AddConstants ( $ columnsMetadata ) { $ output = "" ; foreach ( $ columnsMetadata as $ columnName => $ columnMetadata ) { $ output .= $ this -> _TAB2 . "const " . strtoupper ( $ columnMetadata [ "Field" ] ) . " = \"" . $ columnMetadata [ "Field" ] . "\";" . $ this -> _LF ; } $ output .= $ this -> _CRLF ; fwrite ( $ this -> writer , $ output ) ; } | Writes the constant representation of the class s field properties . |
21,815 | private function AddFields ( $ columnsMetadata ) { $ output = $ this -> _TAB2 . "protected " . $ this -> _LF ; $ columnCount = 0 ; foreach ( $ columnsMetadata as $ columnName => $ columnMetadata ) { if ( count ( $ columnsMetadata ) - 1 === $ columnCount ) { $ output .= $ this -> _TAB4 . "$" . $ columnMetadata [ "Field" ] . ";" . $ this -> _CRLF ; } else { $ output .= $ this -> _TAB4 . "$" . $ columnMetadata [ "Field" ] . "," . $ this -> _LF ; } $ columnCount += 1 ; } fwrite ( $ this -> writer , $ output ) ; } | Writes the field properties from the columns metadata . |
21,816 | private function AddPropertyPhpDoc ( $ columnMetadata , $ isSetter = true ) { $ output = $ this -> _TAB2 . \ Puzzlout \ Framework \ GeneratorEngine \ CodeSnippets \ PhpDocSnippets :: OPENING . $ this -> _TAB2 . $ this -> _LF ; $ placeholders = array ( "{{set_dynamic_code}}" => strtr ( CodeSnippets \ PhpDocSnippets :: SET_PROPERTY_SUMMARY , array ( Placeholders \ PhpDocPlaceholders :: SET_PROPERTY => $ columnMetadata [ "Field" ] ) ) , "{{get_dynamic_code}}" => strtr ( CodeSnippets \ PhpDocSnippets :: GET_PROPERTY_SUMMARY , array ( Placeholders \ PhpDocPlaceholders :: GET_PROPERTY => $ columnMetadata [ "Field" ] ) ) ) ; if ( $ isSetter ) { $ output .= $ this -> _TAB2 . strtr ( "{{set_dynamic_code}}" , $ placeholders ) ; } else { $ output .= $ this -> _TAB2 . strtr ( "{{get_dynamic_code}}" , $ placeholders ) ; } $ output .= $ this -> _LF . $ this -> _TAB2 . CodeSnippets \ PhpDocSnippets :: CLOSING . $ this -> _LF ; return $ output ; } | Writes the PhpDoc for the setter and getter functions from a column metadata . |
21,817 | public function undel ( $ term ) { if ( false === $ this -> has_table ( ) or true === $ this -> is_destructive ) { $ this -> set_error ( 'Model ' . get_class ( $ this ) . ' has no recoverable data' ) ; return false ; } $ term = $ this -> normalize_term ( $ term ) ; return $ this -> trash_it ( $ term , false ) ; } | Restore all deleted data |
21,818 | public function count ( $ with_deleted = null ) { if ( false === $ this -> has_table ( ) ) return false ; if ( $ this -> count === 0 ) { $ with_deleted !== null or $ with_deleted = ( ! $ this -> is_destructive ) ; if ( false === $ with_deleted ) { $ db = $ this -> db -> where ( $ this -> deletion_key , 0 ) ; } $ this -> count = $ db -> count_all_results ( $ this -> table ) ; } return $ this -> count ; } | Count all rows |
21,819 | public function has_table ( ) { if ( null === $ this -> table ) { $ this -> set_error ( 'This model is has no table specified' , true ) ; } elseif ( false === $ this -> table ) { return false ; } } | Determine is this model has table assigned |
21,820 | public function trash_it ( $ term , $ flag = true ) { return $ this -> edit ( $ term , [ $ this -> deletion_key => ( int ) $ flag ] + $ this -> timestamp ( 'modification' ) ) ; } | Wanna mark a thing as garbage? |
21,821 | public function timestamp ( $ state = 'modification' , $ user_id = null ) { if ( ! in_array ( $ state , [ 'creation' , 'modification' ] ) ) { $ this -> set_error ( 'Unsupported timestamp state ' . $ state , true ) ; } $ is_datetime = strtolower ( $ this -> timestamp_format ) == 'datetime' ; $ timestamp = $ is_datetime ? date ( 'Y-m-d H:i:s' ) : time ( ) ; if ( null === $ user_id and ! is_cli ( ) ) { $ user_id = $ this -> session -> user_data ( 'user_id' ) ? : null ; } $ stamps = [ $ this -> modification_key => $ timestamp ] ; if ( $ state == 'creation' ) { $ stamps += [ $ this -> creation_key => $ timestamp ] ; } if ( $ this -> is_autotimestamp ) { return $ stamps ; } return [ ] ; } | Generate creation & modification timestamp |
21,822 | protected function normalize_term ( $ term = null ) { if ( null === $ term ) { return [ ] ; } if ( is_int ( $ term ) ) { $ term = [ $ this -> primary_key => $ term ] ; } if ( $ _term = $ this -> call_hook ( 'term.after.normalized' , $ term ) ) { $ term = $ _term ; } return $ term ; } | Basic query term normalization |
21,823 | public function validate ( $ subject ) : bool { foreach ( $ this -> validatorMap as $ validatorName => $ validatorClass ) { if ( \ array_key_exists ( $ validatorName , $ this -> schema ) ) { $ typeValidator = new $ validatorClass ( $ this -> schema , $ this -> rootSchema ) ; if ( ! $ typeValidator -> validate ( $ subject ) ) { return false ; } } } return true ; } | Single node validator chain |
21,824 | public function hydrate ( Model $ model , \ Tapestry \ Entities \ ContentType $ contentType ) { $ model -> setName ( $ contentType -> getName ( ) ) ; $ model -> setPath ( $ contentType -> getPath ( ) ) ; $ model -> setTemplate ( $ contentType -> getTemplate ( ) ) ; $ model -> setPermalink ( $ contentType -> getPermalink ( ) ) ; $ model -> setEnabled ( $ contentType -> isEnabled ( ) ) ; } | ContentType Hydration . |
21,825 | public function deleteTempFiles ( ) { foreach ( $ this -> _tempFiles as $ tmp ) { if ( is_dir ( $ tmp ) ) { FileHelper :: removeDirectory ( $ tmp ) ; } else { @ unlink ( $ tmp ) ; } } return true ; } | Delete the tracked temporary file . |
21,826 | public function getTempFile ( $ keep = false , $ ext = null ) { $ tmp = tempnam ( $ this -> tempPath , "tmp_" ) ; $ tmpExt = '' ; if ( ! is_null ( $ ext ) ) { $ tmpExt .= ".{$ext}" ; } if ( ! $ keep ) { $ this -> _tempFiles [ ] = $ tmp ; if ( ! empty ( $ tmpExt ) ) { $ tmp = $ tmp . $ tmpExt ; $ this -> _tempFiles [ ] = $ tmp ; } } else { if ( ! empty ( $ tmpExt ) ) { $ tmp = $ tmp . $ tmpExt ; } } return $ tmp ; } | Get a temporary file . |
21,827 | public function getTempPath ( ) { if ( is_null ( $ this -> _tempPath ) ) { $ this -> _tempPath = sys_get_temp_dir ( ) ; } if ( ! is_dir ( $ this -> _tempPath ) ) { @ mkdir ( $ this -> _tempPath , 0755 , true ) ; if ( ! is_dir ( $ this -> _tempPath ) ) { throw new Exception ( "Unable to create temporary path folder {$this->_tempPath}" ) ; } } return $ this -> _tempPath ; } | Get a temporary path . |
21,828 | public function getDOM ( $ doc = null , $ majorVersion = 1 , $ minorVersion = null ) { $ element = parent :: getDOM ( $ doc , $ majorVersion , $ minorVersion ) ; foreach ( $ this -> _entry as $ entry ) { $ element -> appendChild ( $ entry -> getDOM ( $ element -> ownerDocument ) ) ; } return $ element ; } | Retrieves the DOM model representing this object and all children |
21,829 | public function getNextFeed ( ) { $ nextLink = $ this -> getNextLink ( ) ; if ( ! $ nextLink ) { require_once 'Zend/Gdata/App/HttpException.php' ; throw new Zend_Gdata_App_Exception ( 'No link to next set ' . 'of results found.' ) ; } $ nextLinkHref = $ nextLink -> getHref ( ) ; $ service = new Zend_Gdata_App ( $ this -> getHttpClient ( ) ) ; return $ service -> getFeed ( $ nextLinkHref , get_class ( $ this ) ) ; } | Retrieve the next set of results from this feed . |
21,830 | public function getPreviousFeed ( ) { $ previousLink = $ this -> getPreviousLink ( ) ; if ( ! $ previousLink ) { require_once 'Zend/Gdata/App/HttpException.php' ; throw new Zend_Gdata_App_Exception ( 'No link to previous set ' . 'of results found.' ) ; } $ previousLinkHref = $ previousLink -> getHref ( ) ; $ service = new Zend_Gdata_App ( $ this -> getHttpClient ( ) ) ; return $ service -> getFeed ( $ previousLinkHref , get_class ( $ this ) ) ; } | Retrieve the previous set of results from this feed . |
21,831 | public function setMajorProtocolVersion ( $ value ) { parent :: setMajorProtocolVersion ( $ value ) ; foreach ( $ this -> entries as $ entry ) { $ entry -> setMajorProtocolVersion ( $ value ) ; } } | Set the major protocol version that should be used . Values < 1 will cause a Zend_Gdata_App_InvalidArgumentException to be thrown . |
21,832 | public function setMinorProtocolVersion ( $ value ) { parent :: setMinorProtocolVersion ( $ value ) ; foreach ( $ this -> entries as $ entry ) { $ entry -> setMinorProtocolVersion ( $ value ) ; } } | Set the minor protocol version that should be used . If set to NULL no minor protocol version will be sent to the server . Values < 0 will cause a Zend_Gdata_App_InvalidArgumentException to be thrown . |
21,833 | protected function deployThumbnail ( $ thumbnailName ) { $ mediaStorageManager = $ this -> container -> get ( 'open_orchestra_media.manager.storage' ) ; $ fileDir = 'web/bundles/openorchestramediaadmin/images/' ; $ mediaStorageManager -> uploadFile ( $ thumbnailName , $ fileDir . DIRECTORY_SEPARATOR . $ thumbnailName , false ) ; } | Deploy a logo on the media storage |
21,834 | public function parse ( & $ segments ) { $ active = $ this -> menu -> getActive ( ) ; $ vars = [ ] ; if ( ! empty ( $ active ) ) { $ vars = $ active -> query ; } return array_merge ( $ vars , array ( 'path' => implode ( '/' , $ segments ) ) ) ; } | Parse method for URLs This method is meant to transform the human readable URL back into query parameters . It is only executed when SEF mode is switched on . |
21,835 | public function getIterator ( ) : \ Generator { foreach ( $ this -> sourceIterable as $ content ) { try { yield $ this -> stream -> write ( $ content ) ; } catch ( \ InvalidArgumentException $ ex ) { throw new \ RuntimeException ( 'The iterable generated values that are not writable' , 0 , $ ex ) ; } } } | Generates integer values for the amount of written bytes in each iteration . |
21,836 | public function force_ansi ( $ enable = true ) { if ( $ enable ) { $ this -> climate -> forceAnsiOn ( ) ; } else { $ this -> climate -> forceAnsiOff ( ) ; } return $ this ; } | Toggle ANSI support on or off |
21,837 | public function set_description ( $ desc ) { if ( substr ( $ desc , 0 , 5 ) == 'lang:' ) { $ desc = substr ( $ desc , 5 ) ; if ( $ _desc = self :: lang ( $ desc ) ) { return $ this -> climate -> arguments -> description ( $ _desc ) ; } } return $ this -> climate -> arguments -> description ( $ desc ) ; } | Set a program s description . |
21,838 | public static function generateIndentation ( $ indentLevel , $ format ) { if ( $ format ) { $ expr = "" ; for ( $ i = 0 ; $ i < $ indentLevel ; $ i ++ ) $ expr .= " " ; return $ expr ; } else return "" ; } | Generates indentation to format the resulting output expression more nicely . |
21,839 | public static function sequentialArrayToIndentedNix ( array $ array , $ indentLevel , $ format ) { if ( count ( $ array ) == 0 ) return "[]" ; else { $ expr = "[\n" ; foreach ( $ array as $ value ) { $ listMemberExpr = NixGenerator :: phpToIndentedNix ( $ value , $ indentLevel + 1 , $ format ) ; if ( $ value instanceof NixBlock ) { $ listMemberExpr = $ value -> wrapInParenthesis ( $ listMemberExpr ) ; } $ expr .= NixGenerator :: generateIndentation ( $ indentLevel + 1 , $ format ) . $ listMemberExpr . "\n" ; } $ expr .= NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . "]" ; return $ expr ; } } | Converts an array to a Nix list . |
21,840 | public static function arrayMembersToAttrsMembers ( array $ array , $ indentLevel , $ format ) { $ expr = "" ; $ first = true ; $ haveInherits = false ; $ previousInherit = null ; foreach ( $ array as $ key => $ value ) { if ( $ value instanceof NixInherit ) { $ haveInherits = true ; if ( $ previousInherit === null || ! $ value -> equals ( $ previousInherit ) ) { if ( $ first ) $ first = false ; else $ expr .= ";\n" ; $ expr .= NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . $ value -> toNixExpr ( $ indentLevel , $ format ) ; } $ expr .= " " . NixGenerator :: objectKeyToAttrName ( $ key ) ; $ previousInherit = $ value ; } } if ( $ haveInherits ) $ expr .= ";\n" ; foreach ( $ array as $ key => $ value ) { if ( ! ( $ value instanceof NixInherit ) ) $ expr .= NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . NixGenerator :: objectKeyToAttrName ( $ key ) . " = " . NixGenerator :: phpToIndentedNix ( $ value , $ indentLevel , $ format ) . ";\n" ; } return $ expr ; } | Converts members of an array to members of an attribute set |
21,841 | public static function associativeArrayToIndentedNix ( array $ array , $ indentLevel , $ format ) { if ( count ( $ array ) == 0 ) return "{}" ; else return "{\n" . NixGenerator :: arrayMembersToAttrsMembers ( $ array , $ indentLevel + 1 , $ format ) . NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . "}" ; } | Converts an array to a Nix attribute set . |
21,842 | public static function phpToIndentedNix ( $ obj , $ indentLevel , $ format ) { $ expr = "" ; switch ( gettype ( $ obj ) ) { case "boolean" : $ expr .= NixGenerator :: booleanToIndentedNix ( $ obj ) ; break ; case "integer" : $ expr .= $ obj ; break ; case "double" : $ expr .= $ obj ; break ; case "string" : $ expr .= NixGenerator :: stringToIndentedNix ( $ obj ) ; break ; case "array" : $ expr .= NixGenerator :: arrayToIndentedNix ( $ obj , $ indentLevel , $ format ) ; break ; case "object" : $ expr .= NixGenerator :: objectToIndentedNix ( $ obj , $ indentLevel , $ format ) ; break ; case "resource" : throw new Exception ( "Cannot convert a resource to a Nix expression" ) ; break ; case "NULL" : $ expr .= "null" ; break ; case "unknown type" : throw new Exception ( "Cannot convert object of unknown type: " . $ obj ) ; default : throw new Exception ( "Encountered a totally unrecognizable type: " . $ obj ) ; } return $ expr ; } | Converts a PHP variable of any type to a semantically equivalent or similar Nix expression language object . It also uses indentation to format the resulting sub expression more nicely . |
21,843 | public function addRuleCallback ( $ name , Callable $ callback ) { if ( ! is_string ( $ name ) ) { throw new \ InvalidArgumentException ( 'Rule must be a string' ) ; } $ rule = $ this -> createRuleCallback ( $ name , $ callback ) ; $ this -> addRule ( $ rule ) ; } | Adds a rule callback to the Permission . |
21,844 | public function revokeRule ( $ rule ) { if ( $ this -> hasRule ( $ rule ) ) { unset ( $ this -> rules [ $ rule ] ) ; return true ; } else { return false ; } } | Revokes a rule from the Permission . |
21,845 | public function getRule ( $ name ) { if ( $ this -> hasRule ( $ name ) ) { return $ this -> rules [ $ name ] ; } throw new \ InvalidArgumentException ( sprintf ( 'No rule with name "%s" could be found' , $ name ) ) ; } | Returns the named rule from the Permission . |
21,846 | public function checkRules ( $ rules , Array $ params = null ) { if ( is_string ( $ rules ) ) { $ rules = ( array ) explode ( ',' , $ rules ) ; } foreach ( $ rules as $ name ) { if ( ! $ this -> hasRule ( $ name ) || ! $ this -> getRule ( $ name ) -> execute ( $ this , $ params ) ) { return false ; } } return true ; } | Checks the rules for the Permission . |
21,847 | public function GetValue ( $ key ) { $ resources = $ this -> GetList ( ) ; $ keyExist = array_key_exists ( $ key , $ resources ) ; if ( $ keyExist ) { return $ resources [ $ key ] [ \ Puzzlout \ Framework \ BO \ F_common_resource :: F_COMMON_RESOURCE_VALUE ] ; } else { return "???" ; } } | Get the resource value by group and key . |
21,848 | public function GetComment ( $ key ) { $ resources = $ this -> GetList ( ) ; $ keyExist = array_key_exists ( $ key , $ resources ) ; if ( $ keyExist ) { return $ resources [ $ key ] [ \ Puzzlout \ Framework \ BO \ F_common_resource :: F_COMMON_RESOURCE_COMMENT ] ; } else { return "???" ; } } | Get the resource comment by group and key . |
21,849 | public function toArray ( ) { $ _address = [ ] ; if ( $ this -> hasCountry ( ) ) $ _address [ 'country' ] = $ this -> getCountry ( ) ; if ( $ this -> hasState ( ) ) $ _address [ 'state' ] = $ this -> getState ( ) ; if ( $ this -> hasMunicipality ( ) ) $ _address [ 'municipality' ] = $ this -> getMunicipality ( ) ; if ( $ this -> hasCity ( ) ) $ _address [ 'city' ] = $ this -> getCity ( ) ; if ( $ this -> hasDistrict ( ) ) $ _address [ 'district' ] = $ this -> getDistrict ( ) ; if ( $ this -> hasNeighbourhood ( ) ) $ _address [ 'neighbourhood' ] = $ this -> getNeighbourhood ( ) ; if ( $ this -> hasStreet ( ) ) $ _address [ 'street' ] = $ this -> getStreet ( ) ; if ( $ this -> hasNumber ( ) ) $ _address [ 'number' ] = $ this -> getNumber ( ) ; if ( $ this -> hasAddition ( ) ) $ _address [ 'addition' ] = $ this -> getAddition ( ) ; if ( $ this -> hasZipcode ( ) ) $ _address [ 'zipcode' ] = $ this -> getZipcode ( ) ; return $ _address ; } | Convert address to array |
21,850 | public static function fromStdClass ( $ _address ) { $ address = new static ( ) ; if ( isset ( $ _address -> country ) ) $ address -> setCountry ( $ _address -> country ) ; if ( isset ( $ _address -> state ) ) $ address -> setState ( $ _address -> state ) ; if ( isset ( $ _address -> municipality ) ) $ address -> setMunicipality ( $ _address -> municipality ) ; if ( isset ( $ _address -> city ) ) $ address -> setCity ( $ _address -> city ) ; if ( isset ( $ _address -> district ) ) $ address -> setDistrict ( $ _address -> district ) ; if ( isset ( $ _address -> neighbourhood ) ) $ address -> setNeighbourhood ( $ _address -> neighbourhood ) ; if ( isset ( $ _address -> street ) ) $ address -> setStreet ( $ _address -> street ) ; if ( isset ( $ _address -> number ) ) $ address -> setNumber ( $ _address -> number ) ; if ( isset ( $ _address -> addition ) ) $ address -> setAddition ( $ _address -> addition ) ; if ( isset ( $ _address -> zipcode ) ) $ address -> setZipcode ( $ _address -> zipcode ) ; return $ address ; } | Convert from StdClass |
21,851 | protected static function getPath ( $ param ) { $ path = ( is_null ( Application :: $ root ) ? "config/$param.php" : Application :: $ root . "config/$param.php" ) ; return Bus :: need ( ( is_null ( Application :: $ root ) ? "config/$param.php" : Application :: $ root . "config/$param.php" ) ) ; } | get path of config files . |
21,852 | public static function load ( $ kernelTest = false ) { if ( $ kernelTest ) { return self :: mock ( ) ; } else { $ levels = self :: getFirstLevel ( ) ; foreach ( $ levels as $ level ) { self :: $ params [ $ level ] = self :: getPath ( $ level ) ; } return true ; } } | load all params from file to virtual array . |
21,853 | public static function check ( $ param , $ default = false ) { $ p = self :: separate ( $ param ) ; if ( $ p [ 'first' ] == 'database' ) { self :: checkDatabase ( $ p [ 'second' ] ) ; } else { if ( ! in_array ( $ p [ 'first' ] , self :: getFirstLevel ( ) ) ) { if ( ! $ default ) { self :: exception ( $ p [ 'first' ] , $ p [ 'second' ] ) ; } return true ; } elseif ( ! array_key_exists ( $ p [ 'second' ] , self :: $ params [ $ p [ 'first' ] ] ) ) { if ( ! $ default ) { self :: exception ( $ p [ 'first' ] , $ p [ 'second' ] ) ; } return true ; } } return true ; } | check if parameter exists . |
21,854 | protected static function reach ( $ param , $ default = null ) { $ p = self :: separate ( $ param ) ; if ( $ p [ 'first' ] == 'database' ) { return self :: callDatabase ( $ p [ 'second' ] ) ; } return array_get ( self :: $ params , $ param , $ default ) ; } | find request parameter . |
21,855 | protected static function checkDatabase ( $ key ) { $ driver = self :: $ params [ 'database' ] [ 'default' ] ; if ( array_key_exists ( $ key , self :: $ params [ 'database' ] ) ) { return true ; } elseif ( array_key_exists ( $ key , self :: $ params [ 'database' ] [ 'connections' ] [ $ driver ] ) ) { return true ; } else { self :: exception ( 'database' , $ key ) ; } } | check if secondary parameter exists if primary parameter is database . |
21,856 | protected static function callDatabase ( $ key ) { $ params = [ 'migration' , 'prefixing' , 'prefixe' , 'default' ] ; $ data = self :: $ params [ 'database' ] ; $ driver = $ data [ 'default' ] ; exception_if ( ! array_has ( $ data [ 'connections' ] , $ driver ) , DatabaseDriverNotFoundException :: class , $ driver ) ; return ( ! in_array ( $ key , $ params ) ) ? $ data [ 'connections' ] [ $ driver ] [ $ key ] : $ data [ $ key ] ; } | find request parameter if primary parameter is database . |
21,857 | public static function get ( $ key , $ value = null ) { if ( self :: check ( $ key , ! is_null ( $ value ) ) ) { return self :: reach ( $ key , $ value ) ; } static :: set ( $ key , $ value ) ; return $ value ; } | get value of config parameter . |
21,858 | public function delete ( User $ user , User $ entity ) { if ( $ entity -> id === $ user -> id ) { return true ; } return $ user -> hasPermission ( 'user-delete' ) ; } | Policy for deleting single element |
21,859 | protected function getContentType ( ServerRequestInterface $ request ) { if ( null !== $ accept = $ request -> getAttribute ( 'Content-Type' , null ) ) { return $ accept ; } if ( $ request -> hasHeader ( 'Content-Type' ) ) { return $ request -> getHeaderLine ( 'Content-Type' ) ; } return null ; } | Get content type from request . First check for an attribute . An attribute is usually set if content negotiation are done . |
21,860 | public static function & CreateInstance ( array $ constructorConfig = [ ] ) { $ validator = new static ( $ constructorConfig ) ; $ validator :: $ toolClass = \ MvcCore \ Application :: GetInstance ( ) -> GetToolClass ( ) ; return $ validator ; } | Create every time new validator instance with configured form instance . No singleton . |
21,861 | protected function throwNewInvalidArgumentException ( $ errorMsg ) { $ msgs = [ ] ; if ( $ this -> field ) $ msgs [ ] = 'Field name: `' . $ this -> field -> GetName ( ) . '`, Field type: `' . get_class ( $ this -> field ) . '`' ; if ( $ this -> form ) $ msgs [ ] = 'Form id: `' . $ this -> form -> GetId ( ) . '`, Form type: `' . get_class ( $ this -> form ) . '`' ; $ selfClass = version_compare ( PHP_VERSION , '5.5' , '>' ) ? self :: class : __CLASS__ ; throw new \ InvalidArgumentException ( '[' . $ selfClass . '] ' . $ errorMsg . ( $ msgs ? ' ' . implode ( ', ' , $ msgs ) : '' ) ) ; } | Throw new \ InvalidArgumentException with given error message and append automatically current class field name form id field class name and form class name . |
21,862 | protected function getEntity ( $ entityId ) { $ entity = $ this -> getRepository ( ) -> get ( $ entityId ) ; if ( ! $ entity instanceof EntityInterface ) { throw new EntityNotFoundException ( "There are no entities with provided entity ID." ) ; } return $ entity ; } | Gets entity with provided primary key |
21,863 | public function EXE ( I_O $ IO ) { while ( true ) { try { if ( true === $ IO -> I_ ( Type :: BOOL ) ) { return $ IO -> _O ( true ) ; } } catch ( I_O_InputIndexException $ e ) { break ; } } return $ IO -> _O ( false ) ; } | Applies the OR operator to the input values . |
21,864 | public function flashMessages ( $ environment , array $ options = array ( ) ) { $ params = array_merge ( array ( 'close_button' => true , 'trans_domain' => null , ) , $ options ) ; $ template = $ environment -> loadTemplate ( 'ASFLayoutBundle:session:flash-messages.html.twig' ) ; return $ template -> renderBlock ( 'flash_messages' , array_merge ( $ environment -> getGlobals ( ) , $ params ) ) ; } | Return HTML of flash messages according to flash - messages . html . twig . |
21,865 | public function write ( $ string ) { if ( ! is_array ( $ string ) ) { $ string = [ $ string ] ; } foreach ( $ string as $ item ) { $ this -> buffer .= $ item ; } } | Add a string to buffer . |
21,866 | public function slice ( $ from , $ length = null ) { if ( $ length === null ) { return substr ( $ this -> buffer , $ from ) ; } return substr ( $ this -> buffer , $ from , $ length ) ; } | Get a slice from the buffer . |
21,867 | public static function dumpBacktrace ( array $ backtraces , string $ format = "[%INDEX%]%CLASS%%TYPE%%FUNCTION%() in %FILE%(%LINE%)" ) { self :: walkBacktrace ( $ backtraces , function ( $ index , $ file , $ line , $ class , $ type , $ func ) use ( $ format ) { $ line = strtr ( $ format , [ '%INDEX%' => $ index + 1 , '%FILE%' => $ file , '%LINE%' => $ line , '%CLASS%' => $ class , '%TYPE%' => $ type , '%FUNCTION%' => $ func , ] ) ; echo $ line . PHP_EOL ; } ) ; } | Dump back traces |
21,868 | public static function walkBacktrace ( $ backtraces , callable $ callback ) { foreach ( $ backtraces as $ index => $ item ) { $ func = $ item [ 'function' ] ?? '' ; $ class = $ item [ 'class' ] ?? '' ; $ type = $ item [ 'type' ] ?? '' ; $ file = $ item [ 'file' ] ?? '' ; $ line = $ item [ 'line' ] ?? '' ; ( $ callback ) ( $ index , $ file , $ line , $ class , $ type , $ func ) ; } } | Walk back traces |
21,869 | public static function isBitSet ( int $ target , int $ flag , int $ mode ) : bool { switch ( $ mode ) { case self :: BITTEST_MODE_ALL : return ( $ target & $ flag ) === $ flag ; break ; case self :: BITTEST_MODE_ANY : return ( $ target & $ flag ) != 0 ; } return false ; } | Test if specified bit flag is set |
21,870 | public static function formatByteSize ( $ size , $ precision = 1 , $ symbols = NULL ) { if ( $ symbols === NULL ) { $ symbols = array ( 'B' , 'Kb' , 'Mb' , 'Gb' , 'Tb' , 'Pb' ) ; } $ i = 0 ; while ( ( $ size / 1024 ) > 1 ) { $ size = $ size / 1024 ; $ i ++ ; } return ( round ( $ size , $ precision ) . " " . $ symbols [ $ i ] ) ; } | format byte size |
21,871 | public static function hash ( string $ algo = 'sha1' , string $ data = NULL ) { if ( ! $ data ) { $ data = microtime ( ) . uniqid ( mt_rand ( ) , 1 ) ; } return hash ( $ algo , $ data ) ; } | generate hash value |
21,872 | public static function escape ( $ value ) { if ( is_string ( $ value ) ) { $ res = htmlspecialchars ( $ value , ENT_QUOTES , mb_internal_encoding ( ) ) ; return $ res ; } elseif ( is_array ( $ value ) ) { $ ret = array ( ) ; foreach ( $ value as $ key => $ item ) { $ ret [ $ key ] = self :: escape ( $ item ) ; } return $ ret ; } elseif ( is_object ( $ value ) ) { $ object = $ value ; $ vars = get_object_vars ( $ object ) ; foreach ( $ vars as $ key => $ value ) { $ object -> $ key = self :: escape ( $ value ) ; } return $ object ; } return $ value ; } | escape variable for HTML |
21,873 | public static function decode ( $ value ) { if ( is_string ( $ value ) ) { $ res = htmlspecialchars_decode ( $ value , ENT_QUOTES ) ; return $ res ; } elseif ( is_array ( $ value ) ) { return array_map ( 'Charcoal_System::decode' , $ value ) ; } elseif ( is_object ( $ value ) ) { $ object = $ value ; $ vars = get_object_vars ( $ object ) ; foreach ( $ vars as $ key => $ value ) { $ object -> $ key = self :: decode ( $ value ) ; } return $ object ; } return $ value ; } | decode escaped value |
21,874 | public static function stripTags ( $ value , $ allowable_tags = NULL ) { if ( is_string ( $ value ) ) { $ res = strip_tags ( $ value , $ allowable_tags ) ; return $ res ; } elseif ( is_array ( $ value ) ) { $ array = $ value ; foreach ( $ array as $ key => $ value ) { $ array [ $ key ] = self :: stripTags ( $ value , $ allowable_tags ) ; } return $ array ; } elseif ( is_object ( $ value ) ) { $ object = $ value ; $ vars = get_object_vars ( $ object ) ; foreach ( $ vars as $ key => $ value ) { $ object -> $ key = self :: stripTags ( $ value ) ; } return $ object ; } return $ value ; } | remove HTML tags |
21,875 | public static function escapeString ( $ string_data , $ options = NULL ) { if ( ! $ options ) { $ options = array ( 'quote_style' => 'ENT_QUOTES' , ) ; } $ quote_style = ENT_NOQUOTES ; if ( isset ( $ options [ 'quote_style' ] ) && $ options [ 'quote_style' ] == 'ENT_QUOTES' ) { $ quote_style = ENT_QUOTES ; } $ str = htmlspecialchars ( $ string_data , $ quote_style ) ; return $ str ; } | escape string for HTML |
21,876 | public static function makeRandomString ( $ length , $ char_set = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' ) { $ ret = '' ; $ char_set_cnt = strlen ( $ char_set ) ; mt_srand ( ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ idx = mt_rand ( 0 , $ char_set_cnt - 1 ) ; $ ret .= $ char_set [ $ idx ] ; } return $ ret ; } | make random string |
21,877 | public static function caller ( int $ back = 0 ) { $ bt = debug_backtrace ( ) ; $ trace = $ bt [ $ back ] ?? null ; $ file = $ trace [ 'file' ] ?? '' ; $ line = $ trace [ 'line' ] ?? - 1 ; return array ( $ file , intval ( $ line ) ) ; } | return file and line number of called position |
21,878 | public static function callerAsString ( $ back = 0 , $ fullpath = FALSE ) { list ( $ file , $ line ) = self :: caller ( $ back ) ; if ( $ fullpath ) { return "$file($line)" ; } $ file = basename ( $ file ) ; return "$file($line)" ; } | return file and line number of called position as string |
21,879 | public static function getType ( $ value ) { $ type = gettype ( $ value ) ; switch ( $ type ) { case 'string' : return $ type . '(' . strlen ( $ value ) . ')' ; break ; case 'integer' : case 'float' : case 'boolean' : return $ type . '(' . $ value . ')' ; break ; case 'NULL' : case 'unknown type' : return $ type ; break ; case 'array' : return $ type . '(' . count ( $ value ) . ')' ; break ; case 'object' : if ( $ value instanceof \ Countable ) { return get_class ( $ value ) . '(' . count ( $ value ) . ')' ; } elseif ( $ value instanceof HashableInterface ) { return get_class ( $ value ) . '(hash=' . $ value -> hash ( ) . ')' ; } return get_class ( $ value ) ; break ; } return '' ; } | get type of primitive resource array or object |
21,880 | public static function toString ( $ value , $ with_type = FALSE , $ max_size = self :: TOSTRING_MAX_LENGTH , $ tostring_methods = '__toString,toString' ) { $ ret = '' ; if ( $ value === NULL ) { $ ret = 'NULL' ; } else { $ type = gettype ( $ value ) ; switch ( $ type ) { case 'string' : case 'integer' : case 'double' : case 'boolean' : case 'NULL' : case 'unknown type' : $ ret = strval ( $ value ) ; if ( $ with_type ) { $ ret .= '(' . $ type . ')' ; } break ; case 'array' : $ ret = '' ; foreach ( $ value as $ k => $ v ) { if ( strlen ( $ ret ) > 0 ) $ ret .= '/' ; $ ret .= "$k=" . self :: toString ( $ v ) ; if ( $ with_type ) { $ ret .= '(' . gettype ( $ v ) . ')' ; } } break ; case 'object' : { $ methods = explode ( ',' , $ tostring_methods ) ; foreach ( $ methods as $ method ) { if ( method_exists ( $ value , $ method ) ) { $ ret = $ value -> { $ method } ( ) ; break ; } } if ( $ with_type ) { $ ret .= '(' . get_class ( $ value ) . ')' ; } } break ; } } if ( $ max_size > 0 ) { return strlen ( $ ret ) > $ max_size ? substr ( $ ret , 0 , $ max_size ) . '...' : $ ret ; } else { return $ ret ; } } | make string expression about a variable |
21,881 | public static function dump ( $ var , $ format = 'html' , $ back = 0 , $ options = NULL , $ return = FALSE , $ max_depth = 6 ) { list ( $ file , $ line ) = self :: caller ( $ back ) ; if ( ! $ options ) { $ options = array ( ) ; } $ default_options = array ( 'title' => 'system dump' , 'font_size' => 11 , 'max_string_length' => self :: DUMP_MAX_LENGTH , 'type' => 'textarea' , ) ; $ options = array_merge ( $ default_options , $ options ) ; $ title = $ options [ 'title' ] ; $ font_size = $ options [ 'font_size' ] ; $ max_string_length = $ options [ 'max_string_length' ] ; $ type = $ options [ 'type' ] ; $ lines = array ( ) ; $ recursion = array ( ) ; self :: _dump ( '-' , $ var , 0 , $ max_string_length , $ lines , $ max_depth , $ recursion ) ; switch ( $ format ) { case "html" : switch ( $ type ) { case 'div' : $ output = "<div style=\"font-size:12px; margin: 2px\"> $title:" . implode ( '' , $ lines ) . " @$file($line)</div>" ; break ; case 'textarea' : default : $ output = "<h3 style=\"font-size:12px; margin: 0; color:black; background-color:white; text-align: left\"> $title @$file($line)</h3>" ; $ output .= "<textarea rows=14 style=\"width:100%; font-size:{$font_size}px; margin: 0; color:black; background-color:white; border: 1px solid silver;\">" ; $ output .= implode ( PHP_EOL , $ lines ) ; $ output .= "</textarea>" ; break ; } break ; case "shell" : default : $ output = "$title @$file($line)" . PHP_EOL ; $ output .= implode ( PHP_EOL , $ lines ) . PHP_EOL ; break ; } if ( $ return ) { return $ output ; } else { echo $ output ; return null ; } } | dump a variable |
21,882 | public static function convertEncodingRecursive ( $ var , $ to_encoding = NULL , $ from_encoding = NULL ) { $ type = gettype ( $ var ) ; switch ( $ type ) { case 'string' : { return mb_convert_encoding ( $ var , $ to_encoding , $ from_encoding ) ; } break ; case 'integer' : case 'double' : case 'boolean' : case 'NULL' : case 'unknown type' : break ; case 'array' : { $ newArray = array ( ) ; foreach ( $ var as $ key => $ value ) { $ value = self :: convertEncodingRecursive ( $ value , $ to_encoding , $ from_encoding ) ; $ newArray [ $ key ] = $ value ; } return $ newArray ; } break ; case 'object' : { $ newObject = clone $ var ; if ( $ var instanceof \ Traversable ) { foreach ( $ var as $ key => $ value ) { $ value = self :: convertEncodingRecursive ( $ value , $ to_encoding , $ from_encoding ) ; $ newObject -> $ key = $ value ; } return $ newObject ; } else { $ obj_vars = get_object_vars ( $ var ) ; foreach ( $ obj_vars as $ key => $ value ) { $ value = self :: convertEncodingRecursive ( $ value , $ to_encoding , $ from_encoding ) ; $ newObject -> $ key = $ value ; } return $ newObject ; } } break ; } return $ var ; } | convert encoding recursively |
21,883 | protected function authentication ( ) : bool { if ( $ this -> url === null ) { throw new InvalidArgumentException ( 'Project URL is not set' ) ; } $ payload = file_get_contents ( 'php://input' ) ; switch ( $ this -> type ) { case 'gitlab' : $ authenticated = $ this -> authenticateGitlab ( $ payload ) ; break ; case 'github' : $ authenticated = $ this -> authenticateGithub ( $ payload ) ; break ; case 'bitbucket' : $ authenticated = $ this -> authenticateBitbucket ( $ payload ) ; break ; default : throw new InvalidArgumentException ( "Unsupported type '$this->type'" ) ; } if ( $ authenticated ) { return true ; } else { Debugger :: log ( 'Unknown access from ' . $ this -> request -> getRemoteHost ( ) . '(' . $ this -> request -> getRemoteAddress ( ) . ')' , 'deploy' ) ; return false ; } } | Je povolen pristup |
21,884 | private function parseReferences ( $ name ) : string { if ( preg_match_all ( '/\$\{(.*[a-z\.0-9])\}/si' , $ name , $ results , PREG_SET_ORDER ) ) { foreach ( $ results as $ match ) { $ replace = $ match [ 0 ] ; $ key = $ match [ 1 ] ; if ( strpos ( $ key , '.' ) === 0 ) { $ key = substr ( $ name , 0 , strpos ( $ name , $ replace ) - 1 ) . $ key ; } $ value = $ this -> get ( $ key ) ; if ( $ value === null || $ value === '' || $ value === false ) { throw new InvalidArgumentException ( $ key . ' replacement for ' . $ name . ' must not be null or empty' ) ; } $ name = str_replace ( $ replace , $ value , $ name ) ; } } return $ name ; } | Parse any references in the name |
21,885 | public static function fromDirectory ( string $ directory , string $ suffix = '.php' ) : ConfigInterface { $ config = [ ] ; foreach ( new \ DirectoryIterator ( $ directory ) as $ file ) { if ( $ file -> isDot ( ) ) { continue ; } $ suffixLen = strlen ( $ suffix ) ; if ( ! ( substr ( $ file -> getFilename ( ) , - $ suffixLen ) === $ suffix ) ) { continue ; } $ namespace = substr ( $ file -> getFilename ( ) , 0 , - ( $ suffixLen ) ) ; $ config [ $ namespace ] = new File ( $ file -> getPathname ( ) ) ; } return new static ( $ config ) ; } | Fetch the config from the directory |
21,886 | public static function fromEnvironment ( EnvironmentInterface $ environment , string $ directory = './config' ) : ConfigInterface { $ name = $ environment -> name ( ) ; $ projectRoot = $ environment -> projectRoot ( ) ; $ directory = ( strpos ( $ directory , '/' ) === 0 ? $ directory : $ projectRoot . substr ( $ directory , 1 ) ) ; $ config = [ ] ; foreach ( new \ DirectoryIterator ( $ directory ) as $ file ) { if ( $ file -> isDot ( ) || $ file -> getExtension ( ) !== 'php' ) { continue ; } $ parts = explode ( '.' , $ file -> getFilename ( ) ) ; $ namespace = $ parts [ 0 ] ; $ fileEnvironment = ( count ( $ parts ) === 3 ? $ parts [ 1 ] : EnvironmentInterface :: ENV_PRODUCTION ) ; if ( $ fileEnvironment === EnvironmentInterface :: ENV_PRODUCTION && ! array_key_exists ( $ namespace , $ config ) ) { $ config [ $ namespace ] = new File ( $ file -> getPathname ( ) ) ; } if ( $ fileEnvironment === $ name ) { $ config [ $ namespace ] = new File ( $ file -> getPathname ( ) ) ; } } $ config [ 'environment' ] = [ 'name' => $ name , 'projectRoot' => $ projectRoot , ] ; return new static ( $ config ) ; } | From the environment object |
21,887 | public function type ( ) : string { if ( is_string ( $ this -> value ) ) { return $ this -> string ( $ this -> value ) ; } if ( is_array ( $ this -> value ) ) { return $ this -> array ( $ this -> value ) ; } if ( is_object ( $ this -> value ) ) { return $ this -> object ( $ this -> value ) ; } return gettype ( $ this -> value ) ; } | Return a detailled string representation of the value . |
21,888 | public function withHtml ( string $ name , string $ label , string $ containerElementCssSelector = null ) { $ this -> contentGroup -> htmlAreas [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'selector' => $ containerElementCssSelector , 'order' => $ this -> order ++ , ] ; return $ this ; } | Defines a HTML field . |
21,889 | public function withText ( string $ name , string $ label ) { $ this -> contentGroup -> textAreas [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'order' => $ this -> order ++ ] ; return $ this ; } | Defines a text field . |
21,890 | public function withFile ( string $ name , string $ label , array $ allowedExtensions = null ) { $ this -> contentGroup -> fileAreas [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'allowed_extensions' => $ allowedExtensions , 'order' => $ this -> order ++ ] ; return $ this ; } | Defines a file upload field . |
21,891 | public function withTextFromOptions ( string $ name , string $ label , array $ valueLabelMap ) { $ this -> contentGroup -> textAreas [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'options' => $ valueLabelMap , 'order' => $ this -> order ++ ] ; return $ this ; } | Defines a text field that must contain a value from one of the supplied options . |
21,892 | public function withMetadata ( string $ name , string $ label ) { $ this -> contentGroup -> metadata [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'order' => $ this -> order ++ ] ; return $ this ; } | Defines a metadata field . |
21,893 | public function withArrayOf ( string $ name , string $ label , callable $ elementContentDefinitionCallback ) { $ definition = new ContentGroupDefinition ( '__element__' , $ name ) ; $ elementContentDefinitionCallback ( new self ( $ definition ) ) ; $ this -> contentGroup -> nestedArrayContentGroups [ $ name ] = [ 'name' => $ name , 'label' => $ label , 'order' => $ this -> order ++ , 'definition' => $ definition , ] ; return $ this ; } | Defines an array field . |
21,894 | protected function doClear ( $ queue , $ state ) { try { while ( $ item = $ this -> pheanstalk -> { 'peek' . $ state } ( $ queue ) ) { $ this -> pheanstalk -> delete ( $ item ) ; } } catch ( ServerException $ e ) { } return true ; } | Clears a specific state |
21,895 | public static function checkPermission ( array $ config , $ registro = 0 , $ action = "" ) { if ( $ action == "" ) { $ action = substr ( request ( ) -> route ( ) -> getName ( ) , stripos ( request ( ) -> route ( ) -> getName ( ) , "::" ) + 2 ) ; } $ resultado = true ; $ general = false ; if ( isset ( $ config [ 'permissions' ] ) ) { if ( isset ( $ config [ 'permissions' ] [ $ action ] ) ) { $ callback = $ config [ 'permissions' ] [ $ action ] ; } elseif ( isset ( $ config [ 'permissions' ] [ 'default' ] ) ) { $ callback = $ config [ 'permissions' ] [ 'default' ] ; } else { $ general = true ; } } else { $ general = true ; } if ( $ general ) { $ callback = config ( 'sirgrimorum.crudgenerator.permission' ) ; } if ( is_callable ( $ callback ) ) { if ( $ registro > 0 ) { $ objModelo = $ config [ 'modelo' ] :: find ( $ registro ) ; $ resultado = ( bool ) $ callback ( $ objModelo ) ; } else { $ resultado = ( bool ) $ callback ( ) ; } } else { $ resultado = ( bool ) $ callback ; } return $ resultado ; } | Evaluate the permissions callbacks in the configuration array |
21,896 | private static function evaluateFilterWithSingleQuery ( $ registro , $ query , $ attri ) { $ contiene = false ; if ( stripos ( $ query , "*%" ) !== false ) { $ contiene = true ; $ query = str_replace ( "*%" , "" , $ query ) ; } if ( ( $ numArgs = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isFunction ( $ registro , $ attri ) ) !== false ) { if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isJsonString ( $ query ) ) { $ queryArr = json_decode ( $ query , true ) ; } else { $ queryArr = [ $ query ] ; } $ result = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: callFunction ( $ registro , $ attri , $ queryArr , $ numArgs ) ; if ( $ result === false || $ result === null ) { return false ; } else { $ queryObj = array_pop ( $ queryArr ) ; if ( $ result != $ queryObj ) { return false ; } } } elseif ( is_string ( $ registro -> { $ attri } ) ) { if ( $ contiene ) { if ( stripos ( $ registro -> { $ attri } , $ query ) === false ) { return false ; } } else { if ( $ registro -> { $ attri } != $ query ) { return false ; } } } else { if ( ( string ) $ registro -> { $ attri } != $ query ) { return false ; } } return true ; } | Filter an object of a model with a single query . It will use AND operation . |
21,897 | private static function filterWithQuery ( $ registros , $ config , $ datos = [ ] , $ orOperation = "_or" , $ queryStr = "_q" , $ attriStr = "_a" , $ aByAStr = "_aByA" ) { if ( count ( $ datos ) == 0 ) { $ datos = request ( ) -> all ( ) ; } if ( ! is_bool ( $ orOperation ) ) { if ( isset ( $ datos [ $ orOperation ] ) ) { $ orOperation = ! ( $ datos [ $ orOperation ] === 'false' ) ; } else { $ orOperation = true ; } } if ( isset ( $ datos [ $ queryStr ] ) ) { $ query = $ datos [ $ queryStr ] ; if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isJsonString ( $ query ) ) { $ query = json_decode ( $ query , true ) ; } elseif ( stripos ( $ query , "|" ) ) { $ query = explode ( "|" , $ query ) ; } if ( isset ( $ datos [ $ attriStr ] ) ) { $ attri = $ datos [ $ attriStr ] ; if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: isJsonString ( $ attri ) ) { $ attri = json_decode ( $ attri , true ) ; } elseif ( stripos ( $ attri , "|" ) ) { $ attri = explode ( "|" , $ attri ) ; } } else { $ attri = $ config [ 'nombre' ] ; } $ fbf = isset ( $ datos [ $ aByAStr ] ) ; $ registros = $ registros -> filter ( function ( $ registro ) use ( $ query , $ attri , $ fbf , $ orOperation ) { return \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: evaluateFilter ( $ registro , $ query , $ attri , $ orOperation , $ fbf ) ; } ) ; } return $ registros ; } | Filter a collection of object models using a query an attribute sets in an array . |
21,898 | public static function syncHasMany ( $ model , $ campo , $ children_items , $ config ) { $ children = $ model -> { $ campo } ; $ children_items = collect ( $ children_items ) ; $ deleted_ids = $ children -> filter ( function ( $ child ) use ( $ children_items ) { return empty ( $ children_items -> where ( $ config [ $ campo ] [ 'id' ] , $ child -> $ config [ $ campo ] [ 'id' ] ) -> first ( ) ) ; } ) -> map ( function ( $ child ) { $ id = $ child -> id ; $ child -> delete ( ) ; return $ id ; } ) ; $ attachments = $ children_items -> filter ( function ( $ children_item ) { return empty ( $ children_item -> $ config [ $ campo ] [ 'id' ] ) ; } ) -> map ( function ( $ children_item ) use ( $ deleted_ids ) { $ children_item -> $ config [ $ campo ] [ 'id' ] = $ deleted_ids -> pop ( ) ; return new $ config [ $ campo ] [ 'modelo' ] ( $ children_item ) ; } ) ; $ model -> { $ campo } ( ) -> saveMany ( $ attachments ) ; } | Sync a HasMany relationsihp |
21,899 | public static function validateModel ( array $ config , \ Illuminate \ Http \ Request $ request = null ) { if ( is_null ( $ request ) ) { $ request = request ( ) ; } $ rules = [ ] ; $ modeloM = class_basename ( $ config [ "modelo" ] ) ; $ modelo = strtolower ( $ modeloM ) ; if ( isset ( $ config [ 'rules' ] ) ) { if ( is_array ( $ config [ 'rules' ] ) ) { $ rules = $ config [ 'rules' ] ; } } if ( count ( $ rules ) == 0 ) { $ objModelo = new $ config [ 'modelo' ] ; if ( isset ( $ objModelo -> rules ) ) { if ( is_array ( $ objModelo -> rules ) ) { $ rules = $ objModelo -> rules ; } } } $ auxIdCambio = $ request -> get ( $ config [ "id" ] ) ; $ rules = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: translateArray ( $ rules , ":model" , function ( $ string ) use ( $ auxIdCambio ) { return $ auxIdCambio ; } , "Id" ) ; if ( count ( $ rules ) > 0 ) { $ customAttributes = [ ] ; foreach ( $ rules as $ field => $ datos ) { if ( array_has ( $ config , "campos." . $ field . ".label" ) ) { $ customAttributes [ $ field ] = array_get ( $ config , "campos." . $ field . ".label" ) ; } } $ error_messages = [ ] ; if ( isset ( $ config [ 'error_messages' ] ) ) { if ( is_array ( $ config [ 'error_messages' ] ) ) { $ error_messages = $ config [ 'error_messages' ] ; } } if ( count ( $ error_messages ) == 0 ) { $ objModelo = new $ config [ 'modelo' ] ; if ( isset ( $ objModelo -> error_messages ) ) { if ( is_array ( $ objModelo -> error_messages ) ) { $ error_messages = $ objModelo -> error_messages ; } } } $ error_messages = array_merge ( trans ( "crudgenerator::admin.error_messages" ) , $ error_messages ) ; $ validator = \ Illuminate \ Support \ Facades \ Validator :: make ( $ request -> all ( ) , $ rules , $ error_messages , $ customAttributes ) ; return $ validator ; } return false ; } | Runs a validation of a request based on a model and its configuration array |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.