idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
34,800 | protected function registerFrontendRoutes ( Router $ router ) { $ router -> get ( '/' , 'index' , 'FluxBB\Web\Controllers\ForumController@index' ) ; $ router -> get ( '/categories{slug:(?:/[A-Za-z0-9/]*)?}conversations/new' , 'new_topic' , 'FluxBB\Web\Controllers\ConversationController@createForm' ) ; $ router -> post ( '/categories{slug:(?:/[A-Za-z0-9/]*)?}conversations/new' , 'new_topic_handler' , 'FluxBB\Web\Controllers\ConversationController@create' ) ; $ router -> get ( '/categories{slug:(?:/[A-Za-z0-9/]*)?}' , 'category' , 'FluxBB\Web\Controllers\ForumController@category' ) ; $ router -> get ( '/conversations/{id}' , 'conversation' , 'FluxBB\Web\Controllers\ForumController@conversation' ) ; $ router -> get ( '/post/{id}' , 'viewpost' , 'FluxBB\Web\Controllers\ForumController@post' ) ; $ router -> get ( '/register' , 'register' , 'FluxBB\Web\Controllers\AuthController@registerForm' ) ; $ router -> post ( '/register' , 'handle_registration' , 'FluxBB\Web\Controllers\AuthController@register' ) ; $ router -> get ( '/login' , 'login' , 'FluxBB\Web\Controllers\AuthController@loginForm' ) ; $ router -> post ( '/login' , 'handle_login' , 'FluxBB\Web\Controllers\AuthController@login' ) ; $ router -> get ( '/logout' , 'logout' , 'FluxBB\Web\Controllers\AuthController@logout' ) ; $ router -> get ( '/reset_password' , 'reset_password' , 'FluxBB\Web\Controllers\AuthController@resetForm' ) ; $ router -> get ( '/profile/{id}' , 'profile' , 'FluxBB\Web\Controllers\UserController@profile' ) ; $ router -> get ( '/users' , 'userlist' , '' ) ; $ router -> get ( '/search' , 'search' , '' ) ; $ router -> get ( '/post/{id}/edit' , 'post_edit' , 'FluxBB\Web\Controllers\PostController@editForm' ) ; $ router -> post ( '/post/{id}/edit' , 'post_edit_handler' , 'FluxBB\Web\Controllers\PostController@edit' ) ; $ router -> get ( '/post/{id}/report' , 'post_report' , 'FluxBB\Web\Controllers\PostController@reportForm' ) ; $ router -> get ( '/post/{id}/delete' , 'post_delete' , 'FluxBB\Web\Controllers\PostController@deleteForm' ) ; $ router -> get ( '/post/{id}/quote' , 'post_quote' , '' ) ; $ router -> post ( '/topic/{id}/reply' , 'reply_handler' , 'FluxBB\Web\Controllers\PostController@create' ) ; $ router -> post ( '/topic/{id}/subscribe' , 'topic_subscribe' , 'FluxBB\Web\Controllers\ConversationController@subscribe' ) ; $ router -> post ( '/topic/{id}/unsubscribe' , 'topic_unsubscribe' , 'FluxBB\Web\Controllers\ConversationController@unsubscribe' ) ; $ router -> get ( '/admin' , 'admin.index' , 'FluxBB\Web\Controllers\Admin\DashboardController@index' ) ; $ router -> get ( '/admin/settings' , 'admin.settings.global' , 'FluxBB\Web\Controllers\Admin\SettingsController@index' ) ; $ router -> get ( '/admin/settings/email' , 'admin.settings.email' , 'FluxBB\Web\Controllers\Admin\SettingsController@email' ) ; $ router -> get ( '/admin/settings/maintenance' , 'admin.settings.maintenance' , 'FluxBB\Web\Controllers\Admin\SettingsController@maintenance' ) ; $ router -> get ( '/admin/dashboard/stats' , 'admin.dashboard.stats' , 'FluxBB\Web\Controllers\Admin\DashboardController@stats' ) ; $ router -> get ( '/admin/dashboard/updates' , 'admin.dashboard.updates' , 'FluxBB\Web\Controllers\Admin\DashboardController@updates' ) ; $ router -> get ( '/admin/dashboard/reports' , 'admin.dashboard.reports' , 'FluxBB\Web\Controllers\Admin\DashboardController@reports' ) ; $ router -> get ( '/admin/groups' , 'admin.groups.index' , '' ) ; $ router -> get ( '/admin/groups/{id}/edit' , 'admin.groups.edit' , '' ) ; $ router -> get ( '/admin/groups/{id}/delete' , 'admin.groups.delete' , '' ) ; $ router -> get ( '/admin/categories' , 'admin.categories.index' , 'FluxBB\Web\Controllers\Admin\CategoriesController@index' ) ; } | Register the frontend routes . |
34,801 | public function register ( PimpleContainer $ app ) { $ app [ 'capsule.connectionDefault' ] = [ 'driver' => 'mysql' , 'host' => 'localhost' , 'port' => 3306 , 'database' => null , 'username' => null , 'password' => null , 'charset' => 'utf8' , 'collation' => 'utf8_unicode_ci' , 'prefix' => '' , 'strict' => false , 'engine' => null , ] ; $ app [ 'capsule.connections' ] = [ ] ; $ app [ 'capsule.container' ] = function ( PimpleContainer $ app ) { return new CapsuleContainer ( ) ; } ; $ app [ 'capsule.dispatcher' ] = function ( PimpleContainer $ app ) { return new Dispatcher ( $ app [ 'capsule.container' ] ) ; } ; $ app [ 'capsule.options' ] = [ 'setAsGlobal' => true , 'bootEloquent' => true , 'enableQueryLog' => true , ] ; $ app [ 'capsule' ] = function ( PimpleContainer $ app ) { $ capsule = new Capsule ( $ app [ 'capsule.container' ] ) ; if ( ! empty ( $ app [ 'capsule.dispatcher' ] ) ) { $ capsule -> setEventDispatcher ( $ app [ 'capsule.dispatcher' ] ) ; } foreach ( $ app [ 'capsule.connections' ] as $ connectionName => $ connectionConfig ) { $ connectionConfig += $ app [ 'capsule.connectionDefault' ] ; $ capsule -> addConnection ( $ connectionConfig , $ connectionName ) ; if ( $ app [ 'capsule.options' ] [ 'enableQueryLog' ] ) { $ capsule -> getConnection ( $ connectionName ) -> enableQueryLog ( ) ; } } if ( ! empty ( $ app [ 'capsule.options' ] [ 'setAsGlobal' ] ) ) { $ capsule -> setAsGlobal ( ) ; } if ( ! empty ( $ app [ 'capsule.options' ] [ 'bootEloquent' ] ) ) { $ capsule -> bootEloquent ( ) ; } return $ capsule ; } ; } | Register the Capsule Service . |
34,802 | public function boot ( Application $ app ) { if ( $ app [ 'capsule.options' ] [ 'bootEloquent' ] ) { $ app -> before ( function ( ) use ( $ app ) { $ app [ 'capsule' ] ; } , Application :: EARLY_EVENT ) ; } } | Boot the Capsule Service . |
34,803 | public function sync ( $ name , array $ ids , $ delete = true ) { $ relationClass = $ this -> owner -> getRelation ( $ name ) -> modelClass ; $ current = $ this -> getLinkedIds ( $ name ) ; $ unlink = array_diff ( $ current , $ ids ) ; $ link = array_diff ( $ ids , $ current ) ; $ models = ! empty ( $ unlink ) ? $ relationClass :: findAll ( $ unlink ) : [ ] ; foreach ( $ models as $ model ) { $ this -> owner -> unlink ( $ name , $ model , $ delete ) ; } $ models = ! empty ( $ link ) ? $ relationClass :: findAll ( $ link ) : [ ] ; foreach ( $ models as $ model ) { $ this -> owner -> link ( $ name , $ model ) ; } $ this -> afterSync ( $ name ) ; return [ 'linked' => $ link , 'unlinked' => $ unlink ] ; } | Sync the relationship with a list of IDs |
34,804 | protected function transfer ( $ objectOrArray ) : array { $ data = [ ] ; $ errors = [ ] ; if ( \ is_object ( $ objectOrArray ) ) { $ errors = $ this -> dtService -> transfer ( $ objectOrArray , $ data , $ this -> mapper ) ; } elseif ( \ is_array ( $ objectOrArray ) ) { foreach ( $ objectOrArray as $ index => $ itemObjectOrArray ) { [ $ data [ $ index ] , $ itemErrors ] = $ this -> transfer ( $ itemObjectOrArray ) ; if ( ! empty ( $ itemErrors ) ) { $ errors [ $ index ] = $ itemErrors ; } } } else { $ data = $ objectOrArray ; } return [ $ data , $ errors ] ; } | Tries to transfer data from specified object or array to multi - dimensional scalar array |
34,805 | protected function addDatabaseOptions ( ) { $ this -> addOption ( 'database-host' , 'H' , InputOption :: VALUE_REQUIRED , 'Name / IP of the host where the database is running.' ) -> addOption ( 'database-user' , 'u' , InputOption :: VALUE_REQUIRED , 'Username to access the database.' ) -> addOption ( 'database-pass' , 'p' , InputOption :: VALUE_REQUIRED , 'Password to access the database.' ) -> addOption ( 'database-port' , 'P' , InputOption :: VALUE_REQUIRED , 'Port where the database is listen.' ) -> addOption ( 'database-name' , 'N' , InputOption :: VALUE_REQUIRED , 'Name of the database which should be used.' ) ; } | Adds several options for database connections to the command . |
34,806 | protected function loadRelationship ( ) { $ field_parameters = $ this -> getFieldParameters ( ) ; $ query = $ this -> buildRelationshipQuery ( $ field_parameters ) ; if ( ! $ query ) { throw new Exception ( 'Could not build query from field parameters' ) ; } if ( method_exists ( $ this , 'amendRelationshipQuery' ) ) { $ query = $ this -> amendRelationshipQuery ( $ query ) ; } return $ this -> getRelationshipArray ( $ query , $ field_parameters ) ; } | Loads array from database using field parameters specified . |
34,807 | protected function buildRelationshipQuery ( $ field_parameters ) { if ( isset ( $ field_parameters [ 'table' ] ) && ! $ this -> onlyQueryFrom == 'model' ) { $ table = $ field_parameters [ 'table' ] ; return DB :: table ( $ table ) ; } elseif ( isset ( $ field_parameters [ 'model' ] ) && ! $ this -> onlyQueryFrom == 'table' ) { $ class = $ field_parameters [ 'model' ] ; $ model = new $ class ; if ( $ model instanceof Model ) { return $ model ; } throw new Exception ( 'Class \'' . $ class . '\' must be an isntance of \'' . Model :: class . '\'' ) ; } throw new Exception ( 'No valid query to build from field parameters' ) ; } | Builds base query for relationship using field parameters specified . |
34,808 | public static function color ( $ text , $ foreground , $ background = null ) { $ foreground = self :: $ colors [ $ foreground ] ; $ code = "\x03" . $ foreground ; if ( $ background !== null ) { $ background = self :: $ colors [ $ background ] ; $ code .= ',' . $ background ; } return $ code . $ text . "\x03" ; } | Applies colors to the text |
34,809 | public static function parse ( $ msg ) { $ msg = preg_replace_callback ( '/<(\/)?(.+?)(?: (.+?))?>/' , function ( $ matches ) { $ tag = $ matches [ 2 ] ; $ closingTag = $ matches [ 1 ] == '/' ; $ attributes = isset ( $ matches [ 3 ] ) ? $ matches [ 3 ] : null ; if ( isset ( self :: $ tags [ $ tag ] ) ) { return self :: $ formatting [ self :: $ tags [ $ tag ] ] ; } else if ( $ tag == 'color' ) { if ( $ closingTag ) { return "\x03" ; } else if ( ! $ closingTag && ! $ attributes ) { throw new Exception ( '<color> has no attributes set.' ) ; } $ colors = [ ] ; if ( 0 === preg_match ( '/fg=["|\'](.+?)["|\'](?: bg=["|\'](.+?)["|\'])?/' , $ attributes , $ colors ) ) { throw new Exception ( '<color> has invalid attributes set.' ) ; } $ fg = $ colors [ 1 ] ; if ( isset ( self :: $ colors [ $ fg ] ) ) { $ fg = self :: $ colors [ $ fg ] ; } else { throw new Exception ( 'Invalid foreground color "' . $ fg . '".' ) ; } if ( isset ( $ colors [ 2 ] ) ) { $ bg = $ colors [ 2 ] ; if ( isset ( self :: $ colors [ $ bg ] ) ) { $ bg = ',' . self :: $ colors [ $ bg ] ; } else { throw new Exception ( 'Invalid background color "' . $ bg . '".' ) ; } } else { $ bg = '' ; } return "\x03" . $ fg . $ bg ; } else { return null ; } } , $ msg ) ; return $ msg ; } | Parses and returns IRC formatted text |
34,810 | protected function ascertainMetadata ( string $ handlerName , ? string $ httpMethod = null ) : void { if ( empty ( $ this -> handlerClassNames [ $ handlerName ] ) ) { try { $ this -> loadMetadata ( $ handlerName ) ; $ this -> needCacheUpdate = true ; } catch ( \ Throwable $ e ) { [ $ this -> handlerClassNames , $ this -> routes , $ this -> handlerMethodNames , $ this -> consumers , $ this -> attributes , $ this -> producers ] = [ [ ] , [ ] , [ ] , [ ] , [ ] , [ ] ] ; throw $ e ; } } if ( ( $ httpMethod !== null ) && empty ( $ this -> handlerMethodNames [ $ this -> handlerClassNames [ $ handlerName ] ] [ $ httpMethod ] ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Handler %s is not configured to handle %s-method.' , $ handlerName , $ httpMethod ) ) ; } } | Ensures that metadata for specified handler name was loaded and optionally checks if this metadata contains information about specified HTTP method |
34,811 | public function saved ( BlockTypeInterface $ blockType ) { if ( $ blockType -> isDirty ( 'is_shared' ) ) { DynamicBlock :: fromTable ( $ blockType -> getAttribute ( 'identifier' ) ) -> update ( [ 'is_shared' => $ blockType -> getAttribute ( 'is_shared' ) ] ) ; } if ( $ blockType -> isDirty ( 'identifier' ) ) { DynamicBlock :: fromTable ( $ blockType -> getAttribute ( 'identifier' ) ) -> update ( [ 'is_shared' => $ blockType -> getAttribute ( 'is_shared' ) ] ) ; } if ( ! $ blockType -> dynamicTableExists ( ) ) { $ blockType -> createTable ( ) ; } } | Listen to the Block saved event . |
34,812 | public function getFieldTypes ( ) { return array_map ( function ( $ value ) { $ class_name = class_basename ( $ value ) ; return ucfirst ( strtolower ( preg_replace ( '/\B([A-Z])/' , ' $1' , $ class_name ) ) ) ; } , $ this -> getRegistrar ( ) -> getRegisteredFields ( ) ) ; } | Returns an array of registered fields keyed by field slug values in readable format . |
34,813 | public function field ( $ field , $ prefix = null ) { if ( is_array ( $ field ) ) { $ field = new Field ( $ field ) ; } if ( ! $ field instanceof FieldInterface ) { throw new Exception ( 'Field must implement interface ' . FieldInterface :: class . ' or be an array.' ) ; } $ formField = $ this -> getRegistrar ( ) -> resolve ( $ field ) ; if ( $ prefix ) { $ formField -> setPrefix ( $ prefix ) ; } return $ formField ; } | Instantiates a new FormField from our Field model or array . |
34,814 | public function buildJsParams ( $ parameters ) { if ( ! $ parameters ) { return '' ; } $ extractedParams = $ this -> extractJsFunctions ( $ parameters ) ; $ json_parameters = json_encode ( $ extractedParams [ 'parameters' ] , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ; $ json_parameters = str_replace ( $ extractedParams [ 'replacements' ] , $ extractedParams [ 'values' ] , $ json_parameters ) ; return trim ( $ json_parameters , '{}' ) ; } | Formats a JSON string to be pasted into our Javascript . |
34,815 | protected function updateTokenExpiry ( ) { \ DB :: table ( $ this -> tokenTable ) -> where ( 'token' , $ this -> getToken ( ) ) -> update ( [ $ this -> getTokenColumn ( 'expire' ) => Carbon :: parse ( 'now ' . $ this -> getTokenLifetime ( ) ) , ] ) ; } | Update token s expire time . |
34,816 | private function generateQuery ( ) { return $ this -> getUserModel ( ) -> select ( [ $ this -> getUserTable ( ) . '.*' ] ) -> join ( $ this -> getTokenTable ( ) , $ this -> getTokenColumn ( 'user_id' ) , '=' , $ this -> getUserTable ( ) . '.' . $ this -> primaryKey ) -> where ( $ this -> getTokenColumn ( 'token' ) , '=' , $ this -> getToken ( ) ) ; } | Generate base query used to retrieve user by token and update an existing tokens expire time . |
34,817 | protected function doTransform ( Matrix $ mA , $ extra = null ) { $ this -> assertMatrixIsComplete ( $ mA ) ; if ( $ mA -> is ( 'empty' ) ) { return new Matrix ( array ( ) ) ; } $ transposed = array ( ) ; $ data = $ mA -> toArray ( ) ; foreach ( $ data as $ rowKey => $ row ) { if ( is_array ( $ row ) && ! empty ( $ row ) ) { foreach ( $ row as $ columnKey => $ element ) { $ transposed [ $ columnKey ] [ $ rowKey ] = $ element ; } } } return new Matrix ( $ transposed ) ; } | Transpose the matrix |
34,818 | protected function mergeConfigRecursivelyFrom ( $ path , $ key ) { $ config = $ this -> app [ 'config' ] -> get ( $ key , [ ] ) ; $ this -> app [ 'config' ] -> set ( $ key , array_replace_recursive ( require $ path , $ config ) ) ; } | Merge the given configuration with the existing configuration recursively . |
34,819 | public function verify ( ) { $ phpversion = phpversion ( ) ; $ extensions = get_loaded_extensions ( ) ; $ ini = array_only ( ini_get_all ( ) , [ 'max_execution_time' , 'max_file_uploads' , 'max_input_time' , 'post_max_size' , 'upload_max_filesize' ] ) ; $ return = [ 'version' => $ phpversion , 'transports' => implode ( ', ' , stream_get_transports ( ) ) , 'filters' => implode ( ', ' , stream_get_filters ( ) ) , 'doc_root' => getcwd ( ) , 'extensions' => $ extensions , 'ini' => $ ini , ] ; $ this -> configuration = $ return ; $ this -> validate ( $ return ) ; return $ return ; } | verify server environment |
34,820 | protected function validate ( array & $ data ) { $ this -> validateVersion ( ) ; $ this -> validateExtensions ( ) ; $ this -> validateIni ( ) ; $ data = array_merge ( $ data , [ 'messages' => $ this -> messages ] ) ; return $ data ; } | validates server environment |
34,821 | protected function validateIni ( ) { $ data = $ this -> configuration ; if ( ! isset ( $ data [ 'ini' ] ) ) { array_push ( $ this -> messages , [ 'error' , trans ( 'Unable to read php ini configuration. It is recommended to contact with your provider.' ) ] ) ; return $ this ; } if ( empty ( self :: $ iniRequirements ) ) { return $ this ; } $ ini = $ data [ 'ini' ] ; foreach ( self :: $ iniRequirements as $ name => $ value ) { if ( ! isset ( $ ini [ $ name ] ) ) { array_push ( $ this -> messages , [ 'error' , sprintf ( 'Option (%s) not exists in php ini configuration.' , $ name ) ] ) ; } else { if ( $ ini [ $ name ] [ 'global_value' ] != $ value ) { array_push ( $ this -> messages , [ 'warning' , sprintf ( 'Option (%s) is not same with minimal requirement. Found %s expected %s.' , $ name , $ ini [ $ name ] [ 'global_value' ] , $ value ) ] ) ; } } } return $ this ; } | php ini validator |
34,822 | protected function validateExtensions ( ) { $ data = $ this -> configuration ; if ( ! isset ( $ data [ 'extensions' ] ) ) { array_push ( $ this -> messages , [ 'error' , trans ( 'Unable to read php extensions. It is recommended to contact with your provider.' ) ] ) ; return $ this ; } if ( empty ( self :: $ importantExtensions ) ) { return $ this ; } $ extensions = $ data [ 'extensions' ] ; foreach ( self :: $ importantExtensions as $ extension ) { if ( ! in_array ( $ extension , $ extensions ) ) { array_push ( $ this -> messages , [ 'warning' , sprintf ( 'Unable to find %s php extension. Please install extension on your server otherwise system may work not properly.' , $ extension ) ] ) ; } } return $ this ; } | php extensions validator |
34,823 | protected function validateVersion ( ) { $ data = $ this -> configuration ; $ matches = [ ] ; if ( ! isset ( $ data [ 'version' ] ) or ! preg_match ( '/^([0-9]).*$/i' , $ data [ 'version' ] , $ matches ) ) { array_push ( $ this -> messages , [ 'error' , trans ( 'Unable to read php version. It is recommended to contact with your provider.' ) ] ) ; return $ this ; } if ( ! isset ( $ matches [ 1 ] ) ) { array_push ( $ this -> messages , [ 'error' , trans ( 'Unable to read php primary version. It is recommended to contact with your provider.' ) ] ) ; } if ( ( int ) $ matches [ 1 ] < 7 ) { array_push ( $ this -> messages , [ 'warning' , sprintf ( 'Current PHP Version (%s) does not match the minimum system requirements. It is recommended to use PHP Version 7.' , $ data [ 'version' ] ) ] ) ; } if ( ! preg_match ( '/^([0-9]).([0-9]).([0-9])$/' , $ data [ 'version' ] ) ) { array_push ( $ this -> messages , [ 'warning' , sprintf ( 'Current PHP Version (%s) is not stable. Use only stable releases.' , $ data [ 'version' ] ) ] ) ; } return $ this ; } | php version validator |
34,824 | public function isExcludedPath ( $ excludedPaths ) { $ request = new HttpRequest ( ) ; $ basePath = $ request -> getQuery ( '_url' ) ; if ( is_null ( $ excludedPaths ) ) { $ excludedPaths = [ ] ; } elseif ( $ excludedPaths instanceof Config ) { $ excludedPaths = $ excludedPaths -> toArray ( ) ; } else { $ excludedPaths = ( array ) $ excludedPaths ; } foreach ( $ excludedPaths as $ key => $ value ) { if ( substr ( $ basePath , 0 , strlen ( $ value ) ) == $ value && $ value != '/' ) { return true ; } } return false ; } | check if path is excluded from middleware |
34,825 | public function prepareLinks ( ) { $ this [ Argument :: LINKS ] = $ this -> doReplacements ( $ this [ Argument :: LINKS ] ) ; return $ this ; } | Prepare the labels to be passed into the CPT registration . |
34,826 | public function prepareMessages ( ) { $ this [ Argument :: MESSAGES ] = $ this -> doReplacements ( $ this [ Argument :: MESSAGES ] ) ; return $ this ; } | Prepare the messages to be passed into the CPT registration . |
34,827 | public function collectChildren ( ) { if ( $ this -> hasChildrenRelation ( ) ) { $ result = $ this -> getRelation ( $ this -> getChildrenRelationIndex ( ) ) ; } else { $ result = $ this -> children ( ) ; } return $ result ; } | Retrieves query builder for all children of a model . |
34,828 | public function deleteSubtree ( $ withSelf = false , $ forceDelete = false ) { $ action = ( $ forceDelete === true ? 'forceDelete' : 'delete' ) ; $ ids = $ this -> joinClosureBy ( 'descendant' , $ withSelf ) -> pluck ( $ this -> getKeyName ( ) ) ; if ( $ forceDelete ) { $ this -> closure -> whereIn ( $ this -> closure -> getDescendantColumn ( ) , $ ids ) -> delete ( ) ; } $ this -> whereIn ( $ this -> getKeyName ( ) , $ ids ) -> $ action ( ) ; } | Deletes a subtree from database . |
34,829 | public function validate ( $ data = null , $ entity = null ) { if ( is_null ( $ data ) ) { $ data = $ this -> getData ( ) ; } $ this -> data = $ data ; return ! count ( parent :: validate ( $ data , $ entity ) ) ; } | Validate a set of data according to a set of rules |
34,830 | protected function fixLinks ( $ result ) { if ( false === $ this -> replaceLinks ) { return $ result ; } $ isArray = false ; $ string = '' ; if ( is_array ( $ result ) ) { $ string = json_encode ( $ result , JSON_UNESCAPED_SLASHES ) ; $ isArray = true ; } elseif ( is_string ( $ result ) ) { $ string = $ result ; } $ myUri = Environment :: getURI ( ) ; $ allRws = Service :: whereType ( 'rws' ) -> whereIsActive ( 1 ) -> get ( ) -> all ( ) ; if ( ! empty ( $ allRws ) ) { foreach ( $ allRws as $ rws ) { $ config = $ rws -> getConfigAttribute ( ) ; $ baseUrl = trim ( array_get ( $ config , 'base_url' ) , '/' ) ; $ dfUrl = trim ( $ myUri , '/' ) . '/api/v2/' . $ rws -> name ; $ string = str_replace ( $ baseUrl , $ dfUrl , $ string ) ; } } return ( $ isArray ) ? json_decode ( $ string , true ) : $ string ; } | Replaces any hyper links referencing any DF remote web service s base url with the link to the corresponding DF service itself to ensure DF rws works as the gateway to all remote service calls . |
34,831 | protected function getValueChecker ( ) { return function ( $ a , $ b , ComparatorInterface $ comparator ) { $ exceptionMessage = 'Comparator (%s) does not support "%s"' ; $ error = null ; if ( ! $ comparator -> supports ( $ a ) ) { $ error = sprintf ( $ exceptionMessage , get_class ( $ comparator ) , gettype ( $ a ) ) ; } elseif ( ! $ comparator -> supports ( $ b ) ) { $ error = sprintf ( $ exceptionMessage , get_class ( $ comparator ) , gettype ( $ a ) ) ; } if ( $ error !== null ) { throw new \ RuntimeException ( $ error ) ; } } ; } | Returns a closure that validates values before passing them to the ComparatorInterface |
34,832 | protected function ensureValid ( array $ attributes ) { $ validation = $ this -> validation -> make ( $ attributes , $ this -> rules ( ) ) ; if ( $ validation -> fails ( ) ) { throw new ValidationFailed ( $ validation -> getMessageBag ( ) ) ; } return $ this ; } | Make sure the given attributes comply to our rules . |
34,833 | protected function ensureAllInRules ( array $ data ) { $ rules = $ this -> rules ( ) ; $ invalid = array_diff_key ( $ data , $ rules ) ; if ( ! empty ( $ invalid ) ) { throw new ValidationFailed ( new MessageBag ( [ 'Invalid keys found in request.' , ] ) ) ; } return $ this ; } | Make sure all of the keys of the given array exist in our ruleset . |
34,834 | protected function doTransform ( Matrix $ mA , $ extra = null ) { if ( is_null ( $ extra ) ) { throw new TransformationException ( 'Reflection plane not specified' ) ; } else { if ( ! array_key_exists ( $ extra , $ this -> reflectionMatrices ) ) { throw new TransformationException ( 'Reflection plane not supported' ) ; } } if ( $ mA -> is ( 'empty' ) || $ mA -> is ( 'singleitem' ) ) { return clone $ mA ; } $ this -> assertMatrixIsComplete ( $ mA ) ; return $ this -> reflect ( $ mA , $ this -> reflectionMatrices [ $ extra ] ) ; } | Reflect the matrix on a plane |
34,835 | protected function doTransform ( Matrix $ mA , $ extra = null ) { if ( $ mA -> is ( 'empty' ) ) { return new Matrix ( [ ] ) ; } $ this -> assertParameterIsArray ( $ extra , 'Second operand is not an array' ) ; if ( count ( $ extra ) != 2 ) { throw new MatrixException ( 'Second operand does not contain row and column' ) ; } $ row = intval ( $ extra [ 0 ] ) ; $ col = intval ( $ extra [ 1 ] ) ; $ size = $ mA -> rows ( ) ; if ( $ row < 1 || $ row > $ size ) { throw new MatrixException ( 'Row indicator out of bounds' ) ; } if ( $ col < 1 || $ col > $ size ) { throw new MatrixException ( 'Col indicator out of bounds' ) ; } $ fC = new Colreduce ( ) ; $ fR = new Rowreduce ( ) ; return $ fR ( $ fC ( $ mA , [ $ col ] ) , [ $ row ] ) ; } | Return cofactor matrix for a given vertice |
34,836 | public function register ( ) { $ this -> app -> bind ( Proxy :: class , function ( $ app ) { return new Proxy ( $ app [ 'config' ] -> all ( ) ) ; } ) ; $ this -> commands ( Cmd \ Backup :: class ) ; } | Register the phpbu commands . |
34,837 | public function get ( $ key = null ) { if ( is_null ( $ key ) ) { return $ this -> raw ( ) ; } return $ this -> collection -> get ( $ key ) ; } | Gets a property of the currently loaded locale . |
34,838 | public function set ( $ strings , $ locale = null ) { if ( is_array ( $ strings ) ) { return $ this -> setArray ( $ strings , $ locale ) ; } if ( is_dir ( $ strings ) ) { return $ this -> setDirectory ( $ strings ) ; } throw new UnableToSetException ( "We could not figure out how to set '$strings' " ) ; } | Set a source for the gicen locale . |
34,839 | public function setDirectory ( $ directory ) { $ directory = rtrim ( $ directory , "/" ) ; $ dir = opendir ( $ directory ) ; if ( $ dir === false ) { throw new UnableToSetException ( "Could not set '$directory'. It is not a directory!" ) ; } while ( ( $ file = readdir ( $ dir ) ) !== false ) { $ path = $ directory . '/' . $ file ; $ pathInfo = pathinfo ( $ path ) ; $ extension = strtolower ( $ pathInfo [ 'extension' ] ) ; $ filename = $ pathInfo [ 'filename' ] ; if ( $ extension == 'php' ) { $ strings = include $ path ; if ( is_array ( $ strings ) ) { $ this -> collection -> setArray ( $ strings , $ filename ) ; } } } return $ this ; } | Loads a bunch of files from a given directory as locales into the collection . |
34,840 | protected function setupAuthDriver ( Fieldset $ fieldset , AuthProviderService $ authProviderService , AuthProviderContract $ availableAuthDriver ) { $ attributes = [ 'id' => 'api-configuration-' . $ availableAuthDriver -> getName ( ) . '-driver' , 'class' => 'api-auths' ] ; $ isEnabled = $ authProviderService -> isDriverEnabled ( $ availableAuthDriver -> getName ( ) ) ; if ( $ isEnabled ) { $ attributes [ 'checked' ] = 'checked' ; } $ fieldset -> control ( 'input:checkbox' , '' ) -> label ( '<p><b>' . $ availableAuthDriver -> getLabel ( ) . '</b> - ' . $ availableAuthDriver -> getDescription ( ) . '</p>' ) -> value ( $ availableAuthDriver -> getName ( ) ) -> attributes ( $ attributes ) ; } | Creates form controls for every api provider |
34,841 | public function authenticateNotification ( $ rawPayload , $ provided_signature = null ) { if ( $ this -> getParameter ( 'secret' ) ) { $ calculated_signature = hash_hmac ( 'sha256' , $ rawPayload , $ this -> getParameter ( 'secret' ) ) ; if ( $ provided_signature != $ calculated_signature ) { return false ; } } return true ; } | helper function to verify the signature on the header of the file |
34,842 | public function stackScripts ( $ DistributionID = null , $ DistributionVendor = null , $ keywords = null ) { return $ this -> call ( 'avail.stackscripts' , [ 'DistributionID' => $ DistributionID , 'DistributionVendor' => $ DistributionVendor , 'keywords' => $ keywords , ] ) ; } | Returns a list of available public StackScripts . |
34,843 | public function buildRoutesOrder ( ) { $ comparePriority = function ( $ r1 , $ r2 ) { $ a = $ this -> getRoutePriority ( $ r1 ) ; $ b = $ this -> getRoutePriority ( $ r2 ) ; if ( $ a == $ b ) { return 0 ; } return ( $ a < $ b ) ? 1 : - 1 ; } ; uasort ( $ this -> allRoutes , $ comparePriority ) ; foreach ( array_keys ( $ this -> routes ) as $ method ) { uasort ( $ this -> routes [ $ method ] , $ comparePriority ) ; } return $ this ; } | Order routes by priority number . |
34,844 | public static function unexpectedEnd ( Input $ definition ) : self { $ pointer = self :: createPointerString ( $ definition -> getInput ( ) , $ definition -> getIndex ( ) ) ; return new self ( "Unexpected end of route:\n$pointer" ) ; } | Invalid route definition with unexpected end . |
34,845 | public static function unexpectedCharacter ( Input $ definition , array $ expected = [ ] ) : self { $ pointer = self :: createPointerString ( $ definition -> getInput ( ) , $ definition -> getIndex ( ) ) ; if ( empty ( $ expected ) ) { return new self ( "Unexpected character:\n$pointer" ) ; } $ expected = $ expected ?? $ definition -> getLatestExpectations ( ) ; $ expected = array_map ( function ( string $ e ) { return "'$e'" ; } , $ expected ) ; $ expected = implode ( ", " , $ expected ) ; return new self ( "Unexpected character (expected $expected):\n$pointer" ) ; } | Invalid route definition with unexpected character . |
34,846 | public static function optionalIsNotSuffix ( Input $ definition ) : self { $ pointer = self :: createPointerString ( $ definition -> getInput ( ) , $ definition -> getIndex ( ) ) ; return new self ( "Optional sequence cannot be followed by anything else:\n$pointer" ) ; } | Invalid route definition where optional part is not at the very end . |
34,847 | public static function longAttributeName ( Input $ definition , int $ maxLength ) : self { return self :: longAttributeParameter ( $ definition , $ maxLength , "name" ) ; } | Invalid route definition with too long attribute name . |
34,848 | public static function longAttributeType ( Input $ definition , int $ maxLength ) : self { return self :: longAttributeParameter ( $ definition , $ maxLength , "type" ) ; } | Invalid route definition with too long attribute type . |
34,849 | private static function emptyAttributeParameter ( Input $ definition , string $ parameter ) : self { $ pointer = self :: createPointerString ( $ definition -> getInput ( ) , $ definition -> getIndex ( ) ) ; return new self ( "The attribute $parameter is missing:\n$pointer" ) ; } | Invalid route definition with invalid attribute parameter . |
34,850 | private static function longAttributeParameter ( Input $ definition , int $ maxLength , string $ parameter ) : self { $ pointer = self :: createPointerString ( $ definition -> getInput ( ) , $ definition -> getIndex ( ) - 1 ) ; return new self ( "The attribute $parameter exceeded maximum allowed length of $maxLength characters:\n$pointer" ) ; } | Invalid route definition with too long attribute parameter . |
34,851 | private static function createPointerString ( string $ string , int $ padding ) : string { $ pointer = str_repeat ( " " , $ padding ) . "^" ; return $ string . "\n" . $ pointer ; } | Creates a string with an arrow pointing to the character after padding . |
34,852 | protected static function renderXML ( $ file , $ params ) { if ( empty ( static :: $ xml [ $ file ] ) ) { static :: $ xml [ $ file ] = file_get_contents ( __DIR__ . '/xml/' . $ file . '.xml' ) ; } $ search = [ ] ; $ replace = [ ] ; foreach ( $ params as $ key => $ value ) { $ search [ ] = ':' . $ key ; $ replace [ ] = $ value ; } return str_replace ( $ search , $ replace , static :: $ xml [ $ file ] ) ; } | Loads the xml file substitutes params |
34,853 | public function delivery ( $ msg_id , $ msg_key ) { $ data = [ 'message_id' => $ msg_id , 'message_key' => $ msg_key ] ; $ xml = static :: renderXML ( 'delivery' , $ data ) ; $ response = $ this -> sendRequest ( $ xml ) ; libxml_use_internal_errors ( true ) ; $ xmlresp = simplexml_load_string ( $ response ) ; $ arr = json_decode ( json_encode ( $ xmlresp ) , true ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( false ) ; $ delivery = new DhiraaguSmsDelivery ( $ arr ) ; if ( empty ( $ delivery -> message_status_id ) ) { throw DhiraaguDeliveryException :: messageFailed ( $ delivery -> response_status , $ delivery -> response_status_desc ) ; } return $ delivery ; } | Checks the delivery status of a message |
34,854 | public function load ( $ langs ) { $ files = $ this -> listLangFiles ( ) ; $ this -> loadedLang = null ; if ( empty ( $ files ) ) { throw new CantLoadDictionaryException ( CantLoadDictionaryException :: NO_DICTIONARY_FILES ) ; } foreach ( $ langs as $ lang ) { $ loaded = $ this -> loadMatchingFile ( $ files , $ lang ) ; $ dict = $ loaded [ 'dict' ] ; $ loadedLang = $ loaded [ 'lang' ] ; if ( $ dict !== null ) { $ this -> loadedLang = $ loadedLang ; return $ dict ; } } return null ; } | Load the best dictionary looking at the prefered languages given in parameter . |
34,855 | private function loadMatchingFile ( $ files , $ lang ) { foreach ( $ files as $ file ) { $ fileLocale = substr ( $ file , 0 , strlen ( $ file ) - 5 ) ; if ( \ Locale :: filterMatches ( $ lang , $ fileLocale ) ) { return array ( 'dict' => $ this -> loadFile ( $ file ) , 'lang' => $ fileLocale ) ; } } return null ; } | Load the best dictionary looking at the language code given in parameter . |
34,856 | public static function create ( ? TypeCollection $ types = null ) : self { $ types = $ types ?? TypeCollection :: createDefault ( ) ; $ parser = new Parser ( ) ; $ factory = new RouteFactory ( $ parser , $ types ) ; return new self ( $ factory ) ; } | Creates new empty route collection . |
34,857 | public function get ( string $ definition , RequestHandlerInterface $ handler , ? string $ name = null , $ data = null ) : Route { return $ this -> route ( Method :: GET , $ definition , $ handler , $ name , $ data ) ; } | Creates a GET route . |
34,858 | public function post ( string $ definition , RequestHandlerInterface $ handler , ? string $ name = null , $ data = null ) : Route { return $ this -> route ( Method :: POST , $ definition , $ handler , $ name , $ data ) ; } | Creates a POST route . |
34,859 | public function put ( string $ definition , RequestHandlerInterface $ handler , ? string $ name = null , $ data = null ) : Route { return $ this -> route ( Method :: PUT , $ definition , $ handler , $ name , $ data ) ; } | Creates a PUT route . |
34,860 | public function patch ( string $ definition , RequestHandlerInterface $ handler , ? string $ name = null , $ data = null ) : Route { return $ this -> route ( Method :: PATCH , $ definition , $ handler , $ name , $ data ) ; } | Creates a PATCH route . |
34,861 | public function delete ( string $ definition , RequestHandlerInterface $ handler , ? string $ name = null , $ data = null ) : Route { return $ this -> route ( Method :: DELETE , $ definition , $ handler , $ name , $ data ) ; } | Creates a DELETE route . |
34,862 | public function oneNamed ( string $ name ) : ? Route { if ( ! array_key_exists ( $ name , $ this -> named ) ) { return null ; } return $ this -> named [ $ name ] ; } | Returns one route with the given name . |
34,863 | public function allowDelete ( $ order ) { if ( $ order -> getStatus ( ) -> getId ( ) >= OrderStatus :: STATUS_CONFIRMED ) { return false ; } foreach ( $ this -> dependencyClasses as $ dependency ) { if ( ! $ dependency -> allowDelete ( $ order ) ) { return false ; } } return true ; } | Returns array of parameters . |
34,864 | public function allowCancel ( $ order ) { foreach ( $ this -> dependencyClasses as $ dependency ) { if ( ! $ dependency -> allowCancel ( $ order ) ) { return false ; } } return true ; } | Returns the identifying name . |
34,865 | public function getWorkflows ( $ order ) { $ workflows = array ( 'confirm' => array ( 'section' => $ this -> getName ( ) , 'title' => 'salesorder.orders.confirm' , 'event' => 'sulu.salesorder.order.confirm.clicked' , 'disabled' => true , ) , 'edit' => array ( 'section' => $ this -> getName ( ) , 'title' => 'salesorder.orders.edit' , 'event' => 'sulu.salesorder.order.edit.clicked' , 'disabled' => true , ) , ) ; $ orderStatusId = $ order -> getStatus ( ) -> getId ( ) ; if ( $ orderStatusId === OrderStatus :: STATUS_CREATED ) { $ workflows [ 'confirm' ] [ 'disabled' ] = false ; } else if ( $ orderStatusId === OrderStatus :: STATUS_CONFIRMED ) { $ workflows [ 'edit' ] [ 'disabled' ] = false ; } foreach ( $ this -> dependencyClasses as $ dependency ) { $ workflows = array_merge ( $ workflows , $ dependency -> getWorkflows ( $ order ) ) ; } return array_values ( $ workflows ) ; } | Returns all possible workflows for the current entity . |
34,866 | public function reshare ( $ visibility , $ id , $ comment = null , $ twitter = false ) { $ token = $ this -> oauth -> getToken ( ) ; $ parameters = array ( 'oauth_token' => $ token [ 'key' ] , ) ; $ this -> oauth -> setOption ( 'success_code' , 201 ) ; $ base = '/v1/people/~/shares' ; if ( $ twitter ) { $ base .= '?twitter-post=true' ; } $ xml = '<share> <visibility> <code>' . $ visibility . '</code> </visibility>' ; if ( $ comment ) { $ xml .= '<comment>' . $ comment . '</comment>' ; } $ xml .= ' <attribution> <share> <id>' . $ id . '</id> </share> </attribution> </share>' ; $ path = $ this -> getOption ( 'api.url' ) . $ base ; $ header [ 'Content-Type' ] = 'text/xml' ; $ response = $ this -> oauth -> oauthRequest ( $ path , 'POST' , $ parameters , $ xml , $ header ) ; return $ response ; } | Method to reshare an existing share . |
34,867 | public function getCurrentShare ( $ id = null , $ url = null ) { $ token = $ this -> oauth -> getToken ( ) ; $ parameters = array ( 'oauth_token' => $ token [ 'key' ] , ) ; $ base = '/v1/people/' ; if ( $ id ) { $ base .= 'id=' . $ id ; } elseif ( ! $ url ) { $ base .= '~' ; } if ( $ url ) { $ base .= 'url=' . $ this -> oauth -> safeEncode ( $ url ) ; } $ base .= ':(current-share)' ; $ data [ 'format' ] = 'json' ; $ path = $ this -> getOption ( 'api.url' ) . $ base ; $ response = $ this -> oauth -> oauthRequest ( $ path , 'GET' , $ parameters , $ data ) ; return json_decode ( $ response -> body ) ; } | Method to get a particular member s current share . |
34,868 | public function getNetworkStats ( ) { $ token = $ this -> oauth -> getToken ( ) ; $ parameters = array ( 'oauth_token' => $ token [ 'key' ] , ) ; $ base = '/v1/people/~/network/network-stats' ; $ data [ 'format' ] = 'json' ; $ path = $ this -> getOption ( 'api.url' ) . $ base ; $ response = $ this -> oauth -> oauthRequest ( $ path , 'GET' , $ parameters , $ data ) ; return json_decode ( $ response -> body ) ; } | Method to get information about the current member s network . |
34,869 | public function postComment ( $ key , $ comment ) { $ token = $ this -> oauth -> getToken ( ) ; $ parameters = array ( 'oauth_token' => $ token [ 'key' ] , ) ; $ this -> oauth -> setOption ( 'success_code' , 201 ) ; $ base = '/v1/people/~/network/updates/key=' . $ key . '/update-comments' ; $ xml = '<update-comment> <comment>' . $ comment . '</comment> </update-comment>' ; $ header [ 'Content-Type' ] = 'text/xml' ; $ path = $ this -> getOption ( 'api.url' ) . $ base ; $ response = $ this -> oauth -> oauthRequest ( $ path , 'POST' , $ parameters , $ xml , $ header ) ; return $ response ; } | Method to post a new comment to an existing update . |
34,870 | public function staticControl ( $ label , $ html , $ options = array ( ) ) { $ options [ 'type' ] = 'static' ; $ options = $ this -> addClass ( $ options , 'form-control-static' ) ; $ options = $ this -> _initInputOptions ( $ options ) ; $ html = $ this -> Html -> tag ( 'div' , $ html , array ( 'class' => $ options [ 'class' ] ) ) ; if ( $ this -> inputOptions [ 'custom' ] ) { $ html = $ this -> Html -> tag ( 'div' , $ html , array ( 'class' => $ this -> inputOptions [ 'custom' ] [ 'wrap' ] ) ) ; } if ( ! empty ( $ options [ 'label' ] ) ) { $ label = $ this -> Html -> tag ( 'label' , $ label , $ options [ 'label' ] ) ; } $ divOptions = $ this -> _divOptions ( $ options ) ; unset ( $ divOptions [ 'tag' ] ) ; $ html = $ this -> Html -> tag ( 'div' , $ label . $ html , $ divOptions ) ; return $ html ; } | Generates a static from control with the passed label and html options . |
34,871 | private function getPlaintextValue ( EncryptRequest $ request ) { if ( ! $ request -> getPlaintextValue ( ) ) { $ plaintextValue = $ request -> getPlaintextQuestionAsker ( ) -> askQuestion ( ) ; } else { $ plaintextValue = $ request -> getPlaintextValue ( ) ; } return $ plaintextValue ; } | Get plaintext value . |
34,872 | protected function chooseSkeleton ( $ skeleton ) { if ( $ skeleton ) { if ( ! in_array ( $ skeleton , $ this -> skeletons ) ) { throw new InvalidArgumentException ( "Skeleton '$skeleton' is not found." ) ; } } else { $ skeleton = $ this -> choice ( 'Skeleton type' , $ this -> skeletons , array_search ( $ this -> default_skeleton , $ this -> skeletons ) ) ; } return $ skeleton ; } | Choose skeleton by command line parameter or dialog . |
34,873 | protected function encodeEmail ( $ email ) { if ( $ email == '' ) { return '' ; } if ( strpos ( $ email , '@' ) === false ) { return $ email ; } $ arrChunks = explode ( '@' , $ email ) ; $ strHost = array_pop ( $ arrChunks ) ; return implode ( '@' , $ arrChunks ) . '@' . static :: encode ( $ strHost ) ; } | Encode all e - mail addresses within a string |
34,874 | public function getProfile ( $ id = null , $ url = null , $ fields = null , $ type = 'standard' , $ language = null ) { $ token = $ this -> oauth -> getToken ( ) ; $ parameters = array ( 'oauth_token' => $ token [ 'key' ] , ) ; $ base = '/v1/people/' ; $ data [ 'format' ] = 'json' ; if ( $ id ) { $ base .= 'id=' . $ id ; } elseif ( ! $ url ) { $ base .= '~' ; } if ( $ url ) { $ base .= 'url=' . $ this -> oauth -> safeEncode ( $ url ) ; if ( ! strcmp ( $ type , 'public' ) ) { $ base .= ':public' ; } } if ( $ fields ) { $ base .= ':' . $ fields ; } $ header = array ( ) ; if ( $ language ) { $ header = array ( 'Accept-Language' => $ language ) ; } $ path = $ this -> getOption ( 'api.url' ) . $ base ; $ response = $ this -> oauth -> oauthRequest ( $ path , 'GET' , $ parameters , $ data , $ header ) ; return json_decode ( $ response -> body ) ; } | Method to get a member s profile . |
34,875 | public function storeFieldData ( VersionInfo $ versionInfo , $ productId ) { $ contentId = $ versionInfo -> contentInfo -> id ; $ selectQuery = $ this -> connection -> createQueryBuilder ( ) ; $ selectQuery -> select ( 'DISTINCT contentobject_id' ) -> from ( 'ngsyliusproduct' ) -> where ( $ selectQuery -> expr ( ) -> eq ( 'contentobject_id' , ':contentobject_id' ) ) -> setParameter ( 'contentobject_id' , $ contentId , Type :: INTEGER ) ; $ statement = $ selectQuery -> execute ( ) ; $ rows = $ statement -> fetchAll ( PDO :: FETCH_ASSOC ) ; if ( count ( $ rows ) > 0 ) { $ query = $ this -> connection -> createQueryBuilder ( ) ; $ query -> update ( 'ngsyliusproduct' ) -> set ( 'product_id' , ':product_id' ) -> where ( $ query -> expr ( ) -> eq ( 'contentobject_id' , ':contentobject_id' ) ) -> setParameter ( 'product_id' , $ productId , Type :: INTEGER ) -> setParameter ( 'contentobject_id' , $ contentId , Type :: INTEGER ) ; } else { $ query = $ this -> connection -> createQueryBuilder ( ) ; $ query -> insert ( 'ngsyliusproduct' ) -> values ( array ( 'product_id' => ':product_id' , 'contentobject_id' => ':contentobject_id' , ) ) -> setParameter ( 'product_id' , $ productId , Type :: INTEGER ) -> setParameter ( 'contentobject_id' , $ contentId , Type :: INTEGER ) ; } $ query -> execute ( ) ; } | Stores the data in the database based on the given field data . |
34,876 | public function getFieldData ( VersionInfo $ versionInfo ) { $ query = $ this -> connection -> createQueryBuilder ( ) ; $ query -> select ( 'product_id' ) -> from ( 'ngsyliusproduct' ) -> where ( $ query -> expr ( ) -> eq ( 'contentobject_id' , ':contentobject_id' ) ) -> setParameter ( 'contentobject_id' , $ versionInfo -> contentInfo -> id , Type :: INTEGER ) ; $ statement = $ query -> execute ( ) ; $ rows = $ statement -> fetchAll ( PDO :: FETCH_ASSOC ) ; return ! empty ( $ rows [ 0 ] [ 'product_id' ] ) ? ( int ) $ rows [ 0 ] [ 'product_id' ] : null ; } | Gets the product ID stored in the field . |
34,877 | public function indexAction ( Request $ request , AbstractAdmin $ admin ) { $ this -> secure ( $ admin , ContentVoter :: LIST_CONTENT ) ; $ datagrid = $ this -> get ( 'shuwee_admin.datagrid' ) ; $ datagrid -> bind ( $ admin , $ request ) ; return $ this -> render ( 'ShuweeAdminBundle:Content:index.html.twig' , [ 'datagrid' => $ datagrid , ] ) ; } | List all entities of the type supported by given Admin |
34,878 | public function createAction ( Request $ request , AbstractAdmin $ admin ) { $ translator = $ this -> getTranslator ( ) ; $ entityClass = $ admin -> getEntityClass ( ) ; $ entity = new $ entityClass ( ) ; $ this -> secure ( $ admin , ContentVoter :: CREATE_CONTENT , $ entity ) ; $ form = $ this -> getCreateForm ( $ admin , $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ admin -> prePersist ( $ entity ) ; $ em -> persist ( $ entity ) ; $ admin -> postPersist ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , $ translator -> trans ( 'crud.create.success' , [ ] , 'ShuweeAdminBundle' ) ) ; return $ this -> redirect ( $ this -> getAdminRoutingHelper ( ) -> generateUrl ( $ admin , 'index' ) ) ; } $ admin -> preCreateFormRender ( $ form ) ; return $ this -> render ( 'ShuweeAdminBundle:Content:create.html.twig' , [ 'admin' => $ admin , 'form' => $ form -> createView ( ) , ] ) ; } | Create an entity of given type |
34,879 | public function updateAction ( Request $ request , AbstractAdmin $ admin ) { $ translator = $ this -> getTranslator ( ) ; $ id = $ request -> attributes -> get ( 'id' ) ; $ entity = $ this -> getDoctrine ( ) -> getRepository ( $ admin -> getEntityClass ( ) ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'That resource cannot be found' ) ; } $ this -> secure ( $ admin , ContentVoter :: UPDATE_CONTENT , $ entity ) ; $ form = $ this -> getUpdateForm ( $ admin , $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ admin -> preUpdate ( $ entity ) ; $ em -> persist ( $ entity ) ; $ admin -> postUpdate ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , $ translator -> trans ( 'crud.edit.success' , [ ] , 'ShuweeAdminBundle' ) ) ; return $ this -> redirect ( $ this -> getAdminRoutingHelper ( ) -> generateUrl ( $ admin , 'index' ) ) ; } return $ this -> render ( 'ShuweeAdminBundle:Content:update.html.twig' , [ 'admin' => $ admin , 'entity' => $ entity , 'form' => $ form -> createView ( ) , ] ) ; } | Update a given entity |
34,880 | public function toggleAction ( Request $ request , AbstractAdmin $ admin ) { $ id = $ request -> attributes -> get ( 'id' ) ; $ entity = $ this -> getDoctrine ( ) -> getRepository ( $ admin -> getEntityClass ( ) ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'The resource cannot be found' ) ; } $ this -> secure ( $ admin , ContentVoter :: UPDATE_CONTENT , $ entity ) ; $ this -> checkCsrf ( $ request -> attributes -> get ( 'token' ) ) ; $ field = $ request -> attributes -> get ( 'field' ) ; $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; $ current = $ accessor -> getValue ( $ entity , $ field ) ; $ accessor -> setValue ( $ entity , $ field , ! $ current ) ; try { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; return new JsonResponse ( ! $ current , 200 ) ; } catch ( Exception $ e ) { return new JsonResponse ( $ current , 500 ) ; } } | Toggles the value of a given field |
34,881 | private function getCreateForm ( AbstractAdmin $ admin , $ entity ) { $ translator = $ this -> getTranslator ( ) ; $ formType = $ admin -> getForm ( ) ; $ form = $ this -> createForm ( $ formType , $ entity , [ 'action' => $ this -> getAdminRoutingHelper ( ) -> generateUrl ( $ admin , 'create' ) , 'method' => 'POST' , ] ) ; $ form -> add ( 'submit' , SubmitType :: class , [ 'label' => $ translator -> trans ( 'crud.create.action' , [ ] , 'ShuweeAdminBundle' ) , 'attr' => [ 'class' => 'btn-success' ] , ] ) ; return $ form ; } | Get form to create a new entity . |
34,882 | private function getDeleteForm ( AbstractAdmin $ admin , $ entity ) { $ translator = $ this -> getTranslator ( ) ; return $ this -> createFormBuilder ( ) -> setAction ( $ this -> getAdminRoutingHelper ( ) -> generateUrl ( $ admin , 'delete' , [ 'id' => $ entity -> getId ( ) ] ) ) -> setMethod ( 'DELETE' ) -> add ( 'submit' , SubmitType :: class , [ 'label' => $ translator -> trans ( 'crud.delete.action' , [ ] , 'ShuweeAdminBundle' ) , 'attr' => [ 'class' => 'btn-danger' ] , ] ) -> getForm ( ) ; } | Get form to update an existing entity . |
34,883 | private function secure ( AbstractAdmin $ admin , $ attributes , $ object = null ) { if ( ! is_array ( $ attributes ) ) { $ attributes = [ $ attributes ] ; } if ( is_null ( $ object ) ) { $ entityClass = $ admin -> getEntityClass ( ) ; $ object = new $ entityClass ( ) ; } if ( ! $ this -> get ( 'security.authorization_checker' ) -> isGranted ( $ attributes , $ object ) ) { throw new AccessDeniedException ( ) ; } } | Ensure a user is allowed to access an action |
34,884 | private function checkCsrf ( $ tokenValue ) { $ csrfTokenManager = $ this -> get ( 'security.csrf.token_manager' ) ; $ token = new CsrfToken ( 'datagrid' , $ tokenValue ) ; if ( ! $ csrfTokenManager -> isTokenValid ( $ token ) ) { throw new AccessDeniedException ( 'Invalid token' ) ; } } | Check provided token is valid to prevent csrf attacks |
34,885 | public function parse ( OptionsBag $ sessionOptions ) { if ( $ sessionOptions [ 'save_path' ] ) { return $ this -> parseConnectionsFromSavePath ( $ sessionOptions [ 'save_path' ] ) ; } return $ this -> parseConnectionsFromOptions ( $ sessionOptions ) ; } | Parse the session options to connection parameters . |
34,886 | protected function parseConnectionsFromSavePath ( $ savePath ) { $ connections = ( array ) explode ( ',' , $ savePath ) ; $ connections = array_map ( 'trim' , $ connections ) ; return array_map ( [ $ this , 'parseConnectionItemFromSavePath' ] , $ connections ) ; } | Parses session save_path into a list of connection parameters . |
34,887 | protected function parseConnectionsFromOptions ( OptionsBag $ options ) { if ( $ options -> has ( 'connections' ) ) { $ connections = $ options -> get ( 'connections' ) ; } elseif ( $ options -> has ( 'connection' ) ) { $ connections = [ $ options -> get ( 'connection' ) ] ; } elseif ( $ options -> has ( 'host' ) || $ options -> has ( 'port' ) ) { Deprecated :: warn ( 'Specifying "host" and other options directly in session config' , 1.0 , 'Move them under the "connection" key.' ) ; $ connections = [ $ options -> all ( ) ] ; } else { $ connections = [ [ ] ] ; } return array_map ( [ $ this , 'parseConnectionItemFromOptions' ] , $ connections ) ; } | Parses session options with array configuration into a list of connection parameters . |
34,888 | public function parse ( string $ definition , TypeCollection $ types ) : RoutePath { $ definition = new Input ( $ definition ) ; try { $ parsed = $ this -> parseRoute ( $ definition , $ types , [ ] ) ; } catch ( UnexpectedChar $ exception ) { if ( $ definition -> peek ( ) === Input :: END ) { throw InvalidRoute :: unexpectedEnd ( $ definition ) ; } $ expected = $ exception -> getExpected ( ) ; throw InvalidRoute :: unexpectedCharacter ( $ definition , $ expected ) ; } if ( ! $ definition -> atEnd ( ) ) { if ( $ definition -> getLastTaken ( ) === "]" && $ definition -> peek ( ) !== "]" ) { throw InvalidRoute :: optionalIsNotSuffix ( $ definition ) ; } throw InvalidRoute :: unexpectedCharacter ( $ definition ) ; } return $ parsed ; } | Parse the route path definition . |
34,889 | private function parseRoute ( Input $ definition , TypeCollection $ types , array $ attributes ) : RoutePath { $ char = $ definition -> peek ( ) ; if ( $ char === "{" ) { return $ this -> parseAttribute ( $ definition , $ types , $ attributes ) ; } if ( $ char === "[" ) { return $ this -> parseOptional ( $ definition , $ types , $ attributes ) ; } if ( $ char === "}" ) { throw InvalidRoute :: unexpectedCharacter ( $ definition , $ attributes ) ; } if ( $ char === "]" || $ char === Input :: END ) { return new EmptyPath ( ) ; } return $ this -> parseStatic ( $ definition , $ types , $ attributes ) ; } | Parse the main part of the route definition . |
34,890 | private function parseStatic ( Input $ definition , TypeCollection $ types , array $ attributes ) : StaticPath { $ static = $ definition -> takeAllUntil ( "{}[]" ) ; $ next = $ this -> parseRoute ( $ definition , $ types , $ attributes ) ; return new StaticPath ( $ static , $ next ) ; } | Parse the static part of the route definition . |
34,891 | private function parseAttribute ( Input $ definition , TypeCollection $ types , array $ attributes ) : AttributePath { $ definition -> expect ( "{" ) ; $ name = $ this -> parseAttributeName ( $ definition ) ; $ type = $ this -> parseAttributeType ( $ definition ) ?? "" ; $ definition -> expect ( "}" ) ; if ( in_array ( $ name , $ attributes ) ) { throw InvalidRoute :: ambiguousAttribute ( $ definition , $ name ) ; } if ( ! $ types -> hasNamed ( $ type ) ) { throw InvalidRoute :: unknownAttributeType ( $ definition , $ name , $ type ) ; } $ type = $ types -> getNamed ( $ type ) ; $ attributes [ ] = $ name ; $ next = $ this -> parseRoute ( $ definition , $ types , $ attributes ) ; return new AttributePath ( $ name , $ type , $ next ) ; } | Parse a single attribute of the route definition . |
34,892 | private function parseOptional ( Input $ definition , TypeCollection $ types , array $ attributes ) : OptionalPath { $ definition -> expect ( "[" ) ; $ optional = $ this -> parseRoute ( $ definition , $ types , $ attributes ) ; $ definition -> expect ( "]" ) ; return new OptionalPath ( $ optional ) ; } | Parse the optional part of the route definition . |
34,893 | private function parseAttributeName ( Input $ definition ) : string { $ maxLength = self :: MAX_ATTRIBUTE_NAME_LENGTH ; $ name = $ definition -> takeAllAlphaNumUntil ( ":}" ) ; if ( empty ( $ name ) ) { throw InvalidRoute :: emptyAttributeName ( $ definition ) ; } if ( strlen ( $ name ) > $ maxLength ) { throw InvalidRoute :: longAttributeName ( $ definition , $ maxLength ) ; } return $ name ; } | Parse the attribute name . |
34,894 | private function parseAttributeType ( Input $ definition ) : ? string { $ maxLength = self :: MAX_ATTRIBUTE_TYPE_LENGTH ; if ( $ definition -> peek ( ) !== ":" ) { return null ; } $ definition -> take ( ) ; $ type = $ definition -> takeAllAlphaNumUntil ( "}" ) ; if ( empty ( $ type ) ) { throw InvalidRoute :: emptyAttributeType ( $ definition ) ; } if ( strlen ( $ type ) > $ maxLength ) { throw InvalidRoute :: longAttributeType ( $ definition , $ maxLength ) ; } return $ type ; } | Parse the attribute type . |
34,895 | private function initialize ( $ file ) { if ( file_exists ( $ file ) ) { $ this -> file = realpath ( $ file ) ; return false ; } file_put_contents ( $ file , '' ) ; $ this -> file = realpath ( $ file ) ; return true ; } | Initializes the database for work . |
34,896 | public function load ( ) { if ( ! file_exists ( $ this -> file ) ) { return [ ] ; } $ data = file_get_contents ( $ this -> file ) ; if ( strlen ( $ data ) === 0 ) { return [ ] ; } if ( $ this -> isEncrypted ( ) ) { $ data = Crypto :: decryptWithPassword ( $ data , $ this -> key , true ) ; } return json_decode ( $ data , true ) ; } | Loads all data from the database decrypting it if needed . |
34,897 | private function rewrite ( $ data ) { $ text = json_encode ( $ data ) ; if ( $ this -> isEncrypted ( ) && strlen ( $ text ) > 0 ) { $ text = Crypto :: encryptWithPassword ( $ text , $ this -> key , true ) ; } file_put_contents ( $ this -> file , $ text ) ; return $ data ; } | Rewrites all data to the database . |
34,898 | public function insert ( $ data ) { $ db = $ this -> load ( ) ; $ db [ ] = $ data ; return $ this -> rewrite ( $ db ) ; } | Inserts a row into the database . |
34,899 | public function remove ( $ index ) { $ db = $ this -> load ( ) ; array_splice ( $ db , $ index , 1 ) ; return $ this -> rewrite ( $ db ) ; } | Removes a row from the database . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.